Skip to content

Commit f97c3a4

Browse files
authored
Use dual to take the dual of the domain when building symmetric operators (#22)
1 parent c61e4bc commit f97c3a4

File tree

5 files changed

+17
-28
lines changed

5 files changed

+17
-28
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "QuantumOperatorDefinitions"
22
uuid = "826dd319-6fd5-459a-a990-3a4f214664bf"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.1.6"
4+
version = "0.1.7"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -10,13 +10,13 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1010
[weakdeps]
1111
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
1212
GradedUnitRanges = "e2de450a-8a67-46c7-b59c-01d5a3d041c5"
13-
LabelledNumbers = "f856a3a6-4152-4ec4-b2a7-02c1a55d7993"
1413
ITensorBase = "4795dd04-0d67-49bb-8f44-b89c448a1dc7"
14+
LabelledNumbers = "f856a3a6-4152-4ec4-b2a7-02c1a55d7993"
1515
NamedDimsArrays = "60cbd0c0-df58-4cb7-918c-6f5607b73fde"
1616
SymmetrySectors = "f8a8ad64-adbc-4fce-92f7-ffe2bb36a86e"
1717

1818
[extensions]
19-
QuantumOperatorDefinitionsITensorBaseExt = ["ITensorBase", "NamedDimsArrays"]
19+
QuantumOperatorDefinitionsITensorBaseExt = ["ITensorBase", "GradedUnitRanges", "NamedDimsArrays"]
2020
QuantumOperatorDefinitionsSymmetrySectorsExt = ["BlockArrays", "GradedUnitRanges", "LabelledNumbers", "SymmetrySectors"]
2121

2222
[compat]

ext/QuantumOperatorDefinitionsITensorBaseExt/QuantumOperatorDefinitionsITensorBaseExt.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module QuantumOperatorDefinitionsITensorBaseExt
22

3-
using ITensorBase: ITensorBase, ITensor, Index, dag, gettag, prime, settag
3+
using ITensorBase: ITensorBase, ITensor, Index, gettag, prime, settag
4+
using GradedUnitRanges: dual
45
using NamedDimsArrays: dename
56
using QuantumOperatorDefinitions:
67
QuantumOperatorDefinitions,
@@ -38,7 +39,7 @@ function QuantumOperatorDefinitions.has_fermion_string(n::String, r::Index)
3839
end
3940

4041
function Base.axes(::OpName, domain::Tuple{Vararg{Index}})
41-
return (prime.(domain)..., dag.(domain)...)
42+
return (prime.(domain)..., dual.(domain)...)
4243
end
4344
## function Base.axes(::OpName"SWAP", domain::Tuple{Vararg{Index}})
4445
## return (prime.(reverse(domain))..., dag.(domain)...)

src/sitetype.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ function Base.AbstractUnitRange(t::SiteType)
7979
end
8080
return Base.OneTo(length(t))
8181
end
82-
# kwargs are passed for fancier constructors, like `ITensors.Index`.
8382
function (rangetype::Type{<:AbstractUnitRange})(t::SiteType)
8483
return rangetype(AbstractUnitRange(t))
8584
end

test/test_itensorbaseext.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using GradedUnitRanges: GradedUnitRanges
12
using ITensorBase: ITensor, Index, gettag, hastag, prime, settag
23
using NamedDimsArrays: dename
34
using QuantumOperatorDefinitions: OpName, SiteType, StateName, op, site, sites, state

test/test_symmetrysectorsext.jl

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using BlockArrays: AbstractBlockArray, blocklengths
22
using BlockSparseArrays: BlockSparseArray
3-
using GradedUnitRanges: blocklabels
3+
using GradedUnitRanges: blocklabels, dual, isdual
44
using ITensorBase: ITensor, Index, gettag, prime, settag
55
using QuantumOperatorDefinitions: OpName, SiteType, StateName, op, state
66
using SymmetrySectors: SectorProduct, U1, Z
77
using NamedDimsArrays: dename
8-
using Test: @test, @test_broken, @testset
8+
using Test: @test, @testset
99

1010
@testset "SymmetrySectorsExt" begin
1111
t = SiteType("S=1/2"; gradings=("Sz",))
@@ -54,36 +54,27 @@ using Test: @test, @test_broken, @testset
5454
@test blocklabels(r2) == [SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(-1)))]
5555
@test blocklengths(r2) == [1, 1]
5656

57-
# TODO: There is a bug slicing `BitVector` by `GradedOneTo` in Julia 1.11,
58-
# investigate. See: https://github.com/ITensor/GradedUnitRanges.jl/issues/9
5957
t = SiteType("S=1/2"; gradings=("Sz",))
60-
@test state("0", t) == [1, 0] broken = VERSION v"1.11"
58+
@test state("0", t) == [1, 0]
6159

6260
# Force conversion to `Vector{Float64}` before conversion,
6361
# since there is a bug slicing `BitVector` by `GradedOneTo`.
6462
t = SiteType("S=1/2"; gradings=("Sz",))
6563
a = AbstractArray(2.0 * StateName("0"), t)
6664
@test a == [2, 0]
67-
@test a isa AbstractBlockArray
68-
# TODO: Currently slicing a dense array by graded ranges outputs a `BlockedArray`
69-
# rather than a `BlockSparseArray`.
70-
# See: https://github.com/ITensor/GradedUnitRanges.jl/issues/9
71-
@test_broken a isa BlockSparseArray
65+
@test a isa BlockSparseArray
7266
(r1,) = axes(a)
7367
@test blocklabels(r1) == [SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(1)))]
7468
@test blocklengths(r1) == [1, 1]
7569

7670
t = SiteType("S=1/2"; gradings=("Sz",))
7771
a = op("σ⁺", t)
7872
@test a == [0 2; 0 0]
79-
@test a isa AbstractBlockArray
80-
@test_broken a isa BlockSparseArray
73+
@test a isa BlockSparseArray
8174
(r1, r2) = axes(a)
8275
@test blocklabels(r1) == [SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(1)))]
8376
@test blocklengths(r1) == [1, 1]
84-
# TODO: This is a bug in indexing with GradedUnitRangeDual, fix this.
85-
@test_broken blocklabels(r2) ==
86-
[SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(-1)))]
77+
@test blocklabels(r2) == [SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(-1)))]
8778
@test blocklengths(r2) == [1, 1]
8879
end
8980

@@ -97,17 +88,14 @@ end
9788

9889
i′ = prime(i)
9990
a = op("σ⁺", i)
100-
# TODO: The indices should be `(i′, dual(i))`.
101-
@test a == ITensor([0 2; 0 0], (i′, i))
91+
@test a == ITensor([0 2; 0 0], (i′, dual(i)))
92+
@test all(isdual.(axes(a)) .== (false, true))
10293
a′ = dename(a)
103-
@test a′ isa AbstractBlockArray
104-
@test_broken a′ isa BlockSparseArray
94+
@test a′ isa BlockSparseArray
10595
# TODO: Test these without denaming `a`.
10696
(r1, r2) = axes(a′)
10797
@test blocklabels(r1) == [SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(1)))]
10898
@test blocklengths(r1) == [1, 1]
109-
# TODO: This is a bug in indexing with GradedUnitRangeDual, fix this.
110-
@test_broken blocklabels(r2) ==
111-
[SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(-1)))]
99+
@test blocklabels(r2) == [SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(-1)))]
112100
@test blocklengths(r2) == [1, 1]
113101
end

0 commit comments

Comments
 (0)