Skip to content

Commit

Permalink
Merge branch 'master' into feat/schemaContextLib
Browse files Browse the repository at this point in the history
  • Loading branch information
kratsg authored Mar 23, 2022
2 parents f42ae42 + 6d03b9e commit fdc01fc
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pyhf/writexml.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ def build_modifier(spec, modifierspec, channelname, samplename, sampledata):
high = 10
for p in spec['measurements'][0]['config']['parameters']:
if p['name'] == modifierspec['name']:
val = p['inits'][0]
low, high = p['bounds'][0]
val = p.get('inits', [val])[0]
low, high = p.get('bounds', [[low, high]])[0]
attrs['Val'] = str(val)
attrs['Low'] = str(low)
attrs['High'] = str(high)
Expand Down
27 changes: 27 additions & 0 deletions tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,30 @@ def test_integer_data(datadir, mocker):

channel = pyhf.writexml.build_channel(spec, channel_spec, {})
assert channel


@pytest.mark.parametrize(
"fname,val,low,high",
[
('workspace_no_parameter_inits.json', '1', '-5', '5'),
('workspace_no_parameter_bounds.json', '5', '0', '10'),
],
ids=['no_inits', 'no_bounds'],
)
def test_issue1814(datadir, mocker, fname, val, low, high):
with open(datadir / fname) as spec_file:
spec = json.load(spec_file)

modifierspec = {'data': None, 'name': 'mu_sig', 'type': 'normfactor'}
channelname = None
samplename = None
sampledata = None

modifier = pyhf.writexml.build_modifier(
spec, modifierspec, channelname, samplename, sampledata
)
assert modifier is not None
assert sorted(modifier.keys()) == ['High', 'Low', 'Name', 'Val']
assert modifier.get('Val') == val
assert modifier.get('Low') == low
assert modifier.get('High') == high
37 changes: 37 additions & 0 deletions tests/test_export/workspace_no_parameter_bounds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"channels": [
{
"name": "ch",
"samples": [
{
"data": [1000.0],
"modifiers": [
{"data": null, "name": "mu_sig", "type": "normfactor"},
{
"data": {"hi": 1.5, "lo": 0.5},
"name": "unc",
"type": "normsys"
}
],
"name": "signal"
}
]
}
],
"measurements": [
{
"config": {
"parameters": [
{
"name": "mu_sig",
"inits": [5]
}
],
"poi": "mu_sig"
},
"name": "meas"
}
],
"observations": [{"data": [1000], "name": "ch"}],
"version": "1.0.0"
}
37 changes: 37 additions & 0 deletions tests/test_export/workspace_no_parameter_inits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"channels": [
{
"name": "ch",
"samples": [
{
"data": [1000.0],
"modifiers": [
{"data": null, "name": "mu_sig", "type": "normfactor"},
{
"data": {"hi": 1.5, "lo": 0.5},
"name": "unc",
"type": "normsys"
}
],
"name": "signal"
}
]
}
],
"measurements": [
{
"config": {
"parameters": [
{
"name": "mu_sig",
"bounds": [[-5, 5]]
}
],
"poi": "mu_sig"
},
"name": "meas"
}
],
"observations": [{"data": [1000], "name": "ch"}],
"version": "1.0.0"
}

0 comments on commit fdc01fc

Please sign in to comment.