Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.ht
[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
https://www.contributor-covenant.org/faq
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -28,3 +28,10 @@ repos:
rev: v2.34.0
hooks:
- id: pyupgrade
- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle
files: ^src/
additional_dependencies:
- toml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Guidelines](https://github.com/N3PDF/pineko/blob/main/.github/CONTRIBUTING.md).

## Documentation
- The documentation is available here: <a href="https://pineko.readthedocs.io/en/latest/"><img alt="Docs" src="https://readthedocs.org/projects/pineko/badge/?version=latest"></a>
- To build the documentation from source run
- To build the documentation from source run
```bash
cd docs
poetry run make html
Expand Down
1 change: 1 addition & 0 deletions data/grids/load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
# theory example
# scp dom.mi.infn.it:/media/FK/fktables/data/grids/200-SLAC_NC_EM_D_F2.pineappl.lz4 ./200/SLAC_NC_EM_D_F2.pineappl.lz4
# scp dom.mi.infn.it:/media/FK/fktables/data/grids/200-SLAC_NC_EM_P_F2.pineappl.lz4 ./200/SLAC_NC_EM_P_F2.pineappl.lz4
# scp dom.mi.infn.it:/media/FK/fktables_pineko/data/grids/208/HERA_CC_318GEV_EM_SIGMARED.pineappl.lz4 ./208/HERA_CC_318GEV_EM_SIGMARED.pineappl.lz4
497 changes: 151 additions & 346 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 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 Expand Up @@ -110,3 +110,6 @@ max-line-length = 100
[tool.pylint.design]
# Maximum number of arguments for function / method
max-args = 10

[tool.pydocstyle]
convention = "numpy"
2 changes: 2 additions & 0 deletions src/pineko/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
"""pineko = PineAPPL + EKO."""

from .cli import command
from .comparator import compare

Expand Down
46 changes: 35 additions & 11 deletions src/pineko/check.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# -*- coding: utf-8 -*-
"""Tools to check compatibility of EKO and grid."""
import numpy as np


def in1d(a, b, rtol=1e-05, atol=1e-08):
"""
Improved version of np.in1d.
"""Improved version of np.in1d.

Thanks: https://github.com/numpy/numpy/issues/7784#issuecomment-848036186

Parameters
----------
a : list
needle
b : list
haystack
rtol : float
allowed relative error
atol : float
allowed absolute error

Returns
-------
list
mask of found elements
"""
if len(a) == 1:
for be in b:
Expand All @@ -19,21 +35,29 @@ def in1d(a, b, rtol=1e-05, atol=1e-08):
)


def check_grid_and_eko_compatible(pineappl_grid, operators):
"""
Raises a `ValueError` if the EKO operators and the PineAPPL grid are NOT compatible.
def check_grid_and_eko_compatible(pineappl_grid, operators, xif):
"""Check whether the EKO operators and the PineAPPL grid are compatible.

Parameters
----------
pineappl_grid : pineappl.grid.Grid
grid
operators : eko.output.Output
operators
pineappl_grid : pineappl.grid.Grid
grid
operators : eko.output.Output
operators
xif : float
factorization scale variation

Raises
------
ValueError
If the operators and the grid are not compatible.
"""
x_grid, _pids, muf2_grid = pineappl_grid.axes()
x_grid, _pids, _mur2_grid, muf2_grid = pineappl_grid.axes()
# Q2 grid
if not np.all(
in1d(np.unique(list(operators["Q2grid"].keys())), np.array(muf2_grid))
in1d(
np.unique(list(operators["Q2grid"].keys())), xif * xif * np.array(muf2_grid)
)
):
raise ValueError(
"Q2 grid in pineappl grid and eko operator are NOT compatible!"
Expand Down
1 change: 1 addition & 0 deletions src/pineko/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""CLI entry point."""
from . import check, compare, convolute, opcard, theory_
from ._base import command
2 changes: 1 addition & 1 deletion src/pineko/cli/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

@click.group(context_settings=CONTEXT_SETTINGS)
def command():
"""pineko: Combine PineAPPL grids and EKOs into FK tables"""
"""pineko: Combine PineAPPL grids and EKOs into FK tables."""
8 changes: 6 additions & 2 deletions src/pineko/cli/check.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
"""CLI entry point to check compatibility."""
import click
import eko.output
import pineappl
Expand All @@ -11,16 +12,19 @@
@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))
def subcommand(pineappl_path, eko_path):
@click.option("--xif", default=1.0, help="factorization scale variation")
def subcommand(pineappl_path, eko_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)
try:
check.check_grid_and_eko_compatible(pineappl_grid, operators)
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)
11 changes: 8 additions & 3 deletions src/pineko/cli/compare.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
"""CLI entry point to comparison grid vs. FK Table."""
import click
import pineappl
import rich
Expand All @@ -13,8 +14,10 @@
@click.argument("max_as", type=int)
@click.argument("max_al", type=int)
@click.argument("pdf", type=str)
def subcommand(pineappl_path, fktable_path, max_as, max_al, pdf):
"""Compare process level PineAPPL grid and derived FkTable.
@click.option("--xir", default=1.0, help="renormalization scale variation")
@click.option("--xif", default=1.0, help="factorization scale variation")
def subcommand(pineappl_path, fktable_path, max_as, max_al, pdf, xir, xif):
"""Compare process level PineAPPL grid and derived FK Table.

The comparison between the grid stored at PINEAPPL_PATH, and the FK table
stored at FKTABLE_PATH, is performed by convoluting both the grids with the PDF
Expand All @@ -23,8 +26,10 @@ def subcommand(pineappl_path, fktable_path, max_as, max_al, pdf):

The comparison involves the orders in QCD and QED up to the maximum power
of the coupling corresponding respectively to MAX_AS and MAX_AL.

XIR and XIF represent the renormalization and factorization scale in the grid respectively.
"""
pine = pineappl.grid.Grid.read(pineappl_path)
fk = pineappl.fk_table.FkTable.read(fktable_path)
# Note that we need to cast to string before printing to avoid ellipsis ...
rich.print(comparator.compare(pine, fk, max_as, max_al, pdf).to_string())
rich.print(comparator.compare(pine, fk, max_as, max_al, pdf, xir, xif).to_string())
30 changes: 24 additions & 6 deletions src/pineko/cli/convolute.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
"""CLI entry point to convolution."""
import click

from .. import evolve
Expand All @@ -11,25 +12,42 @@
@click.argument("fktable", type=click.Path())
@click.argument("max_as", type=int)
@click.argument("max_al", type=int)
@click.option("--xir", default=1.0, help="renormalization scale variation")
@click.option("--xif", default=1.0, help="factorization scale variation")
@click.option(
"--pdf", default=None, help="if given, print comparison table", show_default=True
)
@click.option(
"--assumption",
"--assumptions",
default="Nf6Ind",
help="the assumption to be used",
help="the flavor assumptions to be used",
show_default=True,
)
def subcommand(pineappl, eko, fktable, max_as, max_al, pdf, assumption):
"""Convolute PineAPPL grid and EKO.
def subcommand(pineappl, eko, 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
FKTABLE is the path where to dump the output.
Moreover, MAX_AS and MAX_AL are used to specify the order in QCD and QED

MAX_AS and MAX_AL are used to specify the order in QCD and QED
couplings (i.e. the maximum power allowed for each correction).

XIR and XIF represent the renormalization and factorization scale in the grid respectively.

ASSUMPTIONS represent the assumptions on the flavor dimension.

PDF is an optional PDF set compatible with the EKO to compare grid and FK table.
"""
_grid, _fk, comp = evolve.evolve_grid(
pineappl, eko, fktable, max_as, max_al, pdf, assumption
pineappl,
eko,
fktable,
max_as,
max_al,
xir,
xif,
assumptions=assumptions,
comparison_pdf=pdf,
)
if comp:
print(comp.to_string())
8 changes: 6 additions & 2 deletions src/pineko/cli/opcard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
"""CLI entry point to the operator card generation."""
import click
import rich

Expand All @@ -12,14 +13,17 @@
"default_card_path", metavar="DEFAULT_CARD", type=click.Path(exists=True)
)
@click.argument("opcard_path", metavar="OPCARD", type=click.Path())
def subcommand(pineappl_path, default_card_path, opcard_path):
@click.option("--xif", default=1.0, help="factorization scale variation")
def subcommand(pineappl_path, default_card_path, opcard_path, xif):
"""Write EKO card for PineAPPL grid.

Writes a copy of the default card from DEFAULT_CARD to OPCARD
with the adjusted x grid and Q2 grid read from PINEAPPL.

XIF is the factorization scale variation.
"""
_x_grid, q2_grid = evolve.write_operator_card_from_file(
pineappl_path, default_card_path, opcard_path
pineappl_path, default_card_path, opcard_path, xif
)
rich.print(
f"[green]Success:[/] Wrote card with {len(q2_grid)} Q2 points to {opcard_path}"
Expand Down
7 changes: 4 additions & 3 deletions src/pineko/cli/theory_.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
"""'theory' mode of CLI."""
import pathlib

import click
Expand All @@ -17,7 +18,7 @@
help="Explicitly specify config file (it has to be a valid TOML file).",
)
def theory_(cfg):
"""Iterate a subcommand on a given theory and list of datasets"""
"""Iterate a subcommand on a given theory and list of datasets."""
path = configs.detect(cfg)
base_configs = configs.load(path)
configs.configs = configs.defaults(base_configs)
Expand All @@ -32,7 +33,7 @@ def theory_(cfg):
@click.option("--overwrite", is_flag=True, help="Allow files to be overwritten")
def inherit_grids(source_theory_id, target_theory_id, datasets, overwrite):
"""Inherit grids for datasets from one theory to another."""
theory.TheoryBuilder(source_theory_id, datasets, overwrite).inherit_grids(
theory.TheoryBuilder(source_theory_id, datasets, overwrite=overwrite).inherit_grids(
target_theory_id
)

Expand All @@ -43,7 +44,7 @@ def inherit_grids(source_theory_id, target_theory_id, datasets, overwrite):
@click.option("--overwrite", is_flag=True, help="Allow files to be overwritten")
def opcards(theory_id, datasets, overwrite):
"""Write EKO card for all FK tables in all datasets."""
theory.TheoryBuilder(theory_id, datasets, overwrite).opcards()
theory.TheoryBuilder(theory_id, datasets, overwrite=overwrite).opcards()


@theory_.command()
Expand Down
41 changes: 24 additions & 17 deletions src/pineko/comparator.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
# -*- coding: utf-8 -*-
"""Provide tools to compare grids and FK tables"""
"""Tools to compare grids and FK tables."""

import numpy as np
import pandas as pd
import pineappl


def compare(pine, fktable, max_as, max_al, pdf):
"""
Build comparison table.
def compare(pine, fktable, max_as, max_al, pdf, xir, xif):
"""Build comparison table.

Parameters
----------
pine : pineappl.grid.Grid
uncovoluted grid
fktable : pineappl.fktable.FkTable
convoluted grid
max_as : int
maximum power of strong coupling
max_al : int
maximum power of electro-weak coupling
pdf : str
PDF set name
pine : pineappl.grid.Grid
uncovoluted grid
fktable : pineappl.fktable.FkTable
convoluted grid
max_as : int
maximum power of strong coupling
max_al : int
maximum power of electro-weak coupling
pdf : str
PDF set name
xir : float
renormalization scale variation
xif : float
factorization scale variation

Returns
-------
df : pd.DataFrame
comparison table
df : pd.DataFrame
comparison table
"""
import lhapdf # pylint: disable=import-outside-toplevel

Expand All @@ -35,7 +38,11 @@ def compare(pine, fktable, max_as, max_al, pdf):
order_mask = pineappl.grid.Order.create_mask(pine.orders(), max_as, max_al)
before = np.array(
pine.convolute_with_one(
pdgid, pdfset.xfxQ2, pdfset.alphasQ2, order_mask=order_mask
pdgid,
pdfset.xfxQ2,
pdfset.alphasQ2,
order_mask=order_mask,
xi=((xir, xif),),
)
)
after = np.array(fktable.convolute_with_one(pdgid, pdfset.xfxQ2))
Expand Down
1 change: 1 addition & 0 deletions src/pineko/configs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
"""Tools related to the configuration file handling."""
import copy
import pathlib

Expand Down
Loading