diff --git a/NDTensors/Project.toml b/NDTensors/Project.toml index ece7615a0d..133f6c98ae 100644 --- a/NDTensors/Project.toml +++ b/NDTensors/Project.toml @@ -1,7 +1,7 @@ name = "NDTensors" uuid = "23ae76d9-e61a-49c4-8f12-3f1a16adf9cf" authors = ["Matthew Fishman "] -version = "0.3.29" +version = "0.3.30" [deps] Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697" @@ -42,8 +42,8 @@ TBLIS = "48530278-0828-4a49-9772-0f3830dfa1e9" cuTENSOR = "011b41b2-24ef-40a8-b3eb-fa098493e9e1" [extensions] -NDTensorsAMDGPUExt = ["AMDGPU","GPUArraysCore"] -NDTensorsCUDAExt = ["CUDA","GPUArraysCore"] +NDTensorsAMDGPUExt = ["AMDGPU", "GPUArraysCore"] +NDTensorsCUDAExt = ["CUDA", "GPUArraysCore"] NDTensorsGPUArraysCoreExt = "GPUArraysCore" NDTensorsHDF5Ext = "HDF5" NDTensorsMetalExt = ["GPUArraysCore", "Metal"] @@ -59,7 +59,6 @@ ArrayLayouts = "1.4" BlockArrays = "1" CUDA = "5" Compat = "4.9" -cuTENSOR = "2" Dictionaries = "0.4" EllipsisNotation = "1.8" FillArrays = "1" @@ -81,11 +80,12 @@ SparseArrays = "1.6" SplitApplyCombine = "1.2.2" StaticArrays = "0.12, 1.0" Strided = "2" -StridedViews = "0.2.2" +StridedViews = "0.2.2, 0.3" TBLIS = "0.2" TimerOutputs = "0.5.5" TupleTools = "1.2.0" VectorInterface = "0.4.2" +cuTENSOR = "2" julia = "1.6" [extras] diff --git a/Project.toml b/Project.toml index 3b05f24e1e..251e846818 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ITensors" uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5" authors = ["Matthew Fishman ", "Miles Stoudenmire "] -version = "0.6.13" +version = "0.6.14" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/lib/SiteTypes/src/sitetypes/aliases.jl b/src/lib/SiteTypes/src/sitetypes/aliases.jl index 30e395234c..727ad7f990 100644 --- a/src/lib/SiteTypes/src/sitetypes/aliases.jl +++ b/src/lib/SiteTypes/src/sitetypes/aliases.jl @@ -20,3 +20,21 @@ alias(::OpName"ntot") = OpName"Ntot"() alias(::OpName"F↑") = OpName"Fup"() alias(::OpName"F↓") = OpName"Fdn"() alias(::OpName"I") = OpName"Id"() + +alias(::OpName"S²") = OpName"S2"() +alias(::OpName"Sᶻ") = OpName"Sz"() +alias(::OpName"Sʸ") = OpName"Sy"() +alias(::OpName"iSʸ") = OpName"iSy"() +alias(::OpName"Sˣ") = OpName"Sx"() +alias(::OpName"S⁻") = OpName"S-"() +alias(::OpName"Sminus") = OpName"S-"() +alias(::OpName"Sm") = OpName"S-"() +alias(::OpName"S⁺") = OpName"S+"() +alias(::OpName"Splus") = OpName"S+"() +alias(::OpName"Sp") = OpName"S+"() +alias(::OpName"projUp") = OpName"ProjUp"() +alias(::OpName"projDn") = OpName"ProjDn"() + +alias(::OpName"Proj0") = OpName"ProjUp"() +alias(::OpName"Proj1") = OpName"ProjDn"() +alias(::OpName"Rn̂") = OpName"Rn"() diff --git a/src/lib/SiteTypes/src/sitetypes/qubit.jl b/src/lib/SiteTypes/src/sitetypes/qubit.jl index 149539355e..e07bd547f0 100644 --- a/src/lib/SiteTypes/src/sitetypes/qubit.jl +++ b/src/lib/SiteTypes/src/sitetypes/qubit.jl @@ -196,8 +196,8 @@ function op(::OpName"Rn", ::SiteType"Qubit"; θ::Real, ϕ::Real, λ::Real) ] end -function op(::OpName"Rn̂", t::SiteType"Qubit"; kwargs...) - return op(OpName("Rn"), t; kwargs...) +function op(on::OpName"Rn̂", t::SiteType"Qubit"; kwargs...) + return op(alias(on), t; kwargs...) end # @@ -435,68 +435,68 @@ op(::OpName"Sz", ::SiteType"Qubit") = [ 0.0 -0.5 ] -op(::OpName"Sᶻ", t::SiteType"Qubit") = op(OpName("Sz"), t) +op(on::OpName"Sᶻ", t::SiteType"Qubit") = op(alias(on), t) op(::OpName"S+", ::SiteType"Qubit") = [ 0 1 0 0 ] -op(::OpName"S⁺", t::SiteType"Qubit") = op(OpName("S+"), t) +op(on::OpName"S⁺", t::SiteType"Qubit") = op(alias(on), t) -op(::OpName"Splus", t::SiteType"Qubit") = op(OpName("S+"), t) +op(on::OpName"Splus", t::SiteType"Qubit") = op(alias(on), t) op(::OpName"S-", ::SiteType"Qubit") = [ 0 0 1 0 ] -op(::OpName"S⁻", t::SiteType"Qubit") = op(OpName("S-"), t) +op(on::OpName"S⁻", t::SiteType"Qubit") = op(alias(on), t) -op(::OpName"Sminus", t::SiteType"Qubit") = op(OpName("S-"), t) +op(on::OpName"Sminus", t::SiteType"Qubit") = op(alias(on), t) op(::OpName"Sx", ::SiteType"Qubit") = [ 0.0 0.5 0.5 0.0 ] -op(::OpName"Sˣ", t::SiteType"Qubit") = op(OpName("Sx"), t) +op(on::OpName"Sˣ", t::SiteType"Qubit") = op(alias(on), t) op(::OpName"iSy", ::SiteType"Qubit") = [ 0.0 0.5 -0.5 0.0 ] -op(::OpName"iSʸ", t::SiteType"Qubit") = op(OpName("iSy"), t) +op(on::OpName"iSʸ", t::SiteType"Qubit") = op(alias(on), t) op(::OpName"Sy", ::SiteType"Qubit") = [ 0.0 -0.5im 0.5im 0.0 ] -op(::OpName"Sʸ", t::SiteType"Qubit") = op(OpName("Sy"), t) +op(on::OpName"Sʸ", t::SiteType"Qubit") = op(alias(on), t) op(::OpName"S2", ::SiteType"Qubit") = [ 0.75 0.0 0.0 0.75 ] -op(::OpName"S²", t::SiteType"Qubit") = op(OpName("S2"), t) +op(on::OpName"S²", t::SiteType"Qubit") = op(alias(on), t) op(::OpName"ProjUp", ::SiteType"Qubit") = [ 1 0 0 0 ] -op(::OpName"projUp", t::SiteType"Qubit") = op(OpName("ProjUp"), t) +op(on::OpName"projUp", t::SiteType"Qubit") = op(alias(on), t) -op(::OpName"Proj0", t::SiteType"Qubit") = op(OpName("ProjUp"), t) +op(on::OpName"Proj0", t::SiteType"Qubit") = op(alias(on), t) op(::OpName"ProjDn", ::SiteType"Qubit") = [ 0 0 0 1 ] -op(::OpName"projDn", t::SiteType"Qubit") = op(OpName("ProjDn"), t) +op(on::OpName"projDn", t::SiteType"Qubit") = op(alias(on), t) -op(::OpName"Proj1", t::SiteType"Qubit") = op(OpName("ProjDn"), t) +op(on::OpName"Proj1", t::SiteType"Qubit") = op(alias(on), t) diff --git a/src/lib/SiteTypes/src/sitetypes/spinone.jl b/src/lib/SiteTypes/src/sitetypes/spinone.jl index bae0b765df..1de6902243 100644 --- a/src/lib/SiteTypes/src/sitetypes/spinone.jl +++ b/src/lib/SiteTypes/src/sitetypes/spinone.jl @@ -1,5 +1,7 @@ using ..ITensors: complex!, QN +alias(::SiteType"SpinOne") = SiteType"S=1"() + """ space(::SiteType"S=1"; conserve_qns = false, @@ -51,109 +53,91 @@ 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 +op(::OpName"Sz", ::SiteType"S=1") = [ + 1.0 0.0 0.0 + 0.0 0.0 0.0 + 0.0 0.0 -1.0 +] -function op!(Op::ITensor, ::OpName"Sᶻ", t::SiteType"S=1", s::Index) - return op!(Op, OpName("Sz"), t, s) -end +op(on::OpName"Sᶻ", t::SiteType"S=1") = op(alias(on), t) -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 +op(::OpName"S+", ::SiteType"S=1") = [ + 0.0 √2 0.0 + 0.0 0.0 √2 + 0.0 0.0 0.0 +] -function op!(Op::ITensor, ::OpName"S⁺", t::SiteType"S=1", s::Index) - return op!(Op, OpName("S+"), t, s) -end +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) -function op!(Op::ITensor, ::OpName"Splus", t::SiteType"S=1", s::Index) - return op!(Op, OpName("S+"), t, s) -end +op(::OpName"S-", ::SiteType"S=1") = [ + 0.0 0.0 0.0 + √2 0.0 0.0 + 0.0 √2 0.0 +] -function op!(Op::ITensor, ::OpName"Sp", t::SiteType"S=1", s::Index) - return op!(Op, OpName("S+"), t, s) -end +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) -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 +op(::OpName"Sx", ::SiteType"S=1") = [ + 0.0 1/√2 0.0 + 1/√2 0.0 1/√2 + 0.0 1/√2 0.0 +] -function op!(Op::ITensor, ::OpName"S⁻", t::SiteType"S=1", s::Index) - return op!(Op, OpName("S-"), t, s) -end +op(on::OpName"Sˣ", t::SiteType"S=1") = op(alias(on), t) -function op!(Op::ITensor, ::OpName"Sminus", t::SiteType"S=1", s::Index) - return op!(Op, OpName("S-"), t, s) -end +op(::OpName"iSy", ::SiteType"S=1") = [ + 0.0 1/√2 0.0 + -1/√2 0.0 1/√2 + 0.0 -1/√2 0.0 +] -function op!(Op::ITensor, ::OpName"Sm", t::SiteType"S=1", s::Index) - return op!(Op, OpName("S-"), t, s) -end +op(on::OpName"iSʸ", t::SiteType"S=1") = op(alias(on), t) -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 +op(::OpName"Sy", ::SiteType"S=1") = [ + 0.0 -im/√2 0.0 + im/√2 0.0 -im/√2 + 0.0 im/√2 0.0 +] -function op!(Op::ITensor, ::OpName"Sˣ", t::SiteType"S=1", s::Index) - return op!(Op, OpName("Sx"), t, s) -end +op(on::OpName"Sʸ", t::SiteType"S=1") = op(alias(on), t) -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 +op(::OpName"Sz2", ::SiteType"S=1") = [ + 1.0 0.0 0.0 + 0.0 0.0 0.0 + 0.0 0.0 1.0 +] -function op!(Op::ITensor, ::OpName"iSʸ", t::SiteType"S=1", s::Index) - return op!(Op, OpName("iSy"), t, s) -end +op(::OpName"Sx2", ::SiteType"S=1") = [ + 0.5 0.0 0.5 + 0.0 1.0 0.0 + 0.5 0.0 0.5 +] -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 +op(::OpName"Sy2", ::SiteType"S=1") = [ + 0.5 0.0 -0.5 + 0.0 1.0 0.0 + -0.5 0.0 0.5 +] -function op!(Op::ITensor, ::OpName"Sʸ", t::SiteType"S=1", s::Index) - return op!(Op, OpName("Sy"), t, s) -end +op(::OpName"S2", ::SiteType"S=1") = [ + 2.0 0.0 0.0 + 0.0 2.0 0.0 + 0.0 0.0 2.0 +] -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 +op(on::OpName"S²", t::SiteType"S=1") = op(alias(on), t) -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 +space(st::SiteType"SpinOne"; kwargs...) = space(alias(st); kwargs...) -space(::SiteType"SpinOne"; kwargs...) = space(SiteType("S=1"); kwargs...) +state(name::StateName, st::SiteType"SpinOne") = state(name, alias(st)) +val(name::ValName, st::SiteType"SpinOne") = val(name, alias(st)) -state(name::StateName, ::SiteType"SpinOne") = state(name, SiteType("S=1")) -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) +function op!(Op::ITensor, o::OpName, st::SiteType"SpinOne", s::Index) + return op!(Op, o, alias(st), s) end + +op(o::OpName, st::SiteType"SpinOne") = op(o, alias(st)) diff --git a/test/base/test_phys_site_types.jl b/test/base/test_phys_site_types.jl index 6ff1154893..21d25d7532 100644 --- a/test/base/test_phys_site_types.jl +++ b/test/base/test_phys_site_types.jl @@ -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 0.0; 0.0 2.0 0.0; 0.0 0.0 2.0] + @test Array(op("S²", s, 2), s[2]', s[2]) ≈ [2.0 0.0 0.0; 0.0 2.0 0.0; 0.0 0.0 2.0] end end