Skip to content

Commit 8a82001

Browse files
committed
Storing photon replicas in a dictionary
1 parent 215ca52 commit 8a82001

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

validphys2/src/validphys/photon/compute.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ def __init__(
6969
self.save_to_disk = save_to_disk
7070
self.q_in = q_in
7171
self.luxpdfset = lux_params["luxset"].load()
72-
self.luxpdfset_members = self.luxpdfset.n_members - 1 #
72+
self.luxpdfset_members = self.luxpdfset.n_members - 1
73+
self.path_to_eko_photon = self.theoryid.path / "eko_photon.tar"
7374

7475
# Compute or load photon_qin
7576
if force_computation:
@@ -88,15 +89,14 @@ def _load_photon(self):
8889
log.info(f"Loading photon QED set from {path_to_photon}")
8990

9091
# Load the needed replicas
91-
photon_qin_array = []
92+
photon_qin_array = {}
9293
for replica in self.replicas:
9394
# As input replica for the photon computation we take the MOD of the luxset_members to
9495
# avoid failing due to limited number of replicas in the luxset
9596
photonreplica = (replica % self.luxpdfset_members) or self.luxpdfset_members
9697
photon_qin = np.load(path_to_photon / f"replica_{photonreplica}.npz")["photon_qin"]
97-
photon_qin_array.append(photon_qin)
98+
photon_qin_array[replica] = photon_qin
9899

99-
photon_qin_array = np.stack(photon_qin_array, axis=0)
100100
return photon_qin_array
101101

102102
def _compute_photon_set(self):
@@ -149,7 +149,7 @@ def _compute_photon_set(self):
149149
)
150150
path_to_photon.mkdir(parents=True, exist_ok=True)
151151

152-
photon_qin_array = []
152+
photon_qin_array = {}
153153
for replica in replicas:
154154
# Avoid failing due to limited number of replicas in the luxset
155155
photonreplica = (replica % self.luxpdfset_members) or self.luxpdfset_members
@@ -180,9 +180,8 @@ def _compute_photon_set(self):
180180
)
181181
log.info(f"Saved photon replica {photonreplica} to {path_to_photon}")
182182

183-
photon_qin_array.append(photon_qin)
183+
photon_qin_array[replica] = photon_qin
184184

185-
photon_qin_array = np.stack(photon_qin_array, axis=0)
186185
return photon_qin_array
187186

188187
def _setup_fiatlux_runcard(self):
@@ -206,7 +205,7 @@ def _setup_fiatlux_runcard(self):
206205
@property
207206
def error_matrix(self):
208207
"""Generate error matrix to be used in generate_errors."""
209-
if "additional_errors" not in self.lux_params:
208+
if not self.lux_params["additional_errors"]:
210209
return None
211210
extra_set = self.lux_params["additional_errors"].load()
212211
qs = [self.q_in] * len(XGRID)
@@ -241,8 +240,7 @@ def _evolve(self):
241240
interpolator = []
242241
integral = []
243242

244-
path_to_eko_photon = self.theoryid.path / "eko_photon.tar"
245-
with EKO.read(path_to_eko_photon) as eko_photon:
243+
with EKO.read(self.path_to_eko_photon) as eko_photon:
246244
# Check that qin mathces with the one in the EKO
247245
if not np.isclose(self.q_in, np.sqrt(eko_photon.mu20)):
248246
log.error(
@@ -262,7 +260,7 @@ def _evolve(self):
262260
pdfs_init = np.zeros_like(eko_op[0, 0])
263261
for j, pid in enumerate(basis_rotation.flavor_basis_pids):
264262
if pid == 22:
265-
pdfs_init[j] = photon_qin_array[replica - 1]
263+
pdfs_init[j] = photon_qin_array[replica]
266264
ph_id = j
267265
elif pid not in self.luxpdfset.flavors:
268266
continue

validphys2/src/validphys/tests/photon/test_compute.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ def test_parameters_init():
3737
# we are not testing the photon here so we make it faster
3838
fiatlux_runcard['eps_base'] = 1e-1
3939

40-
photon = Photon(test_theory, fiatlux_runcard, [1, 2, 3])
40+
photon = Photon(
41+
test_theory, fiatlux_runcard, [1, 2, 3], save_to_disk=False, force_computation=True
42+
)
4143

4244
np.testing.assert_equal(photon.replicas, [1, 2, 3])
4345
np.testing.assert_equal(photon.luxpdfset._name, fiatlux_runcard["luxset"].name)
44-
np.testing.assert_equal(photon.additional_errors.name, "LUXqed17_plus_PDF4LHC15_nnlo_100")
45-
np.testing.assert_equal(photon.luxseed, fiatlux_runcard["luxseed"])
46+
np.testing.assert_equal(
47+
photon.lux_params["additional_errors"].name, "LUXqed17_plus_PDF4LHC15_nnlo_100"
48+
)
49+
np.testing.assert_equal(photon.lux_params["luxseed"], fiatlux_runcard["luxseed"])
4650
np.testing.assert_equal(photon.path_to_eko_photon, test_theory.path / "eko_photon.tar")
4751
np.testing.assert_equal(photon.q_in, 100.0)
4852

@@ -58,7 +62,9 @@ def test_photon():
5862
theory = test_theory.get_description()
5963

6064
for replica in [1, 2, 3]:
61-
photon = Photon(test_theory, fiatlux_runcard, [replica])
65+
photon = Photon(
66+
test_theory, fiatlux_runcard, [replica], save_to_disk=False, force_computation=True
67+
)
6268

6369
# set up fiatlux
6470
path_to_F2 = test_theory.path / "fastkernel/FIATLUX_DIS_F2.pineappl.lz4"

0 commit comments

Comments
 (0)