# correlation matrix of complex operators

**URL:** <https://itensor.discourse.group/t/correlation-matrix-of-complex-operators/584>\
**Category:** DMRG and Numerical Methods\
**Tags:** julia, dmrg\
**Created:** [January 9, 2023, 1:56pm UTC](https://itensor.discourse.group/t/correlation-matrix-of-complex-operators/584 "2023-01-09T13:56:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tymek](https://avatars.discourse-cdn.com/v4/letter/t/b487fb/32.png) [@tymek](https://itensor.discourse.group/u/tymek)\
**Post date:** [January 9, 2023, 1:56pm UTC](https://itensor.discourse.group/t/correlation-matrix-of-complex-operators/584/1 "2023-01-09T13:56:10Z")

</div>

Hello,  
this is my first post so forgive me all the mistakes. I am reaching out to you because since installing julia\_1.8 the correlation matrix i defined, does not work.

First I define a Sx operator:

```julia
function ITensors.op(::OpName"Sy", ::SiteType"Electron", s1::Index) 
    
    S_y = (op("S+", s1) - op("S-", s1))/(2im);
    return S_y
end

```

and then I want to calculate a correlation matrix

```julia
N = 6;
Ne=N;
sites = siteinds("Electron", 2*N, conserve_qns=true);

states = ["0" for n=1:2*N];
for n in 1:trunc(Int,Ne/2.0)
     states[n] = "Up";
end

for n in trunc(Int,Ne/2.0)+1:Ne
     states[n] = "Dn";
end
shuffle!(states);
psi0 = randomMPS(sites,states);

fincorr = correlation_matrix(psi0,"Sy","Sy");

```

But I get a following error: `InexactError: Float64(0.0 - 0.5im) ` which refers to the complex value of the `S_y` operator.

Do you have any idea why this occurs? And is there a way to by-pass it? I am pretty sure my code worked before on older julia’s version.

Thanks in advance for any help,  
Tymek

---

<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:** [January 9, 2023, 2:34pm UTC](https://itensor.discourse.group/t/correlation-matrix-of-complex-operators/584/2 "2023-01-09T14:34:03Z")

</div>

Hi, thanks for the report, this is related to a known issue: [[ITensors] [BUG] Can't measure complex operator on real MPS in expect · Issue #1019 · ITensor/ITensors.jl · GitHub](https://github.com/ITensor/ITensors.jl/issues/1019).

For now, it should work if you use `correlation_matrix(complex(psi0), "Sy", "Sy")`.
