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] tutorial 10 TypeError: PDELibrary.__init__() got an unexpected keyword argument 'function_library' #478

Closed chaous closed 3 months ago

chaous commented 4 months ago

I try to run tutorial 10 and get TypeError: PDELibrary.init() got an unexpected keyword argument 'function_library'. For some reason ps.PDELibrary doesn't have 'function_library'. I tried to install dev and got WARNING: pysindy 1.7.5 does not provide the extra 'dev'

Reproducing code example:

t = np.linspace(0, 10)
x = np.linspace(0, 10)
u = ps.AxesArray(np.ones((len(x) * len(t), 2)),{"ax_coord":1})

# Define PDE library that is quadratic in u, 
# and second-order in spatial derivatives of u.
# library_functions = [lambda x: x, lambda x: x * x]
# library_function_names = [lambda x: x, lambda x: x + x]
pde_lib = ps.PDELibrary(
#     library_functions=library_functions,
    function_library=ps.PolynomialLibrary(degree=2,include_bias=False),
    derivative_order=2,
    spatial_grid=x,
).fit([u])
print("2nd order derivative library: ")
print(pde_lib.get_feature_names())
import pysindy
<< your code here >>

Error message:

Cell In[8], line 10 4 u = ps.AxesArray(np.ones((len(x) len(t), 2)),{"ax_coord":1}) 6 # Define PDE library that is quadratic in u, 7 # and second-order in spatial derivatives of u. 8 # library_functions = [lambda x: x, lambda x: x x] 9 # library_function_names = [lambda x: x, lambda x: x + x] ---> 10 pde_lib = ps.PDELibrary( 11 # library_functions=library_functions, 12 function_library=ps.PolynomialLibrary(degree=2,include_bias=False), 13 derivative_order=2, 14 spatial_grid=x, 15 ).fit([u]) 16 print("2nd order derivative library: ") 17 print(pde_lib.get_feature_names())

TypeError: PDELibrary.init() got an unexpected keyword argument 'function_library'

PySINDy/Python version information:

1.7.5 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0]

Jacob-Stevens-Haas commented 4 months ago

Thanks for your question. Please format your code with backticks, e.g. ```

chaous commented 4 months ago

done

Thanks for your question. Please format your code with backticks, e.g. ```

Jacob-Stevens-Haas commented 4 months ago

Ah, yeah, PDELibrary has only recently been able to accept another library as function_library argument. Before that, you had to manually specify library_functions as a list of callables. It looks like you've tried to set both, which won't work on any version.

You can check help(PDELibrary) for the arguments allowed by 1.7.5.

chaous commented 4 months ago

Ok, I just tried to run the tutorial

Jacob-Stevens-Haas commented 3 months ago

@chaous did this solve your problem?

chaous commented 3 months ago

Yes, I was thank you