diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 7be0ac87c0..95f8e1ddd1 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -263,6 +263,11 @@ This fix enables automatic qubit management to be used with gradients. + +* Fixed the :func:`~.passes.commute_ppr` pass incorrectly modifying operands of PPRs that live in + different blocks. + [(#2267)](https://github.com/PennyLaneAI/catalyst/pull/2267) + * The `--inline-nested-module` pass no longer renames external function declarations. [(#2244)](https://github.com/PennyLaneAI/catalyst/pull/2244) diff --git a/mlir/lib/QEC/Transforms/CommutePPR.cpp b/mlir/lib/QEC/Transforms/CommutePPR.cpp index 2aa3541e14..9bd20375fb 100644 --- a/mlir/lib/QEC/Transforms/CommutePPR.cpp +++ b/mlir/lib/QEC/Transforms/CommutePPR.cpp @@ -132,7 +132,11 @@ void moveCliffordPastNonClifford(const PauliStringWrapper &lhsPauli, // Update the use of value in newRHSOperands for (unsigned i = 0; i < newRHSOperands.size(); i++) { - newRHSOperands[i].replaceAllUsesExcept(nonCliffordOp.getOutQubits()[i], nonCliffordOp); + newRHSOperands[i].replaceUsesWithIf( + nonCliffordOp.getOutQubits()[i], [&](OpOperand &operand) { + return operand.getOwner() != nonCliffordOp && + operand.getOwner()->getBlock() == lhs->getBlock(); + }); } rewriter.replaceOp(rhs, rhs.getInQubits());