Skip to content

Commit 64ce077

Browse files
committed
ITensorBase extension to construct ITensors
1 parent ceb8aa8 commit 64ce077

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

Project.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ version = "0.1.3"
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
88
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
99

10+
[weakdeps]
11+
ITensorBase = "4795dd04-0d67-49bb-8f44-b89c448a1dc7"
12+
13+
[extensions]
14+
QuantumOperatorDefinitionsITensorBaseExt = "ITensorBase"
15+
1016
[compat]
17+
ITensorBase = "0.1.10"
1118
LinearAlgebra = "1.10"
1219
Random = "1.10"
1320
julia = "1.10"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module QuantumOperatorDefinitionsITensorBaseExt
2+
3+
using ITensorBase: ITensor, Index, dag, gettag, prime
4+
using QuantumOperatorDefinitions:
5+
QuantumOperatorDefinitions, OpName, SiteType, StateName, has_fermion_string
6+
7+
function QuantumOperatorDefinitions.SiteType(r::Index)
8+
return SiteType(gettag(r, "sitetype", "Qudit"); length=Int(length(r)))
9+
end
10+
11+
function QuantumOperatorDefinitions.has_fermion_string(n::String, r::Index)
12+
return has_fermion_string(OpName(n), SiteType(r))
13+
end
14+
15+
function Base.AbstractArray(n::OpName, r::Index)
16+
# TODO: Define this with mapped dimnames.
17+
return ITensor(AbstractArray(n, SiteType(r)), (prime(r), dag(r)))
18+
end
19+
20+
function Base.AbstractArray(n::StateName, r::Index)
21+
return ITensor(AbstractArray(n, SiteType(r)), (r,))
22+
end
23+
24+
end

test/test_itensorbaseext.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using ITensorBase: ITensor, Index, prime
2+
using QuantumOperatorDefinitions: op, state
3+
using Test: @test, @testset
4+
5+
@testset "QuantumOperatorDefinitionsITensorBaseExt" begin
6+
i = Index(2)
7+
8+
a = op("X", i)
9+
@test a == ITensor([0 1; 1 0], (prime(i), i))
10+
11+
a = state(1, i)
12+
@test a == ITensor([1, 0], (i,))
13+
end

0 commit comments

Comments
 (0)