Skip to content

Commit 3fa1455

Browse files
authored
Fix commute-ppr pass to correctly handle PPR's operands across different blocks (#2267)
**Description of the Change:** This update addresses an issue where the `commute_ppr` pass incorrectly modified the operands of PPRs across different blocks or regions. The logic has been modified to ensure that PPRs are only moved within the same block. [[sc-105282]]
1 parent 7f7d4b6 commit 3fa1455

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

doc/releases/changelog-dev.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@
347347

348348
This fix enables automatic qubit management to be used with gradients.
349349

350+
351+
* Fixed the :func:`~.passes.commute_ppr` pass incorrectly modifying operands of PPRs that live in
352+
different blocks.
353+
[(#2267)](https://github.com/PennyLaneAI/catalyst/pull/2267)
354+
350355
* The `--inline-nested-module` pass no longer renames external function declarations.
351356
[(#2244)](https://github.com/PennyLaneAI/catalyst/pull/2244)
352357

mlir/lib/QEC/Transforms/CommutePPR.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ void moveCliffordPastNonClifford(const PauliStringWrapper &lhsPauli,
132132

133133
// Update the use of value in newRHSOperands
134134
for (unsigned i = 0; i < newRHSOperands.size(); i++) {
135-
newRHSOperands[i].replaceAllUsesExcept(nonCliffordOp.getOutQubits()[i], nonCliffordOp);
135+
newRHSOperands[i].replaceUsesWithIf(
136+
nonCliffordOp.getOutQubits()[i], [&](OpOperand &operand) {
137+
return operand.getOwner() != nonCliffordOp &&
138+
operand.getOwner()->getBlock() == lhs->getBlock();
139+
});
136140
}
137141

138142
rewriter.replaceOp(rhs, rhs.getInQubits());

0 commit comments

Comments
 (0)