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

Only initialize runner once in NeymanConstructor #103

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
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
33 changes: 22 additions & 11 deletions alea/submitters/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def submit(
if os.path.splitext(limit_threshold)[-1] != ".json":
raise ValueError("The limit_threshold file should be a json file.")

# initialize the runner
script = next(self.computation_tickets_generator())[0]
runner = self.initialized_runner(script, pop_limit_threshold=True)

# calculate the threshold, iterate over the output files
threshold = cast(Dict[str, Any], {})
for runner_args in self.merged_arguments_generator():
Expand Down Expand Up @@ -187,15 +191,22 @@ def submit(
)

# update poi according to poi_expectation
runner_args["statistical_model_args"].pop("limit_threshold", None)
runner = Runner(**runner_args)
expectation_values = runner.model.get_expectation_values(
**{**nominal_values, **generate_values}
)
# in some rare cases the poi is not a rate multiplier
# then the poi_expectation is not in the nominal_expectation_values
component = self.poi.replace("_rate_multiplier", "")
poi_expectation = expectation_values.get(component, None)
if runner.input_poi_expectation:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just "if poi_expectation" in generate_values?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also be fine. What is the benefit?

poi_expectation = generate_values.get("poi_expectation")
# nominal_values are passed to update_poi to update the poi
# like wimp_mass, livetime, etc.
generate_values = runner.update_poi(
runner.model, self.poi, generate_values, nominal_values
Comment on lines +199 to +200
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this won't work with static parameters. That was the entire point of the previous PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran it quickly and yes, this crashes if you have static parameters (as it should).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recent commit 7b4f38f makes the PR compatible with static parameters.

)
else:
expectation_values = runner.model.get_expectation_values(
**{**nominal_values, **generate_values}
)
# in some rare cases the poi is not a rate multiplier
# then the poi_expectation is not in the expectation_values
# in these cases we only assign None to poi_expectation
component = self.poi.replace("_rate_multiplier", "")
poi_expectation = expectation_values.get(component, None)
poi_value = generate_values.pop(self.poi)

# make sure no poi and poi_expectation in the hashed_keys
Expand All @@ -214,8 +225,8 @@ def submit(
)
hashed_keys = {
"poi": self.poi,
"nominal_values": nominal_values,
"generate_values": generate_values,
"nominal_values": deepcopy(nominal_values),
"generate_values": deepcopy(generate_values),
"confidence_level": confidence_level,
}
threshold_key = deterministic_hash(hashed_keys)
Expand Down