Sorry for not describing this clearly. My problem is also about Sx and Sy. I have a spin Hamiltonian in the form: \sum_ j { A(S+_j S-_j+1 + S-_j S+_j+1) + B(Sz_j Sz_j+1 - C), you know just a regular 1D spin 1/2 model. Then I calculated the ground state of it, and just want to print <Sx>, <Sy>, <Sz> at each site with the ground state. So after I get the ground state, I tried the following. But it only works when I only have Sz, and gave error message when including Sx and Sy. ( I attach the error message at the end, sorry it's a bit long...) I'm not sure if it's due to same issue, so just want to try this command "ITensor Sxb = sites.op(“Sx”,b);" in julia version...

Code:

sx1 = fill(0.0, N)

sy1 = fill(0.0, N)

sz1 = fill(0.0, N)

for j in 1:N

orthogonalize!(psi1, j)

psidag1_j = dag(prime(psi1[j], "Site"))

sx1[j] = scalar(psidag1_j * op(sites,"Sx",j) * psi1[j])

sy1[j] = scalar(psidag1_j * op(sites,"Sy",j) * psi1[j])

sz1[j] = scalar(psidag1_j * op(sites,"Sz",j) * psi1[j])

end

println("Sz:")

for j in 1:N

println("$(sz1[j])")

end

println()

println("Sx:")

for j in 1:N

println("$(sx1[j])")

end

println()

println("Sy:")

for j in 1:N

println("$(sy1[j])")

end

println()

ERROR: LoadError: In `setindex!`, the element (1, 2) of ITensor:

Dim 1: (dim=2|id=808|"S=1/2,Site,n=1")' <Out>

1: QN("Sz",1) => 1

2: QN("Sz",-1) => 1

Dim 2: (dim=2|id=808|"S=1/2,Site,n=1") <In>

1: QN("Sz",1) => 1

2: QN("Sz",-1) => 1

NDTensors.BlockSparse{Float64, Vector{Float64}, 2}

2×2

Block(2, 1)

[2:2, 1:1]

0.5

you are trying to set is in a block with flux QN("Sz",2), which is different from the flux QN("Sz",-2) of the other blocks of the ITensor. You may be trying to create an ITensor that does not have a well defined quantum number flux.

Stacktrace:

[1] error(s::String)

@ Base ./error.jl:33

[2] _setindex!!(::ITensors.HasQNs, ::NDTensors.BlockSparseTensor{Float64, 2, Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}, NDTensors.BlockSparse{Float64, Vector{Float64}, 2}}, ::Float64, ::Int64, ::Int64)

@ ITensors ~/.julia/packages/ITensors/5sSxp/src/qn/qnitensor.jl:7

[3] _setindex!!

@ ~/.julia/packages/ITensors/5sSxp/src/itensor.jl:928 [inlined]

[4] setindex!

@ ~/.julia/packages/ITensors/5sSxp/src/itensor.jl:970 [inlined]

[5] setindex!(T::ITensor, x::Float64, I::CartesianIndex{2})

@ ITensors ~/.julia/packages/ITensors/5sSxp/src/itensor.jl:974

[6] ITensor(::NDTensors.AllowAlias, ::Type{Float64}, A::Matrix{Float64}, inds::Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}}; tol::Int64)

@ ITensors ~/.julia/packages/ITensors/5sSxp/src/qn/qnitensor.jl:295

[7] ITensor(::NDTensors.AllowAlias, ::Type{Float64}, A::Matrix{Float64}, inds::Tuple{Index{Vector{Pair{QN, Int64}}}, Index{Vector{Pair{QN, Int64}}}})

@ ITensors ~/.julia/packages/ITensors/5sSxp/src/qn/qnitensor.jl:284

[8] ITensor(::NDTensors.AllowAlias, ::Matrix{Float64}, ::Index{Vector{Pair{QN, Int64}}}, ::Vararg{Index{Vector{Pair{QN, Int64}}}}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})

@ ITensors ~/.julia/packages/ITensors/5sSxp/src/itensor.jl:497

[9] ITensor(::NDTensors.AllowAlias, ::Matrix{Float64}, ::Index{Vector{Pair{QN, Int64}}}, ::Vararg{Index{Vector{Pair{QN, Int64}}}})

@ ITensors ~/.julia/packages/ITensors/5sSxp/src/itensor.jl:497

[10] itensor(::Matrix{Float64}, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})

@ ITensors ~/.julia/packages/ITensors/5sSxp/src/itensor.jl:123

[11] itensor(::Matrix{Float64}, ::Index{Vector{Pair{QN, Int64}}}, ::Vararg{Index{Vector{Pair{QN, Int64}}}})

@ ITensors ~/.julia/packages/ITensors/5sSxp/src/itensor.jl:123

[12] op(name::String, s::Index{Vector{Pair{QN, Int64}}}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})

@ ITensors ~/.julia/packages/ITensors/5sSxp/src/physics/sitetype.jl:260

[13] op

@ ~/.julia/packages/ITensors/5sSxp/src/physics/sitetype.jl:221 [inlined]

[14] #op#947

@ ~/.julia/packages/ITensors/5sSxp/src/physics/sitetype.jl:355 [inlined]

[15] op

@ ~/.julia/packages/ITensors/5sSxp/src/physics/sitetype.jl:355 [inlined]

[16] #op#952

@ ~/.julia/packages/ITensors/5sSxp/src/physics/sitetype.jl:369 [inlined]

[17] op(s::Vector{Index{Vector{Pair{QN, Int64}}}}, opname::String, ns::Int64)

@ ITensors ~/.julia/packages/ITensors/5sSxp/src/physics/sitetype.jl:369

[18] top-level scope

@ ~/dmrg/spin.jl:113