Repository: PennyLaneAI/pennylane
Pull request #6971 (2025-02-16 21:02:26)

add pauli_rep for adjoint op 
**Context:** #6876

**Description of the Change:** add pauli_rep property for adjoint operation

**Benefits:** pauli_rep property is available after adjoint operation

**Possible Drawbacks:** impact downstream functions that relies on pauli_rep 

**Related GitHub Issues:** #6876


albi3ro: Thanks for opening this PR @Hazarre 🚀 .

Can you create a changelog entry at [`doc/releases/changelog-dev.md`](https://github.com/PennyLaneAI/pennylane/blob/master/doc/releases/changelog-dev.md) under "Improvements", and add your name to the list of contributors at the bottom?

Once you mark the PR "Ready for review", I can approve the full CI to run.
Hazarre: > Thanks for opening this PR @Hazarre 🚀 .
> 
> Can you create a changelog entry at [`doc/releases/changelog-dev.md`](https://github.com/PennyLaneAI/pennylane/blob/master/doc/releases/changelog-dev.md) under "Improvements", and add your name to the list of contributors at the bottom?
> 
> Once you mark the PR "Ready for review", I can approve the full CI to run.

@albi3ro Thanks for the guide. I added change log and formatted code. PR is ready for review.
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/6971?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 99.60%. Comparing base [(`ed30bf4`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/ed30bf4721d40daecd876354e7c8552f7a532429?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI) to head [(`90799cc`)](https://app.codecov.io/gh/PennyLaneAI/pennylane/commit/90799cce3160abc6f168b3adeaec57b43a2cbdb4?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).
> Report is 9 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff            @@
##           master    #6971    +/-   ##
========================================
  Coverage   99.59%   99.60%            
========================================
  Files         481      481            
  Lines       45783    45918   +135     
========================================
+ Hits        45598    45735   +137     
+ Misses        185      183     -2     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/PennyLaneAI/pennylane/pull/6971?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=PennyLaneAI).


Patch:
diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md
index cb5a0aef5..f0b9f989e 100644
--- a/doc/releases/changelog-dev.md
+++ b/doc/releases/changelog-dev.md
@@ -35,6 +35,9 @@
 
 <h3>Improvements 🛠</h3>
 
+* `pauli_rep` property is now accessible for `Adjoint` operator when there is a Pauli representation.
+  [(#6871)](https://github.com/PennyLaneAI/pennylane/pull/6871)
+
 * `qml.SWAP` now has sparse representation.
   [(#6965)](https://github.com/PennyLaneAI/pennylane/pull/6965)
 
@@ -401,6 +404,7 @@
 This release contains contributions from (in alphabetical order):
 
 Utkarsh Azad,
+Henry Chang,
 Yushao Chen,
 Isaac De Vlugt,
 Diksha Dhawan,
diff --git a/pennylane/ops/op_math/adjoint.py b/pennylane/ops/op_math/adjoint.py
index a6b83185a..25f0def4e 100644
--- a/pennylane/ops/op_math/adjoint.py
+++ b/pennylane/ops/op_math/adjoint.py
@@ -356,6 +356,11 @@ class Adjoint(SymbolicOp):
     def __init__(self, base=None, id=None):
         self._name = f"Adjoint({base.name})"
         super().__init__(base, id=id)
+        if self.base.pauli_rep:
+            pr = {pw: qml.math.conjugate(coeff) for pw, coeff in self.base.pauli_rep.items()}
+            self._pauli_rep = qml.pauli.PauliSentence(pr)
+        else:
+            self._pauli_rep = None
 
     def __repr__(self):
         return f"Adjoint({self.base})"


Test patch:
diff --git a/tests/ops/op_math/test_adjoint.py b/tests/ops/op_math/test_adjoint.py
index b72d6055c..751114013 100644
--- a/tests/ops/op_math/test_adjoint.py
+++ b/tests/ops/op_math/test_adjoint.py
@@ -320,6 +320,15 @@ class TestProperties:
         assert op.batch_size == 3
         assert op.ndim_params == (0,)
 
+    def test_pauli_rep(self):
+        """Test pauli_rep works after adjoint operation."""
+        coeffs = [1 - 0.5j, 0.2, -3j]
+        paulis = [qml.X(0), qml.Y(0), qml.Z(0)]
+        op = qml.dot(coeffs, paulis)
+        adjoint_ps = qml.adjoint(op).pauli_rep
+        assert (list(adjoint_ps.values()) == qml.math.conjugate(coeffs)).all()
+        assert (qml.adjoint(adjoint_ps.operation()).matrix() == op.matrix()).all()
+
 
 class TestSimplify:
     """Test Adjoint simplify method and depth property."""