def test_sparse_matrix_Y(self): term = QubitOperator(((0, 'Y'), )) sparse_operator = get_sparse_operator(term) self.assertEqual(list(sparse_operator.data), [1j, -1j]) self.assertEqual(list(sparse_operator.indices), [1, 0]) self.assertTrue(is_hermitian(sparse_operator))
def test_sparse_matrix_zero_5qubit(self): sparse_operator = get_sparse_operator(QubitOperator((), 0.0), 5) sparse_operator.eliminate_zeros() self.assertEqual(len(list(sparse_operator.data)), 0) self.assertEqual(sparse_operator.shape, (32, 32))
def test_sparse_matrix_error(self): with self.assertRaises(TypeError): _ = get_sparse_operator(1)
def test_sparse_matrix_quad(self): sparse_operator = get_sparse_operator(QuadOperator('q0'), trunc=self.d) self.assertTrue(numpy.allclose(sparse_operator.toarray(), self.q)) self.assertEqual(sparse_operator.shape, (self.d, self.d))
def test_sparse_matrix_ladder(self): sparse_operator = get_sparse_operator(BosonOperator('0'), trunc=self.d) self.assertTrue(numpy.allclose(sparse_operator.toarray(), self.b)) self.assertEqual(sparse_operator.shape, (self.d, self.d))
def test_sparse_matrix_zero_n_qubit(self): sparse_operator = get_sparse_operator(FermionOperator.zero(), 4) sparse_operator.eliminate_zeros() self.assertEqual(len(list(sparse_operator.data)), 0) self.assertEqual(sparse_operator.shape, (16, 16))
def test_sparse_matrix_identity_5qubit(self): sparse_operator = get_sparse_operator(QubitOperator(()), 5) self.assertEqual(list(sparse_operator.data), [1] * 32) self.assertEqual(sparse_operator.shape, (32, 32))