Skip to content
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

Fixed NeuralDSDE #724

Merged
merged 1 commit into from
Jun 15, 2022
Merged

Fixed NeuralDSDE #724

merged 1 commit into from
Jun 15, 2022

Conversation

ba2tro
Copy link
Contributor

@ba2tro ba2tro commented Jun 14, 2022

Fixed dereferencing of parameters in NeuralDSDE here for SciML/SciMLSensitivity.jl#623 to work , Lux compatible constructors for all layers have been added in /pull/722

Fixed dereferencing of parameters in NeuralDSDE here for SciML/SciMLSensitivity.jl#623 to work , Lux compatible constructors for all layers have been added in SciML/pull/722
@ba2tro
Copy link
Contributor Author

ba2tro commented Jun 14, 2022

Now it expects p to be [p1,p2] . Another approach to solve this would be to expect p = ComponentArray(p1, p2) from the user, but it would lead to issues while dereferincing because
the user may name p1 and p2 anything but the functor expects it to be dereferenced by p.p1 and p.p2 . The new approach allows us to index p like a normal vector of containing two ComponentArrays. The way I implemented it earlier is totally wrong.

@@ -179,13 +179,13 @@ function (n::NeuralDSDE{M})(x,p=n.p) where {M<:FastChain}
solve(prob,n.args...;sensealg=TrackerAdjoint(),n.kwargs...)
end

function (n::NeuralDSDE{M})(x,p1,p2,st1,st2) where {M<:Lux.AbstractExplicitLayer}
function (n::NeuralDSDE{M})(x,p,st1,st2) where {M<:Lux.AbstractExplicitLayer}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

julia can unpack it

Suggested change
function (n::NeuralDSDE{M})(x,p,st1,st2) where {M<:Lux.AbstractExplicitLayer}
function (n::NeuralDSDE{M})(x,(p1, p2),st1,st2) where {M<:Lux.AbstractExplicitLayer}

Copy link
Contributor Author

@ba2tro ba2tro Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we need them to be packed in one p so that we can pass it to the SDEProblem
https://github.com/Abhishek-1Bhatt/DiffEqFlux.jl/blob/b3b7ae7208f03918bdaaf67b39b6775515dcc6e0/src/neural_de.jl#L193

which will then call our functions with p where we will dereference individual p1 and p2 from p

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I added parentheses it works with one p and Julia will unpack it like

p1, p2 = p

Copy link
Contributor Author

@ba2tro ba2tro Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but that is not the point where we want to break it apart(unpack it). If you check the line I referenced above, we want to have one p till there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry. Now, I understand!

@ChrisRackauckas ChrisRackauckas merged commit 9f648dc into SciML:master Jun 15, 2022
@ba2tro ba2tro deleted the patch-2 branch June 19, 2022 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants