-
Notifications
You must be signed in to change notification settings - Fork 12
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
Parameter handling #34
Comments
maybe define a new struct and add a dispatch |
The state of my thoughts on the problem How we handle parameters at the moment
Compatibility with DiffEqFluxThe problem doesn't originate at the level of DiffEqFlux but rather at DiffEqSensitivity.jl, ReverseDiff.jl, ForwardDiff.jl and Zygote.jl. All of these (seem to) work ideally with flat Arrays. The adjoint methods (ReverseDiff) of DiffEqSensitivity will accept a masked version of the tuple synax, such as function nd_wrapper!(dx, x, p, t)
nd!(dx, x, ([p; para_fixed], nothing), t)
end This comes with a reasonable computational overhead. At the moment this is the recommended way for utilizing DiffEqSensitivity, since the performance is okay and we don't have to rewrite our library. Tracker.jl is a very robust package and has no problems differentiating the tuple syntax. However it seems to be faster for large problems and for out-of-place problems. The DiffEqSensitivity manual doesn't recommend its usage with inplace problem such as we provide. At the moment, Tracker is the only option for tackling SDEs but this branch of DiffEqSensitivity is under development. ForwardDiffSensitivity should be fastest for small problems [<100paras], but ForwardDiff.jl needs AbstractArrays to pass along dual numbers. Wrapping the tuple in a function such as above does not work. Modifying Zygote isn't fully compatible with DiffEqSensitivity yet, but that's under development. Still Zygote seems to be used internally for calculating vector jacobian products (vjps). This might cause some of the errors we are seeing. DiffEqSensitivity provids an option for specifying other algorithms for the vjp calculations. We could experiment with that. Parallelization with @threads causes problems at the moment. This will take a while to fix. Compatibility with ModelingToolkitMTK does not like the tuple Syntax. Ideally parameters should be in an array (does the array have to be flat? it seems yes). Wrapping doesn't help either. To use PolicyWithout a concrete problem at hand we have these guidelines.
For a concrete application it might make sense to rewrite ND, such that parameter dimensions are specified at |
Issue about types of parameters in DiffEqFLux: SciML/DiffEqFlux.jl#178 |
It's in the docs: https://fhell.github.io/NetworkDynamics.jl/dev/parameters/ |
Hi, I think the issue I'm facing is related to how ND handles parameters. The parameters are passed onto the ODEproblem as a tuple. The first element getting passed to the nodes is an array of 4 structs corresponding to the number of nodes, the lines have no parameters: The issue is that I'm using a PeriodicCallback to modify each of the four parameters passed to the nodes. For this, I'm using a loop to iterate over
However, this code line seems to be updating all four Any thoughts on why this occurs? |
Hmm... sounds strange. Could you post a minimal example where this problem occurs? I am not sure how this has to do with NetworkDynamics, since in the moment that the callback is applied ND shouldn't be doing anything. |
We need to support the following parameter conventions:
global (every node and edge sees all parameters)
local (every edge sees only parameters with the right index)
partially missing (edges might have no parameters, while vertices have either global or local ps)
At the moment global is the standard and local can be achieved by passing a tuple: https://fhell.github.io/NetworkDynamics.jl/dev/directed_and_weighted_graphs/#Parameter-handling-1
The problem with the tuple syntax is that it doesn't play nicely with Flux and MTK. An array-based solution would be desirable and could be based on: https://github.com/SciML/RecursiveArrayTools.jl
Note however, that there seem to remain some problems with MTK & ArrayPartitions combined SciML/ModelingToolkit.jl#341.
The strategy for tackling this will be to modify
p_e_idx
. Once this is resolved, it should be tested in the relevant environments and the documentation should be expanded.The text was updated successfully, but these errors were encountered: