Skip to content

Commit ff9f6d8

Browse files
author
alexander papageorge
committed
more tests for composite bases
1 parent d61d107 commit ff9f6d8

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

test/test_operators.jl

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,45 @@ b_comp = b⊗b
7070
@test_throws bases.IncompatibleBases embed(b_comp, [[1,2],3], [op,op2])
7171
@test_throws bases.IncompatibleBases embed(b_comp, [[1,3],4], [op,op2])
7272

73+
function basis_vec(n, N)
74+
x = zeros(Complex{Float64}, N)
75+
x[n+1] = 1
76+
return x
77+
end
78+
function basis_maker(dims...)
79+
function bm(ns...)
80+
bases = [basis_vec(n, dim) for (n, dim) in zip(ns, dims)][end:-1:1]
81+
return reduce(kron, bases)
82+
end
83+
end
84+
85+
embed_op = embed(b_comp, [1,4], op)
86+
bv = basis_maker(3,2,3,2)
87+
all_idxs = [(idx, jdx) for (idx, jdx) in [Iterators.product(0:1, 0:2)...]]
88+
89+
m11 = reshape([Bra(b_comp, bv(0,idx,jdx,0)) * embed_op * Ket(b_comp, bv(0,kdx,ldx,0))
90+
for ((idx, jdx), (kdx, ldx)) in Iterators.product(all_idxs, all_idxs)], (6,6))
91+
@test isapprox(m11 / op.data[1, 1], diagm(0=>ones(Complex{Float64}, 6)))
92+
93+
m21 = reshape([Bra(b_comp, bv(1,idx,jdx,0)) * embed_op * Ket(b_comp, bv(0,kdx,ldx,0))
94+
for ((idx, jdx), (kdx, ldx)) in Iterators.product(all_idxs, all_idxs)], (6,6))
95+
@test isapprox(m21 / op.data[2,1], diagm(0=>ones(Complex{Float64}, 6)))
96+
97+
m12 = reshape([Bra(b_comp, bv(0,idx,jdx,0)) * embed_op * Ket(b_comp, bv(1,kdx,ldx,0))
98+
for ((idx, jdx), (kdx, ldx)) in Iterators.product(all_idxs, all_idxs)], (6,6))
99+
@test isapprox(m12 / op.data[1,2], diagm(0=>ones(Complex{Float64}, 6)))
100+
101+
73102
b_comp = b_compb_comp
74103
OP_test1 = dense(tensor([op1,one(b2),op,one(b1),one(b2),op1,one(b2)]...))
75104
OP_test2 = embed(b_comp, [1,[3,4],7], [op1,op,op1])
76-
OP_dif_data = (OP_test1 - OP_test2).data
77-
@test real(sum(abs.(OP_dif_data))) < 1e-10
105+
@test isapprox(OP_test1.data, OP_test2.data)
78106

79107
b8 = b2b2b2
80108
cnot = [1 0 0 0; 0 1 0 0; 0 0 0 1; 0 0 1 0]
81109
op_cnot = DenseOperator(b2b2, cnot)
82110
OP_cnot = embed(b8, [1,3], op_cnot)
83-
@assert ptrace(OP_cnot, [2])/2. == op_cnot
111+
@test ptrace(OP_cnot, [2])/2. == op_cnot
84112

85113
@test_throws ErrorException QuantumOptics.operators.gemm!()
86114
@test_throws ErrorException QuantumOptics.operators.gemv!()

0 commit comments

Comments
 (0)