errors in correlator function for custom itensor operator

Hi everyone
I am trying to simulate a correlation function of multiple sites. The custom itensor operators I defined are:

d=3;
function ITensors.op(::OpName"exp2N", ::SiteType"Qudit", d::Int; m=1) 
  M = zeros(d,d)
  M[m,m] = exp(2*pi*2*im/L)
  return M
end
function ITensors.op(::OpName"exp3N", ::SiteType"Qudit", d::Int; m=1)
  M = zeros(d,d)
  M[m,m] = exp(2*pi*3*im/L)
  return M
end
function ITensors.op(::OpName"exp4N", ::SiteType"Qudit", d::Int; m=1)
  M = zeros(d,d)
  M[m,m] = exp(2*pi*4*im/L)
  return M
end

then I want to calculate the correlation function

c = correlator(psio, ("exp2N", "exp3N","exp4N"), [(1, 2, 3)])

But I get a following error:

ERROR: InexactError: Float64(0.30901699437494745 + 0.9510565162951535im)
Stacktrace:

Real at .\complex.jl

convert(#unused#::Type{Float64}, x::ComplexF64) at .\number.jl

setindex! at .\array.jl

op(::OpName{:exp2N}, ::SiteType{Qudit}, d::Int64; m::Int64) at c:\Users\lenovo\Desktop\code\test.jl

op at c:\Users\lenovo\Desktop\code\test.jl

#op#1163 at C:\Users\lenovo.julia\packages\ITensors\xUMVS\src\physics\site_types\qudit.jl

op(::OpName{:exp2N}, ::SiteType{Qudit}, ::Index{Int64}) at C:\Users\lenovo.julia\packages\ITensors\xUMVS\src\physics\site_types\qudit.jl

op(name::String, s::Index{Int64}; adjoint::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) at C:\Users\lenovo.julia\packages\ITensors\xUMVS\src\physics\sitetype.jl

op(name::String, s::Index{Int64}) at C:\Users\lenovo.julia\packages\ITensors\xUMVS\src\physics\sitetype.jl

add_operator_fermi(op_inds::Vector{Int64}, sites_ind_prev::Vector{Tuple{Int64, Int64}}, L_prev::ITensor, counter::Int64, element::Vector{Int64}, N::Int64, ops::Tuple{String, String}, s::Vector{Index{Int64}}, ln::Vector{Index{Int64}}, psi::MPS, psi_dag::MPS, C::Dict{Tuple{Vararg{Int64}}, ComplexF64}, indices::Tuple{Int64, Int64}, jw::Int64) at C:\Users\lenovo.julia\packages\ITensorCorrelators\RHiLU\src\correlator_bosonic_recursive.jl

correlator_recursive_compact(psi::MPS, ops::Tuple{String, String}, sites::Vector{Tuple{Int64, Int64}}; indices::Tuple{Int64, Int64}) at C:\Users\lenovo.julia\packages\ITensorCorrelators\RHiLU\src\correlator_bosonic_recursive.jl

kwcall(::NamedTuple{(:indices,), Tuple{Tuple{Int64, Int64}}}, ::typeof(ITensorCorrelators.correlator_recursive_compact), psi::MPS, ops::Tuple{String, String}, sites::Vector{Tuple{Int64, Int64}}) at C:\Users\lenovo.julia\packages\ITensorCorrelators\RHiLU\src\correlator_bosonic_recursive.jl

correlator(psi::MPS, cor_ops::Tuple{String, String}, op_sites::Vector{Tuple{Int64, Int64}}) at C:\Users\lenovo.julia\packages\ITensorCorrelators\RHiLU\src\ITensorCorrelators.jl

top-level scope at c:\Users\lenovo\Desktop\code\test.jl

I have try to use

c = correlator(complex(psio), ("exp2N", "exp3N","exp4N"), [(1, 2, 3)])

but it was not work. Do you have any idea why this occurs?
Thanks in advance for any help,
Yuanyu

You should change your definitions from zeros(d, d) to zeros(ComplexF64, d, d). zeros(d, d) implicitly makes a matrix of real values of type Float64.

1 Like

Thank you so much, that is work!