コード例 #1
0
 def test_from_index_list_same_index(self):
     """Test from_list via Pauli + number of qubits raises correctly, if indices duplicate."""
     with self.assertRaises(QiskitError):
         _ = SparsePauliOp.from_sparse_list([("ZZ", [0, 0], 1)], 2)
     with self.assertRaises(QiskitError):
         _ = SparsePauliOp.from_sparse_list([("ZI", [0, 0], 1)], 2)
     with self.assertRaises(QiskitError):
         _ = SparsePauliOp.from_sparse_list([("IZ", [0, 0], 1)], 2)
コード例 #2
0
 def test_from_index_list(self):
     """Test from_list method specifying the Paulis via indices."""
     expected_labels = ["XXZ", "IXI", "YIZ", "III"]
     paulis = ["XXZ", "X", "YZ", ""]
     indices = [[2, 1, 0], [1], [2, 0], []]
     coeffs = [3.0, 5.5, -1j, 23.3333]
     spp_op = SparsePauliOp.from_sparse_list(zip(paulis, indices, coeffs), num_qubits=3)
     np.testing.assert_array_equal(spp_op.coeffs, coeffs)
     self.assertEqual(spp_op.paulis, PauliList(expected_labels))
コード例 #3
0
 def test_from_index_list_raises(self):
     """Test from_list via Pauli + indices raises correctly, if number of qubits invalid."""
     with self.assertRaises(QiskitError):
         _ = SparsePauliOp.from_sparse_list([("Z", [2], 1)], 1)
コード例 #4
0
 def test_from_index_list_endianness(self):
     """Test the construction from index list has the right endianness."""
     spp_op = SparsePauliOp.from_sparse_list([("ZX", [1, 4], 1)],
                                             num_qubits=5)
     expected = Pauli("XIIZI")
     self.assertEqual(spp_op.paulis[0], expected)