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

Update PineAPPL version to v1 #2217

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# A single CI script with github workflow to test NNPDF, and upload the conda package and documentation
name: Test conda package

on: [push]
on:
push:
branches-ignore:
- update-pineappl-v1

concurrency:
group: ${{ github.head_ref || github.ref }}
Expand Down
1 change: 0 additions & 1 deletion conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ requirements:
- requests
- prompt_toolkit
- validobj
- pineappl >=0.8.2
- eko >=0.14.2
- fiatlux
- sphinx >=5.0.2
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ vp-deltachi2 = "validphys.scripts.vp_deltachi2:main"
# Generic dependencies (i.e., validphys)
python = "^3.9"
matplotlib = ">=3.3.0,<3.8"
pineappl = "^0.8.2"
pineappl = { git = "https://github.com/NNPDF/pineappl.git", branch = "v1-file-format", subdirectory = "pineappl_py" }
pandas = "*"
numpy = "*"
validobj = "*"
Expand Down
20 changes: 11 additions & 9 deletions validphys2/src/validphys/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FKTableData:
``xgrid`` indicating the points in ``x`` where the PDF should be
evaluated.

convolution_types: tuple[str]
convolution_types: list(pineappl.convolutions.Conv)
The type of convolution that the FkTable is expecting for each of the
functions to be convolved with (usually the two types of PDF from the two
incoming hadrons).
Expand All @@ -68,7 +68,7 @@ class FKTableData:
ndata: int
xgrid: np.ndarray
sigma: pd.DataFrame
convolution_types: tuple[str] = None
convolution_types: list | None = None
Radonirinaunimi marked this conversation as resolved.
Show resolved Hide resolved
metadata: dict = dataclasses.field(default_factory=dict, repr=False)
protected: bool = False

Expand Down Expand Up @@ -206,26 +206,28 @@ def determine_pdfs(self, pdf):

conv_pdfs = []
for convolution_type in self.convolution_types:

# Check the polarization of the current convolution
polarized = convolution_type.conv_type.polarized
# Check the type of convolutions that the fktable is asking for and match it to the PDF
if convolution_type == "UnpolPDF":
if not polarized:
if pdf.is_polarized:
if pdf.unpolarized_bc is None:
raise ValueError(
"The FKTable asked for an unpolarized PDF but received only polarized PDFs"
)

conv_pdfs.append(pdf.unpolarized_bc.make_only_cv())
else:
conv_pdfs.append(pdf)

elif convolution_type == "PolPDF":
elif polarized:
if not pdf.is_polarized:
raise ValueError(
"""The FKTable asked for a polarized PDF, but the PDF received cannot be understood as polarized.
When using a polarized PDF make sure to include a boundary condition `unpolarized_bc: <pdf name>` whenever needed (`t0`, `dataspecs`...)."""
"""The FKTable asked for a polarized PDF, but the PDF received cannot be understood
as polarized. When using a polarized PDF make sure to include a boundary condition
`unpolarized_bc: <pdf name>` whenever needed (`t0`, `dataspecs`...)."""
)
conv_pdfs.append(pdf)
else: # Other scenarios (such as `time_like`) should be implemented as another `elif` statement
raise ValueError("The convolution type is not recognized!")

return conv_pdfs

Expand Down
2 changes: 1 addition & 1 deletion validphys2/src/validphys/photon/structure_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, path_to_fktable, pdfs):

self.q2_max = max(q2)

predictions = self.fktable.convolve_with_one(2212, pdfs.xfxQ2)
predictions = self.fktable.convolve(pdg_convs=self.fktable.convolutions, xfxs=[pdfs.xfxQ2])

grid2D = predictions.reshape(len(x), len(q2))
self.interpolator = RectBivariateSpline(x, q2, grid2D)
Expand Down
43 changes: 18 additions & 25 deletions validphys2/src/validphys/pineparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,15 @@ def _pinelumi_to_columns(pine_luminosity, hadronic):
)
flav_size = len(evol_basis_pids)
columns = []
# TODO: Extend this to deal with a generic number of convolutions
if hadronic:
for i, j in pine_luminosity:
idx = evol_basis_pids.index(i)
jdx = evol_basis_pids.index(j)
columns.append(flav_size * idx + jdx)
else:
# The proton might come from both sides
try:
columns = [evol_basis_pids.index(i) for _, i in pine_luminosity]
except ValueError:
columns = [evol_basis_pids.index(i) for i, _ in pine_luminosity]
# Now for DIS, there is only ONE single PID
columns = [evol_basis_pids.index(i[0]) for i in pine_luminosity]
return columns


Expand Down Expand Up @@ -155,26 +153,18 @@ def pineappl_reader(fkspec):
# Extract metadata from the first grid
pine_rep = pines[0]

# Is it hadronic? (at the moment only hadronic and DIS are considered)
try:
parton1 = pine_rep.key_values()["convolution_particle_1"]
parton2 = pine_rep.key_values()["convolution_particle_2"]
except KeyError:
# Old pineappl FKTables used `initial_state` instead of `convolution_particle`
parton1 = pine_rep.key_values()["initial_state_1"]
parton2 = pine_rep.key_values()["initial_state_2"]
hadronic = parton1 == parton2

# NOTE: while the following can accept any number of convolutions, at the moment only
# 1 (DIS) or 2 (hadronic) are implemented.
# In the case of DIS grids, convolution 1 refers to the hadron
conv_types = [pine_rep.key_values().get("convolution_type_1", "UnpolPDF")]
if hadronic:
# Sanity check (in case at some point we start fitting things that are not protons)
if parton1 != "2212":
raise ValueError("vp can only read hadronic fktables with 2 protons!")
# Get the convolution types for this FK table
convolutions = pine_rep.convolutions

# Is it hadronic? For the time being, hadronic is defined with `len(convolutions) == 2`.
# Hadronic could also involve 3 convolutions in processes such as `pp->H` (with FFs).
# DIS FK table now only contains ONE single convolutions.
hadronic = len(convolutions) == 2
Radonirinaunimi marked this conversation as resolved.
Show resolved Hide resolved

conv_types.append(pine_rep.key_values().get("convolution_type_2", "UnpolPDF"))
# TODO: While now any arbittrary number of convolutions is allowed, for the time being,
# raise Errors when the number of convolutions is more than 2.
if len(convolutions) > 2:
raise ValueError("vp can only deal with fktables with 2 convolutions!")

Q0 = np.sqrt(pine_rep.muf2())
xgrid = np.array([])
Expand Down Expand Up @@ -212,6 +202,9 @@ def pineappl_reader(fkspec):

# Read the table, remove bin normalization and apply cfactors
raw_fktable = (cfprod * p.table().T / p.bin_normalizations()).T
# If it is a DIS FK table then we need to expand the dimension
if not hadronic:
raw_fktable = np.expand_dims(raw_fktable, axis=-1)
n = raw_fktable.shape[0]

# Apply possible per-fktable fixes
Expand Down Expand Up @@ -272,7 +265,7 @@ def pineappl_reader(fkspec):
sigma=sigma,
ndata=ndata,
Q0=Q0,
convolution_types=tuple(conv_types),
convolution_types=convolutions,
metadata=fkspec.metadata,
Radonirinaunimi marked this conversation as resolved.
Show resolved Hide resolved
hadronic=hadronic,
xgrid=xgrid,
Expand Down
16 changes: 11 additions & 5 deletions validphys2/src/validphys/tests/photon/test_structurefunctions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pineappl
from pineappl.convolutions import Conv, ConvType
from pineappl.fk_table import FkTable

from validphys.api import API
from validphys.core import PDF as PDFset
Expand Down Expand Up @@ -35,7 +36,12 @@ def bin_left(self, i):
else:
return 0

def convolve_with_one(self, pdgid, xfxQ2):
@property
def convolutions(self):
convtype = ConvType(polarized=False, time_like=False)
return [Conv(conv_type=convtype, pid=2212)]

def convolve(self, pdg_convs, xfxs):
return np.zeros((10, 10))


Expand Down Expand Up @@ -63,7 +69,7 @@ def test_zero_pdfs():
def test_zero_grid(monkeypatch):
"test that a zero grid gives a zero structure function"
# patching pineappl.fk_table.FkTable to use ZeroFKTable
monkeypatch.setattr(pineappl.fk_table.FkTable, "read", ZeroFKTable)
monkeypatch.setattr(FkTable, "read", ZeroFKTable)
pdfs = PDFset(PDF).load()
structurefunc = sf.InterpStructureFunction("", pdfs.central_member)
for x in np.geomspace(1e-4, 1.0, 10):
Expand Down Expand Up @@ -96,10 +102,10 @@ def test_interpolation_grid():
for kind in ["F2", "FL"]:
tmp = "fastkernel/FIATLUX_DIS_" + kind + ".pineappl.lz4"
path_to_fktable = test_theory.path / tmp
fktable = pineappl.fk_table.FkTable.read(path_to_fktable)
fktable = FkTable.read(path_to_fktable)
x = np.unique(fktable.bin_left(1))
q2 = np.unique(fktable.bin_left(0))
predictions = fktable.convolve_with_one(2212, pdfs.members[replica].xfxQ2)
predictions = fktable.convolve(fktable.convolutions, [pdfs.members[replica].xfxQ2])
grid2D = predictions.reshape(len(x), len(q2))

struct_func = sf.InterpStructureFunction(path_to_fktable, pdfs.members[replica])
Expand Down
Loading