dynamicslab / pysindy

A package for the sparse identification of nonlinear dynamical systems from data
https://pysindy.readthedocs.io/en/latest/
Other
1.36k stars 304 forks source link

[BUG] PySINDy and CVXPY issues #431

Closed akaptano closed 7 months ago

akaptano commented 7 months ago

Hi @Jacob-Stevens-Haas ,

Two bugs related to cvxpy to report after trying to install pysindy on a new Mac M2 desktop computer: (1)It looks like some changes were made recently that produces errors for users without a cvxpy installation. It looks like when I try to run any python example (e.g. running python /examples/2_introduction_to_sindy/example.py), I receive an error as follows:

File "/Users/akaptanoglu/anaconda3/envs/pysindy/lib/python3.11/site-packages/pysindy/optimizers/stable_linear_sr3.py", line 208, in StableLinearSR3 ) -> Tuple[cp.Variable, cp.Expression]: ^^ NameError: name 'cp' is not defined. Did you mean: 'np'?

I found that this error also occurs on an older windows PC machine.

(2) It looks like the OSQP wheel build does not work for Python 3.11 yet (and therefore CVXPY installation fails with "pip install cvxpy") since I receive the error reported here (https://stackoverflow.com/questions/74226651/error-in-building-wheel-for-osqp-because-no-module-named-cmake).

Please let me know if you can reproduce the following if you reinstall pysindy in a new conda environment with python version >= 3.11. Perhaps there is a workaround for (2) to install CVXPY without the OSQP solver?

Thanks, Alan

Jacob-Stevens-Haas commented 7 months ago

type hint

Ah, good find! the first one can be solved with

from __future__ import annotations

from PEP 563 or

Tuple[cp.Variable, cp.Expression] ---> Tuple["cp.Variable", "cp.Expression"]

from PEP 3107.

The future syntax is more stylistically preferred, but only available in python 3.7 and won't become default behavior until TBD (originally planned 3.10). The second is available since python 3.5 (because of tuple syntax)

OQSP on 3.11

Huh, OSQP has a 3.11 wheel for mac on the most recent release. Does pip not detect the macosx wheel for you? What about downloading and directly installing it? if neither, try brew install cmake before pip install osqp. I'm not on mac so I can't try - currently trying to build python 3.11 to test it on linux

~I don't think there's a good solution for us here. One of the comments on that stackoverflow post points to the OQSP build instructions. On a mac at least, brew install cmake should work. IIUC, the "right" solution is for OSQP and maybe cvxpy to include PEP 517 compliant build instructions using something like scikit-build-core or py-build-cmake~

On a related note, now that we've been able to bump gurobipy to >10.0.0, we should probably expand CI to 3.11 (and even 3.12 now that it's officially released) in order to get a heads up for these kinds of issues.

Jacob-Stevens-Haas commented 7 months ago

I was able to build 3.11.6 on linux and the provided wheel for osqp works. I can install .[cvxpy] fine

akaptano commented 7 months ago

Thanks Jake! Do you mind pushing a fix soon? A number of other users have reported this to me. And I think you're right about OSQP, thanks!

Jacob-Stevens-Haas commented 7 months ago

Yep! I'll get to it today or tomorrow.

Jacob-Stevens-Haas commented 7 months ago

Thanks for taking care of this, sorry I didn't get to it

Closed by https://github.com/dynamicslab/pysindy/commit/638e4bb1657ee9a7caaeca753ec0749f32f194fa