Skip to content

Commit

Permalink
improve check
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomomagni committed Nov 6, 2024
1 parent 08e5ebd commit 9a61792
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
20 changes: 11 additions & 9 deletions src/pineko/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,19 @@ def in1d(a, b, rtol=1e-05, atol=1e-08):
)


def check_grid_and_eko_compatible(pineappl_grid, operators, xif, max_as, max_al):
"""Check whether the EKO operators and the PineAPPL grid are compatible.
def check_grid_and_eko_compatible(
pineappl_grid, eko_xgrid, eko_mu2, xif, max_as, max_al
):
"""Check whether the EKO operator and the PineAPPL grid are compatible.
Parameters
----------
pineappl_grid : pineappl.grid.Grid
grid
operators : eko.EKO
operators
eko_xgrid : list
eko interpolation xgrid
eko_mu2: float
eko mu2 scale
xif : float
factorization scale variation
max_as: int
Expand All @@ -95,7 +99,7 @@ def check_grid_and_eko_compatible(pineappl_grid, operators, xif, max_as, max_al)
Raises
------
ValueError
If the operators and the grid are not compatible.
If the operator and the grid are not compatible.
"""
order_mask = pineappl.grid.Order.create_mask(
pineappl_grid.orders(), max_as, max_al, True
Expand All @@ -104,14 +108,12 @@ def check_grid_and_eko_compatible(pineappl_grid, operators, xif, max_as, max_al)
x_grid = evol_info.x1
muf2_grid = evol_info.fac1
# Q2 grid
if not np.all(
in1d(np.unique(list(operators.mu2grid)), xif * xif * np.array(muf2_grid))
):
if not np.all(in1d(np.array([eko_mu2]), xif * xif * np.array(muf2_grid))):
raise ValueError(
"Q2 grid in pineappl grid and eko operator are NOT compatible!"
)
# x-grid
if not np.all(in1d(np.unique(operators.xgrid.tolist()), np.array(x_grid))):
if not np.all(in1d(np.unique(eko_xgrid), np.array(x_grid))):
raise ValueError("x grid in pineappl grid and eko operator are NOT compatible!")


Expand Down
15 changes: 8 additions & 7 deletions src/pineko/cli/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ def sub_compatibility(grid_path, operator_path, xif, max_as, max_al):
"""
pineappl_grid = pineappl.grid.Grid.read(grid_path)
with eko.EKO.read(operator_path) as operators:
try:
check.check_grid_and_eko_compatible(
pineappl_grid, operators, xif, max_as, max_al
)
rich.print("[green]Success:[/] grids are compatible")
except ValueError as e:
rich.print("[red]Error:[/]", e)
for (q2, _), _ in operators.items():
try:
check.check_grid_and_eko_compatible(
pineappl_grid, operators.xgrid.tolist(), q2, xif, max_as, max_al
)
except ValueError as e:
rich.print("[red]Error:[/]", e)
rich.print("[green]Success:[/] grids and eko are compatible.")


@dataclass
Expand Down
7 changes: 2 additions & 5 deletions src/pineko/evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,6 @@ def evolve_grid(
tcard = operators1.theory_card
opcard = operators1.operator_card

# TODO: do we still want to check here or only later ?
check.check_grid_and_eko_compatible(grid, operators1, xif, max_as, max_al)
if operators2 is not None:
check.check_grid_and_eko_compatible(grid, operators2, xif, max_as, max_al)

# PineAPPL wants alpha_s = 4*pi*a_s
# remember that we already accounted for xif in the opcard generation
evmod = eko.couplings.couplings_mod_ev(opcard.configs.evolution_method)
Expand Down Expand Up @@ -404,6 +399,8 @@ def prepare(operator):
"""Match the raw operator with its relevant metadata."""
for (q2, _), op in operator.items():
op = xgrid_reshape(op, operator.xgrid)
# TODO: this check here could be dropped ?
check.check_grid_and_eko_compatible(grid, x_grid, q2, xif, max_as, max_al)
info = PyOperatorSliceInfo(
fac0=operator.mu20,
x0=operator.xgrid.tolist(),
Expand Down

0 comments on commit 9a61792

Please sign in to comment.