Error in coimputing CdagupCup_{at site 1}

Hi, I am trying to execute the following code:
using ITensors, ITensorMPS

function main(; Nx=2, Ny=2, U=4.0, t=1.0)
N = Nx * Ny

cutoff = [1E-8]


sites = siteinds("Electron", N; conserve_qns=true)



# Half filling
state = [isodd(n) ? "Up" : "Dn" for n in 1:N]

# Initialize wavefunction to a random MPS
# of bond-dimension 10 with same quantum
# numbers as `state`
psi = random_mps(sites, state)


Sz1 = op("Cup", sites[1])

Sz2 = op("Cdagup", sites[1])


Stot = Sz1 * Sz2


psi = apply(Sz1, psi; cutoff)
psi0 = apply(Sz2, psi; cutoff)

Sz = inner(psi, psi0)

println(Sz)



return nothing

end

main()
But I am getting the following error:
ERROR: LoadError: Attempting to contract IndexSet:

((dim=4|id=868|“Electron,Site,n=1”)’
1: QN((“Nf”,0,-1),(“Sz”,0)) => 1
2: QN((“Nf”,1,-1),(“Sz”,1)) => 1
3: QN((“Nf”,1,-1),(“Sz”,-1)) => 1
4: QN((“Nf”,2,-1),(“Sz”,0)) => 1, (dim=4|id=868|“Electron,Site,n=1”)
1: QN((“Nf”,0,-1),(“Sz”,0)) => 1
2: QN((“Nf”,1,-1),(“Sz”,1)) => 1
3: QN((“Nf”,1,-1),(“Sz”,-1)) => 1
4: QN((“Nf”,2,-1),(“Sz”,0)) => 1)

with IndexSet:

((dim=4|id=868|“Electron,Site,n=1”)’
1: QN((“Nf”,0,-1),(“Sz”,0)) => 1
2: QN((“Nf”,1,-1),(“Sz”,1)) => 1
3: QN((“Nf”,1,-1),(“Sz”,-1)) => 1
4: QN((“Nf”,2,-1),(“Sz”,0)) => 1, (dim=4|id=868|“Electron,Site,n=1”)
1: QN((“Nf”,0,-1),(“Sz”,0)) => 1
2: QN((“Nf”,1,-1),(“Sz”,1)) => 1
3: QN((“Nf”,1,-1),(“Sz”,-1)) => 1
4: QN((“Nf”,2,-1),(“Sz”,0)) => 1)

QN indices must have opposite direction to contract, but indices:

(dim=4|id=868|“Electron,Site,n=1”)’
1: QN((“Nf”,0,-1),(“Sz”,0)) => 1
2: QN((“Nf”,1,-1),(“Sz”,1)) => 1
3: QN((“Nf”,1,-1),(“Sz”,-1)) => 1
4: QN((“Nf”,2,-1),(“Sz”,0)) => 1

and:

(dim=4|id=868|“Electron,Site,n=1”)’
1: QN((“Nf”,0,-1),(“Sz”,0)) => 1
2: QN((“Nf”,1,-1),(“Sz”,1)) => 1
3: QN((“Nf”,1,-1),(“Sz”,-1)) => 1
4: QN((“Nf”,2,-1),(“Sz”,0)) => 1

do not have opposite directions.
On a related note, I am littile bit confused what this and mean?

The message on the last line should be: On a related note, I am a little bit confused about what and mean.

The error is coming from the line Stot = Sz1 * Sz2. There, you are trying to contract entirely two tensors, which doesn’t make particular sense here because their arrows (of their indices or legs) are the same direction (remember that * will try to contract matching indices and Sz1 and Sz2 have the exact same indices)

The error is saying that you have block sparse tensors where the indices do not match in a way to allow it to contract, with one “in” and one “out”. See the ITensors.jl paper pages around 26-27, where you see that the arrows have to align on indices , which is generally done with dag

Also, to create that object you can instead do op("Cdagup * Cup",sites[1]) if on the same site. And a warning, when using op with Fermionic operators you’ll need to take into account the Jordan-Wigner strings yourself.

Thank you so much for the response!!!