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

Allow pineko to check if the grid contains SV #24

Merged
merged 40 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ff57aab
First implementation
andreab1997 Jun 13, 2022
c13474d
Fixing
andreab1997 Jun 13, 2022
f7f3e06
Put scalevar parameters as arguments
andreab1997 Jun 13, 2022
02ee40d
Fixed init of cli
andreab1997 Jun 13, 2022
4fad303
Added SV check as default when computing fks
andreab1997 Jun 16, 2022
7713ff0
Fixing
andreab1997 Jun 16, 2022
b1598f6
Splitted funcs, put if in theory and change cli
andreab1997 Jun 17, 2022
c7987f8
Fixing
andreab1997 Jun 17, 2022
9fdd291
Splitted funcs, put if in theory and change cli
andreab1997 Jun 17, 2022
8322198
Fixing
andreab1997 Jun 17, 2022
f2eecce
Merge branch 'sv_check' of github.com:N3PDF/pineko into sv_check
andreab1997 Jun 17, 2022
b4dc401
Change argument of the function and put tocheck as argument
andreab1997 Jul 5, 2022
8c14399
put the grid as argument of evolve
andreab1997 Jul 8, 2022
7c3147a
Run pre-commit
andreab1997 Jul 8, 2022
0316a2f
Removed redundant def of xir and xif
andreab1997 Jul 8, 2022
cd68db0
Fixed import of pineappl
andreab1997 Jul 8, 2022
bd2dbdd
Upgrade PineAPPL to v0.5.4
alecandido Jul 9, 2022
5fcc283
Fixed import of pineappl
andreab1997 Jul 9, 2022
703c316
Merge branch 'sv_check' of github.com:N3PDF/pineko into sv_check
andreab1997 Jul 9, 2022
5d194df
Splitted funcs, put if in theory and change cli
andreab1997 Jun 17, 2022
5a3df49
Fixing
andreab1997 Jun 17, 2022
26ee37e
Fixing
andreab1997 Jun 13, 2022
fbeae62
Put scalevar parameters as arguments
andreab1997 Jun 13, 2022
3f9d6fe
Fixed init of cli
andreab1997 Jun 13, 2022
b406490
Added SV check as default when computing fks
andreab1997 Jun 16, 2022
c053a86
Splitted funcs, put if in theory and change cli
andreab1997 Jun 17, 2022
72c7889
Change argument of the function and put tocheck as argument
andreab1997 Jul 5, 2022
1928fcf
put the grid as argument of evolve
andreab1997 Jul 8, 2022
460af45
Run pre-commit
andreab1997 Jul 8, 2022
8e4ba78
Removed redundant def of xir and xif
andreab1997 Jul 8, 2022
48ec795
Fixed import of pineappl
andreab1997 Jul 8, 2022
381426e
Fixed import of pineappl
andreab1997 Jul 9, 2022
6cec81c
Merge branch 'sv_check' of github.com:N3PDF/pineko into sv_check
andreab1997 Jul 9, 2022
b88a051
Minor changes
andreab1997 Jul 9, 2022
7c30efe
Change names of funcs
andreab1997 Jul 11, 2022
261a2c7
Fixed theory
andreab1997 Jul 11, 2022
776af28
Merge branch 'feature/sv' into sv_check
felixhekhorn Jul 11, 2022
a3bc157
Added relevant tests
andreab1997 Jul 12, 2022
975b8fe
Refactor check subcommand
alecandido Jul 12, 2022
3010f8c
Improve functions' names consistency
alecandido Jul 12, 2022
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
497 changes: 151 additions & 346 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ packages = [{ include = "pineko", from = "src" }]
[tool.poetry.dependencies]
python = ">=3.8,<3.11"
eko = "^0.8.5"
pineappl = "^0.5.2"
pineappl = "^0.5.4"
PyYAML = "^6.0"
numpy = "^1.21.0"
pandas = "^1.4.1"
Expand Down
28 changes: 28 additions & 0 deletions src/pineko/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,31 @@ def check_grid_and_eko_compatible(pineappl_grid, operators, xif):
# x-grid
if not np.all(in1d(np.unique(operators["targetgrid"]), np.array(x_grid))):
raise ValueError("x grid in pineappl grid and eko operator are NOT compatible!")


def check_grid_contains_fact_sv(grid):
"""Checks whether factorization scale-variations are available in the pineappl grid.
Parameters
----------
grid: pineappl.grid.Grid
Pineappl grid
"""
order_list = [order.as_tuple() for order in grid.orders()]
for order in order_list:
if order[-1] != 0:
return
raise ValueError("Factorization scale variations are not available for this grid")


def check_grid_contains_ren_sv(grid):
andreab1997 marked this conversation as resolved.
Show resolved Hide resolved
"""Checks whether renormalization scale-variations are available in the pineappl grid.
Parameters
----------
grid: pineappl.grid.Grid
Pineappl grid
"""
order_list = [order.as_tuple() for order in grid.orders()]
for order in order_list:
if order[-2] != 0:
return
raise ValueError("Renormalization scale variations are not available for this grid")
30 changes: 30 additions & 0 deletions src/pineko/cli/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,33 @@ def subcommand(pineappl_path, eko_path, 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))
@click.argument(
"tocheck",
metavar="TOCHECK",
type=str,
)
def subcommand_sv(pineappl_path, tocheck):
felixhekhorn marked this conversation as resolved.
Show resolved Hide resolved
"""Check if PineAPPL grid contains requested scale variations"""
pineappl_grid = pineappl.grid.Grid.read(pineappl_path)
if tocheck == "xir":
try:
check.check_grid_contains_ren_sv(pineappl_grid)
rich.print(
"[green]Success:[/] grids contain renormalization scale variations"
)
except ValueError as e:
rich.print("[red]Error:[/]", e)
elif tocheck == "xif":
try:
check.check_grid_contains_fact_sv(pineappl_grid)
rich.print(
"[green]Success:[/] grids contain factorization scale variations"
)
except ValueError as e:
rich.print("[red]Error:[/]", e)
else:
raise ValueError("Scale variation to check can be one between xir and xif")
18 changes: 14 additions & 4 deletions src/pineko/cli/convolute.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# -*- coding: utf-8 -*-
"""CLI entry point to convolution."""
import click
import pineappl
import rich

from .. import evolve
from ._base import command


@command.command("convolute")
@click.argument("pineappl", type=click.Path(exists=True))
@click.argument("pine", type=click.Path(exists=True))
@click.argument("eko", type=click.Path(exists=True))
@click.argument("fktable", type=click.Path())
@click.argument("max_as", type=int)
Expand All @@ -23,10 +25,10 @@
help="the flavor assumptions to be used",
show_default=True,
)
def subcommand(pineappl, eko, fktable, max_as, max_al, xir, xif, pdf, assumptions):
def subcommand(pine, eko, fktable, max_as, max_al, xir, xif, pdf, assumptions):
andreab1997 marked this conversation as resolved.
Show resolved Hide resolved
"""Convolute PineAPPL grid and EKO into an FK table.

PINEAPPL and EKO are the path to the respective elements to convolute, and
PINE and EKO are the path to the respective elements to convolute, and
FKTABLE is the path where to dump the output.

MAX_AS and MAX_AL are used to specify the order in QCD and QED
Expand All @@ -38,8 +40,16 @@ def subcommand(pineappl, eko, fktable, max_as, max_al, xir, xif, pdf, assumption

PDF is an optional PDF set compatible with the EKO to compare grid and FK table.
"""
pineappl_grid = pineappl.grid.Grid.read(pine)
rich.print(
rich.panel.Panel.fit("Computing ...", style="magenta", box=rich.box.SQUARE),
f" {pineappl}\n",
f"+ {eko}\n",
f"= {fktable}\n",
f"with max_as={max_as}, max_al={max_al}, xir={xir}, xif={xif}",
)
_grid, _fk, comp = evolve.evolve_grid(
pineappl,
pineappl_grid,
eko,
fktable,
max_as,
Expand Down
13 changes: 2 additions & 11 deletions src/pineko/evolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def write_operator_card(pineappl_grid, default_card, card_path, xi):


def evolve_grid(
pineappl_path,
pineappl_grid,
andreab1997 marked this conversation as resolved.
Show resolved Hide resolved
eko_path,
fktable_path,
max_as,
Expand All @@ -92,7 +92,7 @@ def evolve_grid(

Parameters
----------
pineappl_path : str
pineappl_grid : pineappl.grid.Grid
unconvoluted grid
eko_path : str
evolution operator
Expand All @@ -113,15 +113,6 @@ def evolve_grid(
comparison_pdf : None or str
if given, a comparison table (with / without evolution) will be printed
"""
rich.print(
rich.panel.Panel.fit("Computing ...", style="magenta", box=rich.box.SQUARE),
f" {pineappl_path}\n",
f"+ {eko_path}\n",
f"= {fktable_path}\n",
f"with max_as={max_as}, max_al={max_al}, xir={xir}, xif={xif}",
)
# load
pineappl_grid = pineappl.grid.Grid.read(str(pineappl_path))
_x_grid, _pids, mur2_grid, _muf2_grid = pineappl_grid.axes()
operators = eko.output.Output.load_tar(eko_path)
check.check_grid_and_eko_compatible(pineappl_grid, operators, xif)
Expand Down
23 changes: 19 additions & 4 deletions src/pineko/theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import yaml
from eko import strong_coupling as sc

from . import configs, evolve, parser, theory_card
from . import check, configs, evolve, parser, theory_card

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -346,6 +346,15 @@ def fk(self, name, grid_path, tcard, pdf):
do_log = self.activate_logging(
paths["logs"]["fk"], f"{self.theory_id}-{name}-{pdf}.log"
)
# check if grid contains SV if theory is requesting them
xir = tcard["XIR"]
xif = tcard["XIF"]
Copy link
Member

Choose a reason for hiding this comment

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

@felixhekhorn didn't we have another variable, e.g. in yadism. In order to compute scale variations, even when we are not given a specific value?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, we have there "activateFact" (or similar name) in order to decide whether to compute the SV grids - however for pineko this is not sufficient since we need to collapse on the actual value - or what were you thinking?

Copy link
Member

@alecandido alecandido Jul 11, 2022

Choose a reason for hiding this comment

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

Sorry, so it is just the first part of the comment to be referred to the code below.

Maybe I'd just move it: first # check if sv are requested then # in case of sv, check they are available in the grid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean just the comments right? because the code is already doing that: first it checks if the theory is asking for scale-variations and then it checks whether they are available in the gird.

ftr = tcard["fact_to_ren_scale_ratio"]
pineappl_grid = pineappl.grid.Grid.read(grid_path)
if not np.isclose(xir, 1.0):
check.check_grid_contains_ren_sv(pineappl_grid)
if not (np.isclose(xif, 1.0) and np.isclose(ftr, 1.0)):
check.check_grid_contains_fact_sv(pineappl_grid)
# setup data
eko_filename = self.ekos_path() / f"{name}.tar"
fk_filename = self.fks_path / f"{name}.{parser.EXT}"
Expand All @@ -362,8 +371,6 @@ def fk(self, name, grid_path, tcard, pdf):
# q2_grid = ocard["Q2grid"]
operators = eko.output.Output.load_tar(eko_filename)
q2_grid = operators["Q2grid"].keys()
xir = tcard["XIR"]
xif = tcard["XIF"]
# PineAPPL wants alpha_s = 4*pi*a_s
alphas_values = [
4.0 * np.pi * astrong.a_s(xir * xir * Q2 / xif / xif) for Q2 in q2_grid
Expand All @@ -374,8 +381,16 @@ def fk(self, name, grid_path, tcard, pdf):
logger.info("Start computation of %s", name)
logger.info("max_as=%d, max_al=%d, xir=%f, xif=%f", max_as, max_al, xir, xif)
start_time = time.perf_counter()

rich.print(
rich.panel.Panel.fit("Computing ...", style="magenta", box=rich.box.SQUARE),
f" {grid_path}\n",
f"+ {eko_filename}\n",
f"= {fk_filename}\n",
f"with max_as={max_as}, max_al={max_al}, xir={xir}, xif={xif}",
)
_grid, _fk, comparison = evolve.evolve_grid(
grid_path,
pineappl_grid,
eko_filename,
fk_filename,
max_as,
Expand Down