Skip to content

bug - design_bfgs -> rightmost_root: run example in docstring, it raises an except during optimization #14

@adriansal0712

Description

@adriansal0712

For the code:

from tdspy.stabopt.controller_bfgs import design_bfgs
import numpy as np
E = np.eye(2)
P0 = np.array([[-1., 0.], [0., -2.]])
P1 = np.array([[-0.5, 0.], [0., -0.5]])
P = np.stack([P0, P1], axis=2)
hP = np.array([0.,0.5])
K0 = np.zeros((2,2,1))
hK = np.array([0.])
B = np.eye(2)
C = np.eye(2)
sol = design_bfgs(E, P, hP, K0, hK, B, C, options={"disp": True})

Here's the traceback:

sol = design_bfgs(E, P, hP, K0, hK, B, C, options={"disp": True})
RUNNING THE L-BFGS-B CODE

       * * *

Machine precision = 2.220D-16
N = 4 M = 10
This problem is unconstrained.

At X0 0 variables are exactly at the bounds

At iterate 0 f= -2.84801D+00 |proj g|= 3.29947D-01

At iterate 1 f= -3.17037D+00 |proj g|= 3.14694D-01

At iterate 2 f= -3.87545D+00 |proj g|= 2.77304D-01

At iterate 3 f= -8.46870D+00 |proj g|= 5.41454D-02

At iterate 4 f= -8.58765D+00 |proj g|= 4.82464D-02

At iterate 5 f= -8.83938D+00 |proj g|= 3.95157D-02
Traceback (most recent call last):
File "", line 1, in
File "/Users/adrian/Nextcloud/Software/tdspy/src/tdspy/stabopt/controller_bfgs.py", line 73, in design_bfgs
>>> P = np.stack([P0, P1], axis=2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/optimize/_minimize.py", line 713, in minimize
res = _minimize_lbfgsb(fun, x0, args, jac, bounds,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/optimize/_lbfgsb_py.py", line 407, in _minimize_lbfgsb
f, g = func_and_grad(x)
^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/optimize/_differentiable_functions.py", line 296, in fun_and_grad
self._update_fun()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/optimize/_differentiable_functions.py", line 262, in _update_fun
self._update_fun_impl()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/optimize/_differentiable_functions.py", line 163, in update_fun
self.f = fun_wrapped(self.x)
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/optimize/_differentiable_functions.py", line 145, in fun_wrapped
fx = fun(np.copy(x), *args)
^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/optimize/_optimize.py", line 79, in call
self._compute_if_needed(x, *args)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/optimize/_optimize.py", line 73, in _compute_if_needed
fg = self.fun(x, *args)
^^^^^^^^^^^^^^^^^^
File "/Users/adrian/Nextcloud/Software/tdspy/src/tdspy/stabopt/gradients.py", line 81, in func_sa
rmr, rmr_info = rightmost_root(E, A, hA, r=0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/adrian/Nextcloud/Software/tdspy/src/tdspy/stability/characteristic_roots.py", line 479, in rightmost_root
U, s, Vh = linalg.svd(M, compute_uv=True) # sorted in non-increasing order
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/linalg/_decomp_svd.py", line 108, in svd
a1 = _asarray_validated(a, check_finite=check_finite)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/scipy/_lib/_util.py", line 321, in _asarray_validated
a = toarray(a)
^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/numpy/lib/_function_base_impl.py", line 665, in asarray_chkfinite
raise ValueError(
ValueError: array must not contain infs or NaNs

rmr, rmr_info = rightmost_root(E, P, hP, r=0)
Traceback (most recent call last):
File "", line 1, in
NameError: name 'rightmost_root' is not defined

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions