From 40bc7bcb6dbfedf92d15011a71657cd37bfc5b49 Mon Sep 17 00:00:00 2001 From: niclaurenti Date: Thu, 22 Jun 2023 15:43:08 +0200 Subject: [PATCH] Call api inside tests --- validphys2/src/validphys/photon/compute.py | 9 ++++--- .../validphys/tests/photon/test_compute.py | 26 +++++++++++-------- .../tests/photon/test_structurefunctions.py | 17 ++++++------ 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/validphys2/src/validphys/photon/compute.py b/validphys2/src/validphys/photon/compute.py index 52c3b04c78..c9a5805f07 100644 --- a/validphys2/src/validphys/photon/compute.py +++ b/validphys2/src/validphys/photon/compute.py @@ -81,7 +81,6 @@ def __init__(self, theoryid, lux_params, replicas): self.path_to_eko_photon = theoryid.path / "eko_photon.tar" with EKO.read(self.path_to_eko_photon) as eko: self.q_in = np.sqrt(eko.mu20) - # set fiatlux self.lux = {} @@ -121,7 +120,9 @@ 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="extrapolate", 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): @@ -140,7 +141,9 @@ def compute_photon_array(self, replica): """ # Compute photon PDF log.info(f"Computing photon") - photon_qin = np.array([self.lux[replica].EvaluatePhoton(x, self.q_in**2).total for x in XGRID]) + photon_qin = np.array( + [self.lux[replica].EvaluatePhoton(x, self.q_in**2).total for x in XGRID] + ) photon_qin += self.generate_errors(replica) # fiatlux computes x * gamma(x) photon_qin /= XGRID diff --git a/validphys2/src/validphys/tests/photon/test_compute.py b/validphys2/src/validphys/tests/photon/test_compute.py index c5ad3dc74c..82787e7492 100644 --- a/validphys2/src/validphys/tests/photon/test_compute.py +++ b/validphys2/src/validphys/tests/photon/test_compute.py @@ -14,7 +14,6 @@ from ..conftest import PDF, THEORY_QED -TEST_THEORY = API.theoryid(theoryid=THEORY_QED) def generate_fiatlux_runcard(): return { @@ -29,23 +28,25 @@ def generate_fiatlux_runcard(): def test_parameters_init(): "test initailization of the parameters from Photon class" fiatlux_runcard = generate_fiatlux_runcard() + test_theory = API.theoryid(theoryid=THEORY_QED) # 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]) + photon = Photon(test_theory, fiatlux_runcard, [1, 2, 3]) 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.luxseed, fiatlux_runcard["luxseed"]) - np.testing.assert_equal(photon.path_to_eko_photon, TEST_THEORY.path / "eko_photon.tar") + np.testing.assert_equal(photon.path_to_eko_photon, test_theory.path / "eko_photon.tar") np.testing.assert_equal(photon.q_in, 100.0) def test_masses_init(): "test thresholds values in Alpha class" - theory = TEST_THEORY.get_description() + test_theory = API.theoryid(theoryid=THEORY_QED) + 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, theory["mb"]) @@ -54,7 +55,8 @@ def test_masses_init(): def test_set_thresholds_alpha_em(): "test value of alpha_em at threshold values" - theory = TEST_THEORY.get_description() + test_theory = API.theoryid(theoryid=THEORY_QED) + theory = test_theory.get_description() alpha = Alpha(theory) @@ -77,7 +79,8 @@ def test_set_thresholds_alpha_em(): def test_betas(): "test betas for different nf" - alpha = Alpha(TEST_THEORY.get_description()) + test_theory = API.theoryid(theoryid=THEORY_QED) + alpha = Alpha(test_theory.get_description()) vec_beta0 = [ -0.5305164769729844, -0.6719875374991137, @@ -101,14 +104,15 @@ def test_photon(): """ fiatlux_runcard = generate_fiatlux_runcard() fiatlux_runcard["additional_errors"] = False - theory = TEST_THEORY.get_description() + test_theory = API.theoryid(theoryid=THEORY_QED) + theory = test_theory.get_description() for replica in [1, 2, 3]: - photon = Photon(TEST_THEORY, fiatlux_runcard, [replica]) + 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" + 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]) @@ -137,7 +141,7 @@ def test_photon(): ] ) lux.PlugStructureFunctions(f2.fxq, fl.fxq, f2lo.fxq) - path_to_eko_photon = TEST_THEORY.path / "eko_photon.tar" + path_to_eko_photon = test_theory.path / "eko_photon.tar" 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 diff --git a/validphys2/src/validphys/tests/photon/test_structurefunctions.py b/validphys2/src/validphys/tests/photon/test_structurefunctions.py index f45cf94527..5e83e6458f 100644 --- a/validphys2/src/validphys/tests/photon/test_structurefunctions.py +++ b/validphys2/src/validphys/tests/photon/test_structurefunctions.py @@ -7,8 +7,6 @@ from ..conftest import PDF, THEORY_QED -TEST_THEORY = API.theoryid(theoryid=THEORY_QED) - class ZeroPdfs: def xfxQ(self, x, Q): @@ -44,9 +42,10 @@ def convolute_with_one(self, pdgid, xfxQ2): 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" + test_theory = API.theoryid(theoryid=THEORY_QED) + 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" f2 = sf.InterpStructureFunction(path_to_F2, pdfs) fl = sf.InterpStructureFunction(path_to_FL, pdfs) @@ -76,10 +75,11 @@ def test_params(): "test initialization of parameters" pdfs = PDFset(PDF).load() replica = 1 - theory = TEST_THEORY.get_description() + test_theory = API.theoryid(theoryid=THEORY_QED) + theory = test_theory.get_description() for channel in ["F2", "FL"]: tmp = "fastkernel/fiatlux_dis_" + channel + ".pineappl.lz4" - path_to_fktable = TEST_THEORY.path / tmp + path_to_fktable = test_theory.path / tmp struct_func = sf.InterpStructureFunction(path_to_fktable, pdfs.members[replica]) np.testing.assert_allclose(struct_func.q2_max, 1e8) f2lo = sf.F2LO(pdfs.members[replica], theory) @@ -91,10 +91,11 @@ def test_params(): def test_interpolation_grid(): """test that the values coming out of InterpStructureFunction match the grid ones""" pdfs = PDFset(PDF).load() + test_theory = API.theoryid(theoryid=THEORY_QED) 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 + 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))