Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed ValueRange to ResultRange and Value to OpResult in Gate_Op #1426

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
* `from_plxpr` now uses the `qml.capture.PlxprInterpreter` class for reduced code duplication.
[(#1398)](https://github.com/PennyLaneAI/catalyst/pull/1398)

* Replace `ValueRange` with `ResultRange` and `Value` with `OpResult` to better align with the semantics of `**QubitResult()` functions like `getNonCtrlQubitResults()`. This change ensures clearer intent and usage. Improve the `matchAndRewrite` function by using `replaceAllUsesWith` instead of for loop.
[(#1426)](https://github.com/PennyLaneAI/catalyst/pull/1426)

<h3>Documentation 📝</h3>

<h3>Contributors ✍️</h3>
Expand All @@ -28,4 +31,4 @@ This release contains contributions from (in alphabetical order):

Christina Lee
Mehrdad Malekmohammadi

Sengthai Heng
6 changes: 3 additions & 3 deletions mlir/include/Quantum/IR/QuantumInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def QuantumOperation : OpInterface<"QuantumOperation"> {
>,
InterfaceMethod<
"Return all results which are considered output qubit values (including controls).",
"std::vector<mlir::Value>", "getQubitResults"
"std::vector<mlir::OpResult>", "getQubitResults"
>
];

Expand Down Expand Up @@ -109,7 +109,7 @@ def QuantumGate : OpInterface<"QuantumGate", [QuantumOperation]> {
>,
InterfaceMethod<
"Return results which are considered non-controlled output qubit values.",
"mlir::ValueRange", "getNonCtrlQubitResults"
"mlir::ResultRange", "getNonCtrlQubitResults"
>,
InterfaceMethod<
"Return all operands which are considered controlling input qubit values.",
Expand All @@ -129,7 +129,7 @@ def QuantumGate : OpInterface<"QuantumGate", [QuantumOperation]> {
>,
InterfaceMethod<
"Return all operands which are considered controlling output qubit values.",
"mlir::ValueRange", "getCtrlQubitResults"
"mlir::ResultRange", "getCtrlQubitResults"
sengthai marked this conversation as resolved.
Show resolved Hide resolved
>,
InterfaceMethod<
"Return adjoint flag.",
Expand Down
12 changes: 6 additions & 6 deletions mlir/include/Quantum/IR/QuantumOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ class Gate_Op<string mnemonic, list<Trait> traits = []> :
qubits.assign(replacements);
}

std::vector<mlir::Value> getQubitResults() {
std::vector<mlir::Value> values;
std::vector<mlir::OpResult> getQubitResults() {
std::vector<mlir::OpResult> values;
values.insert(values.end(), getOutQubits().begin(), getOutQubits().end());
return values;
}
Expand Down Expand Up @@ -242,8 +242,8 @@ class UnitaryGate_Op<string mnemonic, list<Trait> traits = []> :
ctrls.assign(replacements.take_back(ctrls.size()));
}

std::vector<mlir::Value> getQubitResults() {
std::vector<mlir::Value> values;
std::vector<mlir::OpResult> getQubitResults() {
std::vector<mlir::OpResult> values;
values.insert(values.end(), getOutQubits().begin(), getOutQubits().end());
values.insert(values.end(), getOutCtrlQubits().begin(), getOutCtrlQubits().end());
return values;
Expand Down Expand Up @@ -283,10 +283,10 @@ class UnitaryGate_Op<string mnemonic, list<Trait> traits = []> :
"must provide values for all control qubit values");
ctrls.assign(replacements);
}
mlir::ValueRange getNonCtrlQubitResults() {
mlir::ResultRange getNonCtrlQubitResults() {
return getOutQubits();
}
mlir::ValueRange getCtrlQubitResults() {
mlir::ResultRange getCtrlQubitResults() {
return getOutCtrlQubits();
}
}];
Expand Down
13 changes: 7 additions & 6 deletions mlir/lib/Quantum/Transforms/ChainedSelfInversePatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,13 @@ struct ChainedUUadjOpRewritePattern : public mlir::OpRewritePattern<OpType> {
// Replace uses
ValueRange originalNonCtrlQubits = parentOp.getNonCtrlQubitOperands();
ValueRange originalCtrlQubits = parentOp.getCtrlQubitOperands();
for (const auto &[idx, nonCtrlQubitResult] : llvm::enumerate(op.getNonCtrlQubitResults())) {
nonCtrlQubitResult.replaceAllUsesWith(originalNonCtrlQubits[idx]);
}
for (const auto &[idx, ctrlQubitResult] : llvm::enumerate(op.getCtrlQubitResults())) {
ctrlQubitResult.replaceAllUsesWith(originalCtrlQubits[idx]);
}

ResultRange nonCtrlQubitResults = op.getNonCtrlQubitResults();
nonCtrlQubitResults.replaceAllUsesWith(originalNonCtrlQubits);

ResultRange ctrlQubitResults = op.getCtrlQubitResults();
ctrlQubitResults.replaceAllUsesWith(originalCtrlQubits);

return success();
}
};
Expand Down