-
Notifications
You must be signed in to change notification settings - Fork 85
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
A model is invalid according to model.json but valid according to defs.json #1360
Comments
Thanks for the Issue @lhenkelm.
This is the crux of you issue, as this assumption isn't correct. |
@lhenkelm there's a couple of problems at play here. Fundamentally, the issue is that your Of course, this is pretty annoying to do (as I realized when I was fleshing out the JSON schema) and support for ref resolver has still waned a bit even to this day... This is why we provide a (undocumented, sorry!) validation utility that wraps Here's your example that correctly gives the right error for your spec: $ cat issue1360.py
import json
import pyhf
j = """{
"channels": [
{
"name": "test_channel_1",
"samples": [
{
"name": "test_sample",
"data": [
0.5,
3.33,
666.666
],
"modifiers": [
{
"name": "lalala",
"type": "normfactor"
}
]
}
]
},
{
"name": "test_channel_2",
"samples": [
{
"name": "test_sample_2",
"data": [
0,
0,
1
],
"modifiers": []
}
]
}
],
"parameters": [
{
"name": "p1"
},
{
"name": "parameter of minor interest",
"factors": [
0.0072992700729927005
]
},
{
"name": "very curious parameter",
"fixed": true
}
]
}"""
d = json.loads(j)
pyhf.utils.validate(d, 'defs.json')
pyhf.utils.validate(d, 'model.json') which complains with $ python issue1360.py
Traceback (most recent call last):
File "/Users/kratsg/.pyenv/versions/pyhf-dev/lib/python3.8/site-packages/pyhf/utils.py", line 49, in validate
return validator.validate(spec)
File "/Users/kratsg/.pyenv/versions/pyhf-dev/lib/python3.8/site-packages/jsonschema/validators.py", line 353, in validate
raise error
jsonschema.exceptions.ValidationError: {'name': 'lalala', 'type': 'normfactor'} is not valid under any of the given schemas
Failed validating 'anyOf' in schema['properties']['channels']['items']['properties']['samples']['items']['properties']['modifiers']['items']:
{'anyOf': [{'$ref': '#/definitions/modifier/histosys'},
{'$ref': '#/definitions/modifier/lumi'},
{'$ref': '#/definitions/modifier/normfactor'},
{'$ref': '#/definitions/modifier/normsys'},
{'$ref': '#/definitions/modifier/shapefactor'},
{'$ref': '#/definitions/modifier/shapesys'},
{'$ref': '#/definitions/modifier/staterror'}]}
On instance['channels'][0]['samples'][0]['modifiers'][0]:
{'name': 'lalala', 'type': 'normfactor'}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "issue1360.py", line 60, in <module>
pyhf.utils.validate(d, 'model.json')
File "/Users/kratsg/.pyenv/versions/pyhf-dev/lib/python3.8/site-packages/pyhf/utils.py", line 51, in validate
raise InvalidSpecification(err, schema_name)
pyhf.exceptions.InvalidSpecification: {'name': 'lalala', 'type': 'normfactor'} is not valid under any of the given schemas.
Path: channels[0].samples[0].modifiers[0]
Instance: {'name': 'lalala', 'type': 'normfactor'} Schema: model.json and this is because you neglected to put In your case, you will want {
"name": "lalala",
"type": "normfactor",
"data": null
} |
@lhenkelm if you have further questions here we're happy to address them. If not I'll close this Issue at the end of the day if you haven't already. 👍 Thanks for using |
Hi @matthewfeickert, @kratsg, thanks for the quick response! This is less a pyhf question, and more about jsonschema, but what does it mean for defs.json to "not have validation"? |
Yes. That's what it means. Look at the documentation here (https://json-schema.org/understanding-json-schema/structuring.html) for details on re-use. The main reason for this structure is to allow extending, but also make it easy to build smaller pieces.
You can make your own custom schema based on ours and use
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "modifier.json",
"type":"array",
"items":{
"anyOf":[
{
"$ref":"defs.json#/definitions/modifier/histosys"
},
{
"$ref":"defs.json#/definitions/modifier/lumi"
},
{
"$ref":"defs.json#/definitions/modifier/normfactor"
},
{
"$ref":"defs.json#/definitions/modifier/normsys"
},
{
"$ref":"defs.json#/definitions/modifier/shapefactor"
},
{
"$ref":"defs.json#/definitions/modifier/shapesys"
},
{
"$ref":"defs.json#/definitions/modifier/staterror"
}
]
}
} or similar. |
Thanks a lot for the fast and comprehensive answers! I'll go and write some schemas then :) |
Description
Writing tests, I discovered a model configuration that triggered buggy behavior of the model.json schema.
The model.json schema claims the model is invalid, yet the defs.json one accepts it as valid.
Expected Behavior
Either boths schemas should find the model invalid, or neither. So model.json should not raise a validation error (its not a realistic example, but it seems to me to comply with what is in the schemas).
Actual Behavior
The model is valid according to defs.json, but checking the validity using model.json raises:
Steps to Reproduce
package versions (PyHF is 0.5.0 from pip with xmlio and tensorflow, but it is not needed to reproduce the issue):
Example:
Checklist
git fetch
to get the most up to date version ofmaster
The text was updated successfully, but these errors were encountered: