USCqserver / OpenQuantumBase.jl

Abstract types and math operations for OpenQuantumTools.jl.
https://uscqserver.github.io/OpenQuantumTools.jl/stable/
MIT License
7 stars 2 forks source link

ame_jump with InexactError due to rounding #95

Closed jsmarsha11 closed 1 year ago

jsmarsha11 commented 1 year ago

I find occasionally when using the AME trajectories solver of HOQST that ame_jump fails with an error, such as

ERROR: LoadError: InexactError: Float64(8.106524306056477e-5 + 8.561864539050956e-22im) Stacktrace: [1] Real @ ./complex.jl:44 [inlined] [2] convert @ ./number.jl:7 [inlined] [3] setindex!(A::Vector{Float64}, x::ComplexF64, i1::Int64) @ Base ./array.jl:966 [4] ame_jump(D::OpenQuantumBase.DaviesGenerator, u::Vector{ComplexF64}, gap_idx::OpenQuantumBase.GapIndices, v::Matrix{ComplexF64}, s::Float64) @ OpenQuantumBase ~/.julia/packages/OpenQuantumBase/O2ct0/src/opensys/trajectory_jump.jl:44 [5] (::OpenQuantumBase.var"#271#272"{Vector{ComplexF64}, OpenQuantumBase.GapIndices, Matrix{ComplexF64}, Float64})(x::OpenQuantumBase.DaviesGenerator) @ OpenQuantumBase ./none:0

The line in question is 44 (prob[idx] = g0 * (ϕ' * ϕ)) in the file src/opensys/trajectory_jump.jl. I suggest wrapping the RHS (as in line 30) in real or a simple real_if_close function (i.e. one which will return the real part if it is close enough to a real to some tolerance). I made the change locally and it seems to have fixed things for me. I can make a PR, but it's quite an easy fix really :)

neversakura commented 1 year ago

Thanks. I will get it fixed.