Skip to content

Commit

Permalink
added a test for eko convolution and LHAPDF info files
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlehoff committed Jun 6, 2023
1 parent c700c27 commit 5ad09fe
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 59 deletions.
50 changes: 25 additions & 25 deletions n3fit/src/n3fit/tests/regressions/quickcard_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
66 changes: 33 additions & 33 deletions n3fit/src/n3fit/tests/regressions/quickcard_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"fl": "sng",
"smallx": 1.1098793745040894,
"largex": 2.694117546081543,
"largex": 2.6941299438476562,
"trainable": true
},
{
Expand All @@ -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
},
{
Expand All @@ -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"
}
}
46 changes: 45 additions & 1 deletion n3fit/src/n3fit/tests/test_evolven3fit.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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, {})
Expand Down Expand Up @@ -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)

0 comments on commit 5ad09fe

Please sign in to comment.