def test_rank(self, bond_dim, cyclic): psi = qu.rand_matrix_product_state( 10, bond_dim, cyclic=cyclic) rhoa = qu.ptr(psi, [2] * 10, [0, 1, 2, 3]) el = qu.eigvalsh(rhoa) # bond_dim squared as cyclic mps is generated assert sum(el > 1e-12) == bond_dim ** (2 if cyclic else 1)
def test_half_filling_groundstate(self): H = qu.ham_hubbard_hardcore(8, t=0.5, V=1.0, mu=1.0) gs = qu.groundstate(H) dims = [2] * 8 cn = qu.num(2) ens = [qu.expec(cn, qu.ptr(gs, dims, i)) for i in range(8)] for en in ens: assert en == pytest.approx(0.5, rel=1e-6)
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)
def one_qubit_dm(self, qstate, i): ''' Returns subsystem density matrix for qubit i by tracing out all other qubits in `qstate`. `qstate` needs to be in *full* qubit space! ''' assert qstate.size == qu.prod(self._sim_dims) return qu.ptr(qstate, dims=self._sim_dims, keep=i)
def test_mutinf_subsys(self): p = qu.rand_ket(2**9) dims = (2**3, 2**2, 2**4) # exact rho_ab = qu.ptr(p, dims, [0, 2]) mi0 = qu.mutual_information(rho_ab, [8, 16]) mi1 = qu.mutinf_subsys(p, dims, sysa=0, sysb=2, approx_thresh=1e30) assert_allclose(mi1, mi0) # approx mi2 = qu.mutinf_subsys(p, dims, sysa=0, sysb=2, approx_thresh=1) assert_allclose(mi1, mi2, rtol=0.1)
def test_entanglement(self): rho = qu.rand_seperable([2, 3, 2], 10) assert_allclose(qu.tr(rho), 1.0) assert qu.isherm(rho) assert qu.logneg(rho, [2, 6]) < 1e-12 assert qu.logneg(rho, [6, 2]) < 1e-12 rho_a = qu.ptr(rho, [2, 3, 2], 1) el = qu.eigvalsh(rho_a) assert np.all(el < 1 - 1e-12) assert np.all(el > 1e-12)
def test_entanglement(self): rho = rand_seperable([2, 3, 2], 10) assert_almost_equal(tr(rho), 1.0) assert isherm(rho) assert logneg(rho, [2, 6]) < 1e-12 assert logneg(rho, [6, 2]) < 1e-12 rho_a = ptr(rho, [2, 3, 2], 1) el = eigvals(rho_a) assert np.all(el < 1 - 1e-12) assert np.all(el > 1e-12)
def test_logneg_subsys(self): p = qu.rand_ket(2**(2 + 3 + 1 + 2)) dims = (2**2, 2**3, 2**1, 2**2) sysa = [0, 3] sysb = 1 # exact 1 ln0 = qu.logneg(qu.ptr(p, dims, [0, 1, 3]), [4, 8, 4], [0, 2]) # exact 2 ln1 = qu.logneg_subsys(p, dims, sysa, sysb, approx_thresh=1e30) assert_allclose(ln0, ln1) # approx ln2 = qu.logneg_subsys(p, dims, sysa, sysb, approx_thresh=1) assert ln1 != ln2 assert_allclose(ln1, ln2, rtol=5e-2)
def test_mixed_sub(self, inds): a = qu.rand_rho(2**3) rho_ab = qu.ptr(a, [2, 2, 2], inds) ixy = qu.mutual_information(rho_ab, (2, 2)) assert (0 <= ixy <= 2.0)
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_bell_state_singlet(self): p = singlet(qtype="dop", sparse=True) assert_allclose(expec(p, p), 1.0) pa = ptr(p, [2, 2], 0) assert_allclose(expec(pa, pa), 0.5)