Skip to content

Commit

Permalink
loop over point_prescriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyStegeman committed Oct 31, 2024
1 parent ec4c42f commit 55902b7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 44 deletions.
2 changes: 1 addition & 1 deletion n3fit/runcards/examples/Fit_with_theory_covmat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ datacuts:
theory:
theoryid: 708 # database id
theorycovmatconfig:
point_prescription: "9 point"
point_prescriptions: ["9 point", "3 point"]
# theoryids:
# from_: scale_variation_theories
pdf: NNPDF31_nlo_as_0118
Expand Down
90 changes: 49 additions & 41 deletions validphys2/src/validphys/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,16 @@ def produce_replicas(self, nreplica: int):
"""Produce a replicas array"""
return NSList(range(1, nreplica + 1), nskey="replica")

def parse_point_prescriptions(self, point_prescriptions):
return NSList(point_prescriptions, nskey="point_prescription")

def produce_inclusive_use_scalevar_uncertainties(
self, use_scalevar_uncertainties: bool = False, point_prescription: (str, None) = None
self, use_scalevar_uncertainties: bool = False, point_prescriptions: (str, None) = None
):
"""Whether to use a scale variation uncertainty theory covmat.
Checks whether a point prescription is included in the runcard and if so
assumes scale uncertainties are to be used."""
if (not use_scalevar_uncertainties) and (point_prescription is not None):
if (not use_scalevar_uncertainties) and (point_prescriptions is not None):
use_scalevar_uncertainties = True
return use_scalevar_uncertainties

Expand Down Expand Up @@ -1142,9 +1145,9 @@ def produce_nnfit_theory_covmat(
f = total_theory_covmat_fitting
else:
# Only scalevar uncertainties
from validphys.theorycovariance.construction import theory_covmat_custom_fitting
from validphys.theorycovariance.construction import theory_covmats_fitting

f = theory_covmat_custom_fitting
f = theory_covmats_fitting
elif use_user_uncertainties:
# Only user uncertainties
from validphys.theorycovariance.construction import user_covmat_fitting
Expand Down Expand Up @@ -1628,12 +1631,11 @@ def produce_group_dataset_inputs_by_experiment(self, data_input):
def produce_group_dataset_inputs_by_process(self, data_input):
return self.produce_group_dataset_inputs_by_metadata(data_input, "nnpdf31_process")

def produce_theoryids(self, theoryid, point_prescription):
def produce_point_prescriptions_theoryids(self, theoryid, point_prescriptions):
"""Produces a list of theoryids given a theoryid at central scales and a point
prescription. The options for the latter are '3 point', '5 point', '5bar point', '7 point'
and '9 point'. Note that these are defined in arXiv:1906.10698. This hard codes the
theories needed for each prescription to avoid user error."""
pp = point_prescription
th = theoryid.id

lsv = yaml.safe_load(read_text(validphys.scalevariations, "scalevariationtheoryids.yaml"))
Expand All @@ -1654,44 +1656,50 @@ def produce_theoryids(self, theoryid, point_prescription):
read_text(validphys.scalevariations, "pointprescriptions.yaml")
)

try:
scales = pp_scales_dict[pp]
except KeyError:
valid_pps = ", ".join(pp_scales_dict.keys())
raise ConfigError(
"Scale variations are not currently defined for this point prescription. This "
+ "configuration only works when 'point_prescription' is equal to one of the "
+ f"following: {valid_pps}. Please use one of these instead if you wish to "
+ "include theory uncertainties here."
)
pp_thids = {}
for pp in point_prescriptions:
try:
scales = pp_scales_dict[pp]
except KeyError:
valid_pps = ", ".join(pp_scales_dict.keys())
raise ConfigError(
"Scale variations are not currently defined for this point prescription. This "
+ "configuration only works when 'point_prescription' is equal to one of the "
+ f"following: {valid_pps}. Please use one of these instead if you wish to "
+ "include theory uncertainties here."
)

# Get dictionary containing theoryid and variations for central theory from runcard
for scalevarsfor_dict in scalevarsfor_list:
if scalevarsfor_dict["theoryid"] == int(th):
theoryid_variations = scalevarsfor_dict
# Get dictionary containing theoryid and variations for central theory from runcard
for scalevarsfor_dict in scalevarsfor_list:
if scalevarsfor_dict["theoryid"] == int(th):
theoryid_variations = scalevarsfor_dict

# Find theoryids for given point prescription for given central theoryid
try:
thids = [theoryid_variations["variations"][scale] for scale in scales]
except KeyError:
available_scales = list(theoryid_variations["variations"])
missing_scales = []
for scale in scales:
if scale not in available_scales:
missing_scales.append(scale)
missing_scales_string = ", ".join(missing_scales)
raise ConfigError(
"For this central theoryid, the requested point prescription is not currently "
+ "available. To use this point prescription for this central theoryid, theoryids "
+ "that correspond to the following scale choices must be created and added to "
+ "validphys2/src/validphys/scalevariations/scalevariationtheoryids.yaml: "
+ f"(k_F, k_R) = {missing_scales_string}."
)
# Find theoryids for given point prescription for given central theoryid
try:
thids = [theoryid_variations["variations"][scale] for scale in scales]
except KeyError:
available_scales = list(theoryid_variations["variations"])
missing_scales = []
for scale in scales:
if scale not in available_scales:
missing_scales.append(scale)
missing_scales_string = ", ".join(missing_scales)
raise ConfigError(
"For this central theoryid, the requested point prescription is not currently "
+ "available. To use this point prescription for this central theoryid, theoryids "
+ "that correspond to the following scale choices must be created and added to "
+ "validphys2/src/validphys/scalevariations/scalevariationtheoryids.yaml: "
+ f"(k_F, k_R) = {missing_scales_string}."
)

# Check each theory is loaded
theoryids = [self.loader.check_theoryID(thid) for thid in thids]
pp_thids[pp] = NSList(theoryids, nskey="theoryid")

return pp_thids

# Check each theory is loaded
theoryids = [self.loader.check_theoryID(thid) for thid in thids]
# NSList needs to be used for theoryids to be recognised as a namespace
return NSList(theoryids, nskey="theoryid")
def produce_theoryids(self, point_prescriptions_theoryids, point_prescription):
return point_prescriptions_theoryids[point_prescription]

@configparser.explicit_node
def produce_filter_data(self, fakedata: bool = False, theorycovmatconfig=None):
Expand Down
5 changes: 4 additions & 1 deletion validphys2/src/validphys/theorycovariance/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def theory_covmat_dataset(
ProcessInfo = namedtuple("ProcessInfo", ("preds", "namelist", "sizes"))


def combine_by_type(each_dataset_results_central_bytheory):
def combine_by_type(each_dataset_results_central_bytheory, theoryids):
"""Groups the datasets bu process and returns an instance of the ProcessInfo class
Parameters
Expand Down Expand Up @@ -523,6 +523,9 @@ def theory_covmat_custom_fitting(theory_covmat_custom, procs_index_matched):
return df


theory_covmats_fitting = collect(theory_covmat_custom_fitting, ("point_prescriptions",))


def total_theory_covmat_fitting(total_theory_covmat, procs_index_matched):
"""total_theory_covmat but reindexed so the order of the datasets matches
those in the experiment covmat so they are aligned when fitting."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def check_correct_theory_combination_internal(
l in {3, 5, 7, 9, 62, 64, 66, 70, 19, 23},
f"Expecting exactly 3, 5, 7, 9, 62, 64, 66, 23, 19 or 70 theories, but got {l}.",
)
opts = {"bar", "nobar"}
xifs = [theoryid.get_description()["XIF"] for theoryid in theoryids]
xirs = [theoryid.get_description()["XIR"] for theoryid in theoryids]
if l == 3:
Expand Down

0 comments on commit 55902b7

Please sign in to comment.