Method Error: No mathching method when using ContinuousDynamicalSystem

Hi everyone,
I’m very new to Julia and trying to wrap my head around the following error. This is a stripped-down version of the ODE I am trying to wrap as a Continuous Dynamical System.

using DifferentialEquations
using ChaosTools

@inline @inbounds function ODE(dy, y, p, t)
    alpha = p
    gamma = alpha * t

    dy[1] = -1im * (-y[2]  +gamma*y[1] )
    dy[2] = -1im * (-(y[1]+y[3]) )
    dy[3] = -1im * (-y[2]  - gamma*y[3] )

    return SVector{3}(dy[1],dy[2],dy[3])
end

p = [0] 

y0=[ -0.9950737714883371,
 -0.09901475429766803,
 -0.004926228511662883]

ds=ContinuousDynamicalSystem(ODE,y0,p)

However, this produces the following error message

LoadError: MethodError: no method matching +(::ForwardDiff.Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#13#20"{Array{Float64,1},Float64,typeof(ODE)},Float64},Float64,3}, ::Array{ForwardDiff.Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#13#20"{Array{Float64,1},Float64,typeof(ODE)},Float64},Float64,3},1})
For element-wise addition, use broadcasting with dot syntax: scalar .+ array
Closest candidates are:
  +(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:538
  +(!Matched::ChainRulesCore.DoesNotExist, ::Any) at /Users/garymccormack/.julia/packages/ChainRulesCore/cpHLu/src/differential_arithmetic.jl:23
  +(!Matched::ChainRulesCore.One, ::Any) at /Users/garymccormack/.julia/packages/ChainRulesCore/cpHLu/src/differential_arithmetic.jl:94
  ...
in expression starting at /Users/garymccormack/OneDrive - The University of Nottingham/ExtendedBoseHubbard/TripleWell/longrange/LyapunovExp/Lyap_RydDress.jl:45
ODE at Lyap_RydDress.jl:19 [inlined]
(::DynamicalSystemsBase.var"#13#20"{Array{Float64,1},Float64,typeof(ODE)})(::StaticArrays.SArray{Tuple{3},ForwardDiff.Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#13#20"{Array{Float64,1},Float64,typeof(ODE)},Float64},Float64,3},1,3}) at dynamicalsystem.jl:313
static_dual_eval at apiutils.jl:32 [inlined]
vector_mode_jacobian at jacobian.jl:178 [inlined]
jacobian at jacobian.jl:85 [inlined]
(::DynamicalSystemsBase.var"#12#19"{typeof(ODE)})(::StaticArrays.SArray{Tuple{3},Float64,1,3}, ::Array{Float64,1}, ::Float64) at dynamicalsystem.jl:312
get_J(::DynamicalSystemsBase.var"#12#19"{typeof(ODE)}, ::StaticArrays.SArray{Tuple{3},Float64,1,3}, ::Array{Float64,1}, ::Float64, ::Bool) at dynamicalsystem.jl:324
ContinuousDynamicalSystem(::Function, ::Array{Float64,1}, ::Array{Float64,1}; t0::Float64) at dynamicalsystem.jl:243
ContinuousDynamicalSystem(::Function, ::Array{Float64,1}, ::Array{Float64,1}) at dynamicalsystem.jl:231
top-level scope at Lyap_RydDress.jl:45
include_string(::Function, ::Module, ::String, ::String) at loading.jl:1088

I’m still learning how to read error messages from Julia and I’m struggling big time with this!
I think it may have something to do with the ODE being a complex ODE, but I’m not sure…
Would anyone be able to help me out?
Thanks in advance :slight_smile:

Your initial condition should be complex numbers if your numbers are eventually complex.

Hi Chris, thanks for the quick reply.
I’ve included the line

y0=complex(y0)

however now it raises an Argument Error

ERROR: LoadError: ArgumentError: Cannot create a dual over scalar type Complex{Float64}. If the type behaves as a scalar, define FowardDiff.can_dual.
Stacktrace:
 [1] throw_cannot_dual(::Type{T} where T) at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/dual.jl:36
 [2] ForwardDiff.Dual{ForwardDiff.Tag{DynamicalSystemsBase.var"#13#20"{Array{Float64,1},Complex{Float64},typeof(ODE)},Complex{Float64}},Complex{Float64},3}(::Complex{Float64}, ::ForwardDiff.Partials{3,Complex{Float64}}) at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/dual.jl:18
 [3] Dual at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/dual.jl:55 [inlined]
 [4] Dual at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/dual.jl:67 [inlined]
 [5] macro expansion at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/apiutils.jl:28 [inlined]
 [6] dualize at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/apiutils.jl:21 [inlined]
 [7] static_dual_eval at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/apiutils.jl:32 [inlined]
 [8] vector_mode_jacobian at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/jacobian.jl:178 [inlined]
 [9] jacobian at /Users/garymccormack/.julia/packages/ForwardDiff/qTmqf/src/jacobian.jl:85 [inlined]
 [10] (::DynamicalSystemsBase.var"#12#19"{typeof(ODE)})(::StaticArrays.SArray{Tuple{3},Complex{Float64},1,3}, ::Array{Float64,1}, ::Complex{Float64}) at /Users/garymccormack/.julia/packages/DynamicalSystemsBase/dkA8o/src/dynamicalsystem.jl:312
 [11] get_J(::DynamicalSystemsBase.var"#12#19"{typeof(ODE)}, ::StaticArrays.SArray{Tuple{3},Complex{Float64},1,3}, ::Array{Float64,1}, ::Complex{Float64}, ::Bool) at /Users/garymccormack/.julia/packages/DynamicalSystemsBase/dkA8o/src/dynamicalsystem.jl:324
 [12] ContinuousDynamicalSystem(::Function, ::Array{Complex{Float64},1}, ::Array{Float64,1}; t0::Float64) at /Users/garymccormack/.julia/packages/DynamicalSystemsBase/dkA8o/src/dynamicalsystem.jl:243
 [13] ContinuousDynamicalSystem(::Function, ::Array{Complex{Float64},1}, ::Array{Float64,1}) at /Users/garymccormack/.julia/packages/DynamicalSystemsBase/dkA8o/src/dynamicalsystem.jl:231
 [14] top-level scope at /Users/garymccormack/OneDrive - The University of Nottingham/ExtendedBoseHubbard/TripleWell/longrange/LyapunovExp/Lyap_RydDress.jl:46
 [15] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1088
in expression starting at /Users/garymccormack/OneDrive - The University of Nottingham/ExtendedBoseHubbard/TripleWell/longrange/LyapunovExp/Lyap_RydDress.jl:46

Double check: is this fine using DifferentialEquations.jl directly instead of through DynamicalSystems.jl?

If I was to solve the differential equations directly I would use

prob = ODEProblem(ODE, collect(Complex{Float64}, y0), tspan, p)

where tspan is defined as(0,20)

This produces no errors and I have gotten nice results from it :).
However, I’m trying to encapsulate the ODE as a Continuous Dynamical system to perform a Lyapunov spectrum analysis on the system, which is where I’m getting the original errors from.

This is a problem for @Datseris

1 Like

Hi, thanks a lot for the tag Chris. @Gary_McCormack could please be so kind to open an issue with this code in DynamicalSystemsBase.jl ? I’ll have a look when I have some extra free time :slight_smile:

However, I’m trying to encapsulate the ODE as a Continuous Dynamical system to perform a Lyapunov spectrum analysis on the system, which is where I’m getting the original errors from.

This will not work with the algorithm for the Lyapunov exponents. You have to separate the real and imaginary parts, as your system is 6-dimensional, not 3-dimensional, given that all components are complex numbers. The Lyapunov exponents operate on the full state space and you have to resolve its dimensionality fully.

Re-write your equations so that you have 6 real numbers as variables and it will work.

In dynamical systems we assume that the dimensionality of the state space is length(u0).