Skip to content

Commit 2515743

Browse files
Modifications to Enable OSG Submissions for CES Jobs (#255)
* add handling for template_filenames * add option to set poi as rate multiplier directly * update run_toymc_wrapper accordingly * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 750b48d commit 2515743

3 files changed

Lines changed: 61 additions & 37 deletions

File tree

alea/runner.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def __init__(
7777
self,
7878
statistical_model: str = "alea.examples.gaussian_model.GaussianModel",
7979
poi: str = "mu",
80+
poi_is_rate_multiplier: bool = False,
8081
hypotheses: list = ["free"],
8182
n_mc: int = 1,
8283
common_hypothesis: Optional[dict] = None,
@@ -99,6 +100,7 @@ def __init__(
99100
):
100101
"""Initialize statistical model, parameters list, and generate values list."""
101102
self.poi = poi
103+
self.poi_is_rate_multiplier = poi_is_rate_multiplier
102104

103105
statistical_model_class = StatisticalModel.get_model_from_name(statistical_model)
104106

@@ -180,7 +182,9 @@ def pre_process_poi(self, value, attribute_name):
180182
)
181183
# update poi according to poi_expectation
182184
if "poi_expectation" in value:
183-
value = self.update_poi(self.model, self.poi, value, self.nominal_values)
185+
value = self.update_poi(
186+
self.model, self.poi, value, self.nominal_values, self.poi_is_rate_multiplier
187+
)
184188
return value
185189

186190
@property
@@ -237,7 +241,11 @@ def runner_arguments():
237241

238242
@staticmethod
239243
def update_poi(
240-
model, poi: str, generate_values: Dict[str, float], nominal_values: Dict[str, float] = {}
244+
model,
245+
poi: str,
246+
generate_values: Dict[str, float],
247+
nominal_values: Dict[str, float] = {},
248+
poi_is_rate_multiplier: bool = False,
241249
):
242250
"""Update the poi according to poi_expectation. First, it will check if poi_expectation is
243251
provided, if not so, it will do nothing. Second, it will check if poi is provided, if so, it
@@ -250,6 +258,9 @@ def update_poi(
250258
generate_values (dict): generate values of toydata,
251259
it can contain "poi_expectation"
252260
nominal_values (dict): nominal values of parameters
261+
poi_is_rate_multiplier (bool): whether the poi is a rate multiplier, default is False,
262+
False: the input unit is number of events.
263+
True: the input unit is rate multiplier.
253264
254265
Caution:
255266
The expectation is evaluated under nominal_values in each batch.
@@ -267,18 +278,21 @@ def update_poi(
267278
"if poi_expectation is provided, because you want to update "
268279
"the generate_values according to the expectations."
269280
)
270-
generate_values_copy = deepcopy(generate_values)
271-
generate_values_copy.pop("poi_expectation")
272-
expectation_values = model.get_expectation_values(
273-
**{**generate_values_copy, **nominal_values}
274-
)
275-
component = poi.replace("_rate_multiplier", "")
276-
nominal_expectation = expectation_values[component]
277-
poi_expectation = generate_values["poi_expectation"]
278-
ratio = poi_expectation / nominal_expectation
279-
# update poi to the correct value
280-
generate_values.pop("poi_expectation")
281-
generate_values[poi] = ratio
281+
poi_expectation = generate_values.pop("poi_expectation")
282+
283+
if poi_is_rate_multiplier:
284+
# Direct assignment: poi_expectation is already the rate_multiplier value
285+
generate_values[poi] = poi_expectation
286+
else:
287+
# Original logic: poi_expectation is number of events, need to normalize
288+
generate_values_copy = deepcopy(generate_values)
289+
expectation_values = model.get_expectation_values(
290+
**{**generate_values_copy, **nominal_values}
291+
)
292+
component = poi.replace("_rate_multiplier", "")
293+
nominal_expectation = expectation_values[component]
294+
ratio = poi_expectation / nominal_expectation
295+
generate_values[poi] = ratio
282296
return generate_values
283297

284298
def _get_parameter_list(self):

alea/submitters/htcondor.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,15 @@ def _modify_yaml(self):
179179
def update_template_filenames(node):
180180
if isinstance(node, dict):
181181
for key, value in node.items():
182-
if key in ["template_filename", "spectrum_name"]:
183-
filename = os.path.basename(value)
184-
node[key] = filename
182+
if key in [
183+
"template_filename",
184+
"template_filenames",
185+
"spectrum_name",
186+
]: # specific keys
187+
if isinstance(value, list): # list case
188+
node[key] = [os.path.basename(v) for v in value]
189+
else: # single file case
190+
node[key] = os.path.basename(value)
185191
else:
186192
update_template_filenames(value)
187193
elif isinstance(node, list):

alea/submitters/run_toymc_wrapper.sh

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,34 @@
33
set -e
44

55
# Check if number of arguments passed is correct
6-
if [ $# -ne 21 ]; then
6+
if [ $# -ne 22 ]; then
77
echo "Error: You need to provide required number of arguments."
88
exit 1
99
fi
1010

1111
# Extract the arguments
1212
statistical_model=$1
1313
poi=$2
14-
hypotheses=$3
15-
n_mc=$4
16-
common_hypothesis=$5
17-
generate_values=$6
18-
nominal_values=$7
19-
statistical_model_config=$8
20-
parameter_definition=$9
21-
statistical_model_args=${10}
22-
likelihood_config=${11}
23-
compute_confidence_interval=${12}
24-
confidence_level=${13}
25-
confidence_interval_kind=${14}
26-
fit_strategy=${15}
27-
toydata_mode=${16}
28-
toydata_filename=${17}
29-
only_toydata=${18}
30-
output_filename=${19}
31-
seed=${20}
32-
metadata=${21}
14+
poi_is_rate_multiplier=$3
15+
hypotheses=$4
16+
n_mc=$5
17+
common_hypothesis=$6
18+
generate_values=$7
19+
nominal_values=$8
20+
statistical_model_config=$9
21+
parameter_definition=${10}
22+
statistical_model_args=${11}
23+
likelihood_config=${12}
24+
compute_confidence_interval=${13}
25+
confidence_level=${14}
26+
confidence_interval_kind=${15}
27+
fit_strategy=${16}
28+
toydata_mode=${17}
29+
toydata_filename=${18}
30+
only_toydata=${19}
31+
output_filename=${20}
32+
seed=${21}
33+
metadata=${22}
3334
echo "statistical_model: $statistical_model"
3435
echo "poi: $poi"
3536
echo "hypotheses: $hypotheses"
@@ -71,6 +72,7 @@ fi
7172
# Escaped strings
7273
STATISTICAL_MODEL=$(echo "$statistical_model" | sed "s/'/\"/g")
7374
POI=$(echo "$poi" | sed "s/'/\"/g")
75+
POI_IS_RATE_MULTIPLIER=$(echo "$poi_is_rate_multiplier" | sed "s/'/\"/g")
7476
HYPOTHESES=$(echo "$hypotheses" | sed "s/'/\"/g")
7577
N_MC=$(echo "$n_mc" | sed "s/'/\"/g")
7678
COMMON_HYPOTHESIS=$(echo "$common_hypothesis" | sed "s/'/\"/g")
@@ -116,6 +118,7 @@ ls -lh templates/
116118
echo "Running command: python alea_run_toymc.py \\
117119
--statistical_model $STATISTICAL_MODEL \\
118120
--poi $POI \\
121+
--poi_is_rate_multiplier $POI_IS_RATE_MULTIPLIER \\
119122
--hypotheses $HYPOTHESES \\
120123
--n_mc $N_MC \\
121124
--common_hypothesis $COMMON_HYPOTHESIS \\
@@ -140,6 +143,7 @@ echo "Running command: python alea_run_toymc.py \\
140143
time python alea_run_toymc.py \
141144
--statistical_model $STATISTICAL_MODEL \
142145
--poi $POI \
146+
--poi_is_rate_multiplier $POI_IS_RATE_MULTIPLIER \
143147
--hypotheses $HYPOTHESES \
144148
--n_mc $N_MC \
145149
--common_hypothesis $COMMON_HYPOTHESIS \

0 commit comments

Comments
 (0)