Skip to content

Commit

Permalink
Fix how threshold is passed into the CLI for compare
Browse files Browse the repository at this point in the history
  • Loading branch information
Radonirinaunimi committed Feb 21, 2025
1 parent ce78abc commit 763558c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
10 changes: 3 additions & 7 deletions src/pineko/cli/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@
@click.option("--xir", default=1.0, help="renormalization scale variation")
@click.option("--xif", default=1.0, help="factorization scale variation")
@click.option(
"--check_accuracies/--no-check_accuracies",
default=True,
help="Check if the difference between Grid and FK is above 2 permille and if so fail",
"--threshold", default=5.0, help="threshold in permille to accept Grid -> FK"
)
def subcommand(
fktable_path, grid_path, max_as, max_al, pdfs, xir, xif, check_accuracies
):
def subcommand(fktable_path, grid_path, max_as, max_al, pdfs, xir, xif, threshold):
"""Compare process level PineAPPL grid and derived FK Table.
The comparison between the grid stored at PINEAPPL_PATH, and the FK table
Expand All @@ -48,6 +44,6 @@ def subcommand(
# Note that we need to cast to string before printing to avoid ellipsis ...
rich.print(
comparator.compare(
pine, fk, max_as, max_al, pdf1, xir, xif, check_accuracies, pdf2
pine, fk, max_as, max_al, pdf1, xir, xif, threshold, pdf2
).to_string()
)
13 changes: 6 additions & 7 deletions src/pineko/comparator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GridtoFKError(Exception):
"""Raised when the difference between the Grid and FK table is above some threshold."""


def compare(pine, fktable, max_as, max_al, pdf1, xir, xif, check_accuracies, pdf2=None):
def compare(pine, fktable, max_as, max_al, pdf1, xir, xif, threshold, pdf2=None):
"""Build comparison table.
Parameters
Expand All @@ -29,9 +29,9 @@ def compare(pine, fktable, max_as, max_al, pdf1, xir, xif, check_accuracies, pdf
renormalization scale variation
xif : float
factorization scale variation
check_accuracies: bool
check if the difference between the Grid and FK table is above 2 permille
and if so raise an error
threshold: float
check if the difference between the Grid and FK table is above the
threshold then raise an error
pdf2: str or None
PDF set for the second convolution, if different from the first
Expand All @@ -47,7 +47,6 @@ def compare(pine, fktable, max_as, max_al, pdf1, xir, xif, check_accuracies, pdf
pdfset2 = lhapdf.mkPDF(pdf2, 0)
else:
pdfset2 = pdfset1
diff_threshold = 2 # in permille

# TODO: This should probably changed in the future to use the Grid::convolutions
try:
Expand Down Expand Up @@ -121,9 +120,9 @@ def compare(pine, fktable, max_as, max_al, pdf1, xir, xif, check_accuracies, pdf
df["FkTable"] = after
df["permille_error"] = (after / before - 1.0) * 1000.0

if check_accuracies and (df["permille_error"].abs() >= diff_threshold).any():
if (df["permille_error"].abs() >= threshold).any():
raise GridtoFKError(
f"The difference between the Grid and FK is above {diff_threshold} permille."
f"The difference between the Grid and FK is above {threshold} permille."
)

return df

0 comments on commit 763558c

Please sign in to comment.