Skip to content

Commit 3010e41

Browse files
committed
workaround for eko==0.13.4
1 parent 805321a commit 3010e41

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

n3fit/src/evolven3fit/evolve.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,40 @@ def evolve_fit(
9696
else:
9797
raise ValueError(f"dump_eko not provided and {eko_path=} not found")
9898

99-
with eko.EKO.edit(eko_path) as eko_op:
99+
# Assume the EKO can be used with no rotation and open it in read-only mode
100+
# inside a try-finally block to make sure the eko is closed at the end
101+
try:
102+
eko_op = eko.EKO.read(eko_path)
103+
100104
# Read the cards directly from the eko to make sure they are consistent
101105
theory = eko_op.theory_card
102106
op = eko_op.operator_card
103107
# And dump them to the log
104108
_logger.debug(f"Theory card: {json.dumps(theory.raw)}")
105109
_logger.debug(f"Operator card: {json.dumps(op.raw)}")
106110

111+
# Check whether it needs to be modified
112+
eko_xgrid = eko_op.xgrid
113+
if XGrid(x_grid) != eko_xgrid:
114+
eko_op.close()
115+
eko_op = eko.EKO.edit(eko_path)
116+
117+
# This is a workaround for EKOS created with 0.13.4
118+
# in 0.13.4 the xgrid corresponds to the (internal) interpolation grid
119+
if eko_op.metadata.version == "0.13.4":
120+
# Prepare an "identity" rotation
121+
eko_xgrid = XGrid(x_grid)
122+
123+
for i, elem in eko_op.items():
124+
eko_op[i] = manipulate.xgrid_reshape(
125+
elem,
126+
eko_xgrid,
127+
op.configs.interpolation_polynomial_degree,
128+
targetgrid=XGrid(x_grid),
129+
inputgrid=XGrid(x_grid),
130+
)
131+
eko_op.xgrid = XGrid(x_grid)
132+
107133
# Modify the info file with the fit-specific info
108134
info = info_file.build(theory, op, 1, info_update={})
109135
info["NumMembers"] = "REPLACE_NREP"
@@ -125,17 +151,6 @@ def evolve_fit(
125151
# and divide by x
126152
all_replicas.append(pdfgrid.T / x_grid)
127153

128-
# reshape the xgrid eko if necessary
129-
if XGrid(x_grid) != eko_op.xgrid:
130-
for _, elem in eko_op.items():
131-
elem = manipulate.xgrid_reshape(
132-
elem,
133-
eko_op.xgrid,
134-
op.configs.interpolation_polynomial_degree,
135-
targetgrid=XGrid(x_grid),
136-
inputgrid=XGrid(x_grid),
137-
)
138-
139154
# output is {(Q2, nf): (replica, flavour, x)}
140155
all_evolved, _ = apply.apply_grids(eko_op, np.array(all_replicas))
141156

@@ -163,9 +178,11 @@ def pdf_xq2(pid, x, Q2):
163178
)
164179
blocks.append(block)
165180
dump_evolved_replica(blocks, usr_path, replica + 1)
181+
finally:
182+
eko_op.close()
166183

167184
# remove folder:
168-
# The function dump_evolved_replica dumps the replica files in a temporary folder
185+
# The function dump_evolved_replica uses a temporary folder
169186
# We need then to remove it after fixing the position of those replica files
170187
(usr_path / "nnfit" / usr_path.stem).rmdir()
171188

0 commit comments

Comments
 (0)