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

fix: Update with_aux to include_auxdata in pyhf v0.6.3+ API #13

Merged
merged 3 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package_dir =
= src
python_requires = >=3.7
install_requires =
pyhf[minuit]==0.5.4 # paramset.suggested_fixed
pyhf[minuit]>=0.6.3
boost_histogram
awkward1

Expand Down
2 changes: 1 addition & 1 deletion src/simplify/fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def fit(
uncertainty = result[:, 1]
labels = model_tools.get_parameter_names(model)
types = model_tools.get_parameter_types(model)
corr_mat = result_obj.minuit.np_matrix(correlation=True, skip_fixed=False)
corr_mat = result_obj.corr
cov_mat = result_obj.hess_inv
best_twice_nll = float(result_obj.fun)

Expand Down
14 changes: 7 additions & 7 deletions src/simplify/model_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def model_and_data(
spec: Union[Dict[str, Any], pyhf.Workspace],
poi_name: Optional[str] = None,
asimov: bool = False,
with_aux: bool = True,
include_auxdata: bool = True,
) -> Tuple[pyhf.pdf.Model, List[float]]:
"""Returns model and data for a pyhf workspace spec in str or workspace format.

Args:
spec (Union[Dict[str, Any], pyhf.Workspace]): a pyhf workspace specification
poi_name (Optional[str], optional): name of the POI. Defaults to None.
asimov (bool, optional): whether to return Asimov data instead. Defaults to False.
with_aux (bool, optional): whether auxiliary data should be returned. Defaults to True.
include_auxdata (bool, optional): whether auxiliary data should be returned. Defaults to True.

Returns:
Tuple[pyhf.pdf.Model, List[float]]:
Expand All @@ -38,9 +38,9 @@ def model_and_data(
poi_name=poi_name,
)
if not asimov:
data = workspace.data(model, with_aux=with_aux)
data = workspace.data(model, include_auxdata=include_auxdata)
else:
data = get_asimov_data(model, with_aux=with_aux)
data = get_asimov_data(model, include_auxdata=include_auxdata)
return model, data


Expand Down Expand Up @@ -117,19 +117,19 @@ def get_prefit_uncertainties(model: pyhf.pdf.Model) -> np.ndarray:
return np.asarray(prefit_unc)


def get_asimov_data(model: pyhf.Model, with_aux: bool = True) -> List[float]:
def get_asimov_data(model: pyhf.Model, include_auxdata: bool = True) -> List[float]:
"""Gets the asimov dataset for a model

Args:
model (pyhf.Model): the model for which to construct the asimov data
with_aux (bool, optional): with or without auxdata. Defaults to True.
include_auxdata (bool, optional): with or without auxdata. Defaults to True.

Returns:
List[float]: asimov dataset
"""

asimov_data = model.expected_data(
get_asimov_parameters(model), include_auxdata=with_aux
get_asimov_parameters(model), include_auxdata=include_auxdata
).tolist()
return asimov_data

Expand Down
2 changes: 1 addition & 1 deletion src/simplify/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def data_MC(
it automatically determines what to use.
"""

model, _ = model_tools.model_and_data(spec, with_aux=False)
model, _ = model_tools.model_and_data(spec, include_auxdata=False)
ylds = yields._get_data_yield_uncertainties(spec, fit_results)

if fit_results is not None:
Expand Down
2 changes: 1 addition & 1 deletion src/simplify/yields.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def _get_data_yield_uncertainties(

"""

model, data_combined = model_tools.model_and_data(spec, with_aux=False)
model, data_combined = model_tools.model_and_data(spec, include_auxdata=False)

if fit_results is not None:
param_values = fit_results.bestfit
Expand Down
2 changes: 1 addition & 1 deletion tests/test_model_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_model_and_data(example_spec):
assert data == [691, 1.0]

# without auxdata
model, data = model_tools.model_and_data(example_spec, with_aux=False)
model, data = model_tools.model_and_data(example_spec, include_auxdata=False)
assert data == [691]


Expand Down