示例#1
0
 def test_simple(self):
     Z = qu.pauli('Z')
     P = qu.projector(Z & Z)
     uu = qu.dop(qu.up()) & qu.dop(qu.up())
     dd = qu.dop(qu.down()) & qu.dop(qu.down())
     assert_allclose(P, uu + dd)
     assert qu.expec(P, qu.bell_state('phi+')) == pytest.approx(1.0)
     assert qu.expec(P, qu.bell_state('psi+')) == pytest.approx(0.0)
示例#2
0
 def test_block2_no_self_ent(self):
     p = qu.bell_state('phi+') & qu.bell_state('phi+')
     ecm = qu.ent_cross_matrix(p,
                               ent_fn=qu.logneg,
                               calc_self_ent=False,
                               sz_blc=2)
     assert_allclose(ecm[0, 1], 0)
     assert_allclose(ecm[0, 0], np.nan)
     assert_allclose(ecm[1, 0], 0)
示例#3
0
 def test_reuse_precomp(self):
     cfn = qu.correlation(None,
                          qu.pauli('z'),
                          qu.pauli('z'),
                          0,
                          1,
                          dims=[2, 2],
                          precomp_func=True)
     assert_allclose(cfn(qu.bell_state('psi-')), -1.0)
     assert_allclose(cfn(qu.bell_state('phi+')), 1.0)
示例#4
0
 def test_block2_upscale(self):
     p = bell_state('phi+') & bell_state('phi+')
     ecm = ent_cross_matrix(p, ent_fn=logneg, calc_self_ent=False, sz_blc=2)
     assert ecm.shape == (2, 2)
     ecm = ent_cross_matrix(p,
                            ent_fn=logneg,
                            calc_self_ent=False,
                            sz_blc=2,
                            upscale=True)
     assert ecm.shape == (4, 4)
示例#5
0
文件: test_core.py 项目: zizai/quimb
 def test_entangled_permute(self):
     dims = [2, 2, 2]
     a = qu.bell_state(0) & qu.up()
     assert_allclose(qu.mutinf_subsys(a, dims, 0, 1), 2.)
     b = qu.permute(a, dims, [1, 2, 0])
     assert_allclose(qu.mutinf_subsys(b, dims, 0, 1), 0., atol=1e-12)
     assert_allclose(qu.mutinf_subsys(b, dims, 0, 2), 2.)
示例#6
0
 def test_bell_state(self):
     p = bell_state('psi-')
     assert_allclose(schmidt_gap(p, [2, 2], 0), 0.0)
     p = up() & down()
     assert_allclose(schmidt_gap(p, [2, 2], 0), 1.0)
     p = rand_ket(2**3)
     assert 0 < schmidt_gap(p, [2] * 3, sysa=[0, 1]) < 1.0
示例#7
0
 def test_bell_state(self):
     p = qu.bell_state('psi-')
     assert_allclose(qu.schmidt_gap(p, [2, 2], 0), 0.0)
     p = qu.up() & qu.down()
     assert_allclose(qu.schmidt_gap(p, [2, 2], 0), 1.0)
     p = qu.rand_ket(2**3)
     assert 0 < qu.schmidt_gap(p, [2] * 3, sysa=[0, 1]) < 1.0
示例#8
0
 def test_partial_transpose(self):
     a = bell_state(0, qtype='dop')
     b = partial_transpose(a)
     assert isinstance(b, np.matrix)
     assert_allclose(
         b,
         [[0, 0, 0, -0.5], [0, 0.5, 0, 0], [0, 0, 0.5, 0], [-0.5, 0, 0, 0]])
示例#9
0
 def test_mutual_information_pure_sub(self):
     a = qu.up() & qu.bell_state(1)
     ixy = qu.mutual_information(a, [2, 2, 2], 0, 1)
     assert_allclose(0.0, ixy, atol=1e-12)
     ixy = qu.mutual_information(a, [2, 2, 2], 0, 2)
     assert_allclose(0.0, ixy, atol=1e-12)
     ixy = qu.mutual_information(a, [2, 2, 2], 2, 1)
     assert_allclose(2.0, ixy, atol=1e-12)
示例#10
0
 def test_partial_transpose(self):
     a = qu.bell_state(0, qtype='dop')
     b = qu.partial_transpose(a)
     assert isinstance(b, qu.qarray)
     assert_allclose(
         b,
         np.array([[0, 0, 0, -0.5], [0, 0.5, 0, 0], [0, 0, 0.5, 0],
                   [-0.5, 0, 0, 0]]))
示例#11
0
 def test_bell_states(self):
     for s, dic in zip(("psi-", "psi+", "phi+", "phi-"), ({
             "qtype": 'dop'
     }, {}, {
             "sparse": True
     }, {})):
         p = bell_state(s, **dic)
         assert_allclose(expec(p, p), 1.0)
         pa = ptr(p, [2, 2], 0)
         assert_allclose(expec(pa, pa), 0.5)
示例#12
0
 def test_entangled(self, s, ct, pre_c):
     p = qu.bell_state('psi-')
     c = qu.correlation(p,
                        qu.pauli(s),
                        qu.pauli(s),
                        0,
                        1,
                        precomp_func=pre_c)
     c = c(p) if pre_c else c
     assert_allclose(c, ct)
示例#13
0
 def test_mixed(self):
     rho = qu.dop(qu.bell_state('psi-'))
     IZ = qu.pauli('I') & qu.pauli('Z')
     ZI = qu.pauli('Z') & qu.pauli('I')
     res, rho_after = qu.measure(rho, IZ)
     # normalized
     assert qu.tr(rho_after) == pytest.approx(1.0)
     # anticorrelated
     assert qu.expectation(rho_after, IZ) == pytest.approx(res)
     assert qu.expectation(rho_after, ZI) == pytest.approx(-res)
     assert isinstance(rho_after, qu.qarray)
示例#14
0
 def test_pure(self):
     psi = qu.bell_state('psi-')
     IZ = qu.pauli('I') & qu.pauli('Z')
     ZI = qu.pauli('Z') & qu.pauli('I')
     res, psi_after = qu.measure(psi, IZ)
     # normalized
     assert qu.expectation(psi_after, psi_after) == pytest.approx(1.0)
     # anticorrelated
     assert qu.expectation(psi_after, IZ) == pytest.approx(res)
     assert qu.expectation(psi_after, ZI) == pytest.approx(-res)
     assert isinstance(psi_after, qu.qarray)
示例#15
0
 def test_owci(self):
     a = qu.qu([1, 0], qtype='op')
     b = qu.qu([0, 1], qtype='op')
     for _ in (0, 1, 2, 3):
         p = qu.rand_product_state(2)
         ci = qu.one_way_classical_information(p @ p.H, [a, b])
         assert_allclose(ci, 0., atol=1e-12)
     for i in (0, 1, 2, 3):
         p = qu.bell_state(i)
         ci = qu.one_way_classical_information(p @ p.H, [a, b])
         assert_allclose(ci, 1., atol=1e-12)
示例#16
0
 def test_bell_states(self, qtype, bs):
     p = qu.bell_state(bs, qtype=qtype)
     assert qu.logneg(p) > 1.0 - 1e-14
示例#17
0
 def test_d2(self):
     rho = qu.eye(2) / 2
     psi = qu.purify(rho)
     assert qu.expec(psi, qu.bell_state('phi+')) > 1 - 1e-14
示例#18
0
 def test_bell_state(self, bs, pre_c):
     p = qu.bell_state(bs)
     qids = qu.qid(p, dims=[2, 2], inds=[0, 1], precomp_func=pre_c)
     assert_allclose(qids(p) if pre_c else qids, [3, 3])
示例#19
0
 def test_entropy_mixed(self):
     a = 0.5 * (qu.bell_state(1, qtype='dop') +
                qu.bell_state(2, qtype='dop'))
     assert_allclose(1.0, qu.entropy(a), atol=1e-12)
示例#20
0
 def test_block2(self):
     p = qu.bell_state('phi+') & qu.bell_state('phi+')
     ecm = qu.ent_cross_matrix(p, ent_fn=qu.logneg, sz_blc=2)
     assert_allclose(ecm[1, 1], 0)
     assert_allclose(ecm[0, 1], 0)
     assert_allclose(ecm[1, 0], 0)
示例#21
0
 def test_bell_state_no_self_ent(self):
     p = qu.bell_state('phi+')
     ecm = qu.ent_cross_matrix(p,
                               ent_fn=qu.concurrence,
                               calc_self_ent=False)
     assert_allclose(ecm, [[np.nan, 1], [1, np.nan]])
示例#22
0
 def test_bell_state(self):
     p = qu.bell_state('phi+')
     ecm = qu.ent_cross_matrix(p, ent_fn=qu.concurrence, calc_self_ent=True)
     assert_allclose(ecm, [[1, 1], [1, 1]])
示例#23
0
 def test_pauli_correlations_no_sum_abs(self, pre_c):
     p = qu.bell_state('psi-')
     ct = qu.pauli_correlations(p, sum_abs=False, precomp_func=pre_c)
     assert_allclose(list(c(p) for c in ct) if pre_c else ct, (-1, -1, -1))
示例#24
0
 def test_pauli_correlations_sum_abs(self, pre_c):
     p = qu.bell_state('psi-')
     ct = qu.pauli_correlations(p, sum_abs=True, precomp_func=pre_c)
     ct = ct(p) if pre_c else ct
     assert_allclose(ct, 3.0)
示例#25
0
 def test_entropy_pure(self):
     a = qu.bell_state(1, qtype='dop')
     assert_allclose(0.0, qu.entropy(a), atol=1e-12)
示例#26
0
 def test_mutual_information_pure(self):
     a = qu.bell_state(0)
     assert_allclose(qu.mutual_information(a), 2.)
     a = qu.rand_product_state(2)
     assert_allclose(qu.mutual_information(a), 0., atol=1e-12)
示例#27
0
文件: test_core.py 项目: zizai/quimb
 def test_partial_trace_bell_states(self):
     for lab in ('psi-', 'psi+', 'phi-', 'phi+'):
         psi = qu.bell_state(lab, qtype='dop')
         rhoa = qu.partial_trace(psi, [2, 2], 0)
         assert_allclose(rhoa, qu.eye(2) / 2)
示例#28
0
 def test_simple(self, qtype, bs):
     p = qu.bell_state(bs, qtype=qtype)
     assert qu.negativity(p) > 0.5 - 1e-14
示例#29
0
文件: test_core.py 项目: zizai/quimb
 def test_bell_state(self):
     a = qu.bell_state('psi-', sparse=True)
     b = qu.core._trace_keep(a @ a.H, [2, 2], 0)
     assert_allclose(b, qu.eye(2) / 2)
     b = qu.core._trace_keep(a @ a.H, [2, 2], 1)
     assert_allclose(b, qu.eye(2) / 2)
示例#30
0
 def test_bell_states(self, qtype, bs):
     p = qu.bell_state(bs, qtype=qtype)
     assert qu.concurrence(p) > 1.0 - 1e-14