Skip to content

Commit 2fa4a5e

Browse files
committed
Simplifications
1 parent 44105b0 commit 2fa4a5e

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

ext/QuantumOperatorDefinitionsITensorBaseExt/QuantumOperatorDefinitionsITensorBaseExt.jl

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,18 @@ using QuantumOperatorDefinitions:
88
function QuantumOperatorDefinitions.SiteType(r::Index)
99
# We pass the axis of the (unnamed) Index because
1010
# the Index may have originated from a slice, in which
11-
# case the start may not be 1 (and it may not even
11+
# case the start may not be 1 (for NonContiguousIndex,
12+
# which we need to add support for, it may not even
1213
# be a unit range).
1314
return SiteType(
1415
gettag(r, "sitetype", "Qudit"); dim=Int.(length(r)), range=only(axes(dename(r)))
1516
)
1617
end
1718

18-
function ITensorBase.Index(t::SiteType; kwargs...)
19-
return Index(AbstractUnitRange(t); kwargs...)
20-
end
21-
19+
# TODO: Define in terms of `OpName` directly, and define a generic
20+
# forwarding method `has_fermion_string(n::String, t) = has_fermion_string(OpName(n), t)`.
2221
function QuantumOperatorDefinitions.has_fermion_string(n::String, r::Index)
2322
return has_fermion_string(OpName(n), SiteType(r))
2423
end
2524

26-
function Base.AbstractArray(n::OpName, r::Index)
27-
# TODO: Define this with mapped dimnames.
28-
# Generalize beyond prime levels with codomain and domain indices.
29-
return ITensor(AbstractArray(n, SiteType(r)), (prime(r), dag(r)))
30-
end
31-
32-
function Base.AbstractArray(n::StateName, r::Index)
33-
return ITensor(AbstractArray(n, SiteType(r)), (r,))
34-
end
35-
3625
end

src/sitetype.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ function Base.length(t::SiteType)
6666
end
6767
return length(t′)
6868
end
69+
# TODO: Use a shorthand `(t::SiteType)() = AbstractUnitRange(t)`,
70+
# i.e. make `SiteType` callable like `OpName` and `StateName`
71+
# are right now.
6972
function Base.AbstractUnitRange(t::SiteType)
7073
# This logic allows specifying a range with extra properties,
7174
# like ones with symmetry sectors.
@@ -76,6 +79,10 @@ function Base.AbstractUnitRange(t::SiteType)
7679
end
7780
return Base.OneTo(length(t))
7881
end
82+
# kwargs are passed for fancier constructors, like `ITensors.Index`.
83+
function (rangetype::Type{<:AbstractUnitRange})(t::SiteType; kwargs...)
84+
return rangetype(AbstractUnitRange(t); kwargs...)
85+
end
7986
Base.size(t::SiteType) = (length(t),)
8087
Base.size(t::SiteType, dim::Integer) = size(t)[dim]
8188
Base.axes(t::SiteType) = (AbstractUnitRange(t),)

0 commit comments

Comments
 (0)