Skip to content

Commit

Permalink
make notation mor uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomomagni committed Jul 24, 2024
1 parent 96ec886 commit 807fc02
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 62 deletions.
4 changes: 2 additions & 2 deletions benchmarks/bench_theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ def benchmark_fk(test_files, test_configs):
)
theory_obj_hera.opcard(grid_name, pathlib.Path(test_files / grid_path), tcard)

theory_obj_hera.fk(grid_name, grid_path, tcard, pdf_a=None, pdf_b=None)
theory_obj_hera.fk(grid_name, grid_path, tcard, pdf1=None, pdf2=None)
# test overwrite function
theory_obj_hera.fk(grid_name, grid_path, tcard, pdf_a=None, pdf_b=None)
theory_obj_hera.fk(grid_name, grid_path, tcard, pdf1=None, pdf2=None)
log_path = pathlib.Path(test_files / "logs/fk/400-HERA_NC_225GEV_EP_SIGMARED.log")
if os.path.exists(log_path):
os.remove(log_path)
Expand Down
10 changes: 5 additions & 5 deletions src/pineko/cli/convolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def subcommand(
"""
grid = pineappl.grid.Grid.read(grid_path)
n_ekos = len(op_paths)
with eko.EKO.edit(op_paths[0]) as operators_a:
with eko.EKO.edit(op_paths[0]) as operators1:
rich.print(
rich.panel.Panel.fit("Computing ...", style="magenta", box=rich.box.SQUARE),
f" {grid_path}\n",
Expand All @@ -80,7 +80,7 @@ def subcommand(
if n_ekos == 1:
_grid, _fk, comp = evolve.evolve_grid(
grid,
operators_a,
operators1,
fktable,
max_as,
max_al,
Expand All @@ -92,16 +92,16 @@ def subcommand(
min_as=min_as,
)
else:
with eko.EKO.edit(op_paths[1]) as operators_b:
with eko.EKO.edit(op_paths[1]) as operators2:
_grid, _fk, comp = evolve.evolve_grid(
grid,
operators_a,
operators1,
fktable,
max_as,
max_al,
xir,
xif,
operators_b=operators_b,
operators2=operators2,
assumptions=assumptions,
comparison_pdf1=pdf1,
comparison_pdf2=pdf2,
Expand Down
52 changes: 25 additions & 27 deletions src/pineko/evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def write_operator_card(pineappl_grid, default_card, card_path, tcard):

# switch on polarization ?
kv = pineappl_grid.key_values()
conv_type_a, conv_type_b = get_ekos_convolution_type(kv)
conv_type_1, conv_type_2 = get_ekos_convolution_type(kv)

# fragmentation function grid?
if "timelike" in kv:
Expand Down Expand Up @@ -258,26 +258,26 @@ def dump_card(card_path, operators_card, conv_type, suffix=False):

# For hardonic obs we might need to dump 2 eko cards

if conv_type_b is None or conv_type_a == conv_type_b:
dump_card(card_path, operators_card, conv_type_a)
if conv_type_2 is None or conv_type_1 == conv_type_2:
dump_card(card_path, operators_card, conv_type_1)
else:
# dump card_a
dump_card(card_path, operators_card, conv_type_a, suffix=True)
dump_card(card_path, operators_card, conv_type_1, suffix=True)
# dump card_b
dump_card(card_path, operators_card, conv_type_b, suffix=True)
dump_card(card_path, operators_card, conv_type_2, suffix=True)

return operators_card["xgrid"], q2_grid


def evolve_grid(
grid,
operators_a,
operators1,
fktable_path,
max_as,
max_al,
xir,
xif,
operators_b=None,
operators2=None,
assumptions="Nf6Ind",
comparison_pdf1=None,
comparison_pdf2=None,
Expand All @@ -290,7 +290,7 @@ def evolve_grid(
----------
grid : pineappl.grid.Grid
unconvolved grid
operators_a : eko.EKO
operators1 : eko.EKO
evolution operator
fktable_path : str
target path for convolved grid
Expand All @@ -302,8 +302,8 @@ def evolve_grid(
renormalization scale variation
xif : float
factorization scale variation
operators_b: eko.EKO
additonal evolution operator if different from operators_a
operators2: eko.EKO
additonal evolution operator if different from operators1
assumptions : str
assumptions on the flavor dimension
comparison_pdf1 : None or str
Expand All @@ -327,9 +327,9 @@ def evolve_grid(
evol_info = grid.evolve_info(order_mask)
x_grid = evol_info.x1
mur2_grid = evol_info.ren1
xif = 1.0 if operators_a.operator_card.configs.scvar_method is not None else xif
tcard = operators_a.theory_card
opcard = operators_a.operator_card
xif = 1.0 if operators1.operator_card.configs.scvar_method is not None else xif
tcard = operators1.theory_card
opcard = operators1.operator_card
# rotate the targetgrid
if "integrability_version" in grid.key_values():
x_grid = np.append(x_grid, 1.0)
Expand All @@ -346,9 +346,9 @@ def xgrid_reshape(operators):
elif not np.allclose(operators.bases.inputpids, br.rotate_flavor_to_evolution):
raise ValueError("The EKO is neither in flavor nor in evolution basis.")

xgrid_reshape(operators_a)
if operators_b is not None:
xgrid_reshape(operators_b)
xgrid_reshape(operators1)
if operators2 is not None:
xgrid_reshape(operators2)

# PineAPPL wants alpha_s = 4*pi*a_s
# remember that we already accounted for xif in the opcard generation
Expand Down Expand Up @@ -389,33 +389,31 @@ def prepare(operator, items):
)
return (info, op.operator)

if operators_b is not None:
if operators2 is not None:
fktable = grid.evolve_with_slice_iter2(
map(lambda it: prepare(operators_a, it), operators_a.items()),
map(lambda it: prepare(operators_b, it), operators_b.items()),
map(lambda it: prepare(operators1, it), operators1.items()),
map(lambda it: prepare(operators2, it), operators2.items()),
alphas_table=alphas_values,
xi=(xir, xif),
order_mask=order_mask,
)
else:
fktable = grid.evolve_with_slice_iter(
map(lambda it: prepare(operators_a, it), operators_a.items()),
map(lambda it: prepare(operators1, it), operators1.items()),
ren1=mur2_grid,
alphas=alphas_values,
xi=(xir, xif),
order_mask=order_mask,
)
rich.print(f"Optimizing for {assumptions}")
fktable.optimize(PyFkAssumptions(assumptions))
fktable.set_key_value("eko_version", operators_a.metadata.version)
fktable.set_key_value("eko_theory_card", json.dumps(operators_a.theory_card.raw))
fktable.set_key_value("eko_version", operators1.metadata.version)
fktable.set_key_value("eko_theory_card", json.dumps(operators1.theory_card.raw))

fktable.set_key_value(
"eko_operator_card", json.dumps(operators_a.operator_card.raw)
)
if operators_b is not None:
fktable.set_key_value("eko_operator_card", json.dumps(operators1.operator_card.raw))
if operators2 is not None:
fktable.set_key_value(
"eko_operator_card_b", json.dumps(operators_b.operator_card.raw)
"eko_operator_card_b", json.dumps(operators2.operator_card.raw)
)

fktable.set_key_value("pineko_version", version.__version__)
Expand Down
56 changes: 28 additions & 28 deletions src/pineko/theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ def get_eko_names(grid_path, name):
grid name, i.e. it's true stem
"""
grid_kv = pineappl.grid.Grid.read(grid_path).key_values()
conv_type_a, conv_type_b = evolve.get_ekos_convolution_type(grid_kv)
conv_type_1, conv_type_2 = evolve.get_ekos_convolution_type(grid_kv)
names = []
if conv_type_b is None or conv_type_a == conv_type_b:
if conv_type_2 is None or conv_type_1 == conv_type_2:
names = [name]
else:
names = [
f"{name}_{conv_type_a}",
f"{name}_{conv_type_b}",
f"{name}_{conv_type_1}",
f"{name}_{conv_type_2}",
]
return names

Expand Down Expand Up @@ -389,7 +389,7 @@ def ekos(self):
self.ekos_path().mkdir(exist_ok=True)
self.iterate(self.eko, tcard=tcard)

def fk(self, name, grid_path, tcard, pdf_a, pdf_b):
def fk(self, name, grid_path, tcard, pdf1, pdf2):
"""Compute a single FK table.
Parameters
Expand All @@ -400,15 +400,15 @@ def fk(self, name, grid_path, tcard, pdf_a, pdf_b):
path to grid
tcard : dict
theory card
pdf_a : str
pdf1 : str
comparison PDF
pdf_b : str
pdf2 : str
comparison PDF
"""
# activate logging
paths = configs.configs["paths"]
do_log = self.activate_logging(
paths["logs"]["fk"], f"{self.theory_id}-{name}-{pdf_a}-{pdf_b}.log"
paths["logs"]["fk"], f"{self.theory_id}-{name}-{pdf1}-{pdf2}.log"
)

# Relevant for FONLL-B and FONLL-D: For FFN0 terms, PTO is lower than
Expand Down Expand Up @@ -466,27 +466,27 @@ def fk(self, name, grid_path, tcard, pdf_a, pdf_b):
check_scvar_evolve(grid, max_as, max_al, check.Scale.FACT)
# loading ekos to produce a tmp copy
n_ekos = len(eko_filename)
with eko.EKO.read(eko_filename[0]) as operators_a:
with eko.EKO.read(eko_filename[0]) as operators1:

# Skip the computation of the fktable if the eko is empty
if len(operators_a.mu2grid) == 0 and check.is_num_fonll(tcard["FNS"]):
if len(operators1.mu2grid) == 0 and check.is_num_fonll(tcard["FNS"]):
rich.print("[green] Skipping empty eko for nFONLL.")
return

eko_tmp_path_a = (
operators_a.paths.root.parent / f"eko-tmp-{name}-{np.random.rand()}.tar"
operators1.paths.root.parent / f"eko-tmp-{name}-{np.random.rand()}.tar"
)
operators_a.deepcopy(eko_tmp_path_a)
operators1.deepcopy(eko_tmp_path_a)

if n_ekos > 1:
with eko.EKO.read(eko_filename[1]) as operators_b:
with eko.EKO.read(eko_filename[1]) as operators2:
eko_tmp_path_b = (
operators_a.paths.root.parent
operators1.paths.root.parent
/ f"eko-tmp-{name}-{np.random.rand()}.tar"
)
operators_b.deepcopy(eko_tmp_path_b)
operators2.deepcopy(eko_tmp_path_b)

with eko.EKO.edit(eko_tmp_path_a) as operators_a:
with eko.EKO.edit(eko_tmp_path_a) as operators1:
# Obtain the assumptions hash
assumptions = theory_card.construct_assumptions(tcard)
# do it!
Expand All @@ -512,30 +512,30 @@ def fk(self, name, grid_path, tcard, pdf_a, pdf_b):
if n_ekos == 1:
_grid, _fk, comparison = evolve.evolve_grid(
grid,
operators_a,
operators1,
fk_filename,
max_as,
max_al,
xir=xir,
xif=xif,
assumptions=assumptions,
comparison_pdf1=pdf_a,
comparison_pdf1=pdf1,
meta_data={"theory_card": json.dumps(tcard)},
)
else:
with eko.EKO.edit(eko_tmp_path_b) as operators_b:
with eko.EKO.edit(eko_tmp_path_b) as operators2:
_grid, _fk, comparison = evolve.evolve_grid(
grid,
operators_a,
operators1,
fk_filename,
max_as,
max_al,
xir=xir,
xif=xif,
assumptions=assumptions,
operators_b=operators_b,
comparison_pdf1=pdf_a,
comparison_pdf2=pdf_b,
operators2=operators2,
comparison_pdf1=pdf1,
comparison_pdf2=pdf2,
meta_data={"theory_card": json.dumps(tcard)},
)
# Remove tmp ekos
Expand All @@ -551,24 +551,24 @@ def fk(self, name, grid_path, tcard, pdf_a, pdf_b):
)
if do_log and comparison is not None:
logger.info(
"Comparison with %s %s:\n %s", pdf_a, pdf_b, comparison.to_string()
"Comparison with %s %s:\n %s", pdf1, pdf2, comparison.to_string()
)
if fk_filename.exists():
rich.print(f"[green]Success:[/] Wrote FK table to {fk_filename}")

def fks(self, pdf_a, pdf_b):
def fks(self, pdf1, pdf2):
"""Compute all FK tables.
Parameters
----------
pdf_a : str
pdf1 : str
comparison PDF
pdf_b : str
pdf2 : str
second comparison PDF if needed
"""
tcard = theory_card.load(self.theory_id)
self.fks_path.mkdir(exist_ok=True)
self.iterate(self.fk, tcard=tcard, pdf_a=pdf_a, pdf_b=pdf_b)
self.iterate(self.fk, tcard=tcard, pdf1=pdf1, pdf2=pdf2)

def construct_ren_sv_grids(self, flavors):
"""Construct renormalization scale variations terms for all the grids in a dataset."""
Expand Down

0 comments on commit 807fc02

Please sign in to comment.