Skip to content

Commit cd76fc1

Browse files
committed
first batch of changes necessary
1 parent 17b53d3 commit cd76fc1

File tree

2 files changed

+68
-21
lines changed

2 files changed

+68
-21
lines changed

n3fit/src/evolven3fit/eko_utils.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22
from typing import Any, Dict, Optional
33

4-
from ekobox.cards import _operator as default_op_card
54
import numpy as np
65

76
from eko.io import runcards
@@ -56,8 +55,7 @@ def construct_eko_cards(
5655
theory["MaxNfAs"] = theory["MaxNfPdf"]
5756

5857
# The Legacy function is able to construct a theory card for eko starting from a NNPDF theory
59-
legacy_class = runcards.Legacy(theory, {})
60-
theory_card = legacy_class.new_theory
58+
theory_card = runcards.Legacy(theory, {}).new_theory
6159

6260
# construct mugrid
6361

@@ -129,8 +127,7 @@ def construct_eko_photon_cards(
129127
theory["MaxNfAs"] = theory["MaxNfPdf"]
130128

131129
# The Legacy function is able to construct a theory card for eko starting from a NNPDF theory
132-
legacy_class = runcards.Legacy(theory, {})
133-
theory_card = legacy_class.new_theory
130+
theory_card = runcards.Legacy(theory, {}).new_theory
134131

135132
# The photon needs to be evolved down to Q0
136133
q_fin = theory["Q0"]
@@ -177,10 +174,34 @@ def build_opcard(op_card_dict, theory, x_grid, mu0, mugrid):
177174
if op_card_dict is None:
178175
op_card_dict = {}
179176

180-
op_card = default_op_card
181-
182-
op_card.update({"mu0": mu0, "mugrid": mugrid})
177+
# Taken from cards.py https://github.com/NNPDF/eko/blob/master/src/ekobox/cards.py
178+
# 7735fdb
179+
op_card = dict(
180+
init=(1.65, 4),
181+
mugrid=[(100.0, 5)],
182+
xgrid=np.geomspace(1e-7, 1.0, 50).tolist(),
183+
configs=dict(
184+
# These three values might be set by op_card_dict
185+
ev_op_iterations=10,
186+
n_integration_cores=1,
187+
polarized=False,
188+
#
189+
ev_op_max_order=[10, 0],
190+
interpolation_polynomial_degree=4,
191+
interpolation_is_log=True,
192+
scvar_method=None,
193+
inversion_method=None,
194+
evolution_method="iterate-exact",
195+
time_like=False,
196+
),
197+
debug=dict(
198+
skip_singlet=False,
199+
skip_non_singlet=False,
200+
),
201+
)
183202

203+
op_card["init"] = (mu0, theory["nf0"])
204+
op_card["mugrid"] = mugrid
184205
op_card["xgrid"] = x_grid
185206

186207
# Specify the evolution options and defaults differently from TRN / EXA

n3fit/src/evolven3fit/evolve.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ def evolve_fit(
106106
else:
107107
raise ValueError(f"dump_eko not provided and {eko_path=} not found")
108108

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)
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)
112112

113113
with eko.EKO.read(eko_path) as eko_op:
114114
# Read the cards directly from the eko to make sure they are consistent
@@ -126,18 +126,42 @@ def evolve_fit(
126126
info["XMax"] = float(x_grid[-1])
127127
# Save the PIDs in the info file in the same order as in the evolution
128128
info["Flavors"] = basis_rotation.flavor_basis_pids
129-
info["NumFlavors"] = theory.heavy.num_flavs_max_pdf
129+
info["NumFlavors"] = 5 # TODO: Maximum number in evol
130130
dump_info_file(usr_path, info)
131131

132-
def _wrap_evolve(pdf, replica):
133-
evolved_blocks = evolve_exportgrid(pdf, eko_op, x_grid)
134-
dump_evolved_replica(evolved_blocks, usr_path, int(replica.removeprefix("replica_")))
135-
136-
# Choose the number of cores to be the Minimal value
137-
nb_cores = min(NUM_CORES, abs(ncores))
138-
Parallel(n_jobs=nb_cores)(
139-
delayed(_wrap_evolve)(pdf, r) for r, pdf in initial_PDFs_dict.items()
140-
)
132+
# Read the information from all replicas into what eko wants:
133+
all_replicas = []
134+
for pdf_data in initial_PDFs_dict.values():
135+
all_replicas.append(np.array(pdf_data["pdfgrid"]).T)
136+
137+
all_evolved, _ = apply.apply_grids(eko_op, np.array(all_replicas))
138+
#{(Q2, nf): (replica, flavour, x)}
139+
nreplicas = len(all_replicas)
140+
all_evolved = [{i: k[r] for i,k in all_evolved.items()} for r in range(nreplicas)]
141+
142+
# Now, replica by replica, break into blocks
143+
targetgrid = eko_op.xgrid.tolist()
144+
by_nf = defaultdict(list)
145+
for q, nf in sorted(eko_op.evolgrid, key=lambda ep: ep[1]):
146+
by_nf[nf].append(q)
147+
q2block_per_nf = {nf: sorted(qs) for nf, qs in by_nf.items()}
148+
149+
for replica, evolved_pdf in enumerate(all_evolved):
150+
blocks = []
151+
for nf, q2grid in q2block_per_nf.items():
152+
153+
def pdf_xq2(pid, x, Q2):
154+
x_idx = targetgrid.index(x)
155+
pid_idx = info["Flavors"].index(pid)
156+
return x * evolved_pdf[(Q2, nf)][pid_idx][x_idx]
157+
# return x * evolved_pdf[(Q2, nf)]["pdfs"][pid][x_idx]
158+
159+
block = genpdf.generate_block(
160+
pdf_xq2, xgrid=targetgrid, sorted_q2grid=q2grid, pids=basis_rotation.flavor_basis_pids
161+
)
162+
blocks.append(block)
163+
164+
dump_evolved_replica(blocks, usr_path, int(replica + 1))
141165

142166
# remove folder:
143167
# The function dump_evolved_replica dumps the replica files in a temporary folder
@@ -188,6 +212,8 @@ def evolve_exportgrid(exportgrid, eko, x_grid):
188212
"""
189213
# construct LhapdfLike object
190214
pdf_grid = np.array(exportgrid["pdfgrid"]).transpose()
215+
216+
191217
pdf_to_evolve = utils.LhapdfLike(pdf_grid, exportgrid["q20"], x_grid)
192218
# evolve pdf
193219
evolved_pdf = apply.apply_pdf(eko, pdf_to_evolve)

0 commit comments

Comments
 (0)