From c700c274798c3140212cd6c2fba695c59f7aa2f8 Mon Sep 17 00:00:00 2001 From: juacrumar Date: Fri, 26 May 2023 12:08:25 +0200 Subject: [PATCH 01/11] update n3fit tests to use theory 399 --- .../tests/regressions/hyper-quickcard.yml | 5 +- .../tests/regressions/noval-quickcard.yml | 3 +- .../n3fit/tests/regressions/pc-quickcard.yml | 2 +- .../src/n3fit/tests/regressions/quickcard.yml | 7 +- .../n3fit/tests/regressions/quickcard_1.json | 62 ++++++------- .../n3fit/tests/regressions/quickcard_2.json | 90 +++++++++---------- n3fit/src/n3fit/tests/test_fit.py | 6 +- 7 files changed, 86 insertions(+), 89 deletions(-) diff --git a/n3fit/src/n3fit/tests/regressions/hyper-quickcard.yml b/n3fit/src/n3fit/tests/regressions/hyper-quickcard.yml index aeb1f30e4b..e85331f756 100644 --- a/n3fit/src/n3fit/tests/regressions/hyper-quickcard.yml +++ b/n3fit/src/n3fit/tests/regressions/hyper-quickcard.yml @@ -33,7 +33,7 @@ datacuts: ############################################################ theory: - theoryid: 162 # database id + theoryid: 399 # database id hyperscan_config: stopping: @@ -116,12 +116,11 @@ fitting: positivity: posdatasets: - { dataset: POSF2U, maxlambda: 1e6 } # Positivity Lagrange Multiplier - - { dataset: POSDYC , maxlambda: 1e5 } + - { dataset: POSDYS , maxlambda: 1e5 } integrability: integdatasets: - {dataset: INTEGXT8, maxlambda: 1e2} - - {dataset: INTEGXT3, maxlambda: 1e2} ############################################################ closuretest: diff --git a/n3fit/src/n3fit/tests/regressions/noval-quickcard.yml b/n3fit/src/n3fit/tests/regressions/noval-quickcard.yml index 2a52a13388..6df9b367e3 100644 --- a/n3fit/src/n3fit/tests/regressions/noval-quickcard.yml +++ b/n3fit/src/n3fit/tests/regressions/noval-quickcard.yml @@ -31,7 +31,7 @@ datacuts: ############################################################ theory: - theoryid: 162 # database id + theoryid: 399 # database id ############################################################ genrep: True # on = generate MC replicas, False = use real data @@ -73,7 +73,6 @@ positivity: integrability: integdatasets: - {dataset: INTEGXT8, maxlambda: 1e2} - - {dataset: INTEGXT3, maxlambda: 1e2} ############################################################ closuretest: diff --git a/n3fit/src/n3fit/tests/regressions/pc-quickcard.yml b/n3fit/src/n3fit/tests/regressions/pc-quickcard.yml index a009bb0d6a..c5fa6679c9 100644 --- a/n3fit/src/n3fit/tests/regressions/pc-quickcard.yml +++ b/n3fit/src/n3fit/tests/regressions/pc-quickcard.yml @@ -31,7 +31,7 @@ datacuts: ############################################################ theory: - theoryid: 162 # database id + theoryid: 399 # database id ############################################################ genrep: True # on = generate MC replicas, False = use real data diff --git a/n3fit/src/n3fit/tests/regressions/quickcard.yml b/n3fit/src/n3fit/tests/regressions/quickcard.yml index 94cd910691..b241b8ddde 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard.yml +++ b/n3fit/src/n3fit/tests/regressions/quickcard.yml @@ -15,7 +15,7 @@ dataset_inputs: - { dataset: NMC, frac: 0.5 } - { dataset: SLACP, frac: 0.5} - { dataset: CMSZDIFF12, frac: 0.5, cfac: ['QCD'], sys: 10 } -- { dataset: CMSTTBARTOT, frac: 1.0, cfac: ['QCD'] } +- { dataset: ATLASTTBARTOT8TEV, frac: 1.0, cfac: ['QCD'] } ############################################################ datacuts: @@ -34,7 +34,7 @@ datacuts: ############################################################ theory: - theoryid: 162 # database id + theoryid: 399 # database id ############################################################ genrep: True # on = generate MC replicas, False = use real data @@ -77,12 +77,11 @@ fitting: positivity: posdatasets: - { dataset: POSF2U, maxlambda: 1e6 } # Positivity Lagrange Multiplier - - { dataset: POSDYC, maxlambda: 1e5 } + - { dataset: POSDYS, maxlambda: 1e5 } integrability: integdatasets: - {dataset: INTEGXT8, maxlambda: 1e2} - - {dataset: INTEGXT3, maxlambda: 1e2} ############################################################ debug: true diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_1.json b/n3fit/src/n3fit/tests/regressions/quickcard_1.json index 4ef9a904d5..f8a8132da4 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_1.json +++ b/n3fit/src/n3fit/tests/regressions/quickcard_1.json @@ -2,7 +2,7 @@ "preprocessing": [ { "fl": "sng", - "smallx": 1.1519856452941895, + "smallx": 1.1317780017852783, "largex": 2.635816812515259, "trainable": true }, @@ -20,8 +20,8 @@ }, { "fl": "v3", - "smallx": 0.29934635758399963, - "largex": 2.618340015411377, + "smallx": 0.30511540174484253, + "largex": 2.623253583908081, "trainable": true }, { @@ -38,58 +38,58 @@ }, { "fl": "t8", - "smallx": 1.0509718656539917, + "smallx": 1.0487886667251587, "largex": 1.9449496269226074, "trainable": true }, { "fl": "cp", - "smallx": 0.7440307140350342, + "smallx": 0.741088330745697, "largex": 3.4628548622131348, "trainable": true } ], "stop_epoch": 1000, "best_epoch": 999, - "erf_tr": 41.37715530395508, - "erf_vl": 30.869430541992188, - "chi2": 23.67120361328125, + "erf_tr": 31.9080753326416, + "erf_vl": 29.347797393798828, + "chi2": 20.596416473388672, "pos_state": "POS_VETO", "arc_lengths": [ - 1.0344613420720543, - 1.201936703437189, - 1.08538146705572, - 1.7372941675022844, - 1.0824835678381461 + 1.0344464673947673, + 1.199236066426708, + 1.088847738155109, + 1.3196733515313401, + 1.0838076324596133 ], "integrability": [ - 0.002680814883203597, - 0.0026808148832050405, - 0.0004433477934050467, - 3.997639417648317, - 0.004036187281601933 + 0.002636682111187061, + 0.00263668211118695, + 0.0002383394112248638, + 3.2648048400878915, + 0.003965188574513334 ], "timing": { "walltime": { - "Total": 25.287529706954956, + "Total": 20.825973987579346, "start": 0.0, - "replica_set": 0.0051801204681396484, - "replica_fitted": 25.287203311920166, - "replica_set_to_replica_fitted": 25.282023191452026 + "replica_set": 0.23225688934326172, + "replica_fitted": 20.825780630111694, + "replica_set_to_replica_fitted": 20.593523740768433 }, "cputime": { - "Total": 25.94147743, + "Total": 25.856474190999997, "start": 0.0, - "replica_set": 0.005177477000000152, - "replica_fitted": 25.941153733, - "replica_set_to_replica_fitted": 25.935976255999996 + "replica_set": 4.852700993999999, + "replica_fitted": 25.856265199, + "replica_set_to_replica_fitted": 21.003564205 } }, "version": { - "keras": "2.11.0", - "tensorflow": "2.11.0, mkl=False", - "numpy": "1.22.3", - "nnpdf": "4.0.6.370+g2f87a4152", - "validphys": "4.0.6.370+g2f87a4152" + "keras": "2.8.0", + "tensorflow": "2.8.2, mkl=False", + "numpy": "1.24.3", + "nnpdf": "4.0.6.742+g00e5c8e08-dev", + "validphys": "4.0.6.742+g00e5c8e08-dev" } } \ No newline at end of file diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_2.json b/n3fit/src/n3fit/tests/regressions/quickcard_2.json index e40ffcd47a..227992b42b 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_2.json +++ b/n3fit/src/n3fit/tests/regressions/quickcard_2.json @@ -2,94 +2,94 @@ "preprocessing": [ { "fl": "sng", - "smallx": 1.099926233291626, - "largex": 2.694965362548828, + "smallx": 1.1098793745040894, + "largex": 2.694117546081543, "trainable": true }, { "fl": "g", - "smallx": 0.9449679851531982, - "largex": 1.6326133012771606, + "smallx": 0.9399998784065247, + "largex": 1.6224415302276611, "trainable": true }, { "fl": "v", - "smallx": 0.7404175400733948, - "largex": 1.7165066003799438, + "smallx": 0.7499998211860657, + "largex": 1.719839096069336, "trainable": true }, { "fl": "v3", - "smallx": 0.21026656031608582, - "largex": 1.3537929058074951, + "smallx": 0.21590425074100494, + "largex": 1.3583499193191528, "trainable": true }, { "fl": "v8", - "smallx": 0.7599998712539673, - "largex": 2.401231050491333, + "smallx": 0.7548623085021973, + "largex": 2.390861749649048, "trainable": true }, { "fl": "t3", - "smallx": 1.4331011772155762, - "largex": 2.2847883701324463, + "smallx": 1.422916054725647, + "largex": 2.2746126651763916, "trainable": true }, { "fl": "t8", - "smallx": 1.0498263835906982, - "largex": 1.7643688917160034, + "smallx": 1.0396350622177124, + "largex": 1.7541793584823608, "trainable": true }, { "fl": "cp", - "smallx": 0.23803016543388367, - "largex": 2.786621570587158, + "smallx": 0.23281367123126984, + "largex": 2.796694040298462, "trainable": true } ], - "stop_epoch": 302, - "best_epoch": 0, - "erf_tr": 3.7486987113952637, - "erf_vl": 3.686168670654297, - "chi2": 2.187959671020508, - "pos_state": "POS_PASS", + "stop_epoch": 1000, + "best_epoch": 999, + "erf_tr": 5.0698370933532715, + "erf_vl": 5.813074588775635, + "chi2": 3.6448733806610107, + "pos_state": "POS_VETO", "arc_lengths": [ - 1.304138632310521, - 1.0696142268055964, - 1.0586845424638887, - 1.2170157426807882, - 1.0427752542860138 + 1.3231140372351198, + 1.1058951132978367, + 1.053545675669248, + 4.754435268325981, + 1.077278876106459 ], "integrability": [ - 0.025669145863502996, - 0.025669145863502996, - 2.930328855610398e-05, - 16.311637878417965, - 0.028825965244325014 + 0.029414556454864682, + 0.02941455645486657, + 0.0003741362179420227, + 13.06098985671997, + 0.02959074033424247 ], "timing": { "walltime": { - "Total": 12.90864634513855, + "Total": 21.088270664215088, "start": 0.0, - "replica_set": 0.003699779510498047, - "replica_fitted": 12.908478260040283, - "replica_set_to_replica_fitted": 12.904778480529785 + "replica_set": 0.23589444160461426, + "replica_fitted": 21.088091611862183, + "replica_set_to_replica_fitted": 20.85219717025757 }, "cputime": { - "Total": 13.139560354999999, + "Total": 26.207612153000003, "start": 0.0, - "replica_set": 0.0037029830000001596, - "replica_fitted": 13.139381430000002, - "replica_set_to_replica_fitted": 13.135678447000002 + "replica_set": 4.9267131299999996, + "replica_fitted": 26.207412609, + "replica_set_to_replica_fitted": 21.280699479 } }, "version": { - "keras": "2.11.0", - "tensorflow": "2.11.0, mkl=False", - "numpy": "1.22.3", - "nnpdf": "4.0.6.370+g2f87a4152", - "validphys": "4.0.6.370+g2f87a4152" + "keras": "2.8.0", + "tensorflow": "2.8.2, mkl=False", + "numpy": "1.24.3", + "nnpdf": "4.0.6.742+g00e5c8e08-dev", + "validphys": "4.0.6.742+g00e5c8e08-dev" } } \ No newline at end of file diff --git a/n3fit/src/n3fit/tests/test_fit.py b/n3fit/src/n3fit/tests/test_fit.py index d800feba6f..80a329faa0 100644 --- a/n3fit/src/n3fit/tests/test_fit.py +++ b/n3fit/src/n3fit/tests/test_fit.py @@ -106,9 +106,9 @@ def test_performfit(tmp_path): @pytest.mark.linux -def test_performfit_and_timing(tmp_path): - auxiliary_performfit(tmp_path, replica=1, timing=True) - auxiliary_performfit(tmp_path, replica=2, timing=True) +@pytest.mark.parametrize("replica", [1, 2]) +def test_performfit_and_timing(tmp_path, replica): + auxiliary_performfit(tmp_path, replica=replica, timing=True) @pytest.mark.skip(reason="Still not implemented in parallel mode") From 5ad09fe6ba248cfecfdc6cb50fec2936d299f66f Mon Sep 17 00:00:00 2001 From: juacrumar Date: Fri, 26 May 2023 14:52:43 +0200 Subject: [PATCH 02/11] added a test for eko convolution and LHAPDF info files --- .../n3fit/tests/regressions/quickcard_1.json | 50 +++++++------- .../n3fit/tests/regressions/quickcard_2.json | 66 +++++++++---------- n3fit/src/n3fit/tests/test_evolven3fit.py | 46 ++++++++++++- 3 files changed, 103 insertions(+), 59 deletions(-) diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_1.json b/n3fit/src/n3fit/tests/regressions/quickcard_1.json index f8a8132da4..7abec23de4 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_1.json +++ b/n3fit/src/n3fit/tests/regressions/quickcard_1.json @@ -51,45 +51,45 @@ ], "stop_epoch": 1000, "best_epoch": 999, - "erf_tr": 31.9080753326416, - "erf_vl": 29.347797393798828, - "chi2": 20.596416473388672, + "erf_tr": 31.90971565246582, + "erf_vl": 29.347829818725586, + "chi2": 20.596195220947266, "pos_state": "POS_VETO", "arc_lengths": [ - 1.0344464673947673, - 1.199236066426708, - 1.088847738155109, - 1.3196733515313401, - 1.0838076324596133 + 1.0344419604975799, + 1.199249640484144, + 1.0880527116547254, + 1.3247058914025585, + 1.08332657756542 ], "integrability": [ - 0.002636682111187061, - 0.00263668211118695, - 0.0002383394112248638, - 3.2648048400878915, - 0.003965188574513334 + 0.002648560388475274, + 0.0026485603884783826, + 0.00023979029810894392, + 3.264821648597718, + 0.003986286144939122 ], "timing": { "walltime": { - "Total": 20.825973987579346, + "Total": 37.674946308135986, "start": 0.0, - "replica_set": 0.23225688934326172, - "replica_fitted": 20.825780630111694, - "replica_set_to_replica_fitted": 20.593523740768433 + "replica_set": 0.2974090576171875, + "replica_fitted": 37.674692153930664, + "replica_set_to_replica_fitted": 37.37728309631348 }, "cputime": { - "Total": 25.856474190999997, + "Total": 95.89040509899999, "start": 0.0, - "replica_set": 4.852700993999999, - "replica_fitted": 25.856265199, - "replica_set_to_replica_fitted": 21.003564205 + "replica_set": 4.001058462, + "replica_fitted": 95.890103173, + "replica_set_to_replica_fitted": 91.889044711 } }, "version": { - "keras": "2.8.0", - "tensorflow": "2.8.2, mkl=False", + "keras": "2.11.0", + "tensorflow": "2.11.0, mkl=True", "numpy": "1.24.3", - "nnpdf": "4.0.6.742+g00e5c8e08-dev", - "validphys": "4.0.6.742+g00e5c8e08-dev" + "nnpdf": "4.0.6.743+g88e22f616-dev", + "validphys": "4.0.6.743+g88e22f616-dev" } } \ No newline at end of file diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_2.json b/n3fit/src/n3fit/tests/regressions/quickcard_2.json index 227992b42b..6a47fa1d00 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_2.json +++ b/n3fit/src/n3fit/tests/regressions/quickcard_2.json @@ -3,7 +3,7 @@ { "fl": "sng", "smallx": 1.1098793745040894, - "largex": 2.694117546081543, + "largex": 2.6941299438476562, "trainable": true }, { @@ -15,25 +15,25 @@ { "fl": "v", "smallx": 0.7499998211860657, - "largex": 1.719839096069336, + "largex": 1.7198402881622314, "trainable": true }, { "fl": "v3", - "smallx": 0.21590425074100494, - "largex": 1.3583499193191528, + "smallx": 0.21582084894180298, + "largex": 1.3583420515060425, "trainable": true }, { "fl": "v8", - "smallx": 0.7548623085021973, - "largex": 2.390861749649048, + "smallx": 0.754185676574707, + "largex": 2.3908095359802246, "trainable": true }, { "fl": "t3", "smallx": 1.422916054725647, - "largex": 2.2746126651763916, + "largex": 2.2746129035949707, "trainable": true }, { @@ -44,52 +44,52 @@ }, { "fl": "cp", - "smallx": 0.23281367123126984, + "smallx": 0.23247937858104706, "largex": 2.796694040298462, "trainable": true } ], "stop_epoch": 1000, "best_epoch": 999, - "erf_tr": 5.0698370933532715, - "erf_vl": 5.813074588775635, - "chi2": 3.6448733806610107, + "erf_tr": 5.0740556716918945, + "erf_vl": 5.817448139190674, + "chi2": 3.645888328552246, "pos_state": "POS_VETO", "arc_lengths": [ - 1.3231140372351198, - 1.1058951132978367, - 1.053545675669248, - 4.754435268325981, - 1.077278876106459 + 1.3231644321499851, + 1.1029587701870078, + 1.0539481882370751, + 4.728937647007949, + 1.063644108706556 ], "integrability": [ - 0.029414556454864682, - 0.02941455645486657, - 0.0003741362179420227, - 13.06098985671997, - 0.02959074033424247 + 0.02915892237797213, + 0.02915892237797324, + 0.00037147028888229183, + 13.060984134674072, + 0.029583527240902782 ], "timing": { "walltime": { - "Total": 21.088270664215088, + "Total": 36.70934009552002, "start": 0.0, - "replica_set": 0.23589444160461426, - "replica_fitted": 21.088091611862183, - "replica_set_to_replica_fitted": 20.85219717025757 + "replica_set": 0.2568092346191406, + "replica_fitted": 36.70907497406006, + "replica_set_to_replica_fitted": 36.45226573944092 }, "cputime": { - "Total": 26.207612153000003, + "Total": 96.177467606, "start": 0.0, - "replica_set": 4.9267131299999996, - "replica_fitted": 26.207412609, - "replica_set_to_replica_fitted": 21.280699479 + "replica_set": 4.545300222999998, + "replica_fitted": 96.17717635, + "replica_set_to_replica_fitted": 91.631876127 } }, "version": { - "keras": "2.8.0", - "tensorflow": "2.8.2, mkl=False", + "keras": "2.11.0", + "tensorflow": "2.11.0, mkl=True", "numpy": "1.24.3", - "nnpdf": "4.0.6.742+g00e5c8e08-dev", - "validphys": "4.0.6.742+g00e5c8e08-dev" + "nnpdf": "4.0.6.743+g88e22f616-dev", + "validphys": "4.0.6.743+g88e22f616-dev" } } \ No newline at end of file diff --git a/n3fit/src/n3fit/tests/test_evolven3fit.py b/n3fit/src/n3fit/tests/test_evolven3fit.py index 4644489198..bb59b22c9b 100644 --- a/n3fit/src/n3fit/tests/test_evolven3fit.py +++ b/n3fit/src/n3fit/tests/test_evolven3fit.py @@ -1,7 +1,12 @@ -import pathlib import logging +import pathlib +import pytest +import shutil +import subprocess as sp from numpy.testing import assert_allclose import numpy as np +from reportengine.compat import yaml +from validphys.api import API from validphys.pdfbases import PIDS_DICT from evolven3fit_new import utils, eko_utils from eko import EKO, runner @@ -15,6 +20,23 @@ def check_consecutive_members(grid, value): return np.allclose(grid[list(grid).index(value) + 1], value) +def check_lhapdf_info(info_path): + """Check the LHAPDF info file is correct""" + info = yaml.load(info_path.open("r", encoding="utf-8")) + + alphas_qs = info["AlphaS_Qs"] + alphas = info["AlphaS_Vals"] + + np.testing.assert_equal(info["QMin"], alphas_qs[0]) + np.testing.assert_equal(len(alphas), len(alphas_qs)) + assert isinstance(info["Particle"], int) + np.testing.assert_allclose(info["AlphaS_OrderQCD"], 2) + assert info["ErrorType"] == "replicas" + + for flavor in info["Flavors"]: + assert isinstance(flavor, int) + + def test_utils(): # Testing the default grid grid = utils.generate_q2grid(1.65, None, None, {}) @@ -80,3 +102,25 @@ def test_eko_utils(tmp_path): eko_op = EKO.read(save_path) assert_allclose(eko_op.operator_card.raw["xgrid"], x_grid) assert_allclose(list(eko_op.operator_card.raw["mugrid"]), op_card_dict["mugrid"]) + + +@pytest.mark.parametrize("fitname", ["Basic_runcard_3replicas_lowprec_399"]) +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 + """ + 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! + check_lhapdf_info(tmp_info) From 08f23a1c2e1f17b6aec9391087f52c19654e4feb Mon Sep 17 00:00:00 2001 From: juacrumar Date: Fri, 26 May 2023 22:05:27 +0200 Subject: [PATCH 03/11] update regression tests --- .../src/n3fit/tests/regressions/quickcard.yml | 4 +- .../n3fit/tests/regressions/quickcard_1.json | 82 +++++++++---------- .../n3fit/tests/regressions/quickcard_2.json | 80 +++++++++--------- 3 files changed, 83 insertions(+), 83 deletions(-) diff --git a/n3fit/src/n3fit/tests/regressions/quickcard.yml b/n3fit/src/n3fit/tests/regressions/quickcard.yml index b241b8ddde..0d5538778b 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard.yml +++ b/n3fit/src/n3fit/tests/regressions/quickcard.yml @@ -52,11 +52,11 @@ parameters: # This defines the parameter dictionary that is passed to the Model optimizer_name: 'RMSprop' learning_rate: 0.00001 clipnorm: 1.0 - epochs: 1000 + epochs: 1100 positivity: multiplier: 1.05 initial: 1.5 - stopping_patience: 0.30 # percentage of the number of epochs + stopping_patience: 0.10 # percentage of the number of epochs layer_type: 'dense' dropout: 0.0 threshold_chi2: 10.0 diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_1.json b/n3fit/src/n3fit/tests/regressions/quickcard_1.json index 7abec23de4..e1ab150b66 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_1.json +++ b/n3fit/src/n3fit/tests/regressions/quickcard_1.json @@ -2,94 +2,94 @@ "preprocessing": [ { "fl": "sng", - "smallx": 1.1317780017852783, - "largex": 2.635816812515259, + "smallx": 1.1307647228240967, + "largex": 2.6348154544830322, "trainable": true }, { "fl": "g", - "smallx": 1.1843736171722412, - "largex": 1.5618072748184204, + "smallx": 1.1853630542755127, + "largex": 1.5627975463867188, "trainable": true }, { "fl": "v", "smallx": 0.5399999022483826, - "largex": 2.0055015087127686, + "largex": 2.004500150680542, "trainable": true }, { "fl": "v3", - "smallx": 0.30511540174484253, - "largex": 2.623253583908081, + "smallx": 0.3061078190803528, + "largex": 2.6242549419403076, "trainable": true }, { "fl": "v8", - "smallx": 0.5784729719161987, - "largex": 2.1212551593780518, + "smallx": 0.5774596929550171, + "largex": 2.120253801345825, "trainable": true }, { "fl": "t3", - "smallx": 1.3452119827270508, - "largex": 1.7576805353164673, + "smallx": 1.3441987037658691, + "largex": 1.7566683292388916, "trainable": true }, { "fl": "t8", - "smallx": 1.0487886667251587, - "largex": 1.9449496269226074, + "smallx": 1.047775387763977, + "largex": 1.945939064025879, "trainable": true }, { "fl": "cp", - "smallx": 0.741088330745697, - "largex": 3.4628548622131348, + "smallx": 0.7400740385055542, + "largex": 3.461853504180908, "trainable": true } ], - "stop_epoch": 1000, - "best_epoch": 999, - "erf_tr": 31.90971565246582, - "erf_vl": 29.347829818725586, - "chi2": 20.596195220947266, + "stop_epoch": 1100, + "best_epoch": 1099, + "erf_tr": 31.587974548339844, + "erf_vl": 29.09645652770996, + "chi2": 20.467185974121094, "pos_state": "POS_VETO", "arc_lengths": [ - 1.0344419604975799, - 1.199249640484144, - 1.0880527116547254, - 1.3247058914025585, - 1.08332657756542 + 1.0353434175487572, + 1.1966792723668909, + 1.0884899669278114, + 1.3288290197461279, + 1.0839435375255841 ], "integrability": [ - 0.002648560388475274, - 0.0026485603884783826, - 0.00023979029810894392, - 3.264821648597718, - 0.003986286144939122 + 0.002641671162566972, + 0.002641671162561421, + 0.0002462610455011838, + 3.1516795754432665, + 0.003926577570384282 ], "timing": { "walltime": { - "Total": 37.674946308135986, + "Total": 17.712170839309692, "start": 0.0, - "replica_set": 0.2974090576171875, - "replica_fitted": 37.674692153930664, - "replica_set_to_replica_fitted": 37.37728309631348 + "replica_set": 0.1738264560699463, + "replica_fitted": 17.712095260620117, + "replica_set_to_replica_fitted": 17.53826880455017 }, "cputime": { - "Total": 95.89040509899999, + "Total": 18.391021507999998, "start": 0.0, - "replica_set": 4.001058462, - "replica_fitted": 95.890103173, - "replica_set_to_replica_fitted": 91.889044711 + "replica_set": 0.173584666, + "replica_fitted": 18.390944242, + "replica_set_to_replica_fitted": 18.217359576 } }, "version": { "keras": "2.11.0", - "tensorflow": "2.11.0, mkl=True", + "tensorflow": "2.11.0, mkl=False", "numpy": "1.24.3", - "nnpdf": "4.0.6.743+g88e22f616-dev", - "validphys": "4.0.6.743+g88e22f616-dev" + "nnpdf": "4.0.6.744+ga791d281e-dev", + "validphys": "4.0.6.744+ga791d281e-dev" } } \ No newline at end of file diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_2.json b/n3fit/src/n3fit/tests/regressions/quickcard_2.json index 6a47fa1d00..d59c97a5f5 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_2.json +++ b/n3fit/src/n3fit/tests/regressions/quickcard_2.json @@ -2,94 +2,94 @@ "preprocessing": [ { "fl": "sng", - "smallx": 1.1098793745040894, - "largex": 2.6941299438476562, + "smallx": 1.1108688116073608, + "largex": 2.6956193447113037, "trainable": true }, { "fl": "g", "smallx": 0.9399998784065247, - "largex": 1.6224415302276611, + "largex": 1.621421217918396, "trainable": true }, { "fl": "v", "smallx": 0.7499998211860657, - "largex": 1.7198402881622314, + "largex": 1.7185953855514526, "trainable": true }, { "fl": "v3", - "smallx": 0.21582084894180298, - "largex": 1.3583420515060425, + "smallx": 0.215017169713974, + "largex": 1.3573191165924072, "trainable": true }, { "fl": "v8", - "smallx": 0.754185676574707, - "largex": 2.3908095359802246, + "smallx": 0.7532474994659424, + "largex": 2.389765977859497, "trainable": true }, { "fl": "t3", - "smallx": 1.422916054725647, - "largex": 2.2746129035949707, + "smallx": 1.4219000339508057, + "largex": 2.273611545562744, "trainable": true }, { "fl": "t8", - "smallx": 1.0396350622177124, - "largex": 1.7541793584823608, + "smallx": 1.0386217832565308, + "largex": 1.7531665563583374, "trainable": true }, { "fl": "cp", - "smallx": 0.23247937858104706, - "largex": 2.796694040298462, + "smallx": 0.23516468703746796, + "largex": 2.7976953983306885, "trainable": true } ], - "stop_epoch": 1000, - "best_epoch": 999, - "erf_tr": 5.0740556716918945, - "erf_vl": 5.817448139190674, - "chi2": 3.645888328552246, + "stop_epoch": 1100, + "best_epoch": 1099, + "erf_tr": 4.962428092956543, + "erf_vl": 5.63330078125, + "chi2": 3.5181877613067627, "pos_state": "POS_VETO", "arc_lengths": [ - 1.3231644321499851, - 1.1029587701870078, - 1.0539481882370751, - 4.728937647007949, - 1.063644108706556 + 1.324828406611252, + 1.1113330992990824, + 1.0539862831681286, + 4.888539270923742, + 1.067708667365969 ], "integrability": [ - 0.02915892237797213, - 0.02915892237797324, - 0.00037147028888229183, - 13.060984134674072, - 0.029583527240902782 + 0.029175871051850266, + 0.02917587105184627, + 0.0003802012824946077, + 12.767466306686401, + 0.029576309956610758 ], "timing": { "walltime": { - "Total": 36.70934009552002, + "Total": 17.551416397094727, "start": 0.0, - "replica_set": 0.2568092346191406, - "replica_fitted": 36.70907497406006, - "replica_set_to_replica_fitted": 36.45226573944092 + "replica_set": 0.17304396629333496, + "replica_fitted": 17.551299571990967, + "replica_set_to_replica_fitted": 17.378255605697632 }, "cputime": { - "Total": 96.177467606, + "Total": 18.186233694000002, "start": 0.0, - "replica_set": 4.545300222999998, - "replica_fitted": 96.17717635, - "replica_set_to_replica_fitted": 91.631876127 + "replica_set": 0.17282558100000145, + "replica_fitted": 18.186119053, + "replica_set_to_replica_fitted": 18.013293472 } }, "version": { "keras": "2.11.0", - "tensorflow": "2.11.0, mkl=True", + "tensorflow": "2.11.0, mkl=False", "numpy": "1.24.3", - "nnpdf": "4.0.6.743+g88e22f616-dev", - "validphys": "4.0.6.743+g88e22f616-dev" + "nnpdf": "4.0.6.744+ga791d281e-dev", + "validphys": "4.0.6.744+ga791d281e-dev" } } \ No newline at end of file From fa558c8efd96de1dafee8f46383466dd36cf6c51 Mon Sep 17 00:00:00 2001 From: juacrumar Date: Mon, 5 Jun 2023 15:05:52 +0200 Subject: [PATCH 04/11] add test for the errors found in #1750 --- n3fit/src/n3fit/tests/test_evolven3fit.py | 56 ++++++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/n3fit/src/n3fit/tests/test_evolven3fit.py b/n3fit/src/n3fit/tests/test_evolven3fit.py index bb59b22c9b..7340a46c20 100644 --- a/n3fit/src/n3fit/tests/test_evolven3fit.py +++ b/n3fit/src/n3fit/tests/test_evolven3fit.py @@ -1,20 +1,28 @@ import logging import pathlib -import pytest import shutil import subprocess as sp -from numpy.testing import assert_allclose + +from evolven3fit_new import eko_utils, utils import numpy as np +from numpy.testing import assert_allclose +import pytest + +from eko import EKO, runner from reportengine.compat import yaml from validphys.api import API from validphys.pdfbases import PIDS_DICT -from evolven3fit_new import utils, eko_utils -from eko import EKO, runner REGRESSION_FOLDER = pathlib.Path(__file__).with_name("regressions") log = logging.getLogger(__name__) +def assert_sorted(arr, title): + """Assert that the array is sorted""" + if not np.all(np.diff(arr) >= 0): + raise ValueError(f"The values of {title} are not sorted!") + + def check_consecutive_members(grid, value): """Check if the first occurrence of value in grid is followed by value again""" return np.allclose(grid[list(grid).index(value) + 1], value) @@ -30,12 +38,42 @@ def check_lhapdf_info(info_path): np.testing.assert_equal(info["QMin"], alphas_qs[0]) np.testing.assert_equal(len(alphas), len(alphas_qs)) assert isinstance(info["Particle"], int) - np.testing.assert_allclose(info["AlphaS_OrderQCD"], 2) + np.testing.assert_allclose(info["AlphaS_OrderQCD"], 2) # Test theories are NNLO assert info["ErrorType"] == "replicas" + # Check that the values of Q are sorted + assert_sorted(alphas_qs, "Qs in the .info file") + for flavor in info["Flavors"]: assert isinstance(flavor, int) + return info + + +def check_lhapdf_dat(dat_path, info): + """Check that the dat file itself makes sense + and that it is consistent with the info file + """ + blocks = dat_path.read_text().split("---")[:-1] + + for i, block in enumerate(blocks[1:]): + sp_block = block.strip().split("\n", 3) + x = np.fromstring(sp_block[0], sep=" ") + q = np.fromstring(sp_block[1], sep=" ") + flavs = np.fromstring(sp_block[2], dtype=int, sep=" ") + + np.testing.assert_array_equal(info["Flavors"], flavs) + + assert x[0] == info["XMin"] + assert x[-1] == info["XMax"] + assert_sorted(x, "x-grid") + + if i == 0: + assert q[0] == info["QMin"] + assert_sorted(q, "q-grid") + + assert q[-1] == info["QMax"] + def test_utils(): # Testing the default grid @@ -116,11 +154,15 @@ def test_perform_evolution(tmp_path, fitname): # 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 = 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! - check_lhapdf_info(tmp_info) + info = check_lhapdf_info(tmp_info) + for datpath in tmp_nnfit.glob("replica_*/*.dat"): + check_lhapdf_dat(datpath, info) From 5e2dc6b1fb9e02cc1885b7b5c644cab95b6d3e07 Mon Sep 17 00:00:00 2001 From: juacrumar Date: Tue, 6 Jun 2023 11:56:26 +0200 Subject: [PATCH 05/11] fixes to info file --- n3fit/src/evolven3fit_new/evolve.py | 43 ++++++++++++++--------- n3fit/src/n3fit/tests/test_evolven3fit.py | 9 ++--- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/n3fit/src/evolven3fit_new/evolve.py b/n3fit/src/evolven3fit_new/evolve.py index f236fa603b..32cea86b22 100644 --- a/n3fit/src/evolven3fit_new/evolve.py +++ b/n3fit/src/evolven3fit_new/evolve.py @@ -77,14 +77,9 @@ def evolve_fit( usr_path = pathlib.Path(fit_folder) initial_PDFs_dict = load_fit(usr_path) - x_grid = np.array( - initial_PDFs_dict[list(initial_PDFs_dict.keys())[0]]["xgrid"] - ).astype(float) + x_grid = np.array(initial_PDFs_dict[list(initial_PDFs_dict.keys())[0]]["xgrid"]).astype(float) theoryID = utils.get_theoryID_from_runcard(usr_path) - theory, op = eko_utils.construct_eko_cards( - theoryID, q_fin, q_points, x_grid, op_card_dict, theory_card_dict - ) - qed = theory.order[1] > 0 + if eko_path is not None: eko_path = pathlib.Path(eko_path) _logger.info(f"Loading eko from : {eko_path}") @@ -94,23 +89,37 @@ def evolve_fit( eko_path = (Loader().check_theoryID(theoryID).path) / "eko.tar" except FileNotFoundError: _logger.info(f"eko not found in theory {theoryID}, we will construct it") + theory, op = eko_utils.construct_eko_cards( + theoryID, q_fin, q_points, x_grid, op_card_dict, theory_card_dict + ) runner.solve(theory, op, dump_eko) eko_path = dump_eko + with eko.EKO.edit(eko_path) as eko_op: x_grid_obj = eko.interpolation.XGrid(x_grid) eko.io.manipulate.xgrid_reshape(eko_op, targetgrid=x_grid_obj, inputgrid=x_grid_obj) - info = info_file.build(theory, op, 1, info_update={}) - info["NumMembers"] = "REPLACE_NREP" - info["ErrorType"] = "replicas" - info["XMin"] = float(x_grid[0]) - info["XMax"] = float(x_grid[-1]) + with eko.EKO.read(eko_path) as eko_op: + # Read the cards directly from the eko to make sure they are consistent + theory = eko_op.theory_card + op = eko_op.operator_card + + qed = theory.order[1] > 0 + + # Modify the info file with the fit-specific info + info = info_file.build(theory, op, 1, info_update={}) + info["NumMembers"] = "REPLACE_NREP" + info["ErrorType"] = "replicas" + info["XMin"] = float(x_grid[0]) + info["XMax"] = float(x_grid[-1]) + # Save the PIDs in the info file in the same order as in the evolution + info["Flavors"] = basis_rotation.flavor_basis_pids dump_info_file(usr_path, info) - for replica in initial_PDFs_dict.keys(): - evolved_block = evolve_exportgrid(initial_PDFs_dict[replica], eko_op, x_grid, qed) - dump_evolved_replica( - evolved_block, usr_path, int(replica.removeprefix("replica_")) - ) + + for replica, pdf_data in initial_PDFs_dict.items(): + evolved_block = evolve_exportgrid(pdf_data, eko_op, x_grid, qed) + dump_evolved_replica(evolved_block, usr_path, int(replica.removeprefix("replica_"))) + # remove folder: # The function dump_evolved_replica dumps the replica files in a temporary folder # We need then to remove it after fixing the position of those replica files diff --git a/n3fit/src/n3fit/tests/test_evolven3fit.py b/n3fit/src/n3fit/tests/test_evolven3fit.py index 7340a46c20..fd0ea1e3b3 100644 --- a/n3fit/src/n3fit/tests/test_evolven3fit.py +++ b/n3fit/src/n3fit/tests/test_evolven3fit.py @@ -64,15 +64,16 @@ def check_lhapdf_dat(dat_path, info): np.testing.assert_array_equal(info["Flavors"], flavs) - assert x[0] == info["XMin"] - assert x[-1] == info["XMax"] + np.testing.assert_equal(x[0], info["XMin"]) + np.testing.assert_equal(x[-1], info["XMax"]) assert_sorted(x, "x-grid") if i == 0: - assert q[0] == info["QMin"] + np.testing.assert_equal(q[0], info["QMin"]) assert_sorted(q, "q-grid") - assert q[-1] == info["QMax"] + # Use allclose here to avoid failing because of a different in the 7th place + np.testing.assert_allclose(q[-1], info["QMax"]) def test_utils(): From dc875eb7afc51df23bcde73311e2555c40c36bcb Mon Sep 17 00:00:00 2001 From: Andrea Barontini Date: Tue, 6 Jun 2023 16:07:38 +0200 Subject: [PATCH 06/11] Separate blocks for each active heavy quark --- n3fit/src/evolven3fit_new/eko_utils.py | 21 ++++++++++++++ n3fit/src/evolven3fit_new/evolve.py | 39 ++++++++++++++------------ 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/n3fit/src/evolven3fit_new/eko_utils.py b/n3fit/src/evolven3fit_new/eko_utils.py index cf92ebb4ce..0160a7ca7c 100644 --- a/n3fit/src/evolven3fit_new/eko_utils.py +++ b/n3fit/src/evolven3fit_new/eko_utils.py @@ -100,3 +100,24 @@ def construct_eko_cards( op_card = runcards.OperatorCard.from_dict(op_card) return theory_card, op_card + + +def split_evolgrid(evolgrid): + """Split the evolgrid in blocks according to the number of flavors and repeating the last entry of one block in the first entry of the next.""" + evolgrid_index_list = [] + evolgrid.sort() + starting_nf = evolgrid[0][1] + for evo_point in evolgrid: + current_nf = evo_point[1] + if current_nf != starting_nf: + evolgrid_index_list.append(evolgrid.index(evo_point)) + starting_nf = current_nf + start_index = 0 + evolgrid_list = [] + for index in evolgrid_index_list: + evolgrid_list.append(evolgrid[start_index:index+1]) + start_index = index + evolgrid_list.append(evolgrid[start_index:]) + return evolgrid_list + + diff --git a/n3fit/src/evolven3fit_new/evolve.py b/n3fit/src/evolven3fit_new/evolve.py index 32cea86b22..dd26953ce0 100644 --- a/n3fit/src/evolven3fit_new/evolve.py +++ b/n3fit/src/evolven3fit_new/evolve.py @@ -117,8 +117,8 @@ def evolve_fit( dump_info_file(usr_path, info) for replica, pdf_data in initial_PDFs_dict.items(): - evolved_block = evolve_exportgrid(pdf_data, eko_op, x_grid, qed) - dump_evolved_replica(evolved_block, usr_path, int(replica.removeprefix("replica_"))) + evolved_blocks = evolve_exportgrid(pdf_data, eko_op, x_grid, qed) + dump_evolved_replica(evolved_blocks, usr_path, int(replica.removeprefix("replica_"))) # remove folder: # The function dump_evolved_replica dumps the replica files in a temporary folder @@ -166,8 +166,8 @@ def evolve_exportgrid(exportgrid, eko, x_grid, qed): whether qed is activated or not Returns ------- - : np.array - evolved block + : list(np.array) + list of evolved blocks """ # construct LhapdfLike object pdf_grid = np.array(exportgrid["pdfgrid"]).transpose() @@ -179,25 +179,28 @@ def evolve_exportgrid(exportgrid, eko, x_grid, qed): def ev_pdf(pid, x, Q2): return x * evolved_pdf[Q2]["pdfs"][pid][targetgrid.index(x)] - - block = genpdf.generate_block( - ev_pdf, - xgrid=targetgrid, - evolgrid=eko.evolgrid, - pids=basis_rotation.flavor_basis_pids, - ) - return block - - -def dump_evolved_replica(evolved_block, usr_path, replica_num): + evolgrid_list = eko_utils.split_evolgrid(eko.evolgrid) + blocks = [] + for evgrid in evolgrid_list: + block = genpdf.generate_block( + ev_pdf, + xgrid=targetgrid, + evolgrid=evgrid, + pids=basis_rotation.flavor_basis_pids, + ) + blocks.append(block) + return blocks + + +def dump_evolved_replica(evolved_blocks, usr_path, replica_num): """ Dump the evolved replica given by evolved_block as the replica num "replica_num" in the folder usr_path/nnfit/replica_/usr_path.stem.dat Parameters ---------- - evolved_block: numpy.array - block of an evolved PDF + evolved_block: list(numpy.array) + list of blocks of an evolved PDF usr_path: pathlib.Path path of the fit folder replica_num: int @@ -208,7 +211,7 @@ def dump_evolved_replica(evolved_block, usr_path, replica_num): path_where_dump.mkdir(exist_ok=True) to_write_in_head = f"PdfType: replica\nFromMCReplica: {replica_num}\n" genpdf.export.dump_blocks( - path_where_dump, replica_num, [evolved_block], pdf_type=to_write_in_head + path_where_dump, replica_num, evolved_blocks, pdf_type=to_write_in_head ) # fixing_replica_path utils.fix_replica_path(usr_path, replica_num) From 44b29ee2951a75f4087905ae26ed515ea4ee2dec Mon Sep 17 00:00:00 2001 From: juacrumar Date: Tue, 6 Jun 2023 17:11:58 +0200 Subject: [PATCH 07/11] fix (and test) number of flavors and thresholds --- n3fit/src/evolven3fit_new/eko_utils.py | 17 ++++++++++++++--- n3fit/src/evolven3fit_new/evolve.py | 1 + n3fit/src/n3fit/tests/test_evolven3fit.py | 2 ++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/n3fit/src/evolven3fit_new/eko_utils.py b/n3fit/src/evolven3fit_new/eko_utils.py index 0160a7ca7c..e91f5c5a0b 100644 --- a/n3fit/src/evolven3fit_new/eko_utils.py +++ b/n3fit/src/evolven3fit_new/eko_utils.py @@ -51,6 +51,7 @@ def construct_eko_cards( theory_card_dict = {} if op_card_dict is None: op_card_dict = {} + # theory_card construction theory = Loader().check_theoryID(theoryID).get_description() theory.pop("FNS") @@ -59,19 +60,29 @@ def construct_eko_cards( theory["nfref"] = NFREF_DEFAULT if "nf0" not in theory: theory["nf0"] = NF0_DEFAULT + # The Legacy function is able to construct a theory card for eko starting from an NNPDF theory legacy_class = runcards.Legacy(theory, {}) theory_card = legacy_class.new_theory + + # Prepare the thresholds according to MaxNfPdf + thresholds = {"c": theory["kcThr"], "b": theory["kbThr"], "t": theory["kbThr"]} + if theory["MaxNfPdf"] < 5: + thresholds["b"] = np.inf + if theory["MaxNfPdf"] < 6: + thresholds["t"] = np.inf + # construct operator card q2_grid = utils.generate_q2grid( theory["Q0"], q_fin, q_points, - {theory["mb"]: theory["kbThr"], theory["mt"]: theory["ktThr"]}, + {theory["mb"]: thresholds["b"], theory["mt"]: thresholds["t"]}, ) op_card = default_op_card - masses = np.array([theory["mc"],theory["mb"],theory["mt"]]) ** 2 - thresholds_ratios=np.array([theory["kcThr"],theory["kbThr"],theory["ktThr"]]) ** 2 + masses = np.array([theory["mc"], theory["mb"], theory["mt"]]) ** 2 + thresholds_ratios = np.array([thresholds["c"], thresholds["b"], thresholds["t"]]) ** 2 + atlas = Atlas( matching_scales=MatchingScales(masses * thresholds_ratios), origin=(theory["Q0"]**2, theory["nf0"]) diff --git a/n3fit/src/evolven3fit_new/evolve.py b/n3fit/src/evolven3fit_new/evolve.py index dd26953ce0..6ba4a35030 100644 --- a/n3fit/src/evolven3fit_new/evolve.py +++ b/n3fit/src/evolven3fit_new/evolve.py @@ -114,6 +114,7 @@ def evolve_fit( info["XMax"] = float(x_grid[-1]) # Save the PIDs in the info file in the same order as in the evolution info["Flavors"] = basis_rotation.flavor_basis_pids + info["NumFlavors"] = theory.couplings.max_num_flavs dump_info_file(usr_path, info) for replica, pdf_data in initial_PDFs_dict.items(): diff --git a/n3fit/src/n3fit/tests/test_evolven3fit.py b/n3fit/src/n3fit/tests/test_evolven3fit.py index fd0ea1e3b3..1796095df1 100644 --- a/n3fit/src/n3fit/tests/test_evolven3fit.py +++ b/n3fit/src/n3fit/tests/test_evolven3fit.py @@ -47,6 +47,8 @@ def check_lhapdf_info(info_path): for flavor in info["Flavors"]: assert isinstance(flavor, int) + assert info["NumFlavors"] <= 6 + return info From 814571f4a5148ef094f34c48014d039f2baf1384 Mon Sep 17 00:00:00 2001 From: "Juan M. Cruz-Martinez" Date: Tue, 6 Jun 2023 17:13:38 +0200 Subject: [PATCH 08/11] Update n3fit/src/evolven3fit_new/evolve.py --- n3fit/src/evolven3fit_new/evolve.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/n3fit/src/evolven3fit_new/evolve.py b/n3fit/src/evolven3fit_new/evolve.py index 6ba4a35030..2002b49b03 100644 --- a/n3fit/src/evolven3fit_new/evolve.py +++ b/n3fit/src/evolven3fit_new/evolve.py @@ -114,7 +114,7 @@ def evolve_fit( info["XMax"] = float(x_grid[-1]) # Save the PIDs in the info file in the same order as in the evolution info["Flavors"] = basis_rotation.flavor_basis_pids - info["NumFlavors"] = theory.couplings.max_num_flavs + info["NumFlavors"] = theory.heavy.num_flavs_max_pdf dump_info_file(usr_path, info) for replica, pdf_data in initial_PDFs_dict.items(): From 0fc99ae53b803a5c7686f198de0f02db4e4a6541 Mon Sep 17 00:00:00 2001 From: "Juan M. Cruz-Martinez" Date: Wed, 7 Jun 2023 08:07:59 +0200 Subject: [PATCH 09/11] fix typo b->t --- n3fit/src/evolven3fit_new/eko_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/n3fit/src/evolven3fit_new/eko_utils.py b/n3fit/src/evolven3fit_new/eko_utils.py index e91f5c5a0b..5fb8d5e643 100644 --- a/n3fit/src/evolven3fit_new/eko_utils.py +++ b/n3fit/src/evolven3fit_new/eko_utils.py @@ -66,7 +66,7 @@ def construct_eko_cards( theory_card = legacy_class.new_theory # Prepare the thresholds according to MaxNfPdf - thresholds = {"c": theory["kcThr"], "b": theory["kbThr"], "t": theory["kbThr"]} + thresholds = {"c": theory["kcThr"], "b": theory["kbThr"], "t": theory["ktThr"]} if theory["MaxNfPdf"] < 5: thresholds["b"] = np.inf if theory["MaxNfPdf"] < 6: From 07d8d315aff44f98cb546e09088aa981e9778466 Mon Sep 17 00:00:00 2001 From: juacrumar Date: Wed, 7 Jun 2023 10:45:30 +0200 Subject: [PATCH 10/11] format evolven3fit with black & isort --- n3fit/src/evolven3fit_new/eko_utils.py | 10 +- n3fit/src/evolven3fit_new/evolve.py | 7 +- n3fit/src/evolven3fit_new/utils.py | 145 +++++++++++++------------ 3 files changed, 83 insertions(+), 79 deletions(-) diff --git a/n3fit/src/evolven3fit_new/eko_utils.py b/n3fit/src/evolven3fit_new/eko_utils.py index 5fb8d5e643..76a02ef8bc 100644 --- a/n3fit/src/evolven3fit_new/eko_utils.py +++ b/n3fit/src/evolven3fit_new/eko_utils.py @@ -1,11 +1,12 @@ import logging from typing import Any, Dict, Optional +from ekobox.cards import _operator as default_op_card import numpy as np + from eko.io import runcards from eko.matchings import Atlas, nf_default from eko.quantities.heavy_quarks import MatchingScales -from ekobox.cards import _operator as default_op_card from validphys.loader import Loader from . import utils @@ -31,6 +32,7 @@ NFREF_DEFAULT = 5 NF0_DEFAULT = 4 + def construct_eko_cards( theoryID, q_fin, @@ -85,7 +87,7 @@ def construct_eko_cards( atlas = Atlas( matching_scales=MatchingScales(masses * thresholds_ratios), - origin=(theory["Q0"]**2, theory["nf0"]) + origin=(theory["Q0"] ** 2, theory["nf0"]), ) op_card.update( { @@ -126,9 +128,7 @@ def split_evolgrid(evolgrid): start_index = 0 evolgrid_list = [] for index in evolgrid_index_list: - evolgrid_list.append(evolgrid[start_index:index+1]) + evolgrid_list.append(evolgrid[start_index : index + 1]) start_index = index evolgrid_list.append(evolgrid[start_index:]) return evolgrid_list - - diff --git a/n3fit/src/evolven3fit_new/evolve.py b/n3fit/src/evolven3fit_new/evolve.py index 2002b49b03..cddb1eb308 100644 --- a/n3fit/src/evolven3fit_new/evolve.py +++ b/n3fit/src/evolven3fit_new/evolve.py @@ -2,11 +2,11 @@ import pathlib import sys +from ekobox import apply, genpdf, info_file import numpy as np + import eko -from eko import basis_rotation -from eko import runner -from ekobox import genpdf, info_file, apply +from eko import basis_rotation, runner from reportengine.compat import yaml from validphys.loader import Loader @@ -180,6 +180,7 @@ def evolve_exportgrid(exportgrid, eko, x_grid, qed): def ev_pdf(pid, x, Q2): return x * evolved_pdf[Q2]["pdfs"][pid][targetgrid.index(x)] + evolgrid_list = eko_utils.split_evolgrid(eko.evolgrid) blocks = [] for evgrid in evolgrid_list: diff --git a/n3fit/src/evolven3fit_new/utils.py b/n3fit/src/evolven3fit_new/utils.py index afbfa6f445..f1303fcbd7 100644 --- a/n3fit/src/evolven3fit_new/utils.py +++ b/n3fit/src/evolven3fit_new/utils.py @@ -1,74 +1,80 @@ -import shutil import pathlib -from scipy.interpolate import interp1d +import shutil + import numpy as np +from scipy.interpolate import interp1d + from reportengine.compat import yaml from validphys.pdfbases import PIDS_DICT -DEFAULT_Q2GRID = np.array( - [ - 1.6500000e00, - 1.7874388e00, - 1.9429053e00, - 2.1193749e00, - 2.3204100e00, - 2.5502944e00, - 2.8142025e00, - 3.1184122e00, - 3.4705775e00, - 3.8800751e00, - 4.3584516e00, - 4.9200000e00, - 4.9200000e00, - 5.5493622e00, - 6.2897452e00, - 7.1650687e00, - 8.2052867e00, - 9.4481248e00, - 1.0941378e01, - 1.2745972e01, - 1.4940062e01, - 1.7624572e01, - 2.0930715e01, - 2.5030298e01, - 3.0149928e01, - 3.6590777e01, - 4.4756282e01, - 5.5191298e01, - 6.8637940e01, - 8.6115921e01, - 1.0903923e02, - 1.3938725e02, - 1.7995815e02, - 2.3474820e02, - 3.0952544e02, - 4.1270732e02, - 5.5671861e02, - 7.6011795e02, - 1.0509694e03, - 1.4722574e03, - 2.0906996e03, - 3.0112909e03, - 4.4016501e03, - 6.5333918e03, - 9.8535186e03, - 1.5109614e04, - 2.3573066e04, - 3.7444017e04, - 6.0599320e04, - 1.0000000e05, - ] - ) **2 +DEFAULT_Q2GRID = ( + np.array( + [ + 1.6500000e00, + 1.7874388e00, + 1.9429053e00, + 2.1193749e00, + 2.3204100e00, + 2.5502944e00, + 2.8142025e00, + 3.1184122e00, + 3.4705775e00, + 3.8800751e00, + 4.3584516e00, + 4.9200000e00, + 4.9200000e00, + 5.5493622e00, + 6.2897452e00, + 7.1650687e00, + 8.2052867e00, + 9.4481248e00, + 1.0941378e01, + 1.2745972e01, + 1.4940062e01, + 1.7624572e01, + 2.0930715e01, + 2.5030298e01, + 3.0149928e01, + 3.6590777e01, + 4.4756282e01, + 5.5191298e01, + 6.8637940e01, + 8.6115921e01, + 1.0903923e02, + 1.3938725e02, + 1.7995815e02, + 2.3474820e02, + 3.0952544e02, + 4.1270732e02, + 5.5671861e02, + 7.6011795e02, + 1.0509694e03, + 1.4722574e03, + 2.0906996e03, + 3.0112909e03, + 4.4016501e03, + 6.5333918e03, + 9.8535186e03, + 1.5109614e04, + 2.3573066e04, + 3.7444017e04, + 6.0599320e04, + 1.0000000e05, + ] + ) + ** 2 +) + class LhapdfLike: """ Class which emulates lhapdf but only for an initial condition PDF (i.e. with only one q2 value). - Q20 is the fitting scale fo the pdf and it is the only available scale for the objects of this class. + Q20 is the fitting scale fo the pdf and it is the only available scale for the objects of this class. X_GRID is the grid of x values on top of which the pdf is interpolated. - PDF_GRID is a dictionary containing the pdf grids at fitting scale for each pid. + PDF_GRID is a dictionary containing the pdf grids at fitting scale for each pid. """ def __init__(self, pdf_grid, q20, x_grid): @@ -76,13 +82,12 @@ def __init__(self, pdf_grid, q20, x_grid): self.q20 = q20 self.x_grid = x_grid self.funcs = [ - interp1d(self.x_grid, self.pdf_grid[pid], kind="cubic") - for pid in range(len(PIDS_DICT)) + interp1d(self.x_grid, self.pdf_grid[pid], kind="cubic") for pid in range(len(PIDS_DICT)) ] def xfxQ2(self, pid, x, q2): """Return the value of the PDF for the requested pid, x value and, whatever the requested - q2 value, for the fitting q2. + q2 value, for the fitting q2. Parameters ---------- @@ -122,15 +127,13 @@ def generate_q2grid(Q0, Qfin, Q_points, match_dict): """Generate the q2grid used in the final evolved pdfs or use the default grid if Qfin or Q_points is not provided. - match_dict contains the couples (mass : factor) where factor is the number to be multiplied to mass + match_dict contains the couples (mass : factor) where factor is the number to be multiplied to mass in order to obtain the relative matching scale. """ if Qfin is None and Q_points is None: return DEFAULT_Q2GRID elif Qfin is None or Q_points is None: - raise ValueError( - "q_fin and q_points must be specified either both or none of them" - ) + raise ValueError("q_fin and q_points must be specified either both or none of them") else: grids = [] Q_ini = Q0 @@ -139,13 +142,11 @@ def generate_q2grid(Q0, Qfin, Q_points, match_dict): match_scale = masses * match_dict[masses] # Fraction of the total points to be included in this batch is proportional # to the log of the ratio between the initial scale and final scale of the - # batch itself (normalized to the same log of the global initial and final - # scales) + # batch itself (normalized to the same log of the global initial and final + # scales) if match_scale < Qfin: frac_of_point = np.log(match_scale / Q_ini) / np.log(Qfin / Q0) - num_points = int( - Q_points * frac_of_point - ) + num_points = int(Q_points * frac_of_point) num_points_list.append(num_points) grids.append(np.geomspace(Q_ini**2, match_scale**2, num=num_points)) Q_ini = match_scale @@ -195,7 +196,9 @@ def check_is_a_fit(config_folder): usr_path = pathlib.Path(config_folder) filter_path = usr_path / "filter.yml" if not filter_path.is_file(): - raise ValueError("filter.yaml file not found: the path" + str(filter_path.absolute()) + " is not valid") + raise ValueError( + "filter.yaml file not found: the path" + str(filter_path.absolute()) + " is not valid" + ) nnfitpath = usr_path / "nnfit" if not nnfitpath.is_dir(): raise ValueError("nnfit folder not found: provided path is not valid") From 75bfa727f7131738b3659ff6a32e9c50ac44ec95 Mon Sep 17 00:00:00 2001 From: juacrumar Date: Wed, 7 Jun 2023 10:46:23 +0200 Subject: [PATCH 11/11] add styling commit to .git-blame-ignore-revs --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 7f7a499db7..e4c65ff0c4 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -12,3 +12,5 @@ b9084ce695c49b5645b82436b19ec6cc3bd30280 a5d7385a79ef242e7eb1b1bf7b3746b6ebd6a0d0 3e8cf70c2d3b36d19fcb764599f6dfa6eb924b77 27f25d037854caa7e15496e4c6fa9d520f365ac9 +# Restyling of evolven3fit_new +07d8d315aff44f98cb546e09088aa981e9778466