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

Cost gradient support #936

Merged
merged 26 commits into from
Aug 30, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
autoclass_content = "both"
autosummary_generate = True
autodoc_member_order = "groupwise"
autodoc_type_aliases = {"ArrayLike": "ArrayLike"}

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
2,346 changes: 2,333 additions & 13 deletions doc/notebooks/cost_functions.ipynb

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions doc/plots/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from matplotlib import pyplot as plt


# custom visualization, x and y are taken from outer scope
# custom visualization; x, y, model are taken from outer scope
def viz(args):
plt.plot(x, y, "ok")
xm = np.linspace(x[0], x[-1], 100)
Expand All @@ -18,4 +18,5 @@ def model(x, a, b):
y = np.array([1.03, 1.58, 2.03, 2.37, 3.09])
c = cost.LeastSquares(x, y, 0.1, model)
m = Minuit(c, 0.5, 0.5)
m.interactive(viz) # calling m.interactive() uses LeastSquares.visualize
m.interactive(viz)
# m.interactive() also works and calls LeastSquares.visualize
11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,13 @@ filterwarnings = [

[tool.ruff]
select = [
"E", "F", # flake8
"D", # pydocstyle
"E",
"F", # flake8
"D", # pydocstyle
]
extend-ignore = [
"D212", # multi-line-summary-first-line
]
extend-ignore = ["D203", "D212"]
src = ["src"]
unfixable = [
"F841", # Removes unused variables
Expand All @@ -112,8 +115,6 @@ convention = "numpy"
".ci/*.py" = ["D"]
"bench/*.py" = ["D"]
"doc/*.py" = ["D"]
"setup.py" = ["D"]
"cmake_ext.py" = ["D"]

[tool.mypy]
ignore_missing_imports = true
Expand Down
6 changes: 5 additions & 1 deletion src/iminuit/_optional_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import contextlib
import warnings
from iminuit.warnings import OptionalDependencyWarning
from typing import Dict, Optional


@contextlib.contextmanager
def optional_module_for(functionality, *, replace=None, stacklevel=3):
def optional_module_for(
functionality: str, *, replace: Optional[Dict[str, str]] = None, stacklevel: int = 3
):
try:
yield
except ModuleNotFoundError as e:
assert e.name is not None
package = e.name.split(".")[0]
if replace:
package = replace.get(package, package)
Expand Down
Loading