+1 vote
asked by (640 points)
reopened by

Hello,
I try to use Trotter Gates. When I use the following snippet

for(int b = 1; b <= N-1; ++b)
{
auto hterm = sites.op("Sx",b)*sites.op("Sx",b+1);
auto g = Gate(sites,b,b+1,Gate::tReal,tstep/2.,hterm);
gates.push_back(g);
}

the program calculate nothing. However, when i use "Sz" rather than "Sx" the program works well. I noticed in http://itensor.org/docs.cgi?vers=cppv2&page=classes/spinhalf that
"Sx" must be converted to an ITensor prior to usage. Could you please say how this can be done?

1 Answer

+1 vote
answered by (70.1k points)
selected by
 
Best answer

Yes this is an unfortunate issue with version 2 of ITensor. The soon to be released version 3 will fix this issue.

By convert to ITensor, what is meant is this:

ITensor Sxb = sites.op(“Sx”,b);

And similar for the other operator. Then you can multiply these ITensors together.

commented by (270 points)
Is there a Julia version for this? Met same problem...
commented by (70.1k points)
Hi, could you please clarify your question. When you say a Julia version for "this" do you mean obtaining operators from the `op` function? Or are you referring this specific issue about the Sx operator in ITensor version 2 and whether the Julia version has a similar issue? Or something else?

Thanks,
Miles
commented by (270 points)
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
commented by (70.1k points)
I see, yes so the way our QN conserving ITensor system works is that you are only allowed to form ITensor which change the total QN of a state by a well-defined amount. The Sx operator doesn't have this property so it can't be made when you are conserving total Sz quantum numbers (setting conserve_qns=true when making your site indices).

On a related note, though, the expectation value of <Sx> is always guaranteed to be zero for a state with a well-defined total Sz quantum number. So you can know analytically that <Sx> will be zero.

But of course there are cases where you want to measure something like <Sx_i Sx_j> which can be non-zero even if total Sz is conserved. For those cases, you should use the fact that Sx = 1/2*(S+ + S-) and measure things like <S+_i S-_j> instead.

Miles
Welcome to ITensor Support Q&A, where you can ask questions and receive answers from other members of the community.

Formatting Tips:
  • To format code, indent by four spaces
  • To format inline LaTeX, surround it by @@ on both sides
  • To format LaTeX on its own line, surround it by $$ above and below
  • For LaTeX, it may be necessary to backslash-escape underscore characters to obtain proper formatting. So for example writing \sum\_i to represent a sum over i.
If you cannot register due to firewall issues (e.g. you cannot see the capcha box) please email Miles Stoudenmire to ask for an account.

To report ITensor bugs, please use the issue tracker.

Categories

...