better-optimize 0.1.7__tar.gz → 0.2.0__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.1.7 → better_optimize-0.2.0}/PKG-INFO +1 -1
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize/_version.py +3 -3
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize/wrapper.py +8 -3
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize.egg-info/PKG-INFO +1 -1
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize.egg-info/SOURCES.txt +1 -0
- better_optimize-0.2.0/tests/test_jax_integration.py +68 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/LICENSE +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/README.md +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize/__init__.py +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize/basinhopping.py +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize/constants.py +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize/minimize.py +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize/root.py +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize/utilities.py +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize.egg-info/dependency_links.txt +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize.egg-info/requires.txt +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/better_optimize.egg-info/top_level.txt +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/pyproject.toml +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/setup.cfg +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/setup.py +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/tests/test_basinhopping.py +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/tests/test_minimize.py +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/tests/test_root.py +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/tests/test_utilities.py +0 -0
- {better_optimize-0.1.7 → better_optimize-0.2.0}/tests/test_wrapper.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: better_optimize
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
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": "2025-
|
|
11
|
+
"date": "2025-12-13T05:36:24+0100",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "0.
|
|
14
|
+
"full-revisionid": "487a1c99b33650b7ba7264b19373ec2d54ca2e1f",
|
|
15
|
+
"version": "0.2.0"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
|
@@ -122,10 +122,15 @@ class ObjectiveWrapper:
|
|
|
122
122
|
if not self.progressbar:
|
|
123
123
|
return
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
value = np.asarray(value)
|
|
126
|
+
if self.root:
|
|
127
|
+
value = np.linalg.norm(value)
|
|
128
|
+
elif value.size != 1:
|
|
129
|
+
raise ValueError(
|
|
130
|
+
f"Objective function must return a scalar value for minimization, got {value.shape}"
|
|
131
|
+
)
|
|
127
132
|
else:
|
|
128
|
-
value =
|
|
133
|
+
value = value.item()
|
|
129
134
|
|
|
130
135
|
value_dict = {"f_value": value}
|
|
131
136
|
if grad is not None:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: better_optimize
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
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
|
|
@@ -16,6 +16,7 @@ better_optimize.egg-info/dependency_links.txt
|
|
|
16
16
|
better_optimize.egg-info/requires.txt
|
|
17
17
|
better_optimize.egg-info/top_level.txt
|
|
18
18
|
tests/test_basinhopping.py
|
|
19
|
+
tests/test_jax_integration.py
|
|
19
20
|
tests/test_minimize.py
|
|
20
21
|
tests/test_root.py
|
|
21
22
|
tests/test_utilities.py
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from numpy.testing import assert_allclose
|
|
5
|
+
|
|
6
|
+
from better_optimize.basinhopping import basinhopping
|
|
7
|
+
from better_optimize.minimize import minimize
|
|
8
|
+
from better_optimize.root import root
|
|
9
|
+
|
|
10
|
+
jax = pytest.importorskip("jax")
|
|
11
|
+
jnp = pytest.importorskip("jax.numpy")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@pytest.fixture(scope="module")
|
|
15
|
+
def jax_1d_quadratic():
|
|
16
|
+
def f(x):
|
|
17
|
+
return jnp.sum((x - 1.0) ** 2)
|
|
18
|
+
|
|
19
|
+
return jax.value_and_grad(f)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_minimize_with_jax_array(jax_1d_quadratic):
|
|
23
|
+
x0 = np.array([2.0])
|
|
24
|
+
|
|
25
|
+
res = minimize(jax_1d_quadratic, x0, method="L-BFGS-B")
|
|
26
|
+
|
|
27
|
+
assert res.success
|
|
28
|
+
assert_allclose(res.x, np.array([1.0]))
|
|
29
|
+
|
|
30
|
+
f_val, _ = jax_1d_quadratic(res.x)
|
|
31
|
+
assert isinstance(f_val, jax.Array)
|
|
32
|
+
assert_allclose(np.asarray(f_val), 0.0, atol=1e-6, rtol=1e-6)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_root_with_jax_array():
|
|
36
|
+
def f(x):
|
|
37
|
+
return jnp.array(x) - 2.0
|
|
38
|
+
|
|
39
|
+
x0 = np.array([0.0])
|
|
40
|
+
|
|
41
|
+
res = root(f, x0, method="hybr")
|
|
42
|
+
|
|
43
|
+
assert res.success
|
|
44
|
+
assert_allclose(res.x, np.array([2.0]), atol=1e-4, rtol=1e-4)
|
|
45
|
+
f_val = f(res.x)
|
|
46
|
+
assert isinstance(f_val, jax.Array)
|
|
47
|
+
assert_allclose(np.asarray(f_val), 0.0, atol=1e-6, rtol=1e-6)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_basinhopping_with_jax_array(jax_1d_quadratic):
|
|
51
|
+
x0 = np.array([3.0])
|
|
52
|
+
|
|
53
|
+
res = basinhopping(
|
|
54
|
+
jax_1d_quadratic,
|
|
55
|
+
x0=x0,
|
|
56
|
+
minimizer_kwargs={"method": "L-BFGS-B", "tol": 1e-6},
|
|
57
|
+
niter=20,
|
|
58
|
+
progressbar=False,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
assert res.success
|
|
62
|
+
assert_allclose(res.x, np.array([1.0]), atol=1e-3, rtol=1e-3)
|
|
63
|
+
|
|
64
|
+
val, grad = jax_1d_quadratic(res.x)
|
|
65
|
+
assert isinstance(val, jax.Array)
|
|
66
|
+
assert isinstance(grad, jax.Array)
|
|
67
|
+
assert_allclose(np.asarray(val), 0.0, atol=1e-5, rtol=1e-5)
|
|
68
|
+
assert_allclose(np.asarray(grad), np.array([0.0]), atol=1e-5, rtol=1e-5)
|
|
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.1.7 → better_optimize-0.2.0}/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
|