Skip to content

Commit

Permalink
make benchmarks passing
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomomagni committed Jul 23, 2024
1 parent 915daf4 commit c2cc150
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion benchmarks/bench_evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def benchmark_evolve_grid(tmp_path, lhapdf_path, test_files, test_pdf):
1.0,
1.0,
assumptions=assumptions,
comparison_pdf="NNPDF40_nnlo_as_01180",
comparison_pdf1="NNPDF40_nnlo_as_01180",
)
# check metadata is there - fixes https://github.com/NNPDF/pineko/issues/70
fk = pineappl.fk_table.FkTable.read(target_path)
Expand Down
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=None)
theory_obj_hera.fk(grid_name, grid_path, tcard, pdf_a=None, pdf_b=None)
# test overwrite function
theory_obj_hera.fk(grid_name, grid_path, tcard, pdf=None)
theory_obj_hera.fk(grid_name, grid_path, tcard, pdf_a=None, pdf_b=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
9 changes: 6 additions & 3 deletions src/pineko/cli/theory_.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ def inherit_ekos(source_theory_id, target_theory_id, datasets, overwrite):
@theory_.command()
@click.argument("theory_id", type=click.INT)
@click.argument("datasets", type=click.STRING, nargs=-1)
@click.option("--pdf", "-p", default=None, help="PDF set used for comparison")
@click.option("--pdf1", "-p", default=None, help="PDF set used for comparison")
@click.option(
"--pdf2", default=None, help="Second PDF set used for comparison, if needed"
)
@click.option("--silent", is_flag=True, help="Suppress logs with comparison")
@click.option(
"-cl",
Expand All @@ -76,11 +79,11 @@ def inherit_ekos(source_theory_id, target_theory_id, datasets, overwrite):
help="Erease previos logs (instead of appending)",
)
@click.option("--overwrite", is_flag=True, help="Allow files to be overwritten")
def fks(theory_id, datasets, pdf, silent, clear_logs, overwrite):
def fks(theory_id, datasets, pdf1, pdf2, silent, clear_logs, overwrite):
"""Compute FK tables in all datasets."""
theory.TheoryBuilder(
theory_id, datasets, silent=silent, clear_logs=clear_logs, overwrite=overwrite
).fks(pdf)
).fks(pdf1, pdf2)


@theory_.command()
Expand Down
4 changes: 2 additions & 2 deletions src/pineko/evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ def prepare(operator, items):
grid, fktable, max_as, max_al, comparison_pdf1, xir, xif, comparison_pdf2
)
fktable.set_key_value("results_fk", comparison.to_string())
fktable.set_key_value("results_fk_pdfset1", comparison_pdf1)
fktable.set_key_value("results_fk_pdfset2", comparison_pdf2)
fktable.set_key_value("results_fk_pdfset1", str(comparison_pdf1))
fktable.set_key_value("results_fk_pdfset2", str(comparison_pdf2))
# write
fktable.write_lz4(str(fktable_path))
return grid, fktable, comparison
25 changes: 16 additions & 9 deletions src/pineko/theory.py
Original file line number Diff line number Diff line change
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):
def fk(self, name, grid_path, tcard, pdf_a, pdf_b):
"""Compute a single FK table.
Parameters
Expand All @@ -400,13 +400,15 @@ def fk(self, name, grid_path, tcard, pdf):
path to grid
tcard : dict
theory card
pdf : str
pdf_a : str
comparison PDF
pdf_b : str
comparison PDF
"""
# activate logging
paths = configs.configs["paths"]
do_log = self.activate_logging(
paths["logs"]["fk"], f"{self.theory_id}-{name}-{pdf}.log"
paths["logs"]["fk"], f"{self.theory_id}-{name}-{pdf_a}-{pdf_b}.log"
)

# Relevant for FONLL-B and FONLL-D: For FFN0 terms, PTO is lower than
Expand Down Expand Up @@ -517,7 +519,7 @@ def fk(self, name, grid_path, tcard, pdf):
xir=xir,
xif=xif,
assumptions=assumptions,
comparison_pdf=pdf,
comparison_pdf1=pdf_a,
meta_data={"theory_card": json.dumps(tcard)},
)
else:
Expand All @@ -532,7 +534,8 @@ def fk(self, name, grid_path, tcard, pdf):
xif=xif,
assumptions=assumptions,
operators_b=operators_b,
comparison_pdf=pdf,
comparison_pdf1=pdf_a,
comparison_pdf2=pdf_b,
meta_data={"theory_card": json.dumps(tcard)},
)
# Remove tmp ekos
Expand All @@ -547,21 +550,25 @@ def fk(self, name, grid_path, tcard, pdf):
time.perf_counter() - start_time,
)
if do_log and comparison is not None:
logger.info("Comparison with %s:\n %s", pdf, comparison.to_string())
logger.info(
"Comparison with %s %s:\n %s", pdf_a, pdf_b, comparison.to_string()
)
if fk_filename.exists():
rich.print(f"[green]Success:[/] Wrote FK table to {fk_filename}")

def fks(self, pdf):
def fks(self, pdf_a, pdf_b):
"""Compute all FK tables.
Parameters
----------
pdf : str
pdf_a : str
comparison PDF
pdf_b : 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=pdf)
self.iterate(self.fk, tcard=tcard, pdf_a=pdf_a, pdf_b=pdf_b)

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 c2cc150

Please sign in to comment.