From b131ba5c902e234082605a2d29dd57b9efd4402a Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Mon, 4 Dec 2023 10:51:40 +0200 Subject: [PATCH 1/8] Fix condition to new damping convention --- .pre-commit-config.yaml | 2 +- src/pineko/fonll.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6f413f3b..768746f9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,7 +20,7 @@ repos: hooks: - id: pycln args: [--config=pyproject.toml] - - repo: https://github.com/psf/black + - repo: https://github.com/psf/black-pre-commit-mirror rev: 23.11.0 hooks: - id: black diff --git a/src/pineko/fonll.py b/src/pineko/fonll.py index 2d9fb548..d120d3f1 100644 --- a/src/pineko/fonll.py +++ b/src/pineko/fonll.py @@ -235,7 +235,7 @@ def collect_updates(fonll_fns, damp): """Produce the different theory cards according to which FONLL is asked for.""" updates = [] is_mixed = fonll_fns in MIXED_ORDER_FNS - is_damped = damp != 0 + is_damped = damp >= 0 base_pto = FNS_BASE_PTO[fonll_fns] cfgs = MIXED_FNS_CONFIG if is_mixed or is_damped else FNS_CONFIG for cfg in cfgs: From 8204c5ca31f9d417fe45cfcc482a77df46360246 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Mon, 4 Dec 2023 11:01:27 +0200 Subject: [PATCH 2/8] Apply linting fixes to fonll.py --- src/pineko/fonll.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pineko/fonll.py b/src/pineko/fonll.py index d120d3f1..a4bbb7a2 100644 --- a/src/pineko/fonll.py +++ b/src/pineko/fonll.py @@ -54,17 +54,18 @@ def __init__( "ffns5til": ffns5til, "ffns5bar": ffns5bar, } - actually_existing_paths = [p for p in self.paths if self.paths[p] is not None] + actually_existing_paths = [p for p, g in self.paths.items() if g is not None] for p in self.paths: if p not in actually_existing_paths: logger.warning( - f"Warning! FK table for {p} does not exist and thus is being skipped." + "Warning! FK table for %s does not exist and thus is being skipped.", + p, ) @property def fk_paths(self): """Returns the list of the FK table paths needed to produce FONLL predictions.""" - return {p: Path(self.paths[p]) for p in self.paths if self.paths[p] is not None} + return {p: Path(self.paths[p]) for p, g in self.paths.items() if g is not None} @property def fks(self): @@ -106,8 +107,11 @@ def Q2grid(self): def update_fk_theorycard(combined_fk, input_theorycard_path): - """Update theorycard entries for the combined fktable by reading the yamldb of the original theory.""" - with open(input_theorycard_path) as f: + """Update theorycard entries for the combined FK table. + + Update by reading the yamldb of the original theory. + """ + with open(input_theorycard_path, encoding="utf-8") as f: final_theorycard = yaml.safe_load(f) theorycard = json.loads(combined_fk.key_values()["theory"]) theorycard["FNS"] = final_theorycard["FNS"] @@ -147,8 +151,8 @@ def combine(fk_dict, dampings=None): sign = -1 if fk in FK_WITH_MINUS else 1 fk_dict[fk].scale(sign) if dampings is not None: - for mass in FK_TO_DAMP: - if fk in FK_TO_DAMP[mass]: + for mass, fks in FK_TO_DAMP.items(): + if fk in fks: fk_dict[fk].scale_by_bin(dampings[mass]) fk_dict[fk].write_lz4(tmpfile_path) combined_fk.merge_from_file(tmpfile_path) @@ -260,7 +264,8 @@ def collect_updates(fonll_fns, damp): def dump_tcards(tcard, tcard_parent_path, theoryid): """Produce the seven FONLL theory cards from the original one. - The produced theory cards are dumped in `tcard_parent_path` with names from '{theoryid}00.yaml' to '{theoryid}06.yaml'. + The produced theory cards are dumped in `tcard_parent_path` with names + from '{theoryid}00.yaml' to '{theoryid}06.yaml'. """ updates = collect_updates(tcard["FNS"], tcard["DAMP"]) n_theory = len(updates) From 643313bc1707e4f3f6f6349b5a49bfaea49ecc23 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Mon, 4 Dec 2023 12:42:03 +0200 Subject: [PATCH 3/8] Adjust damping conditions --- benchmarks/bench_fonll.py | 1 - src/pineko/fonll.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/benchmarks/bench_fonll.py b/benchmarks/bench_fonll.py index 2f2381ff..d59cd258 100644 --- a/benchmarks/bench_fonll.py +++ b/benchmarks/bench_fonll.py @@ -1,4 +1,3 @@ -import numpy as np import pytest import yaml diff --git a/src/pineko/fonll.py b/src/pineko/fonll.py index a4bbb7a2..af607f22 100644 --- a/src/pineko/fonll.py +++ b/src/pineko/fonll.py @@ -181,7 +181,7 @@ def produce_combined_fk( fk_dict = fonll_info.fks dampings = ( None - if damp[0] == -1 + if damp[0] < 0 else produce_dampings(theorycard_constituent_fks, fonll_info, damp[1], damp[2]) ) combined_fk = combine(fk_dict, dampings=dampings) @@ -239,7 +239,7 @@ def collect_updates(fonll_fns, damp): """Produce the different theory cards according to which FONLL is asked for.""" updates = [] is_mixed = fonll_fns in MIXED_ORDER_FNS - is_damped = damp >= 0 + is_damped = damp > 0 base_pto = FNS_BASE_PTO[fonll_fns] cfgs = MIXED_FNS_CONFIG if is_mixed or is_damped else FNS_CONFIG for cfg in cfgs: From 9e72431bad67da7785ff16375a7e1aaf148d0792 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Mon, 4 Dec 2023 14:08:31 +0200 Subject: [PATCH 4/8] Pin damp conditions --- src/pineko/fonll.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pineko/fonll.py b/src/pineko/fonll.py index af607f22..19049a7a 100644 --- a/src/pineko/fonll.py +++ b/src/pineko/fonll.py @@ -181,7 +181,7 @@ def produce_combined_fk( fk_dict = fonll_info.fks dampings = ( None - if damp[0] < 0 + if damp[0] == -1 else produce_dampings(theorycard_constituent_fks, fonll_info, damp[1], damp[2]) ) combined_fk = combine(fk_dict, dampings=dampings) @@ -239,7 +239,7 @@ def collect_updates(fonll_fns, damp): """Produce the different theory cards according to which FONLL is asked for.""" updates = [] is_mixed = fonll_fns in MIXED_ORDER_FNS - is_damped = damp > 0 + is_damped = damp == 1 base_pto = FNS_BASE_PTO[fonll_fns] cfgs = MIXED_FNS_CONFIG if is_mixed or is_damped else FNS_CONFIG for cfg in cfgs: From 9743282b63482d1753742cd4fc21d4c5afa25bd6 Mon Sep 17 00:00:00 2001 From: andreab1997 Date: Tue, 5 Dec 2023 11:34:23 +0100 Subject: [PATCH 5/8] Remove completely the possibility of having 5 grids --- src/pineko/cli/fonll.py | 46 ++++++++--------------------------------- src/pineko/fonll.py | 19 +++++++---------- 2 files changed, 16 insertions(+), 49 deletions(-) diff --git a/src/pineko/cli/fonll.py b/src/pineko/cli/fonll.py index becc5cac..7a061fa4 100644 --- a/src/pineko/cli/fonll.py +++ b/src/pineko/cli/fonll.py @@ -47,11 +47,9 @@ def grids_names(yaml_file): @click.argument("dataset", type=str) @click.option("--FFNS3", type=int, help="theoryID containing the ffns3 fktable") @click.option("--FFN03", type=int, help="theoryID containing the ffn03 fktable") -@click.option("--FFNS4", type=int, help="theoryID containing the ffns4 fktable") @click.option("--FFNS4til", type=int, help="theoryID containing the ffns4til fktable") @click.option("--FFNS4bar", type=int, help="theoryID containing the ffns4bar fktable") @click.option("--FFN04", type=int, help="theoryID containing the ffn04 fktable") -@click.option("--FFNS5", type=int, help="theoryID containing the ffns5 fktable") @click.option("--FFNS5til", type=int, help="theoryID containing the ffns5til fktable") @click.option("--FFNS5bar", type=int, help="theoryID containing the ffns5bar fktable") @click.option("--overwrite", is_flag=True, help="Allow files to be overwritten") @@ -61,11 +59,9 @@ def subcommand( dataset, ffns3, ffn03, - ffns4, ffns4til, ffns4bar, ffn04, - ffns5, ffns5til, ffns5bar, overwrite, @@ -83,40 +79,18 @@ def subcommand( if not ffns3 or not ffn03: raise InconsistentInputsError("ffns3 and/or ffn03 is not provided.") - if any([ffns4, ffns4til, ffns4bar]): - if ffns4: - if any([ffns4til, ffns4bar]): - raise InconsistentInputsError( - "If ffns4 is provided no ffnstil or ffnsbar should be provided." - ) - else: - if ffns4til is None or ffns4bar is None: - raise InconsistentInputsError( - "if ffnstil is provided also ffnsbar should be provided, and vice versa." - ) - else: - raise InconsistentInputsError("ffns4 is not provided.") - - # Do we consider two masses, i.e. mc and mb - two_masses = False - if any([ffns5, ffns5til, ffns5bar]): - two_masses = True - if ffns5: - if any([ffns5til, ffns5bar]): - raise InconsistentInputsError( - "If ffns5 is provided no ffnstil or ffnsbar should be provided." - ) - else: - if ffns5til is None or ffns5bar is None: - raise InconsistentInputsError( - "if ffnstil is provided also ffnsbar should be provided, and vice versa." - ) - - if (ffn04 is None and two_masses) or (ffn04 is not None and not two_masses): + if ffns4til is None or ffns4bar is None: raise InconsistentInputsError( - "If two masses are to be considered, both ffn04 and the nf=5 coefficient should be provided" + "At least one of ffns4til and ffns4bar should be provided." ) + # Do we consider two masses, i.e. mc and mb + if any([ffns5til, ffns5bar, ffn04]): + if (ffns5til is None and ffns5bar is None) or ffn04 is None: + raise InconsistentInputsError( + "To include nf5 contributions, ffn04 and at least one between ffns5til and ffns5bar are mandatory" + ) + # Get theory info tcard = theory_card.load(theoryid) if tcard["DAMP"] == 1: @@ -144,11 +118,9 @@ def subcommand( for name in ( ffns3, ffn03, - ffns4, ffns4til, ffns4bar, ffn04, - ffns5, ffns5til, ffns5bar, ) diff --git a/src/pineko/fonll.py b/src/pineko/fonll.py index 19049a7a..f4bcd9f1 100644 --- a/src/pineko/fonll.py +++ b/src/pineko/fonll.py @@ -40,17 +40,15 @@ class FONLLInfo: """Class containing all the information for FONLL predictions.""" def __init__( - self, ffns3, ffn03, ffns4, ffns4til, ffns4bar, ffn04, ffns5, ffns5til, ffns5bar + self, ffns3, ffn03, ffns4til, ffns4bar, ffn04, ffns5til, ffns5bar ) -> None: """Initialize fonll info.""" self.paths = { "ffns3": ffns3, "ffn03": ffn03, - "ffns4": ffns4, "ffns4til": ffns4til, "ffns4bar": ffns4bar, "ffn04": ffn04, - "ffns5": ffns5, "ffns5til": ffns5til, "ffns5bar": ffns5bar, } @@ -162,11 +160,9 @@ def combine(fk_dict, dampings=None): def produce_combined_fk( ffns3, ffn03, - ffns4, ffns4til, ffns4bar, ffn04, - ffns5, ffns5til, ffns5bar, theoryid, @@ -174,9 +170,7 @@ def produce_combined_fk( cfg=None, ): """Combine the FONLL FK tables into one single FK table.""" - fonll_info = FONLLInfo( - ffns3, ffn03, ffns4, ffns4til, ffns4bar, ffn04, ffns5, ffns5til, ffns5bar - ) + fonll_info = FONLLInfo(ffns3, ffn03, ffns4til, ffns4bar, ffn04, ffns5til, ffns5bar) theorycard_constituent_fks = fonll_info.theorycard_no_fns_pto fk_dict = fonll_info.fks dampings = ( @@ -228,9 +222,11 @@ def scheme(self): FNS_CONFIG = [ SubTheoryConfig(False, 3, "full"), SubTheoryConfig(True, 3, "full"), - SubTheoryConfig(False, 4, "full"), + SubTheoryConfig(False, 4, "massless"), + SubTheoryConfig(False, 4, "massive"), SubTheoryConfig(True, 4, "full"), - SubTheoryConfig(False, 5, "full"), + SubTheoryConfig(False, 5, "massless"), + SubTheoryConfig(False, 5, "massive"), ] """Plain FONLL schemes.""" @@ -239,9 +235,8 @@ def collect_updates(fonll_fns, damp): """Produce the different theory cards according to which FONLL is asked for.""" updates = [] is_mixed = fonll_fns in MIXED_ORDER_FNS - is_damped = damp == 1 base_pto = FNS_BASE_PTO[fonll_fns] - cfgs = MIXED_FNS_CONFIG if is_mixed or is_damped else FNS_CONFIG + cfgs = MIXED_FNS_CONFIG if is_mixed else FNS_CONFIG for cfg in cfgs: po = int(base_pto) + (cfg.delta_pto if is_mixed else 0) updates.append( From 91aec0c09c31c53fc6a256fb2a3edc05c39e1c19 Mon Sep 17 00:00:00 2001 From: andreab1997 Date: Tue, 5 Dec 2023 11:40:51 +0100 Subject: [PATCH 6/8] Correct test_fonll --- tests/test_fonll.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tests/test_fonll.py b/tests/test_fonll.py index bb947ad1..7a11d08a 100644 --- a/tests/test_fonll.py +++ b/tests/test_fonll.py @@ -7,11 +7,9 @@ def test_FONLLInfo(): full_list = [ "ffns3.pineappl.lz4", "ffn03.pineappl.lz4", - "ffns4.pineappl.lz4", "ffns4til.pineappl.lz4", "ffns4bar.pineappl.lz4", "ffn04.pineappl.lz4", - "ffns5.pineappl.lz4", "ffns5til.pineappl.lz4", "ffns5bar.pineappl.lz4", ] @@ -24,20 +22,16 @@ def test_FONLLInfo(): full_list[4], None, None, - None, - full_list[8], ) partialfonll_fake_info = pineko.fonll.FONLLInfo( - full_list[0], full_list[1], None, full_list[3], None, None, None, None, None + full_list[0], full_list[1], full_list[2], full_list[3], None, None, None ) name_list = [ "ffns3", "ffn03", - "ffns4", "ffns4til", "ffns4bar", "ffn04", - "ffns5", "ffns5til", "ffns5bar", ] @@ -47,14 +41,12 @@ def test_FONLLInfo(): assert wrongfonll_fake_info.fk_paths == { name: pathlib.Path(fk) for name, fk in zip( - name_list[:2] + name_list[3:5] + [name_list[-1]], - full_list[:2] + full_list[3:5] + [full_list[-1]], + name_list[:2] + name_list[3:5], + full_list[:2] + full_list[3:5], ) } assert partialfonll_fake_info.fk_paths == { name: pathlib.Path(fk) - for name, fk in zip( - name_list[:2] + name_list[3:4], full_list[:2] + full_list[3:4] - ) + for name, fk in zip(name_list[:4], full_list[:4]) if fk is not None } From 3d9e7f6122076181863423172affa32997049a52 Mon Sep 17 00:00:00 2001 From: andreab1997 Date: Tue, 5 Dec 2023 15:44:45 +0100 Subject: [PATCH 7/8] Remove MIXED_FNS_CONFIG --- benchmarks/bench_evolve.py | 2 +- benchmarks/bench_fonll.py | 2 +- src/pineko/fonll.py | 15 ++------------- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/benchmarks/bench_evolve.py b/benchmarks/bench_evolve.py index 27dd876a..a11ef73b 100644 --- a/benchmarks/bench_evolve.py +++ b/benchmarks/bench_evolve.py @@ -39,7 +39,7 @@ def benchmark_write_operator_card_from_file_num_fonll( # Check if the opcards are ok for opcard_path, cfg in zip( targets_path_list, - pineko.fonll.MIXED_FNS_CONFIG if is_mixed else pineko.fonll.FNS_CONFIG, + pineko.fonll.FNS_CONFIG, ): with open(opcard_path, encoding="utf-8") as f: ocard = yaml.safe_load(f) diff --git a/benchmarks/bench_fonll.py b/benchmarks/bench_fonll.py index d59cd258..27e81c33 100644 --- a/benchmarks/bench_fonll.py +++ b/benchmarks/bench_fonll.py @@ -18,7 +18,7 @@ def benchmark_produce_fonll_tcards( base_pto = pineko.fonll.FNS_BASE_PTO[tcard["FNS"]] for num_fonll_tcard, cfg in zip( theorycards, - pineko.fonll.MIXED_FNS_CONFIG if is_mixed else pineko.fonll.FNS_CONFIG, + pineko.fonll.FNS_CONFIG, ): po = int(base_pto) + (cfg.delta_pto if is_mixed else 0) assert num_fonll_tcard["FNS"] == cfg.scheme diff --git a/src/pineko/fonll.py b/src/pineko/fonll.py index f4bcd9f1..9438aced 100644 --- a/src/pineko/fonll.py +++ b/src/pineko/fonll.py @@ -208,7 +208,7 @@ def scheme(self): return "FONLL-FFN" + ("0" if self.asy else "S") -MIXED_FNS_CONFIG = [ +FNS_CONFIG = [ SubTheoryConfig(False, 3, "full", 1), SubTheoryConfig(True, 3, "full", 1), SubTheoryConfig(False, 4, "massless"), @@ -219,24 +219,13 @@ def scheme(self): ] """Mixed FONLL schemes.""" -FNS_CONFIG = [ - SubTheoryConfig(False, 3, "full"), - SubTheoryConfig(True, 3, "full"), - SubTheoryConfig(False, 4, "massless"), - SubTheoryConfig(False, 4, "massive"), - SubTheoryConfig(True, 4, "full"), - SubTheoryConfig(False, 5, "massless"), - SubTheoryConfig(False, 5, "massive"), -] -"""Plain FONLL schemes.""" - def collect_updates(fonll_fns, damp): """Produce the different theory cards according to which FONLL is asked for.""" updates = [] is_mixed = fonll_fns in MIXED_ORDER_FNS base_pto = FNS_BASE_PTO[fonll_fns] - cfgs = MIXED_FNS_CONFIG if is_mixed else FNS_CONFIG + cfgs = FNS_CONFIG for cfg in cfgs: po = int(base_pto) + (cfg.delta_pto if is_mixed else 0) updates.append( From 7d5ae55a8f21210b64f54d750c90aed85fec5174 Mon Sep 17 00:00:00 2001 From: andreab1997 Date: Tue, 5 Dec 2023 16:09:24 +0100 Subject: [PATCH 8/8] Apply suggestions --- src/pineko/fonll.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pineko/fonll.py b/src/pineko/fonll.py index 9438aced..469e643c 100644 --- a/src/pineko/fonll.py +++ b/src/pineko/fonll.py @@ -220,7 +220,7 @@ def scheme(self): """Mixed FONLL schemes.""" -def collect_updates(fonll_fns, damp): +def collect_updates(fonll_fns): """Produce the different theory cards according to which FONLL is asked for.""" updates = [] is_mixed = fonll_fns in MIXED_ORDER_FNS @@ -251,7 +251,7 @@ def dump_tcards(tcard, tcard_parent_path, theoryid): The produced theory cards are dumped in `tcard_parent_path` with names from '{theoryid}00.yaml' to '{theoryid}06.yaml'. """ - updates = collect_updates(tcard["FNS"], tcard["DAMP"]) + updates = collect_updates(tcard["FNS"]) n_theory = len(updates) theorycards = [copy.deepcopy(tcard) for _ in range(n_theory)] paths_list = []