Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QuantumOperatorDefinitions"
uuid = "826dd319-6fd5-459a-a990-3a4f214664bf"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.2.9"
version = "0.2.10"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -19,7 +19,7 @@ QuantumOperatorDefinitionsITensorBaseExt = ["ITensorBase", "GradedArrays", "Name

[compat]
BlockArrays = "1.3.0"
GradedArrays = "0.4"
GradedArrays = "0.5"
ITensorBase = "0.2, 0.3"
LinearAlgebra = "1.10"
NamedDimsArrays = "0.7, 0.8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module QuantumOperatorDefinitionsGradedArraysExt

using BlockArrays: blocklasts, blocklength, blocklengths
using GradedArrays:
AbstractGradedUnitRange, GradedOneTo, SectorProduct, U1, Z, ×, dual, gradedrange, sectors
AbstractGradedUnitRange, GradedOneTo, U1, Z, ×, dual, gradedrange, sectorproduct, sectors
using QuantumOperatorDefinitions:
QuantumOperatorDefinitions,
@GradingType_str,
Expand Down Expand Up @@ -34,21 +34,21 @@ QuantumOperatorDefinitions.combine_axes(a::GradedOneTo, b::Base.OneTo) = a
QuantumOperatorDefinitions.combine_axes(a::Base.OneTo, b::GradedOneTo) = b

function Base.AbstractUnitRange(::GradingType"N", t::SiteType)
return gradedrange(map(i -> SectorProduct((; N = U1(i - 1))) => 1, 1:length(t)))
return gradedrange(map(i -> sectorproduct((; N = U1(i - 1))) => 1, 1:length(t)))
end
function Base.AbstractUnitRange(::GradingType"Sz", t::SiteType)
return gradedrange(map(i -> SectorProduct((; Sz = U1(i - 1))) => 1, 1:length(t)))
return gradedrange(map(i -> sectorproduct((; Sz = U1(i - 1))) => 1, 1:length(t)))
end
function Base.AbstractUnitRange(::GradingType"Sz↑", t::SiteType)
return AbstractUnitRange(GradingType"Sz"(), t)
end
function Base.AbstractUnitRange(::GradingType"Sz↓", t::SiteType)
return gradedrange(map(i -> SectorProduct((; Sz = U1(-(i - 1)))) => 1, 1:length(t)))
return gradedrange(map(i -> sectorproduct((; Sz = U1(-(i - 1)))) => 1, 1:length(t)))
end

function sector(gradingtype::GradingType, sec)
sectorname = Symbol(get(gradingtype, :name, name(gradingtype)))
return SectorProduct(NamedTuple{(sectorname,)}((sec,)))
return sectorproduct(NamedTuple{(sectorname,)}((sec,)))
end

function Base.AbstractUnitRange(s::GradingType"Nf", t::SiteType"Fermion")
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Aqua = "0.8.9"
BlockArrays = "1"
BlockSparseArrays = "0.8, 0.9, 0.10"
GradedArrays = "0.4"
GradedArrays = "0.5"
ITensorBase = "0.2, 0.3"
NamedDimsArrays = "0.7, 0.8"
QuantumOperatorDefinitions = "0.2"
Expand Down
44 changes: 22 additions & 22 deletions test/test_gradedarraysext.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using BlockArrays: AbstractBlockArray, blocklengths
using BlockSparseArrays: BlockSparseArray
using GradedArrays: SectorProduct, U1, Z, dual, isdual, sectors
using GradedArrays: U1, Z, dual, isdual, sectorproduct, sectors
using ITensorBase: ITensor, Index, gettag, prime, settag
using NamedDimsArrays: dename
using QuantumOperatorDefinitions: OpName, SiteType, StateName, op, state
Expand All @@ -10,47 +10,47 @@ using Test: @test, @testset
t = SiteType("S=1/2"; gradings = ("Sz",))
r = AbstractUnitRange(t)
@test r == 1:2
@test sectors(r) == [SectorProduct((; Sz = U1(0))), SectorProduct((; Sz = U1(1)))]
@test sectors(r) == [sectorproduct((; Sz = U1(0))), sectorproduct((; Sz = U1(1)))]
@test blocklengths(r) == [1, 1]

t = SiteType("Electron"; gradings = ("Nf", "Sz"))
r = AbstractUnitRange(t)
@test r == 1:4
@test sectors(r) == [
SectorProduct((; Nf = U1(0), Sz = U1(0))),
SectorProduct((; Nf = U1(1), Sz = U1(1))),
SectorProduct((; Nf = U1(1), Sz = U1(-1))),
SectorProduct((; Nf = U1(2), Sz = U1(0))),
sectorproduct((; Nf = U1(0), Sz = U1(0))),
sectorproduct((; Nf = U1(1), Sz = U1(1))),
sectorproduct((; Nf = U1(1), Sz = U1(-1))),
sectorproduct((; Nf = U1(2), Sz = U1(0))),
]
@test blocklengths(r) == [1, 1, 1, 1]

t = SiteType("Electron"; gradings = ("Nf" => "NfA", "Sz" => "SzA"))
r = AbstractUnitRange(t)
@test r == 1:4
@test sectors(r) == [
SectorProduct((; NfA = U1(0), SzA = U1(0))),
SectorProduct((; NfA = U1(1), SzA = U1(1))),
SectorProduct((; NfA = U1(1), SzA = U1(-1))),
SectorProduct((; NfA = U1(2), SzA = U1(0))),
sectorproduct((; NfA = U1(0), SzA = U1(0))),
sectorproduct((; NfA = U1(1), SzA = U1(1))),
sectorproduct((; NfA = U1(1), SzA = U1(-1))),
sectorproduct((; NfA = U1(2), SzA = U1(0))),
]
@test blocklengths(r) == [1, 1, 1, 1]

t = SiteType("Electron"; gradings = ("NfParity", "Sz"))
r = AbstractUnitRange(t)
@test r == 1:4
@test sectors(r) == [
SectorProduct((; NfParity = Z{2}(0), Sz = U1(0))),
SectorProduct((; NfParity = Z{2}(1), Sz = U1(1))),
SectorProduct((; NfParity = Z{2}(1), Sz = U1(-1))),
SectorProduct((; NfParity = Z{2}(0), Sz = U1(0))),
sectorproduct((; NfParity = Z{2}(0), Sz = U1(0))),
sectorproduct((; NfParity = Z{2}(1), Sz = U1(1))),
sectorproduct((; NfParity = Z{2}(1), Sz = U1(-1))),
sectorproduct((; NfParity = Z{2}(0), Sz = U1(0))),
]
@test blocklengths(r) == [1, 1, 1, 1]

t = SiteType("S=1/2"; gradings = ("Sz",))
(r1, r2) = axes(OpName("σ⁺"), (t,))
@test sectors(r1) == [SectorProduct((; Sz = U1(0))), SectorProduct((; Sz = U1(1)))]
@test sectors(r1) == [sectorproduct((; Sz = U1(0))), sectorproduct((; Sz = U1(1)))]
@test blocklengths(r1) == [1, 1]
@test sectors(r2) == [SectorProduct((; Sz = U1(0))), SectorProduct((; Sz = U1(1)))]
@test sectors(r2) == [sectorproduct((; Sz = U1(0))), sectorproduct((; Sz = U1(1)))]
@test blocklengths(r2) == [1, 1]

t = SiteType("S=1/2"; gradings = ("Sz",))
Expand All @@ -63,17 +63,17 @@ using Test: @test, @testset
@test a == [2, 0]
@test a isa BlockSparseArray
(r1,) = axes(a)
@test sectors(r1) == [SectorProduct((; Sz = U1(0))), SectorProduct((; Sz = U1(1)))]
@test sectors(r1) == [sectorproduct((; Sz = U1(0))), sectorproduct((; Sz = U1(1)))]
@test blocklengths(r1) == [1, 1]

t = SiteType("S=1/2"; gradings = ("Sz",))
a = op("σ⁺", t)
@test a == [0 2; 0 0]
@test a isa BlockSparseArray
(r1, r2) = axes(a)
@test sectors(r1) == [SectorProduct((; Sz = U1(0))), SectorProduct((; Sz = U1(1)))]
@test sectors(r1) == [sectorproduct((; Sz = U1(0))), sectorproduct((; Sz = U1(1)))]
@test blocklengths(r1) == [1, 1]
@test sectors(r2) == [SectorProduct((; Sz = U1(0))), SectorProduct((; Sz = U1(1)))]
@test sectors(r2) == [sectorproduct((; Sz = U1(0))), sectorproduct((; Sz = U1(1)))]
@test blocklengths(r2) == [1, 1]
end

Expand All @@ -82,7 +82,7 @@ end
@test gettag(i, "sitetype") == "S=1/2"
# TODO: Test without denaming.
@test dename(i) == 1:2
@test sectors(dename(i)) == [SectorProduct((; Sz = U1(0))), SectorProduct((; Sz = U1(1)))]
@test sectors(dename(i)) == [sectorproduct((; Sz = U1(0))), sectorproduct((; Sz = U1(1)))]
@test blocklengths(dename(i)) == [1, 1]

i′ = prime(i)
Expand All @@ -93,8 +93,8 @@ end
@test a′ isa BlockSparseArray
# TODO: Test these without denaming `a`.
(r1, r2) = axes(a′)
@test sectors(r1) == [SectorProduct((; Sz = U1(0))), SectorProduct((; Sz = U1(1)))]
@test sectors(r1) == [sectorproduct((; Sz = U1(0))), sectorproduct((; Sz = U1(1)))]
@test blocklengths(r1) == [1, 1]
@test sectors(r2) == [SectorProduct((; Sz = U1(0))), SectorProduct((; Sz = U1(1)))]
@test sectors(r2) == [sectorproduct((; Sz = U1(0))), sectorproduct((; Sz = U1(1)))]
@test blocklengths(r2) == [1, 1]
end
Loading