From c879ba8e3690da8e2384bd5c1822cc4aa9e1c959 Mon Sep 17 00:00:00 2001 From: Giacomo Magni Date: Tue, 9 Jul 2024 18:15:39 +0200 Subject: [PATCH] remove is_polarized and make it working --- n3fit/src/n3fit/layers/observable.py | 2 ++ n3fit/src/n3fit/tests/test_layers.py | 2 -- validphys2/src/validphys/convolution.py | 30 ++++++++++++++++++------- validphys2/src/validphys/coredata.py | 5 ----- validphys2/src/validphys/pineparser.py | 2 -- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/n3fit/src/n3fit/layers/observable.py b/n3fit/src/n3fit/layers/observable.py index 5bbcaa0428..a513fd6ed3 100644 --- a/n3fit/src/n3fit/layers/observable.py +++ b/n3fit/src/n3fit/layers/observable.py @@ -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 diff --git a/n3fit/src/n3fit/tests/test_layers.py b/n3fit/src/n3fit/tests/test_layers.py index 651b856a79..f5df35ddcc 100644 --- a/n3fit/src/n3fit/tests/test_layers.py +++ b/n3fit/src/n3fit/tests/test_layers.py @@ -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",) @@ -120,7 +119,6 @@ def generate_had(nfk=1): fk, comb, np.ones((1, XSIZE)), - is_polarized=False, convolution_types=("UnpolPDF", "UnpolPDF"), ) ) diff --git a/validphys2/src/validphys/convolution.py b/validphys2/src/validphys/convolution.py index ba7509cd69..6c6a538cfa 100644 --- a/validphys2/src/validphys/convolution.py +++ b/validphys2/src/validphys/convolution.py @@ -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): @@ -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): @@ -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) diff --git a/validphys2/src/validphys/coredata.py b/validphys2/src/validphys/coredata.py index 5382d16e59..d4f7feb09d 100644 --- a/validphys2/src/validphys/coredata.py +++ b/validphys2/src/validphys/coredata.py @@ -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 @@ -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 diff --git a/validphys2/src/validphys/pineparser.py b/validphys2/src/validphys/pineparser.py index 280e8c49dc..7986576b6c 100644 --- a/validphys2/src/validphys/pineparser.py +++ b/validphys2/src/validphys/pineparser.py @@ -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": @@ -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,