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

D(x)-like guesses are not respected during initialization #3049

Closed
hersle opened this issue Sep 16, 2024 · 2 comments · Fixed by #3050
Closed

D(x)-like guesses are not respected during initialization #3049

hersle opened this issue Sep 16, 2024 · 2 comments · Fixed by #3050
Labels
bug Something isn't working

Comments

@hersle
Copy link
Contributor

hersle commented Sep 16, 2024

$x\prime\prime(t) = 0$ with $x(0) = 0$ and ${x\prime(0)}^2 = 1$ should initialize with $x\prime(0) = \pm 1$ chosen by an initial guess, and solve to $x(t) = \pm t$:

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using DifferentialEquations
using Test

for sign in [-1.0, +1.0]
    @variables x(t)
    sys = ODESystem(
        [D(D(x)) ~ 0], t;
        initialization_eqs = [D(x)^2 ~ 1, x ~ 0], guesses = [D(x) => sign], name = :sys
    ) |> structural_simplify
    prob = ODEProblem(sys, [], (0.0, 1.0), [])
    sol = solve(prob, Tsit5())
    @test sol(1.0, idxs=sys.x)  sign # system with D(x(0)) = ±1 should solve to x(1) = ±1
end

But it always chooses the negative branch:

Test Failed at C:\Users\herma\.julia\dev\SymBoltz\bug.jl:14
  Expression: sol(1.0, idxs = sys.x) ≈ sign
   Evaluated: -0.9999999999999956 ≈ 1.0

So it looks like the guess for D(x) is not respected. Is there a missing dummy derivative substitution somewhere, similar to #3029?

@hersle hersle added the bug Something isn't working label Sep 16, 2024
@ChrisRackauckas
Copy link
Member

Yes, this looks like a substitution miss. We probably need to do a pass over the keys like in that issue you linked, where we pass over it to get the new guesses array before putting that with the NonlinearSystem

@hersle
Copy link
Contributor Author

hersle commented Sep 16, 2024

Ok, thanks! I will try to fix it in a similar way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants