Ejemplo n.º 1
0
    def setUp(self):
        super().setUp()
        seed = 0
        aqua_globals.random_seed = seed

        self.num_qubits = 3
        m_size = np.power(2, self.num_qubits)
        matrix = aqua_globals.random.random((m_size, m_size))
        self.qubit_op = MatrixOperator(matrix=matrix)
Ejemplo n.º 2
0
    def setUp(self):
        super().setUp()
        seed = 0
        aqua_globals.random_seed = seed

        self.num_qubits = 2
        m_size = np.power(2, self.num_qubits)
        matrix = aqua_globals.random.random((m_size, m_size))
        self.mat_op = MatrixOperator(matrix=matrix)
        paulis = [Pauli("".join(pauli_label))
                  for pauli_label in itertools.product('IXYZ', repeat=self.num_qubits)]
        weights = aqua_globals.random.random(len(paulis))
        self.pauli_op = WeightedPauliOperator.from_list(paulis, weights)
Ejemplo n.º 3
0
class TestMatrixOperator(QiskitOpflowTestCase):
    """MatrixOperator tests."""
    def setUp(self):
        super().setUp()
        seed = 0
        aqua_globals.random_seed = seed

        self.num_qubits = 3
        m_size = np.power(2, self.num_qubits)
        matrix = aqua_globals.random.random((m_size, m_size))
        self.qubit_op = MatrixOperator(matrix=matrix)

    def test_num_qubits(self):
        """ num qubits test """
        op = MatrixOperator(matrix=np.zeros((2, 2)))
        self.assertEqual(op.num_qubits, 0)
        self.assertEqual(self.qubit_op.num_qubits, self.num_qubits)

    def test_is_empty(self):
        """ is empty test """
        op = MatrixOperator(matrix=np.zeros((2, 2)))
        self.assertTrue(op.is_empty())
        self.assertFalse(self.qubit_op.is_empty())
Ejemplo n.º 4
0
    def test_invalid_primitive(self):
        """Test invalid MatrixOp construction"""
        msg = "MatrixOp can only be instantiated with " \
              "['list', 'ndarray', 'spmatrix', 'Operator'], not "

        with self.assertRaises(TypeError) as cm:
            _ = MatrixOp('invalid')

        self.assertEqual(str(cm.exception), msg + "'str'")

        with self.assertRaises(TypeError) as cm:
            _ = MatrixOp(MatrixOperator(np.eye(2)))

        self.assertEqual(str(cm.exception), msg + "'MatrixOperator'")

        with self.assertRaises(TypeError) as cm:
            _ = MatrixOp(None)

        self.assertEqual(str(cm.exception), msg + "'NoneType'")

        with self.assertRaises(TypeError) as cm:
            _ = MatrixOp(2.0)

        self.assertEqual(str(cm.exception), msg + "'float'")
Ejemplo n.º 5
0
 def test_is_empty(self):
     """ is empty test """
     op = MatrixOperator(matrix=np.zeros((2, 2)))
     self.assertTrue(op.is_empty())
     self.assertFalse(self.qubit_op.is_empty())
Ejemplo n.º 6
0
 def test_num_qubits(self):
     """ num qubits test """
     op = MatrixOperator(matrix=np.zeros((2, 2)))
     self.assertEqual(op.num_qubits, 0)
     self.assertEqual(self.qubit_op.num_qubits, self.num_qubits)