SciML / SciML/DiffEqCallbacks.jl

ManifoldProjection and complex numbers

Open
#220 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Julia
Stars
100
Forks
54
Avg merge
3h 29m
Merged PRs (30d)
8

Description

Question❓
Please bear with me I am not an experienced programmer and I might be doing something silly.

I am trying to integrate
p = 200.0
function psi(du,u,p,t)
du[1] = -im * p * u[1]
du[2] = -im * p * u[2]
end

function g(u,resid)
resid[1] = abs(sol.u[1]) - 1
resid[2] = abs(sol.u[2]) - 1
end

cb = ManifoldProjection(g)

sol = solve(prob,callback = cb)
and I get

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/PcZ48/src/dual.jl:41
[2] ForwardDiff.Dual{ForwardDiff.Tag{DiffEqCallbacks.NonAutonomousFunction{typeof(g), false}, ComplexF64}, ComplexF64, 2}(value::ComplexF64, partials::ForwardDiff.Partials{2, ComplexF64})

After many web-searches it seems to me that this is an old problem since 2018. My question is motivated by the stochastic Schroedinger equation where one needs an efficient integrator capable of preserving the norm of a complex vector for ensemble simulations.
Many thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ManifoldProjection callback and reproduce the example using complex-valued states. Inspect the ForwardDiff dual-creation failure reported at dual.jl:41, then establish whether complex vectors are supported and add or update coverage for the intended behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.