GithubHelp home page GithubHelp logo

Bug in DiffEqPhysics ? about diffeqphysics.jl HOT 14 CLOSED

sciml avatar sciml commented on June 7, 2024
Bug in DiffEqPhysics ?

from diffeqphysics.jl.

Comments (14)

KlausC avatar KlausC commented on June 7, 2024 1

It seems, that some of the solvers in "symplectic_perform_step.jl" silently assume, that f.f2(p, q) == p for the very first calculation in perform_step! (for example lines 1133 and 1275). The corresponding initialize! functions evaluate f.f2 and leave it in a variable, which is not used by perform_step!. That is the case for KahanLi8 and SofSpa10, and also the constant variants, but is correct for SymplecticEuler. It will be necessary to check and fix each individual algorithm.

from diffeqphysics.jl.

ChrisRackauckas avatar ChrisRackauckas commented on June 7, 2024

Are the inputs flipped?

from diffeqphysics.jl.

KlausC avatar KlausC commented on June 7, 2024

I think no, just trying with flipped (p, q) in the definition of H gave nothing reasonable:

julia> H(q, p, param) = p^2/20
H (generic function with 1 method)

julia> prob = HamiltonianProblem(H, p0, q0, (0., 1.))
ODEProblem with uType ArrayPartition{Float64,Tuple{Float64,Float64}} and tType Float64. In-place: false
timespan: (0.0, 1.0)
u0: 1.00.0

julia> sol = solve(prob, dt=0.001)
retcode: Success
Interpolation: specialized 6th order interpolation
t: 7-element Array{Float64,1}:
 0.0
 0.001
 0.011
 0.07787167758977546
 0.26173425803838424
 0.5841996582033573
 1.0
u: 7-element Array{ArrayPartition{Float64,Tuple{Float64,Float64}},1}:
 (1.0, 0.0)
 (0.9999999500000004, 0.0009999999833333335)
 (0.9999939500061004, 0.010999977816680087)
 (0.9996968154128554, 0.07786380759988994)
 (0.9965767138414221, 0.2614355260679268)
 (0.9829840154332482, 0.5808823065288845)
 (0.9504152802553116, 0.9834164685913813)

julia> sol(1.0)
(0.9504152802553114, 0.9834164685913813)

julia> sol = solve(prob, SofSpa10(), dt=0.001);

julia> sol(1.0)
(0.9980287849980085, 0.03937199652442939)

from diffeqphysics.jl.

ChrisRackauckas avatar ChrisRackauckas commented on June 7, 2024

Try another integrator? Maybe there's an issue there. Is prob.f what you'd expect?

from diffeqphysics.jl.

KlausC avatar KlausC commented on June 7, 2024

Is prob.f what you'd expect?

That looks fine.

julia> prob.f
(::DynamicalODEFunction{false,ODEFunction{false,DiffEqPhysics.var"#3#7"{typeof(H),Float64},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},ODEFunction{false,DiffEqPhysics.var"#5#9"{typeof(H),Float64},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing}) (generic function with 2 methods)

julia> prob.f.f1(p0, q0, nothing, 0.0)
0.0

julia> prob.f.f2(p0, q0, nothing, 0.0)
0.1

from diffeqphysics.jl.

KlausC avatar KlausC commented on June 7, 2024

Try another integrator?

That one worked as expected:

julia> sol = solve(prob, Tsit5(), dt=0.001);

julia> sol(1.0)
(1.0, 0.09999999999999959)

from diffeqphysics.jl.

KlausC avatar KlausC commented on June 7, 2024

Another one again fails:


julia> sol = solve(prob, KahanLi6(), dt=0.001);

julia> sol(1.0)
(1.0, 0.27647264980326564)

from diffeqphysics.jl.

ChrisRackauckas avatar ChrisRackauckas commented on June 7, 2024

Are you sure the definition of f isn't flipped? #58 might've been wrong.

from diffeqphysics.jl.

KlausC avatar KlausC commented on June 7, 2024

What do you mean? I will x-check #58 - there was no intention to change any logic there.

from diffeqphysics.jl.

KlausC avatar KlausC commented on June 7, 2024

No changes except (v,x,p) was renamed to (p,q,param) consistently.
I will repeat my experiments with the older release...

from diffeqphysics.jl.

KlausC avatar KlausC commented on June 7, 2024

I use now the pre#58 releases

julia> VERSION
v"1.5.3"
(tmp) pkg> st
Status `/tmp/Project.toml`
  [055956cb] DiffEqPhysics v3.7.0
  [0c46a032] DifferentialEquations v6.16.0

and there is no difference in the results.

from diffeqphysics.jl.

KlausC avatar KlausC commented on June 7, 2024

When I go back more than a year, using the default algo now produces a correct result, but the other algorithms produce exactly the same false results (except of Tsit5, which remains correct).

julia> VERSION
v"1.3.1"

(tmp) pkg> st
    Status `/tmp/Project.toml`
  [055956cb] DiffEqPhysics v3.2.0
  [0c46a032] DifferentialEquations v6.0.0

from diffeqphysics.jl.

ChrisRackauckas avatar ChrisRackauckas commented on June 7, 2024

I think somewhere along the lines the definition flipped the order of the equations and it's now incorrect in this library. Somehow our tests didn't catch that...

from diffeqphysics.jl.

KlausC avatar KlausC commented on June 7, 2024

I will take me the time to investigate and keep you informed.

from diffeqphysics.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.