def test_pauli_reconstruct(self): p1 = qu.rand_rho(4) names_cffs = qu.pauli_decomp(p1, mode='c') pr = sum( qu.kron(*(qu.pauli(s) for s in name)) * names_cffs["".join(name)] for name in itertools.product('IXYZ', repeat=2)) assert_allclose(pr, p1)
def test_pauli_decomp_singlet(self, qtype): p = qu.singlet(qtype=qtype) names_cffs = qu.pauli_decomp(p, mode='cp') assert_allclose(names_cffs['II'], 0.25) assert_allclose(names_cffs['ZZ'], -0.25) assert_allclose(names_cffs['YY'], -0.25) assert_allclose(names_cffs['ZZ'], -0.25) for name in itertools.permutations('IXYZ', 2): assert_allclose(names_cffs["".join(name)], 0.0)
def test_multisubsystem(self): qu.seed_rand(42) dims = [2, 2, 2] IIX = qu.ikron(qu.rand_herm(2), dims, 2) dcmp = qu.pauli_decomp(IIX, mode='c') for p, x in dcmp.items(): if x == 0j: assert (p[0] != 'I') or (p[1] != 'I') else: assert p[0] == p[1] == 'I' K = qu.rand_iso(3 * 4, 4).reshape(3, 4, 4) KIIXK = qu.kraus_op(IIX, K, dims=dims, where=[0, 2]) dcmp = qu.pauli_decomp(KIIXK, mode='c') for p, x in dcmp.items(): if x == 0j: assert p[1] != 'I' else: assert p[1] == 'I'