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

Optimizer for SINDy-PI feature of implicit ODEs #447

Closed niuyushuo closed 5 months ago

niuyushuo commented 6 months ago

Hi,

I am a new user of pysindy and trying to fit implicit ODEs. Based on the example 9 (examples/9_sindypi_with_sympy.ipynb), example 12 (examples/12_weakform_SINDy_examples.ipynb), and example 15 (examples/15_pysindy_lectures.ipynb), building libraries depend on x and x dot could be done by weakPDE or PDE libraries with implicit_terms =True. But for all the optimizers, only SINDyPI supports implicit, but this one is deprecated in pysindy version >1.7. optimzer So just wonder, if any other optimizers work well for implicit ODEs. Thanks a lot. By the way, I am using pysindy 1.7.5.

Jacob-Stevens-Haas commented 6 months ago

Where are you seeing a deprecation warning in SINDyPIOptimizer? Currently it's the only one that will find implicit ODEs/PDEs

niuyushuo commented 6 months ago

Where are you seeing a deprecation warning in SINDyPIOptimizer? Currently it's the only one that will find implicit ODEs/PDEs

Thanks for your response. My bad, it should be SINDyPILibrary is deprecated with version >1.7. But when I test the code by myself, SINDyPILibrary still works well. But get error information: AttributeError: module 'pysindy' has no attribute 'SINDyPI' The test code is in the third block at example of 9_sindypi_with_sympy.ipynb. The issue comes from lines: sindy_opt = ps.SINDyPI( threshold=1e-6, tol=1e-8, thresholder="l1", max_iter=20000, ) Also, tried sindy_opt = ps.SINDyPIOptimizer sindy_opt = ps.optimizers.sindy_pi.SINDyPI They all get the no attribute error. Thanks.

Jacob-Stevens-Haas commented 6 months ago

The optimizer requires cvxpy and scs. Otherwise, I believe, its import is skipped, which is why you were getting the AttributeError. Reinstall pysindy with the optional extra requirements, pip install pysindy[cvxpy] and see if you get the results.

niuyushuo commented 6 months ago

The optimizer requires cvxpy and scs. Otherwise, I believe, its import is skipped, which is why you were getting the AttributeError. Reinstall pysindy with the optional extra requirements, pip install pysindy[cvxpy] and see if you get the results.

Thanks for your response. I tried to reinstall pysindy by 'pip install pysindy[cvxpy]' and got message 'zsh: no matches found: pysindy[cvxpy]'. Also tried to install pysindy from source and got the same message.

Jacob-Stevens-Haas commented 6 months ago

zsh needs to escape any square brackets

You can also just pip install cvxpy scs, and you'll probably get compatible versions.

niuyushuo commented 6 months ago

zsh needs to escape any square brackets

You can also just pip install cvxpy scs, and you'll probably get compatible versions.

Really appreciate your response. Now it works smoothly. It takes me a while to install cvxpy. Running a macOS Monterey Version 12.4 In case anyone else might have a similar issue. Here I list all the lines to solve this issue as following: brew install cmake pip install cvxpy scs pip install pysindy cvxpy

Jacob-Stevens-Haas commented 6 months ago

Glad it works! FWIW each package is handled separately by pip, so

pip install cvxpy scs
pip install pysindy cvxpy

is equivalent to

pip install cvxpy scs pysindy

or

pip install pysindy
pip install cvxpy
pip install scs

but since compatible versions of cvxpy and scs are contained int the pysindy cvxpy extra,

pip install pysindy[cvxpy]

Here, "cvxpy" is the (bad) name we chose to refer to compatible versions of both cvxpy and scs.