better-optimize 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {better_optimize-0.2.0 → better_optimize-0.2.1}/PKG-INFO +1 -1
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize/_version.py +3 -3
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize/wrapper.py +9 -2
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize.egg-info/PKG-INFO +1 -1
- {better_optimize-0.2.0 → better_optimize-0.2.1}/tests/test_wrapper.py +30 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/LICENSE +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/README.md +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize/__init__.py +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize/basinhopping.py +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize/constants.py +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize/minimize.py +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize/root.py +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize/utilities.py +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize.egg-info/SOURCES.txt +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize.egg-info/dependency_links.txt +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize.egg-info/requires.txt +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize.egg-info/top_level.txt +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/pyproject.toml +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/setup.cfg +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/setup.py +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/tests/test_basinhopping.py +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/tests/test_jax_integration.py +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/tests/test_minimize.py +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/tests/test_root.py +0 -0
- {better_optimize-0.2.0 → better_optimize-0.2.1}/tests/test_utilities.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: better_optimize
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: A drop-in replacement for scipy optimize functions with quality of life improvements
|
|
5
5
|
License: MIT License
|
|
6
6
|
Project-URL: Homepage, https://github.com/jessegrabowski/better_optimize
|
|
@@ -8,11 +8,11 @@ import json
|
|
|
8
8
|
|
|
9
9
|
version_json = '''
|
|
10
10
|
{
|
|
11
|
-
"date": "
|
|
11
|
+
"date": "2026-03-02T01:36:39+0100",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "0.2.
|
|
14
|
+
"full-revisionid": "14b8b75021dd22fa3d38135eee74b2ab95c30a06",
|
|
15
|
+
"version": "0.2.1"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
|
@@ -4,6 +4,7 @@ from collections.abc import Callable
|
|
|
4
4
|
from functools import partial
|
|
5
5
|
|
|
6
6
|
import numpy as np
|
|
7
|
+
import scipy.sparse as sp
|
|
7
8
|
|
|
8
9
|
from rich.console import Console
|
|
9
10
|
from rich.progress import (
|
|
@@ -134,10 +135,16 @@ class ObjectiveWrapper:
|
|
|
134
135
|
|
|
135
136
|
value_dict = {"f_value": value}
|
|
136
137
|
if grad is not None:
|
|
137
|
-
|
|
138
|
+
if sp.issparse(grad):
|
|
139
|
+
grad_norm = sp.linalg.norm(grad)
|
|
140
|
+
else:
|
|
141
|
+
grad_norm = np.linalg.norm(grad)
|
|
138
142
|
value_dict["grad_norm"] = grad_norm
|
|
139
143
|
if hess is not None:
|
|
140
|
-
|
|
144
|
+
if sp.issparse(hess):
|
|
145
|
+
hess_norm = sp.linalg.norm(hess)
|
|
146
|
+
else:
|
|
147
|
+
hess_norm = np.linalg.norm(hess)
|
|
141
148
|
value_dict["hess_norm"] = hess_norm
|
|
142
149
|
|
|
143
150
|
if self.n_eval == 0 and self.task is None:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: better_optimize
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: A drop-in replacement for scipy optimize functions with quality of life improvements
|
|
5
5
|
License: MIT License
|
|
6
6
|
Project-URL: Homepage, https://github.com/jessegrabowski/better_optimize
|
|
@@ -7,6 +7,7 @@ from functools import partial
|
|
|
7
7
|
|
|
8
8
|
import numpy as np
|
|
9
9
|
import pytest
|
|
10
|
+
import scipy.sparse as sp
|
|
10
11
|
|
|
11
12
|
from scipy.optimize import minimize as scipy_minimize
|
|
12
13
|
from scipy.optimize import root as scipy_root
|
|
@@ -66,3 +67,32 @@ def test_execption_breaks_optimization(root, monkeypatch):
|
|
|
66
67
|
# Non-KeyboardInterrupt exceptions should break execution.
|
|
67
68
|
with pytest.raises(Exception, match="Simulated error"):
|
|
68
69
|
optimizer_early_stopping_wrapper(f_optim)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def func2(x, a, b):
|
|
73
|
+
f = [a * x[0] * np.cos(x[1]) - 4, x[1] * x[0] - b * x[1] - 5]
|
|
74
|
+
|
|
75
|
+
return np.array(f)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def func2_sparse_jac(x, a, b):
|
|
79
|
+
df = np.array([[a * np.cos(x[1]), -a * x[0] * np.sin(x[1])], [x[1], x[0] - b]])
|
|
80
|
+
return sp.csr_matrix(df)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_wrapper_compatible_with_sparse_outputs():
|
|
84
|
+
x0 = np.array([0.8, 0.8])
|
|
85
|
+
|
|
86
|
+
objective = ObjectiveWrapper(
|
|
87
|
+
f=partial(func2, a=1, b=1),
|
|
88
|
+
jac=partial(func2_sparse_jac, a=1, b=1),
|
|
89
|
+
maxeval=100,
|
|
90
|
+
progressbar=True,
|
|
91
|
+
root=True,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
with objective.progress:
|
|
95
|
+
result = objective(x0)
|
|
96
|
+
|
|
97
|
+
value, grad = result
|
|
98
|
+
assert sp.issparse(grad)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{better_optimize-0.2.0 → better_optimize-0.2.1}/better_optimize.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|