def test_entropy_approx_many_body(self, psi_mb_abc, bsz): rho_ab = psi_mb_abc.ptr(DIMS_MB, [0, 1, 7, 8, 2, 3, 9]) actual_e = entropy(rho_ab) approx_e = entropy_subsys_approx(psi_mb_abc, DIMS_MB, [0, 1, 7, 8, 2, 3, 9], bsz=bsz) assert_allclose(actual_e, approx_e, rtol=2e-1)
def test_entropy_approx_simple(self, psi_abc, bsz): np.random.seed(42) rho_ab = psi_abc.ptr(DIMS, [0, 1]) actual_e = entropy(rho_ab) approx_e = entropy_subsys_approx(psi_abc, DIMS, [0, 1], bsz=bsz, R=20) assert_allclose(actual_e, approx_e, rtol=2e-1)
def test_entropy_matches_dense(self, method): p = MPS_rand_state(5, 32) p_dense = p.to_dense() real_svn = qu.entropy(p_dense.ptr([2] * 5, [0, 1, 2])) svn = (p ^ ...).entropy(('k0', 'k1', 'k2')) assert_allclose(real_svn, svn) # use tensor to left of bipartition p.canonize(2) t1 = p['I2'] left_inds = set(t1.inds) - set(p['I3'].inds) svn = (t1).entropy(left_inds, method=method) assert_allclose(real_svn, svn) # use tensor to right of bipartition p.canonize(3) t2 = p['I3'] left_inds = set(t2.inds) & set(p['I2'].inds) svn = (t2).entropy(left_inds, method=method) assert_allclose(real_svn, svn)
def test_rank(self, m): k = qu.rand_ket(2**4) pab = qu.ptr(k, [2, 2, 2, 2], range(m)) ef = qu.entropy(pab) er = qu.entropy(pab, rank=2**m) assert_allclose(ef, er)
def test_1darray(self, evals, e): assert_allclose(qu.entropy(np.asarray(evals)), e)
def test_list(self, evals, e): assert_allclose(qu.entropy(evals), e)
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)
def test_entropy_pure(self): a = qu.bell_state(1, qtype='dop') assert_allclose(0.0, qu.entropy(a), atol=1e-12)