Skip to content

Commit ace8683

Browse files
giacomomagniscarlehoff
authored andcommitted
add evolve reshape
1 parent cd76fc1 commit ace8683

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

n3fit/src/evolven3fit/evolve.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
import sys
66

77
from ekobox import apply, genpdf, info_file
8-
from joblib import Parallel, delayed
98
import numpy as np
10-
import psutil
119

1210
import eko
11+
from eko.interpolation import XGrid
12+
from eko.io import manipulate
1313
from eko import basis_rotation, runner
1414
from validphys.utils import yaml_safe
1515

@@ -24,8 +24,6 @@
2424
"level": logging.DEBUG,
2525
}
2626

27-
NUM_CORES = psutil.cpu_count(logical=False)
28-
2927

3028
def evolve_fit(
3129
fit_folder,
@@ -106,11 +104,7 @@ def evolve_fit(
106104
else:
107105
raise ValueError(f"dump_eko not provided and {eko_path=} not found")
108106

109-
# with eko.EKO.edit(eko_path) as eko_op:
110-
# x_grid_obj = eko.interpolation.XGrid(x_grid)
111-
# eko.io.manipulate.xgrid_reshape(eko_op, targetgrid=x_grid_obj, inputgrid=x_grid_obj)
112-
113-
with eko.EKO.read(eko_path) as eko_op:
107+
with eko.EKO.edit(eko_path) as eko_op:
114108
# Read the cards directly from the eko to make sure they are consistent
115109
theory = eko_op.theory_card
116110
op = eko_op.operator_card
@@ -126,19 +120,29 @@ def evolve_fit(
126120
info["XMax"] = float(x_grid[-1])
127121
# Save the PIDs in the info file in the same order as in the evolution
128122
info["Flavors"] = basis_rotation.flavor_basis_pids
129-
info["NumFlavors"] = 5 # TODO: Maximum number in evol
123+
info["NumFlavors"] = 5 # TODO: Maximum number in evol
130124
dump_info_file(usr_path, info)
131125

132126
# Read the information from all replicas into what eko wants:
133127
all_replicas = []
134128
for pdf_data in initial_PDFs_dict.values():
135129
all_replicas.append(np.array(pdf_data["pdfgrid"]).T)
136130

131+
# reshape the xgrid eko if necessary
132+
for _, elem in eko_op.items():
133+
elem = manipulate.xgrid_reshape(
134+
elem,
135+
eko_op.xgrid,
136+
op.configs.interpolation_polynomial_degree,
137+
targetgrid=XGrid(x_grid),
138+
inputgrid=XGrid(x_grid),
139+
)
140+
137141
all_evolved, _ = apply.apply_grids(eko_op, np.array(all_replicas))
138-
#{(Q2, nf): (replica, flavour, x)}
142+
# {(Q2, nf): (replica, flavour, x)}
139143
nreplicas = len(all_replicas)
140-
all_evolved = [{i: k[r] for i,k in all_evolved.items()} for r in range(nreplicas)]
141-
144+
all_evolved = [{i: k[r] for i, k in all_evolved.items()} for r in range(nreplicas)]
145+
142146
# Now, replica by replica, break into blocks
143147
targetgrid = eko_op.xgrid.tolist()
144148
by_nf = defaultdict(list)
@@ -154,10 +158,12 @@ def pdf_xq2(pid, x, Q2):
154158
x_idx = targetgrid.index(x)
155159
pid_idx = info["Flavors"].index(pid)
156160
return x * evolved_pdf[(Q2, nf)][pid_idx][x_idx]
157-
# return x * evolved_pdf[(Q2, nf)]["pdfs"][pid][x_idx]
158161

159162
block = genpdf.generate_block(
160-
pdf_xq2, xgrid=targetgrid, sorted_q2grid=q2grid, pids=basis_rotation.flavor_basis_pids
163+
pdf_xq2,
164+
xgrid=targetgrid,
165+
sorted_q2grid=q2grid,
166+
pids=basis_rotation.flavor_basis_pids,
161167
)
162168
blocks.append(block)
163169

@@ -213,7 +219,6 @@ def evolve_exportgrid(exportgrid, eko, x_grid):
213219
# construct LhapdfLike object
214220
pdf_grid = np.array(exportgrid["pdfgrid"]).transpose()
215221

216-
217222
pdf_to_evolve = utils.LhapdfLike(pdf_grid, exportgrid["q20"], x_grid)
218223
# evolve pdf
219224
evolved_pdf = apply.apply_pdf(eko, pdf_to_evolve)

0 commit comments

Comments
 (0)