Skip to content

Commit

Permalink
Simplify spin one
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Jan 23, 2025
1 parent e5c0856 commit d50c07c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 91 deletions.
3 changes: 2 additions & 1 deletion src/itensor/op.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ function op(name::AbstractString, s::Index...; adjoint::Bool=false, kwargs...)
## end

common_stypes = _sitetypes(commontags_s)
@ignore_derivatives push!(common_stypes, SiteType("Generic"))
# TODO: Delete this.
push!(common_stypes, SiteType("Generic"))
opn = OpName(name)
for st in common_stypes
op_mat = AbstractArray(opn, st; kwargs...)
Expand Down
13 changes: 7 additions & 6 deletions src/op.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ alias(::OpName"X") = (OpName"σ⁺"() + OpName"σ⁻"()) / 2
@op_alias "iX" "im" op = OpName"X"()
@op_alias "√X" "" op = OpName"X"()
@op_alias "√NOT" "" op = OpName"X"()
alias(n::OpName"Sx") = OpName("X") / 2
alias(n::OpName"Sx") = OpName"X"() / 2
@op_alias "" "Sx"
@op_alias "Sₓ" "Sx"
alias(::OpName"Sx2") = OpName"Sx"()^2

alias(::OpName"Y") = -im * (OpName"σ⁺"() - OpName"σ⁻"()) / 2
# TODO: No subsript `\_y` available
Expand All @@ -193,9 +194,7 @@ alias(::OpName"Y") = -im * (OpName"σ⁺"() - OpName"σ⁻"()) / 2
@op_alias "σ2" "Y"
@op_alias "σ²" "Y"
@op_alias "σ₂" "Y"
function alias(::OpName"iY")
return real(OpName"Y"()im)
end
alias(::OpName"iY") = (OpName"σ⁺"() - OpName"σ⁻"()) / 2
@op_alias "iσy" "iY"
# TODO: No subsript `\_y` available
# in unicode.
Expand All @@ -207,6 +206,7 @@ alias(n::OpName"Sy") = OpName("Y") / 2
@op_alias "" "Sy"
alias(n::OpName"iSy") = OpName("iY") / 2
@op_alias "iSʸ" "iSy"
alias(::OpName"Sy2") = -OpName"iSy"()^2

function Base.AbstractArray(n::OpName"σᶻ", domain_size::Tuple{Int})
d = only(domain_size)
Expand All @@ -221,7 +221,7 @@ end
@op_alias "σ₃" "Z"
@op_alias "σz" "Z"
@op_alias "iZ" "im" op = OpName"Z"()
alias(n::OpName"Sz") = OpName("Z") / 2
alias(n::OpName"Sz") = OpName"Z"() / 2
@op_alias "Sᶻ" "Sz"
# TODO: Make sure it ends up real, using `S⁺` and `S⁻`,
# define `Sx²`, `Sy²`, and `Sz²`, etc.
Expand All @@ -231,8 +231,9 @@ alias(n::OpName"Sz") = OpName("Z") / 2
# = (d - 1) * (d + 1) / 4 * I
# ```
# where `s = (d - 1) / 2`. See https://en.wikipedia.org/wiki/Spin_(physics)#Higher_spins.
alias(n::OpName"S2") = (OpName("")^2 + OpName("")^2 + OpName("Sᶻ")^2)
alias(n::OpName"S2") = OpName"Sx2"() + OpName"Sy2"() + OpName"Sz2"()
@op_alias "" "S2"
alias(::OpName"Sz2") = OpName"Sz"()^2

using LinearAlgebra: eigen
function Base.AbstractArray(n::OpName"H", domain_size::Tuple{Int})
Expand Down
91 changes: 7 additions & 84 deletions src/sitetypes/spinone.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# TODO: Need to define or replace.
# using ITensorBase: complex!, QN

Base.length(::SiteType"S=1") = 3

alias(::SiteType"SpinOne") = SiteType"S=1"()

"""
Expand Down Expand Up @@ -54,97 +56,18 @@ state(::StateName"Y+", ::SiteType"S=1") = [-1 / 2, -im / sqrt(2), 1 / 2]
state(::StateName"Y0", ::SiteType"S=1") = [1 / sqrt(2), 0, 1 / sqrt(2)]
state(::StateName"Y-", ::SiteType"S=1") = [-1 / 2, im / sqrt(2), 1 / 2]

op(::OpName"Id", ::SiteType"S=1") = [
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
]

op(::OpName"Sz", ::SiteType"S=1") = [
1.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 -1.0
]

op(on::OpName"Sᶻ", t::SiteType"S=1") = op(alias(on), t)

op(::OpName"S+", ::SiteType"S=1") = [
0.0 2 0.0
0.0 0.0 2
0.0 0.0 0.0
]

op(on::OpName"S⁺", t::SiteType"S=1") = op(alias(on), t)
op(on::OpName"Splus", t::SiteType"S=1") = op(alias(on), t)
op(on::OpName"Sp", t::SiteType"S=1") = op(alias(on), t)

op(::OpName"S-", ::SiteType"S=1") = [
0.0 0.0 0.0
2 0.0 0.0
0.0 2 0.0
]

op(on::OpName"S⁻", t::SiteType"S=1") = op(alias(on), t)
op(on::OpName"Sminus", t::SiteType"S=1") = op(alias(on), t)
op(on::OpName"Sm", t::SiteType"S=1") = op(alias(on), t)

op(::OpName"Sx", ::SiteType"S=1") = [
0.0 1/√2 0.0
1/√2 0.0 1/√2
0.0 1/√2 0.0
]

op(on::OpName"Sˣ", t::SiteType"S=1") = op(alias(on), t)

op(::OpName"iSy", ::SiteType"S=1") = [
0.0 1/√2 0.0
-1/√2 0.0 1/√2
0.0 -1/√2 0.0
]

op(on::OpName"iSʸ", t::SiteType"S=1") = op(alias(on), t)

op(::OpName"Sy", ::SiteType"S=1") = [
0.0 -im/√2 0.0
im/√2 0.0 -im/√2
0.0 im/√2 0.0
]

op(on::OpName"Sʸ", t::SiteType"S=1") = op(alias(on), t)

op(::OpName"Sz2", ::SiteType"S=1") = [
1.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 1.0
]

op(::OpName"Sx2", ::SiteType"S=1") = [
0.5 0.0 0.5
0.0 1.0 0.0
0.5 0.0 0.5
]

op(::OpName"Sy2", ::SiteType"S=1") = [
0.5 0.0 -0.5
0.0 1.0 0.0
-0.5 0.0 0.5
]

op(::OpName"S2", ::SiteType"S=1") = [
2.0 0.0 0.0
0.0 2.0 0.0
0.0 0.0 2.0
]

op(on::OpName"S²", t::SiteType"S=1") = op(alias(on), t)

# TODO: Delete this.
space(st::SiteType"SpinOne"; kwargs...) = space(alias(st); kwargs...)

# TODO: Delete this.
state(name::StateName, st::SiteType"SpinOne") = state(name, alias(st))
# TODO: Delete this.
val(name::ValName, st::SiteType"SpinOne") = val(name, alias(st))

# TODO: Delete this.
## function op!(Op::ITensor, o::OpName, st::SiteType"SpinOne", s::Index)
## return op!(Op, o, alias(st), s)
## end

# TODO: Delete this.
op(o::OpName, st::SiteType"SpinOne") = op(o, alias(st))

0 comments on commit d50c07c

Please sign in to comment.