Skip to content
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

Proposal to use pre-commit for continuous integration #78

Merged
merged 9 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/workflows/code_style.yml

This file was deleted.

41 changes: 41 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
args: [--safe, --line-length=100]

- repo: https://github.com/pycqa/docformatter
rev: v1.7.5
hooks:
- id: docformatter

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.0
hooks:
- id: mypy
additional_dependencies: [types-PyYAML, types-tqdm]

- repo: https://github.com/pycqa/doc8
rev: v1.1.1
hooks:
- id: doc8
files: ^docs/.*\.(rst|md)$

- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8

ci:
autoupdate_schedule: weekly
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ A tool to perform toyMC-based inference constructions
[![PyPI version shields.io](https://img.shields.io/pypi/v/alea-inference.svg)](https://pypi.python.org/pypi/alea-inference/)
[![Readthedocs Badge](https://readthedocs.org/projects/alea/badge/?version=latest)](https://alea.readthedocs.io/en/latest/?badge=latest)
[![CodeFactor](https://www.codefactor.io/repository/github/xenonnt/alea/badge)](https://www.codefactor.io/repository/github/xenonnt/alea)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/XENONnT/alea/main.svg)](https://results.pre-commit.ci/latest/github/XENONnT/alea/main)

`alea` is a public package inherited the spirits of previously private XENON likelihood definition and inference construction code `binference` that based on the blueice repo https://github.com/JelleAalbers/blueice.
`alea` is a public package inherited the spirits of previously private XENON likelihood definition and inference construction code `binference` that based on the blueice repo https://github.com/JelleAalbers/blueice.

Binference was developed for XENON1T WIMP searches by Knut Dundas Morå, and for the first XENONnT results by Robert Hammann, Knut Dundas Morå and Tim Wolf.
2 changes: 1 addition & 1 deletion alea/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.1.0'
__version__ = "0.1.0"

from .model import *

Expand Down
30 changes: 15 additions & 15 deletions alea/examples/gaussian_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Union

import numpy as np
from scipy import stats
Expand All @@ -7,10 +7,9 @@


class GaussianModel(StatisticalModel):
"""
A model of a gaussian measurement, where the model has parameters mu and sigma.
For illustration, we show how required nominal parameters can be added
to the init sigma is fixed in this example.
"""A model of a gaussian measurement, where the model has parameters mu and sigma. For
illustration, we show how required nominal parameters can be added to the init sigma is fixed in
this example.

Args:
parameter_definition (dict or list, optional (default=None)):
Expand All @@ -19,34 +18,34 @@ class GaussianModel(StatisticalModel):
Caution:
You must define the nominal values of the parameters (mu, sigma)
in the parameters definition.

"""

def __init__(
self,
parameter_definition: Optional[Dict or List] = None,
**kwargs,
):
self,
parameter_definition: Optional[Union[Dict[str, dict], List[str]]] = None,
**kwargs,
):
"""Initialise a gaussian model."""
if parameter_definition is None:
parameter_definition = ["mu", "sigma"]
super().__init__(parameter_definition=parameter_definition, **kwargs)

def _ll(self, mu=None, sigma=None):
"""
Log-likelihood of the model.
"""Log-likelihood of the model.

Args:
mu (float, optional (default=None)): mean of the gaussian,
if None, the nominal value is used
sigma (float, optional (default=None)): standard deviation of the gaussian,
if None, the nominal value is used

"""
hat_mu = self.data[0]['hat_mu'][0]
hat_mu = self.data[0]["hat_mu"][0]
return stats.norm.logpdf(x=hat_mu, loc=mu, scale=sigma)

def _generate_data(self, mu=None, sigma=None):
"""
Generate data from the model.
"""Generate data from the model.

Args:
mu (float, optional (default=None)): mean of the gaussian,
Expand All @@ -56,7 +55,8 @@ def _generate_data(self, mu=None, sigma=None):

Returns:
list: data generated from the model

"""
hat_mu = stats.norm(loc=mu, scale=sigma).rvs()
data = [np.array([(hat_mu,)], dtype=[('hat_mu', float)])]
data = [np.array([(hat_mu,)], dtype=[("hat_mu", float)])]
return data
Loading