From cf8afebe6b964db967da534f59ddd62a49205168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Mon, 22 May 2023 11:49:01 +0200 Subject: [PATCH 01/37] Add theories 398 397 to theory.db --- nnpdfcpp/data/theory.db | Bin 102400 -> 106496 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/nnpdfcpp/data/theory.db b/nnpdfcpp/data/theory.db index 1f953e2459c1a85332b22111d2482d6dfe3ba942..06c5db50dbc4d5580ade634dc200f83d9c29f3b2 100644 GIT binary patch delta 398 zcmZozz}9epZGto_8v_G_)I=M`OE=2ICEJW*)|q)7c#u=dv&`Fsg1WRAgjnQf$nerorgAozIE!2d|V31M>yG z^SrBg8o0x_#29Uu+BnX#H?vu=eBD?m%E-ff2xv0{Lz7!Guh#UcW=2(}M)v8BQH&bX zPc$>`oc^|rk(=4n$awnmNJaw|w`M*(ij2UDm=zndK-N#L-*tNW0X0SuR?{Z?W})f1 z8H{S%;PAEN5U>Wqri5oNotj36BNWZ_afbnas&dvJCep79M0`@7h>+gn7Gh zAmd@??O7R&)6}OGFtP}+abz*@t>ew)(cyZ>xq>4L7@%Ps+wUhZcCqt-Jpm;E#zAOL delta 220 zcmV<203-i^zy^Sz29O&C1ONa48Id4A0R*vNqz?lX4}X&f5G(_Q4}Y^k5IYZ%fDsiK zgD(I802hNH0000MgB1V(02P61lb0WD0~rV`vj-sG0ki5MG6s==6oV`%w=5_D*cSs0 z0Hl`(Kmnb%&{F{>0Rtg{X_hDfLAMS<0r(9XGXM_H4XO-)3swpi2+aqB1~>%u1F-^b z0W-0269KoUWC6ni13!Zjmu+YPCbu6|0p$uD3;^E%4!8|;3^)q=39blf2O|aE1fc_C W0v!O~k#WDbYM23v2e)Zx0hcGeOFe%8 From fcc3e8e101ce61f56bdcc728491801394af712ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Tue, 13 Jun 2023 22:06:10 +0200 Subject: [PATCH 02/37] Add qed test in test_evolven3fit.py --- n3fit/runcards/examples/Basic_runcard_qed.yml | 2 +- n3fit/src/n3fit/tests/test_evolven3fit.py | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/n3fit/runcards/examples/Basic_runcard_qed.yml b/n3fit/runcards/examples/Basic_runcard_qed.yml index 309f5901d5..d07e9d6cfb 100644 --- a/n3fit/runcards/examples/Basic_runcard_qed.yml +++ b/n3fit/runcards/examples/Basic_runcard_qed.yml @@ -95,7 +95,7 @@ datacuts: ############################################################ theory: - theoryid: 522 # database id + theoryid: 523 # database id ############################################################ trvlseed: 1551864071 diff --git a/n3fit/src/n3fit/tests/test_evolven3fit.py b/n3fit/src/n3fit/tests/test_evolven3fit.py index 1796095df1..22708c6279 100644 --- a/n3fit/src/n3fit/tests/test_evolven3fit.py +++ b/n3fit/src/n3fit/tests/test_evolven3fit.py @@ -169,3 +169,29 @@ def test_perform_evolution(tmp_path, fitname): info = check_lhapdf_info(tmp_info) for datpath in tmp_nnfit.glob("replica_*/*.dat"): check_lhapdf_dat(datpath, info) + + +@pytest.mark.parametrize("fitname", ["Basic_runcard_qed_3replicas_lowprec_398"]) +def test_perform_evolution_qed(tmp_path, fitname): + """Test that evolven3fit_new is able to utilize the current eko in the respective theory. + In addition checks that the generated .info files are correct + """ + fit = API.fit(fit=fitname) + # Move the fit to a temporary folder + tmp_fit = tmp_path / fitname + shutil.copytree(fit.path, tmp_fit) + # Clear the .log and .dat files + (tmp_fit / "evolven3fit_new.log").unlink() + tmp_nnfit = tmp_fit / "nnfit" + tmp_info = tmp_nnfit / f"{fitname}.info" + tmp_info.unlink() + for datpath in tmp_nnfit.glob("replica_*/*.dat"): + datpath.unlink() + + # And re-evolve the fit + sp.run(["evolven3fit_new", "evolve", fitname], cwd=tmp_path, check=True) + + # check that everything worked! + info = check_lhapdf_info(tmp_info) + for datpath in tmp_nnfit.glob("replica_*/*.dat"): + check_lhapdf_dat(datpath, info) From 5e7176ef48e6020447d1e2037b85148100ff2258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Tue, 13 Jun 2023 23:02:35 +0200 Subject: [PATCH 03/37] Add qed test in test_fit --- .../n3fit/tests/regressions/quickcard_qed.yml | 92 ++++++++++++++++++ .../tests/regressions/quickcard_qed_1.json | 95 +++++++++++++++++++ .../tests/regressions/quickcard_qed_2.json | 95 +++++++++++++++++++ 3 files changed, 282 insertions(+) create mode 100644 n3fit/src/n3fit/tests/regressions/quickcard_qed.yml create mode 100644 n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json create mode 100644 n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml b/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml new file mode 100644 index 0000000000..950e32c58c --- /dev/null +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml @@ -0,0 +1,92 @@ +# +# Configuration file for n3fit regression tests +# This runcard includes two DIS datasets, one Hadronic dataset +# and two positivity datasets +# + +############################################################ +description: n3fit regression test + +############################################################ +# frac: training fraction +# ewk: apply ewk k-factors +# sys: systematics treatment (see systypes) +dataset_inputs: +- { dataset: NMC, frac: 0.5 } +- { dataset: SLACP_dwsh, frac: 0.5} +- { dataset: CMSZDIFF12, frac: 0.5, cfac: ['QCD'], sys: 10 } +- { dataset: ATLASTTBARTOT8TEV, frac: 1.0, cfac: ['QCD'] } + +############################################################ +datacuts: + t0pdfset: NNPDF40_nnlo_as_01180 # PDF set to generate t0 covmat + q2min : 3.49 # Q2 minimum + w2min : 12.5 # W2 minimum + combocuts : NNPDF31 # NNPDF3.0 final kin. cuts + jetptcut_tev : 0 # jet pt cut for tevatron + jetptcut_lhc : 0 # jet pt cut for lhc + wptcut_lhc : 30.0 # Minimum pT for W pT diff distributions + jetycut_tev : 1e30 # jet rap. cut for tevatron + jetycut_lhc : 1e30 # jet rap. cut for lhc + dymasscut_min: 0 # dy inv.mass. min cut + dymasscut_max: 1e30 # dy inv.mass. max cut + jetcfactcut : 1e30 # jet cfact. cut + +############################################################ +theory: + theoryid: 398 # database id + +############################################################ +genrep: True # on = generate MC replicas, False = use real data +trvlseed: 3 +nnseed: 2 +mcseed: 1 + +load: "weights.h5" + +parameters: # This defines the parameter dictionary that is passed to the Model Trainer + nodes_per_layer: [15, 10, 8] + activation_per_layer: ['sigmoid', 'sigmoid', 'linear'] + initializer: 'glorot_normal' + optimizer: + optimizer_name: 'RMSprop' + learning_rate: 0.00001 + clipnorm: 1.0 + epochs: 1100 + positivity: + multiplier: 1.05 + initial: 1.5 + stopping_patience: 0.10 # percentage of the number of epochs + layer_type: 'dense' + dropout: 0.0 + threshold_chi2: 10.0 + +fitting: + fitbasis: NN31IC # EVOL (7), EVOLQED (8), etc. + basis: + - { fl: sng, smallx: [1.05,1.19], largex: [1.47,2.70] } + - { fl: g, smallx: [0.94,1.25], largex: [0.11,5.87] } + - { fl: v, smallx: [0.54,0.75], largex: [1.15,2.76] } + - { fl: v3, smallx: [0.21,0.57], largex: [1.35,3.08] } + - { fl: v8, smallx: [0.52,0.76], largex: [0.77,3.56] } + - { fl: t3, smallx: [-0.37,1.52], largex: [1.74,3.39] } + - { fl: t8, smallx: [0.56,1.29], largex: [1.45,3.03] } + - { fl: cp, smallx: [0.12,1.19], largex: [1.83,6.70] } + +############################################################ +positivity: + posdatasets: + - { dataset: POSF2U, maxlambda: 1e6 } # Positivity Lagrange Multiplier + - { dataset: POSDYS, maxlambda: 1e5 } + +integrability: + integdatasets: + - {dataset: INTEGXT8, maxlambda: 1e2} + +############################################################ +debug: true + +fiatlux: + luxset: NNPDF40_nnlo_as_01180 + additional_errors: true # should be set to true only for the last iteration + luxseed: 1234567890 diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json b/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json new file mode 100644 index 0000000000..5c47a02aa6 --- /dev/null +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json @@ -0,0 +1,95 @@ +{ + "preprocessing": [ + { + "fl": "sng", + "smallx": 1.1307647228240967, + "largex": 2.6348154544830322, + "trainable": true + }, + { + "fl": "g", + "smallx": 1.1853630542755127, + "largex": 1.5627975463867188, + "trainable": true + }, + { + "fl": "v", + "smallx": 0.5399999022483826, + "largex": 2.004500150680542, + "trainable": true + }, + { + "fl": "v3", + "smallx": 0.3061821758747101, + "largex": 2.6243231296539307, + "trainable": true + }, + { + "fl": "v8", + "smallx": 0.5774596929550171, + "largex": 2.120253801345825, + "trainable": true + }, + { + "fl": "t3", + "smallx": 1.3441987037658691, + "largex": 1.7566683292388916, + "trainable": true + }, + { + "fl": "t8", + "smallx": 1.04995858669281, + "largex": 1.945939064025879, + "trainable": true + }, + { + "fl": "cp", + "smallx": 0.7400740385055542, + "largex": 3.461853504180908, + "trainable": true + } + ], + "stop_epoch": 1100, + "best_epoch": 1099, + "erf_tr": 31.479900360107422, + "erf_vl": 28.42186164855957, + "chi2": 19.602598190307617, + "pos_state": "POS_VETO", + "arc_lengths": [ + 1.0355354158791996, + 1.1952711188285763, + 1.0889863228847247, + 1.3354546180547748, + 1.0845053775983715 + ], + "integrability": [ + 0.002640353239258264, + 0.002640353239257265, + 0.00025514093067380283, + 3.289671421051026, + 0.0039052469655898037 + ], + "timing": { + "walltime": { + "Total": 1332.9973878860474, + "start": 0.0, + "replica_set": 0.539992094039917, + "replica_fitted": 1332.997339963913, + "replica_set_to_replica_fitted": 1332.457347869873 + }, + "cputime": { + "Total": 1332.938156, + "start": 0.0, + "replica_set": 2.026674, + "replica_fitted": 1332.938103, + "replica_set_to_replica_fitted": 1330.911429 + } + }, + "version": { + "keras": "2.10.0", + "tensorflow": "2.10.0, mkl=False", + "numpy": "1.22.4", + "nnpdf": "4.0.6.840+gfcc3e8e10-dev", + "validphys": "4.0.6.840+gfcc3e8e10-dev" + } +} \ No newline at end of file diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json b/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json new file mode 100644 index 0000000000..15077e500e --- /dev/null +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json @@ -0,0 +1,95 @@ +{ + "preprocessing": [ + { + "fl": "sng", + "smallx": 1.1090877056121826, + "largex": 2.683891534805298, + "trainable": true + }, + { + "fl": "g", + "smallx": 0.9399998784065247, + "largex": 1.6251798868179321, + "trainable": true + }, + { + "fl": "v", + "smallx": 0.7499998211860657, + "largex": 1.726711630821228, + "trainable": true + }, + { + "fl": "v3", + "smallx": 0.2121002972126007, + "largex": 1.3534746170043945, + "trainable": true + }, + { + "fl": "v8", + "smallx": 0.7599999308586121, + "largex": 2.390061616897583, + "trainable": true + }, + { + "fl": "t3", + "smallx": 1.4388009309768677, + "largex": 2.2958621978759766, + "trainable": true + }, + { + "fl": "t8", + "smallx": 1.0386217832565308, + "largex": 1.7531665563583374, + "trainable": true + }, + { + "fl": "cp", + "smallx": 0.24638593196868896, + "largex": 2.7976953983306885, + "trainable": true + } + ], + "stop_epoch": 1100, + "best_epoch": 1099, + "erf_tr": 3.5775744915008545, + "erf_vl": 3.6801669597625732, + "chi2": 2.1422781944274902, + "pos_state": "POS_VETO", + "arc_lengths": [ + 1.320261058152196, + 1.2008326348375713, + 1.0538968228329768, + 5.092393152077501, + 1.0856575181085886 + ], + "integrability": [ + 0.029426240362226908, + 0.029426240362226963, + 0.0003942905323124357, + 12.764077186584473, + 0.029728015419096226 + ], + "timing": { + "walltime": { + "Total": 1296.5483038425446, + "start": 0.0, + "replica_set": 0.4714009761810303, + "replica_fitted": 1296.5482459068298, + "replica_set_to_replica_fitted": 1296.0768449306488 + }, + "cputime": { + "Total": 1296.4548610000002, + "start": 0.0, + "replica_set": 2.022157, + "replica_fitted": 1296.454798, + "replica_set_to_replica_fitted": 1294.4326409999999 + } + }, + "version": { + "keras": "2.10.0", + "tensorflow": "2.10.0, mkl=False", + "numpy": "1.22.4", + "nnpdf": "4.0.6.840+gfcc3e8e10-dev", + "validphys": "4.0.6.840+gfcc3e8e10-dev" + } +} \ No newline at end of file From 0af300487d7c4412bec587b1a510d5afcbef2ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Tue, 13 Jun 2023 23:03:00 +0200 Subject: [PATCH 04/37] Add qed test in test_fit 2 --- n3fit/src/n3fit/tests/test_fit.py | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/n3fit/src/n3fit/tests/test_fit.py b/n3fit/src/n3fit/tests/test_fit.py index 80a329faa0..496115ea50 100644 --- a/n3fit/src/n3fit/tests/test_fit.py +++ b/n3fit/src/n3fit/tests/test_fit.py @@ -33,6 +33,7 @@ log = logging.getLogger(__name__) REGRESSION_FOLDER = pathlib.Path(__file__).with_name("regressions") QUICKNAME = "quickcard" +QUICKNAME_QED = "quickcard_qed" EXE = "n3fit" REPLICA = "1" EXPECTED_MAX_FITTIME = 130 # seen mac ~ 180 and linux ~ 90 @@ -153,3 +154,50 @@ def test_weirdbasis(tmp_path, timing=30): # with pytest.raises(sp.TimeoutExpired): with pytest.raises(sp.CalledProcessError): sp.run(f"{EXE} {quickcard} {REPLICA}".split(), cwd=tmp_path, timeout=timing, check=True) + + +def auxiliary_performfit_qed(tmp_path, replica=1, timing=True, rel_error=2e-3): + """Fits quickcard and checks the json file to ensure the results have not changed. + """ + quickcard = f"{QUICKNAME_QED}.yml" + # Prepare the runcard + quickpath = REGRESSION_FOLDER / quickcard + weightpath = REGRESSION_FOLDER / f"weights_{replica}.h5" + # read up the previous json file for the given replica + old_json = load_data(REGRESSION_FOLDER / f"{QUICKNAME_QED}_{replica}.json") + # cp runcard and weights to tmp folder + shutil.copy(quickpath, tmp_path) + shutil.copy(weightpath, tmp_path / "weights.h5") + # run the fit + sp.run(f"{EXE} {quickcard} {replica}".split(), cwd=tmp_path, check=True) + # read up json files + full_json = tmp_path / f"{QUICKNAME_QED}/nnfit/replica_{replica}/{QUICKNAME_QED}.json" + new_json = load_data(full_json) + # Now compare to regression results, taking into account precision won't be 100% + equal_checks = ["stop_epoch", "pos_state"] + approx_checks = ["erf_tr", "erf_vl", "chi2", "best_epoch", "arc_lengths", "integrability", "best_epoch"] + for key in equal_checks: + assert_equal(new_json[key], old_json[key]) + for key in approx_checks: + if old_json[key] is None and new_json[key] is None: + continue + assert_allclose(new_json[key], old_json[key], rtol=rel_error) + # check that the times didnt grow in a weird manner + if timing: + # Better to catch up errors even when they happen to grow larger by chance + times = new_json["timing"] + fitting_time = times["walltime"]["replica_set_to_replica_fitted"] + assert fitting_time < EXPECTED_MAX_FITTIME + # For safety, check also the version + assert new_json["version"]["nnpdf"] == n3fit.__version__ + + +@pytest.mark.darwin +def test_performfit_qed(tmp_path): + auxiliary_performfit_qed(tmp_path, replica=2, timing=False, rel_error=1e-1) + + +@pytest.mark.linux +@pytest.mark.parametrize("replica", [1, 2]) +def test_performfit_and_timing_qed(tmp_path, replica): + auxiliary_performfit_qed(tmp_path, replica=replica, timing=True) \ No newline at end of file From 22566646bfa1baa1c72996ba85561a2022a4cb3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Wed, 14 Jun 2023 10:23:19 +0200 Subject: [PATCH 05/37] Refector QED tests --- n3fit/src/n3fit/tests/test_evolven3fit.py | 27 +--------- n3fit/src/n3fit/tests/test_fit.py | 61 +++-------------------- 2 files changed, 9 insertions(+), 79 deletions(-) diff --git a/n3fit/src/n3fit/tests/test_evolven3fit.py b/n3fit/src/n3fit/tests/test_evolven3fit.py index 22708c6279..4d0f0c4dda 100644 --- a/n3fit/src/n3fit/tests/test_evolven3fit.py +++ b/n3fit/src/n3fit/tests/test_evolven3fit.py @@ -145,7 +145,7 @@ def test_eko_utils(tmp_path): assert_allclose(list(eko_op.operator_card.raw["mugrid"]), op_card_dict["mugrid"]) -@pytest.mark.parametrize("fitname", ["Basic_runcard_3replicas_lowprec_399"]) +@pytest.mark.parametrize("fitname", ["Basic_runcard_3replicas_lowprec_399", "Basic_runcard_qed_3replicas_lowprec_398"]) def test_perform_evolution(tmp_path, fitname): """Test that evolven3fit_new is able to utilize the current eko in the respective theory. In addition checks that the generated .info files are correct @@ -170,28 +170,3 @@ def test_perform_evolution(tmp_path, fitname): for datpath in tmp_nnfit.glob("replica_*/*.dat"): check_lhapdf_dat(datpath, info) - -@pytest.mark.parametrize("fitname", ["Basic_runcard_qed_3replicas_lowprec_398"]) -def test_perform_evolution_qed(tmp_path, fitname): - """Test that evolven3fit_new is able to utilize the current eko in the respective theory. - In addition checks that the generated .info files are correct - """ - fit = API.fit(fit=fitname) - # Move the fit to a temporary folder - tmp_fit = tmp_path / fitname - shutil.copytree(fit.path, tmp_fit) - # Clear the .log and .dat files - (tmp_fit / "evolven3fit_new.log").unlink() - tmp_nnfit = tmp_fit / "nnfit" - tmp_info = tmp_nnfit / f"{fitname}.info" - tmp_info.unlink() - for datpath in tmp_nnfit.glob("replica_*/*.dat"): - datpath.unlink() - - # And re-evolve the fit - sp.run(["evolven3fit_new", "evolve", fitname], cwd=tmp_path, check=True) - - # check that everything worked! - info = check_lhapdf_info(tmp_info) - for datpath in tmp_nnfit.glob("replica_*/*.dat"): - check_lhapdf_dat(datpath, info) diff --git a/n3fit/src/n3fit/tests/test_fit.py b/n3fit/src/n3fit/tests/test_fit.py index 496115ea50..8cc009fa53 100644 --- a/n3fit/src/n3fit/tests/test_fit.py +++ b/n3fit/src/n3fit/tests/test_fit.py @@ -65,10 +65,10 @@ def test_initialize_seeds(): assert len({replica_mcseed(rep, 1, True) for rep in same_replicas}) == 1 -def auxiliary_performfit(tmp_path, replica=1, timing=True, rel_error=2e-3): +def auxiliary_performfit(tmp_path, runcard=QUICKNAME, replica=1, timing=True, rel_error=2e-3): """Fits quickcard and checks the json file to ensure the results have not changed. """ - quickcard = f"{QUICKNAME}.yml" + quickcard = f"{runcard}.yml" # Prepare the runcard quickpath = REGRESSION_FOLDER / quickcard weightpath = REGRESSION_FOLDER / f"weights_{replica}.h5" @@ -102,14 +102,16 @@ def auxiliary_performfit(tmp_path, replica=1, timing=True, rel_error=2e-3): @pytest.mark.darwin -def test_performfit(tmp_path): - auxiliary_performfit(tmp_path, replica=2, timing=False, rel_error=1e-1) +@pytest.mark.parametrize("runcard", [QUICKNAME, QUICKNAME_QED]) +def test_performfit(tmp_path, runcard): + auxiliary_performfit(tmp_path, runcard=runcard, replica=2, timing=False, rel_error=1e-1) @pytest.mark.linux @pytest.mark.parametrize("replica", [1, 2]) -def test_performfit_and_timing(tmp_path, replica): - auxiliary_performfit(tmp_path, replica=replica, timing=True) +@pytest.mark.parametrize("runcard", [QUICKNAME, QUICKNAME_QED]) +def test_performfit_and_timing(tmp_path, runcard, replica): + auxiliary_performfit(tmp_path, runcard=runcard, replica=replica, timing=True) @pytest.mark.skip(reason="Still not implemented in parallel mode") @@ -154,50 +156,3 @@ def test_weirdbasis(tmp_path, timing=30): # with pytest.raises(sp.TimeoutExpired): with pytest.raises(sp.CalledProcessError): sp.run(f"{EXE} {quickcard} {REPLICA}".split(), cwd=tmp_path, timeout=timing, check=True) - - -def auxiliary_performfit_qed(tmp_path, replica=1, timing=True, rel_error=2e-3): - """Fits quickcard and checks the json file to ensure the results have not changed. - """ - quickcard = f"{QUICKNAME_QED}.yml" - # Prepare the runcard - quickpath = REGRESSION_FOLDER / quickcard - weightpath = REGRESSION_FOLDER / f"weights_{replica}.h5" - # read up the previous json file for the given replica - old_json = load_data(REGRESSION_FOLDER / f"{QUICKNAME_QED}_{replica}.json") - # cp runcard and weights to tmp folder - shutil.copy(quickpath, tmp_path) - shutil.copy(weightpath, tmp_path / "weights.h5") - # run the fit - sp.run(f"{EXE} {quickcard} {replica}".split(), cwd=tmp_path, check=True) - # read up json files - full_json = tmp_path / f"{QUICKNAME_QED}/nnfit/replica_{replica}/{QUICKNAME_QED}.json" - new_json = load_data(full_json) - # Now compare to regression results, taking into account precision won't be 100% - equal_checks = ["stop_epoch", "pos_state"] - approx_checks = ["erf_tr", "erf_vl", "chi2", "best_epoch", "arc_lengths", "integrability", "best_epoch"] - for key in equal_checks: - assert_equal(new_json[key], old_json[key]) - for key in approx_checks: - if old_json[key] is None and new_json[key] is None: - continue - assert_allclose(new_json[key], old_json[key], rtol=rel_error) - # check that the times didnt grow in a weird manner - if timing: - # Better to catch up errors even when they happen to grow larger by chance - times = new_json["timing"] - fitting_time = times["walltime"]["replica_set_to_replica_fitted"] - assert fitting_time < EXPECTED_MAX_FITTIME - # For safety, check also the version - assert new_json["version"]["nnpdf"] == n3fit.__version__ - - -@pytest.mark.darwin -def test_performfit_qed(tmp_path): - auxiliary_performfit_qed(tmp_path, replica=2, timing=False, rel_error=1e-1) - - -@pytest.mark.linux -@pytest.mark.parametrize("replica", [1, 2]) -def test_performfit_and_timing_qed(tmp_path, replica): - auxiliary_performfit_qed(tmp_path, replica=replica, timing=True) \ No newline at end of file From 5a319fc7f4a4fd38df319db5b8b3e3d041f8c63b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Wed, 14 Jun 2023 11:02:52 +0200 Subject: [PATCH 06/37] Fix test --- n3fit/src/n3fit/tests/test_fit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/n3fit/src/n3fit/tests/test_fit.py b/n3fit/src/n3fit/tests/test_fit.py index 8cc009fa53..97d7d55175 100644 --- a/n3fit/src/n3fit/tests/test_fit.py +++ b/n3fit/src/n3fit/tests/test_fit.py @@ -73,14 +73,14 @@ def auxiliary_performfit(tmp_path, runcard=QUICKNAME, replica=1, timing=True, re quickpath = REGRESSION_FOLDER / quickcard weightpath = REGRESSION_FOLDER / f"weights_{replica}.h5" # read up the previous json file for the given replica - old_json = load_data(REGRESSION_FOLDER / f"{QUICKNAME}_{replica}.json") + old_json = load_data(REGRESSION_FOLDER / f"{runcard}_{replica}.json") # cp runcard and weights to tmp folder shutil.copy(quickpath, tmp_path) shutil.copy(weightpath, tmp_path / "weights.h5") # run the fit sp.run(f"{EXE} {quickcard} {replica}".split(), cwd=tmp_path, check=True) # read up json files - full_json = tmp_path / f"{QUICKNAME}/nnfit/replica_{replica}/{QUICKNAME}.json" + full_json = tmp_path / f"{runcard}/nnfit/replica_{replica}/{runcard}.json" new_json = load_data(full_json) # Now compare to regression results, taking into account precision won't be 100% equal_checks = ["stop_epoch", "pos_state"] From 9758018eaea080cba7cea19562fda45f084ddd4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Wed, 14 Jun 2023 11:21:47 +0200 Subject: [PATCH 07/37] Add fiatlux precision in the runcard --- n3fit/runcards/examples/Basic_runcard_qed.yml | 1 + .../n3fit/tests/regressions/quickcard_qed.yml | 1 + .../tests/regressions/quickcard_qed_1.json | 46 +++++++-------- .../tests/regressions/quickcard_qed_2.json | 58 +++++++++---------- validphys2/src/validphys/photon/compute.py | 8 ++- 5 files changed, 61 insertions(+), 53 deletions(-) diff --git a/n3fit/runcards/examples/Basic_runcard_qed.yml b/n3fit/runcards/examples/Basic_runcard_qed.yml index d07e9d6cfb..d7ccf7b9c1 100644 --- a/n3fit/runcards/examples/Basic_runcard_qed.yml +++ b/n3fit/runcards/examples/Basic_runcard_qed.yml @@ -169,3 +169,4 @@ fiatlux: luxset: NNPDF40_nnlo_as_01180 additional_errors: true # should be set to true only for the last iteration luxseed: 1234567890 + abs_err: 1e-2 diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml b/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml index 950e32c58c..5995b99d60 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml @@ -90,3 +90,4 @@ fiatlux: luxset: NNPDF40_nnlo_as_01180 additional_errors: true # should be set to true only for the last iteration luxseed: 1234567890 + abs_err: 1e-2 diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json b/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json index 5c47a02aa6..fd7c92d36d 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json @@ -51,45 +51,45 @@ ], "stop_epoch": 1100, "best_epoch": 1099, - "erf_tr": 31.479900360107422, - "erf_vl": 28.42186164855957, - "chi2": 19.602598190307617, + "erf_tr": 31.479909896850586, + "erf_vl": 28.421838760375977, + "chi2": 19.602609634399414, "pos_state": "POS_VETO", "arc_lengths": [ - 1.0355354158791996, - 1.1952711188285763, - 1.0889863228847247, - 1.3354546180547748, - 1.0845053775983715 + 1.0355354274955006, + 1.195271539211688, + 1.088986348499315, + 1.335431714155942, + 1.0845053845820272 ], "integrability": [ - 0.002640353239258264, - 0.002640353239257265, - 0.00025514093067380283, - 3.289671421051026, - 0.0039052469655898037 + 0.0026403537049198844, + 0.00264035370491833, + 0.00025512540650873827, + 3.2896719574928284, + 0.0039052472275233896 ], "timing": { "walltime": { - "Total": 1332.9973878860474, + "Total": 53.36410307884216, "start": 0.0, - "replica_set": 0.539992094039917, - "replica_fitted": 1332.997339963913, - "replica_set_to_replica_fitted": 1332.457347869873 + "replica_set": 0.47026801109313965, + "replica_fitted": 53.364020109176636, + "replica_set_to_replica_fitted": 52.893752098083496 }, "cputime": { - "Total": 1332.938156, + "Total": 55.200050000000005, "start": 0.0, - "replica_set": 2.026674, - "replica_fitted": 1332.938103, - "replica_set_to_replica_fitted": 1330.911429 + "replica_set": 2.1680059999999983, + "replica_fitted": 55.199962, + "replica_set_to_replica_fitted": 53.031956 } }, "version": { "keras": "2.10.0", "tensorflow": "2.10.0, mkl=False", "numpy": "1.22.4", - "nnpdf": "4.0.6.840+gfcc3e8e10-dev", - "validphys": "4.0.6.840+gfcc3e8e10-dev" + "nnpdf": "4.0.6.844+g5a319fc7f-dev", + "validphys": "4.0.6.844+g5a319fc7f-dev" } } \ No newline at end of file diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json b/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json index 15077e500e..2294d90a85 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json @@ -2,32 +2,32 @@ "preprocessing": [ { "fl": "sng", - "smallx": 1.1090877056121826, + "smallx": 1.1090871095657349, "largex": 2.683891534805298, "trainable": true }, { "fl": "g", "smallx": 0.9399998784065247, - "largex": 1.6251798868179321, + "largex": 1.6251764297485352, "trainable": true }, { "fl": "v", "smallx": 0.7499998211860657, - "largex": 1.726711630821228, + "largex": 1.726712942123413, "trainable": true }, { "fl": "v3", - "smallx": 0.2121002972126007, - "largex": 1.3534746170043945, + "smallx": 0.21201345324516296, + "largex": 1.3534246683120728, "trainable": true }, { "fl": "v8", "smallx": 0.7599999308586121, - "largex": 2.390061616897583, + "largex": 2.3900604248046875, "trainable": true }, { @@ -51,45 +51,45 @@ ], "stop_epoch": 1100, "best_epoch": 1099, - "erf_tr": 3.5775744915008545, - "erf_vl": 3.6801669597625732, - "chi2": 2.1422781944274902, + "erf_tr": 3.57742977142334, + "erf_vl": 3.6800172328948975, + "chi2": 2.142242431640625, "pos_state": "POS_VETO", "arc_lengths": [ - 1.320261058152196, - 1.2008326348375713, - 1.0538968228329768, - 5.092393152077501, - 1.0856575181085886 + 1.320264040560382, + 1.2009584734334209, + 1.053896670589243, + 5.093812560494535, + 1.0856600633895122 ], "integrability": [ - 0.029426240362226908, - 0.029426240362226963, - 0.0003942905323124357, - 12.764077186584473, - 0.029728015419096226 + 0.02942626690492056, + 0.02942626690492034, + 0.00039390505207781423, + 12.764078140258789, + 0.029728126246482744 ], "timing": { "walltime": { - "Total": 1296.5483038425446, + "Total": 53.159754037857056, "start": 0.0, - "replica_set": 0.4714009761810303, - "replica_fitted": 1296.5482459068298, - "replica_set_to_replica_fitted": 1296.0768449306488 + "replica_set": 0.5134978294372559, + "replica_fitted": 53.15968608856201, + "replica_set_to_replica_fitted": 52.646188259124756 }, "cputime": { - "Total": 1296.4548610000002, + "Total": 54.924513, "start": 0.0, - "replica_set": 2.022157, - "replica_fitted": 1296.454798, - "replica_set_to_replica_fitted": 1294.4326409999999 + "replica_set": 2.1671650000000007, + "replica_fitted": 54.92444, + "replica_set_to_replica_fitted": 52.75727499999999 } }, "version": { "keras": "2.10.0", "tensorflow": "2.10.0, mkl=False", "numpy": "1.22.4", - "nnpdf": "4.0.6.840+gfcc3e8e10-dev", - "validphys": "4.0.6.840+gfcc3e8e10-dev" + "nnpdf": "4.0.6.844+g5a319fc7f-dev", + "validphys": "4.0.6.844+g5a319fc7f-dev" } } \ No newline at end of file diff --git a/validphys2/src/validphys/photon/compute.py b/validphys2/src/validphys/photon/compute.py index 657e807ba2..02125d5f29 100644 --- a/validphys2/src/validphys/photon/compute.py +++ b/validphys2/src/validphys/photon/compute.py @@ -19,7 +19,6 @@ FIATLUX_DEFAULT = { "apfel": False, - "eps_base": 1e-5, # precision on final integration of double integral. "eps_rel": 1e-1, # extra precision on any single integration. "mum_proton": 2.792847356, # proton magnetic moment, from # http://pdglive.lbl.gov/DataBlock.action?node=S016MM which itself @@ -59,6 +58,13 @@ def __init__(self, theoryid, lux_params, replicas): # This is going to be changed in favor of a bool em_running # in the runcard fiatlux_runcard["mproton"] = theory["MP"] + if "abs_err" in lux_params: + fiatlux_runcard["eps_base"] = lux_params["abs_err"] + log.info(f"Using eps_base from runcard") + else: + fiatlux_runcard["eps_base"] = 1e-5 # precision on final integration of double integral. + log.info(f"Using default eps_base = 1e-5") + self.replicas = replicas # structure functions From 0a926fdf155f2a759b37e196a9c8b487d8c3baed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Wed, 14 Jun 2023 11:43:05 +0200 Subject: [PATCH 08/37] Rename abs_err -> eps_base --- n3fit/runcards/examples/Basic_runcard_qed.yml | 2 +- n3fit/src/n3fit/tests/regressions/quickcard_qed.yml | 2 +- validphys2/src/validphys/photon/compute.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/n3fit/runcards/examples/Basic_runcard_qed.yml b/n3fit/runcards/examples/Basic_runcard_qed.yml index d7ccf7b9c1..9fd98ce1b1 100644 --- a/n3fit/runcards/examples/Basic_runcard_qed.yml +++ b/n3fit/runcards/examples/Basic_runcard_qed.yml @@ -169,4 +169,4 @@ fiatlux: luxset: NNPDF40_nnlo_as_01180 additional_errors: true # should be set to true only for the last iteration luxseed: 1234567890 - abs_err: 1e-2 + eps_base: 1e-2 diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml b/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml index 5995b99d60..84a880c44e 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml @@ -90,4 +90,4 @@ fiatlux: luxset: NNPDF40_nnlo_as_01180 additional_errors: true # should be set to true only for the last iteration luxseed: 1234567890 - abs_err: 1e-2 + eps_base: 1e-2 diff --git a/validphys2/src/validphys/photon/compute.py b/validphys2/src/validphys/photon/compute.py index 02125d5f29..95525c6177 100644 --- a/validphys2/src/validphys/photon/compute.py +++ b/validphys2/src/validphys/photon/compute.py @@ -58,12 +58,12 @@ def __init__(self, theoryid, lux_params, replicas): # This is going to be changed in favor of a bool em_running # in the runcard fiatlux_runcard["mproton"] = theory["MP"] - if "abs_err" in lux_params: - fiatlux_runcard["eps_base"] = lux_params["abs_err"] - log.info(f"Using eps_base from runcard") + if "eps_base" in lux_params: + fiatlux_runcard["eps_base"] = lux_params["eps_base"] + log.warning(f"Using fiatlux parameter eps_base from runcard") else: fiatlux_runcard["eps_base"] = 1e-5 # precision on final integration of double integral. - log.info(f"Using default eps_base = 1e-5") + log.info(f"Using default value for fiatlux parameter eps_base") self.replicas = replicas From 32e1a868c6583e51b9f32f2f186f7c3ffa257e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Wed, 14 Jun 2023 17:46:31 +0200 Subject: [PATCH 09/37] Use .json from linux machine --- .../tests/regressions/quickcard_qed_1.json | 54 +++++++-------- .../tests/regressions/quickcard_qed_2.json | 66 +++++++++---------- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json b/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json index fd7c92d36d..db2b66daf2 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json @@ -20,8 +20,8 @@ }, { "fl": "v3", - "smallx": 0.3061821758747101, - "largex": 2.6243231296539307, + "smallx": 0.3061824142932892, + "largex": 2.624323606491089, "trainable": true }, { @@ -51,45 +51,45 @@ ], "stop_epoch": 1100, "best_epoch": 1099, - "erf_tr": 31.479909896850586, - "erf_vl": 28.421838760375977, - "chi2": 19.602609634399414, + "erf_tr": 31.486101150512695, + "erf_vl": 28.4218692779541, + "chi2": 19.611825942993164, "pos_state": "POS_VETO", "arc_lengths": [ - 1.0355354274955006, - 1.195271539211688, - 1.088986348499315, - 1.335431714155942, - 1.0845053845820272 + 1.035533162554303, + 1.1953713068471692, + 1.0881025884095246, + 1.3414978876721764, + 1.0839843290638607 ], "integrability": [ - 0.0026403537049198844, - 0.00264035370491833, - 0.00025512540650873827, - 3.2896719574928284, - 0.0039052472275233896 + 0.002653829054906187, + 0.002653829054905521, + 0.0002567724250169823, + 3.2896786332130423, + 0.003927801561079747 ], "timing": { "walltime": { - "Total": 53.36410307884216, + "Total": 58.37841296195984, "start": 0.0, - "replica_set": 0.47026801109313965, - "replica_fitted": 53.364020109176636, - "replica_set_to_replica_fitted": 52.893752098083496 + "replica_set": 0.3208029270172119, + "replica_fitted": 58.37802076339722, + "replica_set_to_replica_fitted": 58.057217836380005 }, "cputime": { - "Total": 55.200050000000005, + "Total": 61.517351913999995, "start": 0.0, - "replica_set": 2.1680059999999983, - "replica_fitted": 55.199962, - "replica_set_to_replica_fitted": 53.031956 + "replica_set": 2.813359167999998, + "replica_fitted": 61.516948647, + "replica_set_to_replica_fitted": 58.703589479 } }, "version": { - "keras": "2.10.0", - "tensorflow": "2.10.0, mkl=False", + "keras": "2.11.0", + "tensorflow": "2.11.0, mkl=False", "numpy": "1.22.4", - "nnpdf": "4.0.6.844+g5a319fc7f-dev", - "validphys": "4.0.6.844+g5a319fc7f-dev" + "nnpdf": "4.0.6.846+g0a926fdf1", + "validphys": "4.0.6.846+g0a926fdf1" } } \ No newline at end of file diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json b/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json index 2294d90a85..e737991a66 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json @@ -2,32 +2,32 @@ "preprocessing": [ { "fl": "sng", - "smallx": 1.1090871095657349, + "smallx": 1.1090763807296753, "largex": 2.683891534805298, "trainable": true }, { "fl": "g", "smallx": 0.9399998784065247, - "largex": 1.6251764297485352, + "largex": 1.6250606775283813, "trainable": true }, { "fl": "v", "smallx": 0.7499998211860657, - "largex": 1.726712942123413, + "largex": 1.7267229557037354, "trainable": true }, { "fl": "v3", - "smallx": 0.21201345324516296, - "largex": 1.3534246683120728, + "smallx": 0.21201331913471222, + "largex": 1.3532426357269287, "trainable": true }, { "fl": "v8", - "smallx": 0.7599999308586121, - "largex": 2.3900604248046875, + "smallx": 0.7599998712539673, + "largex": 2.390087127685547, "trainable": true }, { @@ -44,52 +44,52 @@ }, { "fl": "cp", - "smallx": 0.24638593196868896, + "smallx": 0.24638080596923828, "largex": 2.7976953983306885, "trainable": true } ], "stop_epoch": 1100, "best_epoch": 1099, - "erf_tr": 3.57742977142334, - "erf_vl": 3.6800172328948975, - "chi2": 2.142242431640625, + "erf_tr": 3.5809452533721924, + "erf_vl": 3.6826603412628174, + "chi2": 2.141340732574463, "pos_state": "POS_VETO", "arc_lengths": [ - 1.320264040560382, - 1.2009584734334209, - 1.053896670589243, - 5.093812560494535, - 1.0856600633895122 + 1.3194883264768875, + 1.1995146017416334, + 1.054266019685804, + 5.074692492247958, + 1.0689068380364566 ], "integrability": [ - 0.02942626690492056, - 0.02942626690492034, - 0.00039390505207781423, - 12.764078140258789, - 0.029728126246482744 + 0.02917606895789332, + 0.029176068957894374, + 0.0003924771135637162, + 12.764093160629272, + 0.02982003148645135 ], "timing": { "walltime": { - "Total": 53.159754037857056, + "Total": 57.77593541145325, "start": 0.0, - "replica_set": 0.5134978294372559, - "replica_fitted": 53.15968608856201, - "replica_set_to_replica_fitted": 52.646188259124756 + "replica_set": 0.31868839263916016, + "replica_fitted": 57.77560114860535, + "replica_set_to_replica_fitted": 57.45691275596619 }, "cputime": { - "Total": 54.924513, + "Total": 60.771742980000006, "start": 0.0, - "replica_set": 2.1671650000000007, - "replica_fitted": 54.92444, - "replica_set_to_replica_fitted": 52.75727499999999 + "replica_set": 2.6913169609999983, + "replica_fitted": 60.771408723, + "replica_set_to_replica_fitted": 58.080091762 } }, "version": { - "keras": "2.10.0", - "tensorflow": "2.10.0, mkl=False", + "keras": "2.11.0", + "tensorflow": "2.11.0, mkl=False", "numpy": "1.22.4", - "nnpdf": "4.0.6.844+g5a319fc7f-dev", - "validphys": "4.0.6.844+g5a319fc7f-dev" + "nnpdf": "4.0.6.846+g0a926fdf1", + "validphys": "4.0.6.846+g0a926fdf1" } } \ No newline at end of file From e2954aea1f2f346405aaa0f6b3e63baaec87808a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Wed, 14 Jun 2023 22:52:42 +0200 Subject: [PATCH 10/37] Fix very small bug in interp1d --- validphys2/src/validphys/photon/compute.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validphys2/src/validphys/photon/compute.py b/validphys2/src/validphys/photon/compute.py index 95525c6177..b3d44d01d3 100644 --- a/validphys2/src/validphys/photon/compute.py +++ b/validphys2/src/validphys/photon/compute.py @@ -118,7 +118,7 @@ def __init__(self, theoryid, lux_params, replicas): self.lux[replica].PlugStructureFunctions(f2.fxq, fl.fxq, f2lo.fxq) photon_array = self.compute_photon_array(replica) - self.interpolator.append(interp1d(XGRID, photon_array, fill_value=0.0, kind="cubic")) + self.interpolator.append(interp1d(XGRID, photon_array, fill_value="extrapolate", kind="cubic")) self.integral.append(trapezoid(photon_array, XGRID)) def compute_photon_array(self, replica): From 3d1783d79a498f1da1ce41b2f0dba4507e476177 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Thu, 15 Jun 2023 15:51:33 +0200 Subject: [PATCH 11/37] Download theoryIDs --- n3fit/src/n3fit/tests/test_evolven3fit.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/n3fit/src/n3fit/tests/test_evolven3fit.py b/n3fit/src/n3fit/tests/test_evolven3fit.py index 4d0f0c4dda..133895ce6b 100644 --- a/n3fit/src/n3fit/tests/test_evolven3fit.py +++ b/n3fit/src/n3fit/tests/test_evolven3fit.py @@ -12,6 +12,7 @@ from reportengine.compat import yaml from validphys.api import API from validphys.pdfbases import PIDS_DICT +from validphys.core import TheoryIDSpec REGRESSION_FOLDER = pathlib.Path(__file__).with_name("regressions") log = logging.getLogger(__name__) @@ -150,6 +151,9 @@ def test_perform_evolution(tmp_path, fitname): """Test that evolven3fit_new is able to utilize the current eko in the respective theory. In addition checks that the generated .info files are correct """ + theory = API.theoryid(theoryid=int(fitname[-3:])) + # check that nothing went wrong + assert isinstance(theory, TheoryIDSpec) fit = API.fit(fit=fitname) # Move the fit to a temporary folder tmp_fit = tmp_path / fitname From 296e2d412716fff109e1211efec0893a88e4ad9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Fri, 16 Jun 2023 09:51:59 +0200 Subject: [PATCH 12/37] Add whitelines --- n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json | 2 +- n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json | 2 +- validphys2/src/validphys/photon/compute.py | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json b/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json index db2b66daf2..a960f7da9f 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed_1.json @@ -92,4 +92,4 @@ "nnpdf": "4.0.6.846+g0a926fdf1", "validphys": "4.0.6.846+g0a926fdf1" } -} \ No newline at end of file +} diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json b/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json index e737991a66..18e6a605ae 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed_2.json @@ -92,4 +92,4 @@ "nnpdf": "4.0.6.846+g0a926fdf1", "validphys": "4.0.6.846+g0a926fdf1" } -} \ No newline at end of file +} diff --git a/validphys2/src/validphys/photon/compute.py b/validphys2/src/validphys/photon/compute.py index b3d44d01d3..189f801b97 100644 --- a/validphys2/src/validphys/photon/compute.py +++ b/validphys2/src/validphys/photon/compute.py @@ -58,11 +58,13 @@ def __init__(self, theoryid, lux_params, replicas): # This is going to be changed in favor of a bool em_running # in the runcard fiatlux_runcard["mproton"] = theory["MP"] + + # precision on final integration of double integral if "eps_base" in lux_params: fiatlux_runcard["eps_base"] = lux_params["eps_base"] log.warning(f"Using fiatlux parameter eps_base from runcard") else: - fiatlux_runcard["eps_base"] = 1e-5 # precision on final integration of double integral. + fiatlux_runcard["eps_base"] = 1e-5 log.info(f"Using default value for fiatlux parameter eps_base") self.replicas = replicas From 7585eea0267978026de42c113f7cfedec64ca0e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Fri, 16 Jun 2023 10:06:18 +0200 Subject: [PATCH 13/37] Load theoryID from fit --- n3fit/src/n3fit/tests/test_evolven3fit.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/n3fit/src/n3fit/tests/test_evolven3fit.py b/n3fit/src/n3fit/tests/test_evolven3fit.py index 133895ce6b..aeee049ee5 100644 --- a/n3fit/src/n3fit/tests/test_evolven3fit.py +++ b/n3fit/src/n3fit/tests/test_evolven3fit.py @@ -151,10 +151,8 @@ def test_perform_evolution(tmp_path, fitname): """Test that evolven3fit_new is able to utilize the current eko in the respective theory. In addition checks that the generated .info files are correct """ - theory = API.theoryid(theoryid=int(fitname[-3:])) - # check that nothing went wrong - assert isinstance(theory, TheoryIDSpec) fit = API.fit(fit=fitname) + _ = API.theoryid(theoryid=fit.as_input()['theory']['theoryid']) # Move the fit to a temporary folder tmp_fit = tmp_path / fitname shutil.copytree(fit.path, tmp_fit) From 57a5343bdbd7dfe63b46f9151fddd5fc7dae2cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Fri, 16 Jun 2023 10:36:23 +0200 Subject: [PATCH 14/37] Use test theory in test_compute --- .../validphys/tests/photon/test_compute.py | 135 +++--------------- 1 file changed, 21 insertions(+), 114 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index f61b13a6bd..927bcada49 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -1,141 +1,48 @@ from collections import namedtuple from pathlib import Path -import fiatlux import numpy as np from validphys.photon import structure_functions from validphys.photon.compute import Photon, Alpha from validphys.core import PDF as PDFset +from validphys.api import API from ..conftest import PDF from eko.io import EKO +TEST_THEORY = API.theoryid(theoryid=398) -class FakeTheory: - def __init__(self): - self.path = Path("/fake/path/") - - def get_description(self): - return { - "alphaqed": 0.01, - "Qref": 91.2, - "Qedref": 91.2, - "mc": 1.3, - "mb": 4.92, - "mt": 172.0, - "kcThr": 1.0, - "kbThr": 1.0, - "ktThr": 1.0, - "MaxNfAs": 5, - "MaxNfPdf": 5, - "MP": 0.938 - } - - -fiatlux_runcard = { +FIATLUX_RUNCARD = { "luxset": PDFset(PDF), - "additional_errors": False, - "luxseed": 123456789 + "additional_errors": PDFset("LUXqed17_plus_PDF4LHC15_nnlo_100"), + "luxseed": 123456789, + "eps_base": 1e-2, } -photon = namedtuple("photon", ["total", "elastic", "inelastic"]) - - -class FakeFiatlux: - def __init__(self, runcard): - self.runcard = runcard - self.alphaem = None - self.qref = None - self.trash1 = None - self.trash2 = None - self.f2 = None - self.fl = None - self.f2lo = None - self.res = photon(0., 0., 0.) - - def PlugAlphaQED(self, alphaem, qref): - self.alphaem = alphaem - self.qref = qref - - def InsertInelasticSplitQ(self, args): - self.trash1 = args[0] - self.trash2 = args[1] - - def PlugStructureFunctions(self, f2, fl, f2lo): - self.f2 = f2 - self.fl = fl - self.f2lo = f2lo - - def EvaluatePhoton(self, x, q): - return self.res - -class FakeEKO: - def __init__(self, path): - self.path = path - self.mu20 = 100**2 - - def __enter__(self): - return self - - def __exit__(self, exc_type: type, _exc_value, _traceback): - pass - +def test_parameters_init(): -class FakeStructureFunction: - def __init__(self, path, pdfs): - self.path = path - self.pdfs = pdfs - self.q2_max = 1e8 - - def fxq(self): - return 0 - - -class FakeF2LO: - def __init__(self, pdfs, theory): - self.pdfs = pdfs - self.theory = theory - - def fxq(self): - return 0 - - -def test_parameters_init(monkeypatch): - monkeypatch.setattr( - structure_functions, "InterpStructureFunction", FakeStructureFunction - ) - monkeypatch.setattr(structure_functions, "F2LO", FakeF2LO) - monkeypatch.setattr(fiatlux, "FiatLux", FakeFiatlux) - monkeypatch.setattr(Photon, "compute_photon_array", lambda *args: np.zeros(196)) - monkeypatch.setattr(EKO, "read", FakeEKO) - - photon = Photon(FakeTheory(), fiatlux_runcard, [1, 2, 3]) - alpha = Alpha(FakeTheory().get_description()) + photon = Photon(TEST_THEORY, FIATLUX_RUNCARD, [1, 2, 3]) + alpha = Alpha(TEST_THEORY.get_description()) np.testing.assert_equal(photon.replicas, [1, 2, 3]) - np.testing.assert_equal(photon.luxpdfset._name, fiatlux_runcard["luxset"].name) - np.testing.assert_equal(photon.additional_errors, fiatlux_runcard["additional_errors"]) - np.testing.assert_equal(photon.luxseed, fiatlux_runcard["luxseed"]) + np.testing.assert_equal(photon.luxpdfset._name, FIATLUX_RUNCARD["luxset"].name) + np.testing.assert_equal(photon.additional_errors._name, "LUXqed17_plus_PDF4LHC15_nnlo_100") + np.testing.assert_equal(photon.luxseed, FIATLUX_RUNCARD["luxseed"]) + np.testing.assert_equal(photon.path_to_eko_photon, TEST_THEORY.path / "eko_photon.tar") + np.testing.assert_equal(photon.q_in, 100.) np.testing.assert_almost_equal( - alpha.alpha_em_ref, FakeTheory().get_description()["alphaqed"] + alpha.alpha_em_ref, TEST_THEORY.get_description()["alphaqed"] ) def test_masses_init(): - alpha = Alpha(FakeTheory().get_description()) + alpha = Alpha(TEST_THEORY.get_description()) np.testing.assert_equal(alpha.thresh_t, np.inf) np.testing.assert_almost_equal(alpha.thresh_b, 4.92) - np.testing.assert_almost_equal(alpha.thresh_c, 1.3) - -def test_set_thresholds_alpha_em(monkeypatch): - monkeypatch.setattr( - structure_functions, "InterpStructureFunction", FakeStructureFunction - ) - monkeypatch.setattr(structure_functions, "F2LO", FakeF2LO) + np.testing.assert_almost_equal(alpha.thresh_c, 1.51) - monkeypatch.setattr(fiatlux, "FiatLux", FakeFiatlux) - monkeypatch.setattr(Photon, "compute_photon_array", lambda *args: np.zeros(196)) +def test_set_thresholds_alpha_em(): - alpha = Alpha(FakeTheory().get_description()) + alpha = Alpha(TEST_THEORY.get_description()) np.testing.assert_almost_equal(alpha.thresh[5], 91.2) np.testing.assert_almost_equal(alpha.thresh[4], 4.92) @@ -152,7 +59,7 @@ def test_set_thresholds_alpha_em(monkeypatch): np.testing.assert_equal(len(alpha.thresh), 3) def test_betas(): - alpha = Alpha(FakeTheory().get_description()) + alpha = Alpha(TEST_THEORY.get_description()) vec_beta0 = [ -0.5305164769729844, -0.6719875374991137, @@ -167,4 +74,4 @@ def test_betas(): ] for nf in range(3, 6 + 1): np.testing.assert_allclose(alpha.beta0[nf], vec_beta0[nf - 3], rtol=1e-7) - np.testing.assert_allclose(alpha.b1[nf], vec_b1[nf - 3], rtol=1e-7) + np.testing.assert_allclose(alpha.b1[nf], vec_b1[nf - 3], rtol=1e-7) \ No newline at end of file From 077e2ed75e4a360d2dbd5ba5c8bf65fa8a8fe2e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Fri, 16 Jun 2023 10:38:33 +0200 Subject: [PATCH 15/37] Fix charm mass in test --- validphys2/src/validphys/tests/photon/test_compute.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index 927bcada49..7a25e399c2 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -46,14 +46,14 @@ def test_set_thresholds_alpha_em(): np.testing.assert_almost_equal(alpha.thresh[5], 91.2) np.testing.assert_almost_equal(alpha.thresh[4], 4.92) - np.testing.assert_almost_equal(alpha.thresh[3], 1.3) + np.testing.assert_almost_equal(alpha.thresh[3], 51) np.testing.assert_almost_equal(alpha.alpha_thresh[5], 0.01) np.testing.assert_almost_equal( alpha.alpha_thresh[4], alpha.alpha_em_fixed_flavor(4.92, 0.01, 91.2, 5) ) np.testing.assert_almost_equal( alpha.alpha_thresh[3], - alpha.alpha_em_fixed_flavor(1.3, alpha.alpha_thresh[4], 4.92, 4), + alpha.alpha_em_fixed_flavor(1.51, alpha.alpha_thresh[4], 4.92, 4), ) np.testing.assert_equal(len(alpha.alpha_thresh), 3) np.testing.assert_equal(len(alpha.thresh), 3) From 388be7b9fe05cad4703cd43b62104d242c61cad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Fri, 16 Jun 2023 10:41:06 +0200 Subject: [PATCH 16/37] speed up photon computation in test --- validphys2/src/validphys/tests/photon/test_compute.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index 7a25e399c2..4f876ccb06 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -21,7 +21,12 @@ def test_parameters_init(): - photon = Photon(TEST_THEORY, FIATLUX_RUNCARD, [1, 2, 3]) + fiatlux_runcard = FIATLUX_RUNCARD.copy() + + # we are not testing the photon here so we make it faster + fiatlux_runcard['eps_base'] = 1e-1 + + photon = Photon(TEST_THEORY, fiatlux_runcard, [1, 2, 3]) alpha = Alpha(TEST_THEORY.get_description()) np.testing.assert_equal(photon.replicas, [1, 2, 3]) From ddc57d34893c8ad75ebd92f27f303994f787b1ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Fri, 16 Jun 2023 10:43:27 +0200 Subject: [PATCH 17/37] Fix charm mass in test again --- validphys2/src/validphys/tests/photon/test_compute.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index 4f876ccb06..dcf6102d96 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -51,7 +51,7 @@ def test_set_thresholds_alpha_em(): np.testing.assert_almost_equal(alpha.thresh[5], 91.2) np.testing.assert_almost_equal(alpha.thresh[4], 4.92) - np.testing.assert_almost_equal(alpha.thresh[3], 51) + np.testing.assert_almost_equal(alpha.thresh[3], 1.51) np.testing.assert_almost_equal(alpha.alpha_thresh[5], 0.01) np.testing.assert_almost_equal( alpha.alpha_thresh[4], alpha.alpha_em_fixed_flavor(4.92, 0.01, 91.2, 5) From dba334a0da0e92a8714b3e5aa33d515fc6c4d824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Fri, 16 Jun 2023 10:47:17 +0200 Subject: [PATCH 18/37] Fix testing of alpha --- .../src/validphys/tests/photon/test_compute.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index dcf6102d96..2a27bbf63a 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -47,18 +47,20 @@ def test_masses_init(): def test_set_thresholds_alpha_em(): - alpha = Alpha(TEST_THEORY.get_description()) + theory = TEST_THEORY.get_description() + + alpha = Alpha(theory) - np.testing.assert_almost_equal(alpha.thresh[5], 91.2) - np.testing.assert_almost_equal(alpha.thresh[4], 4.92) - np.testing.assert_almost_equal(alpha.thresh[3], 1.51) - np.testing.assert_almost_equal(alpha.alpha_thresh[5], 0.01) + np.testing.assert_almost_equal(alpha.thresh[5], theory["Qedref"]) + np.testing.assert_almost_equal(alpha.thresh[4], theory["mb"]) + np.testing.assert_almost_equal(alpha.thresh[3], theory["mc"]) + np.testing.assert_almost_equal(alpha.alpha_thresh[5], theory["alphaqed"]) np.testing.assert_almost_equal( - alpha.alpha_thresh[4], alpha.alpha_em_fixed_flavor(4.92, 0.01, 91.2, 5) + alpha.alpha_thresh[4], alpha.alpha_em_fixed_flavor(theory["mb"], theory["alphaqed"], theory["Qedref"], 5) ) np.testing.assert_almost_equal( alpha.alpha_thresh[3], - alpha.alpha_em_fixed_flavor(1.51, alpha.alpha_thresh[4], 4.92, 4), + alpha.alpha_em_fixed_flavor(theory["mb"], alpha.alpha_thresh[4], theory["mb"], 4), ) np.testing.assert_equal(len(alpha.alpha_thresh), 3) np.testing.assert_equal(len(alpha.thresh), 3) From 3fa81ba8dbd478b5a32344305b8cd3f74f233d38 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 10:51:20 +0200 Subject: [PATCH 19/37] Fix test_compute --- validphys2/src/validphys/tests/photon/test_compute.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index 2a27bbf63a..93aef28c04 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -31,7 +31,7 @@ def test_parameters_init(): np.testing.assert_equal(photon.replicas, [1, 2, 3]) np.testing.assert_equal(photon.luxpdfset._name, FIATLUX_RUNCARD["luxset"].name) - np.testing.assert_equal(photon.additional_errors._name, "LUXqed17_plus_PDF4LHC15_nnlo_100") + np.testing.assert_equal(photon.additional_errors.name, "LUXqed17_plus_PDF4LHC15_nnlo_100") np.testing.assert_equal(photon.luxseed, FIATLUX_RUNCARD["luxseed"]) np.testing.assert_equal(photon.path_to_eko_photon, TEST_THEORY.path / "eko_photon.tar") np.testing.assert_equal(photon.q_in, 100.) @@ -60,7 +60,7 @@ def test_set_thresholds_alpha_em(): ) np.testing.assert_almost_equal( alpha.alpha_thresh[3], - alpha.alpha_em_fixed_flavor(theory["mb"], alpha.alpha_thresh[4], theory["mb"], 4), + alpha.alpha_em_fixed_flavor(theory["mc"], alpha.alpha_thresh[4], theory["mb"], 4), ) np.testing.assert_equal(len(alpha.alpha_thresh), 3) np.testing.assert_equal(len(alpha.thresh), 3) From bb3a1fdc86db5c20d79b4286a4cedd3a59ad4297 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 12:13:51 +0200 Subject: [PATCH 20/37] Add test on photon computation --- .../validphys/tests/photon/test_compute.py | 119 ++++++++++++++++-- 1 file changed, 107 insertions(+), 12 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index 93aef28c04..12a2e37e95 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -1,14 +1,19 @@ from collections import namedtuple from pathlib import Path +import tempfile +import fiatlux import numpy as np -from validphys.photon import structure_functions -from validphys.photon.compute import Photon, Alpha -from validphys.core import PDF as PDFset +import yaml + +from eko.io import EKO +from n3fit.io.writer import XGRID from validphys.api import API +from validphys.core import PDF as PDFset +from validphys.photon import structure_functions as sf +from validphys.photon.compute import Alpha, Photon from ..conftest import PDF -from eko.io import EKO TEST_THEORY = API.theoryid(theoryid=398) @@ -19,8 +24,40 @@ "eps_base": 1e-2, } -def test_parameters_init(): +FIATLUX_DEFAULT = { + "apfel": False, + "qed_running": True, + "q2_max": 1e8, + "eps_base": 1e-2, + "eps_rel": 1e-1, # extra precision on any single integration. + "mproton": 0.938, + "mum_proton": 2.792847356, # proton magnetic moment, from + # http://pdglive.lbl.gov/DataBlock.action?node=S016MM which itself + # gets it from arXiv:1203.5425 (CODATA) + # the elastic param type, options: + # dipole + # A1_world_spline + # A1_world_pol_spline + "elastic_param": "A1_world_pol_spline", + "elastic_electric_rescale": 1, + "elastic_magnetic_rescale": 1, + # the inelastic param type, options: + "inelastic_param": "LHAPDF_Hermes_ALLM_CLAS", # Hermes_ALLM_CLAS, LHAPDF_Hermes_ALLM_CLAS + "rescale_r_twist4": 0, + "rescale_r": 1, + "allm_limits": 0, + "rescale_non_resonance": 1, + "rescale_resonance": 1, + "use_mu2_as_upper_limit": False, + "q2min_inel_override": 0.0, + "q2max_inel_override": 1e300, + "lhapdf_transition_q2": 9, + # general + "verbose": False, +} + +def test_parameters_init(): fiatlux_runcard = FIATLUX_RUNCARD.copy() # we are not testing the photon here so we make it faster @@ -34,10 +71,9 @@ def test_parameters_init(): np.testing.assert_equal(photon.additional_errors.name, "LUXqed17_plus_PDF4LHC15_nnlo_100") np.testing.assert_equal(photon.luxseed, FIATLUX_RUNCARD["luxseed"]) np.testing.assert_equal(photon.path_to_eko_photon, TEST_THEORY.path / "eko_photon.tar") - np.testing.assert_equal(photon.q_in, 100.) - np.testing.assert_almost_equal( - alpha.alpha_em_ref, TEST_THEORY.get_description()["alphaqed"] - ) + np.testing.assert_equal(photon.q_in, 100.0) + np.testing.assert_almost_equal(alpha.alpha_em_ref, TEST_THEORY.get_description()["alphaqed"]) + def test_masses_init(): alpha = Alpha(TEST_THEORY.get_description()) @@ -45,8 +81,8 @@ def test_masses_init(): np.testing.assert_almost_equal(alpha.thresh_b, 4.92) np.testing.assert_almost_equal(alpha.thresh_c, 1.51) -def test_set_thresholds_alpha_em(): +def test_set_thresholds_alpha_em(): theory = TEST_THEORY.get_description() alpha = Alpha(theory) @@ -56,7 +92,8 @@ def test_set_thresholds_alpha_em(): np.testing.assert_almost_equal(alpha.thresh[3], theory["mc"]) np.testing.assert_almost_equal(alpha.alpha_thresh[5], theory["alphaqed"]) np.testing.assert_almost_equal( - alpha.alpha_thresh[4], alpha.alpha_em_fixed_flavor(theory["mb"], theory["alphaqed"], theory["Qedref"], 5) + alpha.alpha_thresh[4], + alpha.alpha_em_fixed_flavor(theory["mb"], theory["alphaqed"], theory["Qedref"], 5), ) np.testing.assert_almost_equal( alpha.alpha_thresh[3], @@ -65,6 +102,7 @@ def test_set_thresholds_alpha_em(): np.testing.assert_equal(len(alpha.alpha_thresh), 3) np.testing.assert_equal(len(alpha.thresh), 3) + def test_betas(): alpha = Alpha(TEST_THEORY.get_description()) vec_beta0 = [ @@ -81,4 +119,61 @@ def test_betas(): ] for nf in range(3, 6 + 1): np.testing.assert_allclose(alpha.beta0[nf], vec_beta0[nf - 3], rtol=1e-7) - np.testing.assert_allclose(alpha.b1[nf], vec_b1[nf - 3], rtol=1e-7) \ No newline at end of file + np.testing.assert_allclose(alpha.b1[nf], vec_b1[nf - 3], rtol=1e-7) + + +def test_photon(): + fiatlux_runcard = FIATLUX_RUNCARD.copy() + fiatlux_runcard["additional_errors"] = False + theory = TEST_THEORY.get_description() + + for replica in [1, 2, 3]: + photon = Photon(TEST_THEORY, fiatlux_runcard, [replica]) + + # set up fiatlux + path_to_F2 = TEST_THEORY.path / "fastkernel/fiatlux_dis_F2.pineappl.lz4" + path_to_FL = TEST_THEORY.path / "fastkernel/fiatlux_dis_FL.pineappl.lz4" + pdfs = FIATLUX_RUNCARD["luxset"].load() + f2 = sf.InterpStructureFunction(path_to_F2, pdfs.members[replica]) + fl = sf.InterpStructureFunction(path_to_FL, pdfs.members[replica]) + f2lo = sf.F2LO(pdfs.members[replica], theory) + with tempfile.NamedTemporaryFile(mode="w") as tmp: + with tmp.file as tmp_file: + tmp_file.write(yaml.dump(FIATLUX_DEFAULT)) + lux = fiatlux.FiatLux(tmp.name) + + alpha = Alpha(theory) + + lux.PlugAlphaQED(alpha.alpha_em, alpha.qref) + lux.InsertInelasticSplitQ( + [ + theory["mb"], + 1e100, + ] + ) + lux.PlugStructureFunctions(f2.fxq, fl.fxq, f2lo.fxq) + photon_fiatlux_qin = np.array([lux.EvaluatePhoton(x, 100**2).total for x in XGRID]) + path_to_eko_photon = TEST_THEORY.path / "eko_photon.tar" + photon_fiatlux_qin /= XGRID + with EKO.read(path_to_eko_photon) as eko: + # construct PDFs + pdfs_init = np.zeros((len(eko.bases.inputpids), len(XGRID))) + for j, pid in enumerate(eko.bases.inputpids): + if pid == 22: + pdfs_init[j] = photon_fiatlux_qin + ph_id = j + else: + if pid not in pdfs.flavors: + continue + pdfs_init[j] = np.array([pdfs.xfxQ(x, 100, replica, pid) / x for x in XGRID]) + + # Apply EKO to PDFs + for _, elem in eko.items(): + pdfs_final = np.einsum("ajbk,bk", elem.operator, pdfs_init) + + photon_Q0 = pdfs_final[ph_id] + photon_fiatlux = XGRID * photon_Q0 + + photon_validphys = photon(XGRID[np.newaxis, :, np.newaxis])[0][0, :, 0] + + np.testing.assert_allclose(photon_fiatlux, photon_validphys, rtol=1e-7) From 3901ba54d8d229a44b15f694a73c0d4adedf7de5 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 12:14:32 +0200 Subject: [PATCH 21/37] Remove unused dependencies --- validphys2/src/validphys/tests/photon/test_compute.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index 12a2e37e95..958646a408 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -1,5 +1,3 @@ -from collections import namedtuple -from pathlib import Path import tempfile import fiatlux From f3de6b07cc90146b99797087694a5e990d081371 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 12:25:17 +0200 Subject: [PATCH 22/37] Polish test --- .../validphys/tests/photon/test_compute.py | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index 958646a408..85573120bf 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -24,11 +24,7 @@ FIATLUX_DEFAULT = { "apfel": False, - "qed_running": True, - "q2_max": 1e8, - "eps_base": 1e-2, "eps_rel": 1e-1, # extra precision on any single integration. - "mproton": 0.938, "mum_proton": 2.792847356, # proton magnetic moment, from # http://pdglive.lbl.gov/DataBlock.action?node=S016MM which itself # gets it from arXiv:1203.5425 (CODATA) @@ -135,6 +131,15 @@ def test_photon(): f2 = sf.InterpStructureFunction(path_to_F2, pdfs.members[replica]) fl = sf.InterpStructureFunction(path_to_FL, pdfs.members[replica]) f2lo = sf.F2LO(pdfs.members[replica], theory) + + # runcard + fiatlux_default = FIATLUX_DEFAULT.copy() + fiatlux_default['mproton'] = theory['MP'] + fiatlux_default["qed_running"] = bool(np.isclose(theory["Qedref"], theory["Qref"])) + fiatlux_default["q2_max"] = float(f2.q2_max) + fiatlux_default["eps_base"] = FIATLUX_RUNCARD["eps_base"] + + # load fiatlux with tempfile.NamedTemporaryFile(mode="w") as tmp: with tmp.file as tmp_file: tmp_file.write(yaml.dump(FIATLUX_DEFAULT)) @@ -145,15 +150,15 @@ def test_photon(): lux.PlugAlphaQED(alpha.alpha_em, alpha.qref) lux.InsertInelasticSplitQ( [ - theory["mb"], - 1e100, + theory["kbThr"] * theory["mb"], + theory["ktThr"] * theory["mt"] if theory["MaxNfPdf"] == 6 else 1e100, ] ) lux.PlugStructureFunctions(f2.fxq, fl.fxq, f2lo.fxq) - photon_fiatlux_qin = np.array([lux.EvaluatePhoton(x, 100**2).total for x in XGRID]) path_to_eko_photon = TEST_THEORY.path / "eko_photon.tar" - photon_fiatlux_qin /= XGRID with EKO.read(path_to_eko_photon) as eko: + photon_fiatlux_qin = np.array([lux.EvaluatePhoton(x, eko.mu20).total for x in XGRID]) + photon_fiatlux_qin /= XGRID # construct PDFs pdfs_init = np.zeros((len(eko.bases.inputpids), len(XGRID))) for j, pid in enumerate(eko.bases.inputpids): @@ -163,7 +168,9 @@ def test_photon(): else: if pid not in pdfs.flavors: continue - pdfs_init[j] = np.array([pdfs.xfxQ(x, 100, replica, pid) / x for x in XGRID]) + pdfs_init[j] = np.array( + [pdfs.xfxQ(x, np.sqrt(eko.mu20), replica, pid) / x for x in XGRID] + ) # Apply EKO to PDFs for _, elem in eko.items(): From 7550e2d2881f01abc4ce8398c4653f9a9e2f3a82 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 12:26:46 +0200 Subject: [PATCH 23/37] Polish test again --- validphys2/src/validphys/tests/photon/test_compute.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index 85573120bf..4b3275f067 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -70,10 +70,11 @@ def test_parameters_init(): def test_masses_init(): - alpha = Alpha(TEST_THEORY.get_description()) + theory = TEST_THEORY.get_description() + alpha = Alpha(theory) np.testing.assert_equal(alpha.thresh_t, np.inf) - np.testing.assert_almost_equal(alpha.thresh_b, 4.92) - np.testing.assert_almost_equal(alpha.thresh_c, 1.51) + np.testing.assert_almost_equal(alpha.thresh_b, theory["mb"]) + np.testing.assert_almost_equal(alpha.thresh_c, theory["mc"]) def test_set_thresholds_alpha_em(): From 98d919fa75ddd9a77bded83e58b79bb7881c76ae Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 13:11:33 +0200 Subject: [PATCH 24/37] Pass test theory to test_structurefunctions.py --- .../validphys/tests/photon/test_compute.py | 2 +- .../tests/photon/test_structurefunctions.py | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index 4b3275f067..f875f03ce9 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -19,7 +19,7 @@ "luxset": PDFset(PDF), "additional_errors": PDFset("LUXqed17_plus_PDF4LHC15_nnlo_100"), "luxseed": 123456789, - "eps_base": 1e-2, + "eps_base": 1e-2, # using low precision to speed up tests } FIATLUX_DEFAULT = { diff --git a/validphys2/src/validphys/tests/photon/test_structurefunctions.py b/validphys2/src/validphys/tests/photon/test_structurefunctions.py index 984eb2eecd..c2a8dddfff 100644 --- a/validphys2/src/validphys/tests/photon/test_structurefunctions.py +++ b/validphys2/src/validphys/tests/photon/test_structurefunctions.py @@ -2,7 +2,21 @@ import pineappl import validphys.photon.structure_functions as sf from validphys.lhapdfset import LHAPDFSet +from validphys.api import API +from ..conftest import PDF +from validphys.core import PDF as PDFset +TEST_THEORY = API.theoryid(theoryid=398) +NNPDF40 = PDFset(PDF) + +class ZeroPdfs: + def xfxQ(self, x, Q): + res = {} + for i in range(1, 6 + 1): + res[i] = res[-i] = 0.0 + return res + +TEST_THEORY = API.theoryid(theoryid=398) class ZeroPdfs: def xfxQ(self, x, Q): @@ -125,3 +139,20 @@ def test_F2(monkeypatch): for x in np.geomspace(1e-4, 1.0, 10): for Q in np.geomspace(10, 1000000, 10): np.testing.assert_allclose(structurefunc.fxq(x, Q), 0.0, rtol=1e-5) + +def test_interpolation_grid(): + pdfs = NNPDF40.load() + replica = 1 + for channel in ["F2", "FL"]: + tmp = "fastkernel/fiatlux_dis_" + channel + ".pineappl.lz4" + path_to_fktable = TEST_THEORY.path / tmp + fktable = pineappl.fk_table.FkTable.read(path_to_fktable) + x = np.unique(fktable.bin_left(1)) + q2 = np.unique(fktable.bin_left(0)) + predictions = fktable.convolute_with_one(2212, pdfs.members[replica].xfxQ2) + grid2D = predictions.reshape(len(x), len(q2)) + + struct_func = sf.InterpStructureFunction(path_to_fktable, pdfs.members[replica]) + for i,x_ in enumerate(x): + for j, q2_ in enumerate(q2): + np.testing.assert_allclose(struct_func.fxq(x_, np.sqrt(q2_)), grid2D[i,j], rtol=1e-5) From 4b0ed9c705a011d34d495b20331e49f4518fa0f3 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 13:12:32 +0200 Subject: [PATCH 25/37] Run isort and black on test_structurefunctions.py --- .../tests/photon/test_structurefunctions.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_structurefunctions.py b/validphys2/src/validphys/tests/photon/test_structurefunctions.py index c2a8dddfff..7c9929327f 100644 --- a/validphys2/src/validphys/tests/photon/test_structurefunctions.py +++ b/validphys2/src/validphys/tests/photon/test_structurefunctions.py @@ -1,14 +1,17 @@ import numpy as np import pineappl -import validphys.photon.structure_functions as sf -from validphys.lhapdfset import LHAPDFSet + from validphys.api import API -from ..conftest import PDF from validphys.core import PDF as PDFset +from validphys.lhapdfset import LHAPDFSet +import validphys.photon.structure_functions as sf + +from ..conftest import PDF TEST_THEORY = API.theoryid(theoryid=398) NNPDF40 = PDFset(PDF) + class ZeroPdfs: def xfxQ(self, x, Q): res = {} @@ -16,8 +19,10 @@ def xfxQ(self, x, Q): res[i] = res[-i] = 0.0 return res + TEST_THEORY = API.theoryid(theoryid=398) + class ZeroPdfs: def xfxQ(self, x, Q): res = {} @@ -27,7 +32,6 @@ def xfxQ(self, x, Q): def test_zero_pdfs(): - pdfs = ZeroPdfs() fake_theory = { @@ -140,6 +144,7 @@ def test_F2(monkeypatch): for Q in np.geomspace(10, 1000000, 10): np.testing.assert_allclose(structurefunc.fxq(x, Q), 0.0, rtol=1e-5) + def test_interpolation_grid(): pdfs = NNPDF40.load() replica = 1 @@ -153,6 +158,8 @@ def test_interpolation_grid(): grid2D = predictions.reshape(len(x), len(q2)) struct_func = sf.InterpStructureFunction(path_to_fktable, pdfs.members[replica]) - for i,x_ in enumerate(x): + for i, x_ in enumerate(x): for j, q2_ in enumerate(q2): - np.testing.assert_allclose(struct_func.fxq(x_, np.sqrt(q2_)), grid2D[i,j], rtol=1e-5) + np.testing.assert_allclose( + struct_func.fxq(x_, np.sqrt(q2_)), grid2D[i, j], rtol=1e-5 + ) From 5ede6f4ed07ff34d6e1f31dc396a7bbe84f5d965 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 13:21:11 +0200 Subject: [PATCH 26/37] Test init parameters of test_structurefunctions.py --- .../tests/photon/test_structurefunctions.py | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_structurefunctions.py b/validphys2/src/validphys/tests/photon/test_structurefunctions.py index 7c9929327f..12944a23d4 100644 --- a/validphys2/src/validphys/tests/photon/test_structurefunctions.py +++ b/validphys2/src/validphys/tests/photon/test_structurefunctions.py @@ -20,9 +20,6 @@ def xfxQ(self, x, Q): return res -TEST_THEORY = API.theoryid(theoryid=398) - - class ZeroPdfs: def xfxQ(self, x, Q): res = {} @@ -144,22 +141,37 @@ def test_F2(monkeypatch): for Q in np.geomspace(10, 1000000, 10): np.testing.assert_allclose(structurefunc.fxq(x, Q), 0.0, rtol=1e-5) - -def test_interpolation_grid(): +def test_params(): pdfs = NNPDF40.load() replica = 1 + theory = TEST_THEORY.get_description() for channel in ["F2", "FL"]: tmp = "fastkernel/fiatlux_dis_" + channel + ".pineappl.lz4" path_to_fktable = TEST_THEORY.path / tmp - fktable = pineappl.fk_table.FkTable.read(path_to_fktable) - x = np.unique(fktable.bin_left(1)) - q2 = np.unique(fktable.bin_left(0)) - predictions = fktable.convolute_with_one(2212, pdfs.members[replica].xfxQ2) - grid2D = predictions.reshape(len(x), len(q2)) - struct_func = sf.InterpStructureFunction(path_to_fktable, pdfs.members[replica]) - for i, x_ in enumerate(x): - for j, q2_ in enumerate(q2): - np.testing.assert_allclose( - struct_func.fxq(x_, np.sqrt(q2_)), grid2D[i, j], rtol=1e-5 - ) + np.testing.assert_allclose(struct_func.q2_max, 1e8) + f2lo = sf.F2LO(pdfs.members[replica], theory) + np.testing.assert_allclose(f2lo.thresh_c, theory["mc"]) + np.testing.assert_allclose(f2lo.thresh_b, theory["mb"]) + np.testing.assert_allclose(f2lo.thresh_t, np.inf) + + + +def test_interpolation_grid(): + pdfs = NNPDF40.load() + for replica in [1, 2, 3]: + for channel in ["F2", "FL"]: + tmp = "fastkernel/fiatlux_dis_" + channel + ".pineappl.lz4" + path_to_fktable = TEST_THEORY.path / tmp + fktable = pineappl.fk_table.FkTable.read(path_to_fktable) + x = np.unique(fktable.bin_left(1)) + q2 = np.unique(fktable.bin_left(0)) + predictions = fktable.convolute_with_one(2212, pdfs.members[replica].xfxQ2) + grid2D = predictions.reshape(len(x), len(q2)) + + struct_func = sf.InterpStructureFunction(path_to_fktable, pdfs.members[replica]) + for i, x_ in enumerate(x): + for j, q2_ in enumerate(q2): + np.testing.assert_allclose( + struct_func.fxq(x_, np.sqrt(q2_)), grid2D[i, j], rtol=1e-5 + ) From 52e91306085dab2490f419a44c0ee60bc44c4f99 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 13:21:51 +0200 Subject: [PATCH 27/37] Run isort and black on test_structurefunctions.py --- .../src/validphys/tests/photon/test_structurefunctions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validphys2/src/validphys/tests/photon/test_structurefunctions.py b/validphys2/src/validphys/tests/photon/test_structurefunctions.py index 12944a23d4..df1edf6faf 100644 --- a/validphys2/src/validphys/tests/photon/test_structurefunctions.py +++ b/validphys2/src/validphys/tests/photon/test_structurefunctions.py @@ -141,6 +141,7 @@ def test_F2(monkeypatch): for Q in np.geomspace(10, 1000000, 10): np.testing.assert_allclose(structurefunc.fxq(x, Q), 0.0, rtol=1e-5) + def test_params(): pdfs = NNPDF40.load() replica = 1 @@ -156,7 +157,6 @@ def test_params(): np.testing.assert_allclose(f2lo.thresh_t, np.inf) - def test_interpolation_grid(): pdfs = NNPDF40.load() for replica in [1, 2, 3]: From 370d0dd72a6c3d95def92e61a476fb94f8d439c6 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 14:34:57 +0200 Subject: [PATCH 28/37] Use API to install pdfset --- validphys2/src/validphys/tests/photon/test_compute.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index f875f03ce9..2b217bd448 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -17,7 +17,7 @@ FIATLUX_RUNCARD = { "luxset": PDFset(PDF), - "additional_errors": PDFset("LUXqed17_plus_PDF4LHC15_nnlo_100"), + "additional_errors": API.pdf(pdf='LUXqed17_plus_PDF4LHC15_nnlo_100'), "luxseed": 123456789, "eps_base": 1e-2, # using low precision to speed up tests } From b97450d097a14ba2409ebd622924bc2ee6141bcd Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 15:01:33 +0200 Subject: [PATCH 29/37] Refactor test_structurefunctions.py and add docstrings --- .../validphys/tests/photon/test_compute.py | 10 +- .../tests/photon/test_structurefunctions.py | 114 ++++-------------- 2 files changed, 33 insertions(+), 91 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index 2b217bd448..00da494130 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -52,13 +52,13 @@ def test_parameters_init(): + "test initailization of the parameters from Photon class" fiatlux_runcard = FIATLUX_RUNCARD.copy() # we are not testing the photon here so we make it faster fiatlux_runcard['eps_base'] = 1e-1 photon = Photon(TEST_THEORY, fiatlux_runcard, [1, 2, 3]) - alpha = Alpha(TEST_THEORY.get_description()) np.testing.assert_equal(photon.replicas, [1, 2, 3]) np.testing.assert_equal(photon.luxpdfset._name, FIATLUX_RUNCARD["luxset"].name) @@ -66,10 +66,10 @@ def test_parameters_init(): np.testing.assert_equal(photon.luxseed, FIATLUX_RUNCARD["luxseed"]) np.testing.assert_equal(photon.path_to_eko_photon, TEST_THEORY.path / "eko_photon.tar") np.testing.assert_equal(photon.q_in, 100.0) - np.testing.assert_almost_equal(alpha.alpha_em_ref, TEST_THEORY.get_description()["alphaqed"]) def test_masses_init(): + "test thresholds in Alpha class" theory = TEST_THEORY.get_description() alpha = Alpha(theory) np.testing.assert_equal(alpha.thresh_t, np.inf) @@ -78,10 +78,12 @@ def test_masses_init(): def test_set_thresholds_alpha_em(): + "test value of alpha_em at threshold values" theory = TEST_THEORY.get_description() alpha = Alpha(theory) + np.testing.assert_almost_equal(alpha.alpha_em_ref, theory["alphaqed"]) np.testing.assert_almost_equal(alpha.thresh[5], theory["Qedref"]) np.testing.assert_almost_equal(alpha.thresh[4], theory["mb"]) np.testing.assert_almost_equal(alpha.thresh[3], theory["mc"]) @@ -99,6 +101,7 @@ def test_set_thresholds_alpha_em(): def test_betas(): + "test betas for different nf" alpha = Alpha(TEST_THEORY.get_description()) vec_beta0 = [ -0.5305164769729844, @@ -118,6 +121,9 @@ def test_betas(): def test_photon(): + """test that photon coming out of Photon interpolator matches the photon array + for XGRID points + """ fiatlux_runcard = FIATLUX_RUNCARD.copy() fiatlux_runcard["additional_errors"] = False theory = TEST_THEORY.get_description() diff --git a/validphys2/src/validphys/tests/photon/test_structurefunctions.py b/validphys2/src/validphys/tests/photon/test_structurefunctions.py index df1edf6faf..14f6b227bf 100644 --- a/validphys2/src/validphys/tests/photon/test_structurefunctions.py +++ b/validphys2/src/validphys/tests/photon/test_structurefunctions.py @@ -17,42 +17,12 @@ def xfxQ(self, x, Q): res = {} for i in range(1, 6 + 1): res[i] = res[-i] = 0.0 + res[21] = 0.0 + res[22] = 0.0 return res - - -class ZeroPdfs: - def xfxQ(self, x, Q): - res = {} - for i in range(1, 6 + 1): - res[i] = res[-i] = 0.0 - return res - - -def test_zero_pdfs(): - pdfs = ZeroPdfs() - - fake_theory = { - "mc": 1.3, - "mb": 5.0, - "mt": 172.0, - "kcThr": 1.0, - "kbThr": 1.0, - "ktThr": 1.0, - "MaxNfPdf": 5, - } - - f2lo = sf.F2LO(pdfs, fake_theory) - - np.testing.assert_equal(f2lo.thresh_t, np.inf) - - for x in np.geomspace(1e-4, 1.0, 10): - for Q in np.geomspace(10, 1000000, 10): - np.testing.assert_allclose(f2lo.fxq(x, Q), 0.0) - - -class FakeSet: - def get_entry(self, string): - return 0 + + def xfxQ2(self, i, x, Q2): + return self.xfxQ(x, np.sqrt(Q2))[i] class ZeroFKTable: @@ -73,76 +43,41 @@ def convolute_with_one(self, pdgid, xfxQ2): return np.zeros((10, 10)) -class OnePdf: - def __init__(self): - self.ao = 1 - - def xfxQ(self, x, Q): - return 1.0 - - def xfxQ2(self, x, Q): - return 1.0**2 - - def set(self): - return FakeSet() - - -class OneFKTable: - def __init__(self, path): - self.path = path - self.xgrid = np.geomspace(1e-4, 1.0, 10) - self.qgrid = np.geomspace(1.65, 1000, 10) - - def bin_left(self, i): - if i == 1: - return self.xgrid - if i == 0: - return self.qgrid - else: - return 0 - - def convolute_with_one(self, pdgid, xfxQ2): - return np.zeros((10, 10)) - +def test_zero_pdfs(): + "test that a zero PDF gives a zero structure function" + pdfs = ZeroPdfs() + theory = TEST_THEORY.get_description() + path_to_F2 = TEST_THEORY.path / "fastkernel/fiatlux_dis_F2.pineappl.lz4" + path_to_FL = TEST_THEORY.path / "fastkernel/fiatlux_dis_FL.pineappl.lz4" -class ZeroPdf: - def __init__(self): - self.ao = 1 + f2 = sf.InterpStructureFunction(path_to_F2, pdfs) + fl = sf.InterpStructureFunction(path_to_FL, pdfs) + f2lo = sf.F2LO(pdfs, theory) - def xfxQ(self, x, Q): - return 1.0 + np.testing.assert_equal(f2lo.thresh_t, np.inf) - def xfxQ2(self, x, Q): - return 1.0**2 + for x in np.geomspace(1e-4, 1.0, 10): + for Q in np.geomspace(10, 1000000, 10): + np.testing.assert_allclose(f2lo.fxq(x, Q), 0.0) + np.testing.assert_allclose(f2.fxq(x, Q), 0.0) + np.testing.assert_allclose(fl.fxq(x, Q), 0.0) - def set(self): - return FakeSet() -def test_F2(monkeypatch): - # grid put to 0 and pdf put to 1 +def test_zero_grid(monkeypatch): + "test that a zero grid gives a zero structure function" monkeypatch.setattr(pineappl.fk_table.FkTable, "read", ZeroFKTable) - structurefunc = sf.InterpStructureFunction("", OnePdf()) - for x in np.geomspace(1e-4, 1.0, 10): - for Q in np.geomspace(10, 1000000, 10): - np.testing.assert_allclose(structurefunc.fxq(x, Q), 0.0, rtol=1e-5) - # grid put to 0 and real pdf - pdf = LHAPDFSet("NNPDF40_nnlo_as_01180", "replicas") + pdf = PDFset(PDF).load() structurefunc = sf.InterpStructureFunction("", pdf.central_member) for x in np.geomspace(1e-4, 1.0, 10): for Q in np.geomspace(10, 1000000, 10): np.testing.assert_allclose(structurefunc.fxq(x, Q), 0.0, rtol=1e-5) - # grid put to 1 and pdf put to 0 - monkeypatch.setattr(pineappl.fk_table.FkTable, "read", OneFKTable) - structurefunc = sf.InterpStructureFunction("", ZeroPdf()) - for x in np.geomspace(1e-4, 1.0, 10): - for Q in np.geomspace(10, 1000000, 10): - np.testing.assert_allclose(structurefunc.fxq(x, Q), 0.0, rtol=1e-5) def test_params(): + "test initialization of parameters" pdfs = NNPDF40.load() replica = 1 theory = TEST_THEORY.get_description() @@ -158,6 +93,7 @@ def test_params(): def test_interpolation_grid(): + """test that the values coming out of InterpStructureFunction match the grid ones""" pdfs = NNPDF40.load() for replica in [1, 2, 3]: for channel in ["F2", "FL"]: From 3e548a88a38a00d0d0b1a07d58a34c9e24abe6df Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 15:07:47 +0200 Subject: [PATCH 30/37] Small modification --- .../src/validphys/tests/photon/test_structurefunctions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_structurefunctions.py b/validphys2/src/validphys/tests/photon/test_structurefunctions.py index 14f6b227bf..53dc7c1030 100644 --- a/validphys2/src/validphys/tests/photon/test_structurefunctions.py +++ b/validphys2/src/validphys/tests/photon/test_structurefunctions.py @@ -68,8 +68,8 @@ def test_zero_grid(monkeypatch): "test that a zero grid gives a zero structure function" monkeypatch.setattr(pineappl.fk_table.FkTable, "read", ZeroFKTable) # grid put to 0 and real pdf - pdf = PDFset(PDF).load() - structurefunc = sf.InterpStructureFunction("", pdf.central_member) + pdfs = NNPDF40.load() + structurefunc = sf.InterpStructureFunction("", pdfs.central_member) for x in np.geomspace(1e-4, 1.0, 10): for Q in np.geomspace(10, 1000000, 10): np.testing.assert_allclose(structurefunc.fxq(x, Q), 0.0, rtol=1e-5) From b40db35c19da9c82af9e59c41b9985fa10877318 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 15:20:33 +0200 Subject: [PATCH 31/37] Use FIATLUX_DEFAULT from photon.compute --- .../validphys/tests/photon/test_compute.py | 32 ++----------------- .../tests/photon/test_structurefunctions.py | 3 +- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index 00da494130..948ed3d3db 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -9,7 +9,7 @@ from validphys.api import API from validphys.core import PDF as PDFset from validphys.photon import structure_functions as sf -from validphys.photon.compute import Alpha, Photon +from validphys.photon.compute import Alpha, Photon, FIATLUX_DEFAULT from ..conftest import PDF @@ -22,34 +22,6 @@ "eps_base": 1e-2, # using low precision to speed up tests } -FIATLUX_DEFAULT = { - "apfel": False, - "eps_rel": 1e-1, # extra precision on any single integration. - "mum_proton": 2.792847356, # proton magnetic moment, from - # http://pdglive.lbl.gov/DataBlock.action?node=S016MM which itself - # gets it from arXiv:1203.5425 (CODATA) - # the elastic param type, options: - # dipole - # A1_world_spline - # A1_world_pol_spline - "elastic_param": "A1_world_pol_spline", - "elastic_electric_rescale": 1, - "elastic_magnetic_rescale": 1, - # the inelastic param type, options: - "inelastic_param": "LHAPDF_Hermes_ALLM_CLAS", # Hermes_ALLM_CLAS, LHAPDF_Hermes_ALLM_CLAS - "rescale_r_twist4": 0, - "rescale_r": 1, - "allm_limits": 0, - "rescale_non_resonance": 1, - "rescale_resonance": 1, - "use_mu2_as_upper_limit": False, - "q2min_inel_override": 0.0, - "q2max_inel_override": 1e300, - "lhapdf_transition_q2": 9, - # general - "verbose": False, -} - def test_parameters_init(): "test initailization of the parameters from Photon class" @@ -69,7 +41,7 @@ def test_parameters_init(): def test_masses_init(): - "test thresholds in Alpha class" + "test thresholds values in Alpha class" theory = TEST_THEORY.get_description() alpha = Alpha(theory) np.testing.assert_equal(alpha.thresh_t, np.inf) diff --git a/validphys2/src/validphys/tests/photon/test_structurefunctions.py b/validphys2/src/validphys/tests/photon/test_structurefunctions.py index 53dc7c1030..8798a0e30f 100644 --- a/validphys2/src/validphys/tests/photon/test_structurefunctions.py +++ b/validphys2/src/validphys/tests/photon/test_structurefunctions.py @@ -3,7 +3,6 @@ from validphys.api import API from validphys.core import PDF as PDFset -from validphys.lhapdfset import LHAPDFSet import validphys.photon.structure_functions as sf from ..conftest import PDF @@ -66,8 +65,8 @@ def test_zero_pdfs(): def test_zero_grid(monkeypatch): "test that a zero grid gives a zero structure function" + # patching pineappl.fk_table.FkTable to use ZeroFKTable monkeypatch.setattr(pineappl.fk_table.FkTable, "read", ZeroFKTable) - # grid put to 0 and real pdf pdfs = NNPDF40.load() structurefunc = sf.InterpStructureFunction("", pdfs.central_member) for x in np.geomspace(1e-4, 1.0, 10): From 0958b08b6a03f2702f3eeec24d934cc9537bd825 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Fri, 16 Jun 2023 15:26:04 +0200 Subject: [PATCH 32/37] Remove unused import --- n3fit/src/n3fit/tests/test_evolven3fit.py | 1 - 1 file changed, 1 deletion(-) diff --git a/n3fit/src/n3fit/tests/test_evolven3fit.py b/n3fit/src/n3fit/tests/test_evolven3fit.py index aeee049ee5..820d867891 100644 --- a/n3fit/src/n3fit/tests/test_evolven3fit.py +++ b/n3fit/src/n3fit/tests/test_evolven3fit.py @@ -12,7 +12,6 @@ from reportengine.compat import yaml from validphys.api import API from validphys.pdfbases import PIDS_DICT -from validphys.core import TheoryIDSpec REGRESSION_FOLDER = pathlib.Path(__file__).with_name("regressions") log = logging.getLogger(__name__) From 61c5bb901176ddb82c6be37c492e98cfd8d8faac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Mon, 19 Jun 2023 10:14:13 +0200 Subject: [PATCH 33/37] Remove variable NNPDF40 --- .../src/validphys/tests/photon/test_structurefunctions.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_structurefunctions.py b/validphys2/src/validphys/tests/photon/test_structurefunctions.py index 8798a0e30f..52f68f0a22 100644 --- a/validphys2/src/validphys/tests/photon/test_structurefunctions.py +++ b/validphys2/src/validphys/tests/photon/test_structurefunctions.py @@ -8,7 +8,6 @@ from ..conftest import PDF TEST_THEORY = API.theoryid(theoryid=398) -NNPDF40 = PDFset(PDF) class ZeroPdfs: @@ -67,7 +66,7 @@ def test_zero_grid(monkeypatch): "test that a zero grid gives a zero structure function" # patching pineappl.fk_table.FkTable to use ZeroFKTable monkeypatch.setattr(pineappl.fk_table.FkTable, "read", ZeroFKTable) - pdfs = NNPDF40.load() + pdfs = PDFset(PDF).load() structurefunc = sf.InterpStructureFunction("", pdfs.central_member) for x in np.geomspace(1e-4, 1.0, 10): for Q in np.geomspace(10, 1000000, 10): @@ -77,7 +76,7 @@ def test_zero_grid(monkeypatch): def test_params(): "test initialization of parameters" - pdfs = NNPDF40.load() + pdfs = PDFset(PDF).load() replica = 1 theory = TEST_THEORY.get_description() for channel in ["F2", "FL"]: @@ -93,7 +92,7 @@ def test_params(): def test_interpolation_grid(): """test that the values coming out of InterpStructureFunction match the grid ones""" - pdfs = NNPDF40.load() + pdfs = PDFset(PDF).load() for replica in [1, 2, 3]: for channel in ["F2", "FL"]: tmp = "fastkernel/fiatlux_dis_" + channel + ".pineappl.lz4" From 53d7c73728050d092065714fbc6671cf0edda27b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Mon, 19 Jun 2023 10:28:52 +0200 Subject: [PATCH 34/37] Add comment --- validphys2/src/validphys/photon/compute.py | 1 + 1 file changed, 1 insertion(+) diff --git a/validphys2/src/validphys/photon/compute.py b/validphys2/src/validphys/photon/compute.py index 189f801b97..52c3b04c78 100644 --- a/validphys2/src/validphys/photon/compute.py +++ b/validphys2/src/validphys/photon/compute.py @@ -17,6 +17,7 @@ log = logging.getLogger(__name__) +# not the complete fiatlux runcard since some parameters are set in the code FIATLUX_DEFAULT = { "apfel": False, "eps_rel": 1e-1, # extra precision on any single integration. From d5a48f9092beb2f9100ad19bed9145d4e61d2188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Mon, 19 Jun 2023 15:05:21 +0200 Subject: [PATCH 35/37] Check installation of error pdf in test --- validphys2/src/validphys/tests/photon/test_compute.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index 948ed3d3db..b7942cf468 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -10,14 +10,17 @@ from validphys.core import PDF as PDFset from validphys.photon import structure_functions as sf from validphys.photon.compute import Alpha, Photon, FIATLUX_DEFAULT +from validphys.loader import FallbackLoader from ..conftest import PDF TEST_THEORY = API.theoryid(theoryid=398) +# check if "LUXqed17_plus_PDF4LHC15_nnlo_100" is installed +FallbackLoader().check_pdf("LUXqed17_plus_PDF4LHC15_nnlo_100") FIATLUX_RUNCARD = { "luxset": PDFset(PDF), - "additional_errors": API.pdf(pdf='LUXqed17_plus_PDF4LHC15_nnlo_100'), + "additional_errors": PDFset('LUXqed17_plus_PDF4LHC15_nnlo_100'), "luxseed": 123456789, "eps_base": 1e-2, # using low precision to speed up tests } From 1e237da236ab9dbc0820e226dae11af387ba9745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Mon, 19 Jun 2023 15:06:57 +0200 Subject: [PATCH 36/37] Call black and isort --- validphys2/src/validphys/tests/photon/test_compute.py | 6 +++--- .../src/validphys/tests/photon/test_structurefunctions.py | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index b7942cf468..b17547dcb0 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -8,9 +8,9 @@ from n3fit.io.writer import XGRID from validphys.api import API from validphys.core import PDF as PDFset -from validphys.photon import structure_functions as sf -from validphys.photon.compute import Alpha, Photon, FIATLUX_DEFAULT from validphys.loader import FallbackLoader +from validphys.photon import structure_functions as sf +from validphys.photon.compute import FIATLUX_DEFAULT, Alpha, Photon from ..conftest import PDF @@ -22,7 +22,7 @@ "luxset": PDFset(PDF), "additional_errors": PDFset('LUXqed17_plus_PDF4LHC15_nnlo_100'), "luxseed": 123456789, - "eps_base": 1e-2, # using low precision to speed up tests + "eps_base": 1e-2, # using low precision to speed up tests } diff --git a/validphys2/src/validphys/tests/photon/test_structurefunctions.py b/validphys2/src/validphys/tests/photon/test_structurefunctions.py index 52f68f0a22..571ae765f2 100644 --- a/validphys2/src/validphys/tests/photon/test_structurefunctions.py +++ b/validphys2/src/validphys/tests/photon/test_structurefunctions.py @@ -18,7 +18,7 @@ def xfxQ(self, x, Q): res[21] = 0.0 res[22] = 0.0 return res - + def xfxQ2(self, i, x, Q2): return self.xfxQ(x, np.sqrt(Q2))[i] @@ -61,7 +61,6 @@ def test_zero_pdfs(): np.testing.assert_allclose(fl.fxq(x, Q), 0.0) - def test_zero_grid(monkeypatch): "test that a zero grid gives a zero structure function" # patching pineappl.fk_table.FkTable to use ZeroFKTable @@ -73,7 +72,6 @@ def test_zero_grid(monkeypatch): np.testing.assert_allclose(structurefunc.fxq(x, Q), 0.0, rtol=1e-5) - def test_params(): "test initialization of parameters" pdfs = PDFset(PDF).load() From 1e105cdf1a53c5d97604b874e581a5c2b2cdacac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Laurenti?= Date: Mon, 19 Jun 2023 15:44:01 +0200 Subject: [PATCH 37/37] Fix last commit --- validphys2/src/validphys/tests/photon/test_compute.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index b17547dcb0..9e3226062e 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -16,11 +16,10 @@ TEST_THEORY = API.theoryid(theoryid=398) -# check if "LUXqed17_plus_PDF4LHC15_nnlo_100" is installed -FallbackLoader().check_pdf("LUXqed17_plus_PDF4LHC15_nnlo_100") FIATLUX_RUNCARD = { "luxset": PDFset(PDF), - "additional_errors": PDFset('LUXqed17_plus_PDF4LHC15_nnlo_100'), + # check if "LUXqed17_plus_PDF4LHC15_nnlo_100" is installed + "additional_errors": FallbackLoader().check_pdf("LUXqed17_plus_PDF4LHC15_nnlo_100"), "luxseed": 123456789, "eps_base": 1e-2, # using low precision to speed up tests }