-
-
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
Supplying u0
to ODEProblem
does not work in some cases
#3268
Comments
Yeah this looks like an interface bug. |
This isn't an interface bug. In the first example, there is a single variable In your second example, there are differential and algebraic variables.
When providing the solution from |
As a contrived example, consider the system D(x) ~ x
x^3 + y^3 ~ 3 Where x ~ 1.0
x^3 + y^3 ~ 3 Which solves to x ~ 1.0
y ~ cbrt(2)
x^3 + y^3 ~ 3 which is a valid initialization, but overdetermined nonetheless. |
My understanding of how ModelingToolkit works, is that if you supply @mtkmodel Simple begin
@variables begin
x(t) = 1
y(t), [guess=cbrt(2)]
end
@equations begin
D(x) ~ x
x^3 + y^3 ~ 3
end
end
@mtkbuild sys = Simple()
initprob = ModelingToolkit.InitializationProblem(sys, 0.0)
initsol = solve(initprob)
u0 = initsol[unknowns(sys)]
prob = ODEProblem(sys, u0, (0, 0)) #OK, no warning So I'm confused, why in my 2nd example, do I not get this same behavior? I'm supplying a |
This isn't always the case. A vector In your second example, in addition to the 8 initial conditions from I apologize for the confusion from my example, I was a little mistaken and should have run some code rather than trying to emulate what MTK would do from memory. However, I do feel we should have that behavior, otherwise the user thinks the initial condition they provided is respected and @ChrisRackauckas In this example: julia> @mtkmodel Simple begin
@variables begin
x(t) = 1, [guess = 1]
y(t) = cbrt(2), [guess=cbrt(2)]
end
@equations begin
D(x) ~ x
x^3 + y^3 ~ 3
end
end
julia> @mtkbuild sys = Simple()
julia> prob = ODEProblem(sys, [sys.y => cbrt(3)], (0.0, 1.0)) #OK, no warning
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true
timespan: (0.0, 1.0)
u0: 2-element Vector{Float64}:
1.0
1.4422495703074083 MTK is more than happy to create the system without an initialization problem. Creating the integrator: julia> integ = init(prob)
t: 0.0
u: 2-element Vector{Float64}:
1.0
1.2599210499101785 BrownBasic corrects the algebraic variable. However, it is entirely possible that the initial condition for |
If you want to unconditionally bypass the initialization problem, you need to pass |
Here's the condition for creating an initialization problem, paraphrased from the
|
That case shouldn't bypass initialization. MTK shouldn't do that for any case with algebraic variables? |
Yeah, I was confused to find it bypassed initialization. Will fix ASAP. |
OK, thanks for explaining the So, now I'm even more confused. In the code below, I provide initial equations @mtkmodel Simple begin
@variables begin
x(t), [guess=1]
y(t), [guess=1]
end
@equations begin
D(x) ~ x
x^3 + y^3 ~ 3
end
end
@mtkbuild sys = Simple()
init_eqs = [sys.x => 1, sys.y => cbrt(3)]
initprob = ModelingToolkit.InitializationProblem(sys, 0.0, init_eqs) # Warning: Initialization system is overdetermined
initsol = solve(initprob) # retcode: Failure
prob = ODEProblem(sys, init_eqs, (0, 0.1)) #OK, no warning |
Would adding this and other such keyword arguments to the
Yes, this is the behavior Chris and I were discussing should be fixed. Currently, MTK thinks "I have all the initial conditions, don't need an initialization problem" but that isn't the case and it should build an initprob because the system has algebraic equations. It's also the behavior I expected in the example I gave here. After the fix, providing that initial condition will |
Yes, adding the keyword args that |
We shouldn't really document that. It's an internal that would lead to correctness issues, it shouldn't be exposed to users since it would get easily abused. |
I think it would be really helpful if the |
If I use
InitializationProblem
to pre-calculate au0
for a simple problem, this works without incident...However, for a more complex problem, for some reason I do not get the same behavior...
Note: my system is not overdetermined! I can see this because for one, the
InitializationProblem
build and solves just fine. Also I can simply removeu0
without incident...The text was updated successfully, but these errors were encountered: