Skip to content

Commit

Permalink
remove is_polarized and make it working
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomomagni committed Jul 9, 2024
1 parent ce73e46 commit c879ba8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
2 changes: 2 additions & 0 deletions n3fit/src/n3fit/layers/observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def __init__(

# Check if the given Positivity dataset is a Polarized one and if the current FK
# table is NOT a Polarized FK table.
# FIXME: I have drop is_polarized, but here we are still using it,
# need to replace these with convolution_types
# `is_polarized` method is deprecated and should be replaced by `convolution_types`
nopol_fk_pos: bool = self.is_pos_polarized() and not fkdata.is_polarized
# Check if the current FK table involves `UnpolPDF` when `boundary_condition` is not None
Expand Down
2 changes: 0 additions & 2 deletions n3fit/src/n3fit/tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class _fake_FKTableData:
fktable: np.array
luminosity_mapping: np.array
xgrid: np.array
is_polarized: bool = False
convolution_types: tuple = ("UnpolPDF",)


Expand Down Expand Up @@ -120,7 +119,6 @@ def generate_had(nfk=1):
fk,
comb,
np.ones((1, XSIZE)),
is_polarized=False,
convolution_types=("UnpolPDF", "UnpolPDF"),
)
)
Expand Down
30 changes: 22 additions & 8 deletions validphys2/src/validphys/convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,25 @@ def fk_predictions(loaded_fk, pdf):
def central_fk_predictions(loaded_fk, pdf, unpolarized_bc=None):
"""Same as :py:func:`fk_predictions`, but computing predictions for the
central PDF member only."""

# if the unpolarized_bc is not None, check the convolution types
if unpolarized_bc is not None:
map_pdf_to_conv_types = {
"UnpolPDF": unpolarized_bc,
"PolPDF": pdf,
"None": None,
}
conv_types = loaded_fk.convolution_types
pdf_list = [
map_pdf_to_conv_types[conv_types[0]],
map_pdf_to_conv_types[conv_types[1]]
]
else:
pdf_list = [pdf, pdf]
if loaded_fk.hadronic:
return central_hadron_predictions(loaded_fk, pdf, unpolarized_bc)
return central_hadron_predictions(loaded_fk, pdf_list)
else:
return central_dis_predictions(loaded_fk, pdf, unpolarized_bc)
return central_dis_predictions(loaded_fk, pdf_list[0])


def linear_fk_predictions(loaded_fk, pdf):
Expand Down Expand Up @@ -412,12 +427,12 @@ def hadron_predictions(loaded_fk, pdf):
return res


def central_hadron_predictions(loaded_fk, pdf, unpolarized_bc):
def central_hadron_predictions(loaded_fk, pdf_list):
"""Implementation of :py:func:`central_fk_predictions` for hadronic
observables."""
# TODO: here we need to fetch the FKtable metadata
gv = functools.partial(evolution.central_grid_values, pdf=pdf)
return _gv_hadron_predictions(loaded_fk, gv)
gv1 = functools.partial(evolution.central_grid_values, pdf=pdf_list[0])
gv2 = functools.partial(evolution.central_grid_values, pdf=pdf_list[1])
return _gv_hadron_predictions(loaded_fk, gv1, gv2)


def linear_hadron_predictions(loaded_fk, pdf):
Expand Down Expand Up @@ -450,9 +465,8 @@ def dis_predictions(loaded_fk, pdf):
return res


def central_dis_predictions(loaded_fk, pdf, unpolarized_bc):
def central_dis_predictions(loaded_fk, pdf):
"""Implementation of :py:func:`central_fk_predictions` for DIS
observables."""
# TODO: here we need to fetch the FKtable metadata
gv = functools.partial(evolution.central_grid_values, pdf=pdf)
return _gv_dis_predictions(loaded_fk, gv)
5 changes: 0 additions & 5 deletions validphys2/src/validphys/coredata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ class FKTableData:
"""
Data contained in an FKTable
TODO: remove `is_polarized` as it is now deprecated and should be replaced by
`convolution_particle_`, but to keep backward compatibility with old grids we
still have to keep it.
Parameters
----------
hadronic : bool
Expand Down Expand Up @@ -67,7 +63,6 @@ class FKTableData:
ndata: int
xgrid: np.ndarray
sigma: pd.DataFrame
is_polarized: bool = False
convolution_types: tuple[str] = ("UnpolPDF",)
metadata: dict = dataclasses.field(default_factory=dict, repr=False)
protected: bool = False
Expand Down
2 changes: 0 additions & 2 deletions validphys2/src/validphys/pineparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def pineappl_reader(fkspec):
convolution_type_1 = pine_rep.key_values().get("convolution_type_1", "UnpolPDF")
convolution_type_2 = pine_rep.key_values().get("convolution_type_2", "UnpolPDF")
conv_types = (convolution_type_1, convolution_type_2)
is_polarized = convolution_type_1 == "PolPDF" or convolution_type_2 == "PolPDF"

# Sanity check (in case at some point we start fitting things that are not protons)
if hadronic and pine_rep.key_values()["convolution_particle_1"] != "2212":
Expand Down Expand Up @@ -265,7 +264,6 @@ def pineappl_reader(fkspec):
sigma=sigma,
ndata=ndata,
Q0=Q0,
is_polarized=is_polarized,
convolution_types=conv_types,
metadata=fkspec.metadata,
hadronic=hadronic,
Expand Down

0 comments on commit c879ba8

Please sign in to comment.