diff --git a/qiskit/opflow/primitive_ops/pauli_op.py b/qiskit/opflow/primitive_ops/pauli_op.py index ff1c20f19924..1699275ef52a 100644 --- a/qiskit/opflow/primitive_ops/pauli_op.py +++ b/qiskit/opflow/primitive_ops/pauli_op.py @@ -84,7 +84,7 @@ def add(self, other: OperatorBase) -> OperatorBase: return SummedOp([self, other]) def adjoint(self) -> "PauliOp": - return PauliOp(self.primitive, coeff=self.coeff.conjugate()) + return PauliOp(self.primitive.adjoint(), coeff=self.coeff.conjugate()) def equals(self, other: OperatorBase) -> bool: if isinstance(other, PauliOp) and self.coeff == other.coeff: diff --git a/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml b/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml new file mode 100644 index 000000000000..d9860f702700 --- /dev/null +++ b/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixed a bug where :meth:`.PauliOp.adjoint` did not return a correct value for Paulis + with complex coefficients, like ``PauliOp(Pauli("iX"))``. + Fixed `#9433 `. diff --git a/test/python/opflow/test_op_construction.py b/test/python/opflow/test_op_construction.py index d797c566b9a4..fd474f3942ef 100644 --- a/test/python/opflow/test_op_construction.py +++ b/test/python/opflow/test_op_construction.py @@ -1288,6 +1288,10 @@ def test_adjoint(self): expected = PauliOp(Pauli("XYZX"), coeff=2 - 3j) self.assertEqual(~pauli_op, expected) + pauli_op = PauliOp(Pauli("iXYZX"), coeff=2 + 3j) + expected = PauliOp(Pauli("-iXYZX"), coeff=2 - 3j) + self.assertEqual(~pauli_op, expected) + @data(*itertools.product(pauli_group_labels(2, full_group=True), repeat=2)) @unpack def test_compose(self, label1, label2):