-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get the gradient (zygote) calculated by DynamicalSystems #241
Comments
Oh, I wish I knew anything about automagic differentiation to help you with this... But I've never used Zygote.jl so I have no idea what it does. I think it is worth posting a link to this issue to the Julia slack for |
My goal is to use zygote to solve the gradient and use it for parameter optimization of the problem, and this problem involves DynamicalSystems, which is similar to partial differential equations. Thank you for your reply. I hope that this package will support gradient solving in the future. |
Did you give Enzyme a try? The issue here is that |
Thanks Chris! Besides trying Enzyme, can you also tell us which function from Dynamical Systems you are interested in? I doubt it is |
My issue involves calculating flood progression using the Muskingum-Cunge method in hydrological science, incorporating two variables: outflow, inflow, outflow(t+1) = f(outflow(t), inflow(t+1), inflow(t)), outflow[0] = inflow[0], where inflow is a known variable. The code implementation is as follows:
Due to this code involving array mutation, it cannot compute
Although the computed results are consistent, functions built using DynamicSystems still face the array mutation limitation:
Indeed, Enzyme.jl is also a good autodiff package that supports mutating arrays, but the Optimization.jl package I'm using has only tried AutoZygote and AutoForwarddiff, and AutoEnzyme may need further exploration. In fact, the Muskingum method is derived from simplifying an ODE problem, so perhaps I can directly construct an ODE problem for solution. Finally, thank you for your thoughtful and reliable responses. |
But if DifferentialEquations.jl supports Zygote.gradient, why don't you use the discrete map version of DifferentialEquations.jl? (formally called a discrete problem https://docs.sciml.ai/DiffEqDocs/stable/types/discrete_types/ ) If the only thing you need is to integrate forwards in time a dynamical system, my advice is to use DiffEq directly; DynamicalSystems.jl is primarily for doing some analysis that is happening either on top, or after, evolving the system. p.s.: I admit I don't understand how DiffEq can support Zygote.gradient; in the end of the day we have an ODEIntegrator, and this object constantly mutates its own state. So why isn't that this is not a "mutability problem" for the gradient estimation? In the sense that it is a problem to iteratively create a trajectory because you mutate a vector of vectors, but mutating the ODE integrator itself is not a problem? I think autodiff stuff are currently beyond my knowledge level :D |
If the only thing you need is to integrate forwards in time a dynamical system, my advice is to use DiffEq directly; DynamicalSystems.jl is primarily for doing some analysis that is happening either on top, or after, evolving the system. Yes, it seems better to construct a discrete problem, I will try to convert this problem
Indeed, DiffEq and DynamicalSystems are very similar in writing, but DiffEq can support Zygote.gradient. I think it may be related to the SciMLSensitivity.jl package, which provides support for some autodiff libraries. Finally, thank you for your reply. I will look forward to the support of gradient calculation in this package in the future, because adding a neural network to DynamicalSystems seems to be a very interesting idea. |
Okay, let's keep this issue open for future reference. I don't do autodiff so I can't solve it, but maybe someone in the future will contribute a solution! |
Describe the bug
Hello, I want to use DynamicalSystems.jl to calculate the gradient, but the following problem occurs, which may be related to mutate array
Minimal Working Example
output:
Package versions
Please provide the versions you use. To do this, run the code:
The text was updated successfully, but these errors were encountered: