Skip to main content

spey-pyhf

arxiv DOI DOI doc

Spey logo

github PyPI - Version Documentation Status GitHub License codecov

About

spey-pyhf is a pyhf plug-in for the spey statistical inference interface. It exposes pyhf's full likelihood-building machinery — including HistFactory-style JSON workspaces and signal patches — through Spey's backend-agnostic API, so any analysis that ships a pyhf likelihood can be consumed by Spey alongside other backends. Once installed, Spey automatically detects the plug-in and registers three backends: pyhf (full statistical model from a background-only workspace plus a signal patch), pyhf.uncorrelated_background (a lightweight uncorrelated-background helper) and pyhf.simplify (workspace simplification).

Installation

The plug-in is published on PyPI and can be installed with:

python -m pip install spey-pyhf

To install directly from the main branch:

python -m pip install --upgrade "git+https://github.com/SpeysideHEP/spey-pyhf"

Note that the main branch may not be the stable version.

Quick example

Given a pyhf background-only workspace and a signal patch, you can build a Spey statistical model and compute the exclusion confidence level in a few lines:

import spey

background_only = {
    "channels": [
        {
            "name": "singlechannel",
            "samples": [
                {
                    "name": "background",
                    "data": [50.0, 52.0],
                    "modifiers": [
                        {"name": "uncorr_bkguncrt", "type": "shapesys", "data": [3.0, 7.0]}
                    ],
                }
            ],
        }
    ],
    "observations": [{"name": "singlechannel", "data": [51.0, 48.0]}],
    "measurements": [{"name": "Measurement", "config": {"poi": "mu", "parameters": []}}],
    "version": "1.0.0",
}

signal_patch = [
    {
        "op": "add",
        "path": "/channels/0/samples/1",
        "value": {
            "name": "signal",
            "data": [12.0, 11.0],
            "modifiers": [{"name": "mu", "type": "normfactor", "data": None}],
        },
    }
]

wrapper = spey.get_backend("pyhf")
model = wrapper(
    analysis="simple_pyhf",
    background_only_model=background_only,
    signal_patch=signal_patch,
)

print(model.exclusion_confidence_level())  # [0.9474850259721279]

Because Spey is fully backend-agnostic, every method of spey.StatisticalModel (likelihood scans, upper limits, combinations, etc.) works the same way on top of pyhf. For the full API and tutorials, see the online documentation.

Metadata

Release files for spey-pyhf 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spey-pyhf 0.2.3
File Size Uploaded Provenance Actions
spey_pyhf-0.2.3.tar.gz 42.4 kB Without provenance Details for spey_pyhf-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spey-pyhf 0.2.3
File Interpreter ABI Platform Actions
spey_pyhf-0.2.3-py3-none-any.whl Python 3 none any Details for spey_pyhf-0.2.3-py3-none-any.whl

Total release size: 78.4 kB

Release files / spey_pyhf-0.2.3.tar.gz

Download URL spey_pyhf-0.2.3.tar.gz
Size 42.4 kB
Tags Source
SHA-256 checksum
How to use checksums
388ddc61e7ba0415701c05edc76615970c3de7b5de893957ee2957e78f6d5e66
BLAKE2b-256 checksum
How to use checksums
c4860e3fac3682c5000e5cdba87d1bb637c17b08e872ea86cc1dbf06d2736add
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / spey_pyhf-0.2.3-py3-none-any.whl

Download URL spey_pyhf-0.2.3-py3-none-any.whl
Size 36.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6bb4bb373c7e375758bb4d25c38162f4c6be957c646743f9fbfed962ac3153c
BLAKE2b-256 checksum
How to use checksums
d78ec942daf5ad55219be97614d64ff21c8e3490ab260484e18190afa54d83ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for spey-pyhf 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page