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

Use dual to take the dual of the domain when building symmetric operators #22

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 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.1.6"
version = "0.1.7"

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

[extensions]
QuantumOperatorDefinitionsITensorBaseExt = ["ITensorBase", "NamedDimsArrays"]
QuantumOperatorDefinitionsITensorBaseExt = ["ITensorBase", "GradedUnitRanges", "NamedDimsArrays"]
QuantumOperatorDefinitionsSymmetrySectorsExt = ["BlockArrays", "GradedUnitRanges", "LabelledNumbers", "SymmetrySectors"]

[compat]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module QuantumOperatorDefinitionsITensorBaseExt

using ITensorBase: ITensorBase, ITensor, Index, dag, gettag, prime, settag
using ITensorBase: ITensorBase, ITensor, Index, gettag, prime, settag
using GradedUnitRanges: dual
using NamedDimsArrays: dename
using QuantumOperatorDefinitions:
QuantumOperatorDefinitions,
Expand Down Expand Up @@ -38,7 +39,7 @@
end

function Base.axes(::OpName, domain::Tuple{Vararg{Index}})
return (prime.(domain)..., dag.(domain)...)
return (prime.(domain)..., dual.(domain)...)

Check warning on line 42 in ext/QuantumOperatorDefinitionsITensorBaseExt/QuantumOperatorDefinitionsITensorBaseExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/QuantumOperatorDefinitionsITensorBaseExt/QuantumOperatorDefinitionsITensorBaseExt.jl#L42

Added line #L42 was not covered by tests
end
## function Base.axes(::OpName"SWAP", domain::Tuple{Vararg{Index}})
## return (prime.(reverse(domain))..., dag.(domain)...)
Expand Down
1 change: 0 additions & 1 deletion src/sitetype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function Base.AbstractUnitRange(t::SiteType)
end
return Base.OneTo(length(t))
end
# kwargs are passed for fancier constructors, like `ITensors.Index`.
function (rangetype::Type{<:AbstractUnitRange})(t::SiteType)
return rangetype(AbstractUnitRange(t))
end
Expand Down
1 change: 1 addition & 0 deletions test/test_itensorbaseext.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using GradedUnitRanges: GradedUnitRanges
using ITensorBase: ITensor, Index, gettag, hastag, prime, settag
using NamedDimsArrays: dename
using QuantumOperatorDefinitions: OpName, SiteType, StateName, op, site, sites, state
Expand Down
26 changes: 8 additions & 18 deletions test/test_symmetrysectorsext.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using BlockArrays: AbstractBlockArray, blocklengths
using BlockSparseArrays: BlockSparseArray
using GradedUnitRanges: blocklabels
using GradedUnitRanges: blocklabels, dual, isdual
using ITensorBase: ITensor, Index, gettag, prime, settag
using QuantumOperatorDefinitions: OpName, SiteType, StateName, op, state
using SymmetrySectors: SectorProduct, U1, Z
Expand Down Expand Up @@ -64,26 +64,19 @@ using Test: @test, @test_broken, @testset
t = SiteType("S=1/2"; gradings=("Sz",))
a = AbstractArray(2.0 * StateName("0"), t)
@test a == [2, 0]
@test a isa AbstractBlockArray
# TODO: Currently slicing a dense array by graded ranges outputs a `BlockedArray`
# rather than a `BlockSparseArray`.
# See: https://github.com/ITensor/GradedUnitRanges.jl/issues/9
@test_broken a isa BlockSparseArray
@test a isa BlockSparseArray
(r1,) = axes(a)
@test blocklabels(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 AbstractBlockArray
@test_broken a isa BlockSparseArray
@test a isa BlockSparseArray
(r1, r2) = axes(a)
@test blocklabels(r1) == [SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(1)))]
@test blocklengths(r1) == [1, 1]
# TODO: This is a bug in indexing with GradedUnitRangeDual, fix this.
@test_broken blocklabels(r2) ==
[SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(-1)))]
@test blocklabels(r2) == [SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(-1)))]
@test blocklengths(r2) == [1, 1]
end

Expand All @@ -97,17 +90,14 @@ end

i′ = prime(i)
a = op("σ⁺", i)
# TODO: The indices should be `(i′, dual(i))`.
@test a == ITensor([0 2; 0 0], (i′, i))
@test a == ITensor([0 2; 0 0], (i′, dual(i)))
@test all(isdual.(axes(a)) .== (false, true))
a′ = dename(a)
@test a′ isa AbstractBlockArray
@test_broken a′ isa BlockSparseArray
@test a′ isa BlockSparseArray
# TODO: Test these without denaming `a`.
(r1, r2) = axes(a′)
@test blocklabels(r1) == [SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(1)))]
@test blocklengths(r1) == [1, 1]
# TODO: This is a bug in indexing with GradedUnitRangeDual, fix this.
@test_broken blocklabels(r2) ==
[SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(-1)))]
@test blocklabels(r2) == [SectorProduct((; Sz=U1(0))), SectorProduct((; Sz=U1(-1)))]
@test blocklengths(r2) == [1, 1]
end
Loading