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

Minuit.interactive outside of Jupyter notebooks #1056

Open
wants to merge 44 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0aa85f2
Added PyQt6 widget and added ax kwarg to the visualize methods
adryyan Oct 28, 2024
59c3bf8
Added PyQt6 optional dependency
adryyan Oct 29, 2024
51bbf1f
Added tests
adryyan Oct 29, 2024
1367a88
Bug fixes
Nov 1, 2024
7f22e49
Added get_ipython import for tests
Nov 1, 2024
dae61d0
Fixed tests
Nov 1, 2024
aa29da3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 1, 2024
b90fdb1
Only return QMainWindow
Nov 3, 2024
02fc792
Fixed centering in ComboBox
Nov 3, 2024
cba417d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 3, 2024
9485f85
Added context manager for signal blocking
adryyan Dec 6, 2024
e20f357
Changed partial to lambda
adryyan Dec 6, 2024
2342b7d
Removed qt_exec arg and changed QMainWindow to QWidget
Dec 6, 2024
92f7c83
Removed tabs and added more decimals to SpinBox
Dec 6, 2024
cf0ee81
Moved _make_finite and _guess_initial_step to util
adryyan Dec 11, 2024
7a6f7af
Changed starting of event loop
adryyan Dec 11, 2024
1ba8065
Removed unnecessary lines
adryyan Dec 11, 2024
0901a46
Clean up
adryyan Dec 11, 2024
f7c4fd5
Moved mock ipython fixture to conftest.py
adryyan Dec 11, 2024
2813c51
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 11, 2024
a50b5e5
Removed repeated lines
adryyan Dec 11, 2024
b1fbd3f
Back to pyplot
adryyan Dec 12, 2024
c54c2d9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2024
122daff
Merge branch 'develop' into qtwidget
HDembinski Dec 12, 2024
22dcf94
Removed _widget prefix
adryyan Dec 12, 2024
70e930a
Added run_event_loop argument
adryyan Dec 12, 2024
9d7cc47
Changed layout
adryyan Dec 12, 2024
811b27b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 12, 2024
30a1184
Added is_jupyter
adryyan Dec 13, 2024
6e56da0
Moved run_event_loop to make_widget
adryyan Dec 13, 2024
5c866ae
Use is_jupyter from util and remove run_event_loop
adryyan Dec 13, 2024
0ec2969
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 13, 2024
f034929
Added fmin display to qtwidget
adryyan Dec 13, 2024
7f873ea
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 13, 2024
24ccc77
Removed success message
adryyan Dec 13, 2024
1ce9ea3
Merge branch 'develop' into qtwidget
HDembinski Dec 16, 2024
2fda767
Fixed importskips
Dec 16, 2024
6c5f02b
Ruff ignore conftest.py
Dec 16, 2024
63e0082
block_signals -> _block_signals
Dec 16, 2024
2d872ab
attempt to fix ci
HDembinski Dec 17, 2024
3ffd0c8
attempt to fix
HDembinski Dec 17, 2024
7ec04b2
attempt to fix ci
HDembinski Dec 17, 2024
8d50cbe
attempt to fix ci
HDembinski Dec 17, 2024
17abd16
attempt to fix ci
HDembinski Dec 17, 2024
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
51 changes: 30 additions & 21 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,45 @@ name: Coverage
on:
pull_request:
paths-ignore:
- 'doc/**'
- '.ci/**'
- '*.rst'
- "doc/**"
- ".ci/**"
- "*.rst"
push:
branches:
- main
- develop
- beta/*
paths-ignore:
- 'doc/**'
- '.ci/**'
- '*.rst'
- "doc/**"
- ".ci/**"
- "*.rst"

jobs:
coverage:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ github.job }}-${{ matrix.os }}-${{ matrix.python-version }}
create-symlink: true
- uses: rui314/setup-mold@v1
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: astral-sh/setup-uv@v4
- run: uv pip install --system nox
- run: nox -s cov
- uses: AndreMiras/coveralls-python-action@develop
# install-qt-action also does setup-python
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
aqtversion: "==3.1.*"
version: "6.8.1"
host: "linux"
target: "desktop"
arch: "linux_gcc_64"
# - uses: actions/setup-python@v5
# with:
# python-version: "3.12"
- uses: actions/checkout@v4
with:
submodules: true
- uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ github.job }}-${{ matrix.os }}-${{ matrix.python-version }}
create-symlink: true
- uses: rui314/setup-mold@v1
- uses: astral-sh/setup-uv@v4
- run: uv pip install --system nox
- run: nox -s cov
- uses: AndreMiras/coveralls-python-action@develop
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def pypy(session: nox.Session) -> None:


# Python-3.12 provides coverage info faster
@nox.session(python="3.12", venv_backend="uv", reuse_venv=True)
@nox.session(venv_backend="uv", reuse_venv=True)
def cov(session: nox.Session) -> None:
"""Run covage and place in 'htmlcov' directory."""
session.install("--only-binary=:all:", "-e.[test,doc]")
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ test = [
"ipywidgets",
# needed by ipywidgets >= 8.0.6
"ipykernel",
"PyQt6",
"joblib",
"jacobi",
"matplotlib",
Expand All @@ -52,6 +53,7 @@ test = [
"numba-stats; platform_python_implementation=='CPython'",
"pytest",
"pytest-xdist",
"pytest-qt",
"scipy",
"tabulate",
"boost_histogram",
Expand Down Expand Up @@ -101,6 +103,7 @@ pydocstyle.convention = "numpy"

[tool.ruff.lint.per-file-ignores]
"test_*.py" = ["B", "D"]
"conftest.py" = ["B", "D"]
"*.ipynb" = ["D"]
"automatic_differentiation.ipynb" = ["F821"]
"cython.ipynb" = ["F821"]
Expand Down
17 changes: 2 additions & 15 deletions src/iminuit/ipywidget.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Interactive fitting widget for Jupyter notebooks."""

from .util import _widget_guess_initial_step, _make_finite
import warnings
import numpy as np
from typing import Dict, Any, Callable
import sys

with warnings.catch_warnings():
# ipywidgets produces deprecation warnings through use of internal APIs :(
Expand Down Expand Up @@ -148,7 +148,7 @@ class Parameter(widgets.HBox):
def __init__(self, minuit, par):
val = minuit.values[par]
vmin, vmax = minuit.limits[par]
step = _guess_initial_step(val, vmin, vmax)
step = _widget_guess_initial_step(val, vmin, vmax)
vmin2 = vmin if np.isfinite(vmin) else val - 100 * step
vmax2 = vmax if np.isfinite(vmax) else val + 100 * step

Expand Down Expand Up @@ -277,18 +277,5 @@ def reset(self, value, limits=None):
return widgets.HBox([out, ui])


def _make_finite(x: float) -> float:
sign = -1 if x < 0 else 1
if abs(x) == np.inf:
return sign * sys.float_info.max
return x


def _guess_initial_step(val: float, vmin: float, vmax: float) -> float:
if np.isfinite(vmin) and np.isfinite(vmax):
return 1e-2 * (vmax - vmin)
return 1e-2


def _round(x: float) -> float:
return float(f"{x:.1g}")
19 changes: 14 additions & 5 deletions src/iminuit/minuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2341,10 +2341,14 @@ def interactive(
**kwargs,
):
"""
Return fitting widget (requires ipywidgets, IPython, matplotlib).
Interactive GUI for fitting.

A fitting widget is returned which can be displayed and manipulated in a
Jupyter notebook to find good starting parameters and to debug the fit.
Starts a fitting application (requires PyQt6, matplotlib) in which the
fit is visualized and the parameters can be manipulated to find good
starting parameters and to debug the fit.

When called in a Jupyter notebook (requires ipywidgets, IPython, matplotlib),
a fitting widget is returned instead, which can be displayed.

Parameters
----------
Expand All @@ -2371,9 +2375,14 @@ def interactive(
--------
Minuit.visualize
"""
from iminuit.ipywidget import make_widget

plot = self._visualize(plot)

if mutil.is_jupyter():
from iminuit.ipywidget import make_widget

else:
from iminuit.qtwidget import make_widget

return make_widget(self, plot, kwargs, raise_on_exception)

def _free_parameters(self) -> Set[str]:
Expand Down
Loading
Loading