Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move regression test #127

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions benchmarks/bench_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions tests/test_regression.py → benchmarks/bench_regression.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.

Expand Down
16 changes: 16 additions & 0 deletions benchmarks/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import pathlib
import shutil
from contextlib import contextmanager
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion src/pineko/cli/gen_sv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pathlib

import click
import pineappl
import rich

from .. import scale_variations
Expand Down
1 change: 0 additions & 1 deletion src/pineko/cli/kfactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pathlib

import click
import rich

from .. import kfactor
from ._base import command
Expand Down
2 changes: 1 addition & 1 deletion src/pineko/comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
14 changes: 7 additions & 7 deletions src/pineko/kfactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -329,19 +329,19 @@ 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.
raise ValueError("KFactor contains too many different values.")
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)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/pineko/scale_variations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import numpy as np
import pineappl
import rich
from eko import beta

from . import check
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions src/pineko/theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down