From 45a2498cf2941b8fc57690b77cb47d02f3b4aea0 Mon Sep 17 00:00:00 2001 From: king-p3nguin Date: Tue, 24 Jan 2023 01:04:34 +0900 Subject: [PATCH 1/4] bug fix --- qiskit/opflow/primitive_ops/pauli_op.py | 2 +- .../notes/fix-PauliOp-adjoint-a275876185df989f.yaml | 6 ++++++ test/python/opflow/test_op_construction.py | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml 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..0ff470528acc --- /dev/null +++ b/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes a bug that ``PauliOp.adjoint()`` does not return correct value. Refer to + `#12345 ` for more + details. 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): From 96f9d935e45c7931543020b2c64b46eabc4ec3a3 Mon Sep 17 00:00:00 2001 From: king-p3nguin Date: Tue, 24 Jan 2023 01:07:44 +0900 Subject: [PATCH 2/4] reno mod --- releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml b/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml index 0ff470528acc..ad47d82d8f5d 100644 --- a/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml +++ b/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml @@ -1,6 +1,6 @@ --- fixes: - | - Fixes a bug that ``PauliOp.adjoint()`` does not return correct value. Refer to - `#12345 ` for more + Fixes a bug that ``PauliOp.adjoint()`` does not a return correct value. Refer to + `#9433 ` for more details. From 092cf07a1876cf804d3792fb941dc5ada722406e Mon Sep 17 00:00:00 2001 From: king-p3nguin Date: Tue, 24 Jan 2023 01:08:47 +0900 Subject: [PATCH 3/4] reno mod --- releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml b/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml index ad47d82d8f5d..729e78d1d708 100644 --- a/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml +++ b/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml @@ -1,6 +1,6 @@ --- fixes: - | - Fixes a bug that ``PauliOp.adjoint()`` does not a return correct value. Refer to + Fixes a bug that ``PauliOp.adjoint()`` does not return a correct value. Refer to `#9433 ` for more details. From 9d5e843e979b7a44e6910b721c25393171bd818c Mon Sep 17 00:00:00 2001 From: Kazuki Tsuoka Date: Tue, 24 Jan 2023 21:30:00 +0900 Subject: [PATCH 4/4] Update releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml Co-authored-by: Julien Gacon --- .../notes/fix-PauliOp-adjoint-a275876185df989f.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml b/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml index 729e78d1d708..d9860f702700 100644 --- a/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml +++ b/releasenotes/notes/fix-PauliOp-adjoint-a275876185df989f.yaml @@ -1,6 +1,6 @@ --- fixes: - | - Fixes a bug that ``PauliOp.adjoint()`` does not return a correct value. Refer to - `#9433 ` for more - details. + Fixed a bug where :meth:`.PauliOp.adjoint` did not return a correct value for Paulis + with complex coefficients, like ``PauliOp(Pauli("iX"))``. + Fixed `#9433 `.