示例#1
0
 def test_ndarrays(self):
     a = rand_matrix(2)
     i = eye(2)
     b = eyepad([a], np.array([2, 2, 2]), [0, 2])
     assert_allclose(b, a & i & a)
     b = eyepad([a], [2, 2, 2], np.array([0, 2]))
     assert_allclose(b, a & i & a)
示例#2
0
 def test_sparse(self):
     i = eye(2, sparse=True)
     a = qu(rand_matrix(2), sparse=True)
     b = eyepad(a, [2, 2, 2], 1)  # infer sparse
     assert(issparse(b))
     assert_allclose(b.A, (i & a & i).A)
     a = rand_matrix(2)
     b = eyepad(a, [2, 2, 2], 1, sparse=True)  # explicit sparse
     assert(issparse(b))
     assert_allclose(b.A, (i & a & i).A)
示例#3
0
 def test_overlap(self):
     a = [rand_matrix(4) for i in range(2)]
     dims1 = [2, 2, 2, 2, 2, 2]
     dims2 = [2, 4, 4, 2]
     b = eyepad(a, dims1, [1, 2, 3, 4])
     c = eyepad(a, dims2, [1, 2])
     assert_allclose(c, b)
     dims2 = [4, 2, 2, 4]
     b = eyepad(a, dims1, [0, 1, 4, 5])
     c = eyepad(a, dims2, [0, 3])
     assert_allclose(c, b)
示例#4
0
 def test_basic(self):
     a = rand_matrix(2)
     i = eye(2)
     dims = [2, 2, 2]
     b = eyepad([a], dims, [0])
     assert_allclose(b, a & i & i)
     b = eyepad([a], dims, [1])
     assert_allclose(b, i & a & i)
     b = eyepad([a], dims, [2])
     assert_allclose(b, i & i & a)
     b = eyepad([a], dims, [0, 2])
     assert_allclose(b, a & i & a)
     b = eyepad([a], dims, [0, 1, 2])
     assert_allclose(b, a & a & a)
示例#5
0
 def test_2d_simple(self):
     a = (rand_matrix(2), rand_matrix(2))
     dims = ((2, 3), (3, 2))
     inds = ((0, 0), (1, 1))
     b = eyepad(a, dims, inds)
     assert b.shape == (36, 36)
     assert_allclose(b, a[0] & eye(9) & a[1])
示例#6
0
 def test_mid_multi_reverse(self):
     a = [rand_matrix(2) for i in range(3)]
     i = eye(2)
     dims = [2, 2, 2, 2, 2, 2]
     inds = [5, 4, 1]
     b = eyepad(a, dims, inds)
     assert_allclose(b, i & a[2] & i & i & a[1] & a[0])
示例#7
0
 def test_graph_state_1d(self):
     n = 5
     p = graph_state_1d(n, cyclic=True)
     for j in range(n):
         k = eyepad(
             [pauli('x'), pauli('z'), pauli('z')], [2] * n,
             (j, (j - 1) % n, (j + 1) % n))
         o = p.H @ k @ p
         np.testing.assert_allclose(o, 1)
示例#8
0
 def test_quevo_at_times(self):
     ham = ham_heis(2, cyclic=False)
     p0 = up() & down()
     sim = QuEvo(p0, ham, method='solve')
     ts = np.linspace(0, 10)
     for t, pt in zip(ts, sim.at_times(ts)):
         x = cos(t)
         y = expec(pt, eyepad(pauli('z'), [2, 2], 0))
         assert_allclose(x, y, atol=1e-15)
示例#9
0
 def test_sparse_format_outputs_with_dense(self, od1, stype, pos,
                                           coo_build):
     x = eyepad(od1, [3, 3, 3], pos, sparse=True,
                stype=stype, coo_build=coo_build)
     try:
         default = "bsr" if (2 in pos and not coo_build) else "csr"
     except TypeError:
         default = "bsr" if (pos == 2 and not coo_build) else "csr"
     assert x.format == default if stype is None else stype
示例#10
0
 def test_holey_overlap(self):
     a = rand_matrix(8)
     dims1 = (2, 2, 2, 2, 2)
     dims2 = (2, 8, 2)
     b = eyepad(a, dims1, (1, 3))
     c = eyepad(a, dims2, 1)
     assert_allclose(b, c)
     dims1 = (2, 2, 2, 2, 2)
     dims2 = (2, 2, 8)
     b = eyepad(a, dims1, (2, 4))
     c = eyepad(a, dims2, 2)
     assert_allclose(b, c)
     dims1 = (2, 2, 2, 2, 2)
     dims2 = (8, 2, 2)
     b = eyepad(a, dims1, (0, 2))
     c = eyepad(a, dims2, 0)
     assert_allclose(b, c)
示例#11
0
 def test_sparse_format_outputs(self, os1, stype, pos, coo_build):
     x = eyepad(os1, [3, 3, 3], pos,
                stype=stype, coo_build=coo_build)
     assert x.format == "csr" if stype is None else stype
示例#12
0
 def test_auto(self):
     a = rand_matrix(2)
     i = eye(2)
     b = eyepad([a], (2, -1, 2), [1])
     assert_allclose(b, i & a & i)