def test_composite_oper(): """ Composite: Tests compositing unitaries and superoperators. """ U1 = rand_unitary(3) U2 = rand_unitary(5) S1 = to_super(U1) S2 = to_super(U2) S3 = rand_super(4) S4 = rand_super(7) assert_(composite(U1, U2) == tensor(U1, U2)) assert_(composite(S3, S4) == super_tensor(S3, S4)) assert_(composite(U1, S4) == super_tensor(S1, S4)) assert_(composite(S3, U2) == super_tensor(S3, S2))
def test_composite_vec(): """ Composite: Tests compositing states and density operators. """ k1 = rand_ket(5) k2 = rand_ket(7) r1 = operator_to_vector(ket2dm(k1)) r2 = operator_to_vector(ket2dm(k2)) r3 = operator_to_vector(rand_dm(3)) r4 = operator_to_vector(rand_dm(4)) assert_(composite(k1, k2) == tensor(k1, k2)) assert_(composite(r3, r4) == super_tensor(r3, r4)) assert_(composite(k1, r4) == super_tensor(r1, r4)) assert_(composite(r3, k2) == super_tensor(r3, r2))
def test_stinespring_dims(self, dimension): """ Stinespring: Check that dims of channels are preserved. """ chan = super_tensor(to_super(sigmax()), to_super(qeye(dimension))) A, B = to_stinespring(chan) assert A.dims == [[2, dimension, 1], [2, dimension]] assert B.dims == [[2, dimension, 1], [2, dimension]]
def test_stinespring_dims(self): """ Stinespring: Check that dims of channels are preserved. """ # FIXME: not the most general test, since this assumes a map # from square matrices to square matrices on the same space. chan = super_tensor(to_super(sigmax()), to_super(qeye(3))) A, B = to_stinespring(chan) assert_equal(A.dims, [[2, 3, 1], [2, 3]]) assert_equal(B.dims, [[2, 3, 1], [2, 3]])
def test_super_tensor_property(): """ Tensor: Super_tensor correctly tensors on underlying spaces. """ U1 = rand_unitary(3) U2 = rand_unitary(5) U = tensor(U1, U2) S_tens = to_super(U) S_supertens = super_tensor(to_super(U1), to_super(U2)) assert_(S_tens == S_supertens) assert_equal(S_supertens.superrep, 'super')
def test_SuperChoiChiSuper(self): """ Superoperator: Converting two-qubit superoperator through Choi and chi representations goes back to right superoperator. """ superoperator = super_tensor(rand_super(2), rand_super(2)) choi_matrix = to_choi(superoperator) chi_matrix = to_chi(choi_matrix) test_supe = to_super(chi_matrix) # Assert both that the result is close to expected, and has the right # type. assert_((test_supe - superoperator).norm() < tol) assert_(choi_matrix.type == "super" and choi_matrix.superrep == "choi") assert_(chi_matrix.type == "super" and chi_matrix.superrep == "chi") assert_(test_supe.type == "super" and test_supe.superrep == "super")