Skip to content

Commit

Permalink
Fix PauliOp.adjoint() (#9434) (#9443)
Browse files Browse the repository at this point in the history
* bug fix

* reno mod

* reno mod

* Update releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml

Co-authored-by: Julien Gacon <gaconju@gmail.com>

Co-authored-by: Julien Gacon <gaconju@gmail.com>
(cherry picked from commit 85c30a2)

Co-authored-by: Kazuki Tsuoka <kazukitsuoka@g.ecc.u-tokyo.ac.jp>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mergify[bot] and king-p3nguin authored Jan 24, 2023
1 parent 740e388 commit 7171e83
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion qiskit/opflow/primitive_ops/pauli_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/Qiskit/qiskit-terra/issues/9433>`.
4 changes: 4 additions & 0 deletions test/python/opflow/test_op_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7171e83

Please sign in to comment.