From f8cecac4ce876faef4f1336a9863288485ff48ea Mon Sep 17 00:00:00 2001 From: Daniel Haag <121057143+denialhaag@users.noreply.github.com> Date: Thu, 19 Mar 2026 12:29:06 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=8E=A8=20Format=20TableGen=20files=20?= =?UTF-8?q?using=20clang-format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 15 +- .../mlir/Conversion/JeffToQCO/JeffToQCO.td | 9 +- .../mlir/Conversion/QCOToJeff/QCOToJeff.td | 4 +- .../mlir/Conversion/QCOToQC/QCOToQC.td | 4 +- .../mlir/Conversion/QCToQCO/QCToQCO.td | 4 +- .../mlir/Conversion/QCToQIR/QCToQIR.td | 8 +- mlir/include/mlir/Dialect/QC/IR/QCDialect.td | 10 +- .../mlir/Dialect/QC/IR/QCInterfaces.td | 98 +- mlir/include/mlir/Dialect/QC/IR/QCOps.td | 674 ++++++++------ mlir/include/mlir/Dialect/QC/IR/QCTypes.td | 8 +- .../include/mlir/Dialect/QCO/IR/QCODialect.td | 10 +- .../mlir/Dialect/QCO/IR/QCOInterfaces.td | 202 ++-- mlir/include/mlir/Dialect/QCO/IR/QCOOps.td | 880 ++++++++++-------- mlir/include/mlir/Dialect/QCO/IR/QCOTypes.td | 8 +- .../mlir/Dialect/QCO/Transforms/Passes.td | 48 +- .../mlir/Dialect/QTensor/IR/QTensorDialect.td | 3 +- .../mlir/Dialect/QTensor/IR/QTensorOps.td | 199 ++-- 17 files changed, 1113 insertions(+), 1071 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f19b296e29..3815d30ee0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -104,7 +104,7 @@ repos: # Priority 1: Second-pass fixers - ## Clang-format the C++ part of the code base automatically + ## Format C++ files with clang-format - repo: https://github.com/pre-commit/mirrors-clang-format rev: v22.1.0 hooks: @@ -112,7 +112,16 @@ repos: types_or: [c++, c, cuda] priority: 1 - ## CMake format and lint the CMakeLists.txt files + ## Format TableGen files with clang-format + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v22.1.0 + hooks: + - id: clang-format + types_or: [file] + files: \.td$ + priority: 1 + + ## Format CMakeLists.txt files - repo: https://github.com/cheshirekow/cmake-format-precommit rev: v0.6.13 hooks: @@ -127,7 +136,7 @@ repos: rev: v3.8.1 hooks: - id: prettier - types_or: [yaml, markdown, html, css, scss, javascript, json] + types_or: [yaml, markdown, html, css, scss, javascript, json, json5] priority: 1 ## Python linting using ruff diff --git a/mlir/include/mlir/Conversion/JeffToQCO/JeffToQCO.td b/mlir/include/mlir/Conversion/JeffToQCO/JeffToQCO.td index 5a561215f2..2f1b655bb8 100644 --- a/mlir/include/mlir/Conversion/JeffToQCO/JeffToQCO.td +++ b/mlir/include/mlir/Conversion/JeffToQCO/JeffToQCO.td @@ -27,10 +27,9 @@ def JeffToQCO : Pass<"jeff-to-qco"> { - Support for multiple functions is currently limited }]; - let dependentDialects = [ - "mlir::arith::ArithDialect", - "mlir::math::MathDialect", - "mlir::tensor::TensorDialect", - "mlir::qco::QCODialect", + let dependentDialects = ["mlir::arith::ArithDialect", + "mlir::math::MathDialect", + "mlir::tensor::TensorDialect", + "mlir::qco::QCODialect", ]; } diff --git a/mlir/include/mlir/Conversion/QCOToJeff/QCOToJeff.td b/mlir/include/mlir/Conversion/QCOToJeff/QCOToJeff.td index 1c54ad9d15..d9d5a499d1 100644 --- a/mlir/include/mlir/Conversion/QCOToJeff/QCOToJeff.td +++ b/mlir/include/mlir/Conversion/QCOToJeff/QCOToJeff.td @@ -18,7 +18,5 @@ def QCOToJeff : Pass<"qco-to-jeff"> { Note that this pass is still in development as QCO and Jeff do not have full feature parity yet. }]; - let dependentDialects = [ - "mlir::jeff::JeffDialect", - ]; + let dependentDialects = ["mlir::jeff::JeffDialect"]; } diff --git a/mlir/include/mlir/Conversion/QCOToQC/QCOToQC.td b/mlir/include/mlir/Conversion/QCOToQC/QCOToQC.td index 1863f4c957..a773b3d5c2 100644 --- a/mlir/include/mlir/Conversion/QCOToQC/QCOToQC.td +++ b/mlir/include/mlir/Conversion/QCOToQC/QCOToQC.td @@ -16,7 +16,5 @@ def QCOToQC : Pass<"qco-to-qc"> { It handles the transformation of qubit values in QCO to qubit references in QC, ensuring that the semantics of quantum operations are preserved during the conversion process. }]; - let dependentDialects = [ - "mlir::qc::QCDialect", - ]; + let dependentDialects = ["mlir::qc::QCDialect"]; } diff --git a/mlir/include/mlir/Conversion/QCToQCO/QCToQCO.td b/mlir/include/mlir/Conversion/QCToQCO/QCToQCO.td index 46dfd45336..9ffd33d4f7 100644 --- a/mlir/include/mlir/Conversion/QCToQCO/QCToQCO.td +++ b/mlir/include/mlir/Conversion/QCToQCO/QCToQCO.td @@ -16,7 +16,5 @@ def QCToQCO : Pass<"qc-to-qco"> { It handles the transformation of qubit references in QC to qubit values in QCO, ensuring that the semantics of quantum operations are preserved during the conversion process. }]; - let dependentDialects = [ - "mlir::qco::QCODialect", - ]; + let dependentDialects = ["mlir::qco::QCODialect"]; } diff --git a/mlir/include/mlir/Conversion/QCToQIR/QCToQIR.td b/mlir/include/mlir/Conversion/QCToQIR/QCToQIR.td index dd76a403ca..704c2554e1 100644 --- a/mlir/include/mlir/Conversion/QCToQIR/QCToQIR.td +++ b/mlir/include/mlir/Conversion/QCToQIR/QCToQIR.td @@ -9,7 +9,8 @@ include "mlir/Pass/PassBase.td" def QCToQIR : Pass<"qc-to-qir"> { - let summary = "Lower the QC dialect to the LLVM dialect compliant with QIR 2.0"; + let summary = + "Lower the QC dialect to the LLVM dialect compliant with QIR 2.0"; let description = [{ This pass lowers all operations from the QC dialect to their equivalent operations in the LLVM dialect, ensuring compliance with the QIR 2.0 standard. @@ -44,8 +45,5 @@ def QCToQIR : Pass<"qc-to-qir"> { ``` }]; - - let dependentDialects = [ - "mlir::LLVM::LLVMDialect", - ]; + let dependentDialects = ["mlir::LLVM::LLVMDialect"]; } diff --git a/mlir/include/mlir/Dialect/QC/IR/QCDialect.td b/mlir/include/mlir/Dialect/QC/IR/QCDialect.td index bb3c95af1f..82c9a85399 100644 --- a/mlir/include/mlir/Dialect/QC/IR/QCDialect.td +++ b/mlir/include/mlir/Dialect/QC/IR/QCDialect.td @@ -12,11 +12,11 @@ include "mlir/IR/DialectBase.td" def QCDialect : Dialect { - let name = "qc"; + let name = "qc"; - let summary = "The QC (reference semantics) dialect for quantum computing."; + let summary = "The QC (reference semantics) dialect for quantum computing."; - let description = [{ + let description = [{ The QC dialect uses **reference semantics** where quantum operations modify qubits in place, similar to how hardware physically transforms quantum states. This model provides: @@ -35,9 +35,9 @@ def QCDialect : Dialect { ``` }]; - let cppNamespace = "::mlir::qc"; + let cppNamespace = "::mlir::qc"; - let useDefaultTypePrinterParser = 1; + let useDefaultTypePrinterParser = 1; } #endif // MLIR_DIALECT_QC_IR_QCDIALECT_TD diff --git a/mlir/include/mlir/Dialect/QC/IR/QCInterfaces.td b/mlir/include/mlir/Dialect/QC/IR/QCInterfaces.td index 7d2c86c3dd..6f77839a65 100644 --- a/mlir/include/mlir/Dialect/QC/IR/QCInterfaces.td +++ b/mlir/include/mlir/Dialect/QC/IR/QCInterfaces.td @@ -16,7 +16,7 @@ include "mlir/IR/OpBase.td" //===----------------------------------------------------------------------===// def UnitaryOpInterface : OpInterface<"UnitaryOpInterface"> { - let description = [{ + let description = [{ This interface provides a unified API for all operations that apply or produce a unitary transformation. This includes base gates, user-defined gates, modifier operations (control, inverse, power), and sequences. @@ -25,68 +25,48 @@ def UnitaryOpInterface : OpInterface<"UnitaryOpInterface"> { across all unitary operations in the QC dialect. }]; - let cppNamespace = "::mlir::qc"; + let cppNamespace = "::mlir::qc"; - let methods = [ - // Qubit accessors - InterfaceMethod< - "Returns the number of qubits acted on by the unitary operation.", - "size_t", "getNumQubits", (ins) - >, - InterfaceMethod< - "Returns the number of target qubits (excluding control qubits).", - "size_t", "getNumTargets", (ins) - >, - InterfaceMethod< - "Returns the number of control qubits (both positive and negative).", - "size_t", "getNumControls", (ins) - >, - InterfaceMethod< - "Returns the i-th qubit (targets + controls combined).", - "Value", "getQubit", (ins "size_t":$i) - >, - InterfaceMethod< - "Returns the i-th target qubit.", - "Value", "getTarget", (ins "size_t":$i) - >, - InterfaceMethod< - "Returns the i-th control qubit.", - "Value", "getControl", (ins "size_t":$i) - >, + let methods = [ + // Qubit accessors + InterfaceMethod< + "Returns the number of qubits acted on by the unitary operation.", + "size_t", "getNumQubits", (ins)>, + InterfaceMethod< + "Returns the number of target qubits (excluding control qubits).", + "size_t", "getNumTargets", (ins)>, + InterfaceMethod< + "Returns the number of control qubits (both positive and negative).", + "size_t", "getNumControls", (ins)>, + InterfaceMethod<"Returns the i-th qubit (targets + controls combined).", + "Value", "getQubit", (ins "size_t":$i)>, + InterfaceMethod<"Returns the i-th target qubit.", "Value", "getTarget", + (ins "size_t":$i)>, + InterfaceMethod<"Returns the i-th control qubit.", "Value", "getControl", + (ins "size_t":$i)>, - // Parameter handling - InterfaceMethod< - "Returns the number of parameters.", - "size_t", "getNumParams", (ins) - >, - InterfaceMethod< - "Returns the i-th parameter.", - "Value", "getParameter", (ins "size_t":$i) - >, + // Parameter handling + InterfaceMethod<"Returns the number of parameters.", "size_t", + "getNumParams", (ins)>, + InterfaceMethod<"Returns the i-th parameter.", "Value", "getParameter", + (ins "size_t":$i)>, - // Convenience methods - InterfaceMethod< - "Returns true if the operation has any control qubits, otherwise false.", - "bool", "isControlled", (ins), - [{ return $_op.getNumControls() > 0; }] - >, - InterfaceMethod< - "Returns true if the operation only acts on a single qubit.", - "bool", "isSingleQubit", (ins), - [{ return $_op.getNumQubits() == 1; }] - >, - InterfaceMethod< - "Returns true if the operation acts on two qubits.", - "bool", "isTwoQubit", (ins), - [{ return $_op.getNumQubits() == 2; }] - >, + // Convenience methods + InterfaceMethod<"Returns true if the operation has any control qubits, " + "otherwise false.", + "bool", "isControlled", (ins), + [{ return $_op.getNumControls() > 0; }]>, + InterfaceMethod< + "Returns true if the operation only acts on a single qubit.", "bool", + "isSingleQubit", (ins), [{ return $_op.getNumQubits() == 1; }]>, + InterfaceMethod<"Returns true if the operation acts on two qubits.", + "bool", "isTwoQubit", (ins), + [{ return $_op.getNumQubits() == 2; }]>, - // Identification - InterfaceMethod< - "Returns the base symbol/mnemonic of the operation.", - "StringRef", "getBaseSymbol", (ins) - >, - ]; + // Identification + InterfaceMethod<"Returns the base symbol/mnemonic of the operation.", + "StringRef", "getBaseSymbol", (ins)>, + ]; } #endif // MLIR_DIALECT_QC_IR_QCINTERFACES_TD diff --git a/mlir/include/mlir/Dialect/QC/IR/QCOps.td b/mlir/include/mlir/Dialect/QC/IR/QCOps.td index 8093095868..9ca5480d2f 100644 --- a/mlir/include/mlir/Dialect/QC/IR/QCOps.td +++ b/mlir/include/mlir/Dialect/QC/IR/QCOps.td @@ -23,16 +23,16 @@ include "mlir/Interfaces/SideEffectInterfaces.td" // Base Operation Classes //===----------------------------------------------------------------------===// -class QCOp traits = []> : - Op; +class QCOp traits = []> + : Op; //===----------------------------------------------------------------------===// // Resource Operations //===----------------------------------------------------------------------===// def AllocOp : QCOp<"alloc", [MemoryEffects<[MemAlloc]>]> { - let summary = "Allocate a qubit dynamically"; - let description = [{ + let summary = "Allocate a qubit dynamically"; + let description = [{ Allocates a new qubit dynamically and returns a reference to it. The qubit is initialized to the |0⟩ state. @@ -54,33 +54,32 @@ def AllocOp : QCOp<"alloc", [MemoryEffects<[MemAlloc]>]> { ``` }]; - let arguments = (ins OptionalAttr:$register_name, - OptionalAttr>:$register_size, - OptionalAttr>:$register_index); - let results = (outs QubitType:$result); - let assemblyFormat = [{ + let arguments = (ins OptionalAttr:$register_name, + OptionalAttr>:$register_size, + OptionalAttr>:$register_index); + let results = (outs QubitType:$result); + let assemblyFormat = [{ (`(` $register_name^ `,` $register_size `,` $register_index `)`)? attr-dict `:` type($result) }]; - let builders = [ - OpBuilder<(ins), [{ + let builders = [OpBuilder<(ins), [{ build($_builder, $_state, QubitType::get($_builder.getContext()), nullptr, nullptr, nullptr); }]>, - OpBuilder<(ins "::mlir::StringAttr":$register_name, - "::mlir::IntegerAttr":$register_size, - "::mlir::IntegerAttr":$register_index), [{ + OpBuilder<(ins "::mlir::StringAttr":$register_name, + "::mlir::IntegerAttr":$register_size, + "::mlir::IntegerAttr":$register_index), + [{ build($_builder, $_state, QubitType::get($_builder.getContext()), register_name, register_size, register_index); - }]> - ]; + }]>]; - let hasVerifier = 1; + let hasVerifier = 1; } def DeallocOp : QCOp<"dealloc", [MemoryEffects<[MemFree]>]> { - let summary = "Deallocate a qubit"; - let description = [{ + let summary = "Deallocate a qubit"; + let description = [{ Deallocates a qubit, releasing its resources. Example: @@ -89,15 +88,15 @@ def DeallocOp : QCOp<"dealloc", [MemoryEffects<[MemFree]>]> { ``` }]; - let arguments = (ins QubitType:$qubit); - let assemblyFormat = "$qubit attr-dict `:` type($qubit)"; + let arguments = (ins QubitType:$qubit); + let assemblyFormat = "$qubit attr-dict `:` type($qubit)"; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def StaticOp : QCOp<"static", [Pure]> { - let summary = "Retrieve a static qubit by index"; - let description = [{ + let summary = "Retrieve a static qubit by index"; + let description = [{ The `qc.static` operation produces an SSA value representing a qubit identified by a static index. This is useful for referring to fixed qubits in a quantum program or to hardware-mapped qubits. @@ -108,9 +107,9 @@ def StaticOp : QCOp<"static", [Pure]> { ``` }]; - let arguments = (ins ConfinedAttr:$index); - let results = (outs QubitType:$qubit); - let assemblyFormat = "$index attr-dict `:` type($qubit)"; + let arguments = (ins ConfinedAttr:$index); + let results = (outs QubitType:$qubit); + let assemblyFormat = "$index attr-dict `:` type($qubit)"; } //===----------------------------------------------------------------------===// @@ -118,8 +117,8 @@ def StaticOp : QCOp<"static", [Pure]> { //===----------------------------------------------------------------------===// def MeasureOp : QCOp<"measure"> { - let summary = "Measure a qubit in the computational basis"; - let description = [{ + let summary = "Measure a qubit in the computational basis"; + let description = [{ Measures a qubit in the computational (Z) basis, collapsing the state and returning a classical bit result. @@ -140,28 +139,27 @@ def MeasureOp : QCOp<"measure"> { ``` }]; - let arguments = (ins Arg:$qubit, - OptionalAttr:$register_name, - OptionalAttr>:$register_size, - OptionalAttr>:$register_index); - let results = (outs I1:$result); - let assemblyFormat = [{ + let arguments = (ins Arg:$qubit, + OptionalAttr:$register_name, + OptionalAttr>:$register_size, + OptionalAttr>:$register_index); + let results = (outs I1:$result); + let assemblyFormat = [{ (`(` $register_name^ `,` $register_size `,` $register_index `)`)? $qubit `:` type($qubit) `->` type($result) attr-dict }]; - let builders = [ - OpBuilder<(ins "Value":$qubit), [{ + let builders = [OpBuilder<(ins "Value":$qubit), [{ build($_builder, $_state, $_builder.getI1Type(), qubit, nullptr, nullptr, nullptr); - }]> - ]; + }]>]; - let hasVerifier = 1; + let hasVerifier = 1; } def ResetOp : QCOp<"reset"> { - let summary = "Reset a qubit to |0⟩ state"; - let description = [{ + let summary = "Reset a qubit to |0⟩ state"; + let description = [{ Resets a qubit to the |0⟩ state, regardless of its current state. Example: @@ -170,8 +168,9 @@ def ResetOp : QCOp<"reset"> { ``` }]; - let arguments = (ins Arg:$qubit); - let assemblyFormat = "$qubit attr-dict `:` type($qubit)"; + let arguments = + (ins Arg:$qubit); + let assemblyFormat = "$qubit attr-dict `:` type($qubit)"; } //===----------------------------------------------------------------------===// @@ -179,8 +178,9 @@ def ResetOp : QCOp<"reset"> { //===----------------------------------------------------------------------===// class TargetAndParameterArityTrait - : ParamNativeOpTrait<"TargetAndParameterArityTrait", !strconcat(!cast(T), ",", !cast(P))> { - let cppNamespace = "::mlir::qc"; + : ParamNativeOpTrait<"TargetAndParameterArityTrait", + !strconcat(!cast(T), ",", !cast(P))> { + let cppNamespace = "::mlir::qc"; } def ZeroTargetOneParameter : TargetAndParameterArityTrait<0, 1>; @@ -196,9 +196,11 @@ def TwoTargetTwoParameter : TargetAndParameterArityTrait<2, 2>; // Unitary Operations //===----------------------------------------------------------------------===// -def GPhaseOp : QCOp<"gphase", traits = [UnitaryOpInterface, ZeroTargetOneParameter, MemoryEffects<[MemWrite]>]> { - let summary = "Apply a global phase to the state"; - let description = [{ +def GPhaseOp + : QCOp<"gphase", traits = [UnitaryOpInterface, ZeroTargetOneParameter, + MemoryEffects<[MemWrite]>]> { + let summary = "Apply a global phase to the state"; + let description = [{ Applies a global phase to the state. Example: @@ -207,21 +209,19 @@ def GPhaseOp : QCOp<"gphase", traits = [UnitaryOpInterface, ZeroTargetOneParamet ``` }]; - let arguments = (ins Arg:$theta); - let assemblyFormat = "`(` $theta `)` attr-dict"; + let arguments = (ins Arg:$theta); + let assemblyFormat = "`(` $theta `)` attr-dict"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "gphase"; } }]; - let builders = [ - OpBuilder<(ins "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "const std::variant&":$theta)>]; } def IdOp : QCOp<"id", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an Id gate to a qubit"; - let description = [{ + let summary = "Apply an Id gate to a qubit"; + let description = [{ Applies an Id gate to a qubit, modifying it in place. Example: @@ -230,17 +230,18 @@ def IdOp : QCOp<"id", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in); + let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "id"; } }]; } def XOp : QCOp<"x", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an X gate to a qubit"; - let description = [{ + let summary = "Apply an X gate to a qubit"; + let description = [{ Applies an X gate to a qubit, modifying it in place. Example: @@ -249,17 +250,18 @@ def XOp : QCOp<"x", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in); + let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "x"; } }]; } def YOp : QCOp<"y", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply a Y gate to a qubit"; - let description = [{ + let summary = "Apply a Y gate to a qubit"; + let description = [{ Applies a Y gate to a qubit, modifying it in place. Example: @@ -268,17 +270,18 @@ def YOp : QCOp<"y", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in); + let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "y"; } }]; } def ZOp : QCOp<"z", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply a Z gate to a qubit"; - let description = [{ + let summary = "Apply a Z gate to a qubit"; + let description = [{ Applies a Z gate to a qubit, modifying it in place. Example: @@ -287,17 +290,18 @@ def ZOp : QCOp<"z", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in); + let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "z"; } }]; } def HOp : QCOp<"h", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an H gate to a qubit"; - let description = [{ + let summary = "Apply an H gate to a qubit"; + let description = [{ Applies an H gate to a qubit, modifying it in place. Example: @@ -306,17 +310,18 @@ def HOp : QCOp<"h", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in); + let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "h"; } }]; } def SOp : QCOp<"s", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an S gate to a qubit"; - let description = [{ + let summary = "Apply an S gate to a qubit"; + let description = [{ Applies an S gate to a qubit, modifying it in place. Example: @@ -325,17 +330,18 @@ def SOp : QCOp<"s", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in); + let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "s"; } }]; } def SdgOp : QCOp<"sdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an Sdg gate to a qubit"; - let description = [{ + let summary = "Apply an Sdg gate to a qubit"; + let description = [{ Applies an Sdg gate to a qubit, modifying it in place. Example: @@ -344,17 +350,18 @@ def SdgOp : QCOp<"sdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in); + let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "sdg"; } }]; } def TOp : QCOp<"t", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply a T gate to a qubit"; - let description = [{ + let summary = "Apply a T gate to a qubit"; + let description = [{ Applies a T gate to a qubit, modifying it in place. Example: @@ -363,17 +370,18 @@ def TOp : QCOp<"t", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in); + let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "t"; } }]; } def TdgOp : QCOp<"tdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply a Tdg gate to a qubit"; - let description = [{ + let summary = "Apply a Tdg gate to a qubit"; + let description = [{ Applies a Tdg gate to a qubit, modifying it in place. Example: @@ -382,17 +390,18 @@ def TdgOp : QCOp<"tdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in); + let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "tdg"; } }]; } def SXOp : QCOp<"sx", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an SX gate to a qubit"; - let description = [{ + let summary = "Apply an SX gate to a qubit"; + let description = [{ Applies an SX gate to a qubit, modifying it in place. Example: @@ -401,17 +410,19 @@ def SXOp : QCOp<"sx", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in); + let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "sx"; } }]; } -def SXdgOp : QCOp<"sxdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an SXdg gate to a qubit"; - let description = [{ +def SXdgOp + : QCOp<"sxdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { + let summary = "Apply an SXdg gate to a qubit"; + let description = [{ Applies an SXdg gate to a qubit, modifying it in place. Example: @@ -420,17 +431,18 @@ def SXdgOp : QCOp<"sxdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> ``` }]; - let arguments = (ins Arg:$qubit_in); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in); + let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "sxdg"; } }]; } def RXOp : QCOp<"rx", traits = [UnitaryOpInterface, OneTargetOneParameter]> { - let summary = "Apply an RX gate to a qubit"; - let description = [{ + let summary = "Apply an RX gate to a qubit"; + let description = [{ Applies an RX gate to a qubit, modifying it in place. Example: @@ -439,22 +451,22 @@ def RXOp : QCOp<"rx", traits = [UnitaryOpInterface, OneTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$theta); - let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in, + Arg:$theta); + let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "rx"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$theta)>]; } def RYOp : QCOp<"ry", traits = [UnitaryOpInterface, OneTargetOneParameter]> { - let summary = "Apply an RY gate to a qubit"; - let description = [{ + let summary = "Apply an RY gate to a qubit"; + let description = [{ Applies an RY gate to a qubit, modifying it in place. Example: @@ -463,22 +475,22 @@ def RYOp : QCOp<"ry", traits = [UnitaryOpInterface, OneTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$theta); - let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in, + Arg:$theta); + let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "ry"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$theta)>]; } def RZOp : QCOp<"rz", traits = [UnitaryOpInterface, OneTargetOneParameter]> { - let summary = "Apply an RZ gate to a qubit"; - let description = [{ + let summary = "Apply an RZ gate to a qubit"; + let description = [{ Applies an RZ gate to a qubit, modifying it in place. Example: @@ -487,22 +499,22 @@ def RZOp : QCOp<"rz", traits = [UnitaryOpInterface, OneTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$theta); - let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in, + Arg:$theta); + let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "rz"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$theta)>]; } def POp : QCOp<"p", traits = [UnitaryOpInterface, OneTargetOneParameter]> { - let summary = "Apply a P gate to a qubit"; - let description = [{ + let summary = "Apply a P gate to a qubit"; + let description = [{ Applies a P gate to a qubit, modifying it in place. Example: @@ -511,22 +523,22 @@ def POp : QCOp<"p", traits = [UnitaryOpInterface, OneTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$theta); - let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in, + Arg:$theta); + let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "p"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$theta)>]; } def ROp : QCOp<"r", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { - let summary = "Apply an R gate to a qubit"; - let description = [{ + let summary = "Apply an R gate to a qubit"; + let description = [{ Applies an R gate to a qubit, modifying it in place. Example: @@ -535,23 +547,25 @@ def ROp : QCOp<"r", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$theta, - Arg:$phi); - let assemblyFormat = "`(` $theta `,` $phi `)` $qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in, + Arg:$theta, + Arg:$phi); + let assemblyFormat = + "`(` $theta `,` $phi `)` $qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "r"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$theta, "const std::variant&":$phi)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$theta, + "const std::variant&":$phi)>]; } def U2Op : QCOp<"u2", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { - let summary = "Apply a U2 gate to a qubit"; - let description = [{ + let summary = "Apply a U2 gate to a qubit"; + let description = [{ Applies a U2 gate to a qubit, modifying it in place. Example: @@ -560,23 +574,25 @@ def U2Op : QCOp<"u2", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$phi, - Arg:$lambda); - let assemblyFormat = "`(` $phi `,` $lambda `)` $qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in, + Arg:$phi, + Arg:$lambda); + let assemblyFormat = + "`(` $phi `,` $lambda `)` $qubit_in attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "u2"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$phi, "const std::variant&":$lambda)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$phi, + "const std::variant&":$lambda)>]; } def UOp : QCOp<"u", traits = [UnitaryOpInterface, OneTargetThreeParameter]> { - let summary = "Apply a U gate to a qubit"; - let description = [{ + let summary = "Apply a U gate to a qubit"; + let description = [{ Applies a U gate to a qubit, modifying it in place. Example: @@ -585,24 +601,28 @@ def UOp : QCOp<"u", traits = [UnitaryOpInterface, OneTargetThreeParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$theta, - Arg:$phi, - Arg:$lambda); - let assemblyFormat = "`(` $theta `,` $phi `,` $lambda `)` $qubit_in attr-dict `:` type($qubit_in)"; + let arguments = + (ins Arg:$qubit_in, + Arg:$theta, + Arg:$phi, + Arg:$lambda); + let assemblyFormat = "`(` $theta `,` $phi `,` $lambda `)` $qubit_in " + "attr-dict `:` type($qubit_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "u"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$theta, "const std::variant&":$phi, "const std::variant&":$lambda)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$theta, + "const std::variant&":$phi, + "const std::variant&":$lambda)>]; } -def SWAPOp : QCOp<"swap", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { - let summary = "Apply a SWAP gate to two qubits"; - let description = [{ +def SWAPOp + : QCOp<"swap", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { + let summary = "Apply a SWAP gate to two qubits"; + let description = [{ Applies a SWAP gate to two qubits, modifying them in place. Example: @@ -611,18 +631,23 @@ def SWAPOp : QCOp<"swap", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in); - let assemblyFormat = "$qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in); + let assemblyFormat = "$qubit0_in `,` $qubit1_in attr-dict `:` " + "type($qubit0_in) `,` type($qubit1_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "swap"; } }]; } -def iSWAPOp : QCOp<"iswap", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { - let summary = "Apply a iSWAP gate to two qubits"; - let description = [{ +def iSWAPOp + : QCOp<"iswap", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { + let summary = "Apply a iSWAP gate to two qubits"; + let description = [{ Applies a iSWAP gate to two qubits, modifying them in place. Example: @@ -631,18 +656,22 @@ def iSWAPOp : QCOp<"iswap", traits = [UnitaryOpInterface, TwoTargetZeroParameter ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in); - let assemblyFormat = "$qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in); + let assemblyFormat = "$qubit0_in `,` $qubit1_in attr-dict `:` " + "type($qubit0_in) `,` type($qubit1_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "iswap"; } }]; } def DCXOp : QCOp<"dcx", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { - let summary = "Apply a DCX gate to two qubits"; - let description = [{ + let summary = "Apply a DCX gate to two qubits"; + let description = [{ Applies a DCX gate to two qubits, modifying them in place. Example: @@ -651,18 +680,22 @@ def DCXOp : QCOp<"dcx", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in); - let assemblyFormat = "$qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in); + let assemblyFormat = "$qubit0_in `,` $qubit1_in attr-dict `:` " + "type($qubit0_in) `,` type($qubit1_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "dcx"; } }]; } def ECROp : QCOp<"ecr", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { - let summary = "Apply an ECR gate to two qubits"; - let description = [{ + let summary = "Apply an ECR gate to two qubits"; + let description = [{ Applies an ECR gate to two qubits, modifying them in place. Example: @@ -671,18 +704,22 @@ def ECROp : QCOp<"ecr", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in); - let assemblyFormat = "$qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in); + let assemblyFormat = "$qubit0_in `,` $qubit1_in attr-dict `:` " + "type($qubit0_in) `,` type($qubit1_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "ecr"; } }]; } def RXXOp : QCOp<"rxx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { - let summary = "Apply an RXX gate to two qubits"; - let description = [{ + let summary = "Apply an RXX gate to two qubits"; + let description = [{ Applies an RXX gate to two qubits, modifying them in place. Example: @@ -691,23 +728,26 @@ def RXXOp : QCOp<"rxx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta); - let assemblyFormat = "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in, + Arg:$theta); + let assemblyFormat = "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` " + "type($qubit0_in) `,` type($qubit1_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "rxx"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, + "const std::variant&":$theta)>]; } def RYYOp : QCOp<"ryy", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { - let summary = "Apply an RYY gate to two qubits"; - let description = [{ + let summary = "Apply an RYY gate to two qubits"; + let description = [{ Applies an RYY gate to two qubits, modifying them in place. Example: @@ -716,23 +756,26 @@ def RYYOp : QCOp<"ryy", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta); - let assemblyFormat = "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in, + Arg:$theta); + let assemblyFormat = "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` " + "type($qubit0_in) `,` type($qubit1_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "ryy"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, + "const std::variant&":$theta)>]; } def RZXOp : QCOp<"rzx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { - let summary = "Apply an RZX gate to two qubits"; - let description = [{ + let summary = "Apply an RZX gate to two qubits"; + let description = [{ Applies an RZX gate to two qubits, modifying them in place. Example: @@ -741,23 +784,26 @@ def RZXOp : QCOp<"rzx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta); - let assemblyFormat = "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in, + Arg:$theta); + let assemblyFormat = "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` " + "type($qubit0_in) `,` type($qubit1_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "rzx"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, + "const std::variant&":$theta)>]; } def RZZOp : QCOp<"rzz", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { - let summary = "Apply an RZZ gate to two qubits"; - let description = [{ + let summary = "Apply an RZZ gate to two qubits"; + let description = [{ Applies an RZZ gate to two qubits, modifying them in place. Example: @@ -766,23 +812,27 @@ def RZZOp : QCOp<"rzz", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta); - let assemblyFormat = "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in, + Arg:$theta); + let assemblyFormat = "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` " + "type($qubit0_in) `,` type($qubit1_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "rzz"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, + "const std::variant&":$theta)>]; } -def XXPlusYYOp : QCOp<"xx_plus_yy", traits = [UnitaryOpInterface, TwoTargetTwoParameter]> { - let summary = "Apply an XX+YY gate to two qubits"; - let description = [{ +def XXPlusYYOp + : QCOp<"xx_plus_yy", traits = [UnitaryOpInterface, TwoTargetTwoParameter]> { + let summary = "Apply an XX+YY gate to two qubits"; + let description = [{ Applies an XX+YY gate to two qubits, modifying them in place. Example: @@ -791,24 +841,29 @@ def XXPlusYYOp : QCOp<"xx_plus_yy", traits = [UnitaryOpInterface, TwoTargetTwoPa ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta, - Arg:$beta); - let assemblyFormat = "`(` $theta `,` $beta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in, + Arg:$theta, + Arg:$beta); + let assemblyFormat = "`(` $theta `,` $beta `)` $qubit0_in `,` $qubit1_in " + "attr-dict `:` type($qubit0_in) `,` type($qubit1_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "xx_plus_yy"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, "const std::variant&":$theta, "const std::variant&":$beta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, + "const std::variant&":$theta, + "const std::variant&":$beta)>]; } -def XXMinusYYOp : QCOp<"xx_minus_yy", traits = [UnitaryOpInterface, TwoTargetTwoParameter]> { - let summary = "Apply an XX-YY gate to two qubits"; - let description = [{ +def XXMinusYYOp : QCOp<"xx_minus_yy", + traits = [UnitaryOpInterface, TwoTargetTwoParameter]> { + let summary = "Apply an XX-YY gate to two qubits"; + let description = [{ Applies an XX-YY gate to two qubits, modifying them in place. Example: @@ -817,24 +872,28 @@ def XXMinusYYOp : QCOp<"xx_minus_yy", traits = [UnitaryOpInterface, TwoTargetTwo ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta, - Arg:$beta); - let assemblyFormat = "`(` $theta `,` $beta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in, + Arg:$theta, + Arg:$beta); + let assemblyFormat = "`(` $theta `,` $beta `)` $qubit0_in `,` $qubit1_in " + "attr-dict `:` type($qubit0_in) `,` type($qubit1_in)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ static StringRef getBaseSymbol() { return "xx_minus_yy"; } }]; - let builders = [ - OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, "const std::variant&":$theta, "const std::variant&":$beta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, + "const std::variant&":$theta, + "const std::variant&":$beta)>]; } def BarrierOp : QCOp<"barrier", traits = [UnitaryOpInterface]> { - let summary = "Apply a barrier gate to a set of qubits"; - let description = [{ + let summary = "Apply a barrier gate to a set of qubits"; + let description = [{ Applies a barrier gate to a set of qubits, modifying them in place. Example: @@ -843,10 +902,11 @@ def BarrierOp : QCOp<"barrier", traits = [UnitaryOpInterface]> { ``` }]; - let arguments = (ins Arg, "the target qubits", [MemRead, MemWrite]>:$qubits); - let assemblyFormat = "$qubits attr-dict `:` type($qubits)"; + let arguments = (ins Arg, + "the target qubits", [MemRead, MemWrite]>:$qubits); + let assemblyFormat = "$qubits attr-dict `:` type($qubits)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ size_t getNumQubits() { return getNumTargets(); } size_t getNumTargets() { return getQubits().size(); } static size_t getNumControls() { return 0; } @@ -864,22 +924,21 @@ def BarrierOp : QCOp<"barrier", traits = [UnitaryOpInterface]> { //===----------------------------------------------------------------------===// def YieldOp : QCOp<"yield", traits = [Terminator]> { - let summary = "Yield from a modifier region"; - let description = [{ + let summary = "Yield from a modifier region"; + let description = [{ Terminates a modifier region, yielding control back to the enclosing operation. }]; - let assemblyFormat = "attr-dict"; + let assemblyFormat = "attr-dict"; } -def CtrlOp : QCOp<"ctrl", - traits = [ - UnitaryOpInterface, - SingleBlockImplicitTerminator<"::mlir::qc::YieldOp">, - RecursiveMemoryEffects - ]> { - let summary = "Add control qubits to a unitary operation"; - let description = [{ +def CtrlOp + : QCOp<"ctrl", + traits = [UnitaryOpInterface, + SingleBlockImplicitTerminator<"::mlir::qc::YieldOp">, + RecursiveMemoryEffects]> { + let summary = "Add control qubits to a unitary operation"; + let description = [{ A modifier operation that adds control qubits to the unitary operation defined in its body region. The controlled operation applies the underlying unitary only when all control qubits are in the |1⟩ state. @@ -896,11 +955,14 @@ def CtrlOp : QCOp<"ctrl", ``` }]; - let arguments = (ins Arg, "the control qubits", [MemRead, MemWrite]>:$controls); - let regions = (region SizedRegion<1>:$region); - let assemblyFormat = "`(` $controls `)` $region attr-dict `:` type($controls)"; + let arguments = + (ins Arg, + "the control qubits", [MemRead, MemWrite]>:$controls); + let regions = (region SizedRegion<1>:$region); + let assemblyFormat = + "`(` $controls `)` $region attr-dict `:` type($controls)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] UnitaryOpInterface getBodyUnitary(); size_t getNumQubits() { return getNumTargets() + getNumControls(); } size_t getNumTargets() { return getBodyUnitary().getNumTargets(); } @@ -913,22 +975,19 @@ def CtrlOp : QCOp<"ctrl", static StringRef getBaseSymbol() { return "ctrl"; } }]; - let builders = [ - OpBuilder<(ins "ValueRange":$controls, "const llvm::function_ref&":$bodyBuilder)> - ]; + let builders = [OpBuilder<(ins "ValueRange":$controls, + "const llvm::function_ref&":$bodyBuilder)>]; - let hasCanonicalizer = 1; - let hasVerifier = 1; + let hasCanonicalizer = 1; + let hasVerifier = 1; } def InvOp : QCOp<"inv", - traits = [ - UnitaryOpInterface, - SingleBlockImplicitTerminator<"::mlir::qc::YieldOp">, - RecursiveMemoryEffects - ]> { - let summary = "Invert a unitary operation"; - let description = [{ + traits = [UnitaryOpInterface, + SingleBlockImplicitTerminator<"::mlir::qc::YieldOp">, + RecursiveMemoryEffects]> { + let summary = "Invert a unitary operation"; + let description = [{ A modifier operation that inverts the unitary operation defined in its body region. @@ -940,10 +999,10 @@ def InvOp : QCOp<"inv", ``` }]; - let regions = (region SizedRegion<1>:$region); - let assemblyFormat = "$region attr-dict"; + let regions = (region SizedRegion<1>:$region); + let assemblyFormat = "$region attr-dict"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] UnitaryOpInterface getBodyUnitary(); size_t getNumQubits() { return getBodyUnitary().getNumQubits(); } size_t getNumTargets() { return getNumQubits(); } @@ -956,12 +1015,11 @@ def InvOp : QCOp<"inv", static StringRef getBaseSymbol() { return "inv"; } }]; - let builders = [ - OpBuilder<(ins "const llvm::function_ref&":$bodyBuilder)> - ]; + let builders = [OpBuilder<(ins + "const llvm::function_ref&":$bodyBuilder)>]; - let hasCanonicalizer = 1; - let hasVerifier = 1; + let hasCanonicalizer = 1; + let hasVerifier = 1; } #endif // MLIR_DIALECT_QC_IR_QCOPS_TD diff --git a/mlir/include/mlir/Dialect/QC/IR/QCTypes.td b/mlir/include/mlir/Dialect/QC/IR/QCTypes.td index db830ad3ca..85d36311fa 100644 --- a/mlir/include/mlir/Dialect/QC/IR/QCTypes.td +++ b/mlir/include/mlir/Dialect/QC/IR/QCTypes.td @@ -14,13 +14,13 @@ include "mlir/Dialect/QC/IR/QCDialect.td" include "mlir/IR/AttrTypeBase.td" class QCType traits = []> - : TypeDef { - let mnemonic = typeMnemonic; + : TypeDef { + let mnemonic = typeMnemonic; } def QubitType : QCType<"Qubit", "qubit"> { - let summary = "QC qubit reference type"; - let description = [{ + let summary = "QC qubit reference type"; + let description = [{ The `!qc.qubit` type represents a reference to a quantum bit in the QC dialect. Operations using this type modify qubits in place using reference semantics, similar to how classical imperative languages handle diff --git a/mlir/include/mlir/Dialect/QCO/IR/QCODialect.td b/mlir/include/mlir/Dialect/QCO/IR/QCODialect.td index a9f98d432a..62d1f5bba4 100644 --- a/mlir/include/mlir/Dialect/QCO/IR/QCODialect.td +++ b/mlir/include/mlir/Dialect/QCO/IR/QCODialect.td @@ -12,11 +12,11 @@ include "mlir/IR/DialectBase.td" def QCODialect : Dialect { - let name = "qco"; + let name = "qco"; - let summary = "The QCO (value semantics) dialect for quantum computing."; + let summary = "The QCO (value semantics) dialect for quantum computing."; - let description = [{ + let description = [{ The QCO dialect uses **value semantics** where quantum operations consume input qubits and produce new output values, following the functional programming and SSA paradigm. This model enables: @@ -35,9 +35,9 @@ def QCODialect : Dialect { ``` }]; - let cppNamespace = "::mlir::qco"; + let cppNamespace = "::mlir::qco"; - let useDefaultTypePrinterParser = 1; + let useDefaultTypePrinterParser = 1; } #endif // MLIR_DIALECT_QCO_IR_QCODIALECT_TD diff --git a/mlir/include/mlir/Dialect/QCO/IR/QCOInterfaces.td b/mlir/include/mlir/Dialect/QCO/IR/QCOInterfaces.td index 22dc396c6b..c665766649 100644 --- a/mlir/include/mlir/Dialect/QCO/IR/QCOInterfaces.td +++ b/mlir/include/mlir/Dialect/QCO/IR/QCOInterfaces.td @@ -16,7 +16,7 @@ include "mlir/IR/OpBase.td" //===----------------------------------------------------------------------===// def UnitaryOpInterface : OpInterface<"UnitaryOpInterface"> { - let description = [{ + let description = [{ This interface provides a unified API for all operations that apply or produce a unitary transformation in the QCO dialect. This includes base gates, user-defined gates, modifier operations (control, inverse, power), @@ -26,10 +26,10 @@ def UnitaryOpInterface : OpInterface<"UnitaryOpInterface"> { across all unitary operations with value semantics. }]; - let cppNamespace = "::mlir::qco"; + let cppNamespace = "::mlir::qco"; - // Generic implementation body for getUnitaryMatrix methods - defvar unitaryMatrixMethodBody = [{ + // Generic implementation body for getUnitaryMatrix methods + defvar unitaryMatrixMethodBody = [{ auto process = [&](MatrixType&& m) -> bool { using TargetT = std::remove_cvref_t; using SourceT = std::remove_cvref_t; @@ -84,124 +84,82 @@ def UnitaryOpInterface : OpInterface<"UnitaryOpInterface"> { } }]; - let methods = [ - // Qubit accessors - InterfaceMethod< - "Returns the number of qubits acted on by the unitary operation.", - "size_t", "getNumQubits", (ins) - >, - InterfaceMethod< - "Returns the number of target qubits (excluding control qubits).", - "size_t", "getNumTargets", (ins) - >, - InterfaceMethod< - "Returns the number of control qubits (both positive and negative).", - "size_t", "getNumControls", (ins) - >, - InterfaceMethod< - "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) - >, - InterfaceMethod< - "Returns the i-th target input qubit.", - "Value", "getInputTarget", (ins "size_t":$i) - >, - InterfaceMethod< - "Returns the i-th target output qubit.", - "Value", "getOutputTarget", (ins "size_t":$i) - >, - InterfaceMethod< - "Returns the i-th control input qubit.", - "Value", "getInputControl", (ins "size_t":$i) - >, - InterfaceMethod< - "Returns the i-th control output qubit.", - "Value", "getOutputControl", (ins "size_t":$i) - >, - InterfaceMethod< - "Returns the input qubit corresponding to the given output qubit.", - "Value", "getInputForOutput", (ins "Value":$output) - >, - InterfaceMethod< - "Returns the output qubit corresponding to the given input qubit.", - "Value", "getOutputForInput", (ins "Value":$input) - >, - - // Parameter handling - InterfaceMethod< - "Returns the number of parameters.", - "size_t", "getNumParams", (ins) - >, - InterfaceMethod< - "Returns the i-th parameter.", - "Value", "getParameter", (ins "size_t":$i) - >, - - // Convenience methods - InterfaceMethod< - "Returns true if the operation has any control qubits, otherwise false.", - "bool", "isControlled", (ins), - [{ return $_op.getNumControls() > 0; }] - >, - InterfaceMethod< - "Returns true if the operation only acts on a single qubit.", - "bool", "isSingleQubit", (ins), - [{ return $_op.getNumQubits() == 1; }] - >, - InterfaceMethod< - "Returns true if the operation acts on two qubits.", - "bool", "isTwoQubit", (ins), - [{ return $_op.getNumQubits() == 2; }] - >, - - // Identification - InterfaceMethod< - "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", - (ins "Eigen::Matrix, 1, 1>&":$out), - unitaryMatrixMethodBody - >, - InterfaceMethod< - "Populates the given 2x2 unitary matrix if possible.", - "bool", "getUnitaryMatrix2x2", - (ins "Eigen::Matrix2cd&":$out), - unitaryMatrixMethodBody - >, - InterfaceMethod< - "Populates the given 4x4 unitary matrix if possible.", - "bool", "getUnitaryMatrix4x4", - (ins "Eigen::Matrix4cd&":$out), - unitaryMatrixMethodBody - >, - InterfaceMethod< - "Populates the given dynamic unitary matrix.", - "bool", "getUnitaryMatrixDynamic", - (ins "Eigen::MatrixXcd&":$out), - unitaryMatrixMethodBody - > - ]; - - let extraClassDeclaration = [{ + let methods = [ + // Qubit accessors + InterfaceMethod< + "Returns the number of qubits acted on by the unitary operation.", + "size_t", "getNumQubits", (ins)>, + InterfaceMethod< + "Returns the number of target qubits (excluding control qubits).", + "size_t", "getNumTargets", (ins)>, + InterfaceMethod< + "Returns the number of control qubits (both positive and negative).", + "size_t", "getNumControls", (ins)>, + InterfaceMethod< + "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)>, + InterfaceMethod<"Returns the i-th target input qubit.", "Value", + "getInputTarget", (ins "size_t":$i)>, + InterfaceMethod<"Returns the i-th target output qubit.", "Value", + "getOutputTarget", (ins "size_t":$i)>, + InterfaceMethod<"Returns the i-th control input qubit.", "Value", + "getInputControl", (ins "size_t":$i)>, + InterfaceMethod<"Returns the i-th control output qubit.", "Value", + "getOutputControl", (ins "size_t":$i)>, + InterfaceMethod< + "Returns the input qubit corresponding to the given output qubit.", + "Value", "getInputForOutput", (ins "Value":$output)>, + InterfaceMethod< + "Returns the output qubit corresponding to the given input qubit.", + "Value", "getOutputForInput", (ins "Value":$input)>, + + // Parameter handling + InterfaceMethod<"Returns the number of parameters.", "size_t", + "getNumParams", (ins)>, + InterfaceMethod<"Returns the i-th parameter.", "Value", "getParameter", + (ins "size_t":$i)>, + + // Convenience methods + InterfaceMethod<"Returns true if the operation has any control qubits, " + "otherwise false.", + "bool", "isControlled", (ins), + [{ return $_op.getNumControls() > 0; }]>, + InterfaceMethod< + "Returns true if the operation only acts on a single qubit.", "bool", + "isSingleQubit", (ins), [{ return $_op.getNumQubits() == 1; }]>, + InterfaceMethod<"Returns true if the operation acts on two qubits.", + "bool", "isTwoQubit", (ins), + [{ return $_op.getNumQubits() == 2; }]>, + + // Identification + InterfaceMethod<"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", + (ins "Eigen::Matrix, 1, 1>&":$out), + unitaryMatrixMethodBody>, + InterfaceMethod<"Populates the given 2x2 unitary matrix if possible.", + "bool", "getUnitaryMatrix2x2", + (ins "Eigen::Matrix2cd&":$out), unitaryMatrixMethodBody>, + InterfaceMethod<"Populates the given 4x4 unitary matrix if possible.", + "bool", "getUnitaryMatrix4x4", + (ins "Eigen::Matrix4cd&":$out), unitaryMatrixMethodBody>, + InterfaceMethod<"Populates the given dynamic unitary matrix.", "bool", + "getUnitaryMatrixDynamic", (ins "Eigen::MatrixXcd&":$out), + unitaryMatrixMethodBody>]; + + let extraClassDeclaration = [{ template std::optional getUnitaryMatrix() { MatrixType out; diff --git a/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td b/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td index b5b82127f7..28a9034e80 100644 --- a/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td +++ b/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td @@ -23,16 +23,16 @@ include "mlir/Interfaces/SideEffectInterfaces.td" // Base Operation Classes //===----------------------------------------------------------------------===// -class QCOOp traits = []> : - Op; +class QCOOp traits = []> + : Op; //===----------------------------------------------------------------------===// // Resource Operations //===----------------------------------------------------------------------===// def AllocOp : QCOOp<"alloc", [MemoryEffects<[MemAlloc]>]> { - let summary = "Allocate a qubit dynamically"; - let description = [{ + let summary = "Allocate a qubit dynamically"; + let description = [{ Allocates a new qubit dynamically and returns an SSA value representing it. The qubit is initialized to the |0⟩ state. @@ -54,33 +54,32 @@ def AllocOp : QCOOp<"alloc", [MemoryEffects<[MemAlloc]>]> { ``` }]; - let arguments = (ins OptionalAttr:$register_name, - OptionalAttr>:$register_size, - OptionalAttr>:$register_index); - let results = (outs QubitType:$result); - let assemblyFormat = [{ + let arguments = (ins OptionalAttr:$register_name, + OptionalAttr>:$register_size, + OptionalAttr>:$register_index); + let results = (outs QubitType:$result); + let assemblyFormat = [{ (`(` $register_name^ `,` $register_size `,` $register_index `)`)? attr-dict `:` type($result) }]; - let builders = [ - OpBuilder<(ins), [{ + let builders = [OpBuilder<(ins), [{ build($_builder, $_state, QubitType::get($_builder.getContext()), nullptr, nullptr, nullptr); }]>, - OpBuilder<(ins "::mlir::StringAttr":$register_name, - "::mlir::IntegerAttr":$register_size, - "::mlir::IntegerAttr":$register_index), [{ + OpBuilder<(ins "::mlir::StringAttr":$register_name, + "::mlir::IntegerAttr":$register_size, + "::mlir::IntegerAttr":$register_index), + [{ build($_builder, $_state, QubitType::get($_builder.getContext()), register_name, register_size, register_index); - }]> - ]; + }]>]; - let hasVerifier = 1; + let hasVerifier = 1; } def DeallocOp : QCOOp<"dealloc", [MemoryEffects<[MemFree]>]> { - let summary = "Deallocate a qubit"; - let description = [{ + let summary = "Deallocate a qubit"; + let description = [{ Deallocates a qubit, releasing its resources. Example: @@ -89,14 +88,14 @@ def DeallocOp : QCOOp<"dealloc", [MemoryEffects<[MemFree]>]> { ``` }]; - let arguments = (ins QubitType:$qubit); - let assemblyFormat = "$qubit attr-dict `:` type($qubit)"; - let hasCanonicalizer = 1; + let arguments = (ins QubitType:$qubit); + let assemblyFormat = "$qubit attr-dict `:` type($qubit)"; + let hasCanonicalizer = 1; } def StaticOp : QCOOp<"static", [Pure]> { - let summary = "Retrieve a static qubit by index"; - let description = [{ + let summary = "Retrieve a static qubit by index"; + let description = [{ The `qco.static` operation produces an SSA value representing a qubit identified by a static index. This is useful for referring to fixed qubits in a quantum program or to hardware-mapped qubits. @@ -107,9 +106,9 @@ def StaticOp : QCOOp<"static", [Pure]> { ``` }]; - let arguments = (ins ConfinedAttr:$index); - let results = (outs QubitType:$qubit); - let assemblyFormat = "$index attr-dict `:` type($qubit)"; + let arguments = (ins ConfinedAttr:$index); + let results = (outs QubitType:$qubit); + let assemblyFormat = "$index attr-dict `:` type($qubit)"; } //===----------------------------------------------------------------------===// @@ -117,8 +116,8 @@ def StaticOp : QCOOp<"static", [Pure]> { //===----------------------------------------------------------------------===// def MeasureOp : QCOOp<"measure"> { - let summary = "Measure a qubit in the computational basis"; - let description = [{ + let summary = "Measure a qubit in the computational basis"; + let description = [{ Measures a qubit in the computational (Z) basis, collapsing the state and returning both the output qubit and a classical bit result. @@ -139,29 +138,28 @@ def MeasureOp : QCOOp<"measure"> { ``` }]; - let arguments = (ins Arg:$qubit_in, - OptionalAttr:$register_name, - OptionalAttr>:$register_size, - OptionalAttr>:$register_index); - let results = (outs QubitType:$qubit_out, I1:$result); - let assemblyFormat = [{ + let arguments = (ins Arg:$qubit_in, + OptionalAttr:$register_name, + OptionalAttr>:$register_size, + OptionalAttr>:$register_index); + let results = (outs QubitType:$qubit_out, I1:$result); + let assemblyFormat = [{ (`(` $register_name^ `,` $register_size `,` $register_index `)`)? $qubit_in `:` type($qubit_in) attr-dict }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in), [{ + let builders = [OpBuilder<(ins "Value":$qubit_in), [{ build($_builder, $_state, QubitType::get($_builder.getContext()), $_builder.getI1Type(), qubit_in, nullptr, nullptr, nullptr); - }]> - ]; + }]>]; - let hasVerifier = 1; + let hasVerifier = 1; } def ResetOp : QCOOp<"reset", [Idempotent, SameOperandsAndResultType]> { - let summary = "Reset a qubit to |0⟩ state"; - let description = [{ + let summary = "Reset a qubit to |0⟩ state"; + let description = [{ Resets a qubit to the |0⟩ state, regardless of its current state, and returns the reset qubit. @@ -171,10 +169,12 @@ def ResetOp : QCOOp<"reset", [Idempotent, SameOperandsAndResultType]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let hasCanonicalizer = 1; + let arguments = + (ins Arg:$qubit_in); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = + "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let hasCanonicalizer = 1; } //===----------------------------------------------------------------------===// @@ -182,8 +182,9 @@ def ResetOp : QCOOp<"reset", [Idempotent, SameOperandsAndResultType]> { //===----------------------------------------------------------------------===// class TargetAndParameterArityTrait - : ParamNativeOpTrait<"TargetAndParameterArityTrait", !cast(T) # ", " # !cast(P)> { - let cppNamespace = "::mlir::qco"; + : ParamNativeOpTrait<"TargetAndParameterArityTrait", + !cast(T)#", "#!cast(P)> { + let cppNamespace = "::mlir::qco"; } def ZeroTargetOneParameter : TargetAndParameterArityTrait<0, 1>; @@ -199,9 +200,11 @@ def TwoTargetTwoParameter : TargetAndParameterArityTrait<2, 2>; // Unitary Operations //===----------------------------------------------------------------------===// -def GPhaseOp : QCOOp<"gphase", traits = [UnitaryOpInterface, ZeroTargetOneParameter, MemoryEffects<[MemWrite]>]> { - let summary = "Apply a global phase to the state"; - let description = [{ +def GPhaseOp + : QCOOp<"gphase", traits = [UnitaryOpInterface, ZeroTargetOneParameter, + MemoryEffects<[MemWrite]>]> { + let summary = "Apply a global phase to the state"; + let description = [{ Applies a global phase to the state. Example: @@ -210,24 +213,22 @@ def GPhaseOp : QCOOp<"gphase", traits = [UnitaryOpInterface, ZeroTargetOneParame ``` }]; - let arguments = (ins Arg:$theta); - let assemblyFormat = "`(` $theta `)` attr-dict"; + let arguments = (ins Arg:$theta); + let assemblyFormat = "`(` $theta `)` attr-dict"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "gphase"; } [[nodiscard]] std::optional, 1, 1>> getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "const std::variant&":$theta)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def IdOp : QCOOp<"id", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an Id gate to a qubit"; - let description = [{ + let summary = "Apply an Id gate to a qubit"; + let description = [{ Applies an Id gate to a qubit and returns the transformed qubit. Example: @@ -236,21 +237,22 @@ def IdOp : QCOOp<"id", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = + "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "id"; } [[nodiscard]] static Eigen::Matrix2cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def XOp : QCOOp<"x", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an X gate to a qubit"; - let description = [{ + let summary = "Apply an X gate to a qubit"; + let description = [{ Applies an X gate to a qubit and returns the transformed qubit. Example: @@ -259,21 +261,22 @@ def XOp : QCOOp<"x", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = + "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "x"; } [[nodiscard]] static Eigen::Matrix2cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def YOp : QCOOp<"y", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply a Y gate to a qubit"; - let description = [{ + let summary = "Apply a Y gate to a qubit"; + let description = [{ Applies a Y gate to a qubit and returns the transformed qubit. Example: @@ -282,21 +285,22 @@ def YOp : QCOOp<"y", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = + "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "y"; } [[nodiscard]] static Eigen::Matrix2cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def ZOp : QCOOp<"z", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply a Z gate to a qubit"; - let description = [{ + let summary = "Apply a Z gate to a qubit"; + let description = [{ Applies a Z gate to a qubit and returns the transformed qubit. Example: @@ -305,21 +309,22 @@ def ZOp : QCOOp<"z", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = + "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "z"; } [[nodiscard]] static Eigen::Matrix2cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def HOp : QCOOp<"h", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply a H gate to a qubit"; - let description = [{ + let summary = "Apply a H gate to a qubit"; + let description = [{ Applies a H gate to a qubit and returns the transformed qubit. Example: @@ -328,21 +333,22 @@ def HOp : QCOOp<"h", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = + "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "h"; } [[nodiscard]] static Eigen::Matrix2cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def SOp : QCOOp<"s", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an S gate to a qubit"; - let description = [{ + let summary = "Apply an S gate to a qubit"; + let description = [{ Applies an S gate to a qubit and returns the transformed qubit. Example: @@ -351,21 +357,23 @@ def SOp : QCOOp<"s", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = + "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "s"; } [[nodiscard]] static Eigen::Matrix2cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } -def SdgOp : QCOOp<"sdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an Sdg gate to a qubit"; - let description = [{ +def SdgOp + : QCOOp<"sdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { + let summary = "Apply an Sdg gate to a qubit"; + let description = [{ Applies an Sdg gate to a qubit and returns the transformed qubit. Example: @@ -374,21 +382,22 @@ def SdgOp : QCOOp<"sdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> ``` }]; - let arguments = (ins Arg:$qubit_in); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = + "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "sdg"; } [[nodiscard]] static Eigen::Matrix2cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def TOp : QCOOp<"t", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply a T gate to a qubit"; - let description = [{ + let summary = "Apply a T gate to a qubit"; + let description = [{ Applies a T gate to a qubit and returns the transformed qubit. Example: @@ -397,21 +406,23 @@ def TOp : QCOOp<"t", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = + "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "t"; } [[nodiscard]] static Eigen::Matrix2cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } -def TdgOp : QCOOp<"tdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply a Tdg gate to a qubit"; - let description = [{ +def TdgOp + : QCOOp<"tdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { + let summary = "Apply a Tdg gate to a qubit"; + let description = [{ Applies a Tdg gate to a qubit and returns the transformed qubit. Example: @@ -420,21 +431,22 @@ def TdgOp : QCOOp<"tdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> ``` }]; - let arguments = (ins Arg:$qubit_in); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = + "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "tdg"; } [[nodiscard]] static Eigen::Matrix2cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def SXOp : QCOOp<"sx", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an SX gate to a qubit"; - let description = [{ + let summary = "Apply an SX gate to a qubit"; + let description = [{ Applies an SX gate to a qubit and returns the transformed qubit. Example: @@ -443,21 +455,23 @@ def SXOp : QCOOp<"sx", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = + "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "sx"; } [[nodiscard]] static Eigen::Matrix2cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } -def SXdgOp : QCOOp<"sxdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { - let summary = "Apply an SXdg gate to a qubit"; - let description = [{ +def SXdgOp + : QCOOp<"sxdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { + let summary = "Apply an SXdg gate to a qubit"; + let description = [{ Applies an SXdg gate to a qubit and returns the transformed qubit. Example: @@ -466,21 +480,22 @@ def SXdgOp : QCOOp<"sxdg", traits = [UnitaryOpInterface, OneTargetZeroParameter] ``` }]; - let arguments = (ins Arg:$qubit_in); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = + "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "sxdg"; } [[nodiscard]] static Eigen::Matrix2cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def RXOp : QCOOp<"rx", traits = [UnitaryOpInterface, OneTargetOneParameter]> { - let summary = "Apply an RX gate to a qubit"; - let description = [{ + let summary = "Apply an RX gate to a qubit"; + let description = [{ Applies an RX gate to a qubit and returns the transformed qubit. Example: @@ -489,26 +504,26 @@ def RXOp : QCOOp<"rx", traits = [UnitaryOpInterface, OneTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$theta); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in, + Arg:$theta); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in) " + "`->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "rx"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$theta)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def RYOp : QCOOp<"ry", traits = [UnitaryOpInterface, OneTargetOneParameter]> { - let summary = "Apply an RY gate to a qubit"; - let description = [{ + let summary = "Apply an RY gate to a qubit"; + let description = [{ Applies an RY gate to a qubit and returns the transformed qubit. Example: @@ -517,26 +532,26 @@ def RYOp : QCOOp<"ry", traits = [UnitaryOpInterface, OneTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$theta); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in, + Arg:$theta); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in) " + "`->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "ry"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$theta)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def RZOp : QCOOp<"rz", traits = [UnitaryOpInterface, OneTargetOneParameter]> { - let summary = "Apply an RZ gate to a qubit"; - let description = [{ + let summary = "Apply an RZ gate to a qubit"; + let description = [{ Applies an RZ gate to a qubit and returns the transformed qubit. Example: @@ -545,26 +560,26 @@ def RZOp : QCOOp<"rz", traits = [UnitaryOpInterface, OneTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$theta); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in, + Arg:$theta); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in) " + "`->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "rz"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$theta)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def POp : QCOOp<"p", traits = [UnitaryOpInterface, OneTargetOneParameter]> { - let summary = "Apply a P gate to a qubit"; - let description = [{ + let summary = "Apply a P gate to a qubit"; + let description = [{ Applies a P gate to a qubit and returns the transformed qubit. Example: @@ -573,26 +588,26 @@ def POp : QCOOp<"p", traits = [UnitaryOpInterface, OneTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$theta); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in, + Arg:$theta); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in) " + "`->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "p"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$theta)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def ROp : QCOOp<"r", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { - let summary = "Apply an R gate to a qubit"; - let description = [{ + let summary = "Apply an R gate to a qubit"; + let description = [{ Applies an R gate to a qubit and returns the transformed qubit. Example: @@ -601,27 +616,28 @@ def ROp : QCOOp<"r", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$theta, - Arg:$phi); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "`(` $theta `,` $phi `)` $qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in, + Arg:$theta, + Arg:$phi); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = "`(` $theta `,` $phi `)` $qubit_in attr-dict `:` " + "type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "r"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$theta, "const std::variant&":$phi)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$theta, + "const std::variant&":$phi)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def U2Op : QCOOp<"u2", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { - let summary = "Apply a U2 gate to a qubit"; - let description = [{ + let summary = "Apply a U2 gate to a qubit"; + let description = [{ Applies a U2 gate to a qubit and returns the transformed qubit. Example: @@ -630,27 +646,28 @@ def U2Op : QCOOp<"u2", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$phi, - Arg:$lambda); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "`(` $phi `,` $lambda `)` $qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in, + Arg:$phi, + Arg:$lambda); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = "`(` $phi `,` $lambda `)` $qubit_in attr-dict `:` " + "type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "u2"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$phi, "const std::variant&":$lambda)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$phi, + "const std::variant&":$lambda)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def UOp : QCOOp<"u", traits = [UnitaryOpInterface, OneTargetThreeParameter]> { - let summary = "Apply a U gate to a qubit"; - let description = [{ + let summary = "Apply a U gate to a qubit"; + let description = [{ Applies a U gate to a qubit and returns the transformed qubit. Example: @@ -659,28 +676,31 @@ def UOp : QCOOp<"u", traits = [UnitaryOpInterface, OneTargetThreeParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, - Arg:$theta, - Arg:$phi, - Arg:$lambda); - let results = (outs QubitType:$qubit_out); - let assemblyFormat = "`(` $theta `,` $phi `,` $lambda `)` $qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; + let arguments = (ins Arg:$qubit_in, + Arg:$theta, + Arg:$phi, + Arg:$lambda); + let results = (outs QubitType:$qubit_out); + let assemblyFormat = "`(` $theta `,` $phi `,` $lambda `)` $qubit_in " + "attr-dict `:` type($qubit_in) `->` type($qubit_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "u"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit_in, "const std::variant&":$theta, "const std::variant&":$phi, "const std::variant&":$lambda)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit_in, + "const std::variant&":$theta, + "const std::variant&":$phi, + "const std::variant&":$lambda)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } -def SWAPOp : QCOOp<"swap", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { - let summary = "Apply a SWAP gate to two qubits"; - let description = [{ +def SWAPOp + : QCOOp<"swap", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { + let summary = "Apply a SWAP gate to two qubits"; + let description = [{ Applies a SWAP gate to two qubits and returns the transformed qubits. Example: @@ -689,22 +709,26 @@ def SWAPOp : QCOOp<"swap", traits = [UnitaryOpInterface, TwoTargetZeroParameter] ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in); - let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); - let assemblyFormat = "$qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in); + let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); + let assemblyFormat = + "$qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` " + "type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "swap"; } [[nodiscard]] static Eigen::Matrix4cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } -def iSWAPOp : QCOOp<"iswap", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { - let summary = "Apply a iSWAP gate to two qubits"; - let description = [{ +def iSWAPOp + : QCOOp<"iswap", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { + let summary = "Apply a iSWAP gate to two qubits"; + let description = [{ Applies a iSWAP gate to two qubits and returns the transformed qubits. Example: @@ -713,20 +737,24 @@ def iSWAPOp : QCOOp<"iswap", traits = [UnitaryOpInterface, TwoTargetZeroParamete ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in); - let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); - let assemblyFormat = "$qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in); + let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); + let assemblyFormat = + "$qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` " + "type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "iswap"; } [[nodiscard]] static Eigen::Matrix4cd getUnitaryMatrix(); }]; } -def DCXOp : QCOOp<"dcx", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { - let summary = "Apply a DCX gate to two qubits"; - let description = [{ +def DCXOp + : QCOOp<"dcx", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { + let summary = "Apply a DCX gate to two qubits"; + let description = [{ Applies a DCX gate to two qubits and returns the transformed qubits. Example: @@ -735,22 +763,26 @@ def DCXOp : QCOOp<"dcx", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in); - let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); - let assemblyFormat = "$qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in); + let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); + let assemblyFormat = + "$qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` " + "type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "dcx"; } [[nodiscard]] static Eigen::Matrix4cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } -def ECROp : QCOOp<"ecr", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { - let summary = "Apply an ECR gate to two qubits"; - let description = [{ +def ECROp + : QCOOp<"ecr", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { + let summary = "Apply an ECR gate to two qubits"; + let description = [{ Applies an ECR gate to two qubits and returns the transformed qubits. Example: @@ -759,22 +791,25 @@ def ECROp : QCOOp<"ecr", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in); - let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); - let assemblyFormat = "$qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in); + let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); + let assemblyFormat = + "$qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` " + "type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "ecr"; } [[nodiscard]] static Eigen::Matrix4cd getUnitaryMatrix(); }]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def RXXOp : QCOOp<"rxx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { - let summary = "Apply an RXX gate to two qubits"; - let description = [{ + let summary = "Apply an RXX gate to two qubits"; + let description = [{ Applies an RXX gate to two qubits and returns the transformed qubits. Example: @@ -783,27 +818,29 @@ def RXXOp : QCOOp<"rxx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta); - let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); - let assemblyFormat = "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in, + Arg:$theta); + let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); + let assemblyFormat = + "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) " + "`,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "rxx"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, + "const std::variant&":$theta)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def RYYOp : QCOOp<"ryy", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { - let summary = "Apply an RYY gate to two qubits"; - let description = [{ + let summary = "Apply an RYY gate to two qubits"; + let description = [{ Applies an RYY gate to two qubits and returns the transformed qubits. Example: @@ -812,27 +849,29 @@ def RYYOp : QCOOp<"ryy", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta); - let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); - let assemblyFormat = "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in, + Arg:$theta); + let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); + let assemblyFormat = + "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) " + "`,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "ryy"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, + "const std::variant&":$theta)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def RZXOp : QCOOp<"rzx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { - let summary = "Apply an RZX gate to two qubits"; - let description = [{ + let summary = "Apply an RZX gate to two qubits"; + let description = [{ Applies an RZX gate to two qubits and returns the transformed qubits. Example: @@ -841,27 +880,29 @@ def RZXOp : QCOOp<"rzx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta); - let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); - let assemblyFormat = "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in, + Arg:$theta); + let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); + let assemblyFormat = + "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) " + "`,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "rzx"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, + "const std::variant&":$theta)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def RZZOp : QCOOp<"rzz", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { - let summary = "Apply an RZZ gate to two qubits"; - let description = [{ + let summary = "Apply an RZZ gate to two qubits"; + let description = [{ Applies an RZZ gate to two qubits and returns the transformed qubits. Example: @@ -870,27 +911,30 @@ def RZZOp : QCOOp<"rzz", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta); - let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); - let assemblyFormat = "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in, + Arg:$theta); + let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); + let assemblyFormat = + "`(` $theta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) " + "`,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "rzz"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, "const std::variant&":$theta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, + "const std::variant&":$theta)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } -def XXPlusYYOp : QCOOp<"xx_plus_yy", traits = [UnitaryOpInterface, TwoTargetTwoParameter]> { - let summary = "Apply an XX+YY gate to two qubits"; - let description = [{ +def XXPlusYYOp : QCOOp<"xx_plus_yy", + traits = [UnitaryOpInterface, TwoTargetTwoParameter]> { + let summary = "Apply an XX+YY gate to two qubits"; + let description = [{ Applies an XX+YY gate to two qubits and returns the transformed qubits. Example: @@ -899,28 +943,32 @@ def XXPlusYYOp : QCOOp<"xx_plus_yy", traits = [UnitaryOpInterface, TwoTargetTwoP ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta, - Arg:$beta); - let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); - let assemblyFormat = "`(` $theta `,` $beta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in, + Arg:$theta, + Arg:$beta); + let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); + let assemblyFormat = "`(` $theta `,` $beta `)` $qubit0_in `,` $qubit1_in " + "attr-dict `:` type($qubit0_in) `,` type($qubit1_in) " + "`->` type($qubit0_out) `,` type($qubit1_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "xx_plus_yy"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, "const std::variant&":$theta, "const std::variant&":$beta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, + "const std::variant&":$theta, + "const std::variant&":$beta)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } -def XXMinusYYOp : QCOOp<"xx_minus_yy", traits = [UnitaryOpInterface, TwoTargetTwoParameter]> { - let summary = "Apply an XX-YY gate to two qubits"; - let description = [{ +def XXMinusYYOp : QCOOp<"xx_minus_yy", + traits = [UnitaryOpInterface, TwoTargetTwoParameter]> { + let summary = "Apply an XX-YY gate to two qubits"; + let description = [{ Applies an XX-YY gate to two qubits and returns the transformed qubits. Example: @@ -929,28 +977,31 @@ def XXMinusYYOp : QCOOp<"xx_minus_yy", traits = [UnitaryOpInterface, TwoTargetTw ``` }]; - let arguments = (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta, - Arg:$beta); - let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); - let assemblyFormat = "`(` $theta `,` $beta `)` $qubit0_in `,` $qubit1_in attr-dict `:` type($qubit0_in) `,` type($qubit1_in) `->` type($qubit0_out) `,` type($qubit1_out)"; + let arguments = + (ins Arg:$qubit0_in, + Arg:$qubit1_in, + Arg:$theta, + Arg:$beta); + let results = (outs QubitType:$qubit0_out, QubitType:$qubit1_out); + let assemblyFormat = "`(` $theta `,` $beta `)` $qubit0_in `,` $qubit1_in " + "attr-dict `:` type($qubit0_in) `,` type($qubit1_in) " + "`->` type($qubit0_out) `,` type($qubit1_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ [[nodiscard]] static StringRef getBaseSymbol() { return "xx_minus_yy"; } [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, "const std::variant&":$theta, "const std::variant&":$beta)> - ]; + let builders = [OpBuilder<(ins "Value":$qubit0_in, "Value":$qubit1_in, + "const std::variant&":$theta, + "const std::variant&":$beta)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } def BarrierOp : QCOOp<"barrier", traits = [UnitaryOpInterface]> { - let summary = "Apply a barrier gate to a set of qubits"; - let description = [{ + let summary = "Apply a barrier gate to a set of qubits"; + let description = [{ Applies a barrier gate to a set of qubits and returns the transformed qubits. Example: @@ -959,11 +1010,13 @@ def BarrierOp : QCOOp<"barrier", traits = [UnitaryOpInterface]> { ``` }]; - let arguments = (ins Arg, "the target qubits", [MemRead]>:$qubits_in); - let results = (outs Variadic:$qubits_out); - let assemblyFormat = "$qubits_in attr-dict `:` type($qubits_in) `->` type($qubits_out)"; + let arguments = + (ins Arg, "the target qubits", [MemRead]>:$qubits_in); + let results = (outs Variadic:$qubits_out); + let assemblyFormat = + "$qubits_in attr-dict `:` type($qubits_in) `->` type($qubits_out)"; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ size_t getNumQubits() { return getNumTargets(); } size_t getNumTargets() { return getQubitsIn().size(); } static size_t getNumControls() { return 0; } @@ -982,11 +1035,9 @@ def BarrierOp : QCOOp<"barrier", traits = [UnitaryOpInterface]> { [[nodiscard]] static StringRef getBaseSymbol() { return "barrier"; } }]; - let builders = [ - OpBuilder<(ins "ValueRange":$qubits)> - ]; + let builders = [OpBuilder<(ins "ValueRange":$qubits)>]; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } //===----------------------------------------------------------------------===// @@ -994,8 +1045,8 @@ def BarrierOp : QCOOp<"barrier", traits = [UnitaryOpInterface]> { //===----------------------------------------------------------------------===// def YieldOp : QCOOp<"yield", traits = [Terminator, ReturnLike]> { - let summary = "Yield from a modifier region"; - let description = [{ + let summary = "Yield from a modifier region"; + let description = [{ Terminates a modifier region, yielding the transformed target qubits back to the enclosing modifier operation. The targets must match the expected output signature of the modifier region. @@ -1008,22 +1059,19 @@ def YieldOp : QCOOp<"yield", traits = [Terminator, ReturnLike]> { ``` }]; - let arguments = (ins Variadic:$targets); - let assemblyFormat = "$targets attr-dict"; + let arguments = (ins Variadic:$targets); + let assemblyFormat = "$targets attr-dict"; } -def CtrlOp : QCOOp<"ctrl", traits = - [ - UnitaryOpInterface, - AttrSizedOperandSegments, - AttrSizedResultSegments, - SameOperandsAndResultType, - SameOperandsAndResultShape, - SingleBlockImplicitTerminator<"::mlir::qco::YieldOp">, - RecursiveMemoryEffects - ]> { - let summary = "Add control qubits to a unitary operation"; - let description = [{ +def CtrlOp + : QCOOp<"ctrl", + traits = [UnitaryOpInterface, AttrSizedOperandSegments, + AttrSizedResultSegments, SameOperandsAndResultType, + SameOperandsAndResultShape, + SingleBlockImplicitTerminator<"::mlir::qco::YieldOp">, + RecursiveMemoryEffects]> { + let summary = "Add control qubits to a unitary operation"; + let description = [{ A modifier operation that adds control qubits to the unitary operation defined in its body region. The controlled operation applies the underlying unitary only when all control qubits are in the |1⟩ state. @@ -1040,11 +1088,13 @@ def CtrlOp : QCOOp<"ctrl", traits = ``` }]; - let arguments = (ins Arg, "the control qubits", [MemRead]>:$controls_in, - Arg, "the target qubits", [MemRead]>:$targets_in); - let results = (outs Variadic:$controls_out, Variadic:$targets_out); - let regions = (region SizedRegion<1>:$region); - let assemblyFormat = [{ + let arguments = (ins Arg, + "the control qubits", [MemRead]>:$controls_in, + Arg, "the target qubits", [MemRead]>:$targets_in); + let results = (outs Variadic:$controls_out, + Variadic:$targets_out); + let regions = (region SizedRegion<1>:$region); + let assemblyFormat = [{ `(` $controls_in `)` `targets` custom($region, $targets_in) @@ -1054,7 +1104,7 @@ def CtrlOp : QCOOp<"ctrl", traits = `(` `{` type($controls_out) `}` ( `,` `{` type($targets_out)^ `}` )? `)` }]; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ UnitaryOpInterface getBodyUnitary(); size_t getNumQubits() { return getNumControls() + getNumTargets(); } size_t getNumTargets() { return getTargetsIn().size(); } @@ -1075,25 +1125,25 @@ def CtrlOp : QCOOp<"ctrl", traits = [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "ValueRange":$controls, "ValueRange":$targets), [{ + let builders = [OpBuilder<(ins "ValueRange":$controls, "ValueRange":$targets), + [{ build($_builder, $_state, controls.getTypes(), targets.getTypes(), controls, targets); }]>, - OpBuilder<(ins "ValueRange":$controls, "ValueRange":$targets, "llvm::function_ref(ValueRange)>":$bodyBuilder)> - ]; + OpBuilder<(ins "ValueRange":$controls, "ValueRange":$targets, + "llvm::function_ref(ValueRange)" + ">":$bodyBuilder)>]; - let hasCanonicalizer = 1; - let hasVerifier = 1; + let hasCanonicalizer = 1; + let hasVerifier = 1; } -def InvOp : QCOOp<"inv", - traits = [ - UnitaryOpInterface, - SingleBlockImplicitTerminator<"::mlir::qco::YieldOp">, - RecursiveMemoryEffects - ]> { - let summary = "Invert a unitary operation"; - let description = [{ +def InvOp + : QCOOp<"inv", + traits = [UnitaryOpInterface, + SingleBlockImplicitTerminator<"::mlir::qco::YieldOp">, + RecursiveMemoryEffects]> { + let summary = "Invert a unitary operation"; + let description = [{ A modifier operation that inverts the unitary operation defined in its body region. The operation takes a variadic number of qubits as inputs and produces corresponding output qubits. @@ -1107,10 +1157,12 @@ def InvOp : QCOOp<"inv", ``` }]; - let arguments = (ins Arg, "the qubits involved in the operation", [MemRead]>:$qubits_in); - let results = (outs Variadic:$qubits_out); - let regions = (region SizedRegion<1>:$region); - let assemblyFormat = [{ + let arguments = + (ins Arg, + "the qubits involved in the operation", [MemRead]>:$qubits_in); + let results = (outs Variadic:$qubits_out); + let regions = (region SizedRegion<1>:$region); + let assemblyFormat = [{ custom($region, $qubits_in) attr-dict `:` `{` type($qubits_in) `}` @@ -1118,7 +1170,7 @@ def InvOp : QCOOp<"inv", `{` type($qubits_out) `}` }]; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ UnitaryOpInterface getBodyUnitary(); size_t getNumQubits() { return getNumTargets(); } size_t getNumTargets() { return getQubitsIn().size(); } @@ -1139,33 +1191,34 @@ def InvOp : QCOOp<"inv", [[nodiscard]] std::optional getUnitaryMatrix(); }]; - let builders = [ - OpBuilder<(ins "ValueRange":$qubits), [{ + let builders = [OpBuilder<(ins "ValueRange":$qubits), [{ build($_builder, $_state, qubits.getTypes(), qubits); }]>, - OpBuilder<(ins "ValueRange":$qubits, "llvm::function_ref(ValueRange)>":$bodyBuilder)> - ]; + OpBuilder<(ins "ValueRange":$qubits, + "llvm::function_ref(ValueRange)" + ">":$bodyBuilder)>]; - let hasCanonicalizer = 1; - let hasVerifier = 1; + let hasCanonicalizer = 1; + let hasVerifier = 1; } //===----------------------------------------------------------------------===// // SCF operations //===----------------------------------------------------------------------===// -def IfOp : QCOOp<"if", traits = - [ - DeclareOpInterfaceMethods, - SingleBlock, - SingleBlockImplicitTerminator<"::mlir::qco::YieldOp">, - RecursiveMemoryEffects - ]> { - - let summary = "If-then-else operation for linear (qubit) types"; - let description = [{ +def IfOp + : QCOOp< + "if", + traits = [DeclareOpInterfaceMethods< + RegionBranchOpInterface, ["getNumRegionInvocations", + "getRegionInvocationBounds", + "getEntrySuccessorRegions"]>, + SingleBlock, + SingleBlockImplicitTerminator<"::mlir::qco::YieldOp">, + RecursiveMemoryEffects]> { + + let summary = "If-then-else operation for linear (qubit) types"; + let description = [{ The `qco.if` operation is an if-then-else construct similar to the standard scf.if operation. In addition to the condition, the operation takes a variadic number of qubits as inputs that are required in the bodies of both branches. These qubits are passed down to the individual regions @@ -1183,12 +1236,11 @@ def IfOp : QCOOp<"if", traits = ``` }]; - let arguments = (ins I1:$condition, Variadic:$qubits); - let results = (outs Variadic:$results); - let regions = (region SizedRegion<1>:$thenRegion, - SizedRegion<1>:$elseRegion); + let arguments = (ins I1:$condition, Variadic:$qubits); + let results = (outs Variadic:$results); + let regions = (region SizedRegion<1>:$thenRegion, SizedRegion<1>:$elseRegion); - let assemblyFormat = [{ + let assemblyFormat = [{ $condition custom($thenRegion, $elseRegion, $qubits) attr-dict `:` @@ -1197,15 +1249,17 @@ def IfOp : QCOOp<"if", traits = `{` type($results) `}` }]; - let builders = [ - OpBuilder<(ins "Value":$condition, "ValueRange":$qubits), [{ + let builders = + [OpBuilder<(ins "Value":$condition, "ValueRange":$qubits), [{ build($_builder, $_state, qubits.getTypes(), condition, qubits); }]>, - OpBuilder<(ins "Value":$condition, "ValueRange":$qubits, "llvm::function_ref(ValueRange)>":$thenBuilder, - CArg<"llvm::function_ref(ValueRange)>","nullptr">:$elseBuilder)> - ]; + OpBuilder<(ins "Value":$condition, "ValueRange":$qubits, + "llvm::function_ref(ValueRange)" + ">":$thenBuilder, + CArg<"llvm::function_ref(ValueRange)>", + "nullptr">:$elseBuilder)>]; - let extraClassDeclaration = [{ + let extraClassDeclaration = [{ Block *thenBlock() { return &getThenRegion().back(); } @@ -1216,7 +1270,7 @@ def IfOp : QCOOp<"if", traits = YieldOp elseYield(); }]; - let extraClassDefinition = [{ + let extraClassDefinition = [{ YieldOp $cppClass::thenYield() { return cast(&thenBlock()->back()); } @@ -1225,8 +1279,8 @@ def IfOp : QCOOp<"if", traits = } }]; - let hasCanonicalizer = 1; - let hasVerifier = 1; + let hasCanonicalizer = 1; + let hasVerifier = 1; } #endif // MLIR_DIALECT_QCO_IR_QCOOPS_TD diff --git a/mlir/include/mlir/Dialect/QCO/IR/QCOTypes.td b/mlir/include/mlir/Dialect/QCO/IR/QCOTypes.td index 120fe0e54a..2438b98d6c 100644 --- a/mlir/include/mlir/Dialect/QCO/IR/QCOTypes.td +++ b/mlir/include/mlir/Dialect/QCO/IR/QCOTypes.td @@ -14,13 +14,13 @@ include "mlir/Dialect/QCO/IR/QCODialect.td" include "mlir/IR/AttrTypeBase.td" class QCOType traits = []> - : TypeDef { - let mnemonic = typeMnemonic; + : TypeDef { + let mnemonic = typeMnemonic; } def QubitType : QCOType<"Qubit", "qubit"> { - let summary = "QCO qubit value type"; - let description = [{ + let summary = "QCO qubit value type"; + let description = [{ The `!qco.qubit` type represents an SSA value holding a quantum bit in the QCO dialect. Operations using this type consume input qubits and produce new output qubits following value semantics and the SSA diff --git a/mlir/include/mlir/Dialect/QCO/Transforms/Passes.td b/mlir/include/mlir/Dialect/QCO/Transforms/Passes.td index 9b5942049a..1200912148 100644 --- a/mlir/include/mlir/Dialect/QCO/Transforms/Passes.td +++ b/mlir/include/mlir/Dialect/QCO/Transforms/Passes.td @@ -17,7 +17,8 @@ include "mlir/Pass/PassBase.td" def MappingPass : Pass<"place-and-route", "mlir::ModuleOp"> { let dependentDialects = ["mlir::qco::QCODialect"]; - let summary = "This pass ensures that a program meets the connectivity constraints of a target architecture."; + let summary = "This pass ensures that a program meets the connectivity " + "constraints of a target architecture."; let description = [{ This pass maps the dynamically allocated qubits in a quantum program to the static qubits of a target architecture. The pass performs both placement and routing of the qubits to ensure that all two-qubit operations in the program @@ -34,16 +35,17 @@ def MappingPass : Pass<"place-and-route", "mlir::ModuleOp"> { The cost function of the A* search is defined as follows: - * `f(n) = g(n) + h(n)` - * `g(n) = alpha * depth(n)` - * `h(n) = sum(pow(lambda, i) * h(L, p) for [i, L] in enumerate(layers))` + - `f(n) = g(n) + h(n)` + - `g(n) = alpha * depth(n)` + - `h(n) = sum(pow(lambda, i) * h(L, p) for [i, L] in enumerate(layers))` Where: - * `p` is the dynamic-to-static mapping associated with search node `n`. - * `layers` is an array of layers with size `1 + nlookahead`. - * `depth(n)` returns the distance from the node `n` to the root node. - * `dist(i, j)` returns the distance between the qubits `i` and `j` on the target's coupling graph. - * `h(L, p) := sum(dist(p[gate.first], p[gate.second]) for gate in L)` + + - `p` is the dynamic-to-static mapping associated with search node `n`. + - `layers` is an array of layers with size `1 + nlookahead`. + - `depth(n)` returns the distance from the node `n` to the root node. + - `dist(i, j)` returns the distance between the qubits `i` and `j` on the target's coupling graph. + - `h(L, p) := sum(dist(p[gate.first], p[gate.second]) for gate in L)` To iteratively refine the mapping, the pass performs multiple forward and backward traversals of the circuit. In each traversal, the pass routes the circuit and updates the dynamic-to-static mapping based on the routing decisions @@ -53,20 +55,20 @@ def MappingPass : Pass<"place-and-route", "mlir::ModuleOp"> { The pass option `ntrials` determines how many random initial layouts the pass explores. Per default, the pass always explores the identity layout. If compiled with multi-threading on, these trials will be executed in parallel. }]; - let options = [ - Option<"nlookahead", "nlookahead", "std::size_t", "1", - "The number of lookahead steps.">, - Option<"alpha", "alpha", "float", "1.0F", - "The alpha factor in the cost function. Must be > 0.">, - Option<"lambda", "lambda", "float", "0.5F", - "The lambda factor in the cost function.">, - Option<"niterations", "niterations", "std::size_t", "2", - "The number of forwards and backwards traversal to improve the initial layout.">, - Option<"ntrials", "ntrials", "std::size_t", "4", - "The number of (possibly parallel) random trials of the forwards and backwards mechanism.">, - Option<"seed", "seed", "std::size_t", "42", - "A seed used for randomization."> - ]; + let options = [Option<"nlookahead", "nlookahead", "std::size_t", "1", + "The number of lookahead steps.">, + Option<"alpha", "alpha", "float", "1.0F", + "The alpha factor in the cost function. Must be > 0.">, + Option<"lambda", "lambda", "float", "0.5F", + "The lambda factor in the cost function.">, + Option<"niterations", "niterations", "std::size_t", "2", + "The number of forwards and backwards traversal to " + "improve the initial layout.">, + Option<"ntrials", "ntrials", "std::size_t", "4", + "The number of (possibly parallel) random trials of " + "the forwards and backwards mechanism.">, + Option<"seed", "seed", "std::size_t", "42", + "A seed used for randomization.">]; } #endif // MLIR_DIALECT_QCO_TRANSFORMS_PASSES_TD diff --git a/mlir/include/mlir/Dialect/QTensor/IR/QTensorDialect.td b/mlir/include/mlir/Dialect/QTensor/IR/QTensorDialect.td index 75122363fa..8d01d8a758 100644 --- a/mlir/include/mlir/Dialect/QTensor/IR/QTensorDialect.td +++ b/mlir/include/mlir/Dialect/QTensor/IR/QTensorDialect.td @@ -14,7 +14,8 @@ include "mlir/IR/DialectBase.td" def QTensorDialect : Dialect { let name = "qtensor"; - let summary = "The QTensor dialect for one-dimensional tensors of qubits with linear typing."; + let summary = "The QTensor dialect for one-dimensional tensors of qubits " + "with linear typing."; let description = [{ The QTensor dialect is an adjusted variant of the standard tensor dialect of MLIR that supports linear typing for one-dimensional tensors of qubits. diff --git a/mlir/include/mlir/Dialect/QTensor/IR/QTensorOps.td b/mlir/include/mlir/Dialect/QTensor/IR/QTensorOps.td index 9322eace45..f421ee2dc6 100644 --- a/mlir/include/mlir/Dialect/QTensor/IR/QTensorOps.td +++ b/mlir/include/mlir/Dialect/QTensor/IR/QTensorOps.td @@ -30,20 +30,18 @@ class QTensorOp traits = []> // Type Constraints //===----------------------------------------------------------------------===// -def Static1DQubitTensor : Type< - And<[ - 1DTensorOf<[QubitType]>.predicate, - HasStaticShapePred - ]>, - "Tensor must be statically shaped and elements must be of qubit type">; +def Static1DQubitTensor + : Type.predicate, HasStaticShapePred]>, + "Tensor must be statically shaped and elements must be of qubit " + "type">; //===----------------------------------------------------------------------===// // Operations //===----------------------------------------------------------------------===// def AllocOp : QTensorOp<"alloc", [MemoryEffects<[MemAlloc]>]> { - let summary = "Tensor alloc operation"; - let description = [{ + let summary = "Tensor alloc operation"; + let description = [{ Allocates a one-dimensional qubit tensor with the given size and returns the allocated tensor. The qubits are initialized to the |0> state. If the size is a constant the resulting tensor has a static size, otherwise the tensor has a dynamic size. @@ -54,20 +52,18 @@ def AllocOp : QTensorOp<"alloc", [MemoryEffects<[MemAlloc]>]> { ``` }]; - let arguments = (ins Index:$size); - let results = (outs 1DTensorOf<[QubitType]>:$result); - let assemblyFormat = "`(`$size`)` attr-dict `:` type($result)"; + let arguments = (ins Index:$size); + let results = (outs 1DTensorOf<[QubitType]>:$result); + let assemblyFormat = "`(`$size`)` attr-dict `:` type($result)"; - let builders = [ - OpBuilder<(ins "Value":$size)> - ]; + let builders = [OpBuilder<(ins "Value":$size)>]; - let hasVerifier = 1; + let hasVerifier = 1; } def DeallocOp : QTensorOp<"dealloc", [MemoryEffects<[MemFree]>]> { - let summary = "Deallocate a tensor"; - let description = [{ + let summary = "Deallocate a tensor"; + let description = [{ This operation deallocates the tensor and the values it holds, releasing its resources. Qubits that were extracted but not inserted again need to be deallocated separately. @@ -77,21 +73,23 @@ def DeallocOp : QTensorOp<"dealloc", [MemoryEffects<[MemFree]>]> { ``` }]; - let arguments = (ins 1DTensorOf<[QubitType]>:$tensor); - let assemblyFormat = "$tensor attr-dict `:` type($tensor)"; + let arguments = (ins 1DTensorOf<[QubitType]>:$tensor); + let assemblyFormat = "$tensor attr-dict `:` type($tensor)"; - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } -def FromElementsOp : QTensorOp<"from_elements", [ - Pure, - TypesMatchWith<"operand types match result element type", - "result", "elements", "SmallVector(" - "::llvm::cast($_self).getNumElements(), " - "::llvm::cast($_self).getElementType())"> - ]> { - let summary = "Create a tensor from a range of values"; - let description = [{ +def FromElementsOp + : QTensorOp< + "from_elements", + [Pure, + TypesMatchWith< + "operand types match result element type", "result", "elements", + "SmallVector(" + "::llvm::cast($_self).getNumElements(), " + "::llvm::cast($_self).getElementType())">]> { + let summary = "Create a tensor from a range of values"; + let description = [{ The `qtensor.from_elements` operation is a wrapper operation of the `tensor.from_elements` operation. This operation creates a one-dimensional qubit tensor using the operands as its input. This also causes the input qubits to be consumed. @@ -102,25 +100,26 @@ def FromElementsOp : QTensorOp<"from_elements", [ ``` }]; - let arguments = (ins Variadic:$elements); - let results = (outs Static1DQubitTensor:$result); - let assemblyFormat = "$elements attr-dict `:` type($result)"; + let arguments = (ins Variadic:$elements); + let results = (outs Static1DQubitTensor:$result); + let assemblyFormat = "$elements attr-dict `:` type($result)"; - let builders = [ - // Special case builder for when `elements` has size >=1. - OpBuilder<(ins "ValueRange":$elements)> - ]; + let builders = [ + // Special case builder for when `elements` has size >=1. + OpBuilder<(ins "ValueRange":$elements)>]; } -def ExtractOp : QTensorOp<"extract", [ - Pure, - TypesMatchWith<"result type matches element type of tensor", - "tensor", "result", - "::llvm::cast($_self).getElementType()">, - TypesMatchWith< - "returned tensor type matches input tensor", "tensor", "out_tensor", "$_self">]> { - let summary = "Extract element from tensor"; - let description = [{ +def ExtractOp + : QTensorOp< + "extract", + [Pure, + TypesMatchWith<"result type matches element type of tensor", + "tensor", "result", + "::llvm::cast($_self).getElementType()">, + TypesMatchWith<"returned tensor type matches input tensor", "tensor", + "out_tensor", "$_self">]> { + let summary = "Extract element from tensor"; + let description = [{ The `qtensor.extract` operation is the modified version of the standard `tensor.extract` operation of the tensor dialect. It reads a ranked tensor and returns one qubit from the input tensor at the given index. In addition, it also returns the updated input tensor as a result. @@ -131,21 +130,21 @@ def ExtractOp : QTensorOp<"extract", [ ``` }]; - let arguments = (ins 1DTensorOf<[QubitType]>:$tensor, Index:$index); - let results = (outs 1DTensorOf<[QubitType]>:$out_tensor, QubitType:$result); - let assemblyFormat = "$tensor `[` $index `]` attr-dict `:` type($tensor)"; + let arguments = (ins 1DTensorOf<[QubitType]>:$tensor, Index:$index); + let results = (outs 1DTensorOf<[QubitType]>:$out_tensor, QubitType:$result); + let assemblyFormat = "$tensor `[` $index `]` attr-dict `:` type($tensor)"; - let hasFolder = 1; - let hasVerifier = 1; + let hasFolder = 1; + let hasVerifier = 1; } -def ExtractSliceOp : QTensorOp<"extract_slice", [ - Pure, - TypesMatchWith<"returned tensor type matches input tensor", - "tensor", "out_tensor", "$_self"> - ]> { - let summary = "Extract slice from tensor"; - let description = [{ +def ExtractSliceOp + : QTensorOp<"extract_slice", + [Pure, + TypesMatchWith<"returned tensor type matches input tensor", + "tensor", "out_tensor", "$_self">]> { + let summary = "Extract slice from tensor"; + let description = [{ The `qtensor.extract_slice` operation is the modified version of the standard `tensor.extract_slice` operation of the tensor dialect. It reads a one-dimensional qubit tensor and returns the extracted tensor of qubits specified by the offset and size argument. In addition, it also returns the updated input tensor as result. @@ -163,38 +162,34 @@ def ExtractSliceOp : QTensorOp<"extract_slice", [ ``` }]; - let arguments = (ins - 1DTensorOf<[QubitType]>:$tensor, - Index:$offset, - Index:$size - ); - let results = (outs 1DTensorOf<[QubitType]>:$out_tensor, 1DTensorOf<[QubitType]>:$result); + let arguments = (ins 1DTensorOf<[QubitType]>:$tensor, Index:$offset, + Index:$size); + let results = (outs 1DTensorOf<[QubitType]>:$out_tensor, + 1DTensorOf<[QubitType]>:$result); - let assemblyFormat = [{ + let assemblyFormat = [{ $tensor `[`$offset `]` `[`$size`]` attr-dict `:` type($tensor) `to` type($result) }]; - let builders = [ - OpBuilder<(ins "Value":$tensor, "Value":$offset, - "Value":$size, - CArg<"ArrayRef", "{}">:$attrs)> - ]; + let builders = [OpBuilder<(ins "Value":$tensor, "Value":$offset, + "Value":$size, CArg<"ArrayRef", "{}">:$attrs)>]; - let hasFolder = 1; - let hasVerifier = 1; + let hasFolder = 1; + let hasVerifier = 1; } -def InsertOp : QTensorOp<"insert", [ - Pure, - TypesMatchWith<"result type matches type of dest", - "dest", "result", - "$_self">, - TypesMatchWith<"scalar type matches element type of dest", - "dest", "scalar", - "::llvm::cast($_self).getElementType()">]> { - let summary = "Insert element into tensor"; - let description = [{ +def InsertOp + : QTensorOp< + "insert", + [Pure, + TypesMatchWith<"result type matches type of dest", "dest", "result", + "$_self">, + TypesMatchWith< + "scalar type matches element type of dest", "dest", "scalar", + "::llvm::cast($_self).getElementType()">]> { + let summary = "Insert element into tensor"; + let description = [{ The `qtensor.insert` operation is a wrapper operation for the `tensor.insert` operation of the tensor dialect. This operation inserts a qubit scalar into a ranked tensor as specified by the operation's index. The insertion consumes the input qubit. @@ -205,25 +200,23 @@ def InsertOp : QTensorOp<"insert", [ ``` }]; - let arguments = (ins QubitType:$scalar, - 1DTensorOf<[QubitType]>:$dest, - Index:$index); - let results = (outs 1DTensorOf<[QubitType]>:$result); - let assemblyFormat = [{ + let arguments = (ins QubitType:$scalar, 1DTensorOf<[QubitType]>:$dest, + Index:$index); + let results = (outs 1DTensorOf<[QubitType]>:$result); + let assemblyFormat = [{ $scalar `into` $dest `[` $index `]` attr-dict `:` type($dest) }]; - let hasFolder = 1; - let hasVerifier = 1; + let hasFolder = 1; + let hasVerifier = 1; } -def InsertSliceOp : QTensorOp<"insert_slice", [ - Pure, - TypesMatchWith<"expected result type to match dest type", - "dest", "result", "$_self"> - ]> { - let summary = "Insert slice into tensor"; - let description = [{ +def InsertSliceOp + : QTensorOp<"insert_slice", + [Pure, TypesMatchWith<"expected result type to match dest type", + "dest", "result", "$_self">]> { + let summary = "Insert slice into tensor"; + let description = [{ The `qtensor.insert_slice` operation is a modified version of the `tensor.insert_slice` operation of the tensor dialect. The operation inserts a tensor `source` into another tensor `dest` as specified by the operation's offset and size arguments. This insertion consumes the `source` tensor of qubits. @@ -242,20 +235,16 @@ def InsertSliceOp : QTensorOp<"insert_slice", [ ``` }]; - let arguments = (ins - 1DTensorOf<[QubitType]>:$source, - 1DTensorOf<[QubitType]>:$dest, - Index:$offset, - Index:$size - ); - let results = (outs 1DTensorOf<[QubitType]>:$result); - let assemblyFormat = [{ + let arguments = (ins 1DTensorOf<[QubitType]>:$source, + 1DTensorOf<[QubitType]>:$dest, Index:$offset, Index:$size); + let results = (outs 1DTensorOf<[QubitType]>:$result); + let assemblyFormat = [{ $source `into` $dest `[`$offset `]` `[`$size`]` attr-dict `:` type($source) `into` type($dest) }]; - let hasFolder = 1; - let hasVerifier = 1; + let hasFolder = 1; + let hasVerifier = 1; } #endif // MLIR_DIALECT_QTENSOR_IR_QTENSOROPS_TD From c18b1b6667043d86fd09f4926e704fd418b218cf Mon Sep 17 00:00:00 2001 From: burgholzer Date: Thu, 19 Mar 2026 17:40:52 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=8E=A8=20Combine=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: burgholzer --- .pre-commit-config.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3815d30ee0..dc2a4383e9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -111,12 +111,8 @@ repos: - id: clang-format types_or: [c++, c, cuda] priority: 1 - - ## Format TableGen files with clang-format - - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v22.1.0 - hooks: - id: clang-format + name: clang-format (Tablegen) types_or: [file] files: \.td$ priority: 1 From 19c1a14c7db85ed74b825aaa17248b71a80040cf Mon Sep 17 00:00:00 2001 From: Daniel Haag <121057143+denialhaag@users.noreply.github.com> Date: Thu, 19 Mar 2026 18:35:04 +0100 Subject: [PATCH 3/3] Update changelog --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dc2a4383e9..4fa29e81ad 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -112,7 +112,7 @@ repos: types_or: [c++, c, cuda] priority: 1 - id: clang-format - name: clang-format (Tablegen) + name: clang-format (TableGen) types_or: [file] files: \.td$ priority: 1 diff --git a/CHANGELOG.md b/CHANGELOG.md index bb5994170e..8d798926f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel - ✨ Add conversions between Jeff and QCO ([#1479], [#1548], [#1565]) ([**@denialhaag**]) - ✨ Add a `place-and-route` pass for mapping circuits to architectures with restricted topologies ([#1537], [#1547], [#1568]) ([**@MatthiasReumann**]) - ✨ Add initial infrastructure for new QC and QCO MLIR dialects - ([#1264], [#1330], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1474], [#1475], [#1506], [#1510], [#1513], [#1521], [#1542], [#1548], [#1550], [#1554], [#1570], [#1572]) + ([#1264], [#1330], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1474], [#1475], [#1506], [#1510], [#1513], [#1521], [#1542], [#1548], [#1550], [#1554], [#1570], [#1572], [#1573]) ([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**], [**@simon1hofmann**]) ### Changed @@ -333,6 +333,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool +[#1573]: https://github.com/munich-quantum-toolkit/core/pull/1573 [#1572]: https://github.com/munich-quantum-toolkit/core/pull/1572 [#1571]: https://github.com/munich-quantum-toolkit/core/pull/1571 [#1570]: https://github.com/munich-quantum-toolkit/core/pull/1570