def test_partial_trace_return_type(self): a = qu.qu([0, 2**-0.5, 2**-0.5, 0], 'ket') b = qu.partial_trace(a, [2, 2], 1) assert (type(b) == qu.qarray) a = qu.qu([0, 2**-0.5, 2**-0.5, 0], 'dop') b = qu.partial_trace(a, [2, 2], 1) assert (type(b) == qu.qarray)
def test_partial_trace_return_type(self): a = qu([0, 2**-0.5, 2**-0.5, 0], 'ket') b = partial_trace(a, [2, 2], 1) assert(type(b) == np.matrix) a = qu([0, 2**-0.5, 2**-0.5, 0], 'dop') b = partial_trace(a, [2, 2], 1) assert(type(b) == np.matrix)
def test_partial_trace_early_return(self): a = qu.qu([0.5, 0.5, 0.5, 0.5], 'ket') b = qu.partial_trace(a, [2, 2], [0, 1]) assert_allclose(a @ a.H, b) a = qu.qu([0.5, 0.5, 0.5, 0.5], 'dop') b = qu.partial_trace(a, [2, 2], [0, 1]) assert_allclose(a, b)
def test_ptr_compare_to_manual(self): a = qu.rand_rho(2**2) b = qu.partial_trace(a, [2, 2], 0) c = a.A.reshape([2, 2, 2, 2]).trace(axis1=1, axis2=3) assert_allclose(b, c) b = qu.partial_trace(a, [2, 2], 1) c = a.A.reshape([2, 2, 2, 2]).trace(axis1=0, axis2=2) assert_allclose(b, c)
def test_vec_dense(self): a = rand_ket(4) b = _trace_lose(a, [2, 2], 1) c = partial_trace(a.A, [2, 2], 0) assert_allclose(b, c) b = _trace_lose(a, [2, 2], 0) c = partial_trace(a.A, [2, 2], 1) assert_allclose(b, c)
def test_vs_ptr(self): a = rand_rho(6, sparse=True, density=0.5) b = _trace_lose(a, [2, 3], 1) c = partial_trace(a.A, [2, 3], 0) assert_allclose(b, c) b = _trace_lose(a, [2, 3], 0) c = partial_trace(a.A, [2, 3], 1) assert_allclose(b, c)
def test_partial_trace_single_ket(self): dims = [2, 3, 4] a = np.random.randn(qu.prod(dims), 1) for i, dim in enumerate(dims): b = qu.partial_trace(a, dims, i) assert (b.shape[0] == dim)
def test_partial_trace_basic(self): a = qu.rand_rho(2**2) b = qu.partial_trace(a, [2, 2], 0) assert isinstance(b, qu.qarray) assert qu.isherm(b) assert_allclose(qu.tr(b), 1.0)
def test_partial_trace_simple_ket(self): a = rand_ket(12, sparse=True, density=0.5) dims = [2, 3, 2] b = partial_trace(a, dims, [0, 1]) c = partial_trace(a.A, dims, [0, 1]) assert_allclose(b, c)
def test_partial_trace_sparse_basic(self): a = rand_rho(4) b = partial_trace(a, [2, 2], 0) assert type(b) == np.matrix assert isherm(b) assert_allclose(tr(b), 1.0)
def test_partial_trace_basic(self): a = rand_rho(2**2) b = partial_trace(a, [2, 2], 0) assert isinstance(b, np.matrix) assert isherm(b) assert_allclose(tr(b), 1.0)