Errors in TDVP function

Hey all,

I am trying to implement the TDVP function, and I get some weird error that I couldn’t figure out what is the reason.

Basically, I am trying the develop in imaginary time the following wave function

|\psi_0 \rangle = |0...0\rangle \\ |\psi \rangle= \frac{e^{-\beta H}|\psi_0 \rangle}{ |\langle \psi| \psi \rangle|}

And for some reason I am getting a “InexactError”.
Can someone help me out understand this ?

some example:

n=3 
site=siteinds("Qubit",n)
psi=MPS(site, n->"Up")
tau=0.1 
for I=1:20
    psi=tdvp(H_bath,psi,-τ;cutoff=1e-28)
    normalize!(psi)
end

H is some Hamiltonian that describes long-ranged interactions.

For local Hamiltonian there is no error.

I will also add the error in case it will help…
Thanks a lot in advance!

The error is:

ERROR: LoadError: InexactError: Float64(0.5734939687060105 + 2.90389650522495e-17im)
Stacktrace:
  [1] Real
    @ ./complex.jl:44 [inlined]
  [2] convert
    @ ./number.jl:7 [inlined]
  [3] setindex!(::Matrix{Float64}, ::ComplexF64, ::Int64, ::Int64)
    @ Base ./array.jl:905
  [4] applyexp(H::ProjMPO, tau::Float64, x0::ITensor; kwargs::Base.Pairs{Symbol, Real, NTuple{4, Symbol}, NamedTuple{(:tol, :maxiter, :outputlevel, :current_time), Tuple{Float64, Int64, Int64, Float64}}})
    @ ITensorTDVP ~/.julia/packages/ITensorTDVP/c3OYY/src/applyexp.jl:54
  [5] (::ITensorTDVP.var"#solver#38"{ITensorTDVP.var"#solver#37#39"{Base.Pairs{Symbol, Float64, Tuple{Symbol}, NamedTuple{(:cutoff,), Tuple{Float64}}}}})(H::ProjMPO, t::Float64, psi0::ITensor; kws::Base.Pairs{Symbol, Real, Tuple{Symbol, Symbol}, NamedTuple{(:current_time, :outputlevel), Tuple{Float64, Int64}}})
    @ ITensorTDVP ~/.julia/packages/ITensorTDVP/c3OYY/src/tdvp.jl:27
  [6] tdvp_site_update!(nsite_val::Val{2}, reverse_step_val::Val{true}, solver::ITensorTDVP.var"#solver#38"{ITensorTDVP.var"#solver#37#39"{Base.Pairs{Symbol, Float64, Tuple{Symbol}, NamedTuple{(:cutoff,), Tuple{Float64}}}}}, PH::ProjMPO, psi::MPS, b::Int64; current_time::Float64, outputlevel::Int64, time_step::Float64, normalize::Bool, direction::Base.Order.ForwardOrdering, noise::Float64, which_decomp::Nothing, svd_alg::String, cutoff::Float64, maxdim::Int64, mindim::Int64, maxtruncerr::Float64)
    @ ITensorTDVP ~/.julia/packages/ITensorTDVP/c3OYY/src/tdvp_step.jl:356
  [7] tdvp_site_update!(solver::ITensorTDVP.var"#solver#38"{ITensorTDVP.var"#solver#37#39"{Base.Pairs{Symbol, Float64, Tuple{Symbol}, NamedTuple{(:cutoff,), Tuple{Float64}}}}}, PH::ProjMPO, psi::MPS, b::Int64; nsite::Int64, reverse_step::Bool, current_time::Float64, outputlevel::Int64, time_step::Float64, normalize::Bool, direction::Base.Order.ForwardOrdering, noise::Float64, which_decomp::Nothing, svd_alg::String, cutoff::Float64, maxdim::Int64, mindim::Int64, maxtruncerr::Float64)
    @ ITensorTDVP ~/.julia/packages/ITensorTDVP/c3OYY/src/tdvp_step.jl:157
  [8] tdvp_sweep(direction::Base.Order.ForwardOrdering, solver::Function, PH::ProjMPO, time_step::Float64, psi::MPS; kwargs::Base.Pairs{Symbol, Real, NTuple{7, Symbol}, NamedTuple{(:current_time, :cutoff, :reverse_step, :sweep, :maxdim, :mindim, :noise), Tuple{Float64, Float64, Bool, Int64, Int64, Int64, Float64}}})
    @ ITensorTDVP ~/.julia/packages/ITensorTDVP/c3OYY/src/tdvp_step.jl:80
  [9] tdvp_step(order::ITensorTDVP.TDVPOrder{2, Base.Order.ForwardOrdering()}, solver::Function, PH::ProjMPO, time_step::Float64, psi::MPS; current_time::Float64, kwargs::Base.Pairs{Symbol, Real, NTuple{6, Symbol}, NamedTuple{(:cutoff, :reverse_step, :sweep, :maxdim, :mindim, :noise), Tuple{Float64, Bool, Int64, Int64, Int64, Float64}}})
    @ ITensorTDVP ~/.julia/packages/ITensorTDVP/c3OYY/src/tdvp_step.jl:9
 [10] macro expansion
    @ ~/.julia/packages/ITensorTDVP/c3OYY/src/tdvp_generic.jl:84 [inlined]
 [11] macro expansion
    @ ./timing.jl:299 [inlined]
 [12] tdvp(solver::Function, PH::ProjMPO, t::Float64, psi0::MPS; kwargs::Base.Pairs{Symbol, Float64, Tuple{Symbol}, NamedTuple{(:cutoff,), Tuple{Float64}}})
    @ ITensorTDVP ~/.julia/packages/ITensorTDVP/c3OYY/src/tdvp_generic.jl:83
 [13] tdvp(solver::Function, H::MPO, t::Float64, psi0::MPS; kwargs::Base.Pairs{Symbol, Float64, Tuple{Symbol}, NamedTuple{(:cutoff,), Tuple{Float64}}})
    @ ITensorTDVP ~/.julia/packages/ITensorTDVP/c3OYY/src/tdvp_generic.jl:150
 [14] tdvp(H::MPO, t::Float64, psi0::MPS; kwargs::Base.Pairs{Symbol, Float64, Tuple{Symbol}, NamedTuple{(:cutoff,), Tuple{Float64}}})
    @ ITensorTDVP ~/.julia/packages/ITensorTDVP/c3OYY/src/tdvp.jl:47
 [15] #tdvp#43
    @ ~/.julia/packages/ITensorTDVP/c3OYY/src/tdvp.jl:55 [inlined]
 [16] top-level scope
    @ ~/Desktop/projects/Density_matrix/Decoherence/Energy_density.jl:72
in expression starting at /home/Tomer/Desktop/projects/Density_matrix/Decoherence/Energy_density.jl:70

Is the Hamiltonian complex?

Hey,
No.
If you wish I can share it here

Yeah, please share a full minimal example that reproduces that bug. It’s not clear to me why a complex number would be showing up, it may be an issue with the applyexp solver backend. As an alternative you could try the exponentiate backend, which makes use of KrylovKit.jl, by passing the keyword argument solver_backend="exponentiate".

Hey,
Sorry for the mistake. The Hamiltonian includes the “Sy” operator, but when I applied only “Sy”, it did not printed an error.

The Hamiltonian:

    J=randn(n,n,3,3)
    os = OpSum()
    A = ["Sx", "Sy", "Sz"]
    for j in 1:n-1
        for i in j+1:n
            for α in 1:3
                for β in 1:3
                    os += J[i,j,α,β], A[α], i, A[β], j
                end
            end
        end
    end
    H_syk = MPO(os, site)

I hope it will help.

I think here it might solve your problem to rewrite your Hamiltonian in terms of the “S+” and “S-” operators instead of “Sy” and “Sx”. This is because “S+” and “S-” are real-valued so you would not encounter any complex numbers that way.

Hey miles!
thank you for your comment. I will try that

Related issue: Fix complex issue in applyexp solver · Issue #49 · ITensor/ITensorTDVP.jl · GitHub and discourse thread: tdvp time developing

When it rains, it pours: TDVP for a Hamiltonian with complex parameters

@miles we should probably just change the default backend to "exponentiate".

I have been met the problem, and you just need a command to solve it, i.e,

MPS(ComplexF64, s)

1 Like