@@ -96,14 +96,40 @@ def evolve_fit(
96
96
else :
97
97
raise ValueError (f"dump_eko not provided and { eko_path = } not found" )
98
98
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
+
100
104
# Read the cards directly from the eko to make sure they are consistent
101
105
theory = eko_op .theory_card
102
106
op = eko_op .operator_card
103
107
# And dump them to the log
104
108
_logger .debug (f"Theory card: { json .dumps (theory .raw )} " )
105
109
_logger .debug (f"Operator card: { json .dumps (op .raw )} " )
106
110
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
+
107
133
# Modify the info file with the fit-specific info
108
134
info = info_file .build (theory , op , 1 , info_update = {})
109
135
info ["NumMembers" ] = "REPLACE_NREP"
@@ -125,17 +151,6 @@ def evolve_fit(
125
151
# and divide by x
126
152
all_replicas .append (pdfgrid .T / x_grid )
127
153
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
-
139
154
# output is {(Q2, nf): (replica, flavour, x)}
140
155
all_evolved , _ = apply .apply_grids (eko_op , np .array (all_replicas ))
141
156
@@ -163,9 +178,11 @@ def pdf_xq2(pid, x, Q2):
163
178
)
164
179
blocks .append (block )
165
180
dump_evolved_replica (blocks , usr_path , replica + 1 )
181
+ finally :
182
+ eko_op .close ()
166
183
167
184
# 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
169
186
# We need then to remove it after fixing the position of those replica files
170
187
(usr_path / "nnfit" / usr_path .stem ).rmdir ()
171
188
0 commit comments