Skip to content

Commit

Permalink
add precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
jackaraz committed Dec 12, 2024
1 parent 807de14 commit d2f0268
Show file tree
Hide file tree
Showing 45 changed files with 395 additions and 299 deletions.
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ body:
value: |
## Before posting a feature request
Search existing [GitHub issues](https://github.com/SpeysideHEP/spey/issues) to make sure the issue does not already exist.
* **Please use [Markdown syntax](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax).**
- type: textarea
id: system
Expand Down Expand Up @@ -63,4 +63,3 @@ body:
options:
- label: I have searched existing GitHub issues to make sure the issue does not already exist.
required: true

6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/question.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ body:
## Before posting a question
Search existing [GitHub issues](https://github.com/SpeysideHEP/spey/issues) to make sure the issue does not already exist.
If your question involves software issues, please include your system settings as shown below;
**System Settings:**
Please copy and paste the output of `spey.about()` function. If you are working on a specific branch please add the name of the branch and last commit ID. The abbreviated commit ID can be found via `git log -n1 --format="%h"` command. To retreive the branch name please use `git rev-parse --abbrev-ref HEAD` command.)
- type: textarea
Expand All @@ -21,7 +21,7 @@ body:
label: Question
description: |
How can we help?
* **Please use [Markdown syntax](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax).**
validations:
required: true
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -44,7 +44,7 @@ jobs:
- name: Compile Docs
run: |
cd docs; make clean; make html; cd ..
- name: Fix permissions if needed
run: |
chmod -c -R +rX "docs/_build/html/" | while read line; do
Expand Down Expand Up @@ -77,4 +77,4 @@ jobs:

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v2
17 changes: 17 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on:
pull_request:
branches: ["main", "releases/**"]
push:
branches: ["main", "releases/**", "testing"]

name: Check if pre-commit checks pass

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.8"
- uses: pre-commit/[email protected]
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files
args: ["--maxkb=1024"]
- id: check-ast
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: forbid-submodules

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]
language_version: python3.8

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
args: ["--line-length=90", "--target-version=py38"]
language_version: python3.8
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ python:
install:
- requirements: docs/requirements.txt
- method: pip
path: .
path: .
2 changes: 1 addition & 1 deletion .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
"relation": "isDocumentedBy"
}
]
}
}
2 changes: 1 addition & 1 deletion CITATIONS.bib
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ @software{spey_zenodo
version = {v0.1.11},
doi = {10.5281/zenodo.14071351},
url = {https://doi.org/10.5281/zenodo.14071351}
}
}
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,3 @@ testpypi:
.PHONY: pypi
pypi:
python3 -m twine upload -r pypi dist/*





2 changes: 1 addition & 1 deletion data/path_finder/example_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2942,4 +2942,4 @@
]
}
]
}
}
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Makefile for Sphinx documentation
# Makefile for Sphinx documentation

SPHINXOPTS = -W --keep-going #-n
SPHINXBUILD = sphinx-build
Expand Down
2 changes: 1 addition & 1 deletion docs/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ span#release {
width: 200px;
margin-right: 50px;
line-height: 22px;
}
}
14 changes: 7 additions & 7 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Top-Level

.. currentmodule:: spey

.. autosummary::
.. autosummary::
:toctree: _generated/

version
Expand Down Expand Up @@ -68,7 +68,7 @@ Hypothesis testing

.. currentmodule:: spey.hypothesis_testing

.. autosummary::
.. autosummary::
:toctree: _generated/

test_statistics.qmu
Expand All @@ -91,7 +91,7 @@ Gradient Tools

.. currentmodule:: spey.math

.. autosummary::
.. autosummary::
:toctree: _generated/

value_and_grad
Expand All @@ -105,7 +105,7 @@ Distributions

.. currentmodule:: spey.backends.distributions

.. autosummary::
.. autosummary::
:toctree: _generated/

Poisson
Expand All @@ -119,7 +119,7 @@ Default PDFs

.. currentmodule:: spey.backends.default_pdf

.. autosummary::
.. autosummary::
:toctree: _generated/

DefaultPDFBase
Expand All @@ -133,7 +133,7 @@ Default PDFs
Simple PDFs
~~~~~~~~~~~

.. autosummary::
.. autosummary::
:toctree: _generated/

simple_pdf.Poisson
Expand All @@ -146,7 +146,7 @@ Exceptions

.. currentmodule:: spey.system.exceptions

.. autosummary::
.. autosummary::
:toctree: _generated/
:nosignatures:

Expand Down
2 changes: 1 addition & 1 deletion docs/bib/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ @article{Araz:2023bwx
reportnumber = {IPPP/23/34},
month = {7},
year = {2023}
}
}
2 changes: 1 addition & 1 deletion docs/bibliography.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Bibliography
============

.. bibliography:: bib/references.bib
.. bibliography:: bib/references.bib
6 changes: 3 additions & 3 deletions docs/citations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ The BibTeX entry for citing ``spey`` including latest zenodo archive:
.. note::

To retrieve the latest BibTeX information one can also use :func:`~spey.cite` function.
This function pulls the publication information from Inspire-HEP and uses the repository
identification to pull the latest Zenodo archive information.
This function pulls the publication information from Inspire-HEP and uses the repository
identification to pull the latest Zenodo archive information.

.. code-block:: bibtex
Expand Down Expand Up @@ -40,4 +40,4 @@ An up-to-date list can be found on `Inspire-HEP <https://inspirehep.net/literatu
.. bibliography:: bib/cited.bib
:all:
:style: unsrtalpha
:list: enumerated
:list: enumerated
40 changes: 20 additions & 20 deletions docs/comb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ Combining Statistical Models
:property=og:image: https://spey.readthedocs.io/en/main/_static/spey-logo.png
:property=og:url: https://spey.readthedocs.io/en/main/comb.html

In this section, we will provide a simple statistical model combination example using
`Path Finder algorithm <https://github.com/J-Yellen/PathFinder>`_
In this section, we will provide a simple statistical model combination example using
`Path Finder algorithm <https://github.com/J-Yellen/PathFinder>`_
(For details, see :cite:`Araz:2022vtr`).

The data, necessary to complete this exercise, has been provided under the ``data/path_finder`` folder of
`spey's GitHub repository <https://github.com/SpeysideHEP/spey>`_. Here, one will find ``example_data.json``
and ``overlap_matrix.csv`` files. Both files are generated using MadAnalysis 5 recast of ATLAS-SUSY-2018-31
:cite:`ATLAS:2019gdh, DVN/IHALED_2020, Araz:2020stn`
and ``overlap_matrix.csv`` files. Both files are generated using MadAnalysis 5 recast of ATLAS-SUSY-2018-31
:cite:`ATLAS:2019gdh, DVN/IHALED_2020, Araz:2020stn`
and CMS-SUS-19-006 :cite:`CMS:2019zmd, Mrowietz:2020ztq` analyses.

* ``example_data.json``: Includes cross section and signal, background, and observed yield information
for this example.
* ``overlap_matrix.csv``: Includes overlap matrix that the PathFinder algorithm needs to find the best combination.

Let us first import all the necessary packages and construct the data (please add the Pathfinder path to
Let us first import all the necessary packages and construct the data (please add the Pathfinder path to
``sys.path`` list if needed)

.. code-block:: python3
Expand All @@ -35,12 +35,12 @@ Let us first import all the necessary packages and construct the data (please ad
>>> with open("example_data.json", "r") as f:
>>> example_data = json.load(f)
>>> models = {}
>>> # loop overall data
>>> for data in example_data["data"]:
>>> pdf_wrapper = spey.get_backend("default_pdf.uncorrelated_background")
>>> stat_model = pdf_wrapper(
... signal_yields=data["signal_yields"],
... background_yields=data["background_yields"],
Expand All @@ -49,23 +49,23 @@ Let us first import all the necessary packages and construct the data (please ad
... analysis=data["region"],
... xsection=example_data["xsec"],
... )
>>> llhr = stat_model.chi2(
... poi_test=1.0, poi_test_denominator=0.0, expected=spey.ExpectationType.apriori
... ) / 2.0
>>> models.update({data["region"]: {"stat_model": stat_model, "llhr": llhr}})
``example_data`` has two main section which are ``"data"`` including all the information about regions
``example_data`` has two main section which are ``"data"`` including all the information about regions
and ``"xsec"`` including cross section value in pb. Using the information provided for each region we construct
an uncorrelated background-based statistical model. ``llhr`` is the log-likelihood ratio of signal+background and
background-only statistical models given as

.. math::
.. math::
{\rm llhr} = -\log\frac{\mathcal{L}(1,\theta_1)}{\mathcal{L}(0,\theta_0)}\ .
Finally, the dictionary called ``models`` is just a container to collect all the models. In the next, let us
Finally, the dictionary called ``models`` is just a container to collect all the models. In the next, let us
construct a Binary acceptance matrix and compute the best possible paths

.. code-block:: python3
Expand All @@ -80,7 +80,7 @@ construct a Binary acceptance matrix and compute the best possible paths
>>> plot_results.plot(bam, whdfs)
In the first three lines, we read the overlap matrix, extracted the corresponding weights (``llhr``), and fed these
into the ``pf.BinaryAcceptance`` function. We use the ``WHDFS`` algorithm to compute the top 5 combinations and plot the
into the ``pf.BinaryAcceptance`` function. We use the ``WHDFS`` algorithm to compute the top 5 combinations and plot the
resulting binary acceptance matrix with the paths.

.. image:: ./figs/bam.png
Expand All @@ -90,11 +90,11 @@ resulting binary acceptance matrix with the paths.

Each column and row corresponds to ``overlap_matrix.columns``, and the coloured lines are the chosen paths
where the best path can be seen via ``whdfs.best.path``. In this case we find ``"atlas_susy_2018_31::SRA_H"``,
``"cms_sus_19_006::SR25_Njet23_Nb2_HT6001200_MHT350600"`` and ``'cms_sus_19_006::AGGSR7_Njet2_Nb2_HT600_MHT600'``
regions as best regions to be combined. For the combination, we will use :obj:`~spey.UnCorrStatisticsCombiner`
``"cms_sus_19_006::SR25_Njet23_Nb2_HT6001200_MHT350600"`` and ``'cms_sus_19_006::AGGSR7_Njet2_Nb2_HT600_MHT600'``
regions as best regions to be combined. For the combination, we will use :obj:`~spey.UnCorrStatisticsCombiner`
and feed the statistical models as input.

.. code-block::
.. code-block::
>>> regions = [
... "atlas_susy_2018_31::SRA_H",
Expand All @@ -105,7 +105,7 @@ and feed the statistical models as input.
>>> combined.exclusion_confidence_level(expected=spey.ExpectationType.aposteriori)[2]
>>> # 0.9858284831278277
.. note::
.. note::

:obj:`~spey.UnCorrStatisticsCombiner` can be used for any backend retrieved via :func:`spey.get_backend`
function, which wraps the likelihood prescription with :obj:`~spey.StatisticalModel`.
Expand All @@ -117,7 +117,7 @@ the stack, which can be found via
.. code-block:: python3
>>> poiUL = np.array([models[reg]["stat_model"].poi_upper_limit(expected=spey.ExpectationType.aposteriori) for reg in models.keys()])
In our case, the minimum value that we found was from ``"atlas_susy_2018_31::SRA_H"`` where the expected exclusion
limit can be computed via
Expand All @@ -127,7 +127,7 @@ limit can be computed via
>>> models["atlas_susy_2018_31::SRA_H"]["stat_model"].exclusion_confidence_level(expected=spey.ExpectationType.aposteriori)[2]
>>> # 0.9445409288935508
Finally, we can compare the likelihood distribution of the two
Finally, we can compare the likelihood distribution of the two

.. code-block:: python3
:linenos:
Expand All @@ -154,7 +154,7 @@ which gives us the following result:
:scale: 20
:alt: Binary Acceptance Matrix

.. attention::
.. attention::

The results can vary between scipy versions and the versions of its compilers due to their effect on
optimisation algorithm.
Loading

0 comments on commit d2f0268

Please sign in to comment.