Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PauliOp.adjoint() #9434

Merged
merged 4 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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