-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
Silent and wrong derivatives of observed variables #2697
Comments
Interesting, not entirely sure what's going on here. We can take a look, it's fixable. |
This is because interpolation produces the timeseries for |
I feel the best we can do here right now is error if any of the indexes is an observed quantity and |
That's fine, get an error setup for now and then we can fix it later. |
Sounds good 👍 I think it is better than returning a wrong result As always, thank you for your responsiveness 😃 |
Do you have some quick pointers on how to compute using Test
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using DifferentialEquations
@variables x(t) y(t)
@named sys = ODESystem([D(x) ~ 1, y ~ x^2], t)
sys = structural_simplify(sys) # move y to observed variables
prob = ODEProblem(sys, [x => 0.0], (0.0, 1.0)) # analytical solution: x = t, y = t^2
sol = solve(prob)
y_sym = Dict(eq.lhs => eq.rhs for eq in observed(sys))[y] # find expression for y in terms of other quantities
y′_sym = expand_derivatives(D(y_sym)) # expression for y′ in terms of other quantities
y′_obs(t) = NaN # TODO: how to compute this from ODESolution sol?
y′_anal(t) = 2 * t # analytical solution y′ = 2*x*x′ = 2*t
@test y′_obs(1.0) ≈ y′_anal(1.0) Now |
Derivatives of observed variables calculated with
ODESolution(t, Val{1}, ...)
are incorrect.On
v9.12.2
(after #2574), the simple testfails with
Is this the general case mentioned in #2574?
Having this work generally would be both very convenient and a natural extension to the solution calling interface!
Also, the current behavior is to return the wrong derivative with no error or warning.
I think this is severe and likely to cause hard-to-find bugs in user code.
Is it possible to identify the cases when
y
is an observed variable and the methods of #2574 do not apply?In those cases, for example, could
ODESolution(t, Val{N >= 1}, idxs=y)
issue an error or warning?The text was updated successfully, but these errors were encountered: