# errors in correlator function for custom itensor operator

**URL:** <https://itensor.discourse.group/t/errors-in-correlator-function-for-custom-itensor-operator/1119>\
**Category:** ITensor Julia Questions\
**Created:** [August 28, 2023, 8:40am UTC](https://itensor.discourse.group/t/errors-in-correlator-function-for-custom-itensor-operator/1119 "2023-08-28T08:40:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luckyzy](https://avatars.discourse-cdn.com/v4/letter/l/a5b964/32.png) [@luckyzy](https://itensor.discourse.group/u/luckyzy)\
**Post date:** [August 28, 2023, 8:40am UTC](https://itensor.discourse.group/t/errors-in-correlator-function-for-custom-itensor-operator/1119/1 "2023-08-28T08:40:22Z")

</div>

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

```auto
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

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

```

But I get a following error:

```auto
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

```auto
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

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [August 28, 2023, 1:49pm UTC](https://itensor.discourse.group/t/errors-in-correlator-function-for-custom-itensor-operator/1119/2 "2023-08-28T13:49:00Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![luckyzy](https://avatars.discourse-cdn.com/v4/letter/l/a5b964/32.png) [@luckyzy](https://itensor.discourse.group/u/luckyzy)\
**Post date:** [August 28, 2023, 2:04pm UTC](https://itensor.discourse.group/t/errors-in-correlator-function-for-custom-itensor-operator/1119/3 "2023-08-28T14:04:51Z")

</div>

Thank you so much, that is work!
