Skip to content

Commit 7af788d

Browse files
committed
Add test_bases.jl from QuantumOpticsBase
1 parent 46223c3 commit 7af788d

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ end
2626
println("Starting tests with $(Threads.nthreads()) threads out of `Sys.CPU_THREADS = $(Sys.CPU_THREADS)`...")
2727

2828
@doset "sortedindices"
29+
@doset "bases"
2930
#VERSION >= v"1.9" && @doset "doctests"
3031
get(ENV,"JET_TEST","")=="true" && @doset "jet"
3132
VERSION >= v"1.9" && @doset "aqua"

test/test_bases.jl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Test
2+
using QuantumInterface: tensor, , ptrace, reduced, permutesystems, equal_bases, multiplicable
3+
using QuantumInterface: GenericBasis, CompositeBasis, NLevelBasis, FockBasis
4+
5+
@testset "basis" begin
6+
7+
shape1 = [5]
8+
shape2 = [2, 3]
9+
shape3 = [6]
10+
11+
b1 = GenericBasis(shape1)
12+
b2 = GenericBasis(shape2)
13+
b3 = GenericBasis(shape3)
14+
15+
@test b1.shape == shape1
16+
@test b2.shape == shape2
17+
@test b1 != b2
18+
@test b1 != FockBasis(2)
19+
@test b1 == b1
20+
21+
@test tensor(b1) == b1
22+
comp_b1 = tensor(b1, b2)
23+
comp_uni = b1 b2
24+
comp_b2 = tensor(b1, b1, b2)
25+
@test comp_b1.shape == [prod(shape1), prod(shape2)]
26+
@test comp_uni.shape == [prod(shape1), prod(shape2)]
27+
@test comp_b2.shape == [prod(shape1), prod(shape1), prod(shape2)]
28+
29+
@test b1^3 == CompositeBasis(b1, b1, b1)
30+
@test (b1b2)^2 == CompositeBasis(b1, b2, b1, b2)
31+
@test_throws ArgumentError b1^(0)
32+
33+
comp_b1_b2 = tensor(comp_b1, comp_b2)
34+
@test comp_b1_b2.shape == [prod(shape1), prod(shape2), prod(shape1), prod(shape1), prod(shape2)]
35+
@test comp_b1_b2 == CompositeBasis(b1, b2, b1, b1, b2)
36+
37+
@test_throws ArgumentError tensor()
38+
@test comp_b2.shape == tensor(b1, comp_b1).shape
39+
@test comp_b2 == tensor(b1, comp_b1)
40+
41+
@test_throws ArgumentError ptrace(comp_b1, [1, 2])
42+
@test ptrace(comp_b2, [1]) == ptrace(comp_b2, [2]) == comp_b1 == ptrace(comp_b2, 1)
43+
@test ptrace(comp_b2, [1, 2]) == ptrace(comp_b1, [1])
44+
@test ptrace(comp_b2, [2, 3]) == ptrace(comp_b1, [2])
45+
@test ptrace(comp_b2, [2, 3]) == reduced(comp_b2, [1])
46+
@test_throws ArgumentError reduced(comp_b1, [])
47+
48+
comp1 = tensor(b1, b2, b3)
49+
comp2 = tensor(b2, b1, b3)
50+
@test permutesystems(comp1, [2,1,3]) == comp2
51+
52+
@test !equal_bases([b1, b2], [b1, b3])
53+
@test !multiplicable(comp1, b1 b2 NLevelBasis(prod(b3.shape)))
54+
55+
end # testset

0 commit comments

Comments
 (0)