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

chore: [pre-commit.ci] pre-commit autoupdate #2442

Merged
merged 5 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.9"
rev: "v0.3.3"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
rev: 24.3.0
hooks:
- id: black-jupyter
types_or: [python, pyi, jupyter]
Expand All @@ -50,10 +50,10 @@ repos:
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.12.1]
additional_dependencies: [black==24.3.0]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.9.0
# check the oldest and newest supported Pythons
hooks:
- &mypy
Expand Down
8 changes: 5 additions & 3 deletions docs/examples/notebooks/ImpactPlot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@
" model, _, b, e = fitresults()\n",
" widths = pyhf.tensorlib.concatenate(\n",
" [\n",
" model.config.param_set(k).width()\n",
" if model.config.param_set(k).constrained\n",
" else [None] * model.config.param_set(k).n_parameters\n",
" (\n",
" model.config.param_set(k).width()\n",
" if model.config.param_set(k).constrained\n",
" else [None] * model.config.param_set(k).n_parameters\n",
" )\n",
" for k, v in model.config.par_map.items()\n",
" ]\n",
" )\n",
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The pyhf command line interface."""

from pyhf.cli.cli import pyhf as cli
from pyhf.cli.rootio import cli as rootio
from pyhf.cli.spec import cli as spec
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The pyhf Command Line Interface."""

import logging

import click
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/cli/complete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'''Shell completions for pyhf.'''

import click

try:
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/cli/infer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The inference CLI group."""

import logging

import click
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/cli/patchset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The pyhf spec CLI subcommand."""

import logging

import click
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/cli/rootio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""CLI subapps to handle conversion from ROOT."""

import logging

import click
Expand Down
9 changes: 6 additions & 3 deletions src/pyhf/cli/spec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The pyhf spec CLI subcommand."""

import logging

import click
Expand Down Expand Up @@ -149,9 +150,11 @@ def inspect(workspace, output_file, measurement):
('(*) ' if measurement_name == default_measurement['name'] else '')
+ measurement_name,
measurement_poi,
','.join(measurement_parameters)
if measurement_parameters
else '(none)',
(
','.join(measurement_parameters)
if measurement_parameters
else '(none)'
),
)
)

Expand Down
1 change: 1 addition & 0 deletions src/pyhf/contrib/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""CLI for functionality that will get migrated out eventually."""

import logging
import click
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/contrib/viz/brazil.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Brazil Band Plots."""

from collections import namedtuple

import matplotlib.pyplot as plt
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/infer/calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

Using the calculators hypothesis tests can then be performed.
"""

from pyhf.infer.mle import fixed_poi_fit
from pyhf import get_backend
from pyhf.infer import utils
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/infer/intervals/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Interval estimation"""

import pyhf.infer.intervals.upper_limits

__all__ = ["upper_limits.upper_limit"]
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/infer/intervals/upper_limits.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Interval estimation"""

import numpy as np
from scipy.optimize import toms748

Expand Down
1 change: 1 addition & 0 deletions src/pyhf/infer/mle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for Maximum Likelihood Estimation."""

from pyhf import get_backend
from pyhf.exceptions import UnspecifiedPOI

Expand Down
1 change: 1 addition & 0 deletions src/pyhf/interpolators/code0.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Piecewise-linear Interpolation. (Code 0)."""

import logging
import pyhf
from pyhf.tensor.manager import get_backend
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/interpolators/code1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Piecewise-Exponential Interpolation (Code 1)."""

import logging
import math
import pyhf
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/interpolators/code2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Quadratic Interpolation (Code 2)."""

import logging
import pyhf
from pyhf.tensor.manager import get_backend
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/interpolators/code4.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Polynomial Interpolation (Code 4)."""

import logging
import math
import pyhf
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/interpolators/code4p.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Piecewise-Linear + Polynomial Interpolation (Code 4p)."""

import logging
import pyhf
from pyhf.tensor.manager import get_backend
Expand Down
6 changes: 3 additions & 3 deletions src/pyhf/modifiers/shapesys.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ def _reindex_access_field(self, pdfconfig):

sample_mask = self._shapesys_mask[syst_index][singular_sample_index][0]
access_field_for_syst_and_batch[sample_mask] = selection
self._access_field[
syst_index, batch_index
] = access_field_for_syst_and_batch
self._access_field[syst_index, batch_index] = (
access_field_for_syst_and_batch
)

def _precompute(self):
tensorlib, _ = get_backend()
Expand Down
15 changes: 9 additions & 6 deletions src/pyhf/modifiers/staterror.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@
relerrs = default_backend.sum(
[
[
(modifier_data['data']['uncrt'][binnr] / nomsall[binnr]) ** 2
if nomsall[binnr] > 0
else 0.0
(
(modifier_data['data']['uncrt'][binnr] / nomsall[binnr])
** 2
if nomsall[binnr] > 0
else 0.0
)
for binnr in range(len(modifier_data['data']['nom_data']))
]
for modifier_data in self.builder_data[modname].values()
Expand Down Expand Up @@ -123,7 +126,7 @@

# list of bools, consistent with other modifiers (no numpy.bool_)
fixed = default_backend.tolist(sigmas == 0)
# FIXME: sigmas that are zero will be fixed to 1.0 arbitrarily to ensure

Check notice on line 129 in src/pyhf/modifiers/staterror.py

View check run for this annotation

codefactor.io / CodeFactor

src/pyhf/modifiers/staterror.py#L129

unresolved comment '# FIXME: sigmas that are zero will be fixed to 1.0 arbitrarily to ensure' (C100)
# non-Nan constraint term, but in a future PR need to remove constraints
# for these
sigmas[fixed] = 1.0
Expand Down Expand Up @@ -184,9 +187,9 @@

sample_mask = self._staterror_mask[syst_index][singular_sample_index][0]
access_field_for_syst_and_batch[sample_mask] = selection
self._access_field[
syst_index, batch_index
] = access_field_for_syst_and_batch
self._access_field[syst_index, batch_index] = (
access_field_for_syst_and_batch
)

def _precompute(self):
if not self.param_viewer.index_selection:
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/optimize/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common Backend Shim to prepare minimization for optimizer."""

from pyhf.tensor.manager import get_backend
from pyhf.tensor.common import _TensorViewer

Expand Down
1 change: 1 addition & 0 deletions src/pyhf/optimize/mixins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helper Classes for use of automatic differentiation."""

import logging

import numpy as np
Expand Down Expand Up @@ -84,7 +85,7 @@
# extract number of fixed parameters
num_fixed_pars = len(fitted_pars) - len(fitresult.x)

# FIXME: Set uncertainties for fixed parameters to 0 manually

Check notice on line 88 in src/pyhf/optimize/mixins.py

View check run for this annotation

codefactor.io / CodeFactor

src/pyhf/optimize/mixins.py#L88

unresolved comment '# FIXME: Set uncertainties for fixed parameters to 0 manually' (C100)
# https://github.com/scikit-hep/iminuit/issues/762
# https://github.com/scikit-hep/pyhf/issues/1918
# https://github.com/scikit-hep/cabinetry/pull/346
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/optimize/opt_minuit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Minuit Optimizer Class."""

from pyhf import exceptions
from pyhf.optimize.mixins import OptimizerMixin
import scipy
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/optimize/opt_scipy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""SciPy Optimizer Class."""

from pyhf import exceptions
from pyhf.optimize.mixins import OptimizerMixin
import scipy
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/optimize/opt_tflow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tensorflow Backend Function Shim."""

from pyhf import get_backend
import tensorflow as tf

Expand Down
8 changes: 5 additions & 3 deletions src/pyhf/parameters/paramview.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ def extract_index_access(baseviewer, subviewer, indices):

# the transpose is here so that modifier code doesn't have to do it
indices_concatenated = tensorlib.astensor(
tensorlib.einsum('ij->ji', stitched)
if len(tensorlib.shape(stitched)) > 1
else stitched,
(
tensorlib.einsum('ij->ji', stitched)
if len(tensorlib.shape(stitched)) > 1
else stitched
),
dtype='int',
)
return index_selection, stitched, indices_concatenated
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/patchset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
pyhf patchset provides a user-friendly interface for interacting with patchsets.
"""

import logging
import jsonpatch
from pyhf import exceptions
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/probability.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The probability density function module."""

from pyhf import get_backend

__all__ = ["Independent", "Normal", "Poisson", "Simultaneous"]
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/schema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
See :class:`~pyhf.schema.Schema` for documentation.
"""

import pathlib
import sys
from pyhf.schema.loader import load_schema
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/tensor/numpy_backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""NumPy Tensor Library Module."""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/tensor/pytorch_backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""PyTorch Tensor Library Module."""

import torch
import torch.autograd
from torch.distributions.utils import broadcast_all
Expand Down
1 change: 1 addition & 0 deletions src/pyhf/tensor/tensorflow_backend.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tensorflow Tensor Library Module."""

import logging
import tensorflow as tf
import tensorflow_probability as tfp
Expand Down
9 changes: 3 additions & 6 deletions src/pyhf/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)


# TODO: Switch to os.PathLike[str] once Python 3.8 support dropped

Check notice on line 38 in src/pyhf/typing.py

View check run for this annotation

codefactor.io / CodeFactor

src/pyhf/typing.py#L38

unresolved comment '# TODO: Switch to os.PathLike[str] once Python 3.8 support dropped' (C100)
PathOrStr = Union[str, "os.PathLike[str]"]

Shape = Tuple[int, ...]
Expand Down Expand Up @@ -150,17 +150,14 @@
precision: str
default_do_grad: bool

def _setup(self) -> None:
...
def _setup(self) -> None: ...


class Optimizer(Protocol):
name: str


class PDF(Protocol):
def sample(self, sample_shape: Shape) -> Any:
...
def sample(self, sample_shape: Shape) -> Any: ...

def log_prob(self, value: Any) -> Any:
...
def log_prob(self, value: Any) -> Any: ...
7 changes: 5 additions & 2 deletions src/pyhf/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* the observed data (optional)
* fit configurations ("measurements")
"""

from __future__ import annotations

import collections
Expand All @@ -17,6 +18,8 @@
from pyhf import exceptions, schema
from pyhf.mixins import _ChannelSummaryMixin
from pyhf.pdf import Model
import functools
import operator

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -464,8 +467,8 @@ def data(self, model, include_auxdata=True):

"""
try:
observed_data = sum(
(self.observations[c] for c in model.config.channels), []
observed_data = functools.reduce(
operator.iadd, (self.observations[c] for c in model.config.channels), []
)
except KeyError:
log.error(
Expand Down
4 changes: 1 addition & 3 deletions tests/test_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ def test_code0_validation(backend, do_tensorized_calc):
def test_code1_validation(backend, do_tensorized_calc):
histogramssets = [[[[0.9], [1.0], [1.1]]]]
alphasets = pyhf.tensorlib.astensor([[-2, -1, 0, 1, 2]])
expected = pyhf.tensorlib.astensor(
[[[[0.9**2], [0.9], [1.0], [1.1], [1.1**2]]]]
)
expected = pyhf.tensorlib.astensor([[[[0.9**2], [0.9], [1.0], [1.1], [1.1**2]]]])

interpolator = pyhf.interpolators.get(1, do_tensorized_calc=do_tensorized_calc)(
histogramssets, subscribe=False
Expand Down