Skip to content

Unable to create S_exchange directly as real TensorMap #35

@Yue-Zhengyuan

Description

@Yue-Zhengyuan

MWE:

using MPSKitModels
S_exchange(Float64)

Output:

ERROR: InexactError: Float64(0.0 - 0.5im)
Stacktrace:
  [1] Real
    @ ./complex.jl:44 [inlined]
  [2] convert
    @ ./number.jl:7 [inlined]
  [3] setindex!(::Matrix{Float64}, ::ComplexF64, ::Int64, ::Int64)
    @ Base ./array.jl:983
  [4] spinmatrices(s::Rational{Int64}, elt::Type)
    @ MPSKitModels ~/.julia/packages/MPSKitModels/RcUP6/src/operators/spinoperators.jl:31
  [5] #S_x#42
    @ ~/.julia/packages/MPSKitModels/RcUP6/src/operators/spinoperators.jl:61 [inlined]
  [6] S_x
    @ ~/.julia/packages/MPSKitModels/RcUP6/src/operators/spinoperators.jl:60 [inlined]
  [7] S_xx(elt::Type{Float64}, ::Type{TensorKit.Trivial}; spin::Rational{Int64})
    @ MPSKitModels ~/.julia/packages/MPSKitModels/RcUP6/src/operators/spinoperators.jl:382
  [8] S_xx
    @ ~/.julia/packages/MPSKitModels/RcUP6/src/operators/spinoperators.jl:381 [inlined]
  [9] S_exchange(elt::Type{Float64}, ::Type{TensorKit.Trivial}; spin::Rational{Int64})
    @ MPSKitModels ~/.julia/packages/MPSKitModels/RcUP6/src/operators/spinoperators.jl:422
 [10] S_exchange(elt::Type{Float64}, ::Type{TensorKit.Trivial})
    @ MPSKitModels ~/.julia/packages/MPSKitModels/RcUP6/src/operators/spinoperators.jl:421
 [11] S_exchange(elt::Type{Float64}; kwargs::@Kwargs{})
    @ MPSKitModels ~/.julia/packages/MPSKitModels/RcUP6/src/operators/spinoperators.jl:416
 [12] top-level scope
    @ REPL[3]:1

It appears that the construction uses $S^y$, so I cannot directly set eltype as a real type. Although I can circumvent the issue by real(S_exchange()), it may still be better to be able to directly create it as a real operator. A possible solution (at least for spin-1/2) is to use $(1/2)(S^+_1 S^-_2 + h.c.) + S^z_1 S^z_2$ instead of $S^x_1 S^x_2 + S^y_1 S^y_2 + S^z_1 S^z_2$.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions