Closed eozd closed 4 years ago
This solution is ingenious ! I completely missed that I can recover the parameters from variables. Thank you so very much for your help with this.
As to adams-bashforth implementation, it seems there are certain issues with the current implementation, which I am closely following in the pytorch discussions.
As dopri tests pass, I will be glad to merge this PR upon your go ahead.
If the idea looks good to you, then by any means please go ahead. By the way, I would also like to thank you for the original implementation. As I will be working with tfdiffeq in the immediate future I will make sure to post any issues I may find with the changes I introduced.
Merged ! I do advise wrapping the callable portion of the ode function call(u,t)
inside a tf.function block to see some noticeable speedups. There's some performance bottlenecks I'd like to look into, and hopefully somehow implement the universal ordinary differential equations paper in the future, if I ever get to parse the Julia codebase
Fixes #2
This PR proposes a way to make the adjoint method work with tensorflow custom_gradient interface. The main changes are in
tfdiffeq/adjoint.py
and can be summarized as:OdeintAdjointMethod
function. We instead get these parameters from thevariables
keyword argument ofgrad
function.tf.custom_gradient
requiresgrad
function to return two sets of gradients as a pair. These are i. The gradient with respect to the inputs ofOdeintAdjointMethod
. These arex0
andt
in our case. ii. The gradient with respect to the parameters which aretf.Variable
objects stored in our ODE object.tf.Variable
objects created in adams optimizer, we mark them as non-trainable. However, there still seemsCaveats: I wasn't able to make the method work with the adams method (therefore adams - adjoint test is not enabled either). The problem is that the elements of the tuple returned from
augmented_dynamics
function have different shapes, and this causes problems withadams.py:138