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 34 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
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")
1 change: 0 additions & 1 deletion src/pineko/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""CLI entry point."""
from . import check, compare, convolute, opcard, theory_
from ._base import command
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")
22 changes: 16 additions & 6 deletions src/pineko/cli/convolute.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# -*- 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("eko", type=click.Path(exists=True))
@click.argument("grid_path", type=click.Path(exists=True))
@click.argument("op_path", type=click.Path(exists=True))
@click.argument("fktable", type=click.Path())
@click.argument("max_as", type=int)
@click.argument("max_al", 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(grid_path, op_path, fktable, max_as, max_al, xir, xif, pdf, assumptions):
"""Convolute PineAPPL grid and EKO into an FK table.

PINEAPPL and EKO are the path to the respective elements to convolute, and
GRID_PATH and OP_PATH 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,9 +40,17 @@ 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.
"""
grid = pineappl.grid.Grid.read(grid_path)
rich.print(
rich.panel.Panel.fit("Computing ...", style="magenta", box=rich.box.SQUARE),
f" {grid_path}\n",
f"+ {op_path}\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,
eko,
grid,
op_path,
fktable,
max_as,
max_al,
Expand Down
25 changes: 8 additions & 17 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,
grid,
eko_path,
fktable_path,
max_as,
Expand All @@ -92,7 +92,7 @@ def evolve_grid(

Parameters
----------
pineappl_path : str
grid : pineappl.grid.Grid
unconvoluted grid
eko_path : str
evolution operator
Expand All @@ -113,32 +113,23 @@ 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()
_x_grid, _pids, mur2_grid, _muf2_grid = grid.axes()
operators = eko.output.Output.load_tar(eko_path)
check.check_grid_and_eko_compatible(pineappl_grid, operators, xif)
check.check_grid_and_eko_compatible(grid, operators, xif)
# rotate to evolution (if doable and necessary)
if np.allclose(operators["inputpids"], br.flavor_basis_pids):
operators.to_evol()
elif not np.allclose(operators["inputpids"], br.evol_basis_pids):
raise ValueError("The EKO is neither in flavor nor in evolution basis.")
# do it
order_mask = pineappl.grid.Order.create_mask(pineappl_grid.orders(), max_as, max_al)
order_mask = pineappl.grid.Order.create_mask(grid.orders(), max_as, max_al)
# TODO this is a hack to not break the CLI
# the problem is that the EKO output still does not contain the theory/operators card and
# so I can't compute alpha_s *here* if xir != 1
if np.isclose(xir, 1.0) and alphas_values is None:
mur2_grid = list(operators["Q2grid"].keys())
alphas_values = [op["alphas"] for op in operators["Q2grid"].values()]
fktable = pineappl_grid.convolute_eko(
fktable = grid.convolute_eko(
operators,
xir * xir * mur2_grid,
alphas_values,
Expand All @@ -154,8 +145,8 @@ def evolve_grid(
comparison = None
if comparison_pdf is not None:
comparison = comparator.compare(
pineappl_grid, fktable, max_as, max_al, comparison_pdf, xir, xif
grid, fktable, max_as, max_al, comparison_pdf, xir, xif
)
fktable.set_key_value("results_fk", comparison.to_string())
fktable.set_key_value("results_fk_pdfset", comparison_pdf)
return pineappl_grid, fktable, comparison
return grid, fktable, comparison
24 changes: 20 additions & 4 deletions src/pineko/theory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

import eko
import numpy as np
import pineappl
import rich
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 +347,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 +372,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 +382,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