Repository: Qiskit/qiskit

Issue:
Clifford.from_operator does not fail with non-Clifford diagonal operator
### Environment

- **Qiskit Terra version**: 0.25.1
- **Python version**: 3.10
- **Operating system**: Mac OS


### What is happening?

`Clifford.from_operator` (`from_matrix`) does not fail with non-Clifford diagonal operator (matrix) and returns an incorrect Clifford object.

### How can we reproduce the issue?

Run `Clifford.from_operator(Operator(RZZGate(0.2)))`

### What should happen?

The code should raise an error.

### Any suggestions?

_No response_


Discussion:

Resolving patch:
diff --git a/qiskit/quantum_info/operators/symplectic/clifford.py b/qiskit/quantum_info/operators/symplectic/clifford.py
--- a/qiskit/quantum_info/operators/symplectic/clifford.py
+++ b/qiskit/quantum_info/operators/symplectic/clifford.py
@@ -1004,9 +1004,10 @@ def _pauli_matrix_to_row(mat, num_qubits):
         """Generate a binary vector (a row of tableau representation) from a Pauli matrix.
         Return None if the non-Pauli matrix is supplied."""
         # pylint: disable=too-many-return-statements
+        decimals = 6
 
-        def find_one_index(x, decimals=6):
-            indices = np.where(np.round(np.abs(x), decimals) == 1)
+        def find_one_index(x):
+            indices = np.where(np.round(np.abs(x), decimals=decimals) == 1)
             return indices[0][0] if len(indices[0]) == 1 else None
 
         def bitvector(n, num_bits):
@@ -1018,7 +1019,7 @@ def bitvector(n, num_bits):
             return None
         xbits = bitvector(xint, num_qubits)
 
-        # extract non-zero elements from matrix (rounded to 1, -1, 1j or -1j)
+        # extract non-zero elements from matrix (each must be 1, -1, 1j or -1j for Pauli matrix)
         entries = np.empty(len(mat), dtype=complex)
         for i, row in enumerate(mat):
             index = find_one_index(row)
@@ -1027,7 +1028,9 @@ def bitvector(n, num_bits):
             expected = xint ^ i
             if index != expected:
                 return None
-            entries[i] = np.round(mat[i, index])
+            entries[i] = np.round(mat[i, index], decimals=decimals)
+            if entries[i] not in {1, -1, 1j, -1j}:
+                return None
 
         # compute z-bits
         zbits = np.empty(num_qubits, dtype=bool)


Test patch:
diff --git a/test/python/quantum_info/operators/symplectic/test_clifford.py b/test/python/quantum_info/operators/symplectic/test_clifford.py
--- a/test/python/quantum_info/operators/symplectic/test_clifford.py
+++ b/test/python/quantum_info/operators/symplectic/test_clifford.py
@@ -1068,6 +1068,12 @@ def test_from_matrix_round_trip(self, num_qubits):
             actual = Clifford.from_matrix(expected.to_matrix())
             self.assertEqual(expected, actual)
 
+    def test_from_non_clifford_diagonal_operator(self):
+        """Test if failing with non-clifford diagonal operator.
+        See https://github.com/Qiskit/qiskit/issues/10903"""
+        with self.assertRaises(QiskitError):
+            Clifford.from_operator(Operator(RZZGate(0.2)))
+
     @combine(num_qubits=[1, 2, 3, 4])
     def test_from_operator_round_trip(self, num_qubits):
         """Test round trip conversion to and from operator"""