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

pyhf json2xml requires parameter inits #1814

Closed
1 task done
alexander-held opened this issue Mar 21, 2022 · 1 comment · Fixed by #1819
Closed
1 task done

pyhf json2xml requires parameter inits #1814

alexander-held opened this issue Mar 21, 2022 · 1 comment · Fixed by #1819
Assignees
Labels
bug Something isn't working

Comments

@alexander-held
Copy link
Member

Summary

When converting a workspace via pyhf json2xml, the model config seems to rely on the presence of parameter inits, even though the spec does not strictly require them.

OS / Environment

n/a

Steps to Reproduce

workspace:

{
    "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": [[0, 10]]
                    }
                ],
                "poi": "mu_sig"
            },
            "name": "meas"
        }
    ],
    "observations": [{"data": [1000], "name": "ch"}],
    "version": "1.0.0"
}

convert with pyhf json2xml:

...
  File "[...]/pyhf/src/pyhf/cli/rootio.py", line 88, in json2xml
    writexml.writexml(
  File "[...]/pyhf/src/pyhf/writexml.py", line 292, in writexml
    channel = build_channel(spec, channelspec, spec.get('observations'))
  File "[...]/pyhf/src/pyhf/writexml.py", line 271, in build_channel
    channel.append(build_sample(spec, samplespec, channelspec['name']))
  File "[...]/pyhf/src/pyhf/writexml.py", line 245, in build_sample
    modifier = build_modifier(
  File "[...]/pyhf/src/pyhf/writexml.py", line 181, in build_modifier
    val = p['inits'][0]
KeyError: 'inits'

A fit with pyhf fit works perfectly fine. The addition of "inits": [1.0] in the model config also fixes the crash, as does removing this parameter configuration completely.

File Upload (optional)

No response

Expected Results

I expect the conversion to not rely on the presence of inits. The default of 1.0 may not make sense if some custom bounds are specified, but I think this is on the user to fix. The same issue also appears when just setting a normfactor to constant without specifying the inits.

Actual Results

File "[...]/pyhf/src/pyhf/cli/rootio.py", line 88, in json2xml
    writexml.writexml(
  File "[...]/pyhf/src/pyhf/writexml.py", line 292, in writexml
    channel = build_channel(spec, channelspec, spec.get('observations'))
  File "[...]/pyhf/src/pyhf/writexml.py", line 271, in build_channel
    channel.append(build_sample(spec, samplespec, channelspec['name']))
  File "[...]/pyhf/src/pyhf/writexml.py", line 245, in build_sample
    modifier = build_modifier(
  File "[...]/pyhf/src/pyhf/writexml.py", line 181, in build_modifier
    val = p['inits'][0]
KeyError: 'inits'

pyhf Version

0.6.3

Code of Conduct

  • I agree to follow the Code of Conduct
@alexander-held alexander-held added bug Something isn't working needs-triage Needs a maintainer to categorize and assign labels Mar 21, 2022
@kratsg kratsg self-assigned this Mar 23, 2022
@matthewfeickert matthewfeickert removed the needs-triage Needs a maintainer to categorize and assign label Mar 23, 2022
@matthewfeickert
Copy link
Member

Thanks for raising this @alexander-held. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants