Skip to content

Commit

Permalink
Refactor check subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
alecandido committed Jul 12, 2022
1 parent a3bc157 commit 975b8fe
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/pineko/cli/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,54 @@
from ._base import command


@command.command("check")
@click.argument("pineappl_path", metavar="PINEAPPL", type=click.Path(exists=True))
@click.argument("eko_path", metavar="EKO", type=click.Path(exists=True))
@command.group("check")
def subcommand():
"""Check grid and operator properties."""


@subcommand.command("compatibility")
@click.argument("grid_path", metavar="PINEAPPL", type=click.Path(exists=True))
@click.argument("operator_path", metavar="EKO", type=click.Path(exists=True))
@click.option("--xif", default=1.0, help="factorization scale variation")
def subcommand(pineappl_path, eko_path, xif):
def sub_compatibility(grid_path, operator_path, xif):
"""Check PineAPPL grid and EKO compatibility.
In order to be compatible, the grid provided in PINEAPPL and the operator
provided in EKO, have to expose the same x grid and Q2 grid.
XIF is the factorization scale variation.
"""
pineappl_grid = pineappl.grid.Grid.read(pineappl_path)
operators = eko.output.Output.load_tar(eko_path)
pineappl_grid = pineappl.grid.Grid.read(grid_path)
operators = eko.output.Output.load_tar(operator_path)
try:
check.check_grid_and_eko_compatible(pineappl_grid, operators, xif)
rich.print("[green]Success:[/] grids are compatible")
except ValueError as e:
rich.print("[red]Error:[/]", e)


@command.command("check_scalevar")
@click.argument("pineappl_path", metavar="PINEAPPL", type=click.Path(exists=True))
@subcommand.command("scvar")
@click.argument("grid_path", metavar="PINEAPPL", type=click.Path(exists=True))
@click.argument(
"tocheck",
metavar="TOCHECK",
type=str,
"scale",
metavar="SCALE",
type=click.Choice(["ren", "fact"]),
)
def subcommand_sv(pineappl_path, tocheck):
def subcommand_sv(grid_path, scale):
"""Check if PineAPPL grid contains requested scale variations."""
pineappl_grid = pineappl.grid.Grid.read(pineappl_path)
if tocheck == "xir":
grid = pineappl.grid.Grid.read(grid_path)
if scale == "ren":
try:
check.contains_ren(pineappl_grid)
check.contains_ren(grid)
rich.print(
"[green]Success:[/] grids contain renormalization scale variations"
)
except ValueError as e:
rich.print("[red]Error:[/]", e)
elif tocheck == "xif":
elif scale == "fact":
try:
check.contains_fact(pineappl_grid)
check.contains_fact(grid)
rich.print(
"[green]Success:[/] grids contain factorization scale variations"
)
Expand Down

2 comments on commit 975b8fe

@felixhekhorn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about renaming a bit:

  • subcommand -> check
  • sub_compatibility -> compatibility
  • subcommand_sv -> scvar

Please also expand the docstring for subcommand_sv similar to sub_compatibility (this is show as --help)

@alecandido
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also expand the docstring for subcommand_sv similar to sub_compatibility (this is show as --help)

Yeah, I know, but I'm really short of time now, so I did the minimal thing...

How about renaming a bit:

This I'm not doing on purpose: those functions are created by click, as a result (they are wrapped and there to be called).
It's kind of click magic, but from the experience with other projects better not to mix things.

Please sign in to comment.