scikit-hep / pyhf

pure-Python HistFactory implementation with tensors and autodiff
https://pyhf.readthedocs.io/
Apache License 2.0
274 stars 81 forks source link

Forced measurement object schema validation through `ws.model()` #2457

Open alexander-held opened 3 months ago

alexander-held commented 3 months ago

I am unsure if this is a bug / feature / something else: as far as I can see, a ws.model(validate=False) call will trigger get_measurement() https://github.com/scikit-hep/pyhf/blob/adddb0797c564a0158a8e2e69a58ee1f98604bf7/src/pyhf/workspace.py#L428-L431 and subsequently that one will feature a forced schema validation: https://github.com/scikit-hep/pyhf/blob/adddb0797c564a0158a8e2e69a58ee1f98604bf7/src/pyhf/workspace.py#L394

I noticed this while trying out pyhf on https://marimo.app/ with something like

import micropip
await micropip.install("pyhf")

import pyhf

spec = {
    "channels": [
        {
            "name": "Signal_region",
            "samples": [
                {
                    "data": [140.0],
                    "modifiers": [
                        {
                            "data": {
                                "hi": 1.08,
                                "lo": 0.92
                            },
                            "name": "luminosity",
                            "type": "normsys"
                        }
                    ],
                    "name": "Dummy"
                }
            ]
        }
    ],
    "measurements": [
        {
            "config": {"parameters": [], "poi": ""},
            "name": "Luminosity uncertainty example"
        }
    ],
    "observations": [
        {
            "data": [140.0],
            "name": "Signal_region"
        }
    ],
    "version": "1.0.0"
}

ws = pyhf.Workspace(spec, validate=False)
model = ws.model(validate=False)

which occasionally gives me jsonschema.exceptions.RefResolutionError (may be a glitch with the site and not necessarily a pyhf issue) and I expected I would be able to skip all validation with validate=False.

matthewfeickert commented 3 months ago

Thanks @alexander-held. I think from a user perspective this would qualify as a bug as you're explicitly indicated that you don't want validation.