Exemplo n.º 1
0
 def test_density_matrix_evolve(self):
     orig = qi.random_density_matrix(2, seed=10)
     compat = cqi.DensityMatrix(orig.data)
     orig_op = qi.random_unitary(2, seed=10)
     compat_op = cqi.Operator(orig_op.data)
     target = orig.evolve(orig_op)
     self.assertEqual(orig.evolve(compat_op), target)
     self.assertEqual(compat.evolve(orig_op), target)
     self.assertEqual(compat.evolve(compat_op), target)
Exemplo n.º 2
0
 def test_statevector_evolve(self):
     orig = qi.random_statevector(2, seed=10)
     compat = cqi.Statevector(orig.data)
     orig_op = qi.random_unitary(2, seed=10)
     compat_op = cqi.Operator(orig_op.data)
     target = orig.evolve(orig_op)
     self.assertEqual(orig.evolve(compat_op), target)
     self.assertEqual(compat.evolve(orig_op), target)
     self.assertEqual(compat.evolve(compat_op), target)
Exemplo n.º 3
0
    def test_unitary_iterable_methods(self):
        """Test that the iterable magic methods and related Numpy properties
        work on the compatibility classes."""
        compat = cqi.Operator(qi.random_unitary(2, seed=10))
        compat_data = compat.data

        with self.assertWarns(DeprecationWarning):
            compat_len = len(compat)
        self.assertEqual(compat_len, len(compat_data))
        with self.assertWarns(DeprecationWarning):
            compat_shape = compat.shape
        self.assertEqual(compat_shape, compat_data.shape)
        with self.assertWarns(DeprecationWarning):
            compat_iter = tuple(compat)
        np.testing.assert_array_equal(compat_iter, compat.data)
Exemplo n.º 4
0
 def test_unitary_evolve(self):
     orig = qi.random_unitary(2, seed=10)
     compat = cqi.Operator(orig.data)
     state = qi.random_statevector(2, seed=10)
     target = state.evolve(orig)
     self.assertEqual(state.evolve(compat), target)
Exemplo n.º 5
0
 def test_unitary_compose(self):
     orig = qi.random_unitary(2, seed=10)
     compat = cqi.Operator(orig.data)
     target = orig.compose(orig)
     self.assertEqual(compat.compose(orig), target)
     self.assertEqual(orig.compose(compat), target)
Exemplo n.º 6
0
 def test_unitary_linop(self):
     orig = qi.random_unitary(4, seed=10)
     compat = cqi.Operator(orig.data)
     self.assertEqual(2 * compat - orig, orig)
     self.assertEqual(2 * orig - compat, orig)
Exemplo n.º 7
0
 def test_unitary_copy(self):
     compat = cqi.Operator([[1, 0], [1e-10, 1]])
     cpy = copy.copy(compat)
     self.assertEqual(cpy, compat)
Exemplo n.º 8
0
 def test_unitary_getattr(self):
     compat = cqi.Operator([[1, 0], [1e-10, 1]])
     with self.assertWarns(DeprecationWarning):
         value = compat.round(5)
     self.assertEqual(type(value), np.ndarray)
     self.assertTrue(np.all(value == np.eye(2)))
Exemplo n.º 9
0
 def test_unitary_eq(self):
     orig = qi.random_unitary(4, seed=10)
     compat = cqi.Operator(orig.data)
     self.assertEqual(compat, orig)
     self.assertEqual(orig, compat)