diff --git a/qiskit/quantum_info/operators/symplectic/base_pauli.py b/qiskit/quantum_info/operators/symplectic/base_pauli.py index 755f41181c86..dbadb7dde7c5 100644 --- a/qiskit/quantum_info/operators/symplectic/base_pauli.py +++ b/qiskit/quantum_info/operators/symplectic/base_pauli.py @@ -689,5 +689,5 @@ def _count_y(x, z, dtype=None): """Count the number of I Pauli's""" axis = 1 if dtype is None: - dtype = np.min_scalar_type(x.shape[axis]) + dtype = np.int64(x.shape[axis]) return (x & z).sum(axis=axis, dtype=dtype) diff --git a/releasenotes/notes/fix_evolve_raises_exception_in_Cliffordcircuits-46453dfbef7ac2e2.yaml b/releasenotes/notes/fix_evolve_raises_exception_in_Cliffordcircuits-46453dfbef7ac2e2.yaml new file mode 100644 index 000000000000..c757be7427e2 --- /dev/null +++ b/releasenotes/notes/fix_evolve_raises_exception_in_Cliffordcircuits-46453dfbef7ac2e2.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - | + Fixed an issue with the a bug in the BasePauli/Pauli classes where the phase vector is sometimes set as + dtype uint8 instead of int64 leading to errors when calling the evolve function for circuits containing + gates that modify the pauli phase vector. + The dtype of the phase vector should always be the same, so that evolution and other methods that attempt + to inplace modify the vector don't cause exceptions for mismatched dtypes. + Fixed #8438 diff --git a/test/python/quantum_info/operators/symplectic/test_pauli.py b/test/python/quantum_info/operators/symplectic/test_pauli.py index c952a3a8fb93..ca2ee564c7b4 100644 --- a/test/python/quantum_info/operators/symplectic/test_pauli.py +++ b/test/python/quantum_info/operators/symplectic/test_pauli.py @@ -434,6 +434,19 @@ def test_barrier_delay_sim(self): value = Pauli(circ) self.assertEqual(value, target) + def test_evolve_clifford_with_phase(self): + """Create circuit with gate that modifies Pauli phase""" + qc = QuantumCircuit(2) + qc.cz(0, 1) + op = Operator(qc) + + pauli = random_pauli(2, seed=123) + + value = Operator(pauli.evolve(qc)) + target = op.adjoint().dot(pauli).dot(op) + + self.assertEqual(value, target) + if __name__ == "__main__": unittest.main()