From 4f070e81d150354c5cca5b42eefcdd3d37bcd354 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 10 Oct 2023 16:38:59 +0300 Subject: [PATCH 1/4] Move regression test --- .../bench_regression.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) rename tests/test_regression.py => benchmarks/bench_regression.py (91%) diff --git a/tests/test_regression.py b/benchmarks/bench_regression.py similarity index 91% rename from tests/test_regression.py rename to benchmarks/bench_regression.py index 4c37f9f6..a0b77e16 100644 --- a/tests/test_regression.py +++ b/benchmarks/bench_regression.py @@ -1,10 +1,10 @@ """ - Suite of tests that go through the entire process of creating a new fktable - from a empty folder. +Suite of tests that go through the entire process of creating a new fktable +from a empty folder. - The target theory is 400 and the relevant `.toml`, theory runcard and eko template - are downloaded from https://github.com/NNPDF/theories during this test so this tests - has the double effect of ensuring compatibility between both repositories. +The target theory is 400 and the relevant `.toml`, theory runcard and eko template +are downloaded from https://github.com/NNPDF/theories during this test so this tests +has the double effect of ensuring compatibility between both repositories. """ import itertools from pathlib import Path @@ -82,7 +82,7 @@ def _trim_template(template_card, take_points=10): @pytest.mark.parametrize("dataset", ["LHCBWZMU8TEV", "INTEGXT3"]) -def test_regression(tmp_path, dataset): +def benchmark_regression(tmp_path, dataset): """Run pineko through subprocess to ensure that the shell scripts are working exactly as intended. From 14ee69994bd5f6d2c33bf70682ad3f59c3f8a8d4 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 10 Oct 2023 16:42:39 +0300 Subject: [PATCH 2/4] Make benchmark_detect available locally --- benchmarks/bench_configs.py | 8 +++++--- benchmarks/conftest.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/benchmarks/bench_configs.py b/benchmarks/bench_configs.py index c25421f6..5a52a441 100644 --- a/benchmarks/bench_configs.py +++ b/benchmarks/bench_configs.py @@ -3,10 +3,12 @@ import pineko -def benchmark_detect(test_files): - with pytest.raises(FileNotFoundError): - pineko.configs.detect() +def benchmark_detect(test_files, tmp_path, cd): + with cd(tmp_path): + with pytest.raises(FileNotFoundError): + pineko.configs.detect() conf_file = pineko.configs.detect(test_files) + assert conf_file is not None def benchmark_load(test_files): diff --git a/benchmarks/conftest.py b/benchmarks/conftest.py index a28efc6a..44de162d 100644 --- a/benchmarks/conftest.py +++ b/benchmarks/conftest.py @@ -1,3 +1,4 @@ +import os import pathlib import shutil from contextlib import contextmanager @@ -49,3 +50,18 @@ def wrapped(newdir): lhapdf.setPaths(paths) return wrapped + + +@pytest.fixture +def cd(): + # thanks https://stackoverflow.com/a/24176022/8653979 + @contextmanager + def wrapped(newdir): + prevdir = os.getcwd() + os.chdir(os.path.expanduser(newdir)) + try: + yield + finally: + os.chdir(prevdir) + + return wrapped From b30a07250a11f621dc51c3fd6f40f134c724ed57 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 10 Oct 2023 16:48:10 +0300 Subject: [PATCH 3/4] Move regression data --- {tests => benchmarks}/regression_data/INTEGXT3.npy | Bin .../regression_data/LHCBWZMU8TEV.npy | Bin 2 files changed, 0 insertions(+), 0 deletions(-) rename {tests => benchmarks}/regression_data/INTEGXT3.npy (100%) rename {tests => benchmarks}/regression_data/LHCBWZMU8TEV.npy (100%) diff --git a/tests/regression_data/INTEGXT3.npy b/benchmarks/regression_data/INTEGXT3.npy similarity index 100% rename from tests/regression_data/INTEGXT3.npy rename to benchmarks/regression_data/INTEGXT3.npy diff --git a/tests/regression_data/LHCBWZMU8TEV.npy b/benchmarks/regression_data/LHCBWZMU8TEV.npy similarity index 100% rename from tests/regression_data/LHCBWZMU8TEV.npy rename to benchmarks/regression_data/LHCBWZMU8TEV.npy From 52096a675f370f3a0e49057fe73fcb4c1a11f517 Mon Sep 17 00:00:00 2001 From: Felix Hekhorn Date: Tue, 10 Oct 2023 16:55:06 +0300 Subject: [PATCH 4/4] Apply some low hanging lints --- src/pineko/cli/gen_sv.py | 1 - src/pineko/cli/kfactor.py | 1 - src/pineko/comparator.py | 2 +- src/pineko/kfactor.py | 14 +++++++------- src/pineko/scale_variations.py | 11 ++++++----- src/pineko/theory.py | 3 +-- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/pineko/cli/gen_sv.py b/src/pineko/cli/gen_sv.py index d3301174..911f3556 100644 --- a/src/pineko/cli/gen_sv.py +++ b/src/pineko/cli/gen_sv.py @@ -3,7 +3,6 @@ import pathlib import click -import pineappl import rich from .. import scale_variations diff --git a/src/pineko/cli/kfactor.py b/src/pineko/cli/kfactor.py index eea20356..2283a78b 100644 --- a/src/pineko/cli/kfactor.py +++ b/src/pineko/cli/kfactor.py @@ -3,7 +3,6 @@ import pathlib import click -import rich from .. import kfactor from ._base import command diff --git a/src/pineko/comparator.py b/src/pineko/comparator.py index f477dc4d..a99d68ae 100644 --- a/src/pineko/comparator.py +++ b/src/pineko/comparator.py @@ -30,7 +30,7 @@ def compare(pine, fktable, max_as, max_al, pdf, xir, xif): df : pd.DataFrame comparison table """ - import lhapdf # pylint: disable=import-error + import lhapdf # pylint: disable=import-error,import-outside-toplevel pdfset = lhapdf.mkPDF(pdf, 0) pdgid = int(pdfset.set().get_entry("Particle")) diff --git a/src/pineko/kfactor.py b/src/pineko/kfactor.py index 204059de..46dfc09b 100644 --- a/src/pineko/kfactor.py +++ b/src/pineko/kfactor.py @@ -308,10 +308,10 @@ def do_it( (first_nonzero_order[0] + max_as_test, min_al, 0, 0), grid_orders_filtered ) if is_in and not order_exists: - rich.print(f"[green] Success: Requested order already in the grid.") + rich.print("[green] Success: Requested order already in the grid.") return - elif not is_in and order_exists: - rich.print(f"[red] Abort: order exists is True but order not in the grid.") + if not is_in and order_exists: + rich.print("[red] Abort: order exists is True but order not in the grid.") return construct_and_merge_grids( grid_path, @@ -329,11 +329,11 @@ def filter_k_factors(pigrid, centrals_kfactor): """Filter the centrals k-factors according to their lenght compared to the number of bins of the grid.""" centrals_kfactor_filtered = np.array([]) if pigrid.bins() == len(centrals_kfactor): - rich.print(f"[orange] The number of bins match the lenght of the k-factor.") + rich.print("[orange] The number of bins match the lenght of the k-factor.") centrals_kfactor_filtered = centrals_kfactor elif pigrid.bins() < len(centrals_kfactor): rich.print( - f"[yellow] The number of bins is less than the lenght of the k-factor." + "[yellow] The number of bins is less than the lenght of the k-factor." ) if not all(elem == centrals_kfactor[0] for elem in centrals_kfactor): # This case is actually wrong. @@ -341,7 +341,7 @@ def filter_k_factors(pigrid, centrals_kfactor): centrals_kfactor_filtered = centrals_kfactor else: rich.print( - f"[yellow] The number of bins is more than the lenght of the k-factor." + "[yellow] The number of bins is more than the lenght of the k-factor." ) # This is the last case in which grid.bins() > len(centrals_kfactor) @@ -388,7 +388,7 @@ def compute_k_factor_grid( target_folder: pathlib.Path path where store the new grid (optional) """ - import lhapdf # pylint: disable=import-error + import lhapdf # pylint: disable=import-error,import-outside-toplevel # With respect to the usual convention here max_as is max_as-1 max_as_test = max_as - 1 diff --git a/src/pineko/scale_variations.py b/src/pineko/scale_variations.py index 888fdcd8..adea5518 100644 --- a/src/pineko/scale_variations.py +++ b/src/pineko/scale_variations.py @@ -5,7 +5,6 @@ import numpy as np import pineappl -import rich from eko import beta from . import check @@ -18,12 +17,12 @@ class ReturnState(Enum): """Auxiliary class to list the possible return states.""" - ALREADY_THERE = f"[green]Renormalization scale variations are already in the grid" + ALREADY_THERE = "[green]Renormalization scale variations are already in the grid" ORDER_EXISTS_FAILURE = ( "Order_exists is True but the order does not appear to be in the grid" ) MISSING_CENTRAL = "Central order is not high enough to compute requested sv orders" - SUCCESS = f"[green]Success: scale variation orders included!" + SUCCESS = "[green]Success: scale variation orders included!" def qcd(order: OrderTuple) -> int: @@ -168,7 +167,7 @@ def write_grids(gridpath, grid_list): def merge_grids( - gridpath, grid_list_path, target_path=None, nec_orders={}, order_exists=False + gridpath, grid_list_path, target_path=None, nec_orders=None, order_exists=False ): """Merge the single grids in the original.""" grid = pineappl.grid.Grid.read(gridpath) @@ -177,7 +176,9 @@ def merge_grids( else: target_path = target_path / gridpath.name if order_exists: - grid = construct_and_dump_order_exists_grid(grid, list(nec_orders.keys())[0]) + grid = construct_and_dump_order_exists_grid( + grid, list(nec_orders.keys())[0] if nec_orders is not None else [] + ) for grid_path in grid_list_path: grid.merge_from_file(grid_path) grid_path.unlink() diff --git a/src/pineko/theory.py b/src/pineko/theory.py index 899d8f66..dbacb5ae 100644 --- a/src/pineko/theory.py +++ b/src/pineko/theory.py @@ -325,8 +325,7 @@ def eko(self, name, _grid, tcard): if not self.overwrite: rich.print(f"Skipping existing operator {eko_filename}") return - else: - eko_filename.unlink() + eko_filename.unlink() # do it! logger.info("Start computation of %s", name) start_time = time.perf_counter()