-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
NNODE for DAE Problems #695
Conversation
Hi @ChrisRackauckas, I wanted to check with you to see if the theory that I have added in is correct. I am writing out some tests to verify that it works and will add them in the test file shortly |
I solved a bunch of bugs with this, but when I run this test file I get this long error that I do not really know how to solve. I believe the error starts at line 300, but my logic appears correct there so not sure what the problem is |
I think the problem is the argument signature that you have called You also need to be careful about doing anything to |
Hi @xtalax I have tried a several things but nothing seems to work. However, I think NNODE itself doesnt work for in place problems, so modifying it for the DAE case for in place methods is probably not going to work either. I am trying to find a DAE problem to test that is out of place, but both the DAEProblems from the DAE Problem Library (from DiffEqProblemLibrary.jl), and their corresponding DAEFunctions are in place. If you can direct me to an out of place DAE problem to test (or some other solution for this issue), that would be greatly appreciated Furthermore, if you think I should pursue making NNODE (and then DAE Problems) work for in place problems, I can do that too. Lastly, I did not intend to do anything to |
Kind of. DAEProblems are represented via |
The error is pointing to the fact that you're using the wrong function signature. The out of place DAE is 4 arguments, not 3. It needs to know the current state, not just the derivative. |
…l throws an error
Hi @ChrisRackauckas I tried adding u like you said but it still gives me an error for u being undefined at line 302. Going to keep working on this |
Your test case wasn't a valid out of place DAEProblem. See my suggestion. That should do fine. |
…eneration, still have an error
I made some fixes to this but I still have the following error: I think my new problem definition is a valid out of place DAE problem. My primary confusion lies with when to use |
what's your MWE? |
Does that mean minimum working example? If so, I dont really have one. I tried using a simpler chain but it solved nothing, and I used a problem directly from the DAEProblemLibrary (and from you) so I doubt that is the issue either. Not too sure how to resolve this |
src/ode_solve.jl
Outdated
|
||
function inner_loss_DAE(phi::ODEPhi{C, T, U}, f, autodiff::Bool, t::Number, θ, | ||
p) where {C, T, U <: Number} | ||
sum(abs2, ode_dfdx(phi, t, θ, autodiff) - f(ode_dfdx(phi, t, θ, autodiff), phi, p, t)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the output of a dae function is the residual, so there's nothing to subtract
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I just make that line sum(abs2, ode_dfdx(phi, t, θ, autodiff))
then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you need to evaluate f... sum(abs2,f(ode_dfdx(phi, t, θ, autodiff), phi(t, θ), p, t)))
src/ode_solve.jl
Outdated
p) where {C, T, U <: Number} | ||
out = phi(t, θ) | ||
dxdtguess = Array(ode_dfdx(phi, t, θ, autodiff)) | ||
sum(abs2, f(dxdtguess[i], phi, p, t[i]) for i in 1:size(out, 2)) / length(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can't pass phi
to f
, it's a function.
src/ode_solve.jl
Outdated
p) where {C, T, U <: Number} | ||
out = phi(t, θ) | ||
dxdtguess = Array(ode_dfdx(phi, t, θ, autodiff)) | ||
sum(abs2, f(dxdtguess[i], phi, p, t[i]) for i in 1:size(out, 2)) / length(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sum(abs2, f(dxdtguess[i], phi, p, t[i]) for i in 1:size(out, 2)) / length(t) | |
sum(abs2, f(dxdtguess[i], out, p, t[i]) for i in 1:size(out, 2)) / length(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but you need out at each t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do I need out
or out[:, i]
? I think it should be out[:, i]
but not 100% sure
src/ode_solve.jl
Outdated
sum(abs2, ode_dfdx(phi, t, θ, autodiff) .- f(ode_dfdx(phi, t, θ, autodiff), phi, p, t)) | ||
end | ||
|
||
function inner_loss_DAE(phi::ODEPhi{C, T, U}, f, autodiff::Bool, t::AbstractVector, θ, | ||
p) where {C, T, U} | ||
out = Array(phi(t, θ)) | ||
arrt = Array(t) | ||
dxdtguess = Array(ode_dfdx(phi, t, θ, autodiff)) | ||
sum(abs2, f(dxdtguess[:, i], phi, p, arrt[i]) for i in 1:size(out, 2)) / length(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two have the same errors as above.
What example are you working with to test? It should point exactly to the 4 issues I pointed out above. |
Here is my test code, which should also be in the commit
This should be the Robertson biochemical reactions in DAE form. I've checked this over several times, so I am pretty sure this is not the problem, but there could certainly be something I missed |
@ChrisRackauckas @xtalax I implemented the new edits that you suggested and I am pretty sure that the loss function generation is working properly now. However, the last step here of calling Julia's |
Done in #790 |
Initial changes to ode_solve, added NNDAE to get this solver working for DAE problems