|
| 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 (b1⊗b2)^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