Skip to content

Commit a0970dc

Browse files
authored
Better ruff settings and adjustments, improvements to README (#871)
- Use ruff to enforce pydocstyle - Switch to standard line length of 88, adjust files - Improvements to README
1 parent 67ecf53 commit a0970dc

File tree

14 files changed

+365
-333
lines changed

14 files changed

+365
-333
lines changed

README.rst

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
.. image:: https://mybinder.org/badge_logo.svg
2727
:target: https://mybinder.org/v2/gh/scikit-hep/iminuit/develop?filepath=doc%2Ftutorial
2828

29-
*iminuit* is a Jupyter-friendly Python interface for the *Minuit2* C++ library maintained by CERN's ROOT team.
29+
``iminuit`` is a Jupyter-friendly Python interface for the ``Minuit2`` C++ library maintained by CERN's ROOT team.
3030

3131
Minuit was designed to minimise statistical cost functions, for likelihood and least-squares fits of parametric models to data. It provides the best-fit parameters and error estimates from likelihood profile analysis.
3232

@@ -39,12 +39,22 @@ The iminuit package comes with additional features:
3939
- Builtin cost functions for statistical fits
4040

4141
- Binned and unbinned maximum-likelihood
42+
- Template fits with error propagation [H. Dembinski, A. Abldemotteleb, Eur.Phys.J.C 82 (2022) 11, 1043](https://doi.org/10.1140/epjc/s10052-022-11019-z)
4243
- Non-linear regression with (optionally robust) weighted least-squares
4344
- Gaussian penalty terms
4445
- Cost functions can be combined by adding them: ``total_cost = cost_1 + cost_2``
4546
- Support for SciPy minimisers as alternatives to Minuit's Migrad algorithm (optional)
4647
- Support for Numba accelerated functions (optional)
4748

49+
Dependencies
50+
------------
51+
52+
``iminuit`` is will always be a lean package which only depends on ``numpy``, but additional features are enabled if the following optional packages are installed
53+
- ``matplotlib``: Visualization of fitted model for builtin cost functions
54+
- ``ipywidgets``: Interactive fitting (also requires ``matplotlib``)
55+
- ``scipy``: Compute Minos intervals for arbitrary confidence levels
56+
- ``unicodeitplus``: Render names of model parameters in simple LaTeX as Unicode
57+
4858
Documentation
4959
-------------
5060

@@ -73,8 +83,9 @@ iminuit is intended to be used with a user-provided negative log-likelihood func
7383
m.migrad() # run optimiser
7484
m.hesse() # run covariance estimator
7585
76-
print(m.values) # x: 2, y: 3, z: 4
77-
print(m.errors) # x: 1, y: 1, z: 1
86+
.. image:: doc/_static/minuit_jupyter.png
87+
:alt: Jupyter display of Minuit
88+
7889

7990
Interactive fitting
8091
-------------------

doc/_static/minuit_jupyter.png

37.3 KB
Loading

doc/notebooks/basic.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,10 +1067,11 @@
10671067
]
10681068
},
10691069
{
1070+
"attachments": {},
10701071
"cell_type": "markdown",
10711072
"metadata": {},
10721073
"source": [
1073-
"The paramaters $a$ and $b$ are stronly anti-correlated, the numerical value of the correlation is shown in parentheses. The correlation is also highlighed by the blue color of the off-diagonal elements."
1074+
"The paramaters α and β are stronly anti-correlated, the numerical value of the correlation is shown in parentheses. The correlation is also highlighed by the blue color of the off-diagonal elements."
10741075
]
10751076
},
10761077
{
@@ -1562,7 +1563,7 @@
15621563
"name": "python",
15631564
"nbconvert_exporter": "python",
15641565
"pygments_lexer": "ipython3",
1565-
"version": "3.10.9"
1566+
"version": "3.9.16"
15661567
},
15671568
"nteract": {
15681569
"version": "0.12.3"

pyproject.toml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ test = [
6565
"tabulate",
6666
"boost_histogram",
6767
"resample",
68-
"unicodeit"
68+
"unicodeitplus"
6969
]
7070
doc = [
7171
"sphinx~=5.3.0",
@@ -90,7 +90,19 @@ filterwarnings = [
9090
]
9191

9292
[tool.ruff]
93-
line-length = 90
93+
select = ["E", "F", "D"]
94+
extend-ignore = ["D203", "D212"]
95+
96+
[tool.ruff.pydocstyle]
97+
convention = "numpy"
98+
99+
[tool.ruff.per-file-ignores]
100+
"test_*.py" = ["B", "D"]
101+
".ci/*.py" = ["D"]
102+
"bench/*.py" = ["D"]
103+
"doc/*.py" = ["D"]
104+
"setup.py" = ["D"]
105+
"cmake_ext.py" = ["D"]
94106

95107
[tool.mypy]
96108
ignore_missing_imports = true
@@ -100,9 +112,6 @@ pretty = true
100112
files = ["src"]
101113
no_implicit_optional = false
102114

103-
[tool.pydocstyle]
104-
convention = "numpy"
105-
106115
[tool.cibuildwheel]
107116
# update skip when numpy wheels become available
108117
skip = ["*-musllinux_*", "cp31?-win32", "cp31?-manylinux_i686"]

src/iminuit/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"""Jupyter-friendly Python interface for the Minuit2 library in C++.
1+
"""
2+
Jupyter-friendly Python interface for the Minuit2 library in C++.
23
34
Basic usage example::
45

src/iminuit/_repr_html.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ def fmin(fm):
114114
ff[2],
115115
colspan=3,
116116
style="text-align:center",
117-
title="Total number of function and (optional) gradient evaluations",
117+
title=(
118+
"Total number of function and (optional) gradient evaluations"
119+
),
118120
),
119121
),
120122
tr(
@@ -316,29 +318,3 @@ def matrix(arr):
316318
rows.append(tr(*cols))
317319

318320
return to_str(table(tr(td(), *[th(v) for v in names]), *rows))
319-
320-
321-
# def _parse_latex(s):
322-
# if s.startswith("$") and s.endswith("$"):
323-
# with optional_module_for("displaying LaTeX"):
324-
# from matplotlib.backends.backend_svg import RendererSVG
325-
# from matplotlib.font_manager import FontProperties
326-
# from io import StringIO
327-
328-
# fp = FontProperties(size=9)
329-
# # get bounding box of rendered text
330-
# r = RendererSVG(0, 0, StringIO())
331-
# w, h, _ = r.get_text_width_height_descent(s, fp, ismath=True)
332-
333-
# with StringIO() as f:
334-
# # render LaTeX as path
335-
# r = RendererSVG(w, h, f)
336-
# r.draw_text(r.new_gc(), 0, h, s, fp, angle=0, ismath=True)
337-
# f.seek(0)
338-
# svg = f.read()
339-
340-
# # strip preamble
341-
# svg = svg[svg.index("<svg") + 4 :]
342-
# return f'<svg role="img" style="fill:#f0f0f0" {svg}'
343-
344-
# return s

0 commit comments

Comments
 (0)