Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SiteTypes] Add S2 operator for S=1 and update code style #1502

Merged
merged 5 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 79 additions & 97 deletions src/lib/SiteTypes/src/sitetypes/spinone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,103 +51,83 @@ 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]

function op!(Op::ITensor, ::OpName"Sz", ::SiteType"S=1", s::Index)
Op[s' => 1, s => 1] = +1.0
return Op[s' => 3, s => 3] = -1.0
end

function op!(Op::ITensor, ::OpName"Sᶻ", t::SiteType"S=1", s::Index)
return op!(Op, OpName("Sz"), t, s)
end

function op!(Op::ITensor, ::OpName"S+", ::SiteType"S=1", s::Index)
Op[s' => 2, s => 3] = sqrt(2)
return Op[s' => 1, s => 2] = sqrt(2)
end

function op!(Op::ITensor, ::OpName"S⁺", t::SiteType"S=1", s::Index)
return op!(Op, OpName("S+"), t, s)
end

function op!(Op::ITensor, ::OpName"Splus", t::SiteType"S=1", s::Index)
return op!(Op, OpName("S+"), t, s)
end

function op!(Op::ITensor, ::OpName"Sp", t::SiteType"S=1", s::Index)
return op!(Op, OpName("S+"), t, s)
end

function op!(Op::ITensor, ::OpName"S-", ::SiteType"S=1", s::Index)
Op[s' => 3, s => 2] = sqrt(2)
return Op[s' => 2, s => 1] = sqrt(2)
end

function op!(Op::ITensor, ::OpName"S⁻", t::SiteType"S=1", s::Index)
return op!(Op, OpName("S-"), t, s)
end

function op!(Op::ITensor, ::OpName"Sminus", t::SiteType"S=1", s::Index)
return op!(Op, OpName("S-"), t, s)
end

function op!(Op::ITensor, ::OpName"Sm", t::SiteType"S=1", s::Index)
return op!(Op, OpName("S-"), t, s)
end

function op!(Op::ITensor, ::OpName"Sx", ::SiteType"S=1", s::Index)
Op[s' => 2, s => 1] = 1 / sqrt(2)
Op[s' => 1, s => 2] = 1 / sqrt(2)
Op[s' => 3, s => 2] = 1 / sqrt(2)
return Op[s' => 2, s => 3] = 1 / sqrt(2)
end

function op!(Op::ITensor, ::OpName"Sˣ", t::SiteType"S=1", s::Index)
return op!(Op, OpName("Sx"), t, s)
end

function op!(Op::ITensor, ::OpName"iSy", ::SiteType"S=1", s::Index)
Op[s' => 2, s => 1] = -1 / sqrt(2)
Op[s' => 1, s => 2] = +1 / sqrt(2)
Op[s' => 3, s => 2] = -1 / sqrt(2)
return Op[s' => 2, s => 3] = +1 / sqrt(2)
end

function op!(Op::ITensor, ::OpName"iSʸ", t::SiteType"S=1", s::Index)
return op!(Op, OpName("iSy"), t, s)
end

function op!(Op::ITensor, ::OpName"Sy", ::SiteType"S=1", s::Index)
complex!(Op)
Op[s' => 2, s => 1] = +1im / sqrt(2)
Op[s' => 1, s => 2] = -1im / sqrt(2)
Op[s' => 3, s => 2] = +1im / sqrt(2)
return Op[s' => 2, s => 3] = -1im / sqrt(2)
end

function op!(Op::ITensor, ::OpName"Sʸ", t::SiteType"S=1", s::Index)
return op!(Op, OpName("Sy"), t, s)
end

function op!(Op::ITensor, ::OpName"Sz2", ::SiteType"S=1", s::Index)
Op[s' => 1, s => 1] = +1.0
return Op[s' => 3, s => 3] = +1.0
end

function op!(Op::ITensor, ::OpName"Sx2", ::SiteType"S=1", s::Index)
Op[s' => 1, s => 1] = 0.5
Op[s' => 3, s => 1] = 0.5
Op[s' => 2, s => 2] = 1.0
Op[s' => 1, s => 3] = 0.5
return Op[s' => 3, s => 3] = 0.5
end

function op!(Op::ITensor, ::OpName"Sy2", ::SiteType"S=1", s::Index)
Op[s' => 1, s => 1] = +0.5
Op[s' => 3, s => 1] = -0.5
Op[s' => 2, s => 2] = +1.0
Op[s' => 1, s => 3] = -0.5
return Op[s' => 3, s => 3] = +0.5
end
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(::OpName"Sᶻ", t::SiteType"S=1") = op(OpName("Sz"), t)
mtfishman marked this conversation as resolved.
Show resolved Hide resolved

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

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

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

op(::OpName"S⁻", t::SiteType"S=1") = op(OpName("S-"), t)
op(::OpName"Sminus", t::SiteType"S=1") = op(OpName("S-"), t)
op(::OpName"Sm", t::SiteType"S=1") = op(OpName("S-"), 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(::OpName"Sˣ", t::SiteType"S=1") = op(OpName("Sx"), 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(::OpName"iSʸ", t::SiteType"S=1") = op(OpName("iSy"), 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(::OpName"Sʸ", t::SiteType"S=1") = op(OpName("Sy"), 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(::OpName"S²", t::SiteType"S=1") = op(OpName("S2"), t)

space(::SiteType"SpinOne"; kwargs...) = space(SiteType("S=1"); kwargs...)

Expand All @@ -157,3 +137,5 @@ val(name::ValName, ::SiteType"SpinOne") = val(name, SiteType("S=1"))
function op!(Op::ITensor, o::OpName, ::SiteType"SpinOne", s::Index)
return op!(Op, o, SiteType("S=1"), s)
end

op(o::OpName, ::SiteType"SpinOne") = op(o, SiteType("S=1"))
2 changes: 2 additions & 0 deletions test/base/test_phys_site_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ using ITensors, LinearAlgebra, Test
@test Array(op("Sz2", s, 2), s[2]', s[2]) ≈ [1.0 0 0; 0 0 0; 0 0 +1.0]
@test Array(op("Sx2", s, 2), s[2]', s[2]) ≈ [0.5 0 0.5; 0 1.0 0; 0.5 0 0.5]
@test Array(op("Sy2", s, 2), s[2]', s[2]) ≈ [0.5 0 -0.5; 0 1.0 0; -0.5 0 0.5]
@test Array(op("S2", s, 2), s[2]', s[2]) ≈ [2. 0. 0.; 0. 2. 0.; 0. 0. 2.]
@test Array(op("S²", s, 2), s[2]', s[2]) ≈ [2. 0. 0.; 0. 2. 0.; 0. 0. 2.]
mtfishman marked this conversation as resolved.
Show resolved Hide resolved
end
end

Expand Down
Loading