Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlehoff committed Mar 17, 2022
1 parent 01fc9cc commit cf61a30
Show file tree
Hide file tree
Showing 5 changed files with 335 additions and 52 deletions.
158 changes: 158 additions & 0 deletions Playground for the new commondata format.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "cc3f217c",
"metadata": {},
"outputs": [],
"source": [
"# Put here the path where the new datafiles are\n",
"from pathlib import Path\n",
"BUILDMASTER_PATH = Path(\"/mount/storage/Academic_Workspace/NNPDF/src/nnpdf/buildmaster\")\n",
"\n",
"from validphys.core import CommonDataSpec\n",
"from reportengine.compat import yaml"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "571e330d",
"metadata": {},
"outputs": [],
"source": [
"# This cell is (more or less) what the loader will do when asked for a dataset_input\n",
"\n",
"# Write here the dataset_input you want to play with\n",
"dataset_input = {\n",
" \"dataset\": \"NMCPD\",\n",
" \"variant\": \"shifted\"\n",
"}\n",
"\n",
"# Loader\n",
"setname = dataset_input[\"dataset\"]\n",
"variant = dataset_input[\"variant\"]\n",
"\n",
"setdir = BUILDMASTER_PATH / setname\n",
"metadatafile = setdir / \"metadata.yaml\"\n",
"if not metadatafile.exists():\n",
" raise FileNotFoundError(f\"Metadata not found for {setname}\")\n",
"metadata = yaml.safe_load(metadatafile.open(\"r\", encoding=\"utf-8\"))\n",
" \n",
"# Ask the metadata for the data to load\n",
"datafile = setdir / metadata[\"data_central\"]\n",
"if not datafile.exists():\n",
" raise DataNotFoundError(f\"Datafile '{datafile}' not found\")\n",
"\n",
"cd_spec = CommonDataSpec(datafile, name=setname, metadata=metadata, variant=variant)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "7c5449b4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"CommonDataSpec(datafile=PosixPath('/mount/storage/Academic_Workspace/NNPDF/src/nnpdf/buildmaster/NMCPD/data.json'), name=PosixPath('/mount/storage/Academic_Workspace/NNPDF/src/nnpdf/buildmaster/NMCPD/uncertainties_dw.json'))"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Now you can toy around with the common data spec:\n",
"cd_spec"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "ea6d7631",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.0015, 0.0015, 0.0015, 0.0015, 0.0015, 0.003 , 0.003 , 0.003 ,\n",
" 0.003 , 0.003 , 0.003 , 0.003 , 0.005 , 0.005 , 0.005 , 0.005 ,\n",
" 0.005 , 0.005 , 0.005 , 0.005 , 0.005 , 0.008 , 0.008 , 0.008 ,\n",
" 0.008 , 0.008 , 0.008 , 0.008 , 0.008 , 0.008 , 0.008 , 0.008 ,\n",
" 0.008 , 0.0125, 0.0125, 0.0125, 0.0125, 0.0125, 0.0125, 0.0125,\n",
" 0.0125, 0.0125, 0.0125, 0.0125, 0.0125, 0.0125, 0.0125, 0.0175,\n",
" 0.0175, 0.0175, 0.0175, 0.0175, 0.0175, 0.0175, 0.0175, 0.0175,\n",
" 0.0175, 0.0175, 0.0175, 0.0175, 0.0175, 0.025 , 0.025 , 0.025 ,\n",
" 0.025 , 0.025 , 0.025 , 0.025 , 0.025 , 0.025 , 0.025 , 0.025 ,\n",
" 0.025 , 0.025 , 0.025 , 0.025 , 0.035 , 0.035 , 0.035 , 0.035 ,\n",
" 0.035 , 0.035 , 0.035 , 0.035 , 0.035 , 0.035 , 0.035 , 0.035 ,\n",
" 0.035 , 0.035 , 0.035 , 0.035 , 0.05 , 0.05 , 0.05 , 0.05 ,\n",
" 0.05 , 0.05 , 0.05 , 0.05 , 0.05 , 0.05 , 0.05 , 0.05 ,\n",
" 0.05 , 0.05 , 0.05 , 0.05 , 0.07 , 0.07 , 0.07 , 0.07 ,\n",
" 0.07 , 0.07 , 0.07 , 0.07 , 0.07 , 0.07 , 0.07 , 0.07 ,\n",
" 0.07 , 0.07 , 0.07 , 0.07 , 0.09 , 0.09 , 0.09 , 0.09 ,\n",
" 0.09 , 0.09 , 0.09 , 0.09 , 0.09 , 0.09 , 0.09 , 0.09 ,\n",
" 0.09 , 0.09 , 0.09 , 0.09 , 0.11 , 0.11 , 0.11 , 0.11 ,\n",
" 0.11 , 0.11 , 0.11 , 0.11 , 0.11 , 0.11 , 0.11 , 0.11 ,\n",
" 0.11 , 0.11 , 0.11 , 0.11 , 0.14 , 0.14 , 0.14 , 0.14 ,\n",
" 0.14 , 0.14 , 0.14 , 0.14 , 0.14 , 0.14 , 0.14 , 0.14 ,\n",
" 0.14 , 0.14 , 0.14 , 0.18 , 0.18 , 0.18 , 0.18 , 0.18 ,\n",
" 0.18 , 0.18 , 0.18 , 0.18 , 0.18 , 0.18 , 0.18 , 0.18 ,\n",
" 0.18 , 0.18 , 0.225 , 0.225 , 0.225 , 0.225 , 0.225 , 0.225 ,\n",
" 0.225 , 0.225 , 0.225 , 0.225 , 0.225 , 0.225 , 0.225 , 0.225 ,\n",
" 0.275 , 0.275 , 0.275 , 0.275 , 0.275 , 0.275 , 0.275 , 0.275 ,\n",
" 0.275 , 0.275 , 0.275 , 0.275 , 0.275 , 0.275 , 0.35 , 0.35 ,\n",
" 0.35 , 0.35 , 0.35 , 0.35 , 0.35 , 0.35 , 0.35 , 0.35 ,\n",
" 0.35 , 0.35 , 0.35 , 0.45 , 0.45 , 0.45 , 0.45 , 0.45 ,\n",
" 0.45 , 0.45 , 0.45 , 0.45 , 0.45 , 0.45 , 0.45 , 0.55 ,\n",
" 0.55 , 0.55 , 0.55 , 0.55 , 0.55 , 0.55 , 0.55 , 0.55 ,\n",
" 0.55 , 0.55 , 0.675 , 0.675 , 0.675 , 0.675 , 0.675 , 0.675 ,\n",
" 0.675 , 0.675 , 0.675 , 0.675 ])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Let's look at the kinematics:\n",
"kk = cd_spec.kinematics\n",
"kk.get_kin_cv(\"x\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "30fa242c",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "nnvortex",
"language": "python",
"name": "nnvortex"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
10 changes: 8 additions & 2 deletions validphys2/src/validphys/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def produce_fitpdfandbasis(self, fitpdf, basisfromfit):
def parse_dataset_input(self, dataset: Mapping):
"""The mapping that corresponds to the dataset specifications in the
fit files"""
known_keys = {"dataset", "sys", "cfac", "frac", "weight", "custom_group"}
known_keys = {"dataset", "sys", "cfac", "frac", "weight", "custom_group", "variant"}
try:
name = dataset["dataset"]
if not isinstance(name, str):
Expand All @@ -418,6 +418,9 @@ def parse_dataset_input(self, dataset: Mapping):
sysnum = dataset.get("sys")
cfac = dataset.get("cfac", tuple())
frac = dataset.get("frac", 1)
variant = dataset.get("variant")
if variant is not None and sysnum is not None:
raise ConfigError("variant (new) and sysnum (legacy) cannot be selected at the same time")
if not isinstance(frac, numbers.Real):
raise ConfigError(f"'frac' must be a number, not '{frac}'")
if frac < 0 or frac > 1:
Expand All @@ -441,7 +444,8 @@ def parse_dataset_input(self, dataset: Mapping):
cfac=cfac,
frac=frac,
weight=weight,
custom_group=custom_group
custom_group=custom_group,
variant=variant
)

def parse_use_fitcommondata(self, do_use: bool):
Expand All @@ -454,12 +458,14 @@ def produce_commondata(self, *, dataset_input, use_fitcommondata=False, fit=None

name = dataset_input.name
sysnum = dataset_input.sys
variant = dataset_input.variant
try:
return self.loader.check_commondata(
setname=name,
sysnum=sysnum,
use_fitcommondata=use_fitcommondata,
fit=fit,
variant=variant,
)
except DataNotFoundError as e:
raise ConfigError(str(e), name, self.loader.available_datasets) from e
Expand Down
Loading

0 comments on commit cf61a30

Please sign in to comment.