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

Pineappl integration with validphys #1529

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
4e5e87e
initial commit, vp compatible pineappl fkparser
scarlehoff Feb 22, 2022
ea04749
notebook
scarlehoff Feb 22, 2022
dd123c5
make the fit pineappl compatible
scarlehoff Feb 23, 2022
a1af650
dont load unnecesary C++stuff
scarlehoff Feb 23, 2022
f881b55
move the parsing of the fktable to FKTableData
scarlehoff Feb 24, 2022
14630f8
remove the last explicit piece of libNNPDF from n3fit
scarlehoff Feb 24, 2022
1978d38
use coredata.FKTableData directly in n3fit
scarlehoff Feb 24, 2022
0aba554
update tests
scarlehoff Feb 24, 2022
16b53cc
remove the positivity singularity, now everything is a FittableDataset
scarlehoff Feb 24, 2022
6de540e
use compounds files for the cfactors for the time being
scarlehoff Feb 28, 2022
a6c8b83
consider dis flag cancome in different flavours
scarlehoff Mar 1, 2022
d03ed66
consider apfelcomb compatibility: shifts and repetitions
scarlehoff Mar 1, 2022
9fcceac
more apfelcomb compatibility, apply the normalization factor
scarlehoff Mar 1, 2022
94b3772
add the norm operation
scarlehoff Mar 2, 2022
070c6d7
fix apfelcomb normalization
scarlehoff Mar 2, 2022
6a8911a
fix to load_with_cuts
scarlehoff Mar 3, 2022
7821bef
remove set_eager
scarlehoff Mar 3, 2022
fc8599f
fix for positivity
scarlehoff Mar 3, 2022
384d5eb
allow for old style runcards with poslambda
scarlehoff Mar 4, 2022
978fa68
improve the positivity loader a bit
scarlehoff Mar 8, 2022
509c7d9
isolate a bit more unnecessary libNNPDF loads()
scarlehoff Mar 8, 2022
38a953f
simplify apfelcomb workarounds
scarlehoff Mar 8, 2022
1cb32f1
ensure __hash__ works also for pineappl
scarlehoff Mar 9, 2022
8c37fed
move cfactor application to coredata
scarlehoff Mar 9, 2022
76b1568
apply a bit more refactoring
scarlehoff Mar 10, 2022
1d24c59
fix for optimized fktables
scarlehoff Mar 11, 2022
40e2138
remove NORM operation
scarlehoff Mar 15, 2022
d12e4c3
remove the need to know about protected outside of coredata
scarlehoff Mar 16, 2022
706c563
since we have now a `FittableDataSet`, separate their generation from…
scarlehoff Mar 18, 2022
2da7540
add a flag to fail if the yaml file is not found
scarlehoff Mar 21, 2022
7cb96fc
make sure we are not hashing too much for appl converted grids
scarlehoff Mar 21, 2022
fed0110
changes to comments and explanations
scarlehoff Mar 23, 2022
1a3b9d8
try to use pineappl in conda
scarlehoff Apr 1, 2022
91d5e86
use level_values for x1/x2, unstack for data
scarlehoff Apr 4, 2022
8a2f870
typo
scarlehoff Apr 4, 2022
5ec5dfe
organize the reader, import only things in conda-forge
scarlehoff Apr 4, 2022
646dd01
Update n3fit/src/n3fit/layers/observable.py
scarlehoff Apr 4, 2022
3a7d0d1
be explicit with the versions of pineappl/eko
scarlehoff Apr 4, 2022
9e9d8c4
Merge branch 'validphys_with_pineappl' of github.com:NNPDF/nnpdf into…
scarlehoff Apr 4, 2022
cb41113
hide away imports
scarlehoff Apr 4, 2022
022452d
apply suggestions
scarlehoff May 9, 2022
cb1691b
create a lagrangesetspec
scarlehoff May 9, 2022
65f243e
Apply suggestions from code review
scarlehoff May 9, 2022
3d109f1
modified the code to work with an actual theory_XYZ
scarlehoff May 17, 2022
8ee9005
add theory 400 to the theory db
scarlehoff May 17, 2022
7380d89
dont install eko-pineappl
scarlehoff May 21, 2022
ace28e6
add pineappl
scarlehoff May 22, 2022
4306fb6
install eko
scarlehoff May 22, 2022
942732c
check whether numba alone is enough to break it
scarlehoff May 25, 2022
446867c
bypass the error
scarlehoff May 25, 2022
3ca37ab
style
scarlehoff May 25, 2022
cb1fe42
change load->loadcommondata also for the theory cov
scarlehoff Jun 9, 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
1,140 changes: 1,140 additions & 0 deletions FKTable Playground.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ requirements:
- sphinxcontrib-bibtex
- docutils =0.16 # This dependency is not explicity needed but https://github.com/NNPDF/nnpdf/issues/1220
- curio >=1.0
- pineappl >=0.5.2

test:
requires:
Expand Down
46 changes: 23 additions & 23 deletions n3fit/src/n3fit/layers/observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def _is_unique(list_of_arrays):
""" Check whether the list of arrays more than one different arrays """
"""Check whether the list of arrays more than one different arrays"""
the_first = list_of_arrays[0]
for i in list_of_arrays[1:]:
if not np.array_equal(the_first, i):
Expand All @@ -15,40 +15,40 @@ def _is_unique(list_of_arrays):

class Observable(MetaLayer, ABC):
"""
This class is the parent of the DIS and DY convolutions.
All backend-dependent code necessary for the convolutions
is (must be) concentrated here
This class is the parent of the DIS and DY convolutions.
All backend-dependent code necessary for the convolutions
is (must be) concentrated here

The methods gen_mask and call must be overriden by the observables
where
- gen_mask: it is called by the initializer and generates the mask between
fktables and pdfs
- call: this is what does the actual operation
The methods gen_mask and call must be overriden by the observables
where
- gen_mask: it is called by the initializer and generates the mask between
fktables and pdfs
- call: this is what does the actual operation


Parameters
----------
fktable_dicts: list
list of fktable_dicts which define basis and xgrid for the fktables in the list
fktable_arr: list
list of fktables for this observable
operation_name: str
string defining the name of the operation to be applied to the fktables
nfl: int
number of flavours in the pdf (default:14)
Parameters
----------
fktable_data: list[validphys.coredata.FKTableData]
list of FK which define basis and xgrid for the fktables in the list
fktable_arr: list
list of fktables for this observable
operation_name: str
string defining the name of the operation to be applied to the fktables
nfl: int
number of flavours in the pdf (default:14)
"""

def __init__(self, fktable_dicts, fktable_arr, operation_name, nfl=14, **kwargs):
def __init__(self, fktable_data, fktable_arr, operation_name, nfl=14, **kwargs):
super(MetaLayer, self).__init__(**kwargs)

self.nfl = nfl

basis = []
xgrids = []
self.fktables = []
for fktable, fk in zip(fktable_dicts, fktable_arr):
xgrids.append(fktable["xgrid"])
basis.append(fktable["basis"])
for fkdata, fk in zip(fktable_data, fktable_arr):
xgrids.append(fkdata.xgrid.reshape(1, -1))
basis.append(fkdata.luminosity_mapping)
self.fktables.append(op.numpy_to_tensor(fk))

# check how many xgrids this dataset needs
Expand Down
34 changes: 17 additions & 17 deletions n3fit/src/n3fit/model_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,72 +134,72 @@ def observable_generator(
model_obs_ex = []
model_inputs = []
# The first step is to compute the observable for each of the datasets
for dataset_dict in spec_dict["datasets"]:
for dataset in spec_dict["datasets"]:
# Get the generic information of the dataset
dataset_name = dataset_dict["name"]
dataset_name = dataset.name

# Look at what kind of layer do we need for this dataset
if dataset_dict["hadronic"]:
if dataset.hadronic:
Obs_Layer = DY
else:
Obs_Layer = DIS

# Set the operation (if any) to be applied to the fktables of this dataset
operation_name = dataset_dict["operation"]
operation_name = dataset.operation

# Now generate the observable layer, which takes the following information:
# operation name
# dataset name
# list of fktable_dictionaries
# list of validphys.coredata.FKTableData objects
# these will then be used to check how many different pdf inputs are needed
# (and convolutions if given the case)

if spec_dict["positivity"]:
# Positivity (and integrability, which is a special kind of positivity...)
# enters only at the "training" part of the models
obs_layer_tr = Obs_Layer(
dataset_dict["fktables"],
dataset_dict["tr_fktables"],
dataset.fktables_data,
dataset.training_fktables(),
operation_name,
name=f"dat_{dataset_name}",
)
obs_layer_ex = obs_layer_vl = None
elif spec_dict.get("data_transformation_tr") is not None:
# Data transformation needs access to the full array of output data
obs_layer_ex = Obs_Layer(
dataset_dict["fktables"],
dataset_dict["ex_fktables"],
dataset.fktables_data,
dataset.fktables(),
operation_name,
name=f"exp_{dataset_name}",
)
obs_layer_tr = obs_layer_vl = obs_layer_ex
else:
obs_layer_tr = Obs_Layer(
dataset_dict["fktables"],
dataset_dict["tr_fktables"],
dataset.fktables_data,
dataset.training_fktables(),
operation_name,
name=f"dat_{dataset_name}",
)
obs_layer_ex = Obs_Layer(
dataset_dict["fktables"],
dataset_dict["ex_fktables"],
dataset.fktables_data,
dataset.fktables(),
operation_name,
name=f"exp_{dataset_name}",
)
obs_layer_vl = Obs_Layer(
dataset_dict["fktables"],
dataset_dict["vl_fktables"],
dataset.fktables_data,
dataset.validation_fktables(),
operation_name,
name=f"val_{dataset_name}",
)

# To know how many xpoints we compute we are duplicating functionality from obs_layer
if obs_layer_tr.splitting is None:
xgrid = dataset_dict["fktables"][0]["xgrid"]
xgrid = dataset.fktables_data[0].xgrid.reshape(1, -1)
model_inputs.append(xgrid)
dataset_xsizes.append(xgrid.shape[1])
else:
xgrids = [i["xgrid"] for i in dataset_dict["fktables"]]
xgrids = [i.xgrid.reshape(1, -1) for i in dataset.fktables_data]
model_inputs += xgrids
dataset_xsizes.append(sum([i.shape[1] for i in xgrids]))

Expand Down
13 changes: 8 additions & 5 deletions n3fit/src/n3fit/model_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def __init__(
"""
# Save all input information
self.exp_info = exp_info
if pos_info is None:
pos_info = []
self.pos_info = pos_info
self.integ_info = integ_info
if self.integ_info is not None:
Expand Down Expand Up @@ -275,7 +277,7 @@ def _fill_the_dictionaries(self):
self.experimental["ndata"] += nd_tr + nd_vl

for dataset in exp_dict["datasets"]:
self.all_datasets.append(dataset["name"])
self.all_datasets.append(dataset.name)
self.all_datasets = set(self.all_datasets)

for pos_dict in self.pos_info:
Expand Down Expand Up @@ -532,7 +534,7 @@ def _generate_observables(
force_set_smallest = input_arr.min() > 1e-9
if force_set_smallest:
new_xgrid = np.linspace(
start=1/input_arr_size, stop=1.0, endpoint=False, num=input_arr_size
start=1 / input_arr_size, stop=1.0, endpoint=False, num=input_arr_size
)
else:
new_xgrid = np.linspace(start=0, stop=1.0, endpoint=False, num=input_arr_size)
Expand Down Expand Up @@ -566,8 +568,7 @@ def _generate_observables(
scaler = PchipInterpolator(map_from, map_to)
except ValueError:
raise ValueError(
"interpolation_points is larger than the number of unique "
"input x-values"
"interpolation_points is larger than the number of unique " "input x-values"
)
self._scaler = lambda x: np.concatenate([scaler(np.log(x)), x], axis=-1)

Expand Down Expand Up @@ -918,7 +919,9 @@ def hyperparametrizable(self, params):
# by adding it to this dictionary
dict_out = {
"status": passed,
"loss": self._hyper_loss(fold_losses=l_hyper, n3pdfs=n3pdfs, experimental_models=exp_models),
"loss": self._hyper_loss(
fold_losses=l_hyper, n3pdfs=n3pdfs, experimental_models=exp_models
),
"validation_loss": np.average(l_valid),
"experimental_loss": np.average(l_exper),
"kfold_meta": {
Expand Down
Loading