qojulia / QuantumOptics.jl

Library for the numerical simulation of closed as well as open quantum systems.
http://qojulia.org
Other
533 stars 104 forks source link

Inexact error Complex -> Float with MCWF jumps #335

Closed leostenzel closed 2 years ago

leostenzel commented 2 years ago

Hi, came across an inexact error simulating with mcwf_dynamic;

I think in this line I get very small imaginary parts from dot(psi_new.data, psi_new.data) https://github.com/qojulia/QuantumOptics.jl/blob/b2618ee33c9639617bcba11add5484052efa552b/src/mcwf.jl#L397

Defining a more forgiving conversion seems to solve all issues: Base.convert(::Type{T}, x::Complex) where {T<:AbstractFloat} = abs(imag(x)) < 1e-16 ? T(real(x)) : throw(InexactError(nameof(T), T, x))

But taking the real part, or the norm instead of dot is probably more efficient.

I've put together a small example Pluto notebook, but seems l can only upload the pdf: 🎈 kpo_mcwf_mwe.jl — Pluto.jl.pdf

david-pl commented 2 years ago

@leostenzel you're right, there should be a real there. I've opened a PR.