Skip to content
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel

### Added

- ✨ Add initial infrastructure for new QC and QCO MLIR dialects ([#1264], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1475]) ([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**])
- ✨ Add initial infrastructure for new QC and QCO MLIR dialects ([#1264], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1474], [#1475]) ([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**])

### Changed

Expand Down Expand Up @@ -327,6 +327,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool

[#1481]: https://github.com/munich-quantum-toolkit/core/pull/1481
[#1475]: https://github.com/munich-quantum-toolkit/core/pull/1475
[#1474]: https://github.com/munich-quantum-toolkit/core/pull/1474
[#1472]: https://github.com/munich-quantum-toolkit/core/pull/1472
[#1471]: https://github.com/munich-quantum-toolkit/core/pull/1471
[#1470]: https://github.com/munich-quantum-toolkit/core/pull/1470
Expand Down
4 changes: 4 additions & 0 deletions mlir/include/mlir/Dialect/QCO/IR/QCODialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ template <size_t T, size_t P> class TargetAndParameterArityTrait {
}
return this->getOperation()->getOperand(i);
}
OperandRange getInputQubits() {
return this->getOperation()->getOperands().slice(0, T);
}
Value getOutputQubit(size_t i) {
if constexpr (T == 0) {
llvm::reportFatalUsageError("Operation does not have qubits");
Expand All @@ -89,6 +92,7 @@ template <size_t T, size_t P> class TargetAndParameterArityTrait {
}
return this->getOperation()->getResult(i);
}
ResultRange getOutputQubits() { return this->getOperation()->getResults(); }

Value getInputTarget(const size_t i) { return getInputQubit(i); }
Value getOutputTarget(const size_t i) { return getOutputQubit(i); }
Expand Down
12 changes: 12 additions & 0 deletions mlir/include/mlir/Dialect/QCO/IR/QCOInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,20 @@ def UnitaryOpInterface : OpInterface<"UnitaryOpInterface"> {
"Returns the i-th input qubit (targets + controls combined).",
"Value", "getInputQubit", (ins "size_t":$i)
>,
InterfaceMethod<
"Returns a range of all input qubits (targets + controls combined).",
"OperandRange",
"getInputQubits", (ins)
>,
InterfaceMethod<
"Returns the i-th output qubit (targets + controls combined).",
"Value", "getOutputQubit", (ins "size_t":$i)
>,
InterfaceMethod<
"Returns a range of all output qubits (targets + controls combined).",
"ResultRange",
"getOutputQubits", (ins)
>,
Comment thread
taminob marked this conversation as resolved.
InterfaceMethod<
"Returns the i-th target input qubit.",
"Value", "getInputTarget", (ins "size_t":$i)
Expand Down Expand Up @@ -163,6 +173,8 @@ def UnitaryOpInterface : OpInterface<"UnitaryOpInterface"> {
"Returns the base symbol/mnemonic of the operation.",
"StringRef", "getBaseSymbol", (ins)
>,

// Unitary matrix helpers
InterfaceMethod<
"Populates the given 1x1 unitary matrix if possible.",
"bool", "getUnitaryMatrix1x1",
Expand Down
4 changes: 4 additions & 0 deletions mlir/include/mlir/Dialect/QCO/IR/QCOOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,9 @@ def BarrierOp : QCOOp<"barrier", traits = [UnitaryOpInterface]> {
size_t getNumTargets();
static size_t getNumControls();
Value getInputQubit(size_t i);
OperandRange getInputQubits();
Value getOutputQubit(size_t i);
ResultRange getOutputQubits();
Value getInputTarget(size_t i);
Value getOutputTarget(size_t i);
static Value getInputControl(size_t i);
Expand Down Expand Up @@ -1113,7 +1115,9 @@ def CtrlOp : QCOOp<"ctrl", traits =
size_t getNumTargets();
size_t getNumControls();
Value getInputQubit(size_t i);
OperandRange getInputQubits();
Value getOutputQubit(size_t i);
ResultRange getOutputQubits();
Value getInputTarget(size_t i);
Value getOutputTarget(size_t i);
Value getInputControl(size_t i);
Expand Down
8 changes: 6 additions & 2 deletions mlir/lib/Dialect/QCO/IR/Modifiers/CtrlOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,26 @@ Value CtrlOp::getInputQubit(const size_t i) {
return getControlsIn()[i];
}
if (numControls <= i && i < getNumQubits()) {
return getBodyUnitary().getInputQubit(i - numControls);
return getTargetsIn()[i - numControls];
Comment thread
burgholzer marked this conversation as resolved.
}
llvm::reportFatalUsageError("Invalid qubit index");
}

OperandRange CtrlOp::getInputQubits() { return this->getOperands(); }

Value CtrlOp::getOutputQubit(const size_t i) {
const auto numControls = getNumControls();
if (i < numControls) {
return getControlsOut()[i];
}
if (numControls <= i && i < getNumQubits()) {
return getBodyUnitary().getOutputQubit(i - numControls);
return getTargetsOut()[i - numControls];
}
llvm::reportFatalUsageError("Invalid qubit index");
}

ResultRange CtrlOp::getOutputQubits() { return this->getResults(); }

Value CtrlOp::getInputTarget(const size_t i) {
if (i >= getNumTargets()) {
llvm::reportFatalUsageError("Target index out of bounds");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ size_t BarrierOp::getNumControls() { return 0; }

Value BarrierOp::getInputQubit(const size_t i) { return getInputTarget(i); }

OperandRange BarrierOp::getInputQubits() { return getQubitsIn(); }

Value BarrierOp::getOutputQubit(const size_t i) { return getOutputTarget(i); }

ResultRange BarrierOp::getOutputQubits() { return getQubitsOut(); }

Value BarrierOp::getInputTarget(const size_t i) {
if (i < getNumTargets()) {
return getQubitsIn()[i];
Expand Down
Loading