diff --git a/.github/workflows/check+build+deploy.yaml b/.github/workflows/check+build+deploy.yaml new file mode 100644 index 0000000..212507b --- /dev/null +++ b/.github/workflows/check+build+deploy.yaml @@ -0,0 +1,81 @@ +name: Check/Build/Deploy + +on: + release: + types: [published] + push: + branches: ["releases/**"] + workflow_dispatch: + +jobs: + # check: + # name: OS ${{ matrix.os }}, Python ${{ matrix.python-version }} + # runs-on: ${{ matrix.os }} + + # strategy: + # fail-fast: false + # matrix: + # python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + # os: [ubuntu-latest, macos-latest] + + # steps: + # - uses: actions/checkout@v3 + # - name: Set up Python ${{ matrix.python-version }} + # uses: actions/setup-python@v3 + # with: + # python-version: ${{ matrix.python-version }} + # - name: Install dependencies + # run: | + # python -m pip install --upgrade pip + # python -m pip install pytest pytest-cov + # python -m pip install -e . + # - name: Test with pytest + # run: | + # python -c 'import spey;spey.about()' + # pytest --cov=spey tests/*py #--cov-fail-under 99 + + build: + name: Build wheel + runs-on: ubuntu-latest + # needs: check + steps: + - name: Checkout git repository + uses: actions/checkout@v4 + + - name: Build Spey wheel + run: | + python -m pip install --upgrade pip + python -m pip install wheel + python setup.py bdist_wheel + + - name: Upload wheels as artifacts + uses: actions/upload-artifact@v4 + with: + name: wheel + path: ./dist/*.whl + + deploy: + if: ${{ !github.event.release.prerelease && !contains(github.ref, '-rc') && !contains(github.ref, '-beta') && !contains(github.ref, '-alpha') }} + runs-on: ubuntu-latest + needs: build + environment: + name: pypi + url: https://pypi.org/project/spey-pyhf/ + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + pattern: wheel + merge-multiple: true + path: dist + + - name: Debug + run: ls -l dist + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@v1.4.2 + with: + user: ${{ secrets.TWINE_USERNAME }} + password: ${{ secrets.TWINE_PSSWRD }} + verbose: true diff --git a/.zenodo.json b/.zenodo.json index eb282a8..95a41ef 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,8 +1,8 @@ { "description": "pyhf plug-in for spey package", "license": "MIT", - "title": "SpeysideHEP/spey-pyhf: v0.1.10", - "version": "v0.1.10", + "title": "SpeysideHEP/spey-pyhf: v0.2.0", + "version": "v0.2.0", "upload_type": "software", "creators": [ { @@ -29,7 +29,7 @@ }, { "scheme": "url", - "identifier": "https://github.com/SpeysideHEP/spey-pyhf/tree/v0.1.10", + "identifier": "https://github.com/SpeysideHEP/spey-pyhf/tree/v0.2.0", "relation": "isSupplementTo" }, { diff --git a/CITATIONS.bib b/CITATIONS.bib index 76a2460..f4dd539 100644 --- a/CITATIONS.bib +++ b/CITATIONS.bib @@ -1,15 +1,16 @@ -@article{10.21468/SciPostPhys.16.1.032, - author = {Jack Y. Araz}, - doi = {10.21468/SciPostPhys.16.1.032}, - journal = {SciPost Phys.}, - pages = {032}, - publisher = {SciPost}, - title = {{Spey: Smooth inference for reinterpretation studies}}, - url = {https://scipost.org/10.21468/SciPostPhys.16.1.032}, - volume = {16}, - year = {2024}, - bdsk-url-1 = {https://scipost.org/10.21468/SciPostPhys.16.1.032}, - bdsk-url-2 = {https://doi.org/10.21468/SciPostPhys.16.1.032} +@article{Araz:2023bwx, + author = {Araz, Jack Y.}, + title = {{Spey: Smooth inference for reinterpretation studies}}, + eprint = {2307.06996}, + archiveprefix = {arXiv}, + primaryclass = {hep-ph}, + reportnumber = {IPPP/23/34}, + doi = {10.21468/SciPostPhys.16.1.032}, + journal = {SciPost Phys.}, + volume = {16}, + number = {1}, + pages = {032}, + year = {2024} } @software{spey_pyhf_zenodo, diff --git a/LICENSE b/LICENSE index b36d6ff..f5c7992 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Jack Y. Araz +Copyright (c) 2025 Jack Y. Araz Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/docs/conf.py b/docs/conf.py index 4065a1f..e1f140c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -16,7 +16,7 @@ sys.path.insert(0, str(Path("./ext").resolve())) project = "spey-pyhf" -copyright = "2024, Jack Y. Araz" +copyright = "2025, Jack Y. Araz" author = "Jack Y. Araz" release = get_distribution("spey_pyhf").version version = ".".join(release.split(".")[:3]) diff --git a/setup.py b/setup.py index fa07ae4..640b583 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ with open("src/spey_pyhf/_version.py", encoding="UTF-8") as f: version = f.readlines()[-1].split()[-1].strip("\"'") -requirements = ["pyhf==0.7.6", "spey>=0.1.11"] +requirements = ["pyhf==0.7.6", "spey>=0.2.1"] docs = [ "sphinx==6.2.1", @@ -49,7 +49,7 @@ ] }, install_requires=requirements, - python_requires=">=3.8", + python_requires=">=3.8, <3.13", classifiers=[ "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", diff --git a/src/spey_pyhf/_version.py b/src/spey_pyhf/_version.py index b3ed19d..3ea1063 100644 --- a/src/spey_pyhf/_version.py +++ b/src/spey_pyhf/_version.py @@ -1,3 +1,3 @@ """Version of the spey - pyhf plugin""" -__version__ = "0.1.10" +__version__ = "0.2.0-beta" diff --git a/src/spey_pyhf/helper_functions.py b/src/spey_pyhf/helper_functions.py index 42060b1..e7a5080 100644 --- a/src/spey_pyhf/helper_functions.py +++ b/src/spey_pyhf/helper_functions.py @@ -2,6 +2,8 @@ import logging from typing import Dict, Iterator, List, Optional, Tuple, Union +from spey import log_once + __all__ = ["WorkspaceInterpreter"] @@ -114,15 +116,12 @@ def expected_background_yields(self) -> Dict[str, List[float]]: if channel["name"] not in self._signal_dict: undefined_channels.append(channel["name"]) if len(undefined_channels) > 0: - log.warning( + log_once( "Some of the channels are not defined in the patch set, " "these channels will be kept in the statistical model. " - ) - log.warning( - "If these channels are meant to be removed, please indicate them in the patch set." - ) - log.warning( - "Please check the following channel(s): " + ", ".join(undefined_channels) + "If these channels are meant to be removed, please indicate them in the patch set. " + "Please check the following channel(s): " + ", ".join(undefined_channels), + log_type="warning", ) return yields diff --git a/src/spey_pyhf/interface.py b/src/spey_pyhf/interface.py index 3c1f85c..69a1672 100644 --- a/src/spey_pyhf/interface.py +++ b/src/spey_pyhf/interface.py @@ -2,7 +2,7 @@ import copy import warnings -from typing import Callable, Dict, List, Optional, Text, Tuple, Union +from typing import Callable, Dict, List, Optional, Tuple, Union import numpy as np from spey.base import ModelConfig @@ -73,7 +73,7 @@ class PyhfInterface(BackendBase): """Version of the backend""" author: str = "SpeysideHEP" """Author of the backend""" - spey_requires: str = ">=0.1.9,<0.2.0" + spey_requires: str = ">=0.2.0, <0.3.0" """Spey version required for the backend""" doi: List[str] = ["10.5281/zenodo.1169739", "10.21105/joss.02823"] """Citable DOI for the backend""" diff --git a/src/spey_pyhf/manager.py b/src/spey_pyhf/manager.py index b1bc301..8ff0c7c 100644 --- a/src/spey_pyhf/manager.py +++ b/src/spey_pyhf/manager.py @@ -5,6 +5,8 @@ from spey.system.exceptions import MethodNotAvailable +log = logging.getLogger("Spey") + class PyhfManager: """Manager to unify the usage of pyhf through out the package""" @@ -12,7 +14,12 @@ class PyhfManager: pyhf = importlib.import_module("pyhf") def __init__(self): - PyhfManager.pyhf.set_backend("numpy", precision="64b") + if importlib.util.find_spec("jax") is not None: + PyhfManager.pyhf.set_backend("jax", precision="64b") + log.debug("pyhf backend set to Jax") + else: + PyhfManager.pyhf.set_backend("numpy", precision="64b") + log.debug("pyhf backend set to NumPy") PyhfManager.pyhf.pdf.log.setLevel(logging.CRITICAL) PyhfManager.pyhf.workspace.log.setLevel(logging.CRITICAL) @@ -61,6 +68,7 @@ def backend(self, backend: str) -> None: """ if backend not in self.available_backends: raise MethodNotAvailable(f"{backend} backend currently not available.") + log.debug(f"setting pyhf backend to {backend}") PyhfManager.pyhf.set_backend(backend) @property diff --git a/src/spey_pyhf/simplify.py b/src/spey_pyhf/simplify.py index c55848d..ba44d54 100644 --- a/src/spey_pyhf/simplify.py +++ b/src/spey_pyhf/simplify.py @@ -4,7 +4,7 @@ import warnings from contextlib import contextmanager from pathlib import Path -from typing import Callable, List, Literal, Optional, Text, Union +from typing import Callable, List, Literal, Optional, Union import numpy as np import spey @@ -170,7 +170,7 @@ class Simplify(spey.ConverterBase): """Version of the backend""" author: str = "SpeysideHEP" """Author of the backend""" - spey_requires: str = ">=0.1.5,<0.2.0" + spey_requires: str = ">=0.2.0,<0.3.0" """Spey version required for the backend""" def __call__( @@ -340,7 +340,7 @@ def __call__( # if the initial value is NaN continue search continue current_fit_opts["constraints"] += constraints - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True) as warnings_list: _, new_params = fit( **current_fit_opts, initial_parameters=init_params.tolist(), @@ -348,7 +348,10 @@ def __call__( "model_configuration" ].suggested_bounds, ) - warnings_list += w + for warning in warnings_list: + log.debug( + f"{warning.message} (file: {warning.filename}, L:{warning.lineno})" + ) try: current_sample = statistical_model.backend.get_sampler( @@ -366,12 +369,6 @@ def __call__( ) continue - if len(warnings_list) > 0: - log.warning( - f"{len(warnings_list)} warning(s) generated during sampling." - " This might be due to edge cases in nuisance parameter sampling." - ) - samples = np.vstack(samples) covariance_matrix = np.cov(samples, rowvar=0)