From 00d5ac65d2a74a7550b85ceb3b1fdff413337f5b Mon Sep 17 00:00:00 2001 From: sengthai Date: Thu, 4 Dec 2025 15:34:00 -0500 Subject: [PATCH 1/3] Fix commute_ppr pass to correctly handle PPRs across different blocks/regions --- doc/releases/changelog-dev.md | 5 +++++ mlir/lib/QEC/Transforms/CommutePPR.cpp | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 52cf9a06a5..e53c36036a 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 moving PPRs that live in + different blocks/regions. + [(#2260)](https://github.com/PennyLaneAI/catalyst/pull/2260) +

Internal changes ⚙️

* Resource tracking now writes out at device destruction time instead of qubit deallocation diff --git a/mlir/lib/QEC/Transforms/CommutePPR.cpp b/mlir/lib/QEC/Transforms/CommutePPR.cpp index 2aa3541e14..902a546d92 100644 --- a/mlir/lib/QEC/Transforms/CommutePPR.cpp +++ b/mlir/lib/QEC/Transforms/CommutePPR.cpp @@ -15,6 +15,7 @@ #define DEBUG_TYPE "commute-ppr" #include "mlir/Analysis/TopologicalSortUtils.h" +#include "mlir/IR/Dominance.h" #include "QEC/IR/QECOpInterfaces.h" #include "QEC/IR/QECOps.h" @@ -132,7 +133,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()); From 668fe56568cf4ad77787a39e5647347ba9418489 Mon Sep 17 00:00:00 2001 From: sengthai Date: Thu, 4 Dec 2025 15:37:33 -0500 Subject: [PATCH 2/3] update changelog --- doc/releases/changelog-dev.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index e53c36036a..89b31a2d10 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -263,10 +263,9 @@ This fix enables automatic qubit management to be used with gradients. - -* Fixed the :func:`~.passes.commute_ppr` pass incorrectly moving PPRs that live in - different blocks/regions. - [(#2260)](https://github.com/PennyLaneAI/catalyst/pull/2260) +* 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)

Internal changes ⚙️

From 6221195073b1f2bcf90c21a2960c067a43e97b61 Mon Sep 17 00:00:00 2001 From: sengthai Date: Thu, 4 Dec 2025 17:09:01 -0500 Subject: [PATCH 3/3] remove unnessary header --- mlir/lib/QEC/Transforms/CommutePPR.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/mlir/lib/QEC/Transforms/CommutePPR.cpp b/mlir/lib/QEC/Transforms/CommutePPR.cpp index 902a546d92..9bd20375fb 100644 --- a/mlir/lib/QEC/Transforms/CommutePPR.cpp +++ b/mlir/lib/QEC/Transforms/CommutePPR.cpp @@ -15,7 +15,6 @@ #define DEBUG_TYPE "commute-ppr" #include "mlir/Analysis/TopologicalSortUtils.h" -#include "mlir/IR/Dominance.h" #include "QEC/IR/QECOpInterfaces.h" #include "QEC/IR/QECOps.h"