Issue with Complex DifferentialEquations

Dear Julia community,

bellow you can find the function of interest:

using DifferentialEquations
using OMEinsum
using LinearAlgebra
function ctwa!(du::Matrix{ComplexF64}, u::Matrix{ComplexF64}, 
               par::Tuple{Matrix{Float64}, Array{Float64, 4}, Array{ComplexF64, 3}}, 
               t::Float64)
    @views B_eff, J_eff, Tab = par
   
    # Tab     :  d, D    , D
    # B_eff   :  d, Nc
    # J_eff   :  d, d, Nc, Nc
    # u shape :  Nc   , D   
    uConj = conj(u)

    @ein BTy[i,a]    := B_eff[β,i]     * Tab[β,a,b] * u[i,b]
    @ein JTTyyy[i,a] := J_eff[β,γ,i,j] * Tab[β,a,b] * Tab[γ,c,d] * u[i,b] * uConj[j,c] * u[j,d]
    @views du        .= -im * (BTy + JTTyyy)
end 


prob = ODEProblem(ctwa!, y0, (TMIN,TMAX), par)
sol  = solve( prob , AutoTsit5(Rosenbrock23()), alg_hints=[:stiff], 
                    saveat=TIMEPOINTS, verbose=true)

Unfortunately, I am getting a long error message, which I just pasted a few lines bellow:

ERROR: LoadError: ArgumentError: Cannot create a dual over scalar type ComplexF64. If the type behaves as a scalar, define ForwardDiff.can_dual(::Type{ComplexF64}) = true.

Stacktrace:

[1] throw_cannot_dual(V::Type)

@ ForwardDiff ~/.julia/packages/ForwardDiff/vXysl/src/dual.jl:41

[2] ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, ComplexF64}, ComplexF64, 1}(value::ComplexF64, partials::ForwardDiff.Partials{1, ComplexF64})

@ ForwardDiff ~/.julia/packages/ForwardDiff/vXysl/src/dual.jl:18

<<<

Any help would be greatly appreciated.
JV

ForwardDiff has some issues with complex. Do:

sol  = solve( prob , AutoTsit5(Rosenbrock23(autodiff=false)), alg_hints=[:stiff], 
                    saveat=TIMEPOINTS, verbose=true)
1 Like

Many thanks, it worked well.