From 91b3ef949edc12e84f376ace12a3a2ee5b2c64ab Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Mon, 1 Jun 2026 14:22:26 +0200 Subject: [PATCH 01/80] feat(mlir): :sparkles: implement dead gate elimination canonicalization patterns --- .../include/mlir/Dialect/QCO/IR/QCODialect.td | 2 ++ mlir/include/mlir/Dialect/QCO/IR/QCOOps.td | 1 + mlir/include/mlir/Dialect/QCO/QCOUtils.h | 18 +++++++++++++++ .../Dialect/QCO/IR/Operations/MeasureOp.cpp | 22 +++++++++++++++++++ .../lib/Dialect/QCO/IR/Operations/ResetOp.cpp | 14 ++++++++++++ mlir/lib/Dialect/QCO/IR/QCOOps.cpp | 20 +++++++++++++++++ mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp | 14 ++++++++++++ 7 files changed, 91 insertions(+) diff --git a/mlir/include/mlir/Dialect/QCO/IR/QCODialect.td b/mlir/include/mlir/Dialect/QCO/IR/QCODialect.td index 62d1f5bba4..e7d98a0367 100644 --- a/mlir/include/mlir/Dialect/QCO/IR/QCODialect.td +++ b/mlir/include/mlir/Dialect/QCO/IR/QCODialect.td @@ -38,6 +38,8 @@ def QCODialect : Dialect { let cppNamespace = "::mlir::qco"; let useDefaultTypePrinterParser = 1; + + let hasCanonicalizer = 1; } #endif // MLIR_DIALECT_QCO_IR_QCODIALECT_TD diff --git a/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td b/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td index a5bbfb7f51..04cda7df4a 100644 --- a/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td +++ b/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td @@ -136,6 +136,7 @@ def MeasureOp : QCOOp<"measure"> { }]>]; let hasVerifier = 1; + let hasCanonicalizer = 1; } def ResetOp : QCOOp<"reset", [Idempotent, SameOperandsAndResultType]> { diff --git a/mlir/include/mlir/Dialect/QCO/QCOUtils.h b/mlir/include/mlir/Dialect/QCO/QCOUtils.h index 489fceb00e..5a21b5091c 100644 --- a/mlir/include/mlir/Dialect/QCO/QCOUtils.h +++ b/mlir/include/mlir/Dialect/QCO/QCOUtils.h @@ -237,4 +237,22 @@ mergeTwoTargetOneParameterWithSwappedTargets(OpType op, return success(); } +/** + * @brief Check if given quantum operation is unused (i.e., only used by + * deallocations) and remove it if so. + * + * @param op The operation to check. + * @param rewriter The pattern rewriter. + * @return LogicalResult Success or failure of the removal. + */ +LogicalResult checkAndRemoveDeadGate(Operation* op, PatternRewriter& rewriter) { + if (std::all_of(op->getUsers().begin(), op->getUsers().end(), + [](Operation* user) { return isa(user); })) { + // If the operation is only used by deallocs, we can safely remove it. + rewriter.replaceOp(op, op->getOperands()); + return success(); + } + return failure(); +} + } // namespace mlir::qco diff --git a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp index b76a2d0471..a71412a671 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp @@ -9,12 +9,29 @@ */ #include "mlir/Dialect/QCO/IR/QCOOps.h" +#include "mlir/Dialect/QCO/QCOUtils.h" #include using namespace mlir; using namespace mlir::qco; +namespace { + +/** + * @brief Remove dead measurements. + */ +struct DeadMeasurementRemoval final : OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(MeasureOp op, + PatternRewriter& rewriter) const override { + return checkAndRemoveDeadGate(op, rewriter); + } +}; + +} // namespace + LogicalResult MeasureOp::verify() { const auto registerName = getRegisterName(); const auto registerSize = getRegisterSize(); @@ -37,3 +54,8 @@ LogicalResult MeasureOp::verify() { } return success(); } + +void MeasureOp::getCanonicalizationPatterns(RewritePatternSet& results, + MLIRContext* context) { + results.add(context); +} diff --git a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp index 8832162354..462a28108d 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp @@ -9,6 +9,7 @@ */ #include "mlir/Dialect/QCO/IR/QCOOps.h" +#include "mlir/Dialect/QCO/QCOUtils.h" #include "mlir/Dialect/QTensor/IR/QTensorOps.h" #include "mlir/Dialect/QTensor/IR/QTensorUtils.h" @@ -101,6 +102,18 @@ struct RemoveResetAfterExtract final : OpRewritePattern { } }; +/** + * @brief Remove dead resets. + */ +struct DeadResetRemoval final : OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(ResetOp op, + PatternRewriter& rewriter) const override { + return checkAndRemoveDeadGate(op, rewriter); + } +}; + } // namespace OpFoldResult ResetOp::fold(FoldAdaptor /*adaptor*/) { @@ -114,4 +127,5 @@ OpFoldResult ResetOp::fold(FoldAdaptor /*adaptor*/) { void ResetOp::getCanonicalizationPatterns(RewritePatternSet& results, MLIRContext* context) { results.add(context); + results.add(context); } diff --git a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp index a3ce816081..b2d75a7cad 100644 --- a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp +++ b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp @@ -11,6 +11,7 @@ #include "mlir/Dialect/QCO/IR/QCOOps.h" #include "mlir/Dialect/QCO/IR/QCODialect.h" // IWYU pragma: associated +#include "mlir/Dialect/QCO/QCOUtils.h" #include #include @@ -30,6 +31,21 @@ using namespace mlir; using namespace mlir::qco; +//===----------------------------------------------------------------------===// +// Dialect-Level Canonicalizers +//===----------------------------------------------------------------------===// + +namespace { +struct DeadGateElimination + : public mlir::OpInterfaceRewritePattern { + + LogicalResult matchAndRewrite(UnitaryOpInterface op, + PatternRewriter& rewriter) const override { + return checkAndRemoveDeadGate(op.getOperation(), rewriter); + } +}; +} // namespace + //===----------------------------------------------------------------------===// // Custom Parsers //===----------------------------------------------------------------------===// @@ -258,6 +274,10 @@ void QCODialect::initialize() { >(); } +void QCODialect::getCanonicalizationPatterns(RewritePatternSet& results) const { + results.add(getContext()); +} + //===----------------------------------------------------------------------===// // Types //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp index 4ac2d98faa..bb401dd9f3 100644 --- a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp @@ -9,6 +9,7 @@ */ #include "mlir/Dialect/QCO/IR/QCOOps.h" +#include "mlir/Dialect/QCO/QCOUtils.h" #include #include @@ -234,11 +235,24 @@ struct ConditionPropagation : public OpRewritePattern { return success(changed); } }; + +/** + * @brief Remove dead resets. + */ +struct DeadIfRemoval final : OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + LogicalResult matchAndRewrite(IfOp op, + PatternRewriter& rewriter) const override { + return checkAndRemoveDeadGate(op, rewriter); + } +}; } // namespace void IfOp::getCanonicalizationPatterns(RewritePatternSet& results, MLIRContext* context) { results.add(context); + results.add(context); populateRegionBranchOpInterfaceCanonicalizationPatterns( results, IfOp::getOperationName()); } From ba57aa2f28d4df7a5f873314d2126572f1b22fc1 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Mon, 1 Jun 2026 15:15:54 +0200 Subject: [PATCH 02/80] fix(mlir): :bug: fix tests --- mlir/include/mlir/Dialect/QCO/QCOUtils.h | 15 ++++++++++++--- mlir/lib/Dialect/QCO/IR/QCOOps.cpp | 12 ++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/QCOUtils.h b/mlir/include/mlir/Dialect/QCO/QCOUtils.h index 5a21b5091c..8a46a7b72c 100644 --- a/mlir/include/mlir/Dialect/QCO/QCOUtils.h +++ b/mlir/include/mlir/Dialect/QCO/QCOUtils.h @@ -245,12 +245,21 @@ mergeTwoTargetOneParameterWithSwappedTargets(OpType op, * @param rewriter The pattern rewriter. * @return LogicalResult Success or failure of the removal. */ -LogicalResult checkAndRemoveDeadGate(Operation* op, PatternRewriter& rewriter) { +inline LogicalResult checkAndRemoveDeadGate(Operation* op, + PatternRewriter& rewriter) { if (std::all_of(op->getUsers().begin(), op->getUsers().end(), [](Operation* user) { return isa(user); })) { // If the operation is only used by deallocs, we can safely remove it. - rewriter.replaceOp(op, op->getOperands()); - return success(); + if (auto u = dyn_cast(op)) { + // We specifically have to replace the output *qubits* with the input + // *qubits* to ignore parameters. + rewriter.replaceOp(op, u.getInputQubits()); + return success(); + } else { + // This includes the `IfOp` as well as `Reset` and `Measure`. + rewriter.replaceOp(op, op->getOperands()); + return success(); + } } return failure(); } diff --git a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp index b2d75a7cad..61031d3258 100644 --- a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp +++ b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp @@ -36,11 +36,19 @@ using namespace mlir::qco; //===----------------------------------------------------------------------===// namespace { -struct DeadGateElimination - : public mlir::OpInterfaceRewritePattern { +struct DeadGateElimination final + : public OpInterfaceRewritePattern { + + explicit DeadGateElimination(MLIRContext* context) + : OpInterfaceRewritePattern(context) {} LogicalResult matchAndRewrite(UnitaryOpInterface op, PatternRewriter& rewriter) const override { + if (op->use_empty()) { + // This effectively ignores the GPhase operation and variants such as its + // inverse, which should never be considered dead. + return failure(); + } return checkAndRemoveDeadGate(op.getOperation(), rewriter); } }; From b83afab6110f9207b35b3a3cf67d515f9c085628 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Mon, 1 Jun 2026 15:26:59 +0200 Subject: [PATCH 03/80] test(mlir): :white_check_mark: add direct test for dead gate elimination --- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 413f29336d..1267ce553d 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -114,6 +114,39 @@ TEST_F(QCOTest, BuilderRejectsMixedStaticAndDynamicQubitAllocationModes) { "Cannot mix dynamic and static qubit allocation modes"); } +TEST_F(QCOTest, CheckDeadGateElimination) { + QCOProgramBuilder builder(context.get()); + builder.initialize(); + auto q0_0 = builder.allocQubit(); + auto q1_0 = builder.allocQubit(); + auto q0_1 = builder.h(q0_0); + auto [q0_2, q1_1] = builder.cx(q0_1, q1_0); + auto q1_2 = builder.h(q1_1); + builder.sink(q0_2); + builder.sink(q1_2); + auto module = builder.finalize(); + + QCOProgramBuilder reference(context.get()); + reference.initialize(); + auto r0 = reference.allocQubit(); + auto r1 = reference.allocQubit(); + reference.sink(r0); + reference.sink(r1); + auto ref = reference.finalize(); + + ASSERT_TRUE(module); + EXPECT_TRUE(verify(*module).succeeded()); + EXPECT_TRUE(runQCOCleanupPipeline(module.get()).succeeded()); + EXPECT_TRUE(verify(*module).succeeded()); + + ASSERT_TRUE(ref); + EXPECT_TRUE(verify(*ref).succeeded()); + EXPECT_TRUE(runQCOCleanupPipeline(ref.get()).succeeded()); + EXPECT_TRUE(verify(*ref).succeeded()); + + EXPECT_TRUE(areModulesEquivalentWithPermutations(module.get(), ref.get())); +} + TEST_F(QCOTest, DirectIfBuilder) { // Test If construction directly QCOProgramBuilder builder(context.get()); From 4243ac0f78ac780cd7446b45f1411e72adc33893 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Mon, 1 Jun 2026 15:35:41 +0200 Subject: [PATCH 04/80] docs(mlir): :memo: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dad0d3abf3..ed0b4dfbcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel ### Added +- ✨ Add Dead Gate Elimination Pattern ([#1755]) ([**DRovara**]) - 🚸 Add [CMake presets] to provide a standardized and reproducible way to configure builds ([#1660]) ([**@denialhaag**]) - ✨ Add a `quantum-loop-unroll` pass for unrolling for-loop operations containing quantum operations ([#1718]) ([**@MatthiasReumann**]) - ✨ Add a `hadamard-lifting` pass for lifting Hadamard gates above Pauli gates ([#1605]) ([**@lirem101**], [**@burgholzer**]) @@ -402,6 +403,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool +[#1755]: https://github.com/munich-quantum-toolkit/core/pull/1755 [#1749]: https://github.com/munich-quantum-toolkit/core/pull/1749 [#1748]: https://github.com/munich-quantum-toolkit/core/pull/1748 [#1737]: https://github.com/munich-quantum-toolkit/core/pull/1737 From a50032b48137f23e43bc378d55afbc8795571540 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Mon, 1 Jun 2026 15:48:49 +0200 Subject: [PATCH 05/80] style(mlir): :rotating_light: fix linter issues --- mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp | 2 ++ mlir/lib/Dialect/QCO/IR/QCOOps.cpp | 3 +++ mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 14 +++++++------- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp index a71412a671..5d0462b6d7 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp @@ -11,6 +11,8 @@ #include "mlir/Dialect/QCO/IR/QCOOps.h" #include "mlir/Dialect/QCO/QCOUtils.h" +#include +#include #include using namespace mlir; diff --git a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp index 61031d3258..33474448d7 100644 --- a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp +++ b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp @@ -11,13 +11,16 @@ #include "mlir/Dialect/QCO/IR/QCOOps.h" #include "mlir/Dialect/QCO/IR/QCODialect.h" // IWYU pragma: associated +#include "mlir/Dialect/QCO/IR/QCOInterfaces.h" #include "mlir/Dialect/QCO/QCOUtils.h" #include #include +#include #include #include #include +#include #include #include #include diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 1267ce553d..7c76b2a049 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -117,13 +117,13 @@ TEST_F(QCOTest, BuilderRejectsMixedStaticAndDynamicQubitAllocationModes) { TEST_F(QCOTest, CheckDeadGateElimination) { QCOProgramBuilder builder(context.get()); builder.initialize(); - auto q0_0 = builder.allocQubit(); - auto q1_0 = builder.allocQubit(); - auto q0_1 = builder.h(q0_0); - auto [q0_2, q1_1] = builder.cx(q0_1, q1_0); - auto q1_2 = builder.h(q1_1); - builder.sink(q0_2); - builder.sink(q1_2); + auto q0S0 = builder.allocQubit(); + auto q1S0 = builder.allocQubit(); + auto q0S1 = builder.h(q0S0); + auto [q0S2, q1S1] = builder.cx(q0S1, q1S0); + auto q1S2 = builder.h(q1S1); + builder.sink(q0S2); + builder.sink(q1S2); auto module = builder.finalize(); QCOProgramBuilder reference(context.get()); From d8c9ad5bfb3890caf957b9b4e8de206067435cf7 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 2 Jun 2026 09:37:45 +0200 Subject: [PATCH 06/80] fix(mlir): :recycle: guard RegionOp removal for child oeprations with memory effects --- mlir/include/mlir/Dialect/QCO/IR/QCOOps.td | 228 +++++++++--------- mlir/include/mlir/Dialect/QCO/QCOUtils.h | 12 +- mlir/lib/Dialect/QCO/IR/QCOOps.cpp | 9 +- mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp | 2 +- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 4 +- 5 files changed, 137 insertions(+), 118 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td b/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td index 04cda7df4a..4b05cd1442 100644 --- a/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td +++ b/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td @@ -96,7 +96,7 @@ def StaticOp : QCOOp<"static", [Pure]> { // Measurement and Reset Operations //===----------------------------------------------------------------------===// -def MeasureOp : QCOOp<"measure"> { +def MeasureOp : QCOOp<"measure", [Pure]> { let summary = "Measure a qubit in the computational basis"; let description = [{ Measures a qubit in the computational (Z) basis, collapsing the state @@ -119,8 +119,7 @@ def MeasureOp : QCOOp<"measure"> { ``` }]; - let arguments = (ins Arg:$qubit_in, + let arguments = (ins Arg:$qubit_in, OptionalAttr:$register_name, OptionalAttr>:$register_size, OptionalAttr>:$register_index); @@ -139,7 +138,7 @@ def MeasureOp : QCOOp<"measure"> { let hasCanonicalizer = 1; } -def ResetOp : QCOOp<"reset", [Idempotent, SameOperandsAndResultType]> { +def ResetOp : QCOOp<"reset", [Idempotent, SameOperandsAndResultType, Pure]> { let summary = "Reset a qubit to |0⟩ state"; let description = [{ Resets a qubit to the |0⟩ state, regardless of its current state, @@ -151,8 +150,7 @@ def ResetOp : QCOOp<"reset", [Idempotent, SameOperandsAndResultType]> { ``` }]; - let arguments = - (ins Arg:$qubit_in); + let arguments = (ins Arg:$qubit_in); let results = (outs QubitType:$qubit_out); let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; @@ -209,7 +207,8 @@ def GPhaseOp let hasCanonicalizer = 1; } -def IdOp : QCOOp<"id", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { +def IdOp + : QCOOp<"id", traits = [UnitaryOpInterface, OneTargetZeroParameter, Pure]> { let summary = "Apply an Id gate to a qubit"; let description = [{ Applies an Id gate to a qubit and returns the transformed qubit. @@ -220,7 +219,7 @@ def IdOp : QCOOp<"id", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); + let arguments = (ins Arg:$qubit_in); let results = (outs QubitType:$qubit_out); let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; @@ -233,7 +232,8 @@ def IdOp : QCOOp<"id", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { let hasCanonicalizer = 1; } -def XOp : QCOOp<"x", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { +def XOp + : QCOOp<"x", traits = [UnitaryOpInterface, OneTargetZeroParameter, Pure]> { let summary = "Apply an X gate to a qubit"; let description = [{ Applies an X gate to a qubit and returns the transformed qubit. @@ -244,7 +244,7 @@ def XOp : QCOOp<"x", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); + let arguments = (ins Arg:$qubit_in); let results = (outs QubitType:$qubit_out); let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; @@ -257,7 +257,8 @@ def XOp : QCOOp<"x", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { let hasCanonicalizer = 1; } -def YOp : QCOOp<"y", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { +def YOp + : QCOOp<"y", traits = [UnitaryOpInterface, OneTargetZeroParameter, Pure]> { let summary = "Apply a Y gate to a qubit"; let description = [{ Applies a Y gate to a qubit and returns the transformed qubit. @@ -268,7 +269,7 @@ def YOp : QCOOp<"y", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); + let arguments = (ins Arg:$qubit_in); let results = (outs QubitType:$qubit_out); let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; @@ -281,7 +282,8 @@ def YOp : QCOOp<"y", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { let hasCanonicalizer = 1; } -def ZOp : QCOOp<"z", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { +def ZOp + : QCOOp<"z", traits = [UnitaryOpInterface, OneTargetZeroParameter, Pure]> { let summary = "Apply a Z gate to a qubit"; let description = [{ Applies a Z gate to a qubit and returns the transformed qubit. @@ -292,7 +294,7 @@ def ZOp : QCOOp<"z", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); + let arguments = (ins Arg:$qubit_in); let results = (outs QubitType:$qubit_out); let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; @@ -305,7 +307,8 @@ def ZOp : QCOOp<"z", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { let hasCanonicalizer = 1; } -def HOp : QCOOp<"h", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { +def HOp + : QCOOp<"h", traits = [UnitaryOpInterface, OneTargetZeroParameter, Pure]> { let summary = "Apply a H gate to a qubit"; let description = [{ Applies a H gate to a qubit and returns the transformed qubit. @@ -316,7 +319,7 @@ def HOp : QCOOp<"h", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); + let arguments = (ins Arg:$qubit_in); let results = (outs QubitType:$qubit_out); let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; @@ -329,7 +332,8 @@ def HOp : QCOOp<"h", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { let hasCanonicalizer = 1; } -def SOp : QCOOp<"s", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { +def SOp + : QCOOp<"s", traits = [UnitaryOpInterface, OneTargetZeroParameter, Pure]> { let summary = "Apply an S gate to a qubit"; let description = [{ Applies an S gate to a qubit and returns the transformed qubit. @@ -340,7 +344,7 @@ def SOp : QCOOp<"s", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); + let arguments = (ins Arg:$qubit_in); let results = (outs QubitType:$qubit_out); let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; @@ -353,8 +357,8 @@ def SOp : QCOOp<"s", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { let hasCanonicalizer = 1; } -def SdgOp - : QCOOp<"sdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { +def SdgOp : QCOOp<"sdg", + traits = [UnitaryOpInterface, OneTargetZeroParameter, Pure]> { let summary = "Apply an Sdg gate to a qubit"; let description = [{ Applies an Sdg gate to a qubit and returns the transformed qubit. @@ -365,7 +369,7 @@ def SdgOp ``` }]; - let arguments = (ins Arg:$qubit_in); + let arguments = (ins Arg:$qubit_in); let results = (outs QubitType:$qubit_out); let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; @@ -378,7 +382,8 @@ def SdgOp let hasCanonicalizer = 1; } -def TOp : QCOOp<"t", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { +def TOp + : QCOOp<"t", traits = [UnitaryOpInterface, OneTargetZeroParameter, Pure]> { let summary = "Apply a T gate to a qubit"; let description = [{ Applies a T gate to a qubit and returns the transformed qubit. @@ -389,7 +394,7 @@ def TOp : QCOOp<"t", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); + let arguments = (ins Arg:$qubit_in); let results = (outs QubitType:$qubit_out); let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; @@ -402,8 +407,8 @@ def TOp : QCOOp<"t", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { let hasCanonicalizer = 1; } -def TdgOp - : QCOOp<"tdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { +def TdgOp : QCOOp<"tdg", + traits = [UnitaryOpInterface, OneTargetZeroParameter, Pure]> { let summary = "Apply a Tdg gate to a qubit"; let description = [{ Applies a Tdg gate to a qubit and returns the transformed qubit. @@ -414,7 +419,7 @@ def TdgOp ``` }]; - let arguments = (ins Arg:$qubit_in); + let arguments = (ins Arg:$qubit_in); let results = (outs QubitType:$qubit_out); let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; @@ -427,7 +432,8 @@ def TdgOp let hasCanonicalizer = 1; } -def SXOp : QCOOp<"sx", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { +def SXOp + : QCOOp<"sx", traits = [UnitaryOpInterface, OneTargetZeroParameter, Pure]> { let summary = "Apply an SX gate to a qubit"; let description = [{ Applies an SX gate to a qubit and returns the transformed qubit. @@ -438,7 +444,7 @@ def SXOp : QCOOp<"sx", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in); + let arguments = (ins Arg:$qubit_in); let results = (outs QubitType:$qubit_out); let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; @@ -451,8 +457,8 @@ def SXOp : QCOOp<"sx", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { let hasCanonicalizer = 1; } -def SXdgOp - : QCOOp<"sxdg", traits = [UnitaryOpInterface, OneTargetZeroParameter]> { +def SXdgOp : QCOOp<"sxdg", traits = [UnitaryOpInterface, OneTargetZeroParameter, + Pure]> { let summary = "Apply an SXdg gate to a qubit"; let description = [{ Applies an SXdg gate to a qubit and returns the transformed qubit. @@ -463,7 +469,7 @@ def SXdgOp ``` }]; - let arguments = (ins Arg:$qubit_in); + let arguments = (ins Arg:$qubit_in); let results = (outs QubitType:$qubit_out); let assemblyFormat = "$qubit_in attr-dict `:` type($qubit_in) `->` type($qubit_out)"; @@ -476,7 +482,8 @@ def SXdgOp let hasCanonicalizer = 1; } -def RXOp : QCOOp<"rx", traits = [UnitaryOpInterface, OneTargetOneParameter]> { +def RXOp + : QCOOp<"rx", traits = [UnitaryOpInterface, OneTargetOneParameter, Pure]> { let summary = "Apply an RX gate to a qubit"; let description = [{ Applies an RX gate to a qubit and returns the transformed qubit. @@ -487,7 +494,7 @@ def RXOp : QCOOp<"rx", traits = [UnitaryOpInterface, OneTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, + let arguments = (ins Arg:$qubit_in, Arg:$theta); let results = (outs QubitType:$qubit_out); let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in) " @@ -505,7 +512,8 @@ def RXOp : QCOOp<"rx", traits = [UnitaryOpInterface, OneTargetOneParameter]> { let hasCanonicalizer = 1; } -def RYOp : QCOOp<"ry", traits = [UnitaryOpInterface, OneTargetOneParameter]> { +def RYOp + : QCOOp<"ry", traits = [UnitaryOpInterface, OneTargetOneParameter, Pure]> { let summary = "Apply an RY gate to a qubit"; let description = [{ Applies an RY gate to a qubit and returns the transformed qubit. @@ -516,7 +524,7 @@ def RYOp : QCOOp<"ry", traits = [UnitaryOpInterface, OneTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, + let arguments = (ins Arg:$qubit_in, Arg:$theta); let results = (outs QubitType:$qubit_out); let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in) " @@ -534,7 +542,8 @@ def RYOp : QCOOp<"ry", traits = [UnitaryOpInterface, OneTargetOneParameter]> { let hasCanonicalizer = 1; } -def RZOp : QCOOp<"rz", traits = [UnitaryOpInterface, OneTargetOneParameter]> { +def RZOp + : QCOOp<"rz", traits = [UnitaryOpInterface, OneTargetOneParameter, Pure]> { let summary = "Apply an RZ gate to a qubit"; let description = [{ Applies an RZ gate to a qubit and returns the transformed qubit. @@ -545,7 +554,7 @@ def RZOp : QCOOp<"rz", traits = [UnitaryOpInterface, OneTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, + let arguments = (ins Arg:$qubit_in, Arg:$theta); let results = (outs QubitType:$qubit_out); let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in) " @@ -563,7 +572,8 @@ def RZOp : QCOOp<"rz", traits = [UnitaryOpInterface, OneTargetOneParameter]> { let hasCanonicalizer = 1; } -def POp : QCOOp<"p", traits = [UnitaryOpInterface, OneTargetOneParameter]> { +def POp + : QCOOp<"p", traits = [UnitaryOpInterface, OneTargetOneParameter, Pure]> { let summary = "Apply a P gate to a qubit"; let description = [{ Applies a P gate to a qubit and returns the transformed qubit. @@ -574,7 +584,7 @@ def POp : QCOOp<"p", traits = [UnitaryOpInterface, OneTargetOneParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, + let arguments = (ins Arg:$qubit_in, Arg:$theta); let results = (outs QubitType:$qubit_out); let assemblyFormat = "`(` $theta `)` $qubit_in attr-dict `:` type($qubit_in) " @@ -592,7 +602,8 @@ def POp : QCOOp<"p", traits = [UnitaryOpInterface, OneTargetOneParameter]> { let hasCanonicalizer = 1; } -def ROp : QCOOp<"r", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { +def ROp + : QCOOp<"r", traits = [UnitaryOpInterface, OneTargetTwoParameter, Pure]> { let summary = "Apply an R gate to a qubit"; let description = [{ Applies an R gate to a qubit and returns the transformed qubit. @@ -603,7 +614,7 @@ def ROp : QCOOp<"r", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, + let arguments = (ins Arg:$qubit_in, Arg:$theta, Arg:$phi); let results = (outs QubitType:$qubit_out); @@ -622,7 +633,8 @@ def ROp : QCOOp<"r", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { let hasCanonicalizer = 1; } -def U2Op : QCOOp<"u2", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { +def U2Op + : QCOOp<"u2", traits = [UnitaryOpInterface, OneTargetTwoParameter, Pure]> { let summary = "Apply a U2 gate to a qubit"; let description = [{ Applies a U2 gate to a qubit and returns the transformed qubit. @@ -633,7 +645,7 @@ def U2Op : QCOOp<"u2", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, + let arguments = (ins Arg:$qubit_in, Arg:$phi, Arg:$lambda); let results = (outs QubitType:$qubit_out); @@ -652,7 +664,8 @@ def U2Op : QCOOp<"u2", traits = [UnitaryOpInterface, OneTargetTwoParameter]> { let hasCanonicalizer = 1; } -def UOp : QCOOp<"u", traits = [UnitaryOpInterface, OneTargetThreeParameter]> { +def UOp + : QCOOp<"u", traits = [UnitaryOpInterface, OneTargetThreeParameter, Pure]> { let summary = "Apply a U gate to a qubit"; let description = [{ Applies a U gate to a qubit and returns the transformed qubit. @@ -663,7 +676,7 @@ def UOp : QCOOp<"u", traits = [UnitaryOpInterface, OneTargetThreeParameter]> { ``` }]; - let arguments = (ins Arg:$qubit_in, + let arguments = (ins Arg:$qubit_in, Arg:$theta, Arg:$phi, Arg:$lambda); @@ -684,8 +697,8 @@ def UOp : QCOOp<"u", traits = [UnitaryOpInterface, OneTargetThreeParameter]> { let hasCanonicalizer = 1; } -def SWAPOp - : QCOOp<"swap", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { +def SWAPOp : QCOOp<"swap", traits = [UnitaryOpInterface, TwoTargetZeroParameter, + Pure]> { let summary = "Apply a SWAP gate to two qubits"; let description = [{ Applies a SWAP gate to two qubits and returns the transformed qubits. @@ -696,9 +709,8 @@ def SWAPOp ``` }]; - let arguments = - (ins Arg:$qubit0_in, - Arg:$qubit1_in); + 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) `,` " @@ -712,8 +724,8 @@ def SWAPOp let hasCanonicalizer = 1; } -def iSWAPOp - : QCOOp<"iswap", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { +def iSWAPOp : QCOOp<"iswap", traits = [UnitaryOpInterface, + TwoTargetZeroParameter, Pure]> { let summary = "Apply a iSWAP gate to two qubits"; let description = [{ Applies a iSWAP gate to two qubits and returns the transformed qubits. @@ -724,9 +736,8 @@ def iSWAPOp ``` }]; - let arguments = - (ins Arg:$qubit0_in, - Arg:$qubit1_in); + 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) `,` " @@ -738,8 +749,8 @@ def iSWAPOp }]; } -def DCXOp - : QCOOp<"dcx", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { +def DCXOp : QCOOp<"dcx", + traits = [UnitaryOpInterface, TwoTargetZeroParameter, Pure]> { let summary = "Apply a DCX gate to two qubits"; let description = [{ Applies a DCX gate to two qubits and returns the transformed qubits. @@ -750,9 +761,8 @@ def DCXOp ``` }]; - let arguments = - (ins Arg:$qubit0_in, - Arg:$qubit1_in); + 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) `,` " @@ -766,8 +776,8 @@ def DCXOp let hasCanonicalizer = 1; } -def ECROp - : QCOOp<"ecr", traits = [UnitaryOpInterface, TwoTargetZeroParameter]> { +def ECROp : QCOOp<"ecr", + traits = [UnitaryOpInterface, TwoTargetZeroParameter, Pure]> { let summary = "Apply an ECR gate to two qubits"; let description = [{ Applies an ECR gate to two qubits and returns the transformed qubits. @@ -778,9 +788,8 @@ def ECROp ``` }]; - let arguments = - (ins Arg:$qubit0_in, - Arg:$qubit1_in); + 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) `,` " @@ -794,7 +803,8 @@ def ECROp let hasCanonicalizer = 1; } -def RXXOp : QCOOp<"rxx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { +def RXXOp + : QCOOp<"rxx", traits = [UnitaryOpInterface, TwoTargetOneParameter, Pure]> { let summary = "Apply an RXX gate to two qubits"; let description = [{ Applies an RXX gate to two qubits and returns the transformed qubits. @@ -805,10 +815,9 @@ def RXXOp : QCOOp<"rxx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { ``` }]; - let arguments = - (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta); + 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) " @@ -826,7 +835,8 @@ def RXXOp : QCOOp<"rxx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { let hasCanonicalizer = 1; } -def RYYOp : QCOOp<"ryy", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { +def RYYOp + : QCOOp<"ryy", traits = [UnitaryOpInterface, TwoTargetOneParameter, Pure]> { let summary = "Apply an RYY gate to two qubits"; let description = [{ Applies an RYY gate to two qubits and returns the transformed qubits. @@ -837,10 +847,9 @@ def RYYOp : QCOOp<"ryy", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { ``` }]; - let arguments = - (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta); + 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) " @@ -858,7 +867,8 @@ def RYYOp : QCOOp<"ryy", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { let hasCanonicalizer = 1; } -def RZXOp : QCOOp<"rzx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { +def RZXOp + : QCOOp<"rzx", traits = [UnitaryOpInterface, TwoTargetOneParameter, Pure]> { let summary = "Apply an RZX gate to two qubits"; let description = [{ Applies an RZX gate to two qubits and returns the transformed qubits. @@ -869,10 +879,9 @@ def RZXOp : QCOOp<"rzx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { ``` }]; - let arguments = - (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta); + 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) " @@ -890,7 +899,8 @@ def RZXOp : QCOOp<"rzx", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { let hasCanonicalizer = 1; } -def RZZOp : QCOOp<"rzz", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { +def RZZOp + : QCOOp<"rzz", traits = [UnitaryOpInterface, TwoTargetOneParameter, Pure]> { let summary = "Apply an RZZ gate to two qubits"; let description = [{ Applies an RZZ gate to two qubits and returns the transformed qubits. @@ -901,10 +911,9 @@ def RZZOp : QCOOp<"rzz", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { ``` }]; - let arguments = - (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta); + 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) " @@ -922,8 +931,8 @@ def RZZOp : QCOOp<"rzz", traits = [UnitaryOpInterface, TwoTargetOneParameter]> { let hasCanonicalizer = 1; } -def XXPlusYYOp : QCOOp<"xx_plus_yy", - traits = [UnitaryOpInterface, TwoTargetTwoParameter]> { +def XXPlusYYOp : QCOOp<"xx_plus_yy", traits = [UnitaryOpInterface, + TwoTargetTwoParameter, Pure]> { 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. @@ -934,11 +943,10 @@ def XXPlusYYOp : QCOOp<"xx_plus_yy", ``` }]; - let arguments = - (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta, - Arg:$beta); + 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) " @@ -957,8 +965,8 @@ def XXPlusYYOp : QCOOp<"xx_plus_yy", let hasCanonicalizer = 1; } -def XXMinusYYOp : QCOOp<"xx_minus_yy", - traits = [UnitaryOpInterface, TwoTargetTwoParameter]> { +def XXMinusYYOp : QCOOp<"xx_minus_yy", traits = [UnitaryOpInterface, + TwoTargetTwoParameter, Pure]> { 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. @@ -969,11 +977,10 @@ def XXMinusYYOp : QCOOp<"xx_minus_yy", ``` }]; - let arguments = - (ins Arg:$qubit0_in, - Arg:$qubit1_in, - Arg:$theta, - Arg:$beta); + 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) " @@ -992,7 +999,7 @@ def XXMinusYYOp : QCOOp<"xx_minus_yy", let hasCanonicalizer = 1; } -def BarrierOp : QCOOp<"barrier", traits = [UnitaryOpInterface]> { +def BarrierOp : QCOOp<"barrier", traits = [UnitaryOpInterface, Pure]> { 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. @@ -1004,7 +1011,7 @@ def BarrierOp : QCOOp<"barrier", traits = [UnitaryOpInterface]> { }]; let arguments = - (ins Arg, "the target qubits", [MemRead]>:$qubits_in); + (ins Arg, "the target qubits">:$qubits_in); let results = (outs Variadic:$qubits_out); let assemblyFormat = "$qubits_in attr-dict `:` type($qubits_in) `->` type($qubits_out)"; @@ -1042,7 +1049,7 @@ def BarrierOp : QCOOp<"barrier", traits = [UnitaryOpInterface]> { // Modifiers //===----------------------------------------------------------------------===// -def YieldOp : QCOOp<"yield", traits = [Terminator, ReturnLike]> { +def YieldOp : QCOOp<"yield", traits = [Terminator, ReturnLike, Pure]> { let summary = "Yield from a modifier region"; let description = [{ Terminates a modifier region, yielding the transformed target qubit and qtensor values back to the enclosing modifier operation. @@ -1067,7 +1074,7 @@ def CtrlOp AttrSizedResultSegments, SameOperandsAndResultType, SameOperandsAndResultShape, SingleBlockImplicitTerminator<"::mlir::qco::YieldOp">, - RecursiveMemoryEffects]> { + Pure, RecursiveMemoryEffects]> { let summary = "Add control qubits to a unitary operation"; let description = [{ A modifier operation that adds control qubits to the unitary operation @@ -1086,9 +1093,9 @@ def CtrlOp ``` }]; - let arguments = (ins Arg, - "the control qubits", [MemRead]>:$controls_in, - Arg, "the target qubits", [MemRead]>:$targets_in); + let arguments = + (ins Arg, "the control qubits">:$controls_in, + Arg, "the target qubits">:$targets_in); let results = (outs Variadic:$controls_out, Variadic:$targets_out); let regions = (region SizedRegion<1>:$region); @@ -1144,7 +1151,7 @@ def InvOp : QCOOp<"inv", traits = [UnitaryOpInterface, SingleBlockImplicitTerminator<"::mlir::qco::YieldOp">, - RecursiveMemoryEffects]> { + Pure, RecursiveMemoryEffects]> { let summary = "Invert a unitary operation"; let description = [{ A modifier operation that inverts the unitary operation defined in its body @@ -1160,9 +1167,8 @@ def InvOp ``` }]; - let arguments = - (ins Arg, - "the qubits involved in the operation", [MemRead]>:$qubits_in); + let arguments = (ins Arg, + "the qubits involved in the operation">:$qubits_in); let results = (outs Variadic:$qubits_out); let regions = (region SizedRegion<1>:$region); let assemblyFormat = [{ @@ -1222,7 +1228,7 @@ def IfOp "getRegionInvocationBounds", "getEntrySuccessorRegions"]>, SingleBlock, - SingleBlockImplicitTerminator<"::mlir::qco::YieldOp">, + SingleBlockImplicitTerminator<"::mlir::qco::YieldOp">, Pure, RecursiveMemoryEffects]> { let summary = "If-then-else operation for linear (qubit) types"; diff --git a/mlir/include/mlir/Dialect/QCO/QCOUtils.h b/mlir/include/mlir/Dialect/QCO/QCOUtils.h index 8a46a7b72c..6135c416cd 100644 --- a/mlir/include/mlir/Dialect/QCO/QCOUtils.h +++ b/mlir/include/mlir/Dialect/QCO/QCOUtils.h @@ -239,7 +239,7 @@ mergeTwoTargetOneParameterWithSwappedTargets(OpType op, /** * @brief Check if given quantum operation is unused (i.e., only used by - * deallocations) and remove it if so. + * sinks) and remove it if so. * * @param op The operation to check. * @param rewriter The pattern rewriter. @@ -249,14 +249,20 @@ inline LogicalResult checkAndRemoveDeadGate(Operation* op, PatternRewriter& rewriter) { if (std::all_of(op->getUsers().begin(), op->getUsers().end(), [](Operation* user) { return isa(user); })) { - // If the operation is only used by deallocs, we can safely remove it. + // If the operation is only used by sinks, we can safely remove it. if (auto u = dyn_cast(op)) { // We specifically have to replace the output *qubits* with the input // *qubits* to ignore parameters. rewriter.replaceOp(op, u.getInputQubits()); return success(); + } else if (auto m = dyn_cast(op)) { + // We specifically have to replace the output *qubits* with the input + // *qubits* to ignore the classical outcome. + rewriter.replaceAllUsesWith(m.getQubitOut(), m.getQubitIn()); + rewriter.eraseOp(op); + return success(); } else { - // This includes the `IfOp` as well as `Reset` and `Measure`. + // This includes the `IfOp` as well as `Reset`. rewriter.replaceOp(op, op->getOperands()); return success(); } diff --git a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp index 33474448d7..fe11640e0d 100644 --- a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp +++ b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp @@ -39,6 +39,10 @@ using namespace mlir::qco; //===----------------------------------------------------------------------===// namespace { + +/** + * @brief Remove dead measurements. + */ struct DeadGateElimination final : public OpInterfaceRewritePattern { @@ -47,9 +51,10 @@ struct DeadGateElimination final LogicalResult matchAndRewrite(UnitaryOpInterface op, PatternRewriter& rewriter) const override { - if (op->use_empty()) { + if (!isMemoryEffectFree(op)) { // This effectively ignores the GPhase operation and variants such as its - // inverse, which should never be considered dead. + // inverse or `if` ops containing it, which should never be considered + // dead. return failure(); } return checkAndRemoveDeadGate(op.getOperation(), rewriter); diff --git a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp index bb401dd9f3..fc10e98157 100644 --- a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp @@ -237,7 +237,7 @@ struct ConditionPropagation : public OpRewritePattern { }; /** - * @brief Remove dead resets. + * @brief Remove dead `IfOp` instructions. */ struct DeadIfRemoval final : OpRewritePattern { using OpRewritePattern::OpRewritePattern; diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 7c76b2a049..f1d3f02777 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -121,7 +121,7 @@ TEST_F(QCOTest, CheckDeadGateElimination) { auto q1S0 = builder.allocQubit(); auto q0S1 = builder.h(q0S0); auto [q0S2, q1S1] = builder.cx(q0S1, q1S0); - auto q1S2 = builder.h(q1S1); + auto [q1S2, c1] = builder.measure(q1S1); builder.sink(q0S2); builder.sink(q1S2); auto module = builder.finalize(); @@ -144,6 +144,8 @@ TEST_F(QCOTest, CheckDeadGateElimination) { EXPECT_TRUE(runQCOCleanupPipeline(ref.get()).succeeded()); EXPECT_TRUE(verify(*ref).succeeded()); + module.get().dump(); + EXPECT_TRUE(areModulesEquivalentWithPermutations(module.get(), ref.get())); } From 97175472e086cdd46e8bb5393d16cc7024729dd7 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 2 Jun 2026 09:54:03 +0200 Subject: [PATCH 07/80] fix(mlir): :bug: fix handling for `IfOp` removal and add specialized test --- mlir/include/mlir/Dialect/QCO/QCOUtils.h | 7 +- mlir/lib/Dialect/QCO/IR/QCOOps.cpp | 1 + mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 87 +++++++++++++++++-- 3 files changed, 87 insertions(+), 8 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/QCOUtils.h b/mlir/include/mlir/Dialect/QCO/QCOUtils.h index 6135c416cd..deda577eba 100644 --- a/mlir/include/mlir/Dialect/QCO/QCOUtils.h +++ b/mlir/include/mlir/Dialect/QCO/QCOUtils.h @@ -261,8 +261,13 @@ inline LogicalResult checkAndRemoveDeadGate(Operation* op, rewriter.replaceAllUsesWith(m.getQubitOut(), m.getQubitIn()); rewriter.eraseOp(op); return success(); + } else if (auto i = dyn_cast(op)) { + // We specifically have to replace the output *qubits* with the input + // *qubits* to ignore the condition. + rewriter.replaceOp(op, i.getQubits()); + return success(); } else { - // This includes the `IfOp` as well as `Reset`. + // This currently only includes the `Reset` operation. rewriter.replaceOp(op, op->getOperands()); return success(); } diff --git a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp index fe11640e0d..dc302e3028 100644 --- a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp +++ b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include // The following headers are needed for some template instantiations. diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index f1d3f02777..3af2feb196 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -132,21 +132,94 @@ TEST_F(QCOTest, CheckDeadGateElimination) { auto r1 = reference.allocQubit(); reference.sink(r0); reference.sink(r1); - auto ref = reference.finalize(); + auto refModule = reference.finalize(); ASSERT_TRUE(module); EXPECT_TRUE(verify(*module).succeeded()); EXPECT_TRUE(runQCOCleanupPipeline(module.get()).succeeded()); EXPECT_TRUE(verify(*module).succeeded()); - ASSERT_TRUE(ref); - EXPECT_TRUE(verify(*ref).succeeded()); - EXPECT_TRUE(runQCOCleanupPipeline(ref.get()).succeeded()); - EXPECT_TRUE(verify(*ref).succeeded()); + ASSERT_TRUE(refModule); + EXPECT_TRUE(verify(*refModule).succeeded()); + EXPECT_TRUE(runQCOCleanupPipeline(refModule.get()).succeeded()); + EXPECT_TRUE(verify(*refModule).succeeded()); - module.get().dump(); + EXPECT_TRUE( + areModulesEquivalentWithPermutations(module.get(), refModule.get())); +} + +TEST_F(QCOTest, CheckIfOpDeadGateElimination) { + QCOProgramBuilder builder(context.get()); + builder.initialize(); + auto q0S0 = builder.allocQubit(); + auto q1S0 = builder.allocQubit(); + auto q0S1 = builder.h(q0S0); + auto [q0S2, c0] = builder.measure(q0S1); + + // This is an `if` with memory effects - it can't be removed. + auto q1S1 = builder.qcoIf( + c0, {q1S0}, + [&](ValueRange qubits) -> SmallVector { + auto q1Then = builder.x(qubits[0]); + builder.gphase(0.5); + return SmallVector{q1Then}; + }, + [&](ValueRange qubits) -> SmallVector { + auto q1Else = builder.h(qubits[0]); + return SmallVector{q1Else}; + })[0]; + + // This is an `if` without memory effects - it can be removed. + auto q1S2 = builder.qcoIf( + c0, {q1S1}, + [&](ValueRange qubits) -> SmallVector { + auto q1Then = builder.x(qubits[0]); + return SmallVector{q1Then}; + }, + [&](ValueRange qubits) -> SmallVector { + auto q1Else = builder.h(qubits[0]); + return SmallVector{q1Else}; + })[0]; + builder.sink(q0S2); + builder.sink(q1S2); + auto module = builder.finalize(); - EXPECT_TRUE(areModulesEquivalentWithPermutations(module.get(), ref.get())); + QCOProgramBuilder reference(context.get()); + reference.initialize(); + auto r0S0 = reference.allocQubit(); + auto r1S0 = reference.allocQubit(); + auto r0S1 = reference.h(r0S0); + auto [r0S2, cr0] = reference.measure(r0S1); + + // This is an `if` with memory effects - it can't be removed. + auto r1S1 = reference.qcoIf( + cr0, {r1S0}, + [&](ValueRange qubits) -> SmallVector { + auto q1Then = reference.x(qubits[0]); + reference.gphase(0.5); + return SmallVector{q1Then}; + }, + [&](ValueRange qubits) -> SmallVector { + auto q1Else = reference.h(qubits[0]); + return SmallVector{q1Else}; + })[0]; + + reference.sink(r0S2); + reference.sink(r1S1); + auto refModule = reference.finalize(); + + ASSERT_TRUE(module); + EXPECT_TRUE(verify(*module).succeeded()); + EXPECT_TRUE(runQCOCleanupPipeline(module.get()).succeeded()); + EXPECT_TRUE(verify(*module).succeeded()); + + ASSERT_TRUE(refModule); + EXPECT_TRUE(verify(*refModule).succeeded()); + EXPECT_TRUE(runQCOCleanupPipeline(refModule.get()).succeeded()); + EXPECT_TRUE(verify(*refModule).succeeded()); + + EXPECT_TRUE( + areModulesEquivalentWithPermutations(module.get(), refModule.get())); } TEST_F(QCOTest, DirectIfBuilder) { From 2d65418e7a1e4b367f747902f5a5479571475873 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 2 Jun 2026 10:10:45 +0200 Subject: [PATCH 08/80] fix(mlir): :bug: minor bug and code style fixes --- mlir/include/mlir/Dialect/QCO/QCOUtils.h | 4 ++-- mlir/lib/Dialect/QCO/IR/QCOOps.cpp | 5 +++-- mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp | 5 +++++ mlir/lib/Support/IRVerification.cpp | 1 - 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/QCOUtils.h b/mlir/include/mlir/Dialect/QCO/QCOUtils.h index deda577eba..9c6af7a8f4 100644 --- a/mlir/include/mlir/Dialect/QCO/QCOUtils.h +++ b/mlir/include/mlir/Dialect/QCO/QCOUtils.h @@ -247,8 +247,8 @@ mergeTwoTargetOneParameterWithSwappedTargets(OpType op, */ inline LogicalResult checkAndRemoveDeadGate(Operation* op, PatternRewriter& rewriter) { - if (std::all_of(op->getUsers().begin(), op->getUsers().end(), - [](Operation* user) { return isa(user); })) { + if (llvm::all_of(op->getUsers(), + [](Operation* user) { return isa(user); })) { // If the operation is only used by sinks, we can safely remove it. if (auto u = dyn_cast(op)) { // We specifically have to replace the output *qubits* with the input diff --git a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp index dc302e3028..b1407ee0df 100644 --- a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp +++ b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include // The following headers are needed for some template instantiations. @@ -42,7 +43,7 @@ using namespace mlir::qco; namespace { /** - * @brief Remove dead measurements. + * @brief Remove dead gates. */ struct DeadGateElimination final : public OpInterfaceRewritePattern { @@ -54,7 +55,7 @@ struct DeadGateElimination final PatternRewriter& rewriter) const override { if (!isMemoryEffectFree(op)) { // This effectively ignores the GPhase operation and variants such as its - // inverse or `if` ops containing it, which should never be considered + // inverse or `ctrl` ops containing it, which should never be considered // dead. return failure(); } diff --git a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp index fc10e98157..6589fbbad7 100644 --- a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -244,6 +245,10 @@ struct DeadIfRemoval final : OpRewritePattern { LogicalResult matchAndRewrite(IfOp op, PatternRewriter& rewriter) const override { + if (!isMemoryEffectFree(op)) { + // This effectively ignores `IfOp`s with memory effects. + return failure(); + } return checkAndRemoveDeadGate(op, rewriter); } }; diff --git a/mlir/lib/Support/IRVerification.cpp b/mlir/lib/Support/IRVerification.cpp index eaac426f0a..8aa982e976 100644 --- a/mlir/lib/Support/IRVerification.cpp +++ b/mlir/lib/Support/IRVerification.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include From 278a54e356e4417f4b9446a689c8c74835c35d5f Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 2 Jun 2026 10:19:43 +0200 Subject: [PATCH 09/80] style(mlir): :rotating_light: fix linter issues on includes --- mlir/lib/Dialect/QCO/IR/QCOOps.cpp | 1 - mlir/lib/Support/IRVerification.cpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp index b1407ee0df..e49d00da5a 100644 --- a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp +++ b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include diff --git a/mlir/lib/Support/IRVerification.cpp b/mlir/lib/Support/IRVerification.cpp index 8aa982e976..eaac426f0a 100644 --- a/mlir/lib/Support/IRVerification.cpp +++ b/mlir/lib/Support/IRVerification.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include From 44eaf7e6bdb0274d2057a64d5b4c1690e35bbb6b Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 2 Jun 2026 10:57:00 +0200 Subject: [PATCH 10/80] fix: :pencil2: fix typo in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed0b4dfbcc..22616216d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel ### Added -- ✨ Add Dead Gate Elimination Pattern ([#1755]) ([**DRovara**]) +- ✨ Add Dead Gate Elimination Pattern ([#1755]) ([**@DRovara**]) - 🚸 Add [CMake presets] to provide a standardized and reproducible way to configure builds ([#1660]) ([**@denialhaag**]) - ✨ Add a `quantum-loop-unroll` pass for unrolling for-loop operations containing quantum operations ([#1718]) ([**@MatthiasReumann**]) - ✨ Add a `hadamard-lifting` pass for lifting Hadamard gates above Pauli gates ([#1605]) ([**@lirem101**], [**@burgholzer**]) From 8b3af4390da92f914007b5607e1325769a9444ed Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Tue, 2 Jun 2026 20:25:18 +0200 Subject: [PATCH 11/80] =?UTF-8?q?=F0=9F=8E=A8=20Optimize=20`checkAndRemove?= =?UTF-8?q?DeadGate`=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Burgholzer --- mlir/include/mlir/Dialect/QCO/QCOUtils.h | 56 +++++++++++++----------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/QCOUtils.h b/mlir/include/mlir/Dialect/QCO/QCOUtils.h index 9c6af7a8f4..e8f9cf9450 100644 --- a/mlir/include/mlir/Dialect/QCO/QCOUtils.h +++ b/mlir/include/mlir/Dialect/QCO/QCOUtils.h @@ -10,6 +10,7 @@ #pragma once +#include #include #include #include @@ -238,7 +239,7 @@ mergeTwoTargetOneParameterWithSwappedTargets(OpType op, } /** - * @brief Check if given quantum operation is unused (i.e., only used by + * @brief Check if a given quantum operation is unused (i.e., only used by * sinks) and remove it if so. * * @param op The operation to check. @@ -247,32 +248,35 @@ mergeTwoTargetOneParameterWithSwappedTargets(OpType op, */ inline LogicalResult checkAndRemoveDeadGate(Operation* op, PatternRewriter& rewriter) { - if (llvm::all_of(op->getUsers(), - [](Operation* user) { return isa(user); })) { - // If the operation is only used by sinks, we can safely remove it. - if (auto u = dyn_cast(op)) { - // We specifically have to replace the output *qubits* with the input - // *qubits* to ignore parameters. - rewriter.replaceOp(op, u.getInputQubits()); - return success(); - } else if (auto m = dyn_cast(op)) { - // We specifically have to replace the output *qubits* with the input - // *qubits* to ignore the classical outcome. - rewriter.replaceAllUsesWith(m.getQubitOut(), m.getQubitIn()); - rewriter.eraseOp(op); - return success(); - } else if (auto i = dyn_cast(op)) { - // We specifically have to replace the output *qubits* with the input - // *qubits* to ignore the condition. - rewriter.replaceOp(op, i.getQubits()); - return success(); - } else { - // This currently only includes the `Reset` operation. - rewriter.replaceOp(op, op->getOperands()); - return success(); - } + if (!llvm::all_of(op->getUsers(), + [](Operation* user) { return isa(user); })) { + return failure(); } - return failure(); + + // If the operation is only used by sinks, we can safely remove it. + return TypeSwitch(op) + .Case([&](auto u) { + // Replace output *qubits* with input *qubits* to ignore parameters. + rewriter.replaceOp(op, u.getInputQubits()); + return success(); + }) + .Case([&](auto m) { + // Replace output *qubits* with input *qubits* to ignore classical + // outcome. + rewriter.replaceAllUsesWith(m.getQubitOut(), m.getQubitIn()); + rewriter.eraseOp(op); + return success(); + }) + .Case([&](auto i) { + // Replace output *qubits* with input *qubits* to ignore the condition. + rewriter.replaceOp(op, i.getQubits()); + return success(); + }) + .Default([&](auto*) { + // This currently only includes the `Reset` operation. + rewriter.replaceOp(op, op->getOperands()); + return success(); + }); } } // namespace mlir::qco From 69981101dfdf43dd42d44cf78af942258aad9528 Mon Sep 17 00:00:00 2001 From: Lukas Burgholzer Date: Tue, 2 Jun 2026 20:54:19 +0200 Subject: [PATCH 12/80] =?UTF-8?q?=F0=9F=93=9D=20Add=20to=20generic=20chang?= =?UTF-8?q?elog=20entry=20for=20mqt-cc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Burgholzer --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22616216d5..40752e554d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,6 @@ This project adheres to [Semantic Versioning], with the exception that minor rel ### Added -- ✨ Add Dead Gate Elimination Pattern ([#1755]) ([**@DRovara**]) - 🚸 Add [CMake presets] to provide a standardized and reproducible way to configure builds ([#1660]) ([**@denialhaag**]) - ✨ Add a `quantum-loop-unroll` pass for unrolling for-loop operations containing quantum operations ([#1718]) ([**@MatthiasReumann**]) - ✨ Add a `hadamard-lifting` pass for lifting Hadamard gates above Pauli gates ([#1605]) ([**@lirem101**], [**@burgholzer**]) @@ -19,7 +18,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel - ✨ Add conversions between `jeff` and QCO ([#1479], [#1548], [#1565], [#1637], [#1676], [#1706]) ([**@denialhaag**], [**@burgholzer**]) - ✨ Add a `place-and-route` pass for mapping circuits to architectures with restricted topologies ([#1537], [#1547], [#1568], [#1581], [#1583], [#1588], [#1600], [#1664], [#1709], [#1716], [#1748]) ([**@MatthiasReumann**], [**@burgholzer**]) - ✨ 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], [#1567], [#1569], [#1570], [#1572], [#1573], [#1580], [#1602], [#1620], [#1623], [#1624], [#1626], [#1627], [#1635], [#1638], [#1673], [#1675], [#1700], [#1717], [#1728], [#1730], [#1749]) + ([#1264], [#1330], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1474], [#1475], [#1506], [#1510], [#1513], [#1521], [#1542], [#1548], [#1550], [#1554], [#1567], [#1569], [#1570], [#1572], [#1573], [#1580], [#1602], [#1620], [#1623], [#1624], [#1626], [#1627], [#1635], [#1638], [#1673], [#1675], [#1700], [#1717], [#1728], [#1730], [#1749], [#1755]) ([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**], [**@simon1hofmann**]) ### Changed From d56ccafec0648d9c590a1755ab468bb78acde1dd Mon Sep 17 00:00:00 2001 From: Damian Rovara <93778306+DRovara@users.noreply.github.com> Date: Wed, 3 Jun 2026 13:32:28 +0200 Subject: [PATCH 13/80] Update mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp Co-authored-by: Lukas Burgholzer Signed-off-by: Damian Rovara <93778306+DRovara@users.noreply.github.com> --- mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp index 462a28108d..595761a1a6 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp @@ -126,6 +126,5 @@ OpFoldResult ResetOp::fold(FoldAdaptor /*adaptor*/) { void ResetOp::getCanonicalizationPatterns(RewritePatternSet& results, MLIRContext* context) { - results.add(context); - results.add(context); +results.add(context); } From fb9fffb7a1a8f78083617b00a28eb6e9282fe7a1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 3 Jun 2026 11:33:33 +0000 Subject: [PATCH 14/80] =?UTF-8?q?=F0=9F=8E=A8=20pre-commit=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp index 595761a1a6..8185289762 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp @@ -126,5 +126,5 @@ OpFoldResult ResetOp::fold(FoldAdaptor /*adaptor*/) { void ResetOp::getCanonicalizationPatterns(RewritePatternSet& results, MLIRContext* context) { -results.add(context); + results.add(context); } From 44f295a42fcae57ae7b3c33955d809a2d6cc44d4 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Wed, 3 Jun 2026 13:49:51 +0200 Subject: [PATCH 15/80] test(mlir): :white_check_mark: improve test and add custom return types to QCOProgramBuilder --- .../Dialect/QCO/Builder/QCOProgramBuilder.h | 33 ++++++++++++++++++- .../Dialect/QCO/Builder/QCOProgramBuilder.cpp | 20 +++++++---- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 25 +++++++++----- 3 files changed, 62 insertions(+), 16 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h b/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h index 772ea1eba2..1745923964 100644 --- a/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h @@ -78,7 +78,8 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { //===--------------------------------------------------------------------===// /** - * @brief Initialize the builder and prepare for program construction + * @brief Initialize the builder and prepare for program construction, with + * a default return type of i64. * * @details * Creates a main function with an entry_point attribute. Must be called @@ -86,6 +87,17 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { */ void initialize(); + /** + * @brief Initialize the builder and prepare for program construction + * with specified return types. + * @param returnTypes The return types for the main function + * + * @details + * Creates a main function with an entry_point attribute. Must be called + * before adding operations. + */ + void initialize(TypeRange returnTypes); + //===--------------------------------------------------------------------===// // Constants //===--------------------------------------------------------------------===// @@ -1375,6 +1387,25 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { */ OwningOpRef finalize(); + /** + * @brief Finalize the program with a given exit code and return the + * constructed module + * @param returnValues Values representing the exit code to return + * + * @details + * Automatically deallocates all remaining valid qubits and tensors of qubits, + * adds a return statement with a given exit code, + * and transfers ownership of the module to the caller. The builder should not + * be used after calling this method. + * + * The return values must have the types indicated by the function signature + * of the main function, which returns an `i64` by default and can be + * modified by passing different arguments to the `initialize()` method. + * + * @return OwningOpRef containing the constructed quantum program module + */ + OwningOpRef finalize(ValueRange returnValues); + /** * @brief Convenience method for building quantum programs * @param context The MLIR context to use for building the program diff --git a/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp b/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp index a07c52aa0f..8627bd9291 100644 --- a/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp +++ b/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp @@ -52,12 +52,14 @@ QCOProgramBuilder::QCOProgramBuilder(MLIRContext* context) ctx->loadDialect(); } -void QCOProgramBuilder::initialize() { +void QCOProgramBuilder::initialize() { initialize({getI64Type()}); } + +void QCOProgramBuilder::initialize(TypeRange returnTypes) { // Set insertion point to the module body setInsertionPointToStart(mlir::cast(module).getBody()); // Create main function as entry point - auto funcType = getFunctionType({}, {getI64Type()}); + auto funcType = getFunctionType({}, returnTypes); auto mainFunc = func::FuncOp::create(*this, "main", funcType); // Add entry_point attribute to identify the main function @@ -1098,6 +1100,13 @@ void QCOProgramBuilder::ensureAllocationMode( OwningOpRef QCOProgramBuilder::finalize() { checkFinalized(); + auto exitCode = intConstant(0); + return finalize({exitCode}); +} + +OwningOpRef QCOProgramBuilder::finalize(ValueRange returnValues) { + checkFinalized(); + // Ensure that main function exists and insertion point is valid auto* insertionBlock = getInsertionBlock(); func::FuncOp mainFunc = nullptr; @@ -1146,11 +1155,8 @@ OwningOpRef QCOProgramBuilder::finalize() { validQubits.clear(); validTensors.clear(); - // Create constant 0 for successful exit code - auto exitCode = intConstant(0); - - // Add return statement with exit code 0 to the main function - func::ReturnOp::create(*this, exitCode); + // Add return statement with the given return values to the main function + func::ReturnOp::create(*this, returnValues); // Invalidate context to prevent use-after-finalize ctx = nullptr; diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 3af2feb196..747c88a422 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -116,23 +116,29 @@ TEST_F(QCOTest, BuilderRejectsMixedStaticAndDynamicQubitAllocationModes) { TEST_F(QCOTest, CheckDeadGateElimination) { QCOProgramBuilder builder(context.get()); - builder.initialize(); + builder.initialize({builder.getI1Type(), builder.getI1Type()}); auto q0S0 = builder.allocQubit(); auto q1S0 = builder.allocQubit(); - auto q0S1 = builder.h(q0S0); - auto [q0S2, q1S1] = builder.cx(q0S1, q1S0); + + auto [q0Measured, m0] = builder.measure(q0S0); + auto [q1Measured, m1] = builder.measure(q1S0); + + auto q0S1 = builder.h(q0Measured); + auto [q0S2, q1S1] = builder.cx(q0S1, q1Measured); auto [q1S2, c1] = builder.measure(q1S1); builder.sink(q0S2); builder.sink(q1S2); - auto module = builder.finalize(); + auto module = builder.finalize({m0, m1}); QCOProgramBuilder reference(context.get()); - reference.initialize(); + reference.initialize({reference.getI1Type(), reference.getI1Type()}); auto r0 = reference.allocQubit(); auto r1 = reference.allocQubit(); - reference.sink(r0); - reference.sink(r1); - auto refModule = reference.finalize(); + auto [r0Measured, mr0] = reference.measure(r0); + auto [r1Measured, mr1] = reference.measure(r1); + reference.sink(r0Measured); + reference.sink(r1Measured); + auto refModule = reference.finalize({mr0, mr1}); ASSERT_TRUE(module); EXPECT_TRUE(verify(*module).succeeded()); @@ -144,6 +150,9 @@ TEST_F(QCOTest, CheckDeadGateElimination) { EXPECT_TRUE(runQCOCleanupPipeline(refModule.get()).succeeded()); EXPECT_TRUE(verify(*refModule).succeeded()); + module->dump(); + refModule->dump(); + EXPECT_TRUE( areModulesEquivalentWithPermutations(module.get(), refModule.get())); } From b6cbf8e7508969bd5f62685c3b6064dcf1872fc9 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Wed, 3 Jun 2026 13:51:37 +0200 Subject: [PATCH 16/80] style(mlir): :recycle: remove unneeded dumps --- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 747c88a422..a1ef1d8e73 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -150,9 +150,6 @@ TEST_F(QCOTest, CheckDeadGateElimination) { EXPECT_TRUE(runQCOCleanupPipeline(refModule.get()).succeeded()); EXPECT_TRUE(verify(*refModule).succeeded()); - module->dump(); - refModule->dump(); - EXPECT_TRUE( areModulesEquivalentWithPermutations(module.get(), refModule.get())); } From dee0752928dec877c0d33033dbf2ad23c6928d8f Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Wed, 3 Jun 2026 14:01:06 +0200 Subject: [PATCH 17/80] style(mlir): :recycle: move `checkAndRemoveDeadGate` implementation out of helper function --- mlir/include/mlir/Dialect/QCO/QCOUtils.h | 41 ------------------- .../Dialect/QCO/IR/Operations/MeasureOp.cpp | 7 +++- .../lib/Dialect/QCO/IR/Operations/ResetOp.cpp | 7 +++- mlir/lib/Dialect/QCO/IR/QCOOps.cpp | 8 +++- mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp | 9 +++- 5 files changed, 27 insertions(+), 45 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/QCOUtils.h b/mlir/include/mlir/Dialect/QCO/QCOUtils.h index e8f9cf9450..7cdffc18e7 100644 --- a/mlir/include/mlir/Dialect/QCO/QCOUtils.h +++ b/mlir/include/mlir/Dialect/QCO/QCOUtils.h @@ -238,45 +238,4 @@ mergeTwoTargetOneParameterWithSwappedTargets(OpType op, return success(); } -/** - * @brief Check if a given quantum operation is unused (i.e., only used by - * sinks) and remove it if so. - * - * @param op The operation to check. - * @param rewriter The pattern rewriter. - * @return LogicalResult Success or failure of the removal. - */ -inline LogicalResult checkAndRemoveDeadGate(Operation* op, - PatternRewriter& rewriter) { - if (!llvm::all_of(op->getUsers(), - [](Operation* user) { return isa(user); })) { - return failure(); - } - - // If the operation is only used by sinks, we can safely remove it. - return TypeSwitch(op) - .Case([&](auto u) { - // Replace output *qubits* with input *qubits* to ignore parameters. - rewriter.replaceOp(op, u.getInputQubits()); - return success(); - }) - .Case([&](auto m) { - // Replace output *qubits* with input *qubits* to ignore classical - // outcome. - rewriter.replaceAllUsesWith(m.getQubitOut(), m.getQubitIn()); - rewriter.eraseOp(op); - return success(); - }) - .Case([&](auto i) { - // Replace output *qubits* with input *qubits* to ignore the condition. - rewriter.replaceOp(op, i.getQubits()); - return success(); - }) - .Default([&](auto*) { - // This currently only includes the `Reset` operation. - rewriter.replaceOp(op, op->getOperands()); - return success(); - }); -} - } // namespace mlir::qco diff --git a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp index 5d0462b6d7..83fe25582f 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp @@ -28,7 +28,12 @@ struct DeadMeasurementRemoval final : OpRewritePattern { LogicalResult matchAndRewrite(MeasureOp op, PatternRewriter& rewriter) const override { - return checkAndRemoveDeadGate(op, rewriter); + if (!llvm::all_of(op->getUsers(), + [](Operation* user) { return isa(user); })) { + return failure(); + } + rewriter.replaceAllUsesWith(op.getQubitOut(), op.getQubitIn()); + rewriter.eraseOp(op); } }; diff --git a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp index 8185289762..245cf415ba 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp @@ -110,7 +110,12 @@ struct DeadResetRemoval final : OpRewritePattern { LogicalResult matchAndRewrite(ResetOp op, PatternRewriter& rewriter) const override { - return checkAndRemoveDeadGate(op, rewriter); + if (!llvm::all_of(op->getUsers(), + [](Operation* user) { return isa(user); })) { + return failure(); + } + rewriter.replaceOp(op, op->getOperands()); + return success(); } }; diff --git a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp index e49d00da5a..f3ae237f77 100644 --- a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp +++ b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp @@ -58,7 +58,13 @@ struct DeadGateElimination final // dead. return failure(); } - return checkAndRemoveDeadGate(op.getOperation(), rewriter); + if (!llvm::all_of(op->getUsers(), + [](Operation* user) { return isa(user); })) { + return failure(); + } + + rewriter.replaceOp(op, op.getInputQubits()); + return success(); } }; } // namespace diff --git a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp index 6589fbbad7..558038dd2b 100644 --- a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp @@ -249,7 +249,14 @@ struct DeadIfRemoval final : OpRewritePattern { // This effectively ignores `IfOp`s with memory effects. return failure(); } - return checkAndRemoveDeadGate(op, rewriter); + + if (!llvm::all_of(op->getUsers(), + [](Operation* user) { return isa(user); })) { + return failure(); + } + + rewriter.replaceOp(op, op.getQubits()); + return success(); } }; } // namespace From 244f8bb2aeb57b82b3d971da57b16c1ecba5aa03 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Wed, 3 Jun 2026 14:23:05 +0200 Subject: [PATCH 18/80] style(mlir): :recycle: implement helper function to check if a gate is dead --- mlir/include/mlir/Dialect/QCO/QCOUtils.h | 17 +++++++++++++++++ .../lib/Dialect/QCO/IR/Operations/MeasureOp.cpp | 5 +++-- mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp | 4 ++-- mlir/lib/Dialect/QCO/IR/QCOOps.cpp | 9 +-------- mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp | 8 +------- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/QCOUtils.h b/mlir/include/mlir/Dialect/QCO/QCOUtils.h index 7cdffc18e7..1c920403fe 100644 --- a/mlir/include/mlir/Dialect/QCO/QCOUtils.h +++ b/mlir/include/mlir/Dialect/QCO/QCOUtils.h @@ -238,4 +238,21 @@ mergeTwoTargetOneParameterWithSwappedTargets(OpType op, return success(); } +/** + * @brief Check if given quantum operation is unused (i.e., only used by + * sinks and no memory effects). + * + * @param op The operation to check. + * @return bool True if the operation is unused, false otherwise. + */ +inline bool checkDeadGate(Operation* op) { + if (!isMemoryEffectFree(op)) { + // This ignores operations with and regions that have children with memory + // effects, which should never be considered dead. + return false; + } + return llvm::all_of(op->getUsers(), + [](Operation* user) { return isa(user); }); +} + } // namespace mlir::qco diff --git a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp index 83fe25582f..b2107f7836 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp @@ -28,12 +28,13 @@ struct DeadMeasurementRemoval final : OpRewritePattern { LogicalResult matchAndRewrite(MeasureOp op, PatternRewriter& rewriter) const override { - if (!llvm::all_of(op->getUsers(), - [](Operation* user) { return isa(user); })) { + if (!checkDeadGate(op)) { return failure(); } + rewriter.replaceAllUsesWith(op.getQubitOut(), op.getQubitIn()); rewriter.eraseOp(op); + return success(); } }; diff --git a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp index 245cf415ba..0886ba39a6 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp @@ -110,10 +110,10 @@ struct DeadResetRemoval final : OpRewritePattern { LogicalResult matchAndRewrite(ResetOp op, PatternRewriter& rewriter) const override { - if (!llvm::all_of(op->getUsers(), - [](Operation* user) { return isa(user); })) { + if (!checkDeadGate(op)) { return failure(); } + rewriter.replaceOp(op, op->getOperands()); return success(); } diff --git a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp index f3ae237f77..87edb6179f 100644 --- a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp +++ b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp @@ -52,14 +52,7 @@ struct DeadGateElimination final LogicalResult matchAndRewrite(UnitaryOpInterface op, PatternRewriter& rewriter) const override { - if (!isMemoryEffectFree(op)) { - // This effectively ignores the GPhase operation and variants such as its - // inverse or `ctrl` ops containing it, which should never be considered - // dead. - return failure(); - } - if (!llvm::all_of(op->getUsers(), - [](Operation* user) { return isa(user); })) { + if (!checkDeadGate(op)) { return failure(); } diff --git a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp index 558038dd2b..43e2154ce4 100644 --- a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp @@ -245,13 +245,7 @@ struct DeadIfRemoval final : OpRewritePattern { LogicalResult matchAndRewrite(IfOp op, PatternRewriter& rewriter) const override { - if (!isMemoryEffectFree(op)) { - // This effectively ignores `IfOp`s with memory effects. - return failure(); - } - - if (!llvm::all_of(op->getUsers(), - [](Operation* user) { return isa(user); })) { + if (!checkDeadGate(op)) { return failure(); } From 6eaac407e914afe440b02efdcbbb8008c7690749 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Wed, 3 Jun 2026 14:29:39 +0200 Subject: [PATCH 19/80] style(mlir): :rotating_light: fix includes --- mlir/include/mlir/Dialect/QCO/QCOUtils.h | 1 + mlir/lib/Dialect/QCO/IR/QCOOps.cpp | 1 - mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/QCOUtils.h b/mlir/include/mlir/Dialect/QCO/QCOUtils.h index 1c920403fe..4ade5351f7 100644 --- a/mlir/include/mlir/Dialect/QCO/QCOUtils.h +++ b/mlir/include/mlir/Dialect/QCO/QCOUtils.h @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace mlir::qco { diff --git a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp index 87edb6179f..a49a833929 100644 --- a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp +++ b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include // The following headers are needed for some template instantiations. diff --git a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp index 43e2154ce4..00e17eb0a1 100644 --- a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include From 07a3f4db3997526104a7d43df83073a54ea6123a Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Fri, 5 Jun 2026 10:45:37 +0200 Subject: [PATCH 20/80] docs(mlir): :memo: add comments to document `gphase` operation as memory effect --- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index a1ef1d8e73..e4c4262572 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -167,7 +167,7 @@ TEST_F(QCOTest, CheckIfOpDeadGateElimination) { c0, {q1S0}, [&](ValueRange qubits) -> SmallVector { auto q1Then = builder.x(qubits[0]); - builder.gphase(0.5); + builder.gphase(0.5); // This adds memory effects to the `IfOp`. return SmallVector{q1Then}; }, [&](ValueRange qubits) -> SmallVector { @@ -202,7 +202,7 @@ TEST_F(QCOTest, CheckIfOpDeadGateElimination) { cr0, {r1S0}, [&](ValueRange qubits) -> SmallVector { auto q1Then = reference.x(qubits[0]); - reference.gphase(0.5); + reference.gphase(0.5); // Due to memory effect, the `IfOp` stays. return SmallVector{q1Then}; }, [&](ValueRange qubits) -> SmallVector { From cab4155315bb1c79561324f0ce39921cfbd0a348 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Fri, 5 Jun 2026 13:44:22 +0200 Subject: [PATCH 21/80] test(mlir): :white_check_mark: update tests to now use return values --- .../Dialect/QCO/Builder/QCOProgramBuilder.h | 26 +- .../Dialect/QCO/Builder/QCOProgramBuilder.cpp | 26 +- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 114 +- .../Dialect/QCO/IR/test_qco_ir_matrix.cpp | 35 +- mlir/unittests/TestCaseUtils.h | 14 +- mlir/unittests/programs/qco_programs.cpp | 2671 ++++++++++++----- mlir/unittests/programs/qco_programs.h | 922 ++++-- 7 files changed, 2644 insertions(+), 1164 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h b/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h index 1745923964..380750ba8a 100644 --- a/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h @@ -98,6 +98,12 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { */ void initialize(TypeRange returnTypes); + /** + * @brief Modify the return types of the main function after initialization. + * @param returnTypes The new return types for the main function + */ + void retype(TypeRange returnTypes); + //===--------------------------------------------------------------------===// // Constants //===--------------------------------------------------------------------===// @@ -384,7 +390,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { * * @param qubit Input qubit (must be valid/unconsumed) * @param bit The classical bit to record the result - * @return Output qubit value + * @return Pair of (output_qubit, measurement_result) * * @par Example: * ```c++ @@ -394,7 +400,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { * %q0_out, %r0 = qco.measure("c", 3, 0) %q0 : !qco.qubit * ``` */ - Value measure(Value qubit, const Bit& bit); + std::pair measure(Value qubit, const Bit& bit); /** * @brief Reset a qubit to |0⟩ state @@ -1419,6 +1425,22 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { build(MLIRContext* context, const function_ref& buildFunc); + /** + * @brief Convenience method for building quantum programs with returns. + * @param context The MLIR context to use for building the program + * @param returnTypes The types of the values to be returned by the program. + * @param buildFunc A function that takes a reference to a QCOProgramBuilder + * and uses it to build the desired quantum program. The builder will be + * properly initialized before calling this function, and the resulting module + * will be finalized using the returned ValueRange after this function + * completes. + * @return The module containing the quantum program built by buildFunc. + */ + static OwningOpRef buildWithReturn( + MLIRContext* context, + const function_ref, SmallVector>( + QCOProgramBuilder&)>& buildFunc); + private: enum class AllocationMode : uint8_t { Unset, Static, Dynamic }; diff --git a/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp b/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp index 8627bd9291..1e39c1fabf 100644 --- a/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp +++ b/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp @@ -71,6 +71,16 @@ void QCOProgramBuilder::initialize(TypeRange returnTypes) { setInsertionPointToStart(&entryBlock); } +void QCOProgramBuilder::retype(TypeRange returnTypes) { + auto mainFunc = dyn_cast(module).lookupSymbol("main"); + if (!mainFunc) { + llvm::reportFatalUsageError("Main function not found for retyping"); + } + auto funcType = + getFunctionType(mainFunc.getFunctionType().getInputs(), returnTypes); + mainFunc.setType(funcType); +} + Value QCOProgramBuilder::intConstant(const int64_t value) { checkFinalized(); return arith::ConstantOp::create(*this, getI64IntegerAttr(value)).getResult(); @@ -397,7 +407,8 @@ std::pair QCOProgramBuilder::measure(Value qubit) { return {qubitOut, result}; } -Value QCOProgramBuilder::measure(Value qubit, const Bit& bit) { +std::pair QCOProgramBuilder::measure(Value qubit, + const Bit& bit) { checkFinalized(); auto nameAttr = getStringAttr(bit.registerName); @@ -410,7 +421,7 @@ Value QCOProgramBuilder::measure(Value qubit, const Bit& bit) { // Update tracking updateQubitTracking(qubit, qubitOut); - return qubitOut; + return {qubitOut, measureOp.getResult()}; } Value QCOProgramBuilder::reset(Value qubit) { @@ -1173,4 +1184,15 @@ OwningOpRef QCOProgramBuilder::build( return builder.finalize(); } +OwningOpRef QCOProgramBuilder::buildWithReturn( + MLIRContext* context, + const function_ref, SmallVector>( + QCOProgramBuilder&)>& buildFunc) { + QCOProgramBuilder builder(context); + builder.initialize(); + auto [result, resultTypes] = buildFunc(builder); + builder.retype(resultTypes); + return builder.finalize(result); +} + } // namespace mlir::qco diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index e4c4262572..13d3adc5e7 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -74,7 +74,8 @@ TEST_P(QCOTest, ProgramEquivalence) { const auto name = " (" + GetParam().name + ")"; mqt::test::DeferredPrinter printer; - auto program = QCOProgramBuilder::build(context.get(), programBuilder.fn); + auto program = + QCOProgramBuilder::buildWithReturn(context.get(), programBuilder.fn); ASSERT_TRUE(program); printer.record(program.get(), "Original QCO IR" + name); EXPECT_TRUE(verify(*program).succeeded()); @@ -83,7 +84,8 @@ TEST_P(QCOTest, ProgramEquivalence) { printer.record(program.get(), "Canonicalized QCO IR" + name); EXPECT_TRUE(verify(*program).succeeded()); - auto reference = QCOProgramBuilder::build(context.get(), referenceBuilder.fn); + auto reference = + QCOProgramBuilder::buildWithReturn(context.get(), referenceBuilder.fn); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QCO IR" + name); EXPECT_TRUE(verify(*reference).succeeded()); @@ -231,7 +233,7 @@ TEST_F(QCOTest, CheckIfOpDeadGateElimination) { TEST_F(QCOTest, DirectIfBuilder) { // Test If construction directly QCOProgramBuilder builder(context.get()); - builder.initialize(); + builder.initialize({builder.getI1Type()}); auto c0 = arith::ConstantIndexOp::create(builder, 0); auto c1 = arith::ConstantIndexOp::create(builder, 1); auto r0 = qtensor::AllocOp::create(builder, c1); @@ -244,18 +246,19 @@ TEST_F(QCOTest, DirectIfBuilder) { auto innerQubit = XOp::create(builder, qubits[0]); return SmallVector{innerQubit}; }); - auto r2 = qtensor::InsertOp::create(builder, ifOp.getResult(0), + auto finalMeasureOp = MeasureOp::create(builder, ifOp.getResult(0)); + auto r2 = qtensor::InsertOp::create(builder, finalMeasureOp.getQubitOut(), extractOp.getOutTensor(), c0); qtensor::DeallocOp::create(builder, r2); - auto directBuilder = builder.finalize(); + auto directBuilder = builder.finalize({finalMeasureOp.getResult()}); ASSERT_TRUE(directBuilder); EXPECT_TRUE(verify(*directBuilder).succeeded()); EXPECT_TRUE(runQCOCleanupPipeline(directBuilder.get()).succeeded()); EXPECT_TRUE(verify(*directBuilder).succeeded()); - auto refBuilder = - QCOProgramBuilder::build(context.get(), MQT_NAMED_BUILDER(simpleIf).fn); + auto refBuilder = QCOProgramBuilder::buildWithReturn( + context.get(), MQT_NAMED_BUILDER(simpleIf).fn); ASSERT_TRUE(refBuilder); EXPECT_TRUE(verify(*refBuilder).succeeded()); EXPECT_TRUE(runQCOCleanupPipeline(refBuilder.get()).succeeded()); @@ -269,10 +272,9 @@ TEST_F(QCOTest, IfOpParser) { // Test IfOp parser const char* mlirCode = R"( module { - func.func @main() -> i64 attributes {passthrough = ["entry_point"]} { + func.func @main() -> i1 attributes {passthrough = ["entry_point"]} { %c0 = arith.constant 0 : index %c1 = arith.constant 1 : index - %c0_i64 = arith.constant 0 : i64 %q0_0 = qco.alloc : !qco.qubit %t0 = qtensor.alloc(%c1) : tensor<1x!qco.qubit> %q0_1 = qco.h %q0_0 : !qco.qubit -> !qco.qubit @@ -286,9 +288,10 @@ TEST_F(QCOTest, IfOpParser) { } else args(%arg0 = %q0_2, %arg1 = %t0) { qco.yield %arg0, %arg1 : !qco.qubit, tensor<1x!qco.qubit> } - qco.sink %q0_4 : !qco.qubit + %q0_5, %c = qco.measure %q0_4 : !qco.qubit + qco.sink %q0_5 : !qco.qubit qtensor.dealloc %t3 : tensor<1x!qco.qubit> - return %c0_i64 : i64 + return %c : i1 } })"; @@ -299,7 +302,7 @@ TEST_F(QCOTest, IfOpParser) { EXPECT_TRUE(runQCOCleanupPipeline(parsedSourceModule.get()).succeeded()); EXPECT_TRUE(verify(*parsedSourceModule).succeeded()); - auto refBuilder = QCOProgramBuilder::build( + auto refBuilder = QCOProgramBuilder::buildWithReturn( context.get(), MQT_NAMED_BUILDER(ifOneQubitOneTensor).fn); ASSERT_TRUE(refBuilder); EXPECT_TRUE(verify(*refBuilder).succeeded()); @@ -413,7 +416,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(twoDcx)}, QCOTestCase{"TwoDCXSwappedTargets", MQT_NAMED_BUILDER(twoDcxSwappedTargets), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc2QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/EcrOp.cpp @@ -440,7 +443,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledEcr), MQT_NAMED_BUILDER(multipleControlledEcr)}, QCOTestCase{"TwoECR", MQT_NAMED_BUILDER(twoEcr), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc2QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/GphaseOp.cpp @@ -484,7 +487,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledH), MQT_NAMED_BUILDER(multipleControlledH)}, QCOTestCase{"TwoH", MQT_NAMED_BUILDER(twoH), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(allocQubit)})); /// @} /// \name QCO/Operations/StandardGates/IdOp.cpp @@ -493,24 +496,24 @@ INSTANTIATE_TEST_SUITE_P( QCOIDOpTest, QCOTest, testing::Values( QCOTestCase{"Identity", MQT_NAMED_BUILDER(identity), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(allocQubit)}, QCOTestCase{"SingleControlledIdentity", MQT_NAMED_BUILDER(singleControlledIdentity), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc2QubitRegister)}, QCOTestCase{"MultipleControlledIdentity", MQT_NAMED_BUILDER(multipleControlledIdentity), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc3QubitRegister)}, QCOTestCase{"NestedControlledIdentity", MQT_NAMED_BUILDER(nestedControlledIdentity), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc3QubitRegister)}, QCOTestCase{"TrivialControlledIdentity", MQT_NAMED_BUILDER(trivialControlledIdentity), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(allocQubit)}, QCOTestCase{"InverseIdentity", MQT_NAMED_BUILDER(inverseIdentity), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(allocQubit)}, QCOTestCase{"InverseMultipleControlledIdentity", MQT_NAMED_BUILDER(inverseMultipleControlledIdentity), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc3QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/IswapOp.cpp @@ -560,7 +563,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledP), MQT_NAMED_BUILDER(multipleControlledP)}, QCOTestCase{"TwoPOppositePhase", MQT_NAMED_BUILDER(twoPOppositePhase), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(allocQubit)})); /// @} /// \name QCO/Operations/StandardGates/ROp.cpp @@ -611,7 +614,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledRx), MQT_NAMED_BUILDER(multipleControlledRx)}, QCOTestCase{"TwoRXOppositePhase", MQT_NAMED_BUILDER(twoRxOppositePhase), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc1QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/RxxOp.cpp @@ -644,10 +647,10 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(rxx)}, QCOTestCase{"TwoRXXOppositePhase", MQT_NAMED_BUILDER(twoRxxOppositePhase), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc2QubitRegister)}, QCOTestCase{"TwoRXXOppositePhaseSwappedTargets", MQT_NAMED_BUILDER(twoRxxOppositePhaseSwappedTargets), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc2QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/RyOp.cpp @@ -672,7 +675,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledRy), MQT_NAMED_BUILDER(multipleControlledRy)}, QCOTestCase{"TwoRYOppositePhase", MQT_NAMED_BUILDER(twoRyOppositePhase), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc1QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/RyyOp.cpp @@ -705,10 +708,10 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(ryy)}, QCOTestCase{"TwoRYYOppositePhaseSwappedTargets", MQT_NAMED_BUILDER(twoRyyOppositePhaseSwappedTargets), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc2QubitRegister)}, QCOTestCase{"TwoRYYOppositePhase", MQT_NAMED_BUILDER(twoRyyOppositePhase), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc2QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/RzOp.cpp @@ -733,7 +736,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledRz), MQT_NAMED_BUILDER(multipleControlledRz)}, QCOTestCase{"TwoRZOppositePhase", MQT_NAMED_BUILDER(twoRzOppositePhase), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc1QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/RzxOp.cpp @@ -761,7 +764,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(multipleControlledRzx)}, QCOTestCase{"TwoRZXOppositePhase", MQT_NAMED_BUILDER(twoRzxOppositePhase), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc2QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/RzzOp.cpp @@ -794,10 +797,10 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(rzz)}, QCOTestCase{"TwoRZZOppositePhaseSwappedTargets", MQT_NAMED_BUILDER(twoRzzOppositePhaseSwappedTargets), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc2QubitRegister)}, QCOTestCase{"TwoRZZOppositePhase", MQT_NAMED_BUILDER(twoRzzOppositePhase), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc2QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/SOp.cpp @@ -821,7 +824,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledS), MQT_NAMED_BUILDER(multipleControlledSdg)}, QCOTestCase{"SThenSdg", MQT_NAMED_BUILDER(sThenSdg), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc1QubitRegister)}, QCOTestCase{"TwoS", MQT_NAMED_BUILDER(twoS), MQT_NAMED_BUILDER(z)})); /// @} @@ -849,7 +852,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledSdg), MQT_NAMED_BUILDER(multipleControlledS)}, QCOTestCase{"SdgThenS", MQT_NAMED_BUILDER(sdgThenS), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc1QubitRegister)}, QCOTestCase{"TwoSdg", MQT_NAMED_BUILDER(twoSdg), MQT_NAMED_BUILDER(z)})); /// @} @@ -878,10 +881,10 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledSwap), MQT_NAMED_BUILDER(multipleControlledSwap)}, QCOTestCase{"TwoSWAP", MQT_NAMED_BUILDER(twoSwap), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc2QubitRegister)}, QCOTestCase{"TwoSWAPSwappedTargets", MQT_NAMED_BUILDER(twoSwapSwappedTargets), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc2QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/SxOp.cpp @@ -906,7 +909,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledSx), MQT_NAMED_BUILDER(multipleControlledSxdg)}, QCOTestCase{"SXThenSXdg", MQT_NAMED_BUILDER(sxThenSxdg), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc1QubitRegister)}, QCOTestCase{"TwoSX", MQT_NAMED_BUILDER(twoSx), MQT_NAMED_BUILDER(x)})); /// @} @@ -934,7 +937,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledSxdg), MQT_NAMED_BUILDER(multipleControlledSx)}, QCOTestCase{"SXdgThenSX", MQT_NAMED_BUILDER(sxdgThenSx), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc1QubitRegister)}, QCOTestCase{"TwoSXdg", MQT_NAMED_BUILDER(twoSxdg), MQT_NAMED_BUILDER(x)})); /// @} @@ -960,7 +963,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledT), MQT_NAMED_BUILDER(multipleControlledTdg)}, QCOTestCase{"TThenTdg", MQT_NAMED_BUILDER(tThenTdg), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc1QubitRegister)}, QCOTestCase{"TwoT", MQT_NAMED_BUILDER(twoT), MQT_NAMED_BUILDER(s)})); /// @} @@ -988,7 +991,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledTdg), MQT_NAMED_BUILDER(multipleControlledT)}, QCOTestCase{"TdgThenS", MQT_NAMED_BUILDER(tdgThenT), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc1QubitRegister)}, QCOTestCase{"TwoTdg", MQT_NAMED_BUILDER(twoTdg), MQT_NAMED_BUILDER(sdg)})); /// @} @@ -1073,7 +1076,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledX), MQT_NAMED_BUILDER(multipleControlledX)}, QCOTestCase{"TwoX", MQT_NAMED_BUILDER(twoX), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc1QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/XxMinusYyOp.cpp @@ -1102,7 +1105,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(multipleControlledXxMinusYY)}, QCOTestCase{"TwoXXMinusYYOppositePhase", MQT_NAMED_BUILDER(twoXxMinusYYOppositePhase), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc2QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/XxPlusYyOp.cpp @@ -1131,7 +1134,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(multipleControlledXxPlusYY)}, QCOTestCase{"TwoXXPlusYYOppositePhase", MQT_NAMED_BUILDER(twoXxPlusYYOppositePhase), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc2QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/YOp.cpp @@ -1155,7 +1158,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledY), MQT_NAMED_BUILDER(multipleControlledY)}, QCOTestCase{"TwoY", MQT_NAMED_BUILDER(twoY), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc1QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/ZOp.cpp @@ -1179,7 +1182,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(inverseMultipleControlledZ), MQT_NAMED_BUILDER(multipleControlledZ)}, QCOTestCase{"TwoZ", MQT_NAMED_BUILDER(twoZ), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(alloc1QubitRegister)})); /// @} /// \name QCO/Operations/MeasureOp.cpp @@ -1208,13 +1211,13 @@ INSTANTIATE_TEST_SUITE_P( QCOResetOpTest, QCOTest, testing::Values(QCOTestCase{"ResetQubitWithoutOp", MQT_NAMED_BUILDER(resetQubitWithoutOp), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(allocQubit)}, QCOTestCase{"ResetMultipleQubitsWithoutOp", MQT_NAMED_BUILDER(resetMultipleQubitsWithoutOp), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(alloc2QubitRegister)}, QCOTestCase{"RepeatedResetWithoutOp", MQT_NAMED_BUILDER(repeatedResetWithoutOp), - MQT_NAMED_BUILDER(emptyQCO)}, + MQT_NAMED_BUILDER(allocQubit)}, QCOTestCase{"ResetQubitAfterSingleOp", MQT_NAMED_BUILDER(resetQubitAfterSingleOp), MQT_NAMED_BUILDER(resetQubitAfterSingleOp)}, @@ -1232,16 +1235,9 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCOQubitManagementTest, QCOTest, testing::Values( - QCOTestCase{"AllocQubit", MQT_NAMED_BUILDER(allocQubit), - MQT_NAMED_BUILDER(emptyQCO)}, - QCOTestCase{"AllocQubitRegister", MQT_NAMED_BUILDER(allocQubitRegister), - MQT_NAMED_BUILDER(emptyQCO)}, - QCOTestCase{"AllocMultipleQubitRegisters", - MQT_NAMED_BUILDER(allocMultipleQubitRegisters), - MQT_NAMED_BUILDER(emptyQCO)}, - QCOTestCase{"AllocLargeRegister", MQT_NAMED_BUILDER(allocLargeRegister), + QCOTestCase{"AllocQubit", MQT_NAMED_BUILDER(allocQubitNoMeasure), MQT_NAMED_BUILDER(emptyQCO)}, - QCOTestCase{"StaticQubits", MQT_NAMED_BUILDER(staticQubits), + QCOTestCase{"StaticQubits", MQT_NAMED_BUILDER(staticQubitsNoMeasure), MQT_NAMED_BUILDER(emptyQCO)}, QCOTestCase{"StaticQubitsWithOps", MQT_NAMED_BUILDER(staticQubitsWithOps), @@ -1259,5 +1255,5 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(staticQubitsWithInv), MQT_NAMED_BUILDER(staticQubitsWithInv)}, QCOTestCase{"AllocSinkPair", MQT_NAMED_BUILDER(allocSinkPair), - MQT_NAMED_BUILDER(emptyQCO)})); + MQT_NAMED_BUILDER(allocQubit)})); /// @} diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp index 24103da18c..af51838e16 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp @@ -59,7 +59,8 @@ class QCOMatrixTest : public testing::TestWithParam { /// \name QCO/Modifiers/CtrlOp.cpp /// @{ TEST_F(QCOMatrixTest, CXOpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), singleControlledX); + auto moduleOp = + QCOProgramBuilder::buildWithReturn(context.get(), singleControlledX); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -89,7 +90,8 @@ TEST_F(QCOMatrixTest, CXOpMatrix) { /// \name QCO/Modifiers/InvOp.cpp /// @{ TEST_F(QCOMatrixTest, InverseIswapOpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), inverseIswap); + auto moduleOp = + QCOProgramBuilder::buildWithReturn(context.get(), inverseIswap); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -163,7 +165,8 @@ TEST_F(QCOMatrixTest, ECROpMatrix) { /// \name QCO/Operations/StandardGates/GphaseOp.cpp /// @{ TEST_F(QCOMatrixTest, GPhaseOpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), globalPhase); + auto moduleOp = + QCOProgramBuilder::buildWithReturn(context.get(), globalPhase); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -244,7 +247,7 @@ TEST_F(QCOMatrixTest, iSWAPOpMatrix) { /// \name QCO/Operations/StandardGates/POp.cpp /// @{ TEST_F(QCOMatrixTest, POpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), p); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), p); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -267,7 +270,7 @@ TEST_F(QCOMatrixTest, POpMatrix) { /// \name QCO/Operations/StandardGates/ROp.cpp /// @{ TEST_F(QCOMatrixTest, ROpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), r); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), r); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -290,7 +293,7 @@ TEST_F(QCOMatrixTest, ROpMatrix) { /// \name QCO/Operations/StandardGates/RxOp.cpp /// @{ TEST_F(QCOMatrixTest, RXOpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), rx); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), rx); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -314,7 +317,7 @@ TEST_F(QCOMatrixTest, RXOpMatrix) { /// \name QCO/Operations/StandardGates/RxxOp.cpp /// @{ TEST_F(QCOMatrixTest, RXXOpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), rxx); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), rxx); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -341,7 +344,7 @@ TEST_F(QCOMatrixTest, RXXOpMatrix) { /// \name QCO/Operations/StandardGates/RyOp.cpp /// @{ TEST_F(QCOMatrixTest, RYOpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), ry); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), ry); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -365,7 +368,7 @@ TEST_F(QCOMatrixTest, RYOpMatrix) { /// \name QCO/Operations/StandardGates/RyyOp.cpp /// @{ TEST_F(QCOMatrixTest, RYYOpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), ryy); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), ryy); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -392,7 +395,7 @@ TEST_F(QCOMatrixTest, RYYOpMatrix) { /// \name QCO/Operations/StandardGates/RzOp.cpp /// @{ TEST_F(QCOMatrixTest, RZOpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), rz); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), rz); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -416,7 +419,7 @@ TEST_F(QCOMatrixTest, RZOpMatrix) { /// \name QCO/Operations/StandardGates/RzxOp.cpp /// @{ TEST_F(QCOMatrixTest, RZXOpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), rzx); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), rzx); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -443,7 +446,7 @@ TEST_F(QCOMatrixTest, RZXOpMatrix) { /// \name QCO/Operations/StandardGates/RzzOp.cpp /// @{ TEST_F(QCOMatrixTest, RZZOpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), rzz); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), rzz); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -600,7 +603,7 @@ TEST_F(QCOMatrixTest, TdgOpMatrix) { /// \name QCO/Operations/StandardGates/U2Op.cpp /// @{ TEST_F(QCOMatrixTest, U2OpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), u2); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), u2); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -624,7 +627,7 @@ TEST_F(QCOMatrixTest, U2OpMatrix) { /// \name QCO/Operations/StandardGates/UOp.cpp /// @{ TEST_F(QCOMatrixTest, UOpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), u); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), u); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -666,7 +669,7 @@ TEST_F(QCOMatrixTest, XOpMatrix) { /// \name QCO/Operations/StandardGates/XxMinusYyOp.cpp /// @{ TEST_F(QCOMatrixTest, XXMinusYYOpMatrix) { - auto moduleOp = QCOProgramBuilder::build(context.get(), xxMinusYY); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), xxMinusYY); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -694,7 +697,7 @@ TEST_F(QCOMatrixTest, XXMinusYYOpMatrix) { /// \name QCO/Operations/StandardGates/XxPlusYyOp.cpp /// @{ TEST_F(QCOMatrixTest, XXPlusYYOp) { - auto moduleOp = QCOProgramBuilder::build(context.get(), xxPlusYY); + auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), xxPlusYY); ASSERT_TRUE(moduleOp); // Get the operation from the module diff --git a/mlir/unittests/TestCaseUtils.h b/mlir/unittests/TestCaseUtils.h index 570c86c87f..16dbd46fdc 100644 --- a/mlir/unittests/TestCaseUtils.h +++ b/mlir/unittests/TestCaseUtils.h @@ -28,9 +28,13 @@ namespace mqt::test { template struct NamedBuilder { const char* name = nullptr; - void (*fn)(BuilderT&) = nullptr; + std::pair, mlir::SmallVector> ( + *fn)(BuilderT&) = nullptr; - constexpr NamedBuilder(const char* nameIn, void (*fnIn)(BuilderT&)) noexcept + constexpr NamedBuilder( + const char* nameIn, + std::pair, mlir::SmallVector> ( + *fnIn)(BuilderT&)) noexcept : name(nameIn), fn(fnIn) {} // NOLINTNEXTLINE(*-explicit-constructor) @@ -42,8 +46,10 @@ template struct NamedBuilder { }; template -[[nodiscard]] constexpr NamedBuilder -namedBuilder(const char* name, void (*fn)(BuilderT&)) noexcept { +[[nodiscard]] constexpr NamedBuilder namedBuilder( + const char* name, + std::pair, mlir::SmallVector> ( + *fn)(BuilderT&)) noexcept { return NamedBuilder{name, fn}; } diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 0ad96fbb10..6c5cb9f68e 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -14,201 +14,321 @@ #include #include +#include #include #include #include +static std::pair, mlir::SmallVector> +measureAndReturn(mlir::qco::QCOProgramBuilder& b, + mlir::SmallVector qubits) { + mlir::SmallVector bits; + mlir::SmallVector bitTypes; + auto i1Type = b.getI1Type(); + for (const auto& q : qubits) { + auto [q2, bit] = b.measure(q); + bits.push_back(bit); + bitTypes.push_back(i1Type); + } + return {bits, bitTypes}; +} + namespace mlir::qco { -void emptyQCO([[maybe_unused]] QCOProgramBuilder& builder) {} +std::pair, SmallVector> +emptyQCO([[maybe_unused]] QCOProgramBuilder& builder) { + return measureAndReturn(builder, {}); +} + +std::pair, SmallVector> +allocQubit(QCOProgramBuilder& b) { + auto q = b.allocQubit(); + return measureAndReturn(b, {q}); +} + +std::pair, SmallVector> +allocQubitNoMeasure(QCOProgramBuilder& b) { + auto q = b.allocQubit(); + return measureAndReturn(b, {}); +} + +std::pair, SmallVector> +alloc1QubitRegister(QCOProgramBuilder& b) { + auto reg = b.allocQubitRegister(1); + return measureAndReturn(b, {reg[0]}); +} -void allocQubit(QCOProgramBuilder& b) { b.allocQubit(); } +std::pair, SmallVector> +alloc2QubitRegister(QCOProgramBuilder& b) { + auto reg = b.allocQubitRegister(2); + return measureAndReturn(b, {reg[0], reg[1]}); +} -void allocQubitRegister(QCOProgramBuilder& b) { b.allocQubitRegister(2); } +std::pair, SmallVector> +alloc3QubitRegister(QCOProgramBuilder& b) { + auto reg = b.allocQubitRegister(3); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); +} -void allocMultipleQubitRegisters(QCOProgramBuilder& b) { - b.allocQubitRegister(2); - b.allocQubitRegister(3); +std::pair, SmallVector> +allocMultipleQubitRegisters(QCOProgramBuilder& b) { + auto r1 = b.allocQubitRegister(2); + auto r2 = b.allocQubitRegister(3); + return measureAndReturn(b, {r1[0], r1[1], r2[0], r2[1], r2[2]}); } -void allocLargeRegister(QCOProgramBuilder& b) { b.allocQubitRegister(100); } +std::pair, SmallVector> +allocLargeRegister(QCOProgramBuilder& b) { + auto r = b.allocQubitRegister(100); + return measureAndReturn(b, {r[0]}); +} -void staticQubits(QCOProgramBuilder& b) { - b.staticQubit(0); - b.staticQubit(1); +std::pair, SmallVector> +staticQubitsNoMeasure(QCOProgramBuilder& b) { + auto q1 = b.staticQubit(0); + auto q2 = b.staticQubit(1); + return measureAndReturn(b, {}); } -void staticQubitsWithOps(QCOProgramBuilder& b) { +std::pair, SmallVector> +staticQubits(QCOProgramBuilder& b) { + auto q1 = b.staticQubit(0); + auto q2 = b.staticQubit(1); + return measureAndReturn(b, {q1, q2}); +} + +std::pair, SmallVector> +staticQubitsWithOps(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); q0 = b.h(q0); q1 = b.h(q1); + return measureAndReturn(b, {q0, q1}); } -void staticQubitsWithParametricOps(QCOProgramBuilder& b) { +std::pair, SmallVector> +staticQubitsWithParametricOps(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); q0 = b.rx(std::numbers::pi / 4., q0); q1 = b.p(std::numbers::pi / 2., q1); + return measureAndReturn(b, {q0, q1}); } -void staticQubitsWithTwoTargetOps(QCOProgramBuilder& b) { +std::pair, SmallVector> +staticQubitsWithTwoTargetOps(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); std::tie(q0, q1) = b.rzz(0.123, q0, q1); + return measureAndReturn(b, {q0, q1}); } -void staticQubitsWithCtrl(QCOProgramBuilder& b) { +std::pair, SmallVector> +staticQubitsWithCtrl(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); std::tie(q0, q1) = b.cx(q0, q1); + return measureAndReturn(b, {q0, q1}); } -void staticQubitsWithInv(QCOProgramBuilder& b) { +std::pair, SmallVector> +staticQubitsWithInv(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); q0 = b.inv({q0}, [&](auto targets) -> SmallVector { return {b.t(targets[0])}; })[0]; + return measureAndReturn(b, {q0}); } -void allocSinkPair(QCOProgramBuilder& b) { +std::pair, SmallVector> +allocSinkPair(QCOProgramBuilder& b) { auto q = b.allocQubit(); - b.sink(q); + auto [q1, c] = b.measure(q); + b.sink(q1); + return {{c}, {b.getI1Type()}}; } -void mixedStaticThenDynamicQubit(QCOProgramBuilder& b) { - b.staticQubit(0); - b.allocQubit(); +std::pair, SmallVector> +mixedStaticThenDynamicQubit(QCOProgramBuilder& b) { + auto q0 = b.staticQubit(0); + auto q1 = b.allocQubit(); + return measureAndReturn(b, {q0, q1}); } -void mixedDynamicRegisterThenStaticQubit(QCOProgramBuilder& b) { +std::pair, SmallVector> +mixedDynamicRegisterThenStaticQubit(QCOProgramBuilder& b) { b.qtensorAlloc(2); - b.staticQubit(0); + auto q1 = b.staticQubit(0); + return measureAndReturn(b, {q1}); } -void singleMeasurementToSingleBit(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleMeasurementToSingleBit(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); - q[0] = b.measure(q[0], c[0]); + const auto [q1, bit] = b.measure(q[0], c[0]); + return {{bit}, {b.getI1Type()}}; } -void repeatedMeasurementToSameBit(QCOProgramBuilder& b) { +std::pair, SmallVector> +repeatedMeasurementToSameBit(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); - q[0] = b.measure(q[0], c[0]); - q[0] = b.measure(q[0], c[0]); - q[0] = b.measure(q[0], c[0]); + auto [q1, c1] = b.measure(q[0], c[0]); + auto [q2, c2] = b.measure(q1, c[0]); + auto [q3, c3] = b.measure(q2, c[0]); + return {{c1, c2, c3}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; } -void repeatedMeasurementToDifferentBits(QCOProgramBuilder& b) { +std::pair, SmallVector> +repeatedMeasurementToDifferentBits(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(3); - q[0] = b.measure(q[0], c[0]); - q[0] = b.measure(q[0], c[1]); - q[0] = b.measure(q[0], c[2]); + auto [q1, c1] = b.measure(q[0], c[0]); + auto [q2, c2] = b.measure(q1, c[1]); + auto [q3, c3] = b.measure(q2, c[2]); + return {{c1, c2, c3}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; } -void multipleClassicalRegistersAndMeasurements(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleClassicalRegistersAndMeasurements(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); const auto& c0 = b.allocClassicalBitRegister(1, "c0"); const auto& c1 = b.allocClassicalBitRegister(2, "c1"); - b.measure(q[0], c0[0]); - b.measure(q[1], c1[0]); - b.measure(q[2], c1[1]); + auto [q1, bit1] = b.measure(q[0], c0[0]); + auto [q2, bit2] = b.measure(q1, c1[0]); + auto [q3, bit3] = b.measure(q2, c1[1]); + return {{bit1, bit2, bit3}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; } -void measurementWithoutRegisters(QCOProgramBuilder& b) { +std::pair, SmallVector> +measurementWithoutRegisters(QCOProgramBuilder& b) { auto q = b.allocQubit(); - b.measure(q); + auto [q1, c] = b.measure(q); + return {{c}, {b.getI1Type()}}; } -void resetQubitWithoutOp(QCOProgramBuilder& b) { +std::pair, SmallVector> +resetQubitWithoutOp(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.reset(q); + return measureAndReturn(b, {q}); } -void resetMultipleQubitsWithoutOp(QCOProgramBuilder& b) { +std::pair, SmallVector> +resetMultipleQubitsWithoutOp(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); q[0] = b.reset(q[0]); q[1] = b.reset(q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void repeatedResetWithoutOp(QCOProgramBuilder& b) { +std::pair, SmallVector> +repeatedResetWithoutOp(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.reset(q); q = b.reset(q); q = b.reset(q); + return measureAndReturn(b, {q}); } -void resetQubitAfterSingleOp(QCOProgramBuilder& b) { +std::pair, SmallVector> +resetQubitAfterSingleOp(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); q[0] = b.reset(q[0]); + return measureAndReturn(b, {q[0]}); } -void resetMultipleQubitsAfterSingleOp(QCOProgramBuilder& b) { +std::pair, SmallVector> +resetMultipleQubitsAfterSingleOp(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); q[0] = b.h(q[0]); q[0] = b.reset(q[0]); q[1] = b.h(q[1]); q[1] = b.reset(q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void repeatedResetAfterSingleOp(QCOProgramBuilder& b) { +std::pair, SmallVector> +repeatedResetAfterSingleOp(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); q[0] = b.reset(q[0]); q[0] = b.reset(q[0]); q[0] = b.reset(q[0]); + return measureAndReturn(b, {q[0]}); } -void globalPhase(QCOProgramBuilder& b) { b.gphase(0.123); } +std::pair, SmallVector> +globalPhase(QCOProgramBuilder& b) { + b.gphase(0.123); + return measureAndReturn(b, {}); +} -void singleControlledGlobalPhase(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledGlobalPhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.cgphase(0.123, q[0]); + q[0] = b.cgphase(0.123, q[0]); + return measureAndReturn(b, {q[0]}); } -void multipleControlledGlobalPhase(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledGlobalPhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcgphase(0.123, {q[0], q[1], q[2]}); + auto qs = b.mcgphase(0.123, {q[0], q[1], q[2]}); + return measureAndReturn(b, {qs[0], qs[1], qs[2]}); } -void inverseGlobalPhase(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseGlobalPhase(QCOProgramBuilder& b) { b.inv({}, [&](ValueRange /*qubits*/) { b.gphase(-0.123); return SmallVector{}; }); + return measureAndReturn(b, {}); } -void inverseMultipleControlledGlobalPhase(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledGlobalPhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto qs = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { SmallVector controls{qubits[0], qubits[1], qubits[2]}; auto controlsOut = b.mcgphase(-0.123, controls); return SmallVector(controlsOut.begin(), controlsOut.end()); }); + return measureAndReturn(b, {qs[0], qs[1], qs[2]}); } -void identity(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(1); - b.id(q[0]); +std::pair, SmallVector> +identity(QCOProgramBuilder& b) { + auto q = b.allocQubit(); + q = b.id(q); + return measureAndReturn(b, {q}); } -void singleControlledIdentity(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledIdentity(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.cid(q[1], q[0]); + std::tie(q[1], q[0]) = b.cid(q[1], q[0]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledIdentity(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledIdentity(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcid({q[2], q[1]}, q[0]); + auto res = b.mcid({q[2], q[1]}, q[0]); + q[2] = res.first[0]; + q[1] = res.first[1]; + q[0] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledIdentity(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledIdentity(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.id(innerTargets[0])}; @@ -216,47 +336,71 @@ void nestedControlledIdentity(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledIdentity(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(1); - b.mcid({}, q[0]); +std::pair, SmallVector> +trivialControlledIdentity(QCOProgramBuilder& b) { + auto q = b.allocQubit(); + auto res = b.mcid({}, q); + q = res.second; + return measureAndReturn(b, {q}); } -void inverseIdentity(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(1); - b.inv({q[0]}, - [&](ValueRange qubits) { return SmallVector{b.id(qubits[0])}; }); +std::pair, SmallVector> +inverseIdentity(QCOProgramBuilder& b) { + auto q = b.allocQubit(); + auto res = b.inv( + {q}, [&](ValueRange qubits) { return SmallVector{b.id(qubits[0])}; }); + q = res[0]; + return measureAndReturn(b, {q}); } -void inverseMultipleControlledIdentity(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledIdentity(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcid({qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void x(QCOProgramBuilder& b) { +std::pair, SmallVector> x(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.x(q[0]); + q[0] = b.x(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledX(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.cx(q[0], q[1]); + std::tie(q[0], q[1]) = b.cx(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledX(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcx({q[0], q[1]}, q[2]); + auto res = b.mcx({q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledX(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledX(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.x(innerTargets[0])}; @@ -264,61 +408,94 @@ void nestedControlledX(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledX(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcx({}, q[0]); + auto res = b.mcx({}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void repeatedControlledX(QCOProgramBuilder& b) { +std::pair, SmallVector> +repeatedControlledX(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto control = b.h(q0); + std::vector targets; for (auto i = 0; i < 50; i++) { auto qubit = b.allocQubit(); - control = b.cx(control, qubit).first; + auto res = b.cx(control, qubit); + control = res.first; + targets.push_back(res.second); } + targets.push_back(control); + return measureAndReturn(b, + SmallVector(targets.begin(), targets.end())); } -void inverseX(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.x(qubits[0])}; }); + auto res = b.inv( + {q[0]}, [&](ValueRange qubits) { return SmallVector{b.x(qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledX(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcx({qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void twoX(QCOProgramBuilder& b) { +std::pair, SmallVector> twoX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.x(q[0]); q[0] = b.x(q[0]); + return measureAndReturn(b, {q[0]}); } -void y(QCOProgramBuilder& b) { +std::pair, SmallVector> y(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.y(q[0]); + q[0] = b.y(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledY(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.cy(q[0], q[1]); + std::tie(q[0], q[1]) = b.cy(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledY(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcy({q[0], q[1]}, q[2]); + auto res = b.mcy({q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledY(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledY(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.y(innerTargets[0])}; @@ -326,52 +503,78 @@ void nestedControlledY(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledY(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcy({}, q[0]); + auto res = b.mcy({}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseY(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.y(qubits[0])}; }); + auto res = b.inv( + {q[0]}, [&](ValueRange qubits) { return SmallVector{b.y(qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledY(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcy({qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void twoY(QCOProgramBuilder& b) { +std::pair, SmallVector> twoY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.y(q[0]); q[0] = b.y(q[0]); + return measureAndReturn(b, {q[0]}); } -void z(QCOProgramBuilder& b) { +std::pair, SmallVector> z(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.z(q[0]); + q[0] = b.z(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledZ(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.cz(q[0], q[1]); + std::tie(q[0], q[1]) = b.cz(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledZ(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcz({q[0], q[1]}, q[2]); + auto res = b.mcz({q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledZ(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledZ(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.z(innerTargets[0])}; @@ -379,52 +582,78 @@ void nestedControlledZ(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledZ(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcz({}, q[0]); + auto res = b.mcz({}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseZ(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.z(qubits[0])}; }); + auto res = b.inv( + {q[0]}, [&](ValueRange qubits) { return SmallVector{b.z(qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledZ(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcz({qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void twoZ(QCOProgramBuilder& b) { +std::pair, SmallVector> twoZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.z(q[0]); q[0] = b.z(q[0]); + return measureAndReturn(b, {q[0]}); } -void h(QCOProgramBuilder& b) { +std::pair, SmallVector> h(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.h(q[0]); + q[0] = b.h(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledH(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.ch(q[0], q[1]); + std::tie(q[0], q[1]) = b.ch(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledH(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mch({q[0], q[1]}, q[2]); + auto res = b.mch({q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledH(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledH(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.h(innerTargets[0])}; @@ -432,57 +661,87 @@ void nestedControlledH(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledH(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mch({}, q[0]); + auto res = b.mch({}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseH(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.h(qubits[0])}; }); + auto res = b.inv( + {q[0]}, [&](ValueRange qubits) { return SmallVector{b.h(qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledH(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mch({qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void twoH(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(1); - q[0] = b.h(q[0]); - q[0] = b.h(q[0]); +std::pair, SmallVector> twoH(QCOProgramBuilder& b) { + auto q = b.allocQubit(); + q = b.h(q); + q = b.h(q); + return measureAndReturn(b, {q}); } -void hWithoutRegister(QCOProgramBuilder& b) { +std::pair, SmallVector> +hWithoutRegister(QCOProgramBuilder& b) { auto q = b.allocQubit(); - b.h(q); + q = b.h(q); + return measureAndReturn(b, {q}); } -void s(QCOProgramBuilder& b) { +std::pair, SmallVector> s(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.s(q[0]); + q[0] = b.s(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledS(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.cs(q[0], q[1]); + auto res = b.cs(q[0], q[1]); + q[0] = res.first; + q[1] = res.second; + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledS(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcs({q[0], q[1]}, q[2]); + auto res = b.mcs({q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledS(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledS(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.s(innerTargets[0])}; @@ -490,58 +749,88 @@ void nestedControlledS(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledS(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcs({}, q[0]); + auto res = b.mcs({}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseS(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.s(qubits[0])}; }); + auto res = b.inv( + {q[0]}, [&](ValueRange qubits) { return SmallVector{b.s(qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledS(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcs({qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void sThenSdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +sThenSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.s(q[0]); q[0] = b.sdg(q[0]); + return measureAndReturn(b, {q[0]}); } -void twoS(QCOProgramBuilder& b) { +std::pair, SmallVector> twoS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.s(q[0]); q[0] = b.s(q[0]); + return measureAndReturn(b, {q[0]}); } -void sdg(QCOProgramBuilder& b) { +std::pair, SmallVector> sdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.sdg(q[0]); + q[0] = b.sdg(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledSdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.csdg(q[0], q[1]); + auto res = b.csdg(q[0], q[1]); + q[0] = res.first; + q[1] = res.second; + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledSdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcsdg({q[0], q[1]}, q[2]); + auto res = b.mcsdg({q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledSdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledSdg(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.sdg(innerTargets[0])}; @@ -549,59 +838,88 @@ void nestedControlledSdg(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledSdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcsdg({}, q[0]); + auto res = b.mcsdg({}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseSdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, - [&](ValueRange qubits) { return SmallVector{b.sdg(qubits[0])}; }); + auto res = b.inv( + {q[0]}, [&](ValueRange qubits) { return SmallVector{b.sdg(qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledSdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcsdg({qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void sdgThenS(QCOProgramBuilder& b) { +std::pair, SmallVector> +sdgThenS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sdg(q[0]); q[0] = b.s(q[0]); + return measureAndReturn(b, {q[0]}); } -void twoSdg(QCOProgramBuilder& b) { +std::pair, SmallVector> twoSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sdg(q[0]); q[0] = b.sdg(q[0]); + return measureAndReturn(b, {q[0]}); } -void t_(QCOProgramBuilder& b) { +std::pair, SmallVector> t_(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.t(q[0]); + q[0] = b.t(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledT(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.ct(q[0], q[1]); + auto res = b.ct(q[0], q[1]); + q[0] = res.first; + q[1] = res.second; + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledT(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mct({q[0], q[1]}, q[2]); + auto res = b.mct({q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledT(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledT(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.t(innerTargets[0])}; @@ -609,58 +927,88 @@ void nestedControlledT(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledT(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mct({}, q[0]); + auto res = b.mct({}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseT(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.t(qubits[0])}; }); + auto res = b.inv( + {q[0]}, [&](ValueRange qubits) { return SmallVector{b.t(qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledT(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mct({qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void tThenTdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +tThenTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.t(q[0]); q[0] = b.tdg(q[0]); + return measureAndReturn(b, {q[0]}); } -void twoT(QCOProgramBuilder& b) { +std::pair, SmallVector> twoT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.t(q[0]); q[0] = b.t(q[0]); + return measureAndReturn(b, {q[0]}); } -void tdg(QCOProgramBuilder& b) { +std::pair, SmallVector> tdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.tdg(q[0]); + q[0] = b.tdg(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledTdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.ctdg(q[0], q[1]); + auto res = b.ctdg(q[0], q[1]); + q[0] = res.first; + q[1] = res.second; + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledTdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mctdg({q[0], q[1]}, q[2]); + auto res = b.mctdg({q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledTdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledTdg(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.tdg(innerTargets[0])}; @@ -668,59 +1016,88 @@ void nestedControlledTdg(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledTdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mctdg({}, q[0]); + auto res = b.mctdg({}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseTdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, - [&](ValueRange qubits) { return SmallVector{b.tdg(qubits[0])}; }); + auto res = b.inv( + {q[0]}, [&](ValueRange qubits) { return SmallVector{b.tdg(qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledTdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mctdg({qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void tdgThenT(QCOProgramBuilder& b) { +std::pair, SmallVector> +tdgThenT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.tdg(q[0]); q[0] = b.t(q[0]); + return measureAndReturn(b, {q[0]}); } -void twoTdg(QCOProgramBuilder& b) { +std::pair, SmallVector> twoTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.tdg(q[0]); q[0] = b.tdg(q[0]); + return measureAndReturn(b, {q[0]}); } -void sx(QCOProgramBuilder& b) { +std::pair, SmallVector> sx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.sx(q[0]); + q[0] = b.sx(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledSx(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.csx(q[0], q[1]); + auto res = b.csx(q[0], q[1]); + q[0] = res.first; + q[1] = res.second; + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledSx(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcsx({q[0], q[1]}, q[2]); + auto res = b.mcsx({q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledSx(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledSx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.sx(innerTargets[0])}; @@ -728,59 +1105,88 @@ void nestedControlledSx(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledSx(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcsx({}, q[0]); + auto res = b.mcsx({}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseSx(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, - [&](ValueRange qubits) { return SmallVector{b.sx(qubits[0])}; }); + auto res = b.inv( + {q[0]}, [&](ValueRange qubits) { return SmallVector{b.sx(qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledSx(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcsx({qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void sxThenSxdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +sxThenSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sx(q[0]); q[0] = b.sxdg(q[0]); + return measureAndReturn(b, {q[0]}); } -void twoSx(QCOProgramBuilder& b) { +std::pair, SmallVector> twoSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sx(q[0]); q[0] = b.sx(q[0]); + return measureAndReturn(b, {q[0]}); } -void sxdg(QCOProgramBuilder& b) { +std::pair, SmallVector> sxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.sxdg(q[0]); + q[0] = b.sxdg(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledSxdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.csxdg(q[0], q[1]); + auto res = b.csxdg(q[0], q[1]); + q[0] = res.first; + q[1] = res.second; + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledSxdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcsxdg({q[0], q[1]}, q[2]); + auto res = b.mcsxdg({q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledSxdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledSxdg(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.sxdg(innerTargets[0])}; @@ -788,59 +1194,89 @@ void nestedControlledSxdg(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledSxdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcsxdg({}, q[0]); + auto res = b.mcsxdg({}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseSxdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, - [&](ValueRange qubits) { return SmallVector{b.sxdg(qubits[0])}; }); + auto res = b.inv({q[0]}, [&](ValueRange qubits) { + return SmallVector{b.sxdg(qubits[0])}; + }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledSxdg(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcsxdg({qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void sxdgThenSx(QCOProgramBuilder& b) { +std::pair, SmallVector> +sxdgThenSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sxdg(q[0]); q[0] = b.sx(q[0]); + return measureAndReturn(b, {q[0]}); } -void twoSxdg(QCOProgramBuilder& b) { +std::pair, SmallVector> twoSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sxdg(q[0]); q[0] = b.sxdg(q[0]); + return measureAndReturn(b, {q[0]}); } -void rx(QCOProgramBuilder& b) { +std::pair, SmallVector> rx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.rx(0.123, q[0]); + q[0] = b.rx(0.123, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledRx(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.crx(0.123, q[0], q[1]); + auto res = b.crx(0.123, q[0], q[1]); + q[0] = res.first; + q[1] = res.second; + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledRx(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcrx(0.123, {q[0], q[1]}, q[2]); + auto res = b.mcrx(0.123, {q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledRx(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.rx(0.123, innerTargets[0])}; @@ -848,59 +1284,87 @@ void nestedControlledRx(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledRx(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcrx(0.123, {}, q[0]); + auto res = b.mcrx(0.123, {}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseRx(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { + auto res = b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.rx(-0.123, qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledRx(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcrx(-0.123, {qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void twoRxOppositePhase(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoRxOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rx(0.123, q[0]); q[0] = b.rx(-0.123, q[0]); + return measureAndReturn(b, {q[0]}); } -void rxPiOver2(QCOProgramBuilder& b) { +std::pair, SmallVector> +rxPiOver2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.rx(std::numbers::pi / 2, q[0]); + q[0] = b.rx(std::numbers::pi / 2, q[0]); + return measureAndReturn(b, {q[0]}); } -void ry(QCOProgramBuilder& b) { +std::pair, SmallVector> ry(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.ry(0.456, q[0]); + q[0] = b.ry(0.456, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledRy(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.cry(0.456, q[0], q[1]); + std::tie(q[0], q[1]) = b.cry(0.456, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledRy(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcry(0.456, {q[0], q[1]}, q[2]); + auto res = b.mcry(0.456, {q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledRy(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRy(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.ry(0.456, innerTargets[0])}; @@ -908,58 +1372,87 @@ void nestedControlledRy(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledRy(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcry(0.456, {}, q[0]); + auto res = b.mcry(0.456, {}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseRy(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { + auto res = b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.ry(-0.456, qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledRy(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcry(-0.456, {qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void twoRyOppositePhase(QCOProgramBuilder& b) { + +std::pair, SmallVector> +twoRyOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.ry(0.456, q[0]); q[0] = b.ry(-0.456, q[0]); + return measureAndReturn(b, {q[0]}); } -void ryPiOver2(QCOProgramBuilder& b) { +std::pair, SmallVector> +ryPiOver2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.ry(std::numbers::pi / 2, q[0]); + q[0] = b.ry(std::numbers::pi / 2, q[0]); + return measureAndReturn(b, {q[0]}); } -void rz(QCOProgramBuilder& b) { +std::pair, SmallVector> rz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.rz(0.789, q[0]); + q[0] = b.rz(0.789, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledRz(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.crz(0.789, q[0], q[1]); + std::tie(q[0], q[1]) = b.crz(0.789, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledRz(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcrz(0.789, {q[0], q[1]}, q[2]); + auto res = b.mcrz(0.789, {q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledRz(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRz(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.rz(0.789, innerTargets[0])}; @@ -967,54 +1460,80 @@ void nestedControlledRz(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledRz(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcrz(0.789, {}, q[0]); + auto res = b.mcrz(0.789, {}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseRz(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { + auto res = b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.rz(-0.789, qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledRz(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcrz(-0.789, {qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void twoRzOppositePhase(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoRzOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rz(0.789, q[0]); q[0] = b.rz(-0.789, q[0]); + return measureAndReturn(b, {q[0]}); } -void p(QCOProgramBuilder& b) { +std::pair, SmallVector> p(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.p(0.123, q[0]); + q[0] = b.p(0.123, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledP(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.cp(0.123, q[0], q[1]); + std::tie(q[0], q[1]) = b.cp(0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledP(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcp(0.123, {q[0], q[1]}, q[2]); + auto res = b.mcp(0.123, {q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledP(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledP(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.p(0.123, innerTargets[0])}; @@ -1022,53 +1541,80 @@ void nestedControlledP(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledP(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcp(0.123, {}, q[0]); + auto res = b.mcp(0.123, {}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseP(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, - [&](ValueRange qubits) { return SmallVector{b.p(-0.123, qubits[0])}; }); + auto res = b.inv({q[0]}, [&](ValueRange qubits) { + return SmallVector{b.p(-0.123, qubits[0])}; + }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledP(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcp(-0.123, {qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void twoPOppositePhase(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(1); - q[0] = b.p(0.123, q[0]); - q[0] = b.p(-0.123, q[0]); +std::pair, SmallVector> +twoPOppositePhase(QCOProgramBuilder& b) { + auto q = b.allocQubit(); + q = b.p(0.123, q); + q = b.p(-0.123, q); + return measureAndReturn(b, {q}); } -void r(QCOProgramBuilder& b) { +std::pair, SmallVector> r(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.r(0.123, 0.456, q[0]); + q[0] = b.r(0.123, 0.456, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledR(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.cr(0.123, 0.456, q[0], q[1]); + std::tie(q[0], q[1]) = b.cr(0.123, 0.456, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledR(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcr(0.123, 0.456, {q[0], q[1]}, q[2]); + auto res = b.mcr(0.123, 0.456, {q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledR(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledR(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.r(0.123, 0.456, innerTargets[0])}; @@ -1076,58 +1622,86 @@ void nestedControlledR(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledR(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcr(0.123, 0.456, {}, q[0]); + auto res = b.mcr(0.123, 0.456, {}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseR(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { + auto res = b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.r(-0.123, 0.456, qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledR(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcr(-0.123, 0.456, {qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void canonicalizeRToRx(QCOProgramBuilder& b) { +std::pair, SmallVector> +canonicalizeRToRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.r(0.123, 0., q[0]); + return measureAndReturn(b, {q[0]}); } -void canonicalizeRToRy(QCOProgramBuilder& b) { +std::pair, SmallVector> +canonicalizeRToRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.r(0.456, std::numbers::pi / 2, q[0]); + return measureAndReturn(b, {q[0]}); } -void u2(QCOProgramBuilder& b) { +std::pair, SmallVector> u2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.u2(0.234, 0.567, q[0]); + q[0] = b.u2(0.234, 0.567, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledU2(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledU2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.cu2(0.234, 0.567, q[0], q[1]); + std::tie(q[0], q[1]) = b.cu2(0.234, 0.567, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledU2(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledU2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcu2(0.234, 0.567, {q[0], q[1]}, q[2]); + auto res = b.mcu2(0.234, 0.567, {q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledU2(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledU2(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.u2(0.234, 0.567, innerTargets[0])}; @@ -1135,63 +1709,95 @@ void nestedControlledU2(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledU2(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledU2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcu2(0.234, 0.567, {}, q[0]); + auto res = b.mcu2(0.234, 0.567, {}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseU2(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseU2(QCOProgramBuilder& b) { constexpr double pi = std::numbers::pi; auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { + auto res = b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.u2(-0.567 + pi, -0.234 - pi, qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledU2(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledU2(QCOProgramBuilder& b) { constexpr double pi = std::numbers::pi; auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcu2(-0.567 + pi, -0.234 - pi, {qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void canonicalizeU2ToH(QCOProgramBuilder& b) { + +std::pair, SmallVector> +canonicalizeU2ToH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.u2(0., std::numbers::pi, q[0]); + q[0] = b.u2(0., std::numbers::pi, q[0]); + return measureAndReturn(b, {q[0]}); } -void canonicalizeU2ToRx(QCOProgramBuilder& b) { +std::pair, SmallVector> +canonicalizeU2ToRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.u2(-std::numbers::pi / 2, std::numbers::pi / 2, q[0]); + q[0] = b.u2(-std::numbers::pi / 2, std::numbers::pi / 2, q[0]); + return measureAndReturn(b, {q[0]}); } -void canonicalizeU2ToRy(QCOProgramBuilder& b) { + +std::pair, SmallVector> +canonicalizeU2ToRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.u2(0., 0., q[0]); + q[0] = b.u2(0., 0., q[0]); + return measureAndReturn(b, {q[0]}); } -void u(QCOProgramBuilder& b) { +std::pair, SmallVector> u(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.u(0.1, 0.2, 0.3, q[0]); + q[0] = b.u(0.1, 0.2, 0.3, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledU(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.cu(0.1, 0.2, 0.3, q[0], q[1]); + std::tie(q[0], q[1]) = b.cu(0.1, 0.2, 0.3, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledU(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcu(0.1, 0.2, 0.3, {q[0], q[1]}, q[2]); + auto res = b.mcu(0.1, 0.2, 0.3, {q[0], q[1]}, q[2]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledU(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledU(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { + auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1]}, [&](ValueRange innerTargets) { return SmallVector{b.u(0.1, 0.2, 0.3, innerTargets[0])}; @@ -1199,746 +1805,1184 @@ void nestedControlledU(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledU(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.mcu(0.1, 0.2, 0.3, {}, q[0]); + auto res = b.mcu(0.1, 0.2, 0.3, {}, q[0]); + q[0] = res.second; + return measureAndReturn(b, {q[0]}); } -void inverseU(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { + auto res = b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.u(-0.1, -0.3, -0.2, qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledU(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = b.mcu(-0.1, -0.3, -0.2, {qubits[0], qubits[1]}, qubits[2]); return llvm::to_vector( llvm::concat(controlsOut, ValueRange{targetOut})); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void canonicalizeUToP(QCOProgramBuilder& b) { +std::pair, SmallVector> +canonicalizeUToP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.u(0., 0., 0.123, q[0]); + q[0] = b.u(0., 0., 0.123, q[0]); + return measureAndReturn(b, {q[0]}); } -void canonicalizeUToRx(QCOProgramBuilder& b) { +std::pair, SmallVector> +canonicalizeUToRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.u(0.123, -std::numbers::pi / 2, std::numbers::pi / 2, q[0]); + q[0] = b.u(0.123, -std::numbers::pi / 2, std::numbers::pi / 2, q[0]); + return measureAndReturn(b, {q[0]}); } -void canonicalizeUToRy(QCOProgramBuilder& b) { +std::pair, SmallVector> +canonicalizeUToRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.u(0.456, 0., 0., q[0]); + q[0] = b.u(0.456, 0., 0., q[0]); + return measureAndReturn(b, {q[0]}); } -void canonicalizeUToU2(QCOProgramBuilder& b) { +std::pair, SmallVector> +canonicalizeUToU2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.u(std::numbers::pi / 2, 0.234, 0.567, q[0]); + q[0] = b.u(std::numbers::pi / 2, 0.234, 0.567, q[0]); + return measureAndReturn(b, {q[0]}); } -void swap(QCOProgramBuilder& b) { +std::pair, SmallVector> swap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.swap(q[0], q[1]); + std::tie(q[0], q[1]) = b.swap(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledSwap(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.cswap(q[0], q[1], q[2]); + auto res = b.cswap(q[0], q[1], q[2]); + q[0] = res.first; + q[1] = res.second.first; + q[2] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledSwap(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.mcswap({q[0], q[1]}, q[2], q[3]); + auto res = b.mcswap({q[0], q[1]}, q[2], q[3]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second.first; + q[3] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledSwap(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledSwap(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { - const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( - {targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.swap(innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; - }); - return llvm::to_vector( - llvm::concat(innerControlsOut, innerTargetsOut)); - }); + auto res = + b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { + const auto& [innerControlsOut, innerTargetsOut] = + b.ctrl({targets[0]}, {targets[1], targets[2]}, + [&](ValueRange innerTargets) { + auto res = b.swap(innerTargets[0], innerTargets[1]); + return SmallVector{res.first, res.second}; + }); + return llvm::to_vector( + llvm::concat(innerControlsOut, innerTargetsOut)); + }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + reg[3] = res.second[2]; + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledSwap(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.mcswap({}, q[0], q[1]); + auto res = b.mcswap({}, q[0], q[1]); + q[0] = res.second.first; + q[1] = res.second.second; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseSwap(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.swap(qubits[0], qubits[1]); return SmallVector{res.first, res.second}; }); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledSwap(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.mcswap({qubits[0], qubits[1]}, qubits[2], qubits[3]); SmallVector targets{targetsOut.first, targetsOut.second}; return llvm::to_vector(llvm::concat(controlsOut, targets)); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + q[3] = res[3]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void twoSwap(QCOProgramBuilder& b) { +std::pair, SmallVector> twoSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.swap(q[0], q[1]); std::tie(q[0], q[1]) = b.swap(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void twoSwapSwappedTargets(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoSwapSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.swap(q[0], q[1]); std::tie(q[1], q[0]) = b.swap(q[1], q[0]); + return measureAndReturn(b, {q[0], q[1]}); } -void iswap(QCOProgramBuilder& b) { +std::pair, SmallVector> iswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.iswap(q[0], q[1]); + std::tie(q[0], q[1]) = b.iswap(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledIswap(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.ciswap(q[0], q[1], q[2]); + auto res = b.ciswap(q[0], q[1], q[2]); + q[0] = res.first; + q[1] = res.second.first; + q[2] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledIswap(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.mciswap({q[0], q[1]}, q[2], q[3]); + auto res = b.mciswap({q[0], q[1]}, q[2], q[3]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second.first; + q[3] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledIswap(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledIswap(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { - const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( - {targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.iswap(innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; - }); - return llvm::to_vector( - llvm::concat(innerControlsOut, innerTargetsOut)); - }); + auto res = + b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { + const auto& [innerControlsOut, innerTargetsOut] = + b.ctrl({targets[0]}, {targets[1], targets[2]}, + [&](ValueRange innerTargets) { + auto res = b.iswap(innerTargets[0], innerTargets[1]); + return SmallVector{res.first, res.second}; + }); + return llvm::to_vector( + llvm::concat(innerControlsOut, innerTargetsOut)); + }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + reg[3] = res.second[2]; + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledIswap(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.mciswap({}, q[0], q[1]); + auto res = b.mciswap({}, q[0], q[1]); + q[0] = res.second.first; + q[1] = res.second.second; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseIswap(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.iswap(qubits[0], qubits[1]); return SmallVector{res.first, res.second}; }); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledIswap(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.mciswap({qubits[0], qubits[1]}, qubits[2], qubits[3]); SmallVector targets{targetsOut.first, targetsOut.second}; return llvm::to_vector(llvm::concat(controlsOut, targets)); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + q[3] = res[3]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void dcx(QCOProgramBuilder& b) { +std::pair, SmallVector> dcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.dcx(q[0], q[1]); + std::tie(q[0], q[1]) = b.dcx(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledDcx(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.cdcx(q[0], q[1], q[2]); + auto res = b.cdcx(q[0], q[1], q[2]); + q[0] = res.first; + q[1] = res.second.first; + q[2] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledDcx(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.mcdcx({q[0], q[1]}, q[2], q[3]); + auto res = b.mcdcx({q[0], q[1]}, q[2], q[3]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second.first; + q[3] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledDcx(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledDcx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { - const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( - {targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.dcx(innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; - }); - return llvm::to_vector( - llvm::concat(innerControlsOut, innerTargetsOut)); - }); + auto res = + b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { + const auto& [innerControlsOut, innerTargetsOut] = + b.ctrl({targets[0]}, {targets[1], targets[2]}, + [&](ValueRange innerTargets) { + auto res = b.dcx(innerTargets[0], innerTargets[1]); + return SmallVector{res.first, res.second}; + }); + return llvm::to_vector( + llvm::concat(innerControlsOut, innerTargetsOut)); + }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + reg[3] = res.second[2]; + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledDcx(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.mcdcx({}, q[0], q[1]); + auto res = b.mcdcx({}, q[0], q[1]); + q[0] = res.second.first; + q[1] = res.second.second; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseDcx(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[1], q[0]}, [&](ValueRange qubits) { + auto res = b.inv({q[1], q[0]}, [&](ValueRange qubits) { auto res = b.dcx(qubits[0], qubits[1]); return SmallVector{res.first, res.second}; }); + q[1] = res[0]; + q[0] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledDcx(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.inv({q[0], q[1], q[3], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[3], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.mcdcx({qubits[0], qubits[1]}, qubits[2], qubits[3]); SmallVector targets{targetsOut.first, targetsOut.second}; return llvm::to_vector(llvm::concat(controlsOut, targets)); }); + q[0] = res[0]; + q[1] = res[1]; + q[3] = res[2]; + q[2] = res[3]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void twoDcx(QCOProgramBuilder& b) { +std::pair, SmallVector> twoDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.dcx(q[0], q[1]); std::tie(q[0], q[1]) = b.dcx(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void twoDcxSwappedTargets(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoDcxSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.dcx(q[0], q[1]); std::tie(q[1], q[0]) = b.dcx(q[1], q[0]); + return measureAndReturn(b, {q[0], q[1]}); } -void ecr(QCOProgramBuilder& b) { +std::pair, SmallVector> ecr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.ecr(q[0], q[1]); + std::tie(q[0], q[1]) = b.ecr(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledEcr(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.cecr(q[0], q[1], q[2]); + auto res = b.cecr(q[0], q[1], q[2]); + q[0] = res.first; + q[1] = res.second.first; + q[2] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledEcr(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.mcecr({q[0], q[1]}, q[2], q[3]); + auto res = b.mcecr({q[0], q[1]}, q[2], q[3]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second.first; + q[3] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledEcr(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledEcr(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { - const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( - {targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.ecr(innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; - }); - return llvm::to_vector( - llvm::concat(innerControlsOut, innerTargetsOut)); - }); + auto res = + b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { + const auto& [innerControlsOut, innerTargetsOut] = + b.ctrl({targets[0]}, {targets[1], targets[2]}, + [&](ValueRange innerTargets) { + auto res = b.ecr(innerTargets[0], innerTargets[1]); + return SmallVector{res.first, res.second}; + }); + return llvm::to_vector( + llvm::concat(innerControlsOut, innerTargetsOut)); + }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + reg[3] = res.second[2]; + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledEcr(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.mcecr({}, q[0], q[1]); + auto res = b.mcecr({}, q[0], q[1]); + q[0] = res.second.first; + q[1] = res.second.second; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseEcr(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.ecr(qubits[0], qubits[1]); return SmallVector{res.first, res.second}; }); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledEcr(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.mcecr({qubits[0], qubits[1]}, qubits[2], qubits[3]); SmallVector targets{targetsOut.first, targetsOut.second}; return llvm::to_vector(llvm::concat(controlsOut, targets)); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + q[3] = res[3]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void twoEcr(QCOProgramBuilder& b) { +std::pair, SmallVector> twoEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.ecr(q[0], q[1]); std::tie(q[0], q[1]) = b.ecr(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void rxx(QCOProgramBuilder& b) { +std::pair, SmallVector> rxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.rxx(0.123, q[0], q[1]); + std::tie(q[0], q[1]) = b.rxx(0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledRxx(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.crxx(0.123, q[0], q[1], q[2]); + auto res = b.crxx(0.123, q[0], q[1], q[2]); + q[0] = res.first; + q[1] = res.second.first; + q[2] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledRxx(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); + auto res = b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second.first; + q[3] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledRxx(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRxx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { - const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( - {targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.rxx(0.123, innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; - }); - return llvm::to_vector( - llvm::concat(innerControlsOut, innerTargetsOut)); - }); + auto res = + b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { + const auto& [innerControlsOut, innerTargetsOut] = + b.ctrl({targets[0]}, {targets[1], targets[2]}, + [&](ValueRange innerTargets) { + auto res = b.rxx(0.123, innerTargets[0], innerTargets[1]); + return SmallVector{res.first, res.second}; + }); + return llvm::to_vector( + llvm::concat(innerControlsOut, innerTargetsOut)); + }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + reg[3] = res.second[2]; + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledRxx(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.mcrxx(0.123, {}, q[0], q[1]); + auto res = b.mcrxx(0.123, {}, q[0], q[1]); + q[0] = res.second.first; + q[1] = res.second.second; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseRxx(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.rxx(-0.123, qubits[0], qubits[1]); return SmallVector{res.first, res.second}; }); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledRxx(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.mcrxx(-0.123, {qubits[0], qubits[1]}, qubits[2], qubits[3]); SmallVector targets{targetsOut.first, targetsOut.second}; return llvm::to_vector(llvm::concat(controlsOut, targets)); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + q[3] = res[3]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void tripleControlledRxx(QCOProgramBuilder& b) { +std::pair, SmallVector> +tripleControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(5); - b.mcrxx(0.123, {q[0], q[1], q[2]}, q[3], q[4]); + auto res = b.mcrxx(0.123, {q[0], q[1], q[2]}, q[3], q[4]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.first[2]; + q[3] = res.second.first; + q[4] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4]}); } -void fourControlledRxx(QCOProgramBuilder& b) { +std::pair, SmallVector> +fourControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(6); - b.mcrxx(0.123, {q[0], q[1], q[2], q[3]}, q[4], q[5]); + auto res = b.mcrxx(0.123, {q[0], q[1], q[2], q[3]}, q[4], q[5]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.first[2]; + q[3] = res.first[3]; + q[4] = res.second.first; + q[5] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4], q[5]}); } -void twoRxx(QCOProgramBuilder& b) { +std::pair, SmallVector> twoRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); // 0.045 + 0.078 = 0.123 std::tie(q[0], q[1]) = b.rxx(0.045, q[0], q[1]); std::tie(q[0], q[1]) = b.rxx(0.078, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void twoRxxSwappedTargets(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoRxxSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); // 0.045 + 0.078 = 0.123 std::tie(q[0], q[1]) = b.rxx(0.045, q[0], q[1]); std::tie(q[1], q[0]) = b.rxx(0.078, q[1], q[0]); + return measureAndReturn(b, {q[0], q[1]}); } -void twoRxxOppositePhase(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoRxxOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rxx(0.123, q[0], q[1]); std::tie(q[0], q[1]) = b.rxx(-0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void twoRxxOppositePhaseSwappedTargets(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoRxxOppositePhaseSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rxx(0.123, q[0], q[1]); std::tie(q[1], q[0]) = b.rxx(-0.123, q[1], q[0]); + return measureAndReturn(b, {q[0], q[1]}); } -void ryy(QCOProgramBuilder& b) { +std::pair, SmallVector> ryy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.ryy(0.123, q[0], q[1]); + std::tie(q[0], q[1]) = b.ryy(0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledRyy(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.cryy(0.123, q[0], q[1], q[2]); + auto res = b.cryy(0.123, q[0], q[1], q[2]); + q[0] = res.first; + q[1] = res.second.first; + q[2] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledRyy(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.mcryy(0.123, {q[0], q[1]}, q[2], q[3]); + auto res = b.mcryy(0.123, {q[0], q[1]}, q[2], q[3]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second.first; + q[3] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledRyy(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRyy(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { - const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( - {targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.ryy(0.123, innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; - }); - return llvm::to_vector( - llvm::concat(innerControlsOut, innerTargetsOut)); - }); + auto res = + b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { + const auto& [innerControlsOut, innerTargetsOut] = + b.ctrl({targets[0]}, {targets[1], targets[2]}, + [&](ValueRange innerTargets) { + auto res = b.ryy(0.123, innerTargets[0], innerTargets[1]); + return SmallVector{res.first, res.second}; + }); + return llvm::to_vector( + llvm::concat(innerControlsOut, innerTargetsOut)); + }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + reg[3] = res.second[2]; + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledRyy(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.mcryy(0.123, {}, q[0], q[1]); + auto res = b.mcryy(0.123, {}, q[0], q[1]); + q[0] = res.second.first; + q[1] = res.second.second; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseRyy(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.ryy(-0.123, qubits[0], qubits[1]); return SmallVector{res.first, res.second}; }); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledRyy(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.mcryy(-0.123, {qubits[0], qubits[1]}, qubits[2], qubits[3]); SmallVector targets{targetsOut.first, targetsOut.second}; return llvm::to_vector(llvm::concat(controlsOut, targets)); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + q[3] = res[3]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void twoRyy(QCOProgramBuilder& b) { +std::pair, SmallVector> twoRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); // 0.045 + 0.078 = 0.123 std::tie(q[0], q[1]) = b.ryy(0.045, q[0], q[1]); std::tie(q[0], q[1]) = b.ryy(0.078, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void twoRyyOppositePhaseSwappedTargets(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoRyyOppositePhaseSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.ryy(0.123, q[0], q[1]); std::tie(q[1], q[0]) = b.ryy(-0.123, q[1], q[0]); + return measureAndReturn(b, {q[0], q[1]}); } -void twoRyyOppositePhase(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoRyyOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.ryy(0.123, q[0], q[1]); std::tie(q[0], q[1]) = b.ryy(-0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void twoRyySwappedTargets(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoRyySwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); // 0.045 + 0.078 = 0.123 std::tie(q[0], q[1]) = b.ryy(0.045, q[0], q[1]); std::tie(q[1], q[0]) = b.ryy(0.078, q[1], q[0]); + return measureAndReturn(b, {q[0], q[1]}); } -void rzx(QCOProgramBuilder& b) { +std::pair, SmallVector> rzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.rzx(0.123, q[0], q[1]); + std::tie(q[0], q[1]) = b.rzx(0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledRzx(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.crzx(0.123, q[0], q[1], q[2]); + auto res = b.crzx(0.123, q[0], q[1], q[2]); + q[0] = res.first; + q[1] = res.second.first; + q[2] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledRzx(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.mcrzx(0.123, {q[0], q[1]}, q[2], q[3]); + auto res = b.mcrzx(0.123, {q[0], q[1]}, q[2], q[3]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second.first; + q[3] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledRzx(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRzx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { - const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( - {targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.rzx(0.123, innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; - }); - return llvm::to_vector( - llvm::concat(innerControlsOut, innerTargetsOut)); - }); + auto res = + b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { + const auto& [innerControlsOut, innerTargetsOut] = + b.ctrl({targets[0]}, {targets[1], targets[2]}, + [&](ValueRange innerTargets) { + auto res = b.rzx(0.123, innerTargets[0], innerTargets[1]); + return SmallVector{res.first, res.second}; + }); + return llvm::to_vector( + llvm::concat(innerControlsOut, innerTargetsOut)); + }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + reg[3] = res.second[2]; + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledRzx(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.mcrzx(0.123, {}, q[0], q[1]); + auto res = b.mcrzx(0.123, {}, q[0], q[1]); + q[0] = res.second.first; + q[1] = res.second.second; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseRzx(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.rzx(-0.123, qubits[0], qubits[1]); return SmallVector{res.first, res.second}; }); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledRzx(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.mcrzx(-0.123, {qubits[0], qubits[1]}, qubits[2], qubits[3]); SmallVector targets{targetsOut.first, targetsOut.second}; return llvm::to_vector(llvm::concat(controlsOut, targets)); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + q[3] = res[3]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void twoRzxOppositePhase(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoRzxOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rzx(0.123, q[0], q[1]); std::tie(q[0], q[1]) = b.rzx(-0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void rzz(QCOProgramBuilder& b) { +std::pair, SmallVector> rzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.rzz(0.123, q[0], q[1]); + std::tie(q[0], q[1]) = b.rzz(0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledRzz(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.crzz(0.123, q[0], q[1], q[2]); + auto res = b.crzz(0.123, q[0], q[1], q[2]); + q[0] = res.first; + q[1] = res.second.first; + q[2] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledRzz(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.mcrzz(0.123, {q[0], q[1]}, q[2], q[3]); + auto res = b.mcrzz(0.123, {q[0], q[1]}, q[2], q[3]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second.first; + q[3] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledRzz(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRzz(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { - const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( - {targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.rzz(0.123, innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; - }); - return llvm::to_vector( - llvm::concat(innerControlsOut, innerTargetsOut)); - }); + auto res = + b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { + const auto& [innerControlsOut, innerTargetsOut] = + b.ctrl({targets[0]}, {targets[1], targets[2]}, + [&](ValueRange innerTargets) { + auto res = b.rzz(0.123, innerTargets[0], innerTargets[1]); + return SmallVector{res.first, res.second}; + }); + return llvm::to_vector( + llvm::concat(innerControlsOut, innerTargetsOut)); + }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + reg[3] = res.second[2]; + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledRzz(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.mcrzz(0.123, {}, q[0], q[1]); + auto res = b.mcrzz(0.123, {}, q[0], q[1]); + q[0] = res.second.first; + q[1] = res.second.second; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseRzz(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.rzz(-0.123, qubits[0], qubits[1]); return SmallVector{res.first, res.second}; }); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledRzz(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.mcrzz(-0.123, {qubits[0], qubits[1]}, qubits[2], qubits[3]); SmallVector targets{targetsOut.first, targetsOut.second}; return llvm::to_vector(llvm::concat(controlsOut, targets)); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + q[3] = res[3]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void twoRzz(QCOProgramBuilder& b) { +std::pair, SmallVector> twoRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); // 0.045 + 0.078 = 0.123 std::tie(q[0], q[1]) = b.rzz(0.045, q[0], q[1]); std::tie(q[0], q[1]) = b.rzz(0.078, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void twoRzzSwappedTargets(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoRzzSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); // 0.045 + 0.078 = 0.123 std::tie(q[0], q[1]) = b.rzz(0.045, q[0], q[1]); std::tie(q[1], q[0]) = b.rzz(0.078, q[1], q[0]); + return measureAndReturn(b, {q[0], q[1]}); } -void twoRzzOppositePhase(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoRzzOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rzz(0.123, q[0], q[1]); std::tie(q[0], q[1]) = b.rzz(-0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void twoRzzOppositePhaseSwappedTargets(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoRzzOppositePhaseSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rzz(0.123, q[0], q[1]); std::tie(q[1], q[0]) = b.rzz(-0.123, q[1], q[0]); + return measureAndReturn(b, {q[0], q[1]}); } -void xxPlusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +xxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.xx_plus_yy(0.123, 0.456, q[0], q[1]); + std::tie(q[0], q[1]) = b.xx_plus_yy(0.123, 0.456, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledXxPlusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.cxx_plus_yy(0.123, 0.456, q[0], q[1], q[2]); + auto res = b.cxx_plus_yy(0.123, 0.456, q[0], q[1], q[2]); + q[0] = res.first; + q[1] = res.second.first; + q[2] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledXxPlusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.mcxx_plus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); + auto res = b.mcxx_plus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second.first; + q[3] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledXxPlusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledXxPlusYY(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { - const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( - {targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = - b.xx_plus_yy(0.123, 0.456, innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; - }); - return llvm::to_vector( - llvm::concat(innerControlsOut, innerTargetsOut)); - }); + auto res = + b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { + const auto& [innerControlsOut, innerTargetsOut] = + b.ctrl({targets[0]}, {targets[1], targets[2]}, + [&](ValueRange innerTargets) { + auto res = b.xx_plus_yy(0.123, 0.456, innerTargets[0], + innerTargets[1]); + return SmallVector{res.first, res.second}; + }); + return llvm::to_vector( + llvm::concat(innerControlsOut, innerTargetsOut)); + }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + reg[3] = res.second[2]; + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledXxPlusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.mcxx_plus_yy(0.123, 0.456, {}, q[0], q[1]); + auto res = b.mcxx_plus_yy(0.123, 0.456, {}, q[0], q[1]); + q[0] = res.second.first; + q[1] = res.second.second; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseXxPlusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.xx_plus_yy(-0.123, 0.456, qubits[0], qubits[1]); return SmallVector{res.first, res.second}; }); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledXxPlusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.mcxx_plus_yy( -0.123, 0.456, {qubits[0], qubits[1]}, qubits[2], qubits[3]); SmallVector targets{targetsOut.first, targetsOut.second}; return llvm::to_vector(llvm::concat(controlsOut, targets)); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + q[3] = res[3]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void twoXxPlusYYOppositePhase(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoXxPlusYYOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.xx_plus_yy(0.123, 0.456, q[0], q[1]); std::tie(q[0], q[1]) = b.xx_plus_yy(-0.123, 0.456, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void xxMinusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +xxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.xx_minus_yy(0.123, 0.456, q[0], q[1]); + std::tie(q[0], q[1]) = b.xx_minus_yy(0.123, 0.456, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledXxMinusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.cxx_minus_yy(0.123, 0.456, q[0], q[1], q[2]); + auto res = b.cxx_minus_yy(0.123, 0.456, q[0], q[1], q[2]); + q[0] = res.first; + q[1] = res.second.first; + q[2] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledXxMinusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.mcxx_minus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); + auto res = b.mcxx_minus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second.first; + q[3] = res.second.second; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledXxMinusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledXxMinusYY(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { - const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( - {targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = - b.xx_minus_yy(0.123, 0.456, innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; - }); - return llvm::to_vector( - llvm::concat(innerControlsOut, innerTargetsOut)); - }); + auto res = + b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { + const auto& [innerControlsOut, innerTargetsOut] = + b.ctrl({targets[0]}, {targets[1], targets[2]}, + [&](ValueRange innerTargets) { + auto res = b.xx_minus_yy(0.123, 0.456, innerTargets[0], + innerTargets[1]); + return SmallVector{res.first, res.second}; + }); + return llvm::to_vector( + llvm::concat(innerControlsOut, innerTargetsOut)); + }); + reg[0] = res.first[0]; + reg[1] = res.second[0]; + reg[2] = res.second[1]; + reg[3] = res.second[2]; + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledXxMinusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.mcxx_minus_yy(0.123, 0.456, {}, q[0], q[1]); + auto res = b.mcxx_minus_yy(0.123, 0.456, {}, q[0], q[1]); + q[0] = res.second.first; + q[1] = res.second.second; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseXxMinusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.xx_minus_yy(-0.123, 0.456, qubits[0], qubits[1]); return SmallVector{res.first, res.second}; }); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledXxMinusYY(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.mcxx_minus_yy( -0.123, 0.456, {qubits[0], qubits[1]}, qubits[2], qubits[3]); SmallVector targets{targetsOut.first, targetsOut.second}; return llvm::to_vector(llvm::concat(controlsOut, targets)); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + q[3] = res[3]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void twoXxMinusYYOppositePhase(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoXxMinusYYOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.xx_minus_yy(0.123, 0.456, q[0], q[1]); std::tie(q[0], q[1]) = b.xx_minus_yy(-0.123, 0.456, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void barrier(QCOProgramBuilder& b) { +std::pair, SmallVector> barrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.barrier(q[0]); + auto q1 = b.barrier(q[0]); + return measureAndReturn(b, {q1}); } -void barrierTwoQubits(QCOProgramBuilder& b) { +std::pair, SmallVector> +barrierTwoQubits(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.barrier({q[0], q[1]}); + auto res = b.barrier({q[0], q[1]}); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void barrierMultipleQubits(QCOProgramBuilder& b) { +std::pair, SmallVector> +barrierMultipleQubits(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.barrier({q[0], q[1], q[2]}); + auto res = b.barrier({q[0], q[1], q[2]}); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void singleControlledBarrier(QCOProgramBuilder& b) { +std::pair, SmallVector> +singleControlledBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.ctrl({q[1]}, {q[0]}, [&](ValueRange targets) { + auto res = b.ctrl({q[1]}, {q[0]}, [&](ValueRange targets) { return SmallVector{b.barrier(targets[0])}; }); + q[1] = res.first[0]; + q[0] = res.second[0]; + return measureAndReturn(b, {q[0]}); } -void inverseBarrier(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv({q[0]}, [&](ValueRange qubits) { + auto res = b.inv({q[0]}, [&](ValueRange qubits) { return SmallVector{b.barrier(qubits[0])}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void twoBarrier(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto b1 = b.barrier({q[0], q[1]}); q[0] = b1[0]; q[1] = b1[1]; - b.barrier({q[0], q[1]}); + auto b2 = b.barrier({q[0], q[1]}); + q[0] = b2[0]; + q[1] = b2[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void trivialCtrl(QCOProgramBuilder& b) { +std::pair, SmallVector> +trivialCtrl(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.ctrl({}, {q[0], q[1]}, [&](ValueRange targets) { + auto [_, q01] = b.ctrl({}, {q[0], q[1]}, [&](ValueRange targets) { auto [q0, q1] = b.rxx(0.123, targets[0], targets[1]); return SmallVector{q0, q1}; }); + return measureAndReturn(b, {q01[0], q01[1]}); } -void nestedCtrl(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedCtrl(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.ctrl({q[0]}, {q[1], q[2], q[3]}, [&](ValueRange targets) { + auto res = b.ctrl({q[0]}, {q[1], q[2], q[3]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( {targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { auto [q0, q1] = b.rxx(0.123, innerTargets[0], innerTargets[1]); @@ -1947,11 +2991,17 @@ void nestedCtrl(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + q[0] = res.first[0]; + q[1] = res.second[0]; + q[2] = res.second[1]; + q[3] = res.second[2]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void tripleNestedCtrl(QCOProgramBuilder& b) { +std::pair, SmallVector> +tripleNestedCtrl(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(5); - b.ctrl({q[0]}, {q[1], q[2], q[3], q[4]}, [&](ValueRange targets) { + auto res = b.ctrl({q[0]}, {q[1], q[2], q[3], q[4]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( {targets[0]}, {targets[1], targets[2], targets[3]}, [&](ValueRange innerTargets) { @@ -1968,25 +3018,42 @@ void tripleNestedCtrl(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); + q[0] = res.first[0]; + q[1] = res.second[0]; + q[2] = res.second[1]; + q[3] = res.second[2]; + q[4] = res.second[3]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4]}); } -void doubleNestedCtrlTwoQubits(QCOProgramBuilder& b) { +std::pair, SmallVector> +doubleNestedCtrlTwoQubits(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(6); - b.ctrl({q[0], q[1]}, {q[2], q[3], q[4], q[5]}, [&](ValueRange targets) { - const auto& [innerControlsOut, innerTargetsOut] = - b.ctrl({targets[0], targets[1]}, {targets[2], targets[3]}, - [&](ValueRange innerTargets) { - auto [q0, q1] = b.rxx(0.123, innerTargets[0], innerTargets[1]); - return SmallVector{q0, q1}; - }); - return llvm::to_vector( - llvm::concat(innerControlsOut, innerTargetsOut)); - }); + auto res = + b.ctrl({q[0], q[1]}, {q[2], q[3], q[4], q[5]}, [&](ValueRange targets) { + const auto& [innerControlsOut, innerTargetsOut] = + b.ctrl({targets[0], targets[1]}, {targets[2], targets[3]}, + [&](ValueRange innerTargets) { + auto [q0, q1] = + b.rxx(0.123, innerTargets[0], innerTargets[1]); + return SmallVector{q0, q1}; + }); + return llvm::to_vector( + llvm::concat(innerControlsOut, innerTargetsOut)); + }); + q[0] = res.first[0]; + q[1] = res.first[1]; + q[2] = res.second[0]; + q[3] = res.second[1]; + q[4] = res.second[2]; + q[5] = res.second[3]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4], q[5]}); } -void ctrlInvSandwich(QCOProgramBuilder& b) { +std::pair, SmallVector> +ctrlInvSandwich(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.ctrl({q[0]}, {q[1], q[2], q[3]}, [&](ValueRange targets) { + auto res = b.ctrl({q[0]}, {q[1], q[2], q[3]}, [&](ValueRange targets) { auto inner = b.inv( {targets[0], targets[1], targets[2]}, [&](ValueRange innerTargets) { auto [innerControlsOut, innerTargetsOut] = @@ -1999,24 +3066,34 @@ void ctrlInvSandwich(QCOProgramBuilder& b) { return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); - return SmallVector{inner}; + return llvm::to_vector(inner); }); + q[0] = res.first[0]; + q[1] = res.second[0]; + q[2] = res.second[1]; + q[3] = res.second[2]; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedInv(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedInv(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto inner = b.inv({qubits[0], qubits[1]}, [&](ValueRange innerQubits) { auto [q0, q1] = b.rxx(0.123, innerQubits[0], innerQubits[1]); return SmallVector{q0, q1}; }); - return SmallVector{inner}; + return llvm::to_vector(inner); }); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void tripleNestedInv(QCOProgramBuilder& b) { +std::pair, SmallVector> +tripleNestedInv(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto inner1 = b.inv({qubits[0], qubits[1]}, [&](ValueRange innerQubits) { auto inner2 = b.inv( {innerQubits[0], innerQubits[1]}, [&](ValueRange innerInnerQubits) { @@ -2024,15 +3101,19 @@ void tripleNestedInv(QCOProgramBuilder& b) { b.rxx(-0.123, innerInnerQubits[0], innerInnerQubits[1]); return SmallVector{q0, q1}; }); - return SmallVector{inner2}; + return llvm::to_vector(inner2); }); - return SmallVector{inner1}; + return llvm::to_vector(inner1); }); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void invCtrlSandwich(QCOProgramBuilder& b) { +std::pair, SmallVector> +invCtrlSandwich(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.ctrl({qubits[0]}, {qubits[1], qubits[2]}, [&](ValueRange targets) { auto inner = @@ -2040,38 +3121,50 @@ void invCtrlSandwich(QCOProgramBuilder& b) { auto [q0, q1] = b.rxx(0.123, innerQubits[0], innerQubits[1]); return SmallVector{q0, q1}; }); - return SmallVector{inner}; + return llvm::to_vector(inner); }); return llvm::to_vector(llvm::concat(controlsOut, targetsOut)); }); + q[0] = res[0]; + q[1] = res[1]; + q[2] = res[2]; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void simpleIf(QCOProgramBuilder& b) { +std::pair, SmallVector> +simpleIf(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto q0 = b.h(q[0]); auto [measuredQubit, measureResult] = b.measure(q0); - b.qcoIf(measureResult, measuredQubit, [&](ValueRange args) { + auto res = b.qcoIf(measureResult, measuredQubit, [&](ValueRange args) { auto innerQubit = b.x(args[0]); return SmallVector{innerQubit}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void ifTwoQubits(QCOProgramBuilder& b) { +std::pair, SmallVector> +ifTwoQubits(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto q0 = b.h(q[0]); auto [measuredQubit, measureResult] = b.measure(q0); - b.qcoIf(measureResult, {measuredQubit, q[1]}, [&](ValueRange args) { - auto innerQubit0 = b.x(args[0]); - auto innerQubit1 = b.x(args[1]); - return SmallVector{innerQubit0, innerQubit1}; - }); + auto res = + b.qcoIf(measureResult, {measuredQubit, q[1]}, [&](ValueRange args) { + auto innerQubit0 = b.x(args[0]); + auto innerQubit1 = b.x(args[1]); + return SmallVector{innerQubit0, innerQubit1}; + }); + q[0] = res[0]; + q[1] = res[1]; + return measureAndReturn(b, {q[0], q[1]}); } -void ifElse(QCOProgramBuilder& b) { +std::pair, SmallVector> ifElse(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto q0 = b.h(q[0]); auto [measuredQubit, measureResult] = b.measure(q0); - b.qcoIf( + auto res = b.qcoIf( measureResult, {measuredQubit}, [&](ValueRange args) { auto innerQubit = b.x(args[0]); @@ -2081,25 +3174,31 @@ void ifElse(QCOProgramBuilder& b) { auto innerQubit = b.z(args[0]); return SmallVector{innerQubit}; }); + q[0] = res[0]; + return measureAndReturn(b, {q[0]}); } -void ifOneQubitOneTensor(QCOProgramBuilder& b) { +std::pair, SmallVector> +ifOneQubitOneTensor(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto t0 = b.allocQubitRegister(1); auto q1 = b.h(q0); auto [measuredQubit, measureResult] = b.measure(q1); - b.qcoIf(measureResult, {measuredQubit, t0.value}, [&](ValueRange args) { - auto innerQubit0 = b.x(args[0]); - auto [t1, innerQubit1] = b.qtensorExtract(args[1], 0); - auto innerQubit2 = b.x(innerQubit1); - auto t2 = b.qtensorInsert(innerQubit2, t1, 0); - return SmallVector{innerQubit0, t2}; - }); + auto ifRes = + b.qcoIf(measureResult, {measuredQubit, t0.value}, [&](ValueRange args) { + auto innerQubit0 = b.x(args[0]); + auto [t1, innerQubit1] = b.qtensorExtract(args[1], 0); + auto innerQubit2 = b.x(innerQubit1); + auto t2 = b.qtensorInsert(innerQubit2, t1, 0); + return SmallVector{innerQubit0, t2}; + }); + return measureAndReturn(b, {ifRes[0]}); } -void constantTrueIf(QCOProgramBuilder& b) { +std::pair, SmallVector> +constantTrueIf(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.qcoIf( + auto ifRes = b.qcoIf( true, q.qubits, [&](ValueRange args) { auto innerQubit = b.x(args[0]); @@ -2109,11 +3208,13 @@ void constantTrueIf(QCOProgramBuilder& b) { auto innerQubit = b.z(args[0]); return SmallVector{innerQubit}; }); + return measureAndReturn(b, {ifRes[0]}); } -void constantFalseIf(QCOProgramBuilder& b) { +std::pair, SmallVector> +constantFalseIf(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.qcoIf( + auto ifRes = b.qcoIf( false, q.qubits, [&](ValueRange args) { auto innerQubit = b.x(args[0]); @@ -2123,13 +3224,15 @@ void constantFalseIf(QCOProgramBuilder& b) { auto innerQubit = b.z(args[0]); return SmallVector{innerQubit}; }); + return measureAndReturn(b, {ifRes[0]}); } -void nestedTrueIf(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedTrueIf(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto q0 = b.h(q[0]); auto [measuredQubit, measureResult] = b.measure(q0); - b.qcoIf(measureResult, measuredQubit, [&](ValueRange outerArgs) { + auto ifRes = b.qcoIf(measureResult, measuredQubit, [&](ValueRange outerArgs) { auto innerResult = b.qcoIf(measureResult, outerArgs, [&](ValueRange innerArgs) { auto innerQubit = b.x(innerArgs[0]); @@ -2137,13 +3240,15 @@ void nestedTrueIf(QCOProgramBuilder& b) { }); return llvm::to_vector(innerResult); }); + return measureAndReturn(b, {ifRes[0]}); } -void nestedFalseIf(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedFalseIf(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto q0 = b.h(q[0]); auto [measuredQubit, measureResult] = b.measure(q0); - b.qcoIf( + auto ifRes = b.qcoIf( measureResult, measuredQubit, [&](ValueRange args) { auto innerQubit = b.x(args[0]); @@ -2159,68 +3264,90 @@ void nestedFalseIf(QCOProgramBuilder& b) { }); return llvm::to_vector(innerResult); }); + return measureAndReturn(b, {ifRes[0]}); } -void qtensorAlloc(QCOProgramBuilder& b) { b.qtensorAlloc(3); } +std::pair, SmallVector> +qtensorAlloc(QCOProgramBuilder& b) { + auto qtensor = b.qtensorAlloc(3); + return measureAndReturn(b, {qtensor}); +} -void qtensorDealloc(QCOProgramBuilder& b) { +std::pair, SmallVector> +qtensorDealloc(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); b.qtensorDealloc(qtensor); + return measureAndReturn(b, {}); } -void qtensorFromElements(QCOProgramBuilder& b) { +std::pair, SmallVector> +qtensorFromElements(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.allocQubit(); auto q2 = b.allocQubit(); - b.qtensorFromElements({q0, q1, q2}); + auto t = b.qtensorFromElements({q0, q1, q2}); + return measureAndReturn(b, {t}); } -void qtensorExtract(QCOProgramBuilder& b) { +std::pair, SmallVector> +qtensorExtract(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); - b.qtensorExtract(qtensor, 0); + auto [t, q] = b.qtensorExtract(qtensor, 0); + return measureAndReturn(b, {t, q}); } -void qtensorInsert(QCOProgramBuilder& b) { +std::pair, SmallVector> +qtensorInsert(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); auto q1 = b.h(q0); - b.qtensorInsert(q1, extractOutTensor, 0); + auto insertOutTensor = b.qtensorInsert(q1, extractOutTensor, 0); + return measureAndReturn(b, {insertOutTensor}); } -void qtensorExtractInsertIndexMismatch(QCOProgramBuilder& b) { +std::pair, SmallVector> +qtensorExtractInsertIndexMismatch(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); - b.qtensorInsert(q0, extractOutTensor, 1); + auto insertOutTensor = b.qtensorInsert(q0, extractOutTensor, 1); + return measureAndReturn(b, {insertOutTensor}); } -void qtensorExtractInsertSameIndex(QCOProgramBuilder& b) { +std::pair, SmallVector> +qtensorExtractInsertSameIndex(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); - b.qtensorInsert(q0, extractOutTensor, 0); + auto insertOutTensor = b.qtensorInsert(q0, extractOutTensor, 0); + return measureAndReturn(b, {insertOutTensor}); } -void qtensorInsertExtractIndexMismatch(QCOProgramBuilder& b) { +std::pair, SmallVector> +qtensorInsertExtractIndexMismatch(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); auto q1 = b.h(q0); auto insertOutTensor = b.qtensorInsert(q1, extractOutTensor, 0); auto [extractOutTensor1, q2] = b.qtensorExtract(insertOutTensor, 1); - b.qtensorInsert(q2, extractOutTensor1, 0); + auto insertOutTensor1 = b.qtensorInsert(q2, extractOutTensor1, 0); + return measureAndReturn(b, {insertOutTensor1}); } -void qtensorInsertExtractSameIndex(QCOProgramBuilder& b) { +std::pair, SmallVector> +qtensorInsertExtractSameIndex(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); auto q1 = b.h(q0); auto insertOutTensor = b.qtensorInsert(q1, extractOutTensor, 0); auto [extractOutTensor1, q2] = b.qtensorExtract(insertOutTensor, 0); - b.qtensorInsert(q2, extractOutTensor1, 0); + auto insertOutTensor1 = b.qtensorInsert(q2, extractOutTensor1, 0); + return measureAndReturn(b, {insertOutTensor1}); } -void simpleWhileReset(QCOProgramBuilder& b) { +std::pair, SmallVector> +simpleWhileReset(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.h(q0); - b.scfWhile( + auto scfWhile = b.scfWhile( ValueRange{q1}, [&](ValueRange iterArgs) { auto [q2, measureResult] = b.measure(iterArgs[0]); @@ -2231,11 +3358,13 @@ void simpleWhileReset(QCOProgramBuilder& b) { auto q3 = b.h(iterArgs[0]); return SmallVector{q3}; }); + return measureAndReturn(b, {scfWhile[0]}); } -void simpleDoWhileReset(QCOProgramBuilder& b) { +std::pair, SmallVector> +simpleDoWhileReset(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); - b.scfWhile( + auto scfWhile = b.scfWhile( ValueRange{q0}, [&](ValueRange iterArgs) { auto q1 = b.h(iterArgs[0]); @@ -2244,35 +3373,43 @@ void simpleDoWhileReset(QCOProgramBuilder& b) { return SmallVector{q2}; }, [&](ValueRange iterArgs) { return llvm::to_vector(iterArgs); }); + return measureAndReturn(b, {scfWhile[0]}); } -void simpleForLoop(QCOProgramBuilder& b) { +std::pair, SmallVector> +simpleForLoop(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(2); - b.scfFor(0, 2, 1, {reg.value}, [&](Value iv, ValueRange iterArgs) { - auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); - auto q1 = b.h(q0); - auto insert = b.qtensorInsert(q1, t0, iv); - return SmallVector{insert}; - }); + auto scfFor = + b.scfFor(0, 2, 1, {reg.value}, [&](Value iv, ValueRange iterArgs) { + auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); + auto q1 = b.h(q0); + auto insert = b.qtensorInsert(q1, t0, iv); + return SmallVector{insert}; + }); + return measureAndReturn(b, {scfFor[0]}); }; -void nestedForLoopIfOp(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedForLoopIfOp(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto q0 = b.allocQubit(); - b.scfFor(0, 2, 1, {reg.value, q0}, [&](Value iv, ValueRange iterArgs) { - auto q1 = b.h(iterArgs[1]); - auto [q2, cond] = b.measure(q1); - auto ifOp = b.qcoIf(cond, iterArgs[0], [&](ValueRange args) { - auto [t0, q3] = b.qtensorExtract(args[0], iv); - auto q4 = b.h(q3); - auto insert = b.qtensorInsert(q4, t0, iv); - return SmallVector{insert}; - }); - return SmallVector{ifOp[0], q2}; - }); + auto scfFor = + b.scfFor(0, 2, 1, {reg.value, q0}, [&](Value iv, ValueRange iterArgs) { + auto q1 = b.h(iterArgs[1]); + auto [q2, cond] = b.measure(q1); + auto ifOp = b.qcoIf(cond, iterArgs[0], [&](ValueRange args) { + auto [t0, q3] = b.qtensorExtract(args[0], iv); + auto q4 = b.h(q3); + auto insert = b.qtensorInsert(q4, t0, iv); + return SmallVector{insert}; + }); + return SmallVector{ifOp[0], q2}; + }); + return measureAndReturn(b, {scfFor[0], scfFor[1]}); } -void nestedForLoopWhileOp(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedForLoopWhileOp(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto loopResult = b.scfFor(0, 2, 1, {reg.value}, [&](Value iv, ValueRange iterArgs) { @@ -2281,61 +3418,72 @@ void nestedForLoopWhileOp(QCOProgramBuilder& b) { auto insert = b.qtensorInsert(q1, t0, iv); return SmallVector{insert}; }); - b.scfFor(0, 2, 1, loopResult, [&](Value iv, ValueRange iterArgs) { - auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); - auto whileResult = b.scfWhile( - q0, - [&](ValueRange iterArgs) { - auto [q1, measureResult] = b.measure(iterArgs[0]); - b.scfCondition(measureResult, q1); - return SmallVector{q1}; - }, - [&](ValueRange iterArgs) { - auto q2 = b.h(iterArgs[0]); - return SmallVector{q2}; - }); - auto insert = b.qtensorInsert(whileResult[0], t0, iv); - return SmallVector{insert}; - }); + auto scfFor = + b.scfFor(0, 2, 1, loopResult, [&](Value iv, ValueRange iterArgs) { + auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); + auto whileResult = b.scfWhile( + q0, + [&](ValueRange iterArgs) { + auto [q1, measureResult] = b.measure(iterArgs[0]); + b.scfCondition(measureResult, q1); + return SmallVector{q1}; + }, + [&](ValueRange iterArgs) { + auto q2 = b.h(iterArgs[0]); + return SmallVector{q2}; + }); + auto insert = b.qtensorInsert(whileResult[0], t0, iv); + return SmallVector{insert}; + }); + return measureAndReturn(b, {scfFor[0]}); } -void nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto control0 = b.allocQubit(); auto control1 = b.h(control0); - b.scfFor(0, 3, 1, {reg.value, control1}, [&](Value iv, ValueRange iterArgs) { - auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); - auto q1 = b.h(q0); - auto [controls, targets] = b.ctrl(iterArgs[1], q1, [&](ValueRange args) { - auto q2 = b.x(args[0]); - return SmallVector{q2}; - }); - auto insert = b.qtensorInsert(targets[0], t0, iv); - return SmallVector{insert, controls[0]}; - }); -} - -void nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b) { + auto scfFor = b.scfFor(0, 3, 1, {reg.value, control1}, + [&](Value iv, ValueRange iterArgs) { + auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); + auto q1 = b.h(q0); + auto [controls, targets] = + b.ctrl(iterArgs[1], q1, [&](ValueRange args) { + auto q2 = b.x(args[0]); + return SmallVector{q2}; + }); + auto insert = b.qtensorInsert(targets[0], t0, iv); + return SmallVector{insert, controls[0]}; + }); + return measureAndReturn(b, {scfFor[0], scfFor[1]}); +} + +std::pair, SmallVector> +nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto control = b.h(reg[0]); - b.scfFor(1, 4, 1, {reg.value, control}, [&](Value iv, ValueRange iterArgs) { - auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); - auto q1 = b.h(q0); - auto [controls, targets] = b.ctrl(iterArgs[1], q1, [&](ValueRange args) { - auto q2 = b.x(args[0]); - return SmallVector{q2}; - }); - auto insert = b.qtensorInsert(targets[0], t0, iv); - return SmallVector{insert, controls[0]}; - }); -} - -void nestedIfOpForLoop(QCOProgramBuilder& b) { + auto scfFor = b.scfFor(1, 4, 1, {reg.value, control}, + [&](Value iv, ValueRange iterArgs) { + auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); + auto q1 = b.h(q0); + auto [controls, targets] = + b.ctrl(iterArgs[1], q1, [&](ValueRange args) { + auto q2 = b.x(args[0]); + return SmallVector{q2}; + }); + auto insert = b.qtensorInsert(targets[0], t0, iv); + return SmallVector{insert, controls[0]}; + }); + return measureAndReturn(b, {scfFor[0], scfFor[1]}); +} + +std::pair, SmallVector> +nestedIfOpForLoop(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); auto q1 = b.h(q0); auto [q2, cond] = b.measure(q1); - b.qcoIf( + auto ifRes = b.qcoIf( cond, {reg.value, q2}, [&](ValueRange args) { auto q3 = b.h(args[1]); @@ -2351,6 +3499,7 @@ void nestedIfOpForLoop(QCOProgramBuilder& b) { }); return SmallVector{scfFor[0], args[1]}; }); + return measureAndReturn(b, {ifRes[0], ifRes[1]}); } } // namespace mlir::qco diff --git a/mlir/unittests/programs/qco_programs.h b/mlir/unittests/programs/qco_programs.h index b4197c5a7f..c6f8d3b0e4 100644 --- a/mlir/unittests/programs/qco_programs.h +++ b/mlir/unittests/programs/qco_programs.h @@ -10,1072 +10,1354 @@ #pragma once +#include + +#include + namespace mlir::qco { class QCOProgramBuilder; /// Creates an empty QCO program. -void emptyQCO(QCOProgramBuilder& builder); +std::pair, SmallVector> +emptyQCO(QCOProgramBuilder& builder); // --- Qubit Management ----------------------------------------------------- // /// Allocates a single qubit. -void allocQubit(QCOProgramBuilder& b); +std::pair, SmallVector> +allocQubit(QCOProgramBuilder& b); + +/// Allocates a single qubit that is not measured. +std::pair, SmallVector> +allocQubitNoMeasure(QCOProgramBuilder& b); + +/// Allocates a qubit register of size `1`. +std::pair, SmallVector> +alloc1QubitRegister(QCOProgramBuilder& b); /// Allocates a qubit register of size `2`. -void allocQubitRegister(QCOProgramBuilder& b); +std::pair, SmallVector> +alloc2QubitRegister(QCOProgramBuilder& b); + +/// Allocates a qubit register of size `3`. +std::pair, SmallVector> +alloc3QubitRegister(QCOProgramBuilder& b); /// Allocates two qubit registers of size `2` and `3`. -void allocMultipleQubitRegisters(QCOProgramBuilder& b); +std::pair, SmallVector> +allocMultipleQubitRegisters(QCOProgramBuilder& b); /// Allocates a large qubit register. -void allocLargeRegister(QCOProgramBuilder& b); +std::pair, SmallVector> +allocLargeRegister(QCOProgramBuilder& b); /// Allocates two inline qubits. -void staticQubits(QCOProgramBuilder& b); +std::pair, SmallVector> +staticQubits(QCOProgramBuilder& b); + +/// Allocates two inline qubits without measuring them. +std::pair, SmallVector> +staticQubitsNoMeasure(QCOProgramBuilder& b); /// Allocates two static qubits and applies operations. -void staticQubitsWithOps(QCOProgramBuilder& b); +std::pair, SmallVector> +staticQubitsWithOps(QCOProgramBuilder& b); /// Allocates two static qubits and applies parametric gates. -void staticQubitsWithParametricOps(QCOProgramBuilder& b); +std::pair, SmallVector> +staticQubitsWithParametricOps(QCOProgramBuilder& b); /// Allocates two static qubits and applies a two-target gate. -void staticQubitsWithTwoTargetOps(QCOProgramBuilder& b); +std::pair, SmallVector> +staticQubitsWithTwoTargetOps(QCOProgramBuilder& b); /// Allocates two static qubits and applies a controlled gate. -void staticQubitsWithCtrl(QCOProgramBuilder& b); +std::pair, SmallVector> +staticQubitsWithCtrl(QCOProgramBuilder& b); /// Allocates a static qubit and applies an inverse modifier. -void staticQubitsWithInv(QCOProgramBuilder& b); +std::pair, SmallVector> +staticQubitsWithInv(QCOProgramBuilder& b); /// Allocates and explicitly sinks a single qubit. -void allocSinkPair(QCOProgramBuilder& b); +std::pair, SmallVector> +allocSinkPair(QCOProgramBuilder& b); // --- Invalid / mixed addressing (unit tests) -------------------------------- /// @pre `builder.initialize()`. Fatal mixed addressing: static then dynamic /// alloc. -void mixedStaticThenDynamicQubit(QCOProgramBuilder& b); +std::pair, SmallVector> +mixedStaticThenDynamicQubit(QCOProgramBuilder& b); /// @pre `builder.initialize()`. Fatal mixed addressing: `qtensor` alloc then /// static. -void mixedDynamicRegisterThenStaticQubit(QCOProgramBuilder& b); +std::pair, SmallVector> +mixedDynamicRegisterThenStaticQubit(QCOProgramBuilder& b); // --- MeasureOp ------------------------------------------------------------ // /// Measures a single qubit into a single classical bit. -void singleMeasurementToSingleBit(QCOProgramBuilder& b); +std::pair, SmallVector> +singleMeasurementToSingleBit(QCOProgramBuilder& b); /// Repeatedly measures a single qubit into the same classical bit. -void repeatedMeasurementToSameBit(QCOProgramBuilder& b); +std::pair, SmallVector> +repeatedMeasurementToSameBit(QCOProgramBuilder& b); /// Repeatedly measures a single qubit into different classical bits. -void repeatedMeasurementToDifferentBits(QCOProgramBuilder& b); +std::pair, SmallVector> +repeatedMeasurementToDifferentBits(QCOProgramBuilder& b); /// Measures multiple qubits into multiple classical bits. -void multipleClassicalRegistersAndMeasurements(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleClassicalRegistersAndMeasurements(QCOProgramBuilder& b); /// Measures a single qubit into a single classical bit, without explicitly /// allocating a quantum or classical register. -void measurementWithoutRegisters(QCOProgramBuilder& b); +std::pair, SmallVector> +measurementWithoutRegisters(QCOProgramBuilder& b); // --- ResetOp -------------------------------------------------------------- // /// Resets a single qubit without any operations being applied. -void resetQubitWithoutOp(QCOProgramBuilder& b); +std::pair, SmallVector> +resetQubitWithoutOp(QCOProgramBuilder& b); /// Resets multiple qubits without any operations being applied. -void resetMultipleQubitsWithoutOp(QCOProgramBuilder& b); +std::pair, SmallVector> +resetMultipleQubitsWithoutOp(QCOProgramBuilder& b); /// Repeatedly resets a single qubit without any operations being applied. -void repeatedResetWithoutOp(QCOProgramBuilder& b); +std::pair, SmallVector> +repeatedResetWithoutOp(QCOProgramBuilder& b); /// Resets a single qubit after a single operation. -void resetQubitAfterSingleOp(QCOProgramBuilder& b); +std::pair, SmallVector> +resetQubitAfterSingleOp(QCOProgramBuilder& b); /// Resets multiple qubits after a single operation. -void resetMultipleQubitsAfterSingleOp(QCOProgramBuilder& b); +std::pair, SmallVector> +resetMultipleQubitsAfterSingleOp(QCOProgramBuilder& b); /// Repeatedly resets a single qubit after a single operation. -void repeatedResetAfterSingleOp(QCOProgramBuilder& b); +std::pair, SmallVector> +repeatedResetAfterSingleOp(QCOProgramBuilder& b); // --- GPhaseOp ------------------------------------------------------------- // /// Creates a circuit with just a global phase. -void globalPhase(QCOProgramBuilder& b); +std::pair, SmallVector> +globalPhase(QCOProgramBuilder& b); /// Creates a controlled global phase gate with a single control qubit. -void singleControlledGlobalPhase(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledGlobalPhase(QCOProgramBuilder& b); /// Creates a multi-controlled global phase gate with multiple control qubits. -void multipleControlledGlobalPhase(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledGlobalPhase(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a global phase gate. -void inverseGlobalPhase(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseGlobalPhase(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled global /// phase gate. -void inverseMultipleControlledGlobalPhase(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledGlobalPhase(QCOProgramBuilder& b); // --- IdOp ----------------------------------------------------------------- // /// Creates a circuit with just an identity gate. -void identity(QCOProgramBuilder& b); +std::pair, SmallVector> identity(QCOProgramBuilder& b); /// Creates a controlled identity gate with a single control qubit. -void singleControlledIdentity(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledIdentity(QCOProgramBuilder& b); /// Creates a multi-controlled identity gate with multiple control qubits. -void multipleControlledIdentity(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledIdentity(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled identity gate. -void nestedControlledIdentity(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledIdentity(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled identity gate. -void trivialControlledIdentity(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledIdentity(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an identity gate. -void inverseIdentity(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseIdentity(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled identity /// gate. -void inverseMultipleControlledIdentity(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledIdentity(QCOProgramBuilder& b); // --- XOp ------------------------------------------------------------------ // /// Creates a circuit with just an X gate. -void x(QCOProgramBuilder& b); +std::pair, SmallVector> x(QCOProgramBuilder& b); /// Creates a circuit with a single controlled X gate. -void singleControlledX(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledX(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled X gate. -void multipleControlledX(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledX(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled X gate. -void nestedControlledX(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledX(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled X gate. -void trivialControlledX(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledX(QCOProgramBuilder& b); /// Creates a circuit with repeated controlled X gates. -void repeatedControlledX(QCOProgramBuilder& b); +std::pair, SmallVector> +repeatedControlledX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an X gate. -void inverseX(QCOProgramBuilder& b); +std::pair, SmallVector> inverseX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled X gate. -void inverseMultipleControlledX(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledX(QCOProgramBuilder& b); /// Creates a circuit with two X gates in a row. -void twoX(QCOProgramBuilder& b); +std::pair, SmallVector> twoX(QCOProgramBuilder& b); // --- YOp ------------------------------------------------------------------ // /// Creates a circuit with just a Y gate. -void y(QCOProgramBuilder& b); +std::pair, SmallVector> y(QCOProgramBuilder& b); /// Creates a circuit with a single controlled Y gate. -void singleControlledY(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledY(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled Y gate. -void multipleControlledY(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledY(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled Y gate. -void nestedControlledY(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledY(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled Y gate. -void trivialControlledY(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Y gate. -void inverseY(QCOProgramBuilder& b); +std::pair, SmallVector> inverseY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Y gate. -void inverseMultipleControlledY(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledY(QCOProgramBuilder& b); /// Creates a circuit with two Y gates in a row. -void twoY(QCOProgramBuilder& b); +std::pair, SmallVector> twoY(QCOProgramBuilder& b); // --- ZOp ------------------------------------------------------------------ // /// Creates a circuit with just a Z gate. -void z(QCOProgramBuilder& b); +std::pair, SmallVector> z(QCOProgramBuilder& b); /// Creates a circuit with a single controlled Z gate. -void singleControlledZ(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledZ(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled Z gate. -void multipleControlledZ(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledZ(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled Z gate. -void nestedControlledZ(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledZ(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled Z gate. -void trivialControlledZ(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledZ(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Z gate. -void inverseZ(QCOProgramBuilder& b); +std::pair, SmallVector> inverseZ(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Z gate. -void inverseMultipleControlledZ(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledZ(QCOProgramBuilder& b); /// Creates a circuit with two Z gates in a row. -void twoZ(QCOProgramBuilder& b); +std::pair, SmallVector> twoZ(QCOProgramBuilder& b); // --- HOp ------------------------------------------------------------------ // /// Creates a circuit with just an H gate. -void h(QCOProgramBuilder& b); +std::pair, SmallVector> h(QCOProgramBuilder& b); /// Creates a circuit with a single controlled H gate. -void singleControlledH(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledH(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled H gate. -void multipleControlledH(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledH(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled H gate. -void nestedControlledH(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledH(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled H gate. -void trivialControlledH(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledH(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an H gate. -void inverseH(QCOProgramBuilder& b); +std::pair, SmallVector> inverseH(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled H gate. -void inverseMultipleControlledH(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledH(QCOProgramBuilder& b); /// Creates a circuit with two H gates in a row. -void twoH(QCOProgramBuilder& b); +std::pair, SmallVector> twoH(QCOProgramBuilder& b); /// Creates a circuit with just an H gate and no qubit register. -void hWithoutRegister(QCOProgramBuilder& b); +std::pair, SmallVector> +hWithoutRegister(QCOProgramBuilder& b); // --- SOp ------------------------------------------------------------------ // /// Creates a circuit with just an S gate. -void s(QCOProgramBuilder& b); +std::pair, SmallVector> s(QCOProgramBuilder& b); /// Creates a circuit with a single controlled S gate. -void singleControlledS(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledS(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled S gate. -void multipleControlledS(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledS(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled S gate. -void nestedControlledS(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledS(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled S gate. -void trivialControlledS(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledS(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an S gate. -void inverseS(QCOProgramBuilder& b); +std::pair, SmallVector> inverseS(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled S gate. -void inverseMultipleControlledS(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledS(QCOProgramBuilder& b); /// Creates a circuit with an S gate followed by an Sdg gate. -void sThenSdg(QCOProgramBuilder& b); +std::pair, SmallVector> sThenSdg(QCOProgramBuilder& b); /// Creates a circuit with two S gates in a row. -void twoS(QCOProgramBuilder& b); +std::pair, SmallVector> twoS(QCOProgramBuilder& b); // --- SdgOp ---------------------------------------------------------------- // /// Creates a circuit with just an Sdg gate. -void sdg(QCOProgramBuilder& b); +std::pair, SmallVector> sdg(QCOProgramBuilder& b); /// Creates a circuit with a single controlled Sdg gate. -void singleControlledSdg(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled Sdg gate. -void multipleControlledSdg(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled Sdg gate. -void nestedControlledSdg(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled Sdg gate. -void trivialControlledSdg(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an Sdg gate. -void inverseSdg(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseSdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Sdg gate. -void inverseMultipleControlledSdg(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with an Sdg gate followed an S gate. -void sdgThenS(QCOProgramBuilder& b); +std::pair, SmallVector> sdgThenS(QCOProgramBuilder& b); /// Creates a circuit with two Sdg gates in a row. -void twoSdg(QCOProgramBuilder& b); +std::pair, SmallVector> twoSdg(QCOProgramBuilder& b); // --- TOp ------------------------------------------------------------------ // /// Creates a circuit with just a T gate. -void t_(QCOProgramBuilder& b); // NOLINT(*-identifier-naming) +std::pair, SmallVector> +t_(QCOProgramBuilder& b); // NOLINT(*-identifier-naming) /// Creates a circuit with a single controlled T gate. -void singleControlledT(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledT(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled T gate. -void multipleControlledT(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledT(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled T gate. -void nestedControlledT(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledT(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled T gate. -void trivialControlledT(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledT(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a T gate. -void inverseT(QCOProgramBuilder& b); +std::pair, SmallVector> inverseT(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled T gate. -void inverseMultipleControlledT(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledT(QCOProgramBuilder& b); /// Creates a circuit with a T gate followed by a Tdg gate. -void tThenTdg(QCOProgramBuilder& b); +std::pair, SmallVector> tThenTdg(QCOProgramBuilder& b); /// Creates a circuit with two T gates in a row. -void twoT(QCOProgramBuilder& b); +std::pair, SmallVector> twoT(QCOProgramBuilder& b); // --- TdgOp ---------------------------------------------------------------- // /// Creates a circuit with just a Tdg gate. -void tdg(QCOProgramBuilder& b); +std::pair, SmallVector> tdg(QCOProgramBuilder& b); /// Creates a circuit with a single controlled Tdg gate. -void singleControlledTdg(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled Tdg gate. -void multipleControlledTdg(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled Tdg gate. -void nestedControlledTdg(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled Tdg gate. -void trivialControlledTdg(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Tdg gate. -void inverseTdg(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseTdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Tdg gate. -void inverseMultipleControlledTdg(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with a Tdg gate followed by a T gate. -void tdgThenT(QCOProgramBuilder& b); +std::pair, SmallVector> tdgThenT(QCOProgramBuilder& b); /// Creates a circuit with two Tdg gates in a row. -void twoTdg(QCOProgramBuilder& b); +std::pair, SmallVector> twoTdg(QCOProgramBuilder& b); // --- SXOp ----------------------------------------------------------------- // /// Creates a circuit with just an SX gate. -void sx(QCOProgramBuilder& b); +std::pair, SmallVector> sx(QCOProgramBuilder& b); /// Creates a circuit with a single controlled SX gate. -void singleControlledSx(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledSx(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled SX gate. -void multipleControlledSx(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledSx(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled SX gate. -void nestedControlledSx(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledSx(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled SX gate. -void trivialControlledSx(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledSx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an SX gate. -void inverseSx(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseSx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SX gate. -void inverseMultipleControlledSx(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledSx(QCOProgramBuilder& b); /// Creates a circuit with an SX gate followed by an SXdg gate. -void sxThenSxdg(QCOProgramBuilder& b); +std::pair, SmallVector> +sxThenSxdg(QCOProgramBuilder& b); /// Creates a circuit with two SX gates in a row. -void twoSx(QCOProgramBuilder& b); +std::pair, SmallVector> twoSx(QCOProgramBuilder& b); // --- SXdgOp --------------------------------------------------------------- // /// Creates a circuit with just an SXdg gate. -void sxdg(QCOProgramBuilder& b); +std::pair, SmallVector> sxdg(QCOProgramBuilder& b); /// Creates a circuit with a single controlled SXdg gate. -void singleControlledSxdg(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled SXdg gate. -void multipleControlledSxdg(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled SXdg gate. -void nestedControlledSxdg(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled SXdg gate. -void trivialControlledSxdg(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an SXdg gate. -void inverseSxdg(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseSxdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SXdg /// gate. -void inverseMultipleControlledSxdg(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with an SXdg gate followed by an SX gate. -void sxdgThenSx(QCOProgramBuilder& b); +std::pair, SmallVector> +sxdgThenSx(QCOProgramBuilder& b); /// Creates a circuit with two SXdg gates in a row. -void twoSxdg(QCOProgramBuilder& b); +std::pair, SmallVector> twoSxdg(QCOProgramBuilder& b); // --- RXOp ----------------------------------------------------------------- // /// Creates a circuit with just an RX gate. -void rx(QCOProgramBuilder& b); +std::pair, SmallVector> rx(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RX gate. -void singleControlledRx(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledRx(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RX gate. -void multipleControlledRx(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRx(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RX gate. -void nestedControlledRx(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRx(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RX gate. -void trivialControlledRx(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RX gate. -void inverseRx(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseRx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RX gate. -void inverseMultipleControlledRx(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRx(QCOProgramBuilder& b); /// Creates a circuit with two RX gates in a row with opposite phases. -void twoRxOppositePhase(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRxOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with an RX gate with an angle of pi/2. -void rxPiOver2(QCOProgramBuilder& b); +std::pair, SmallVector> +rxPiOver2(QCOProgramBuilder& b); // --- RYOp ----------------------------------------------------------------- // /// Creates a circuit with just an RY gate. -void ry(QCOProgramBuilder& b); +std::pair, SmallVector> ry(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RY gate. -void singleControlledRy(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledRy(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RY gate. -void multipleControlledRy(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRy(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RY gate. -void nestedControlledRy(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRy(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RY gate. -void trivialControlledRy(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRy(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RY gate. -void inverseRy(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseRy(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RY gate. -void inverseMultipleControlledRy(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRy(QCOProgramBuilder& b); /// Creates a circuit with two RY gates in a row with opposite phases. -void twoRyOppositePhase(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRyOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with an RY gate with an angle of pi/2. -void ryPiOver2(QCOProgramBuilder& b); +std::pair, SmallVector> +ryPiOver2(QCOProgramBuilder& b); // --- RZOp ----------------------------------------------------------------- // /// Creates a circuit with just an RZ gate. -void rz(QCOProgramBuilder& b); +std::pair, SmallVector> rz(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RZ gate. -void singleControlledRz(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledRz(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RZ gate. -void multipleControlledRz(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRz(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RZ gate. -void nestedControlledRz(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRz(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RZ gate. -void trivialControlledRz(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRz(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZ gate. -void inverseRz(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseRz(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZ gate. -void inverseMultipleControlledRz(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRz(QCOProgramBuilder& b); /// Creates a circuit with two RZ gates in a row with opposite phases. -void twoRzOppositePhase(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRzOppositePhase(QCOProgramBuilder& b); // --- POp ------------------------------------------------------------------ // /// Creates a circuit with just a P gate. -void p(QCOProgramBuilder& b); +std::pair, SmallVector> p(QCOProgramBuilder& b); /// Creates a circuit with a single controlled P gate. -void singleControlledP(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledP(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled P gate. -void multipleControlledP(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledP(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled P gate. -void nestedControlledP(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledP(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled P gate. -void trivialControlledP(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledP(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a P gate. -void inverseP(QCOProgramBuilder& b); +std::pair, SmallVector> inverseP(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled P gate. -void inverseMultipleControlledP(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledP(QCOProgramBuilder& b); /// Creates a circuit with two P gates in a row with opposite phases. -void twoPOppositePhase(QCOProgramBuilder& b); +std::pair, SmallVector> +twoPOppositePhase(QCOProgramBuilder& b); // --- ROp ------------------------------------------------------------------ // /// Creates a circuit with just an R gate. -void r(QCOProgramBuilder& b); +std::pair, SmallVector> r(QCOProgramBuilder& b); /// Creates a circuit with a single controlled R gate. -void singleControlledR(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledR(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled R gate. -void multipleControlledR(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledR(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled R gate. -void nestedControlledR(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledR(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled R gate. -void trivialControlledR(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledR(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an R gate. -void inverseR(QCOProgramBuilder& b); +std::pair, SmallVector> inverseR(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled R gate. -void inverseMultipleControlledR(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledR(QCOProgramBuilder& b); /// Creates a circuit with an R gate that can be canonicalized to an RX gate. -void canonicalizeRToRx(QCOProgramBuilder& b); +std::pair, SmallVector> +canonicalizeRToRx(QCOProgramBuilder& b); /// Creates a circuit with an R gate that can be canonicalized to an RY gate. -void canonicalizeRToRy(QCOProgramBuilder& b); +std::pair, SmallVector> +canonicalizeRToRy(QCOProgramBuilder& b); // --- U2Op ----------------------------------------------------------------- // /// Creates a circuit with just a U2 gate. -void u2(QCOProgramBuilder& b); +std::pair, SmallVector> u2(QCOProgramBuilder& b); /// Creates a circuit with a single controlled U2 gate. -void singleControlledU2(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledU2(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled U2 gate. -void multipleControlledU2(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledU2(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled U2 gate. -void nestedControlledU2(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledU2(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled U2 gate. -void trivialControlledU2(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledU2(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a U2 gate. -void inverseU2(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseU2(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled U2 gate. -void inverseMultipleControlledU2(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledU2(QCOProgramBuilder& b); /// Creates a circuit with a U2 gate that can be canonicalized to an H gate. -void canonicalizeU2ToH(QCOProgramBuilder& b); +std::pair, SmallVector> +canonicalizeU2ToH(QCOProgramBuilder& b); /// Creates a circuit with a U2 gate that can be canonicalized to an RX gate. -void canonicalizeU2ToRx(QCOProgramBuilder& b); +std::pair, SmallVector> +canonicalizeU2ToRx(QCOProgramBuilder& b); /// Creates a circuit with a U2 gate that can be canonicalized to an RY gate. -void canonicalizeU2ToRy(QCOProgramBuilder& b); +std::pair, SmallVector> +canonicalizeU2ToRy(QCOProgramBuilder& b); // --- UOp ------------------------------------------------------------------ // /// Creates a circuit with just a U gate. -void u(QCOProgramBuilder& b); +std::pair, SmallVector> u(QCOProgramBuilder& b); /// Creates a circuit with a single controlled U gate. -void singleControlledU(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledU(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled U gate. -void multipleControlledU(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledU(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled U gate. -void nestedControlledU(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledU(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled U gate. -void trivialControlledU(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledU(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a U gate. -void inverseU(QCOProgramBuilder& b); +std::pair, SmallVector> inverseU(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled U gate. -void inverseMultipleControlledU(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledU(QCOProgramBuilder& b); /// Creates a circuit with a U gate that can be canonicalized to a P gate. -void canonicalizeUToP(QCOProgramBuilder& b); +std::pair, SmallVector> +canonicalizeUToP(QCOProgramBuilder& b); /// Creates a circuit with a U gate that can be canonicalized to an RX gate. -void canonicalizeUToRx(QCOProgramBuilder& b); +std::pair, SmallVector> +canonicalizeUToRx(QCOProgramBuilder& b); /// Creates a circuit with a U gate that can be canonicalized to an RY gate. -void canonicalizeUToRy(QCOProgramBuilder& b); +std::pair, SmallVector> +canonicalizeUToRy(QCOProgramBuilder& b); /// Creates a circuit with a U gate that can be canonicalized to a U2 gate. -void canonicalizeUToU2(QCOProgramBuilder& b); +std::pair, SmallVector> +canonicalizeUToU2(QCOProgramBuilder& b); // --- SWAPOp --------------------------------------------------------------- // /// Creates a circuit with just a SWAP gate. -void swap(QCOProgramBuilder& b); +std::pair, SmallVector> swap(QCOProgramBuilder& b); /// Creates a circuit with a single controlled SWAP gate. -void singleControlledSwap(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledSwap(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled SWAP gate. -void multipleControlledSwap(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledSwap(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled SWAP gate. -void nestedControlledSwap(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledSwap(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled SWAP gate. -void trivialControlledSwap(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledSwap(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a SWAP gate. -void inverseSwap(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseSwap(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SWAP /// gate. -void inverseMultipleControlledSwap(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledSwap(QCOProgramBuilder& b); /// Creates a circuit with two SWAP gates in a row. -void twoSwap(QCOProgramBuilder& b); +std::pair, SmallVector> twoSwap(QCOProgramBuilder& b); /// Creates a circuit with two SWAP gates in a row with swapped targets. -void twoSwapSwappedTargets(QCOProgramBuilder& b); +std::pair, SmallVector> +twoSwapSwappedTargets(QCOProgramBuilder& b); // --- iSWAPOp -------------------------------------------------------------- // /// Creates a circuit with just an iSWAP gate. -void iswap(QCOProgramBuilder& b); +std::pair, SmallVector> iswap(QCOProgramBuilder& b); /// Creates a circuit with a single controlled iSWAP gate. -void singleControlledIswap(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledIswap(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled iSWAP gate. -void multipleControlledIswap(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledIswap(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled iSWAP gate. -void nestedControlledIswap(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledIswap(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled iSWAP gate. -void trivialControlledIswap(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledIswap(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an iSWAP gate. -void inverseIswap(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseIswap(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled iSWAP /// gate. -void inverseMultipleControlledIswap(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledIswap(QCOProgramBuilder& b); // --- DCXOp ---------------------------------------------------------------- // /// Creates a circuit with just a DCX gate. -void dcx(QCOProgramBuilder& b); +std::pair, SmallVector> dcx(QCOProgramBuilder& b); /// Creates a circuit with a single controlled DCX gate. -void singleControlledDcx(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledDcx(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled DCX gate. -void multipleControlledDcx(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledDcx(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled DCX gate. -void nestedControlledDcx(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledDcx(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled DCX gate. -void trivialControlledDcx(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledDcx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a DCX gate. -void inverseDcx(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseDcx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled DCX gate. -void inverseMultipleControlledDcx(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledDcx(QCOProgramBuilder& b); /// Creates a circuit with two DCX gates in a row with identical targets. -void twoDcx(QCOProgramBuilder& b); +std::pair, SmallVector> twoDcx(QCOProgramBuilder& b); /// Creates a circuit with two DCX gates in a row with swapped targets. -void twoDcxSwappedTargets(QCOProgramBuilder& b); +std::pair, SmallVector> +twoDcxSwappedTargets(QCOProgramBuilder& b); // --- ECROp ---------------------------------------------------------------- // /// Creates a circuit with just an ECR gate. -void ecr(QCOProgramBuilder& b); +std::pair, SmallVector> ecr(QCOProgramBuilder& b); /// Creates a circuit with a single controlled ECR gate. -void singleControlledEcr(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledEcr(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled ECR gate. -void multipleControlledEcr(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledEcr(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled ECR gate. -void nestedControlledEcr(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledEcr(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled ECR gate. -void trivialControlledEcr(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledEcr(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an ECR gate. -void inverseEcr(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseEcr(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled ECR gate. -void inverseMultipleControlledEcr(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledEcr(QCOProgramBuilder& b); /// Creates a circuit with two ECR gates in a row. -void twoEcr(QCOProgramBuilder& b); +std::pair, SmallVector> twoEcr(QCOProgramBuilder& b); // --- RXXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RXX gate. -void rxx(QCOProgramBuilder& b); +std::pair, SmallVector> rxx(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RXX gate. -void singleControlledRxx(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RXX gate. -void multipleControlledRxx(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RXX gate. -void nestedControlledRxx(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RXX gate. -void trivialControlledRxx(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RXX gate. -void inverseRxx(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseRxx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RXX gate. -void inverseMultipleControlledRxx(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with a triple-controlled RXX gate. -void tripleControlledRxx(QCOProgramBuilder& b); +std::pair, SmallVector> +tripleControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with a four-controlled RXX gate. -void fourControlledRxx(QCOProgramBuilder& b); +std::pair, SmallVector> +fourControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with two RXX gates in a row. -void twoRxx(QCOProgramBuilder& b); +std::pair, SmallVector> twoRxx(QCOProgramBuilder& b); /// Creates a circuit with two RXX gates in a row with swapped targets. -void twoRxxSwappedTargets(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRxxSwappedTargets(QCOProgramBuilder& b); /// Creates a circuit with two RXX gates in a row with opposite phases. -void twoRxxOppositePhase(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRxxOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with two RXX gates in a row with opposite phases and /// swapped targets. -void twoRxxOppositePhaseSwappedTargets(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRxxOppositePhaseSwappedTargets(QCOProgramBuilder& b); // --- RYYOp ---------------------------------------------------------------- // /// Creates a circuit with just an RYY gate. -void ryy(QCOProgramBuilder& b); +std::pair, SmallVector> ryy(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RYY gate. -void singleControlledRyy(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledRyy(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RYY gate. -void multipleControlledRyy(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRyy(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RYY gate. -void nestedControlledRyy(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRyy(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RYY gate. -void trivialControlledRyy(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRyy(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RYY gate. -void inverseRyy(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseRyy(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RYY gate. -void inverseMultipleControlledRyy(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRyy(QCOProgramBuilder& b); /// Creates a circuit with two RYY gates in a row. -void twoRyy(QCOProgramBuilder& b); +std::pair, SmallVector> twoRyy(QCOProgramBuilder& b); /// Creates a circuit with two RYY gates in a row with swapped targets. -void twoRyySwappedTargets(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRyySwappedTargets(QCOProgramBuilder& b); /// Creates a circuit with two RYY gates in a row with opposite phases. -void twoRyyOppositePhase(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRyyOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with two RYY gates in a row with opposite phases and /// swapped targets. -void twoRyyOppositePhaseSwappedTargets(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRyyOppositePhaseSwappedTargets(QCOProgramBuilder& b); // --- RZXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZX gate. -void rzx(QCOProgramBuilder& b); +std::pair, SmallVector> rzx(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RZX gate. -void singleControlledRzx(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledRzx(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RZX gate. -void multipleControlledRzx(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRzx(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RZX gate. -void nestedControlledRzx(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRzx(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RZX gate. -void trivialControlledRzx(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRzx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZX gate. -void inverseRzx(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseRzx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZX gate. -void inverseMultipleControlledRzx(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRzx(QCOProgramBuilder& b); /// Creates a circuit with two RZX gates in a row with opposite phases. -void twoRzxOppositePhase(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRzxOppositePhase(QCOProgramBuilder& b); // --- RZZOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZZ gate. -void rzz(QCOProgramBuilder& b); +std::pair, SmallVector> rzz(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RZZ gate. -void singleControlledRzz(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledRzz(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RZZ gate. -void multipleControlledRzz(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRzz(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RZZ gate. -void nestedControlledRzz(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRzz(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RZZ gate. -void trivialControlledRzz(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRzz(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZZ gate. -void inverseRzz(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseRzz(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZZ gate. -void inverseMultipleControlledRzz(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRzz(QCOProgramBuilder& b); /// Creates a circuit with two RZZ gates in a row. -void twoRzz(QCOProgramBuilder& b); +std::pair, SmallVector> twoRzz(QCOProgramBuilder& b); /// Creates a circuit with two RZZ gates in a row with swapped targets. -void twoRzzSwappedTargets(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRzzSwappedTargets(QCOProgramBuilder& b); /// Creates a circuit with two RZZ gates in a row with opposite phases. -void twoRzzOppositePhase(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRzzOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with two RZZ gates in a row with opposite phases and /// swapped targets. -void twoRzzOppositePhaseSwappedTargets(QCOProgramBuilder& b); +std::pair, SmallVector> +twoRzzOppositePhaseSwappedTargets(QCOProgramBuilder& b); // --- XXPlusYYOp ----------------------------------------------------------- // /// Creates a circuit with just an XXPlusYY gate. -void xxPlusYY(QCOProgramBuilder& b); +std::pair, SmallVector> xxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with a single controlled XXPlusYY gate. -void singleControlledXxPlusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledXxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled XXPlusYY gate. -void multipleControlledXxPlusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledXxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled XXPlusYY gate. -void nestedControlledXxPlusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledXxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled XXPlusYY gate. -void trivialControlledXxPlusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledXxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an XXPlusYY gate. -void inverseXxPlusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseXxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled XXPlusYY /// gate. -void inverseMultipleControlledXxPlusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledXxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with two XXPlusYY gates in a row with opposite phases. -void twoXxPlusYYOppositePhase(QCOProgramBuilder& b); +std::pair, SmallVector> +twoXxPlusYYOppositePhase(QCOProgramBuilder& b); // --- XXMinusYYOp ---------------------------------------------------------- // /// Creates a circuit with just an XXMinusYY gate. -void xxMinusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +xxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with a single controlled XXMinusYY gate. -void singleControlledXxMinusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledXxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled XXMinusYY gate. -void multipleControlledXxMinusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +multipleControlledXxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled XXMinusYY gate. -void nestedControlledXxMinusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedControlledXxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled XXMinusYY gate. -void trivialControlledXxMinusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialControlledXxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an XXMinusYY gate. -void inverseXxMinusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseXxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled XXMinusYY /// gate. -void inverseMultipleControlledXxMinusYY(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledXxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with two XXMinusYY gates in a row with opposite phases. -void twoXxMinusYYOppositePhase(QCOProgramBuilder& b); +std::pair, SmallVector> +twoXxMinusYYOppositePhase(QCOProgramBuilder& b); // --- BarrierOp ------------------------------------------------------------ // /// Creates a circuit with a barrier. -void barrier(QCOProgramBuilder& b); +std::pair, SmallVector> barrier(QCOProgramBuilder& b); /// Creates a circuit with a barrier on two qubits. -void barrierTwoQubits(QCOProgramBuilder& b); +std::pair, SmallVector> +barrierTwoQubits(QCOProgramBuilder& b); /// Creates a circuit with a barrier on multiple qubits. -void barrierMultipleQubits(QCOProgramBuilder& b); +std::pair, SmallVector> +barrierMultipleQubits(QCOProgramBuilder& b); /// Creates a circuit with a single controlled barrier. -void singleControlledBarrier(QCOProgramBuilder& b); +std::pair, SmallVector> +singleControlledBarrier(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a barrier. -void inverseBarrier(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseBarrier(QCOProgramBuilder& b); /// Creates a circuit with two barriers in a row with overlapping qubits. -void twoBarrier(QCOProgramBuilder& b); +std::pair, SmallVector> +twoBarrier(QCOProgramBuilder& b); // --- CtrlOp --------------------------------------------------------------- // /// Creates a circuit with a trivial ctrl modifier. -void trivialCtrl(QCOProgramBuilder& b); +std::pair, SmallVector> +trivialCtrl(QCOProgramBuilder& b); /// Creates a circuit with nested ctrl modifiers. -void nestedCtrl(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedCtrl(QCOProgramBuilder& b); /// Creates a circuit with triple nested ctrl modifiers. -void tripleNestedCtrl(QCOProgramBuilder& b); +std::pair, SmallVector> +tripleNestedCtrl(QCOProgramBuilder& b); /// Creates a circuit with double nested ctrl modifiers with two qubits each. -void doubleNestedCtrlTwoQubits(QCOProgramBuilder& b); +std::pair, SmallVector> +doubleNestedCtrlTwoQubits(QCOProgramBuilder& b); /// Creates a circuit with control modifiers interleaved by an inverse modifier. -void ctrlInvSandwich(QCOProgramBuilder& b); +std::pair, SmallVector> +ctrlInvSandwich(QCOProgramBuilder& b); // --- InvOp ---------------------------------------------------------------- // /// Creates a circuit with nested inverse modifiers. -void nestedInv(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedInv(QCOProgramBuilder& b); /// Creates a circuit with triple nested inverse modifiers. -void tripleNestedInv(QCOProgramBuilder& b); +std::pair, SmallVector> +tripleNestedInv(QCOProgramBuilder& b); /// Creates a circuit with inverse modifiers interleaved by a control modifier. -void invCtrlSandwich(QCOProgramBuilder& b); +std::pair, SmallVector> +invCtrlSandwich(QCOProgramBuilder& b); // --- IfOp ---------------------------------------------------------------- // /// Creates a circuit with a simple if operation with one qubit. -void simpleIf(QCOProgramBuilder& b); +std::pair, SmallVector> simpleIf(QCOProgramBuilder& b); /// Creates a circuit with an if operation with two qubits. -void ifTwoQubits(QCOProgramBuilder& b); +std::pair, SmallVector> +ifTwoQubits(QCOProgramBuilder& b); /// Creates a circuit with an if operation with an else branch. -void ifElse(QCOProgramBuilder& b); +std::pair, SmallVector> ifElse(QCOProgramBuilder& b); /// Creates a circuit with an if operation with one qubit and one register. -void ifOneQubitOneTensor(QCOProgramBuilder& b); +std::pair, SmallVector> +ifOneQubitOneTensor(QCOProgramBuilder& b); /// Creates a circuit with an if operation that uses a constant true as /// condition. -void constantTrueIf(QCOProgramBuilder& b); +std::pair, SmallVector> +constantTrueIf(QCOProgramBuilder& b); /// Creates a circuit with an if operation that uses a constant false as /// condition. -void constantFalseIf(QCOProgramBuilder& b); +std::pair, SmallVector> +constantFalseIf(QCOProgramBuilder& b); /// Creates a circuit with a nested if operation in the then branch that uses /// the same condition. -void nestedTrueIf(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedTrueIf(QCOProgramBuilder& b); /// Creates a circuit with a nested if operation in the else branch that uses /// the same condition. -void nestedFalseIf(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedFalseIf(QCOProgramBuilder& b); /// Creates a circuit with an if operation with a nested for operation with /// a register. -void nestedIfOpForLoop(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedIfOpForLoop(QCOProgramBuilder& b); // --- WhileOp -------------------------------------------------------------- // /// Creates a circuit with a while operation using a while loop. -void simpleWhileReset(QCOProgramBuilder& b); +std::pair, SmallVector> +simpleWhileReset(QCOProgramBuilder& b); /// Creates a circuit with a while operation using a do-while loop. -void simpleDoWhileReset(QCOProgramBuilder& b); +std::pair, SmallVector> +simpleDoWhileReset(QCOProgramBuilder& b); // --- ForOp ---------------------------------------------------------------- // /// Creates a circuit with a simple for operation with a register. -void simpleForLoop(QCOProgramBuilder& b); +std::pair, SmallVector> +simpleForLoop(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested if operation. -void nestedForLoopIfOp(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedForLoopIfOp(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a register and a nested while /// operation. -void nestedForLoopWhileOp(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedForLoopWhileOp(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is separately allocated from the /// register. -void nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is extracted from the register. -void nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b); +std::pair, SmallVector> +nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b); // --- QTensor Operations -------------------------------------------------- // /// Allocates a tensor of size `3`. -void qtensorAlloc(QCOProgramBuilder& b); +std::pair, SmallVector> +qtensorAlloc(QCOProgramBuilder& b); /// Allocates and explicitly deallocates a tensor. -void qtensorDealloc(QCOProgramBuilder& b); +std::pair, SmallVector> +qtensorDealloc(QCOProgramBuilder& b); /// Constructs a tensor with from_elements. -void qtensorFromElements(QCOProgramBuilder& b); +std::pair, SmallVector> +qtensorFromElements(QCOProgramBuilder& b); /// Extracts a qubit from a tensor. -void qtensorExtract(QCOProgramBuilder& b); +std::pair, SmallVector> +qtensorExtract(QCOProgramBuilder& b); /// Inserts a qubit into a tensor. -void qtensorInsert(QCOProgramBuilder& b); +std::pair, SmallVector> +qtensorInsert(QCOProgramBuilder& b); /// Extracts a qubit from a tensor and inserts it immediately at a different /// index. -void qtensorExtractInsertIndexMismatch(QCOProgramBuilder& b); +std::pair, SmallVector> +qtensorExtractInsertIndexMismatch(QCOProgramBuilder& b); /// Extracts a qubit from a tensor and inserts it immediately at the same index. -void qtensorExtractInsertSameIndex(QCOProgramBuilder& b); +std::pair, SmallVector> +qtensorExtractInsertSameIndex(QCOProgramBuilder& b); /// Inserts a qubit into a tensor and extracts it immediately at a different /// index. -void qtensorInsertExtractIndexMismatch(QCOProgramBuilder& b); +std::pair, SmallVector> +qtensorInsertExtractIndexMismatch(QCOProgramBuilder& b); /// Inserts a qubit into a tensor and extracts it immediately at the same index. -void qtensorInsertExtractSameIndex(QCOProgramBuilder& b); +std::pair, SmallVector> +qtensorInsertExtractSameIndex(QCOProgramBuilder& b); } // namespace mlir::qco From 6f1c64eee3e6149b081019cff5240cf8a3ecad82 Mon Sep 17 00:00:00 2001 From: Damian Rovara <93778306+DRovara@users.noreply.github.com> Date: Mon, 8 Jun 2026 10:56:54 +0200 Subject: [PATCH 22/80] Update mlir/include/mlir/Dialect/QCO/QCOUtils.h Co-authored-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com> Signed-off-by: Damian Rovara <93778306+DRovara@users.noreply.github.com> --- mlir/include/mlir/Dialect/QCO/QCOUtils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/include/mlir/Dialect/QCO/QCOUtils.h b/mlir/include/mlir/Dialect/QCO/QCOUtils.h index 4ade5351f7..b15c8a3752 100644 --- a/mlir/include/mlir/Dialect/QCO/QCOUtils.h +++ b/mlir/include/mlir/Dialect/QCO/QCOUtils.h @@ -248,7 +248,7 @@ mergeTwoTargetOneParameterWithSwappedTargets(OpType op, */ inline bool checkDeadGate(Operation* op) { if (!isMemoryEffectFree(op)) { - // This ignores operations with and regions that have children with memory + // This ignores operations and regions that have children with memory // effects, which should never be considered dead. return false; } From 7e63992906c91ac32accf3fd879d43ffe3b0c33a Mon Sep 17 00:00:00 2001 From: Damian Rovara <93778306+DRovara@users.noreply.github.com> Date: Mon, 8 Jun 2026 10:57:29 +0200 Subject: [PATCH 23/80] Update mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp Co-authored-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com> Signed-off-by: Damian Rovara <93778306+DRovara@users.noreply.github.com> --- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 13d3adc5e7..cb283eaaf2 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -1237,7 +1237,7 @@ INSTANTIATE_TEST_SUITE_P( testing::Values( QCOTestCase{"AllocQubit", MQT_NAMED_BUILDER(allocQubitNoMeasure), MQT_NAMED_BUILDER(emptyQCO)}, - QCOTestCase{"StaticQubits", MQT_NAMED_BUILDER(staticQubitsNoMeasure), + QCOTestCase{"StaticQubitsNoMeasure", MQT_NAMED_BUILDER(staticQubitsNoMeasure), MQT_NAMED_BUILDER(emptyQCO)}, QCOTestCase{"StaticQubitsWithOps", MQT_NAMED_BUILDER(staticQubitsWithOps), From 2e9f4e67085ecfce32633b75d841561715eb275f Mon Sep 17 00:00:00 2001 From: Damian Rovara <93778306+DRovara@users.noreply.github.com> Date: Mon, 8 Jun 2026 10:57:51 +0200 Subject: [PATCH 24/80] Update mlir/unittests/programs/qco_programs.cpp Co-authored-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com> Signed-off-by: Damian Rovara <93778306+DRovara@users.noreply.github.com> --- mlir/unittests/programs/qco_programs.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 6c5cb9f68e..c120898fc1 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -37,8 +37,8 @@ measureAndReturn(mlir::qco::QCOProgramBuilder& b, namespace mlir::qco { std::pair, SmallVector> -emptyQCO([[maybe_unused]] QCOProgramBuilder& builder) { - return measureAndReturn(builder, {}); +emptyQCO(QCOProgramBuilder& b) { + return measureAndReturn(b, {}); } std::pair, SmallVector> From 29b0cbed1425576c21d0ec0dc985595f3575fec0 Mon Sep 17 00:00:00 2001 From: Damian Rovara <93778306+DRovara@users.noreply.github.com> Date: Mon, 8 Jun 2026 10:58:19 +0200 Subject: [PATCH 25/80] Update mlir/unittests/programs/qco_programs.h Co-authored-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com> Signed-off-by: Damian Rovara <93778306+DRovara@users.noreply.github.com> --- mlir/unittests/programs/qco_programs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/unittests/programs/qco_programs.h b/mlir/unittests/programs/qco_programs.h index c6f8d3b0e4..239d57d799 100644 --- a/mlir/unittests/programs/qco_programs.h +++ b/mlir/unittests/programs/qco_programs.h @@ -10,7 +10,7 @@ #pragma once -#include +#include #include From 225c88f761ce3c3eec9ab82c68ac7663f69a0aed Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Mon, 8 Jun 2026 11:19:51 +0200 Subject: [PATCH 26/80] style(mlir): :recycle: address some review comments --- mlir/include/mlir/Dialect/QCO/QCOUtils.h | 1 - mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp | 2 +- mlir/unittests/programs/qco_programs.h | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/QCOUtils.h b/mlir/include/mlir/Dialect/QCO/QCOUtils.h index b15c8a3752..9d844805a9 100644 --- a/mlir/include/mlir/Dialect/QCO/QCOUtils.h +++ b/mlir/include/mlir/Dialect/QCO/QCOUtils.h @@ -10,7 +10,6 @@ #pragma once -#include #include #include #include diff --git a/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp b/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp index 1e39c1fabf..5d3e811b26 100644 --- a/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp +++ b/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp @@ -72,7 +72,7 @@ void QCOProgramBuilder::initialize(TypeRange returnTypes) { } void QCOProgramBuilder::retype(TypeRange returnTypes) { - auto mainFunc = dyn_cast(module).lookupSymbol("main"); + auto mainFunc = getEntryPoint(mlir::cast(module)); if (!mainFunc) { llvm::reportFatalUsageError("Main function not found for retyping"); } diff --git a/mlir/unittests/programs/qco_programs.h b/mlir/unittests/programs/qco_programs.h index 239d57d799..95b4634633 100644 --- a/mlir/unittests/programs/qco_programs.h +++ b/mlir/unittests/programs/qco_programs.h @@ -10,6 +10,7 @@ #pragma once +#include #include #include From 4c5a22d892b60332990670607e00b35fcf5c02e0 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 11 Jun 2026 16:43:59 +0200 Subject: [PATCH 27/80] refactor(mlir): :recycle: remove old `build` method from QCOProgramBuilder --- .../Dialect/QCO/Builder/QCOProgramBuilder.h | 23 ++++--------------- .../Dialect/QCO/Builder/QCOProgramBuilder.cpp | 9 -------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h b/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h index 380750ba8a..26496473c7 100644 --- a/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h @@ -1413,20 +1413,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { OwningOpRef finalize(ValueRange returnValues); /** - * @brief Convenience method for building quantum programs - * @param context The MLIR context to use for building the program - * @param buildFunc A function that takes a reference to a QCOProgramBuilder - * and uses it to build the desired quantum program. The builder will be - * properly initialized before calling this function, and the resulting module - * will be finalized and returned after this function completes. - * @return The module containing the quantum program built by buildFunc. - */ - static OwningOpRef - build(MLIRContext* context, - const function_ref& buildFunc); - - /** - * @brief Convenience method for building quantum programs with returns. + * @brief Convenience method for building quantum programs. * @param context The MLIR context to use for building the program * @param returnTypes The types of the values to be returned by the program. * @param buildFunc A function that takes a reference to a QCOProgramBuilder @@ -1436,10 +1423,10 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { * completes. * @return The module containing the quantum program built by buildFunc. */ - static OwningOpRef buildWithReturn( - MLIRContext* context, - const function_ref, SmallVector>( - QCOProgramBuilder&)>& buildFunc); + static OwningOpRef + build(MLIRContext* context, + const function_ref, SmallVector>( + QCOProgramBuilder&)>& buildFunc); private: enum class AllocationMode : uint8_t { Unset, Static, Dynamic }; diff --git a/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp b/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp index 5d3e811b26..cd906664cf 100644 --- a/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp +++ b/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp @@ -1176,15 +1176,6 @@ OwningOpRef QCOProgramBuilder::finalize(ValueRange returnValues) { } OwningOpRef QCOProgramBuilder::build( - MLIRContext* context, - const function_ref& buildFunc) { - QCOProgramBuilder builder(context); - builder.initialize(); - buildFunc(builder); - return builder.finalize(); -} - -OwningOpRef QCOProgramBuilder::buildWithReturn( MLIRContext* context, const function_ref, SmallVector>( QCOProgramBuilder&)>& buildFunc) { From fd40b826ffe93b6aaf4e94db33325ad419318e85 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 11 Jun 2026 16:44:54 +0200 Subject: [PATCH 28/80] feat(mlir): :recycle: add return types to `QCProgramBuilder` --- .../Dialect/QC/Builder/QCProgramBuilder.h | 48 +++++++++++++++++-- .../Dialect/QC/Builder/QCProgramBuilder.cpp | 39 +++++++++++---- 2 files changed, 73 insertions(+), 14 deletions(-) diff --git a/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h b/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h index ab9532cfb4..b46cb38029 100644 --- a/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h @@ -70,7 +70,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder { //===--------------------------------------------------------------------===// /** - * @brief Initialize the builder and prepare for program construction + * @brief Initialize the builder and prepare for program construction, with + * a default return type of i64. * * @details * Creates a main function with an entry_point attribute. Must be called @@ -78,6 +79,23 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder { */ void initialize(); + /** + * @brief Initialize the builder and prepare for program construction + * with specified return types. + * @param returnTypes The return types for the main function + * + * @details + * Creates a main function with an entry_point attribute. Must be called + * before adding operations. + */ + void initialize(TypeRange returnTypes); + + /** + * @brief Modify the return types of the main function after initialization. + * @param returnTypes The new return types for the main function + */ + void retype(TypeRange returnTypes); + //===--------------------------------------------------------------------===// // Constants //===--------------------------------------------------------------------===// @@ -1086,17 +1104,39 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder { OwningOpRef finalize(); /** - * @brief Convenience method for building quantum programs + * @brief Finalize the program with a given exit code and return the + * constructed module + * @param returnValues Values representing the exit code to return + * + * @details + * Automatically deallocates all remaining valid qubits and tensors of qubits, + * adds a return statement with a given exit code, + * and transfers ownership of the module to the caller. The builder should not + * be used after calling this method. + * + * The return values must have the types indicated by the function signature + * of the main function, which returns an `i64` by default and can be + * modified by passing different arguments to the `initialize()` method. + * + * @return OwningOpRef containing the constructed quantum program module + */ + OwningOpRef finalize(ValueRange returnValues); + + /** + * @brief Convenience method for building quantum programs with returns. * @param context The MLIR context to use for building the program + * @param returnTypes The types of the values to be returned by the program. * @param buildFunc A function that takes a reference to a QCProgramBuilder * and uses it to build the desired quantum program. The builder will be * properly initialized before calling this function, and the resulting module - * will be finalized and returned after this function completes. + * will be finalized using the returned ValueRange after this function + * completes. * @return The module containing the quantum program built by buildFunc. */ static OwningOpRef build(MLIRContext* context, - const function_ref& buildFunc); + const function_ref, SmallVector>( + QCProgramBuilder&)>& buildFunc); private: enum class AllocationMode : uint8_t { Unset, Static, Dynamic }; diff --git a/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp b/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp index 5eb022c03a..93ef16b2fa 100644 --- a/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp +++ b/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp @@ -12,6 +12,7 @@ #include "mlir/Dialect/QC/IR/QCDialect.h" #include "mlir/Dialect/QC/IR/QCOps.h" +#include "mlir/Dialect/QCO/IR/QCODialect.h" #include "mlir/Dialect/Utils/Utils.h" #include @@ -47,12 +48,14 @@ QCProgramBuilder::QCProgramBuilder(MLIRContext* context) ctx->loadDialect(); } -void QCProgramBuilder::initialize() { +void QCProgramBuilder::initialize() { initialize({getI64Type()}); } + +void QCProgramBuilder::initialize(TypeRange returnTypes) { // Set insertion point to the module body setInsertionPointToStart(cast(module).getBody()); // Create main function as entry point - auto funcType = getFunctionType({}, {getI64Type()}); + auto funcType = getFunctionType({}, returnTypes); auto mainFunc = func::FuncOp::create(*this, "main", funcType); // Add entry_point attribute to identify the main function @@ -65,6 +68,16 @@ void QCProgramBuilder::initialize() { regionStack.emplace_back(entryBlock.getParent()); } +oid QCProgramBuilder::retype(TypeRange returnTypes) { + auto mainFunc = qco::getEntryPoint(mlir::cast(module)); + if (!mainFunc) { + llvm::reportFatalUsageError("Main function not found for retyping"); + } + auto funcType = + getFunctionType(mainFunc.getFunctionType().getInputs(), returnTypes); + mainFunc.setType(funcType); +} + Value QCProgramBuilder::boolConstant(const bool value) { checkFinalized(); return arith::ConstantOp::create(*this, getBoolAttr(value)).getResult(); @@ -637,6 +650,13 @@ void QCProgramBuilder::ensureAllocationMode( OwningOpRef QCProgramBuilder::finalize() { checkFinalized(); + auto exitCode = intConstant(0); + return finalize({exitCode}); +} + +OwningOpRef QCProgramBuilder::finalize(ValueRange returnValues) { + checkFinalized(); + // Ensure that main function exists and insertion point is valid auto* insertionBlock = getInsertionBlock(); func::FuncOp mainFunc = nullptr; @@ -667,11 +687,8 @@ OwningOpRef QCProgramBuilder::finalize() { } allocatedMemrefs.clear(); - // Create constant 0 for successful exit code - auto exitCode = intConstant(0); - - // Add return statement with exit code 0 to the main function - func::ReturnOp::create(*this, exitCode); + // Add return statement with the given return values to the main function + func::ReturnOp::create(*this, returnValues); // Invalidate context to prevent use-after-finalize ctx = nullptr; @@ -682,11 +699,13 @@ OwningOpRef QCProgramBuilder::finalize() { OwningOpRef QCProgramBuilder::build( MLIRContext* context, - const function_ref& buildFunc) { + const function_ref, SmallVector>( + QCProgramBuilder&)>& buildFunc) { QCProgramBuilder builder(context); builder.initialize(); - buildFunc(builder); - return builder.finalize(); + auto [result, resultTypes] = buildFunc(builder); + builder.retype(resultTypes); + return builder.finalize(result); } } // namespace mlir::qc From e2ac1312be13ffa346fbcd8a8e846e24d8b62150 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 11 Jun 2026 17:17:23 +0200 Subject: [PATCH 29/80] feat(mlir): :recycle: update test programs for QC to also return return types --- .../Dialect/QC/Builder/QCProgramBuilder.h | 2 +- .../Dialect/QC/Builder/QCProgramBuilder.cpp | 2 +- .../Compiler/test_compiler_pipeline.cpp | 14 +- mlir/unittests/programs/qc_programs.cpp | 1041 ++++++++++++----- mlir/unittests/programs/qc_programs.h | 734 ++++++++---- 5 files changed, 1265 insertions(+), 528 deletions(-) diff --git a/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h b/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h index b46cb38029..b1735d6246 100644 --- a/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h @@ -1123,7 +1123,7 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder { OwningOpRef finalize(ValueRange returnValues); /** - * @brief Convenience method for building quantum programs with returns. + * @brief Convenience method for building quantum programs. * @param context The MLIR context to use for building the program * @param returnTypes The types of the values to be returned by the program. * @param buildFunc A function that takes a reference to a QCProgramBuilder diff --git a/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp b/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp index 93ef16b2fa..b46a49a410 100644 --- a/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp +++ b/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp @@ -68,7 +68,7 @@ void QCProgramBuilder::initialize(TypeRange returnTypes) { regionStack.emplace_back(entryBlock.getParent()); } -oid QCProgramBuilder::retype(TypeRange returnTypes) { +void QCProgramBuilder::retype(TypeRange returnTypes) { auto mainFunc = qco::getEntryPoint(mlir::cast(module)); if (!mainFunc) { llvm::reportFatalUsageError("Main function not found for retyping"); diff --git a/mlir/unittests/Compiler/test_compiler_pipeline.cpp b/mlir/unittests/Compiler/test_compiler_pipeline.cpp index 44618eedae..383fa7e9d6 100644 --- a/mlir/unittests/Compiler/test_compiler_pipeline.cpp +++ b/mlir/unittests/Compiler/test_compiler_pipeline.cpp @@ -207,10 +207,15 @@ TEST_P(CompilerPipelineTest, EndToEndPipeline) { */ TEST_F(CompilerPipelineTest, RotationGateMergingPass) { auto module = mlir::qc::QCProgramBuilder::build( - context.get(), [&](mlir::qc::QCProgramBuilder& b) { + context.get(), + [&](mlir::qc::QCProgramBuilder& b) + -> std::pair, + mlir::SmallVector> { auto q = b.allocQubit(); b.rz(1.0, q); b.rx(1.0, q); + auto m = b.measure(q); + return {{m}, {b.getI1Type()}}; }); ASSERT_TRUE(module); @@ -230,10 +235,15 @@ TEST_F(CompilerPipelineTest, RotationGateMergingPass) { */ TEST_F(CompilerPipelineTest, HadamardLiftingPass) { auto module = mlir::qc::QCProgramBuilder::build( - context.get(), [&](mlir::qc::QCProgramBuilder& b) { + context.get(), + [&](mlir::qc::QCProgramBuilder& b) + -> std::pair, + mlir::SmallVector> { auto q = b.allocQubit(); b.x(q); b.h(q); + auto m = b.measure(q); + return {{m}, {b.getI1Type()}}; }); ASSERT_TRUE(module); diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index 373452252a..f0f6bfe698 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -12,60 +12,110 @@ #include "mlir/Dialect/QC/Builder/QCProgramBuilder.h" +#include +#include +#include +#include + #include +#include +#include + +static std::pair, mlir::SmallVector> +measureAndReturn(mlir::qc::QCProgramBuilder& b, + mlir::SmallVector qubits) { + mlir::SmallVector bits; + mlir::SmallVector bitTypes; + auto i1Type = b.getI1Type(); + for (const auto& q : qubits) { + bits.push_back(b.measure(q)); + bitTypes.push_back(i1Type); + } + return {bits, bitTypes}; +} namespace mlir::qc { -void emptyQC([[maybe_unused]] QCProgramBuilder& builder) {} +std::pair, SmallVector> +emptyQC([[maybe_unused]] QCProgramBuilder& builder) { + return measureAndReturn(builder, {}); +} -void allocQubit(QCProgramBuilder& b) { b.allocQubit(); } +std::pair, SmallVector> +allocQubit(QCProgramBuilder& b) { + auto q = b.allocQubit(); + return measureAndReturn(b, {q}); +} -void allocQubitRegister(QCProgramBuilder& b) { b.allocQubitRegister(2); } +std::pair, SmallVector> +allocQubitRegister(QCProgramBuilder& b) { + auto q = b.allocQubitRegister(2); + return measureAndReturn(b, {q[0], q[1]}); +} -void allocMultipleQubitRegisters(QCProgramBuilder& b) { - b.allocQubitRegister(2); - b.allocQubitRegister(3); +std::pair, SmallVector> +allocMultipleQubitRegisters(QCProgramBuilder& b) { + auto q0 = b.allocQubitRegister(2); + auto q1 = b.allocQubitRegister(3); + return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}); } -void allocLargeRegister(QCProgramBuilder& b) { b.allocQubitRegister(100); } +std::pair, SmallVector> +allocLargeRegister(QCProgramBuilder& b) { + auto q = b.allocQubitRegister(100); + return measureAndReturn(b, {q[0], q[99]}); +} -void staticQubits(QCProgramBuilder& b) { - b.staticQubit(0); - b.staticQubit(1); +std::pair, SmallVector> +staticQubits(QCProgramBuilder& b) { + auto q0 = b.staticQubit(0); + auto q1 = b.staticQubit(1); + return measureAndReturn(b, {q0, q1}); } -void staticQubitsWithOps(QCProgramBuilder& b) { +std::pair, SmallVector> +staticQubitsWithOps(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.h(q0); b.h(q1); + return measureAndReturn(b, {q0, q1}); } -void staticQubitsWithParametricOps(QCProgramBuilder& b) { +std::pair, SmallVector> +staticQubitsWithParametricOps(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.rx(std::numbers::pi / 4., q0); b.p(std::numbers::pi / 2., q1); + return measureAndReturn(b, {q0, q1}); } -void staticQubitsWithTwoTargetOps(QCProgramBuilder& b) { +std::pair, SmallVector> +staticQubitsWithTwoTargetOps(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.rzz(0.123, q0, q1); + return measureAndReturn(b, {q0, q1}); } -void staticQubitsWithCtrl(QCProgramBuilder& b) { +std::pair, SmallVector> +staticQubitsWithCtrl(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.cx(q0, q1); + return measureAndReturn(b, {q0, q1}); } -void staticQubitsWithInv(QCProgramBuilder& b) { +std::pair, SmallVector> +staticQubitsWithInv(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); b.inv([&]() { b.t(q0); }); + return measureAndReturn(b, {q0}); } -void staticQubitsWithDuplicates(QCProgramBuilder& b) { +std::pair, SmallVector> +staticQubitsWithDuplicates(QCProgramBuilder& b) { const auto q0a = b.staticQubit(0); const auto q1a = b.staticQubit(1); const auto q0b = b.staticQubit(0); @@ -76,9 +126,11 @@ void staticQubitsWithDuplicates(QCProgramBuilder& b) { b.rzz(0.123, q0b, q1b); b.cx(q0b, q1b); b.inv([&]() { b.t(q0a); }); + return measureAndReturn(b, {q0b, q1b}); } -void staticQubitsCanonical(QCProgramBuilder& b) { +std::pair, SmallVector> +staticQubitsCanonical(QCProgramBuilder& b) { const auto q0 = b.staticQubit(0); const auto q1 = b.staticQubit(1); @@ -87,1223 +139,1663 @@ void staticQubitsCanonical(QCProgramBuilder& b) { b.rzz(0.123, q0, q1); b.cx(q0, q1); b.inv([&]() { b.t(q0); }); + return measureAndReturn(b, {q0, q1}); } -void allocDeallocPair(QCProgramBuilder& b) { +std::pair, SmallVector> +allocDeallocPair(QCProgramBuilder& b) { auto q = b.allocQubit(); b.dealloc(q); + return measureAndReturn(b, {}); } -void mixedStaticThenDynamicQubit(QCProgramBuilder& b) { - b.staticQubit(0); - b.allocQubit(); +std::pair, SmallVector> +mixedStaticThenDynamicQubit(QCProgramBuilder& b) { + auto q0 = b.staticQubit(0); + auto q1 = b.allocQubit(); + return measureAndReturn(b, {q0, q1}); } -void mixedDynamicRegisterThenStaticQubit(QCProgramBuilder& b) { - b.allocQubitRegister(2); - b.staticQubit(0); +std::pair, SmallVector> +mixedDynamicRegisterThenStaticQubit(QCProgramBuilder& b) { + auto q0 = b.allocQubitRegister(2); + auto q1 = b.staticQubit(0); + return measureAndReturn(b, {q0[0], q0[1], q1}); } -void singleMeasurementToSingleBit(QCProgramBuilder& b) { +std::pair, SmallVector> +singleMeasurementToSingleBit(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); b.measure(q[0], c[0]); + return measureAndReturn(b, {q[0]}); } -void repeatedMeasurementToSameBit(QCProgramBuilder& b) { +std::pair, SmallVector> +repeatedMeasurementToSameBit(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); b.measure(q[0], c[0]); b.measure(q[0], c[0]); b.measure(q[0], c[0]); + return measureAndReturn(b, {q[0]}); } -void repeatedMeasurementToDifferentBits(QCProgramBuilder& b) { +std::pair, SmallVector> +repeatedMeasurementToDifferentBits(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(3); b.measure(q[0], c[0]); b.measure(q[0], c[1]); b.measure(q[0], c[2]); + return measureAndReturn(b, {q[0]}); } -void multipleClassicalRegistersAndMeasurements(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleClassicalRegistersAndMeasurements(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); const auto& c0 = b.allocClassicalBitRegister(1, "c0"); const auto& c1 = b.allocClassicalBitRegister(2, "c1"); b.measure(q[0], c0[0]); b.measure(q[1], c1[0]); b.measure(q[2], c1[1]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void measurementWithoutRegisters(QCProgramBuilder& b) { +std::pair, SmallVector> +measurementWithoutRegisters(QCProgramBuilder& b) { auto q = b.allocQubit(); b.measure(q); + return measureAndReturn(b, {q}); } -void resetQubitWithoutOp(QCProgramBuilder& b) { +std::pair, SmallVector> +resetQubitWithoutOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); + return measureAndReturn(b, {q[0]}); } -void resetMultipleQubitsWithoutOp(QCProgramBuilder& b) { +std::pair, SmallVector> +resetMultipleQubitsWithoutOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.reset(q[0]); b.reset(q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void repeatedResetWithoutOp(QCProgramBuilder& b) { +std::pair, SmallVector> +repeatedResetWithoutOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); + return measureAndReturn(b, {q[0]}); } -void resetQubitAfterSingleOp(QCProgramBuilder& b) { +std::pair, SmallVector> +resetQubitAfterSingleOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); + return measureAndReturn(b, {q[0]}); } -void resetMultipleQubitsAfterSingleOp(QCProgramBuilder& b) { +std::pair, SmallVector> +resetMultipleQubitsAfterSingleOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.h(q[0]); b.reset(q[0]); b.h(q[1]); b.reset(q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void repeatedResetAfterSingleOp(QCProgramBuilder& b) { +std::pair, SmallVector> +repeatedResetAfterSingleOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); + return measureAndReturn(b, {q[0]}); } -void globalPhase(QCProgramBuilder& b) { b.gphase(0.123); } +std::pair, SmallVector> +globalPhase(QCProgramBuilder& b) { + b.gphase(0.123); + return measureAndReturn(b, {}); +} -void singleControlledGlobalPhase(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.cgphase(0.123, q[0]); + return measureAndReturn(b, {q[0]}); } -void multipleControlledGlobalPhase(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcgphase(0.123, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledGlobalPhase(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.ctrl(q[0], [&] { b.cgphase(0.123, q[1]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void trivialControlledGlobalPhase(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcgphase(0.123, {}); + return measureAndReturn(b, {q[0]}); } -void inverseGlobalPhase(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseGlobalPhase(QCProgramBuilder& b) { b.inv([&]() { b.gphase(-0.123); }); + return measureAndReturn(b, {}); } -void inverseMultipleControlledGlobalPhase(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcgphase(-0.123, {q[0], q[1], q[2]}); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void identity(QCProgramBuilder& b) { +std::pair, SmallVector> identity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.id(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledIdentity(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cid(q[1], q[0]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledIdentity(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcid({q[2], q[1]}, q[0]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledIdentity(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.ctrl(q[2], [&] { b.cid(q[1], q[0]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void trivialControlledIdentity(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcid({}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseIdentity(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.id(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledIdentity(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcid({q[2], q[1]}, q[0]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void x(QCProgramBuilder& b) { +std::pair, SmallVector> x(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.x(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledX(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledX(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cx(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledX(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledX(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcx({q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledX(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledX(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.cx(reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledX(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledX(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcx({}, q[0]); + return measureAndReturn(b, {q[0]}); } -void repeatedControlledX(QCProgramBuilder& b) { +std::pair, SmallVector> +repeatedControlledX(QCProgramBuilder& b) { auto control = b.allocQubit(); b.h(control); + mlir::SmallVector qubits = {control}; for (auto i = 0; i < 50; i++) { auto qubit = b.allocQubit(); b.cx(control, qubit); + qubits.push_back(qubit); } + return measureAndReturn(b, qubits); } -void inverseX(QCProgramBuilder& b) { +std::pair, SmallVector> inverseX(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.x(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledX(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledX(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcx({q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void y(QCProgramBuilder& b) { +std::pair, SmallVector> y(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.y(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledY(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cy(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledY(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcy({q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledY(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledY(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.cy(reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledY(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcy({}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseY(QCProgramBuilder& b) { +std::pair, SmallVector> inverseY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.y(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledY(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcy({q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void z(QCProgramBuilder& b) { +std::pair, SmallVector> z(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.z(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledZ(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledZ(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cz(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledZ(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledZ(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcz({q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledZ(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledZ(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.cz(reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledZ(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledZ(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcz({}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseZ(QCProgramBuilder& b) { +std::pair, SmallVector> inverseZ(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.z(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledZ(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledZ(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcz({q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void h(QCProgramBuilder& b) { +std::pair, SmallVector> h(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledH(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledH(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ch(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledH(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledH(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mch({q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledH(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledH(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.ch(reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledH(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledH(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mch({}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseH(QCProgramBuilder& b) { +std::pair, SmallVector> inverseH(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.h(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledH(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledH(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mch({q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void hWithoutRegister(QCProgramBuilder& b) { +std::pair, SmallVector> +hWithoutRegister(QCProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); + return measureAndReturn(b, {q}); } -void s(QCProgramBuilder& b) { +std::pair, SmallVector> s(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.s(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledS(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledS(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cs(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledS(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledS(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcs({q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledS(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledS(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.cs(reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledS(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledS(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcs({}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseS(QCProgramBuilder& b) { +std::pair, SmallVector> inverseS(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.s(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledS(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledS(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcs({q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void sdg(QCProgramBuilder& b) { +std::pair, SmallVector> sdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sdg(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledSdg(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledSdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csdg(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledSdg(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledSdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsdg({q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledSdg(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledSdg(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.csdg(reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledSdg(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledSdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcsdg({}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseSdg(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseSdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.sdg(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledSdg(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledSdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcsdg({q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void t_(QCProgramBuilder& b) { +std::pair, SmallVector> t_(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.t(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledT(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledT(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ct(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledT(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledT(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mct({q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledT(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledT(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.ct(reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledT(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledT(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mct({}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseT(QCProgramBuilder& b) { +std::pair, SmallVector> inverseT(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.t(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledT(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledT(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mct({q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void tdg(QCProgramBuilder& b) { +std::pair, SmallVector> tdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.tdg(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledTdg(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledTdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ctdg(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledTdg(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledTdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mctdg({q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledTdg(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledTdg(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.ctdg(reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledTdg(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledTdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mctdg({}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseTdg(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseTdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.tdg(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledTdg(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledTdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mctdg({q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void sx(QCProgramBuilder& b) { +std::pair, SmallVector> sx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sx(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledSx(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledSx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csx(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledSx(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledSx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsx({q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledSx(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledSx(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.csx(reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledSx(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledSx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcsx({}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseSx(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseSx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.sx(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledSx(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledSx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcsx({q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void sxdg(QCProgramBuilder& b) { +std::pair, SmallVector> sxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sxdg(q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledSxdg(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledSxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csxdg(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledSxdg(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledSxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsxdg({q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledSxdg(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledSxdg(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.csxdg(reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledSxdg(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledSxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcsxdg({}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseSxdg(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseSxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.sxdg(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledSxdg(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledSxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcsxdg({q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void rx(QCProgramBuilder& b) { +std::pair, SmallVector> rx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rx(0.123, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledRx(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.crx(0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledRx(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcrx(0.123, {q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledRx(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRx(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.crx(0.123, reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledRx(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcrx(0.123, {}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseRx(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseRx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.rx(-0.123, q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledRx(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcrx(-0.123, {q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void ry(QCProgramBuilder& b) { +std::pair, SmallVector> ry(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.ry(0.456, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledRy(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cry(0.456, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledRy(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcry(0.456, {q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledRy(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRy(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.cry(0.456, reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledRy(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcry(0.456, {}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseRy(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseRy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.ry(-0.456, q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledRy(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcry(-0.456, {q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void rz(QCProgramBuilder& b) { +std::pair, SmallVector> rz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rz(0.789, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledRz(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.crz(0.789, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledRz(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcrz(0.789, {q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledRz(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRz(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.crz(0.789, reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledRz(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcrz(0.789, {}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseRz(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseRz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.rz(-0.789, q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledRz(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcrz(-0.789, {q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void p(QCProgramBuilder& b) { +std::pair, SmallVector> p(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.p(0.123, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledP(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledP(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cp(0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledP(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledP(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcp(0.123, {q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledP(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledP(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.cp(0.123, reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledP(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledP(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcp(0.123, {}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseP(QCProgramBuilder& b) { +std::pair, SmallVector> inverseP(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.p(-0.123, q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledP(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledP(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcp(-0.123, {q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void r(QCProgramBuilder& b) { +std::pair, SmallVector> r(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.r(0.123, 0.456, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledR(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledR(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cr(0.123, 0.456, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledR(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledR(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcr(0.123, 0.456, {q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledR(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledR(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.cr(0.123, 0.456, reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledR(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledR(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcr(0.123, 0.456, {}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseR(QCProgramBuilder& b) { +std::pair, SmallVector> inverseR(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.r(-0.123, 0.456, q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledR(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledR(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcr(-0.123, 0.456, {q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void u2(QCProgramBuilder& b) { +std::pair, SmallVector> u2(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u2(0.234, 0.567, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledU2(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledU2(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cu2(0.234, 0.567, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledU2(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledU2(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcu2(0.234, 0.567, {q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledU2(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledU2(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.cu2(0.234, 0.567, reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledU2(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledU2(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcu2(0.234, 0.567, {}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseU2(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseU2(QCProgramBuilder& b) { constexpr double pi = std::numbers::pi; auto q = b.allocQubitRegister(1); b.inv([&]() { b.u2(-0.567 + pi, -0.234 - pi, q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledU2(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledU2(QCProgramBuilder& b) { constexpr double pi = std::numbers::pi; auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcu2(-0.567 + pi, -0.234 - pi, {q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void u(QCProgramBuilder& b) { +std::pair, SmallVector> u(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u(0.1, 0.2, 0.3, q[0]); + return measureAndReturn(b, {q[0]}); } -void singleControlledU(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledU(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cu(0.1, 0.2, 0.3, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void multipleControlledU(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledU(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcu(0.1, 0.2, 0.3, {q[0], q[1]}, q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void nestedControlledU(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledU(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], [&] { b.cu(0.1, 0.2, 0.3, reg[1], reg[2]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2]}); } -void trivialControlledU(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledU(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcu(0.1, 0.2, 0.3, {}, q[0]); + return measureAndReturn(b, {q[0]}); } -void inverseU(QCProgramBuilder& b) { +std::pair, SmallVector> inverseU(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.u(-0.1, -0.3, -0.2, q[0]); }); + return measureAndReturn(b, {q[0]}); } -void inverseMultipleControlledU(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledU(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.mcu(-0.1, -0.3, -0.2, {q[0], q[1]}, q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void swap(QCProgramBuilder& b) { +std::pair, SmallVector> swap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.swap(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledSwap(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledSwap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cswap(q[0], q[1], q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledSwap(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledSwap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcswap({q[0], q[1]}, q[2], q[3]); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledSwap(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledSwap(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], [&] { b.cswap(reg[1], reg[2], reg[3]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledSwap(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledSwap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcswap({}, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseSwap(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseSwap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv([&]() { b.swap(q[0], q[1]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledSwap(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledSwap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv([&]() { b.mcswap({q[0], q[1]}, q[2], q[3]); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void iswap(QCProgramBuilder& b) { +std::pair, SmallVector> iswap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.iswap(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledIswap(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledIswap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.ciswap(q[0], q[1], q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledIswap(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledIswap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mciswap({q[0], q[1]}, q[2], q[3]); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledIswap(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledIswap(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], [&] { b.ciswap(reg[1], reg[2], reg[3]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledIswap(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledIswap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mciswap({}, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseIswap(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseIswap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv([&]() { b.iswap(q[0], q[1]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledIswap(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledIswap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv([&]() { b.mciswap({q[0], q[1]}, q[2], q[3]); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void dcx(QCProgramBuilder& b) { +std::pair, SmallVector> dcx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.dcx(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledDcx(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledDcx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cdcx(q[0], q[1], q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledDcx(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledDcx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcdcx({q[0], q[1]}, q[2], q[3]); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledDcx(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledDcx(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], [&] { b.cdcx(reg[1], reg[2], reg[3]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledDcx(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledDcx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcdcx({}, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseDcx(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseDcx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv([&]() { b.dcx(q[1], q[0]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledDcx(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledDcx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv([&]() { b.mcdcx({q[0], q[1]}, q[3], q[2]); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void ecr(QCProgramBuilder& b) { +std::pair, SmallVector> ecr(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ecr(q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledEcr(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledEcr(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cecr(q[0], q[1], q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledEcr(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledEcr(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcecr({q[0], q[1]}, q[2], q[3]); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledEcr(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledEcr(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], [&] { b.cecr(reg[1], reg[2], reg[3]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledEcr(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledEcr(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcecr({}, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseEcr(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseEcr(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv([&]() { b.ecr(q[0], q[1]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledEcr(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledEcr(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv([&]() { b.mcecr({q[0], q[1]}, q[2], q[3]); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void rxx(QCProgramBuilder& b) { +std::pair, SmallVector> rxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rxx(0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledRxx(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crxx(0.123, q[0], q[1], q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledRxx(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledRxx(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRxx(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], [&] { b.crxx(0.123, reg[1], reg[2], reg[3]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledRxx(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcrxx(0.123, {}, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseRxx(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv([&]() { b.rxx(-0.123, q[0], q[1]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledRxx(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv([&]() { b.mcrxx(-0.123, {q[0], q[1]}, q[2], q[3]); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void tripleControlledRxx(QCProgramBuilder& b) { +std::pair, SmallVector> +tripleControlledRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(5); b.mcrxx(0.123, {q[0], q[1], q[2]}, q[3], q[4]); + return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4]}); } -void fourControlledRxx(QCProgramBuilder& b) { + +std::pair, SmallVector> +fourControlledRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(6); b.mcrxx(0.123, {q[0], q[1], q[2], q[3]}, q[4], q[5]); + return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4], q[5]}); } -void ryy(QCProgramBuilder& b) { +std::pair, SmallVector> ryy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ryy(0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledRyy(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRyy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cryy(0.123, q[0], q[1], q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledRyy(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRyy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcryy(0.123, {q[0], q[1]}, q[2], q[3]); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledRyy(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRyy(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], [&] { b.cryy(0.123, reg[1], reg[2], reg[3]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledRyy(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRyy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcryy(0.123, {}, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseRyy(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseRyy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv([&]() { b.ryy(-0.123, q[0], q[1]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledRyy(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRyy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv([&]() { b.mcryy(-0.123, {q[0], q[1]}, q[2], q[3]); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void rzx(QCProgramBuilder& b) { +std::pair, SmallVector> rzx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rzx(0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledRzx(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRzx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crzx(0.123, q[0], q[1], q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledRzx(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRzx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrzx(0.123, {q[0], q[1]}, q[2], q[3]); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledRzx(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRzx(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], [&] { b.crzx(0.123, reg[1], reg[2], reg[3]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledRzx(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRzx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcrzx(0.123, {}, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseRzx(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseRzx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv([&]() { b.rzx(-0.123, q[0], q[1]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledRzx(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRzx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv([&]() { b.mcrzx(-0.123, {q[0], q[1]}, q[2], q[3]); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void rzz(QCProgramBuilder& b) { +std::pair, SmallVector> rzz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rzz(0.123, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledRzz(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledRzz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crzz(0.123, q[0], q[1], q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledRzz(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledRzz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrzz(0.123, {q[0], q[1]}, q[2], q[3]); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledRzz(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledRzz(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], [&] { b.crzz(0.123, reg[1], reg[2], reg[3]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledRzz(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledRzz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcrzz(0.123, {}, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseRzz(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseRzz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv([&]() { b.rzz(-0.123, q[0], q[1]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledRzz(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledRzz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv([&]() { b.mcrzz(-0.123, {q[0], q[1]}, q[2], q[3]); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void xxPlusYY(QCProgramBuilder& b) { +std::pair, SmallVector> xxPlusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.xx_plus_yy(0.123, 0.456, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledXxPlusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledXxPlusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cxx_plus_yy(0.123, 0.456, q[0], q[1], q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledXxPlusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledXxPlusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcxx_plus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledXxPlusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledXxPlusYY(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], [&] { b.cxx_plus_yy(0.123, 0.456, reg[1], reg[2], reg[3]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledXxPlusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledXxPlusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcxx_plus_yy(0.123, 0.456, {}, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseXxPlusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseXxPlusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv([&]() { b.xx_plus_yy(-0.123, 0.456, q[0], q[1]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledXxPlusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledXxPlusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv([&]() { b.mcxx_plus_yy(-0.123, 0.456, {q[0], q[1]}, q[2], q[3]); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void xxMinusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +xxMinusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.xx_minus_yy(0.123, 0.456, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void singleControlledXxMinusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledXxMinusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cxx_minus_yy(0.123, 0.456, q[0], q[1], q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void multipleControlledXxMinusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +multipleControlledXxMinusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcxx_minus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedControlledXxMinusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedControlledXxMinusYY(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], [&] { b.cxx_minus_yy(0.123, 0.456, reg[1], reg[2], reg[3]); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -void trivialControlledXxMinusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialControlledXxMinusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcxx_minus_yy(0.123, 0.456, {}, q[0], q[1]); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseXxMinusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseXxMinusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv([&]() { b.xx_minus_yy(-0.123, 0.456, q[0], q[1]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseMultipleControlledXxMinusYY(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseMultipleControlledXxMinusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv([&]() { b.mcxx_minus_yy(-0.123, 0.456, {q[0], q[1]}, q[2], q[3]); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void barrier(QCProgramBuilder& b) { +std::pair, SmallVector> barrier(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.barrier(q[0]); + return measureAndReturn(b, {q[0]}); } -void barrierTwoQubits(QCProgramBuilder& b) { +std::pair, SmallVector> +barrierTwoQubits(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.barrier({q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}); } -void barrierMultipleQubits(QCProgramBuilder& b) { +std::pair, SmallVector> +barrierMultipleQubits(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.barrier({q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void singleControlledBarrier(QCProgramBuilder& b) { +std::pair, SmallVector> +singleControlledBarrier(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ctrl(q[1], [&] { b.barrier(q[0]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void inverseBarrier(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseBarrier(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv([&]() { b.barrier(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void trivialCtrl(QCProgramBuilder& b) { +std::pair, SmallVector> +trivialCtrl(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ctrl({}, [&]() { b.rxx(0.123, q[0], q[1]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void nestedCtrl(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedCtrl(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.ctrl(q[0], [&]() { b.ctrl(q[1], [&]() { b.rxx(0.123, q[2], q[3]); }); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void tripleNestedCtrl(QCProgramBuilder& b) { +std::pair, SmallVector> +tripleNestedCtrl(QCProgramBuilder& b) { auto q = b.allocQubitRegister(5); b.ctrl(q[0], [&]() { b.ctrl(q[1], [&]() { b.ctrl(q[2], [&]() { b.rxx(0.123, q[3], q[4]); }); }); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4]}); } -void doubleNestedCtrlTwoQubits(QCProgramBuilder& b) { +std::pair, SmallVector> +doubleNestedCtrlTwoQubits(QCProgramBuilder& b) { auto q = b.allocQubitRegister(6); b.ctrl({q[0], q[1]}, [&]() { b.ctrl({q[2], q[3]}, [&]() { b.rxx(0.123, q[4], q[5]); }); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4], q[5]}); } -void ctrlInvSandwich(QCProgramBuilder& b) { +std::pair, SmallVector> +ctrlInvSandwich(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.ctrl(q[0], [&]() { b.inv([&]() { b.ctrl(q[1], [&]() { b.rxx(-0.123, q[2], q[3]); }); }); }); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -void nestedInv(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedInv(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv([&]() { b.inv([&]() { b.rxx(0.123, q[0], q[1]); }); }); + return measureAndReturn(b, {q[0], q[1]}); } -void tripleNestedInv(QCProgramBuilder& b) { +std::pair, SmallVector> +tripleNestedInv(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv( [&]() { b.inv([&]() { b.inv([&]() { b.rxx(-0.123, q[0], q[1]); }); }); }); + return measureAndReturn(b, {q[0], q[1]}); } -void invCtrlSandwich(QCProgramBuilder& b) { +std::pair, SmallVector> +invCtrlSandwich(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv([&]() { b.ctrl(q[0], [&]() { b.inv([&]() { b.rxx(0.123, q[1], q[2]); }); }); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } -void simpleIf(QCProgramBuilder& b) { +std::pair, SmallVector> simpleIf(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); auto cond = b.measure(q[0]); b.scfIf(cond, [&] { b.x(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void ifElse(QCProgramBuilder& b) { +std::pair, SmallVector> ifElse(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); auto cond = b.measure(q[0]); b.scfIf(cond, [&] { b.x(q[0]); }, [&] { b.z(q[0]); }); + return measureAndReturn(b, {q[0]}); } -void ifTwoQubits(QCProgramBuilder& b) { +std::pair, SmallVector> +ifTwoQubits(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.h(q[0]); auto cond = b.measure(q[0]); @@ -1311,9 +1803,11 @@ void ifTwoQubits(QCProgramBuilder& b) { b.x(q[0]); b.x(q[1]); }); + return measureAndReturn(b, {q[0], q[1]}); } -void nestedIfOpForLoop(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedIfOpForLoop(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); b.h(q0); @@ -1326,9 +1820,11 @@ void nestedIfOpForLoop(QCProgramBuilder& b) { b.h(q1); }); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], q0}); } -void simpleWhileReset(QCProgramBuilder& b) { +std::pair, SmallVector> +simpleWhileReset(QCProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); b.scfWhile( @@ -1337,9 +1833,11 @@ void simpleWhileReset(QCProgramBuilder& b) { b.scfCondition(measureResult); }, [&] { b.h(q); }); + return measureAndReturn(b, {q}); } -void simpleDoWhileReset(QCProgramBuilder& b) { +std::pair, SmallVector> +simpleDoWhileReset(QCProgramBuilder& b) { auto q = b.allocQubit(); b.scfWhile( [&] { @@ -1348,17 +1846,21 @@ void simpleDoWhileReset(QCProgramBuilder& b) { b.scfCondition(measureResult); }, [&] {}); + return measureAndReturn(b, {q}); } -void simpleForLoop(QCProgramBuilder& b) { +std::pair, SmallVector> +simpleForLoop(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(2); b.scfFor(0, 2, 1, [&](Value iv) { auto q = b.memrefLoad(reg.value, iv); b.h(q); }); + return measureAndReturn(b, {reg[0], reg[1]}); }; -void nestedForLoopIfOp(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedForLoopIfOp(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto qCond = b.allocQubit(); b.scfFor(0, 2, 1, [&](Value iv) { @@ -1369,9 +1871,11 @@ void nestedForLoopIfOp(QCProgramBuilder& b) { b.h(q); }); }); + return measureAndReturn(b, {reg[0], reg[1], qCond}); } -void nestedForLoopWhileOp(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedForLoopWhileOp(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(2); b.scfFor(0, 2, 1, [&](Value iv) { auto q = b.memrefLoad(reg.value, iv); @@ -1386,9 +1890,11 @@ void nestedForLoopWhileOp(QCProgramBuilder& b) { }, [&] { b.h(q); }); }); + return measureAndReturn(b, {reg[0], reg[1]}); } -void nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto control = b.allocQubit(); b.h(control); @@ -1397,9 +1903,11 @@ void nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b) { b.h(q0); b.ctrl(control, [&] { b.x(q0); }); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], control}); } -void nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b) { +std::pair, SmallVector> +nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.h(reg[0]); b.scfFor(1, 4, 1, [&](Value iv) { @@ -1407,6 +1915,7 @@ void nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b) { b.h(q0); b.ctrl(reg[0], [&] { b.x(q0); }); }); + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } } // namespace mlir::qc diff --git a/mlir/unittests/programs/qc_programs.h b/mlir/unittests/programs/qc_programs.h index e6569f7648..ae4bc4858b 100644 --- a/mlir/unittests/programs/qc_programs.h +++ b/mlir/unittests/programs/qc_programs.h @@ -10,876 +10,1094 @@ #pragma once +#include +#include + +#include + namespace mlir::qc { class QCProgramBuilder; /// Creates an empty QC Program. -void emptyQC(QCProgramBuilder& builder); +std::pair, SmallVector> +emptyQC(QCProgramBuilder& builder); // --- Qubit Management ----------------------------------------------------- // /// Allocates a single qubit. -void allocQubit(QCProgramBuilder& b); +std::pair, SmallVector> +allocQubit(QCProgramBuilder& b); /// Allocates a qubit register of size `2`. -void allocQubitRegister(QCProgramBuilder& b); +std::pair, SmallVector> +allocQubitRegister(QCProgramBuilder& b); /// Allocates two qubit registers of size `2` and `3`. -void allocMultipleQubitRegisters(QCProgramBuilder& b); +std::pair, SmallVector> +allocMultipleQubitRegisters(QCProgramBuilder& b); /// Allocates a large qubit register. -void allocLargeRegister(QCProgramBuilder& b); +std::pair, SmallVector> +allocLargeRegister(QCProgramBuilder& b); /// Allocates two inline qubits. -void staticQubits(QCProgramBuilder& b); +std::pair, SmallVector> +staticQubits(QCProgramBuilder& b); /// Allocates two static qubits and applies operations. -void staticQubitsWithOps(QCProgramBuilder& b); +std::pair, SmallVector> +staticQubitsWithOps(QCProgramBuilder& b); /// Allocates two static qubits and applies parametric gates. -void staticQubitsWithParametricOps(QCProgramBuilder& b); +std::pair, SmallVector> +staticQubitsWithParametricOps(QCProgramBuilder& b); /// Allocates two static qubits and applies a two-target gate. -void staticQubitsWithTwoTargetOps(QCProgramBuilder& b); +std::pair, SmallVector> +staticQubitsWithTwoTargetOps(QCProgramBuilder& b); /// Allocates two static qubits and applies a controlled gate. -void staticQubitsWithCtrl(QCProgramBuilder& b); +std::pair, SmallVector> +staticQubitsWithCtrl(QCProgramBuilder& b); /// Allocates a static qubit and applies an inverse modifier. -void staticQubitsWithInv(QCProgramBuilder& b); +std::pair, SmallVector> +staticQubitsWithInv(QCProgramBuilder& b); /// Allocates duplicate static qubits and applies operations on both. -void staticQubitsWithDuplicates(QCProgramBuilder& b); +std::pair, SmallVector> +staticQubitsWithDuplicates(QCProgramBuilder& b); /// Same as `staticQubitsWithDuplicates`, but with canonical static qubit /// retrievals. -void staticQubitsCanonical(QCProgramBuilder& b); +std::pair, SmallVector> +staticQubitsCanonical(QCProgramBuilder& b); /// Allocates and explicitly deallocates a single qubit. -void allocDeallocPair(QCProgramBuilder& b); +std::pair, SmallVector> +allocDeallocPair(QCProgramBuilder& b); // --- Invalid / mixed addressing (unit tests) -------------------------------- /// @pre `builder.initialize()`. Fatal mixed addressing: static then dynamic /// alloc. -void mixedStaticThenDynamicQubit(QCProgramBuilder& b); +std::pair, SmallVector> +mixedStaticThenDynamicQubit(QCProgramBuilder& b); /// @pre `builder.initialize()`. Fatal mixed addressing: dynamic register then /// static. -void mixedDynamicRegisterThenStaticQubit(QCProgramBuilder& b); +std::pair, SmallVector> +mixedDynamicRegisterThenStaticQubit(QCProgramBuilder& b); // --- MeasureOp ------------------------------------------------------------ // /// Measures a single qubit into a single classical bit. -void singleMeasurementToSingleBit(QCProgramBuilder& b); +std::pair, SmallVector> +singleMeasurementToSingleBit(QCProgramBuilder& b); /// Repeatedly measures a single qubit into the same classical bit. -void repeatedMeasurementToSameBit(QCProgramBuilder& b); +std::pair, SmallVector> +repeatedMeasurementToSameBit(QCProgramBuilder& b); /// Repeatedly measures a single qubit into different classical bits. -void repeatedMeasurementToDifferentBits(QCProgramBuilder& b); +std::pair, SmallVector> +repeatedMeasurementToDifferentBits(QCProgramBuilder& b); /// Measures multiple qubits into multiple classical bits. -void multipleClassicalRegistersAndMeasurements(QCProgramBuilder& b); +std::pair, SmallVector> +multipleClassicalRegistersAndMeasurements(QCProgramBuilder& b); /// Measures a single qubit into a single classical bit, without explicitly /// allocating a quantum or classical register. -void measurementWithoutRegisters(QCProgramBuilder& b); +std::pair, SmallVector> +measurementWithoutRegisters(QCProgramBuilder& b); // --- ResetOp -------------------------------------------------------------- // /// Resets a single qubit without any operations being applied. -void resetQubitWithoutOp(QCProgramBuilder& b); +std::pair, SmallVector> +resetQubitWithoutOp(QCProgramBuilder& b); /// Resets multiple qubits without any operations being applied. -void resetMultipleQubitsWithoutOp(QCProgramBuilder& b); +std::pair, SmallVector> +resetMultipleQubitsWithoutOp(QCProgramBuilder& b); /// Repeatedly resets a single qubit without any operations being applied. -void repeatedResetWithoutOp(QCProgramBuilder& b); +std::pair, SmallVector> +repeatedResetWithoutOp(QCProgramBuilder& b); /// Resets a single qubit after a single operation. -void resetQubitAfterSingleOp(QCProgramBuilder& b); +std::pair, SmallVector> +resetQubitAfterSingleOp(QCProgramBuilder& b); /// Resets multiple qubits after a single operation. -void resetMultipleQubitsAfterSingleOp(QCProgramBuilder& b); +std::pair, SmallVector> +resetMultipleQubitsAfterSingleOp(QCProgramBuilder& b); /// Repeatedly resets a single qubit after a single operation. -void repeatedResetAfterSingleOp(QCProgramBuilder& b); +std::pair, SmallVector> +repeatedResetAfterSingleOp(QCProgramBuilder& b); // --- GPhaseOp ------------------------------------------------------------- // /// Creates a circuit with just a global phase. -void globalPhase(QCProgramBuilder& b); +std::pair, SmallVector> +globalPhase(QCProgramBuilder& b); /// Creates a controlled global phase gate with a single control qubit. -void singleControlledGlobalPhase(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledGlobalPhase(QCProgramBuilder& b); /// Creates a multi-controlled global phase gate with multiple control qubits. -void multipleControlledGlobalPhase(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledGlobalPhase(QCProgramBuilder& b); /// Creates a circuit with a nested controlled global phase gate. -void nestedControlledGlobalPhase(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledGlobalPhase(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled global phase gate. -void trivialControlledGlobalPhase(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledGlobalPhase(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a global phase gate. -void inverseGlobalPhase(QCProgramBuilder& b); +std::pair, SmallVector> +inverseGlobalPhase(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled global /// phase gate. -void inverseMultipleControlledGlobalPhase(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledGlobalPhase(QCProgramBuilder& b); // --- IdOp ----------------------------------------------------------------- // /// Creates a circuit with just an identity gate. -void identity(QCProgramBuilder& b); +std::pair, SmallVector> identity(QCProgramBuilder& b); /// Creates a controlled identity gate with a single control qubit. -void singleControlledIdentity(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledIdentity(QCProgramBuilder& b); /// Creates a multi-controlled identity gate with multiple control qubits. -void multipleControlledIdentity(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledIdentity(QCProgramBuilder& b); /// Creates a circuit with a nested controlled identity gate. -void nestedControlledIdentity(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledIdentity(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled identity gate. -void trivialControlledIdentity(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledIdentity(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an identity gate. -void inverseIdentity(QCProgramBuilder& b); +std::pair, SmallVector> +inverseIdentity(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled identity /// gate. -void inverseMultipleControlledIdentity(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledIdentity(QCProgramBuilder& b); // --- XOp ------------------------------------------------------------------ // /// Creates a circuit with just an X gate. -void x(QCProgramBuilder& b); +std::pair, SmallVector> x(QCProgramBuilder& b); /// Creates a circuit with a single controlled X gate. -void singleControlledX(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledX(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled X gate. -void multipleControlledX(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledX(QCProgramBuilder& b); /// Creates a circuit with a nested controlled X gate. -void nestedControlledX(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledX(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled X gate. -void trivialControlledX(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledX(QCProgramBuilder& b); /// Creates a circuit with repeated controlled X gates. -void repeatedControlledX(QCProgramBuilder& b); +std::pair, SmallVector> +repeatedControlledX(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an X gate. -void inverseX(QCProgramBuilder& b); +std::pair, SmallVector> inverseX(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled X gate. -void inverseMultipleControlledX(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledX(QCProgramBuilder& b); // --- YOp ------------------------------------------------------------------ // /// Creates a circuit with just a Y gate. -void y(QCProgramBuilder& b); +std::pair, SmallVector> y(QCProgramBuilder& b); /// Creates a circuit with a single controlled Y gate. -void singleControlledY(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledY(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled Y gate. -void multipleControlledY(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledY(QCProgramBuilder& b); /// Creates a circuit with a nested controlled Y gate. -void nestedControlledY(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledY(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled Y gate. -void trivialControlledY(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Y gate. -void inverseY(QCProgramBuilder& b); +std::pair, SmallVector> inverseY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Y gate. -void inverseMultipleControlledY(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledY(QCProgramBuilder& b); // --- ZOp ------------------------------------------------------------------ // /// Creates a circuit with just a Z gate. -void z(QCProgramBuilder& b); +std::pair, SmallVector> z(QCProgramBuilder& b); /// Creates a circuit with a single controlled Z gate. -void singleControlledZ(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledZ(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled Z gate. -void multipleControlledZ(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledZ(QCProgramBuilder& b); /// Creates a circuit with a nested controlled Z gate. -void nestedControlledZ(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledZ(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled Z gate. -void trivialControlledZ(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledZ(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Z gate. -void inverseZ(QCProgramBuilder& b); +std::pair, SmallVector> inverseZ(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Z gate. -void inverseMultipleControlledZ(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledZ(QCProgramBuilder& b); // --- HOp ------------------------------------------------------------------ // /// Creates a circuit with just an H gate. -void h(QCProgramBuilder& b); +std::pair, SmallVector> h(QCProgramBuilder& b); /// Creates a circuit with a single controlled H gate. -void singleControlledH(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledH(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled H gate. -void multipleControlledH(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledH(QCProgramBuilder& b); /// Creates a circuit with a nested controlled H gate. -void nestedControlledH(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledH(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled H gate. -void trivialControlledH(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledH(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an H gate. -void inverseH(QCProgramBuilder& b); +std::pair, SmallVector> inverseH(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled H gate. -void inverseMultipleControlledH(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledH(QCProgramBuilder& b); /// Creates a circuit with just an H gate and no qubit register. -void hWithoutRegister(QCProgramBuilder& b); +std::pair, SmallVector> +hWithoutRegister(QCProgramBuilder& b); // --- SOp ------------------------------------------------------------------ // /// Creates a circuit with just an S gate. -void s(QCProgramBuilder& b); +std::pair, SmallVector> s(QCProgramBuilder& b); /// Creates a circuit with a single controlled S gate. -void singleControlledS(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledS(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled S gate. -void multipleControlledS(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledS(QCProgramBuilder& b); /// Creates a circuit with a nested controlled S gate. -void nestedControlledS(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledS(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled S gate. -void trivialControlledS(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledS(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an S gate. -void inverseS(QCProgramBuilder& b); +std::pair, SmallVector> inverseS(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled S gate. -void inverseMultipleControlledS(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledS(QCProgramBuilder& b); // --- SdgOp ---------------------------------------------------------------- // /// Creates a circuit with just an Sdg gate. -void sdg(QCProgramBuilder& b); +std::pair, SmallVector> sdg(QCProgramBuilder& b); /// Creates a circuit with a single controlled Sdg gate. -void singleControlledSdg(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledSdg(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled Sdg gate. -void multipleControlledSdg(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledSdg(QCProgramBuilder& b); /// Creates a circuit with a nested controlled Sdg gate. -void nestedControlledSdg(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledSdg(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled Sdg gate. -void trivialControlledSdg(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledSdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an Sdg gate. -void inverseSdg(QCProgramBuilder& b); +std::pair, SmallVector> +inverseSdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Sdg gate. -void inverseMultipleControlledSdg(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledSdg(QCProgramBuilder& b); // --- TOp ------------------------------------------------------------------ // /// Creates a circuit with just a T gate. -void t_(QCProgramBuilder& b); // NOLINT(*-identifier-naming) +std::pair, SmallVector> +t_(QCProgramBuilder& b); // NOLINT(*-identifier-naming) /// Creates a circuit with a single controlled T gate. -void singleControlledT(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledT(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled T gate. -void multipleControlledT(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledT(QCProgramBuilder& b); /// Creates a circuit with a nested controlled T gate. -void nestedControlledT(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledT(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled T gate. -void trivialControlledT(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledT(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a T gate. -void inverseT(QCProgramBuilder& b); +std::pair, SmallVector> inverseT(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled T gate. -void inverseMultipleControlledT(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledT(QCProgramBuilder& b); // --- TdgOp ---------------------------------------------------------------- // /// Creates a circuit with just a Tdg gate. -void tdg(QCProgramBuilder& b); +std::pair, SmallVector> tdg(QCProgramBuilder& b); /// Creates a circuit with a single controlled Tdg gate. -void singleControlledTdg(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledTdg(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled Tdg gate. -void multipleControlledTdg(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledTdg(QCProgramBuilder& b); /// Creates a circuit with a nested controlled Tdg gate. -void nestedControlledTdg(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledTdg(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled Tdg gate. -void trivialControlledTdg(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledTdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Tdg gate. -void inverseTdg(QCProgramBuilder& b); +std::pair, SmallVector> +inverseTdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Tdg gate. -void inverseMultipleControlledTdg(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledTdg(QCProgramBuilder& b); // --- SXOp ----------------------------------------------------------------- // /// Creates a circuit with just an SX gate. -void sx(QCProgramBuilder& b); +std::pair, SmallVector> sx(QCProgramBuilder& b); /// Creates a circuit with a single controlled SX gate. -void singleControlledSx(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledSx(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled SX gate. -void multipleControlledSx(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledSx(QCProgramBuilder& b); /// Creates a circuit with a nested controlled SX gate. -void nestedControlledSx(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledSx(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled SX gate. -void trivialControlledSx(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledSx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an SX gate. -void inverseSx(QCProgramBuilder& b); +std::pair, SmallVector> inverseSx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SX gate. -void inverseMultipleControlledSx(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledSx(QCProgramBuilder& b); // --- SXdgOp --------------------------------------------------------------- // /// Creates a circuit with just an SXdg gate. -void sxdg(QCProgramBuilder& b); +std::pair, SmallVector> sxdg(QCProgramBuilder& b); /// Creates a circuit with a single controlled SXdg gate. -void singleControlledSxdg(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledSxdg(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled SXdg gate. -void multipleControlledSxdg(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledSxdg(QCProgramBuilder& b); /// Creates a circuit with a nested controlled SXdg gate. -void nestedControlledSxdg(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledSxdg(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled SXdg gate. -void trivialControlledSxdg(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledSxdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an SXdg gate. -void inverseSxdg(QCProgramBuilder& b); +std::pair, SmallVector> +inverseSxdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SXdg /// gate. -void inverseMultipleControlledSxdg(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledSxdg(QCProgramBuilder& b); // --- RXOp ----------------------------------------------------------------- // /// Creates a circuit with just an RX gate. -void rx(QCProgramBuilder& b); +std::pair, SmallVector> rx(QCProgramBuilder& b); /// Creates a circuit with a single controlled RX gate. -void singleControlledRx(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledRx(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RX gate. -void multipleControlledRx(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRx(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RX gate. -void nestedControlledRx(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRx(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RX gate. -void trivialControlledRx(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RX gate. -void inverseRx(QCProgramBuilder& b); +std::pair, SmallVector> inverseRx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RX gate. -void inverseMultipleControlledRx(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRx(QCProgramBuilder& b); // --- RYOp ----------------------------------------------------------------- // /// Creates a circuit with just an RY gate. -void ry(QCProgramBuilder& b); +std::pair, SmallVector> ry(QCProgramBuilder& b); /// Creates a circuit with a single controlled RY gate. -void singleControlledRy(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledRy(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RY gate. -void multipleControlledRy(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRy(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RY gate. -void nestedControlledRy(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRy(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RY gate. -void trivialControlledRy(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRy(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RY gate. -void inverseRy(QCProgramBuilder& b); +std::pair, SmallVector> inverseRy(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RY gate. -void inverseMultipleControlledRy(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRy(QCProgramBuilder& b); // --- RZOp ----------------------------------------------------------------- // /// Creates a circuit with just an RZ gate. -void rz(QCProgramBuilder& b); +std::pair, SmallVector> rz(QCProgramBuilder& b); /// Creates a circuit with a single controlled RZ gate. -void singleControlledRz(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledRz(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RZ gate. -void multipleControlledRz(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRz(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RZ gate. -void nestedControlledRz(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRz(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RZ gate. -void trivialControlledRz(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRz(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZ gate. -void inverseRz(QCProgramBuilder& b); +std::pair, SmallVector> inverseRz(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZ gate. -void inverseMultipleControlledRz(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRz(QCProgramBuilder& b); // --- POp ------------------------------------------------------------------ // /// Creates a circuit with just a P gate. -void p(QCProgramBuilder& b); +std::pair, SmallVector> p(QCProgramBuilder& b); /// Creates a circuit with a single controlled P gate. -void singleControlledP(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledP(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled P gate. -void multipleControlledP(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledP(QCProgramBuilder& b); /// Creates a circuit with a nested controlled P gate. -void nestedControlledP(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledP(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled P gate. -void trivialControlledP(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledP(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a P gate. -void inverseP(QCProgramBuilder& b); +std::pair, SmallVector> inverseP(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled P gate. -void inverseMultipleControlledP(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledP(QCProgramBuilder& b); // --- ROp ------------------------------------------------------------------ // /// Creates a circuit with just an R gate. -void r(QCProgramBuilder& b); +std::pair, SmallVector> r(QCProgramBuilder& b); /// Creates a circuit with a single controlled R gate. -void singleControlledR(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledR(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled R gate. -void multipleControlledR(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledR(QCProgramBuilder& b); /// Creates a circuit with a nested controlled R gate. -void nestedControlledR(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledR(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled R gate. -void trivialControlledR(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledR(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an R gate. -void inverseR(QCProgramBuilder& b); +std::pair, SmallVector> inverseR(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled R gate. -void inverseMultipleControlledR(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledR(QCProgramBuilder& b); // --- U2Op ----------------------------------------------------------------- // /// Creates a circuit with just a U2 gate. -void u2(QCProgramBuilder& b); +std::pair, SmallVector> u2(QCProgramBuilder& b); /// Creates a circuit with a single controlled U2 gate. -void singleControlledU2(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledU2(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled U2 gate. -void multipleControlledU2(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledU2(QCProgramBuilder& b); /// Creates a circuit with a nested controlled U2 gate. -void nestedControlledU2(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledU2(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled U2 gate. -void trivialControlledU2(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledU2(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a U2 gate. -void inverseU2(QCProgramBuilder& b); +std::pair, SmallVector> inverseU2(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled U2 gate. -void inverseMultipleControlledU2(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledU2(QCProgramBuilder& b); // --- UOp ------------------------------------------------------------------ // /// Creates a circuit with just a U gate. -void u(QCProgramBuilder& b); +std::pair, SmallVector> u(QCProgramBuilder& b); /// Creates a circuit with a single controlled U gate. -void singleControlledU(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledU(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled U gate. -void multipleControlledU(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledU(QCProgramBuilder& b); /// Creates a circuit with a nested controlled U gate. -void nestedControlledU(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledU(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled U gate. -void trivialControlledU(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledU(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a U gate. -void inverseU(QCProgramBuilder& b); +std::pair, SmallVector> inverseU(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled U gate. -void inverseMultipleControlledU(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledU(QCProgramBuilder& b); // --- SWAPOp --------------------------------------------------------------- // /// Creates a circuit with just a SWAP gate. -void swap(QCProgramBuilder& b); +std::pair, SmallVector> swap(QCProgramBuilder& b); /// Creates a circuit with a single controlled SWAP gate. -void singleControlledSwap(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledSwap(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled SWAP gate. -void multipleControlledSwap(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledSwap(QCProgramBuilder& b); /// Creates a circuit with a nested controlled SWAP gate. -void nestedControlledSwap(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledSwap(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled SWAP gate. -void trivialControlledSwap(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledSwap(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a SWAP gate. -void inverseSwap(QCProgramBuilder& b); +std::pair, SmallVector> +inverseSwap(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SWAP /// gate. -void inverseMultipleControlledSwap(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledSwap(QCProgramBuilder& b); // --- iSWAPOp -------------------------------------------------------------- // /// Creates a circuit with just an iSWAP gate. -void iswap(QCProgramBuilder& b); +std::pair, SmallVector> iswap(QCProgramBuilder& b); /// Creates a circuit with a single controlled iSWAP gate. -void singleControlledIswap(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledIswap(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled iSWAP gate. -void multipleControlledIswap(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledIswap(QCProgramBuilder& b); /// Creates a circuit with a nested controlled iSWAP gate. -void nestedControlledIswap(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledIswap(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled iSWAP gate. -void trivialControlledIswap(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledIswap(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an iSWAP gate. -void inverseIswap(QCProgramBuilder& b); +std::pair, SmallVector> +inverseIswap(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled iSWAP /// gate. -void inverseMultipleControlledIswap(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledIswap(QCProgramBuilder& b); // --- DCXOp ---------------------------------------------------------------- // /// Creates a circuit with just a DCX gate. -void dcx(QCProgramBuilder& b); +std::pair, SmallVector> dcx(QCProgramBuilder& b); /// Creates a circuit with a single controlled DCX gate. -void singleControlledDcx(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledDcx(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled DCX gate. -void multipleControlledDcx(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledDcx(QCProgramBuilder& b); /// Creates a circuit with a nested controlled DCX gate. -void nestedControlledDcx(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledDcx(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled DCX gate. -void trivialControlledDcx(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledDcx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a DCX gate. -void inverseDcx(QCProgramBuilder& b); +std::pair, SmallVector> +inverseDcx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled DCX gate. -void inverseMultipleControlledDcx(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledDcx(QCProgramBuilder& b); // --- ECROp ---------------------------------------------------------------- // /// Creates a circuit with just an ECR gate. -void ecr(QCProgramBuilder& b); +std::pair, SmallVector> ecr(QCProgramBuilder& b); /// Creates a circuit with a single controlled ECR gate. -void singleControlledEcr(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledEcr(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled ECR gate. -void multipleControlledEcr(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledEcr(QCProgramBuilder& b); /// Creates a circuit with a nested controlled ECR gate. -void nestedControlledEcr(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledEcr(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled ECR gate. -void trivialControlledEcr(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledEcr(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an ECR gate. -void inverseEcr(QCProgramBuilder& b); +std::pair, SmallVector> +inverseEcr(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled ECR gate. -void inverseMultipleControlledEcr(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledEcr(QCProgramBuilder& b); // --- RXXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RXX gate. -void rxx(QCProgramBuilder& b); +std::pair, SmallVector> rxx(QCProgramBuilder& b); /// Creates a circuit with a single controlled RXX gate. -void singleControlledRxx(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledRxx(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RXX gate. -void multipleControlledRxx(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRxx(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RXX gate. -void nestedControlledRxx(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRxx(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RXX gate. -void trivialControlledRxx(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRxx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RXX gate. -void inverseRxx(QCProgramBuilder& b); +std::pair, SmallVector> +inverseRxx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RXX gate. -void inverseMultipleControlledRxx(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRxx(QCProgramBuilder& b); /// Creates a circuit with a triple-controlled RXX gate. -void tripleControlledRxx(QCProgramBuilder& b); +std::pair, SmallVector> +tripleControlledRxx(QCProgramBuilder& b); /// Creates a circuit with a four-controlled RXX gate. -void fourControlledRxx(QCProgramBuilder& b); +std::pair, SmallVector> +fourControlledRxx(QCProgramBuilder& b); // --- RYYOp ---------------------------------------------------------------- // /// Creates a circuit with just an RYY gate. -void ryy(QCProgramBuilder& b); +std::pair, SmallVector> ryy(QCProgramBuilder& b); /// Creates a circuit with a single controlled RYY gate. -void singleControlledRyy(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledRyy(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RYY gate. -void multipleControlledRyy(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRyy(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RYY gate. -void nestedControlledRyy(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRyy(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RYY gate. -void trivialControlledRyy(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRyy(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RYY gate. -void inverseRyy(QCProgramBuilder& b); +std::pair, SmallVector> +inverseRyy(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RYY gate. -void inverseMultipleControlledRyy(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRyy(QCProgramBuilder& b); // --- RZXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZX gate. -void rzx(QCProgramBuilder& b); +std::pair, SmallVector> rzx(QCProgramBuilder& b); /// Creates a circuit with a single controlled RZX gate. -void singleControlledRzx(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledRzx(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RZX gate. -void multipleControlledRzx(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRzx(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RZX gate. -void nestedControlledRzx(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRzx(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RZX gate. -void trivialControlledRzx(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRzx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZX gate. -void inverseRzx(QCProgramBuilder& b); +std::pair, SmallVector> +inverseRzx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZX gate. -void inverseMultipleControlledRzx(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRzx(QCProgramBuilder& b); // --- RZZOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZZ gate. -void rzz(QCProgramBuilder& b); +std::pair, SmallVector> rzz(QCProgramBuilder& b); /// Creates a circuit with a single controlled RZZ gate. -void singleControlledRzz(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledRzz(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RZZ gate. -void multipleControlledRzz(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledRzz(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RZZ gate. -void nestedControlledRzz(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledRzz(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RZZ gate. -void trivialControlledRzz(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledRzz(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZZ gate. -void inverseRzz(QCProgramBuilder& b); +std::pair, SmallVector> +inverseRzz(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZZ gate. -void inverseMultipleControlledRzz(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledRzz(QCProgramBuilder& b); // --- XXPlusYYOp ----------------------------------------------------------- // /// Creates a circuit with just an XXPlusYY gate. -void xxPlusYY(QCProgramBuilder& b); +std::pair, SmallVector> xxPlusYY(QCProgramBuilder& b); /// Creates a circuit with a single controlled XXPlusYY gate. -void singleControlledXxPlusYY(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledXxPlusYY(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled XXPlusYY gate. -void multipleControlledXxPlusYY(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledXxPlusYY(QCProgramBuilder& b); /// Creates a circuit with a nested controlled XXPlusYY gate. -void nestedControlledXxPlusYY(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledXxPlusYY(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled XXPlusYY gate. -void trivialControlledXxPlusYY(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledXxPlusYY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an XXPlusYY gate. -void inverseXxPlusYY(QCProgramBuilder& b); +std::pair, SmallVector> +inverseXxPlusYY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled XXPlusYY /// gate. -void inverseMultipleControlledXxPlusYY(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledXxPlusYY(QCProgramBuilder& b); // --- XXMinusYYOp ---------------------------------------------------------- // /// Creates a circuit with just an XXMinusYY gate. -void xxMinusYY(QCProgramBuilder& b); +std::pair, SmallVector> xxMinusYY(QCProgramBuilder& b); /// Creates a circuit with a single controlled XXMinusYY gate. -void singleControlledXxMinusYY(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledXxMinusYY(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled XXMinusYY gate. -void multipleControlledXxMinusYY(QCProgramBuilder& b); +std::pair, SmallVector> +multipleControlledXxMinusYY(QCProgramBuilder& b); /// Creates a circuit with a nested controlled XXMinusYY gate. -void nestedControlledXxMinusYY(QCProgramBuilder& b); +std::pair, SmallVector> +nestedControlledXxMinusYY(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled XXMinusYY gate. -void trivialControlledXxMinusYY(QCProgramBuilder& b); +std::pair, SmallVector> +trivialControlledXxMinusYY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an XXMinusYY gate. -void inverseXxMinusYY(QCProgramBuilder& b); +std::pair, SmallVector> +inverseXxMinusYY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled XXMinusYY /// gate. -void inverseMultipleControlledXxMinusYY(QCProgramBuilder& b); +std::pair, SmallVector> +inverseMultipleControlledXxMinusYY(QCProgramBuilder& b); // --- BarrierOp ------------------------------------------------------------ // /// Creates a circuit with a barrier. -void barrier(QCProgramBuilder& b); +std::pair, SmallVector> barrier(QCProgramBuilder& b); /// Creates a circuit with a barrier on two qubits. -void barrierTwoQubits(QCProgramBuilder& b); +std::pair, SmallVector> +barrierTwoQubits(QCProgramBuilder& b); /// Creates a circuit with a barrier on multiple qubits. -void barrierMultipleQubits(QCProgramBuilder& b); +std::pair, SmallVector> +barrierMultipleQubits(QCProgramBuilder& b); /// Creates a circuit with a single controlled barrier. -void singleControlledBarrier(QCProgramBuilder& b); +std::pair, SmallVector> +singleControlledBarrier(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a barrier. -void inverseBarrier(QCProgramBuilder& b); +std::pair, SmallVector> +inverseBarrier(QCProgramBuilder& b); // --- CtrlOp --------------------------------------------------------------- // /// Creates a circuit with a trivial ctrl modifier. -void trivialCtrl(QCProgramBuilder& b); +std::pair, SmallVector> +trivialCtrl(QCProgramBuilder& b); /// Creates a circuit with nested ctrl modifiers. -void nestedCtrl(QCProgramBuilder& b); +std::pair, SmallVector> +nestedCtrl(QCProgramBuilder& b); /// Creates a circuit with triple nested ctrl modifiers. -void tripleNestedCtrl(QCProgramBuilder& b); +std::pair, SmallVector> +tripleNestedCtrl(QCProgramBuilder& b); /// Creates a circuit with double nested ctrl modifiers with two qubits each. -void doubleNestedCtrlTwoQubits(QCProgramBuilder& b); +std::pair, SmallVector> +doubleNestedCtrlTwoQubits(QCProgramBuilder& b); /// Creates a circuit with control modifiers interleaved by an inverse modifier. -void ctrlInvSandwich(QCProgramBuilder& b); +std::pair, SmallVector> +ctrlInvSandwich(QCProgramBuilder& b); // --- InvOp ---------------------------------------------------------------- // /// Creates a circuit with nested inverse modifiers. -void nestedInv(QCProgramBuilder& b); +std::pair, SmallVector> nestedInv(QCProgramBuilder& b); /// Creates a circuit with triple nested inverse modifiers. -void tripleNestedInv(QCProgramBuilder& b); +std::pair, SmallVector> +tripleNestedInv(QCProgramBuilder& b); /// Creates a circuit with inverse modifiers interleaved by a control modifier. -void invCtrlSandwich(QCProgramBuilder& b); +std::pair, SmallVector> +invCtrlSandwich(QCProgramBuilder& b); // --- IfOp ----------------------------------------------------------------- // /// Creates a circuit with a simple if operation with one qubit. -void simpleIf(QCProgramBuilder& b); +std::pair, SmallVector> simpleIf(QCProgramBuilder& b); /// Creates a circuit with an if operation with an else branch. -void ifElse(QCProgramBuilder& b); +std::pair, SmallVector> ifElse(QCProgramBuilder& b); /// Creates a circuit with an if operation with two qubits. -void ifTwoQubits(QCProgramBuilder& b); +std::pair, SmallVector> +ifTwoQubits(QCProgramBuilder& b); /// Creates a circuit with an if operation with a nested for operation with /// a register. -void nestedIfOpForLoop(QCProgramBuilder& b); +std::pair, SmallVector> +nestedIfOpForLoop(QCProgramBuilder& b); // --- WhileOp -------------------------------------------------------------- // /// Creates a circuit with a while operation using a while loop. -void simpleWhileReset(QCProgramBuilder& b); +std::pair, SmallVector> +simpleWhileReset(QCProgramBuilder& b); /// Creates a circuit with a while operation using a do-while loop. -void simpleDoWhileReset(QCProgramBuilder& b); +std::pair, SmallVector> +simpleDoWhileReset(QCProgramBuilder& b); // --- ForOp ---------------------------------------------------------------- // /// Creates a circuit with a simple for operation with a register. -void simpleForLoop(QCProgramBuilder& b); +std::pair, SmallVector> +simpleForLoop(QCProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested if operation. -void nestedForLoopIfOp(QCProgramBuilder& b); +std::pair, SmallVector> +nestedForLoopIfOp(QCProgramBuilder& b); /// Creates a circuit with a for operation with a register and a nested while /// operation. -void nestedForLoopWhileOp(QCProgramBuilder& b); +std::pair, SmallVector> +nestedForLoopWhileOp(QCProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is separately allocated from the /// register. -void nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b); +std::pair, SmallVector> +nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is extracted from the register. -void nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b); +std::pair, SmallVector> +nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b); } // namespace mlir::qc From 88bac4e7d8017e9c5db54ea44e33c97d3b33546d Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 23 Jun 2026 18:23:27 +0200 Subject: [PATCH 30/80] chore(mlir): :construction: update QIR program builder and test system --- .../Dialect/QC/Builder/QCProgramBuilder.h | 1 - .../Dialect/QIR/Builder/QIRProgramBuilder.h | 57 +- .../Dialect/QIR/Builder/QIRProgramBuilder.cpp | 50 +- .../Compiler/test_compiler_pipeline.cpp | 7 +- mlir/unittests/programs/qir_programs.cpp | 657 ++++++++---------- mlir/unittests/programs/qir_programs.h | 346 ++++----- 6 files changed, 528 insertions(+), 590 deletions(-) diff --git a/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h b/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h index 139be3ae0f..e5bf471821 100644 --- a/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h @@ -1131,7 +1131,6 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder { /** * @brief Convenience method for building quantum programs. * @param context The MLIR context to use for building the program - * @param returnTypes The types of the values to be returned by the program. * @param buildFunc A function that takes a reference to a QCProgramBuilder * and uses it to build the desired quantum program. The builder will be * properly initialized before calling this function, and the resulting module diff --git a/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h b/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h index 30802171eb..d8f5bd3173 100644 --- a/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h @@ -102,6 +102,23 @@ class QIRProgramBuilder final : public ImplicitLocOpBuilder { */ void initialize(); + /** + * @brief Initialize the builder and prepare for program construction + * with specified return types. + * @param returnType The return type for the main function + * + * @details + * Creates a main function with an entry_point attribute. Must be called + * before adding operations. + */ + void initialize(Type returnType); + + /** + * @brief Modify the return type of the main function after initialization. + * @param returnType The new return type for the main function + */ + void retype(Type returnType); + //===--------------------------------------------------------------------===// // Constants //===--------------------------------------------------------------------===// @@ -383,6 +400,24 @@ class QIRProgramBuilder final : public ImplicitLocOpBuilder { */ QIRProgramBuilder& reset(Value qubit); + /** + * @brief Read the value of the given measurement result. + * + * @details + * The value is read via `__quantum__rt__read_result`. + * + * @param result The value representing the measurement result + * @return An LLVM pointer to the measurement result + * + * @par Example: + * ```c++ + * auto result = builder.measure(q0, 0); + * auto value = builder.readResult(result); + * + * ``` + */ + Value readResult(Value result); + //===--------------------------------------------------------------------===// // Unitary Operations //===--------------------------------------------------------------------===// @@ -1026,6 +1061,25 @@ class QIRProgramBuilder final : public ImplicitLocOpBuilder { */ OwningOpRef finalize(); + /** + * @brief Finalize the program with a given exit code and return the + * constructed module + * @param returnValue The value representing the exit code to return + * + * @details + * Automatically deallocates all remaining valid qubits and tensors of qubits, + * adds a return statement with a given exit code, + * and transfers ownership of the module to the caller. The builder should not + * be used after calling this method. + * + * The return value must have the type indicated by the function signature + * of the main function, which returns an `i64` by default and can be + * modified by passing different arguments to the `initialize()` method. + * + * @return OwningOpRef containing the constructed quantum program module + */ + OwningOpRef finalize(Value returnValue); + /** * @brief Convenience method for building quantum programs * @param context The MLIR context to use for building the program @@ -1037,7 +1091,8 @@ class QIRProgramBuilder final : public ImplicitLocOpBuilder { */ static OwningOpRef build(MLIRContext* context, - const function_ref& buildFunc, + const function_ref< + std::pair(QIRProgramBuilder&)>& buildFunc, Profile profile = Profile::Adaptive); private: diff --git a/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp b/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp index 771e62b926..2943de2dc7 100644 --- a/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp +++ b/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp @@ -48,12 +48,14 @@ QIRProgramBuilder::QIRProgramBuilder(MLIRContext* context) getContext()->loadDialect(); } -void QIRProgramBuilder::initialize() { +void QIRProgramBuilder::initialize() { initialize(getI64Type()); } + +void QIRProgramBuilder::initialize(Type returnType) { // Set insertion point to the module body setInsertionPointToStart(cast(module).getBody()); // Create main function: () -> i64 - auto funcType = LLVM::LLVMFunctionType::get(getI64Type(), {}); + auto funcType = LLVM::LLVMFunctionType::get(returnType, {}); auto mainFuncOp = LLVM::LLVMFuncOp::create(*this, "main", funcType); mainFunc = mainFuncOp.getOperation(); @@ -84,7 +86,6 @@ void QIRProgramBuilder::initialize() { // Create exit code constant in entry block setInsertionPointToStart(entryBlock); - exitCode = intConstant(0); // Add initialize call auto initSig = LLVM::LLVMFunctionType::get(voidType, ptrType); @@ -96,14 +97,19 @@ void QIRProgramBuilder::initialize() { setInsertionPointToEnd(entryBlock); LLVM::BrOp::create(*this, bodyBlock); - // Return the exit code (success) in output block - setInsertionPointToEnd(outputBlock); - LLVM::ReturnOp::create(*this, exitCode); - // Set insertion point to body block for user operations setInsertionPointToStart(bodyBlock); } +void QIRProgramBuilder::retype(Type returnType) { + auto mainFn = dyn_cast(mainFunc); + if (!mainFn) { + llvm::reportFatalUsageError("Main function not found for retyping"); + } + auto funcType = LLVM::LLVMFunctionType::get(returnType, {}); + mainFn.setType(funcType); +} + Value QIRProgramBuilder::resolveIntVariant( const std::variant& variant) { if (std::holds_alternative(variant)) { @@ -423,6 +429,17 @@ QIRProgramBuilder& QIRProgramBuilder::reset(Value qubit) { return *this; } +Value QIRProgramBuilder::readResult(mlir::Value result) { + checkFinalized(); + + const auto fnSig = LLVM::LLVMFunctionType::get(getI1Type(), {ptrType}); + auto fnDec = + getOrCreateFunctionDeclaration(*this, module, QIR_READ_RESULT, fnSig); + auto readOp = LLVM::CallOp::create(*this, fnDec, result); + + return readOp.getResult(); +} + //===----------------------------------------------------------------------===// // Unitary Operations //===----------------------------------------------------------------------===// @@ -983,9 +1000,20 @@ void QIRProgramBuilder::generateOutputRecording() { OwningOpRef QIRProgramBuilder::finalize() { checkFinalized(); + auto exitCode = intConstant(0); + return finalize(exitCode); +} + +OwningOpRef QIRProgramBuilder::finalize(Value returnValue) { + checkFinalized(); + // Save current insertion point const InsertionGuard guard(*this); + // Add return statement with the given return values to the main function + setInsertionPointToEnd(outputBlock); + LLVM::ReturnOp::create(*this, returnValue); + // Release resources in output block setInsertionPoint(outputBlock->getTerminator()); @@ -1037,12 +1065,14 @@ OwningOpRef QIRProgramBuilder::finalize() { OwningOpRef QIRProgramBuilder::build( MLIRContext* context, - const function_ref& buildFunc, Profile profile) { + const function_ref(QIRProgramBuilder&)>& buildFunc, + Profile profile) { QIRProgramBuilder builder(context); builder.profile = profile; builder.initialize(); - buildFunc(builder); - return builder.finalize(); + auto [result, resultType] = buildFunc(builder); + builder.retype(resultType); + return builder.finalize(result); } } // namespace mlir::qir diff --git a/mlir/unittests/Compiler/test_compiler_pipeline.cpp b/mlir/unittests/Compiler/test_compiler_pipeline.cpp index a4fd294209..86f000e9ea 100644 --- a/mlir/unittests/Compiler/test_compiler_pipeline.cpp +++ b/mlir/unittests/Compiler/test_compiler_pipeline.cpp @@ -44,8 +44,11 @@ namespace mqt::test::compiler { -using QCProgramBuilderFn = NamedBuilder; -using QIRProgramBuilderFn = NamedBuilder; +using QCProgramBuilderFn = NamedBuilder< + mlir::qc::QCProgramBuilder, + std::pair, mlir::SmallVector>>; +using QIRProgramBuilderFn = NamedBuilder>; using QuantumComputationBuilderFn = NamedBuilder<::qc::QuantumComputation>; namespace { diff --git a/mlir/unittests/programs/qir_programs.cpp b/mlir/unittests/programs/qir_programs.cpp index acfda0097c..769297d3e6 100644 --- a/mlir/unittests/programs/qir_programs.cpp +++ b/mlir/unittests/programs/qir_programs.cpp @@ -12,35 +12,67 @@ #include "mlir/Dialect/QIR/Builder/QIRProgramBuilder.h" +#include +#include +#include +#include +#include +#include +#include +#include + #include -namespace mlir::qir { +static std::pair +measureAndReturn(mlir::qir::QIRProgramBuilder& b, + mlir::SmallVector qubits) { + + if (qubits.empty()) { + auto zeroConst = b.intConstant(0); + return {zeroConst, b.getI64Type()}; + } + if (qubits.size() == 1) { + auto outcome = b.measure(qubits[0], 0); + auto result = b.readResult(outcome); + return {result, b.getI1Type()}; + } + + llvm::SmallVector elementTypes(qubits.size(), b.getI1Type()); + auto structType = + mlir::LLVM::LLVMStructType::getLiteral(b.getContext(), elementTypes); + mlir::Value structValue = mlir::LLVM::PoisonOp::create(b, structType); + + for (auto i = 0L; i < qubits.size(); ++i) { + auto outcome = b.measure(qubits[i], i); + auto result = b.readResult(outcome); + auto insert = mlir::LLVM::InsertValueOp::create(b, structValue, result, i); + structValue = insert.getResult(); + } + return {structValue, structType}; +} -std::pair, SmallVector> -emptyQIR([[maybe_unused]] QIRProgramBuilder& builder) { - return {{builder.intConstant(0)}, {builder.getI64Type()}}; +namespace mlir::qir { +std::pair emptyQIR(QIRProgramBuilder& b) { + return measureAndReturn(b, {}); } -std::pair, SmallVector> -allocQubit(QIRProgramBuilder& b) { - b.allocQubitRegister(1); - return {{b.intConstant(0)}, {b.getI64Type()}}; +std::pair allocQubit(QIRProgramBuilder& b) { + auto q = b.allocQubit(); + return measureAndReturn(b, {q}); } -std::pair, SmallVector> -allocQubitRegister(QIRProgramBuilder& b) { - b.allocQubitRegister(2); - return {{b.intConstant(0)}, {b.getI64Type()}}; +std::pair allocQubitRegister(QIRProgramBuilder& b) { + auto q = b.allocQubitRegister(2); + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -allocMultipleQubitRegisters(QIRProgramBuilder& b) { - b.allocQubitRegister(2); - b.allocQubitRegister(3); - return {{b.intConstant(0)}, {b.getI64Type()}}; +std::pair allocMultipleQubitRegisters(QIRProgramBuilder& b) { + auto q0 = b.allocQubitRegister(2); + auto q1 = b.allocQubitRegister(3); + return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}); } -std::pair, SmallVector> +std::pair allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); auto q1 = b.allocQubitRegister(3); @@ -49,65 +81,57 @@ allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b) { b.h(q1[0]); b.h(q1[1]); b.h(q1[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}); } -std::pair, SmallVector> -allocLargeRegister(QIRProgramBuilder& b) { - b.allocQubitRegister(100); - return {{b.intConstant(0)}, {b.getI64Type()}}; +std::pair allocLargeRegister(QIRProgramBuilder& b) { + auto q = b.allocQubitRegister(100); + return measureAndReturn(b, {q[0], q[99]}); } -std::pair, SmallVector> -staticQubits(QIRProgramBuilder& b) { - b.staticQubit(0); - b.staticQubit(1); - return {{b.intConstant(0)}, {b.getI64Type()}}; +std::pair staticQubits(QIRProgramBuilder& b) { + auto q0 = b.staticQubit(0); + auto q1 = b.staticQubit(1); + return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithOps(QIRProgramBuilder& b) { +std::pair staticQubitsWithOps(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.h(q0); b.h(q1); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithParametricOps(QIRProgramBuilder& b) { +std::pair staticQubitsWithParametricOps(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.rx(std::numbers::pi / 4., q0); b.p(std::numbers::pi / 2., q1); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithTwoTargetOps(QIRProgramBuilder& b) { +std::pair staticQubitsWithTwoTargetOps(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.rzz(0.123, q0, q1); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithCtrl(QIRProgramBuilder& b) { +std::pair staticQubitsWithCtrl(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.cx(q0, q1); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithInv(QIRProgramBuilder& b) { +std::pair staticQubitsWithInv(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); b.tdg(q0); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q0}); } -std::pair, SmallVector> -staticQubitsWithDuplicates(QIRProgramBuilder& b) { +std::pair staticQubitsWithDuplicates(QIRProgramBuilder& b) { auto q0a = b.staticQubit(0); auto q1a = b.staticQubit(1); auto q0b = b.staticQubit(0); @@ -117,11 +141,10 @@ staticQubitsWithDuplicates(QIRProgramBuilder& b) { b.rzz(0.123, q0b, q1b); b.cx(q0b, q1b); b.tdg(q0a); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q0b, q1b}); } -std::pair, SmallVector> -staticQubitsCanonical(QIRProgramBuilder& b) { +std::pair staticQubitsCanonical(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.rx(std::numbers::pi / 4., q0); @@ -129,52 +152,49 @@ staticQubitsCanonical(QIRProgramBuilder& b) { b.rzz(0.123, q0, q1); b.cx(q0, q1); b.tdg(q0); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -mixedStaticThenDynamicQubit(QIRProgramBuilder& b) { - b.staticQubit(0); - b.allocQubit(); - return {{b.intConstant(0)}, {b.getI64Type()}}; +std::pair mixedStaticThenDynamicQubit(QIRProgramBuilder& b) { + auto q0 = b.staticQubit(0); + auto q1 = b.allocQubit(); + return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> +std::pair mixedDynamicRegisterThenStaticQubit(QIRProgramBuilder& b) { - b.allocQubitRegister(2); - b.staticQubit(0); - return {{b.intConstant(0)}, {b.getI64Type()}}; + auto q0 = b.allocQubitRegister(2); + auto q1 = b.staticQubit(0); + return measureAndReturn(b, {q0[0], q0[1], q1}); } -std::pair, SmallVector> -singleMeasurementToSingleBit(QIRProgramBuilder& b) { +std::pair singleMeasurementToSingleBit(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto c = b.allocClassicalBitRegister(1); b.measure(q[0], c[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -repeatedMeasurementToSameBit(QIRProgramBuilder& b) { +std::pair repeatedMeasurementToSameBit(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto c = b.allocClassicalBitRegister(1); b.measure(q[0], c[0]); b.measure(q[0], c[0]); b.measure(q[0], c[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> +std::pair repeatedMeasurementToDifferentBits(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto c = b.allocClassicalBitRegister(3); b.measure(q[0], c[0]); b.measure(q[0], c[1]); b.measure(q[0], c[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> +std::pair multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); const auto& c0 = b.allocClassicalBitRegister(1, "c0"); @@ -182,670 +202,599 @@ multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b) { b.measure(q[0], c0[0]); b.measure(q[1], c1[0]); b.measure(q[2], c1[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> -measurementWithoutRegisters(QIRProgramBuilder& b) { +std::pair measurementWithoutRegisters(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.measure(q, 0); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q}); } -std::pair, SmallVector> -resetQubitWithoutOp(QIRProgramBuilder& b) { +std::pair resetQubitWithoutOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -resetMultipleQubitsWithoutOp(QIRProgramBuilder& b) { +std::pair resetMultipleQubitsWithoutOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.reset(q[0]); b.reset(q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -repeatedResetWithoutOp(QIRProgramBuilder& b) { +std::pair repeatedResetWithoutOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -resetQubitAfterSingleOp(QIRProgramBuilder& b) { +std::pair resetQubitAfterSingleOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b) { +std::pair resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.h(q[0]); b.reset(q[0]); b.h(q[1]); b.reset(q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -repeatedResetAfterSingleOp(QIRProgramBuilder& b) { +std::pair repeatedResetAfterSingleOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -globalPhase(QIRProgramBuilder& b) { +std::pair globalPhase(QIRProgramBuilder& b) { b.gphase(0.123); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {}); } -std::pair, SmallVector> -identity(QIRProgramBuilder& b) { +std::pair identity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.id(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledIdentity(QIRProgramBuilder& b) { +std::pair singleControlledIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cid(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledIdentity(QIRProgramBuilder& b) { +std::pair multipleControlledIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcid({q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> x(QIRProgramBuilder& b) { +std::pair x(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.x(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledX(QIRProgramBuilder& b) { +std::pair singleControlledX(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cx(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledX(QIRProgramBuilder& b) { +std::pair multipleControlledX(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcx({q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> y(QIRProgramBuilder& b) { +std::pair y(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.y(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledY(QIRProgramBuilder& b) { +std::pair singleControlledY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cy(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledY(QIRProgramBuilder& b) { +std::pair multipleControlledY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcy({q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> z(QIRProgramBuilder& b) { +std::pair z(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.z(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledZ(QIRProgramBuilder& b) { +std::pair singleControlledZ(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cz(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledZ(QIRProgramBuilder& b) { +std::pair multipleControlledZ(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcz({q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> h(QIRProgramBuilder& b) { +std::pair h(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledH(QIRProgramBuilder& b) { +std::pair singleControlledH(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ch(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledH(QIRProgramBuilder& b) { +std::pair multipleControlledH(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mch({q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> -hWithoutRegister(QIRProgramBuilder& b) { +std::pair hWithoutRegister(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q}); } -std::pair, SmallVector> s(QIRProgramBuilder& b) { +std::pair s(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.s(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledS(QIRProgramBuilder& b) { +std::pair singleControlledS(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cs(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledS(QIRProgramBuilder& b) { +std::pair multipleControlledS(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcs({q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> sdg(QIRProgramBuilder& b) { +std::pair sdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sdg(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledSdg(QIRProgramBuilder& b) { +std::pair singleControlledSdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csdg(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledSdg(QIRProgramBuilder& b) { +std::pair multipleControlledSdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsdg({q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> t_(QIRProgramBuilder& b) { +std::pair t_(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.t(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledT(QIRProgramBuilder& b) { +std::pair singleControlledT(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ct(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledT(QIRProgramBuilder& b) { +std::pair multipleControlledT(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mct({q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> tdg(QIRProgramBuilder& b) { +std::pair tdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.tdg(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledTdg(QIRProgramBuilder& b) { +std::pair singleControlledTdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ctdg(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledTdg(QIRProgramBuilder& b) { +std::pair multipleControlledTdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mctdg({q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> sx(QIRProgramBuilder& b) { +std::pair sx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sx(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledSx(QIRProgramBuilder& b) { +std::pair singleControlledSx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csx(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledSx(QIRProgramBuilder& b) { +std::pair multipleControlledSx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsx({q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> sxdg(QIRProgramBuilder& b) { +std::pair sxdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sxdg(q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledSxdg(QIRProgramBuilder& b) { +std::pair singleControlledSxdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csxdg(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledSxdg(QIRProgramBuilder& b) { +std::pair multipleControlledSxdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsxdg({q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> rx(QIRProgramBuilder& b) { +std::pair rx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rx(0.123, q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledRx(QIRProgramBuilder& b) { +std::pair singleControlledRx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.crx(0.123, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledRx(QIRProgramBuilder& b) { +std::pair multipleControlledRx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcrx(0.123, {q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> ry(QIRProgramBuilder& b) { +std::pair ry(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.ry(0.456, q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledRy(QIRProgramBuilder& b) { +std::pair singleControlledRy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cry(0.456, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledRy(QIRProgramBuilder& b) { +std::pair multipleControlledRy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcry(0.456, {q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> rz(QIRProgramBuilder& b) { +std::pair rz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rz(0.789, q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledRz(QIRProgramBuilder& b) { +std::pair singleControlledRz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.crz(0.789, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledRz(QIRProgramBuilder& b) { +std::pair multipleControlledRz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcrz(0.789, {q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> p(QIRProgramBuilder& b) { +std::pair p(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.p(0.123, q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledP(QIRProgramBuilder& b) { +std::pair singleControlledP(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cp(0.123, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledP(QIRProgramBuilder& b) { +std::pair multipleControlledP(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcp(0.123, {q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> r(QIRProgramBuilder& b) { +std::pair r(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.r(0.123, 0.456, q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledR(QIRProgramBuilder& b) { +std::pair singleControlledR(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cr(0.123, 0.456, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledR(QIRProgramBuilder& b) { +std::pair multipleControlledR(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcr(0.123, 0.456, {q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> u2(QIRProgramBuilder& b) { +std::pair u2(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u2(0.234, 0.567, q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledU2(QIRProgramBuilder& b) { +std::pair singleControlledU2(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cu2(0.234, 0.567, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledU2(QIRProgramBuilder& b) { +std::pair multipleControlledU2(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcu2(0.234, 0.567, {q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> u(QIRProgramBuilder& b) { +std::pair u(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u(0.1, 0.2, 0.3, q[0]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -singleControlledU(QIRProgramBuilder& b) { +std::pair singleControlledU(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cu(0.1, 0.2, 0.3, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -multipleControlledU(QIRProgramBuilder& b) { +std::pair multipleControlledU(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcu(0.1, 0.2, 0.3, {q[0], q[1]}, q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> swap(QIRProgramBuilder& b) { +std::pair swap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.swap(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -singleControlledSwap(QIRProgramBuilder& b) { +std::pair singleControlledSwap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cswap(q[0], q[1], q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> -multipleControlledSwap(QIRProgramBuilder& b) { +std::pair multipleControlledSwap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcswap({q[0], q[1]}, q[2], q[3]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -std::pair, SmallVector> iswap(QIRProgramBuilder& b) { +std::pair iswap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.iswap(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -singleControlledIswap(QIRProgramBuilder& b) { +std::pair singleControlledIswap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.ciswap(q[0], q[1], q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> -multipleControlledIswap(QIRProgramBuilder& b) { +std::pair multipleControlledIswap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mciswap({q[0], q[1]}, q[2], q[3]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -std::pair, SmallVector> dcx(QIRProgramBuilder& b) { +std::pair dcx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.dcx(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -singleControlledDcx(QIRProgramBuilder& b) { +std::pair singleControlledDcx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cdcx(q[0], q[1], q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> -multipleControlledDcx(QIRProgramBuilder& b) { +std::pair multipleControlledDcx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcdcx({q[0], q[1]}, q[2], q[3]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -std::pair, SmallVector> ecr(QIRProgramBuilder& b) { +std::pair ecr(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ecr(q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -singleControlledEcr(QIRProgramBuilder& b) { +std::pair singleControlledEcr(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cecr(q[0], q[1], q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> -multipleControlledEcr(QIRProgramBuilder& b) { +std::pair multipleControlledEcr(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcecr({q[0], q[1]}, q[2], q[3]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -std::pair, SmallVector> rxx(QIRProgramBuilder& b) { +std::pair rxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rxx(0.123, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -singleControlledRxx(QIRProgramBuilder& b) { +std::pair singleControlledRxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crxx(0.123, q[0], q[1], q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> -multipleControlledRxx(QIRProgramBuilder& b) { +std::pair multipleControlledRxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -std::pair, SmallVector> -tripleControlledRxx(QIRProgramBuilder& b) { +std::pair tripleControlledRxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(5); b.mcrxx(0.123, {q[0], q[1], q[2]}, q[3], q[4]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4]}); } -std::pair, SmallVector> ryy(QIRProgramBuilder& b) { +std::pair ryy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ryy(0.123, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -singleControlledRyy(QIRProgramBuilder& b) { +std::pair singleControlledRyy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cryy(0.123, q[0], q[1], q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> -multipleControlledRyy(QIRProgramBuilder& b) { +std::pair multipleControlledRyy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcryy(0.123, {q[0], q[1]}, q[2], q[3]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -std::pair, SmallVector> rzx(QIRProgramBuilder& b) { +std::pair rzx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rzx(0.123, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -singleControlledRzx(QIRProgramBuilder& b) { +std::pair singleControlledRzx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crzx(0.123, q[0], q[1], q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> -multipleControlledRzx(QIRProgramBuilder& b) { +std::pair multipleControlledRzx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrzx(0.123, {q[0], q[1]}, q[2], q[3]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -std::pair, SmallVector> rzz(QIRProgramBuilder& b) { +std::pair rzz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rzz(0.123, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -singleControlledRzz(QIRProgramBuilder& b) { +std::pair singleControlledRzz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crzz(0.123, q[0], q[1], q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> -multipleControlledRzz(QIRProgramBuilder& b) { +std::pair multipleControlledRzz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrzz(0.123, {q[0], q[1]}, q[2], q[3]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -std::pair, SmallVector> -xxPlusYY(QIRProgramBuilder& b) { +std::pair xxPlusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.xx_plus_yy(0.123, 0.456, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -singleControlledXxPlusYY(QIRProgramBuilder& b) { +std::pair singleControlledXxPlusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cxx_plus_yy(0.123, 0.456, q[0], q[1], q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> -multipleControlledXxPlusYY(QIRProgramBuilder& b) { +std::pair multipleControlledXxPlusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcxx_plus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -std::pair, SmallVector> -xxMinusYY(QIRProgramBuilder& b) { +std::pair xxMinusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.xx_minus_yy(0.123, 0.456, q[0], q[1]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -singleControlledXxMinusYY(QIRProgramBuilder& b) { +std::pair singleControlledXxMinusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cxx_minus_yy(0.123, 0.456, q[0], q[1], q[2]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2]}); } -std::pair, SmallVector> -multipleControlledXxMinusYY(QIRProgramBuilder& b) { +std::pair multipleControlledXxMinusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcxx_minus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } -std::pair, SmallVector> -simpleIf(QIRProgramBuilder& b) { +std::pair simpleIf(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); auto cond = b.measure(q[0], 0); b.scfIf(cond, [&] { b.x(q[0]); }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> ifElse(QIRProgramBuilder& b) { +std::pair ifElse(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); auto cond = b.measure(q[0], 0); b.scfIf(cond, [&] { b.x(q[0]); }, [&] { b.z(q[0]); }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0]}); } -std::pair, SmallVector> -ifTwoQubits(QIRProgramBuilder& b) { +std::pair ifTwoQubits(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.h(q[0]); auto cond = b.measure(q[0], 0); @@ -853,11 +802,10 @@ ifTwoQubits(QIRProgramBuilder& b) { b.x(q[0]); b.x(q[1]); }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1]}); } -std::pair, SmallVector> -nestedIfOpForLoop(QIRProgramBuilder& b) { +std::pair nestedIfOpForLoop(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); b.h(q0); @@ -870,11 +818,10 @@ nestedIfOpForLoop(QIRProgramBuilder& b) { b.h(q1); }); }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {reg[0], reg[1], reg[2], q0}); } -std::pair, SmallVector> -simpleWhileReset(QIRProgramBuilder& b) { +std::pair simpleWhileReset(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); b.scfWhile( @@ -883,32 +830,29 @@ simpleWhileReset(QIRProgramBuilder& b) { return measureResult; }, [&] { b.h(q); }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q}); } -std::pair, SmallVector> -simpleDoWhileReset(QIRProgramBuilder& b) { +std::pair simpleDoWhileReset(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.scfWhile([&] { b.h(q); auto measureResult = b.measure(q, 0); return measureResult; }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q}); } -std::pair, SmallVector> -simpleForLoop(QIRProgramBuilder& b) { +std::pair simpleForLoop(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(2); b.scfFor(0, 2, 1, [&](Value iv) { auto q = b.load(reg.value, iv); b.h(q); }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {reg[0], reg[1]}); }; -std::pair, SmallVector> -nestedForLoopIfOp(QIRProgramBuilder& b) { +std::pair nestedForLoopIfOp(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto qCond = b.allocQubit(); b.scfFor(0, 2, 1, [&](Value iv) { @@ -919,11 +863,10 @@ nestedForLoopIfOp(QIRProgramBuilder& b) { b.h(q); }); }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {reg[0], reg[1], qCond}); } -std::pair, SmallVector> -nestedForLoopWhileOp(QIRProgramBuilder& b) { +std::pair nestedForLoopWhileOp(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(2); b.scfFor(0, 2, 1, [&](Value iv) { auto q = b.load(reg.value, iv); @@ -938,10 +881,10 @@ nestedForLoopWhileOp(QIRProgramBuilder& b) { }, [&] { b.h(q); }); }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {reg[0], reg[1]}); } -std::pair, SmallVector> +std::pair nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto control = b.allocQubit(); @@ -951,10 +894,10 @@ nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b) { b.h(q0); b.cx(control, q0); }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {reg[0], reg[1], reg[2], control}); } -std::pair, SmallVector> +std::pair nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.h(reg[0]); @@ -963,14 +906,14 @@ nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b) { b.h(q0); b.cx(reg[0], q0); }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); } -std::pair, SmallVector> ctrlTwo(QIRProgramBuilder& b) { +std::pair ctrlTwo(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcx({q[0], q[1]}, q[2]); b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); } } // namespace mlir::qir diff --git a/mlir/unittests/programs/qir_programs.h b/mlir/unittests/programs/qir_programs.h index 526b7d04ff..80e1cea79a 100644 --- a/mlir/unittests/programs/qir_programs.h +++ b/mlir/unittests/programs/qir_programs.h @@ -10,6 +10,7 @@ #pragma once +#include #include #include @@ -19,561 +20,468 @@ namespace mlir::qir { class QIRProgramBuilder; /// Creates an empty QIR program. -std::pair, SmallVector> -emptyQIR(QIRProgramBuilder& builder); +std::pair emptyQIR(QIRProgramBuilder& builder); // --- Qubit Management ----------------------------------------------------- // /// Allocates a single qubit. -std::pair, SmallVector> -allocQubit(QIRProgramBuilder& b); +std::pair allocQubit(QIRProgramBuilder& b); /// Allocates a qubit register of size `2`. -std::pair, SmallVector> -allocQubitRegister(QIRProgramBuilder& b); +std::pair allocQubitRegister(QIRProgramBuilder& b); /// Allocates two qubit registers of size `2` and `3`. -std::pair, SmallVector> -allocMultipleQubitRegisters(QIRProgramBuilder& b); +std::pair allocMultipleQubitRegisters(QIRProgramBuilder& b); /// Allocates two qubit registers of size `2` and `3` and applies operations. -std::pair, SmallVector> -allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b); +std::pair allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b); /// Allocates a large qubit register. -std::pair, SmallVector> -allocLargeRegister(QIRProgramBuilder& b); +std::pair allocLargeRegister(QIRProgramBuilder& b); /// Allocates two inline qubits. -std::pair, SmallVector> -staticQubits(QIRProgramBuilder& b); +std::pair staticQubits(QIRProgramBuilder& b); /// Allocates two static qubits and applies operations. -std::pair, SmallVector> -staticQubitsWithOps(QIRProgramBuilder& b); +std::pair staticQubitsWithOps(QIRProgramBuilder& b); /// Allocates two static qubits and applies parametric gates. -std::pair, SmallVector> -staticQubitsWithParametricOps(QIRProgramBuilder& b); +std::pair staticQubitsWithParametricOps(QIRProgramBuilder& b); /// Allocates two static qubits and applies a two-target gate. -std::pair, SmallVector> -staticQubitsWithTwoTargetOps(QIRProgramBuilder& b); +std::pair staticQubitsWithTwoTargetOps(QIRProgramBuilder& b); /// Allocates two static qubits and applies a controlled gate. -std::pair, SmallVector> -staticQubitsWithCtrl(QIRProgramBuilder& b); +std::pair staticQubitsWithCtrl(QIRProgramBuilder& b); /// Allocates a static qubit and applies the inverse of a T gate (Tdg). -std::pair, SmallVector> -staticQubitsWithInv(QIRProgramBuilder& b); +std::pair staticQubitsWithInv(QIRProgramBuilder& b); /// Allocates duplicate static qubits and applies operations on both. -std::pair, SmallVector> -staticQubitsWithDuplicates(QIRProgramBuilder& b); +std::pair staticQubitsWithDuplicates(QIRProgramBuilder& b); /// Same as `staticQubitsWithDuplicates`, but with canonical static qubit /// retrievals. -std::pair, SmallVector> -staticQubitsCanonical(QIRProgramBuilder& b); +std::pair staticQubitsCanonical(QIRProgramBuilder& b); // --- Invalid / mixed addressing (unit tests) -------------------------------- /// @pre `builder.initialize()`. Fatal mixed addressing: static then dynamic /// alloc. -std::pair, SmallVector> -mixedStaticThenDynamicQubit(QIRProgramBuilder& b); +std::pair mixedStaticThenDynamicQubit(QIRProgramBuilder& b); /// @pre `builder.initialize()`. Fatal mixed addressing: dynamic register then /// static. -std::pair, SmallVector> +std::pair mixedDynamicRegisterThenStaticQubit(QIRProgramBuilder& b); // --- MeasureOp ------------------------------------------------------------ // /// Measures a single qubit into a single classical bit. -std::pair, SmallVector> -singleMeasurementToSingleBit(QIRProgramBuilder& b); +std::pair singleMeasurementToSingleBit(QIRProgramBuilder& b); /// Repeatedly measures a single qubit into the same classical bit. -std::pair, SmallVector> -repeatedMeasurementToSameBit(QIRProgramBuilder& b); +std::pair repeatedMeasurementToSameBit(QIRProgramBuilder& b); /// Repeatedly measures a single qubit into different classical bits. -std::pair, SmallVector> -repeatedMeasurementToDifferentBits(QIRProgramBuilder& b); +std::pair repeatedMeasurementToDifferentBits(QIRProgramBuilder& b); /// Measures multiple qubits into multiple classical bits. -std::pair, SmallVector> +std::pair multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b); /// Measures a single qubit into a single classical bit, without explicitly /// allocating a quantum or classical register. -std::pair, SmallVector> -measurementWithoutRegisters(QIRProgramBuilder& b); +std::pair measurementWithoutRegisters(QIRProgramBuilder& b); // --- ResetOp -------------------------------------------------------------- // /// Resets a single qubit without any operations being applied. -std::pair, SmallVector> -resetQubitWithoutOp(QIRProgramBuilder& b); +std::pair resetQubitWithoutOp(QIRProgramBuilder& b); /// Resets multiple qubits without any operations being applied. -std::pair, SmallVector> -resetMultipleQubitsWithoutOp(QIRProgramBuilder& b); +std::pair resetMultipleQubitsWithoutOp(QIRProgramBuilder& b); /// Repeatedly resets a single qubit without any operations being applied. -std::pair, SmallVector> -repeatedResetWithoutOp(QIRProgramBuilder& b); +std::pair repeatedResetWithoutOp(QIRProgramBuilder& b); /// Resets a single qubit after a single operation. -std::pair, SmallVector> -resetQubitAfterSingleOp(QIRProgramBuilder& b); +std::pair resetQubitAfterSingleOp(QIRProgramBuilder& b); /// Resets multiple qubits after a single operation. -std::pair, SmallVector> -resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b); +std::pair resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b); /// Repeatedly resets a single qubit after a single operation. -std::pair, SmallVector> -repeatedResetAfterSingleOp(QIRProgramBuilder& b); +std::pair repeatedResetAfterSingleOp(QIRProgramBuilder& b); // --- GPhaseOp ------------------------------------------------------------- // /// Creates a circuit with just a global phase. -std::pair, SmallVector> -globalPhase(QIRProgramBuilder& b); +std::pair globalPhase(QIRProgramBuilder& b); // --- IdOp ----------------------------------------------------------------- // /// Creates a circuit with just an identity gate. -std::pair, SmallVector> identity(QIRProgramBuilder& b); +std::pair identity(QIRProgramBuilder& b); /// Creates a controlled identity gate with a single control qubit. -std::pair, SmallVector> -singleControlledIdentity(QIRProgramBuilder& b); +std::pair singleControlledIdentity(QIRProgramBuilder& b); /// Creates a multi-controlled identity gate with multiple control qubits. -std::pair, SmallVector> -multipleControlledIdentity(QIRProgramBuilder& b); +std::pair multipleControlledIdentity(QIRProgramBuilder& b); // --- XOp ------------------------------------------------------------------ // /// Creates a circuit with just an X gate. -std::pair, SmallVector> x(QIRProgramBuilder& b); +std::pair x(QIRProgramBuilder& b); /// Creates a circuit with a single controlled X gate. -std::pair, SmallVector> -singleControlledX(QIRProgramBuilder& b); +std::pair singleControlledX(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled X gate. -std::pair, SmallVector> -multipleControlledX(QIRProgramBuilder& b); +std::pair multipleControlledX(QIRProgramBuilder& b); // --- YOp ------------------------------------------------------------------ // /// Creates a circuit with just a Y gate. -std::pair, SmallVector> y(QIRProgramBuilder& b); +std::pair y(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Y gate. -std::pair, SmallVector> -singleControlledY(QIRProgramBuilder& b); +std::pair singleControlledY(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Y gate. -std::pair, SmallVector> -multipleControlledY(QIRProgramBuilder& b); +std::pair multipleControlledY(QIRProgramBuilder& b); // --- ZOp ------------------------------------------------------------------ // /// Creates a circuit with just a Z gate. -std::pair, SmallVector> z(QIRProgramBuilder& b); +std::pair z(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Z gate. -std::pair, SmallVector> -singleControlledZ(QIRProgramBuilder& b); +std::pair singleControlledZ(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Z gate. -std::pair, SmallVector> -multipleControlledZ(QIRProgramBuilder& b); +std::pair multipleControlledZ(QIRProgramBuilder& b); // --- HOp ------------------------------------------------------------------ // /// Creates a circuit with just an H gate. -std::pair, SmallVector> h(QIRProgramBuilder& b); +std::pair h(QIRProgramBuilder& b); /// Creates a circuit with a single controlled H gate. -std::pair, SmallVector> -singleControlledH(QIRProgramBuilder& b); +std::pair singleControlledH(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled H gate. -std::pair, SmallVector> -multipleControlledH(QIRProgramBuilder& b); +std::pair multipleControlledH(QIRProgramBuilder& b); /// Creates a circuit with just an H gate and no qubit register. -std::pair, SmallVector> -hWithoutRegister(QIRProgramBuilder& b); +std::pair hWithoutRegister(QIRProgramBuilder& b); // --- SOp ------------------------------------------------------------------ // /// Creates a circuit with just an S gate. -std::pair, SmallVector> s(QIRProgramBuilder& b); +std::pair s(QIRProgramBuilder& b); /// Creates a circuit with a single controlled S gate. -std::pair, SmallVector> -singleControlledS(QIRProgramBuilder& b); +std::pair singleControlledS(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled S gate. -std::pair, SmallVector> -multipleControlledS(QIRProgramBuilder& b); +std::pair multipleControlledS(QIRProgramBuilder& b); // --- SdgOp ---------------------------------------------------------------- // /// Creates a circuit with just an Sdg gate. -std::pair, SmallVector> sdg(QIRProgramBuilder& b); +std::pair sdg(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Sdg gate. -std::pair, SmallVector> -singleControlledSdg(QIRProgramBuilder& b); +std::pair singleControlledSdg(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Sdg gate. -std::pair, SmallVector> -multipleControlledSdg(QIRProgramBuilder& b); +std::pair multipleControlledSdg(QIRProgramBuilder& b); // --- TOp ------------------------------------------------------------------ // /// Creates a circuit with just a T gate. -std::pair, SmallVector> -t_(QIRProgramBuilder& b); // NOLINT(*-identifier-naming) +std::pair t_(QIRProgramBuilder& b); // NOLINT(*-identifier-naming) /// Creates a circuit with a single controlled T gate. -std::pair, SmallVector> -singleControlledT(QIRProgramBuilder& b); +std::pair singleControlledT(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled T gate. -std::pair, SmallVector> -multipleControlledT(QIRProgramBuilder& b); +std::pair multipleControlledT(QIRProgramBuilder& b); // --- TdgOp ---------------------------------------------------------------- // /// Creates a circuit with just a Tdg gate. -std::pair, SmallVector> tdg(QIRProgramBuilder& b); +std::pair tdg(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Tdg gate. -std::pair, SmallVector> -singleControlledTdg(QIRProgramBuilder& b); +std::pair singleControlledTdg(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Tdg gate. -std::pair, SmallVector> -multipleControlledTdg(QIRProgramBuilder& b); +std::pair multipleControlledTdg(QIRProgramBuilder& b); // --- SXOp ----------------------------------------------------------------- // /// Creates a circuit with just an SX gate. -std::pair, SmallVector> sx(QIRProgramBuilder& b); +std::pair sx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled SX gate. -std::pair, SmallVector> -singleControlledSx(QIRProgramBuilder& b); +std::pair singleControlledSx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled SX gate. -std::pair, SmallVector> -multipleControlledSx(QIRProgramBuilder& b); +std::pair multipleControlledSx(QIRProgramBuilder& b); // --- SXdgOp --------------------------------------------------------------- // /// Creates a circuit with just an SXdg gate. -std::pair, SmallVector> sxdg(QIRProgramBuilder& b); +std::pair sxdg(QIRProgramBuilder& b); /// Creates a circuit with a single controlled SXdg gate. -std::pair, SmallVector> -singleControlledSxdg(QIRProgramBuilder& b); +std::pair singleControlledSxdg(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled SXdg gate. -std::pair, SmallVector> -multipleControlledSxdg(QIRProgramBuilder& b); +std::pair multipleControlledSxdg(QIRProgramBuilder& b); // --- RXOp ----------------------------------------------------------------- // /// Creates a circuit with just an RX gate. -std::pair, SmallVector> rx(QIRProgramBuilder& b); +std::pair rx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RX gate. -std::pair, SmallVector> -singleControlledRx(QIRProgramBuilder& b); +std::pair singleControlledRx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RX gate. -std::pair, SmallVector> -multipleControlledRx(QIRProgramBuilder& b); +std::pair multipleControlledRx(QIRProgramBuilder& b); // --- RYOp ----------------------------------------------------------------- // /// Creates a circuit with just an RY gate. -std::pair, SmallVector> ry(QIRProgramBuilder& b); +std::pair ry(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RY gate. -std::pair, SmallVector> -singleControlledRy(QIRProgramBuilder& b); +std::pair singleControlledRy(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RY gate. -std::pair, SmallVector> -multipleControlledRy(QIRProgramBuilder& b); +std::pair multipleControlledRy(QIRProgramBuilder& b); // --- RZOp ----------------------------------------------------------------- // /// Creates a circuit with just an RZ gate. -std::pair, SmallVector> rz(QIRProgramBuilder& b); +std::pair rz(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RZ gate. -std::pair, SmallVector> -singleControlledRz(QIRProgramBuilder& b); +std::pair singleControlledRz(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RZ gate. -std::pair, SmallVector> -multipleControlledRz(QIRProgramBuilder& b); +std::pair multipleControlledRz(QIRProgramBuilder& b); // --- POp ------------------------------------------------------------------ // /// Creates a circuit with just a P gate. -std::pair, SmallVector> p(QIRProgramBuilder& b); +std::pair p(QIRProgramBuilder& b); /// Creates a circuit with a single controlled P gate. -std::pair, SmallVector> -singleControlledP(QIRProgramBuilder& b); +std::pair singleControlledP(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled P gate. -std::pair, SmallVector> -multipleControlledP(QIRProgramBuilder& b); +std::pair multipleControlledP(QIRProgramBuilder& b); // --- ROp ------------------------------------------------------------------ // /// Creates a circuit with just an R gate. -std::pair, SmallVector> r(QIRProgramBuilder& b); +std::pair r(QIRProgramBuilder& b); /// Creates a circuit with a single controlled R gate. -std::pair, SmallVector> -singleControlledR(QIRProgramBuilder& b); +std::pair singleControlledR(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled R gate. -std::pair, SmallVector> -multipleControlledR(QIRProgramBuilder& b); +std::pair multipleControlledR(QIRProgramBuilder& b); // --- U2Op ----------------------------------------------------------------- // /// Creates a circuit with just a U2 gate. -std::pair, SmallVector> u2(QIRProgramBuilder& b); +std::pair u2(QIRProgramBuilder& b); /// Creates a circuit with a single controlled U2 gate. -std::pair, SmallVector> -singleControlledU2(QIRProgramBuilder& b); +std::pair singleControlledU2(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled U2 gate. -std::pair, SmallVector> -multipleControlledU2(QIRProgramBuilder& b); +std::pair multipleControlledU2(QIRProgramBuilder& b); // --- UOp ------------------------------------------------------------------ // /// Creates a circuit with just a U gate. -std::pair, SmallVector> u(QIRProgramBuilder& b); +std::pair u(QIRProgramBuilder& b); /// Creates a circuit with a single controlled U gate. -std::pair, SmallVector> -singleControlledU(QIRProgramBuilder& b); +std::pair singleControlledU(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled U gate. -std::pair, SmallVector> -multipleControlledU(QIRProgramBuilder& b); +std::pair multipleControlledU(QIRProgramBuilder& b); // --- SWAPOp --------------------------------------------------------------- // /// Creates a circuit with just a SWAP gate. -std::pair, SmallVector> swap(QIRProgramBuilder& b); +std::pair swap(QIRProgramBuilder& b); /// Creates a circuit with a single controlled SWAP gate. -std::pair, SmallVector> -singleControlledSwap(QIRProgramBuilder& b); +std::pair singleControlledSwap(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled SWAP gate. -std::pair, SmallVector> -multipleControlledSwap(QIRProgramBuilder& b); +std::pair multipleControlledSwap(QIRProgramBuilder& b); // --- iSWAPOp -------------------------------------------------------------- // /// Creates a circuit with just an iSWAP gate. -std::pair, SmallVector> iswap(QIRProgramBuilder& b); +std::pair iswap(QIRProgramBuilder& b); /// Creates a circuit with a single controlled iSWAP gate. -std::pair, SmallVector> -singleControlledIswap(QIRProgramBuilder& b); +std::pair singleControlledIswap(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled iSWAP gate. -std::pair, SmallVector> -multipleControlledIswap(QIRProgramBuilder& b); +std::pair multipleControlledIswap(QIRProgramBuilder& b); // --- DCXOp ---------------------------------------------------------------- // /// Creates a circuit with just a DCX gate. -std::pair, SmallVector> dcx(QIRProgramBuilder& b); +std::pair dcx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled DCX gate. -std::pair, SmallVector> -singleControlledDcx(QIRProgramBuilder& b); +std::pair singleControlledDcx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled DCX gate. -std::pair, SmallVector> -multipleControlledDcx(QIRProgramBuilder& b); +std::pair multipleControlledDcx(QIRProgramBuilder& b); // --- ECROp ---------------------------------------------------------------- // /// Creates a circuit with just an ECR gate. -std::pair, SmallVector> ecr(QIRProgramBuilder& b); +std::pair ecr(QIRProgramBuilder& b); /// Creates a circuit with a single controlled ECR gate. -std::pair, SmallVector> -singleControlledEcr(QIRProgramBuilder& b); +std::pair singleControlledEcr(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled ECR gate. -std::pair, SmallVector> -multipleControlledEcr(QIRProgramBuilder& b); +std::pair multipleControlledEcr(QIRProgramBuilder& b); // --- RXXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RXX gate. -std::pair, SmallVector> rxx(QIRProgramBuilder& b); +std::pair rxx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RXX gate. -std::pair, SmallVector> -singleControlledRxx(QIRProgramBuilder& b); +std::pair singleControlledRxx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RXX gate. -std::pair, SmallVector> -multipleControlledRxx(QIRProgramBuilder& b); +std::pair multipleControlledRxx(QIRProgramBuilder& b); /// Creates a circuit with a triple-controlled RXX gate. -std::pair, SmallVector> -tripleControlledRxx(QIRProgramBuilder& b); +std::pair tripleControlledRxx(QIRProgramBuilder& b); // --- RYYOp ---------------------------------------------------------------- // /// Creates a circuit with just an RYY gate. -std::pair, SmallVector> ryy(QIRProgramBuilder& b); +std::pair ryy(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RYY gate. -std::pair, SmallVector> -singleControlledRyy(QIRProgramBuilder& b); +std::pair singleControlledRyy(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RYY gate. -std::pair, SmallVector> -multipleControlledRyy(QIRProgramBuilder& b); +std::pair multipleControlledRyy(QIRProgramBuilder& b); // --- RZXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZX gate. -std::pair, SmallVector> rzx(QIRProgramBuilder& b); +std::pair rzx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RZX gate. -std::pair, SmallVector> -singleControlledRzx(QIRProgramBuilder& b); +std::pair singleControlledRzx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RZX gate. -std::pair, SmallVector> -multipleControlledRzx(QIRProgramBuilder& b); +std::pair multipleControlledRzx(QIRProgramBuilder& b); // --- RZZOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZZ gate. -std::pair, SmallVector> rzz(QIRProgramBuilder& b); +std::pair rzz(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RZZ gate. -std::pair, SmallVector> -singleControlledRzz(QIRProgramBuilder& b); +std::pair singleControlledRzz(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RZZ gate. -std::pair, SmallVector> -multipleControlledRzz(QIRProgramBuilder& b); +std::pair multipleControlledRzz(QIRProgramBuilder& b); // --- XXPlusYYOp ----------------------------------------------------------- // /// Creates a circuit with just an XXPlusYY gate. -std::pair, SmallVector> xxPlusYY(QIRProgramBuilder& b); +std::pair xxPlusYY(QIRProgramBuilder& b); /// Creates a circuit with a single controlled XXPlusYY gate. -std::pair, SmallVector> -singleControlledXxPlusYY(QIRProgramBuilder& b); +std::pair singleControlledXxPlusYY(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled XXPlusYY gate. -std::pair, SmallVector> -multipleControlledXxPlusYY(QIRProgramBuilder& b); +std::pair multipleControlledXxPlusYY(QIRProgramBuilder& b); // --- XXMinusYYOp ---------------------------------------------------------- // /// Creates a circuit with just an XXMinusYY gate. -std::pair, SmallVector> -xxMinusYY(QIRProgramBuilder& b); +std::pair xxMinusYY(QIRProgramBuilder& b); /// Creates a circuit with a single controlled XXMinusYY gate. -std::pair, SmallVector> -singleControlledXxMinusYY(QIRProgramBuilder& b); +std::pair singleControlledXxMinusYY(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled XXMinusYY gate. -std::pair, SmallVector> -multipleControlledXxMinusYY(QIRProgramBuilder& b); +std::pair multipleControlledXxMinusYY(QIRProgramBuilder& b); // --- IfOp ----------------------------------------------------------------- // /// Creates a circuit with a simple if operation with one qubit. -std::pair, SmallVector> simpleIf(QIRProgramBuilder& b); +std::pair simpleIf(QIRProgramBuilder& b); /// Creates a circuit with an if operation with an else branch. -std::pair, SmallVector> ifElse(QIRProgramBuilder& b); +std::pair ifElse(QIRProgramBuilder& b); /// Creates a circuit with an if operation with two qubits. -std::pair, SmallVector> -ifTwoQubits(QIRProgramBuilder& b); +std::pair ifTwoQubits(QIRProgramBuilder& b); /// Creates a circuit with an if operation with a nested for operation with /// a register. -std::pair, SmallVector> -nestedIfOpForLoop(QIRProgramBuilder& b); +std::pair nestedIfOpForLoop(QIRProgramBuilder& b); // --- WhileOp -------------------------------------------------------------- // /// Creates a circuit with a while operation using a while loop. -std::pair, SmallVector> -simpleWhileReset(QIRProgramBuilder& b); +std::pair simpleWhileReset(QIRProgramBuilder& b); /// Creates a circuit with a while operation using a do-while loop. -std::pair, SmallVector> -simpleDoWhileReset(QIRProgramBuilder& b); +std::pair simpleDoWhileReset(QIRProgramBuilder& b); // --- ForOp ---------------------------------------------------------------- // /// Creates a circuit with a simple for operation with a register. -std::pair, SmallVector> -simpleForLoop(QIRProgramBuilder& b); +std::pair simpleForLoop(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested if operation. -std::pair, SmallVector> -nestedForLoopIfOp(QIRProgramBuilder& b); +std::pair nestedForLoopIfOp(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a nested while /// operation. -std::pair, SmallVector> -nestedForLoopWhileOp(QIRProgramBuilder& b); +std::pair nestedForLoopWhileOp(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is separately allocated from the /// register. -std::pair, SmallVector> +std::pair nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is extracted from the register. -std::pair, SmallVector> +std::pair nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b); // --- CtrlOp --------------------------------------------------------------- // /// Creates a circuit with a control modifier applied to two gates. -std::pair, SmallVector> ctrlTwo(QIRProgramBuilder& b); +std::pair ctrlTwo(QIRProgramBuilder& b); } // namespace mlir::qir From 8a519b863a44b1e8bf0e9311898281aaed627409 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Wed, 24 Jun 2026 16:10:29 +0200 Subject: [PATCH 31/80] feat(mlir): :white_check_mark: make all Compiler Pipeline tests pass --- include/mqt-core/ir/QuantumComputation.hpp | 3 +- .../TranslateQuantumComputationToQC.cpp | 14 +- .../Compiler/test_compiler_pipeline.cpp | 43 ++--- mlir/unittests/programs/qc_programs.cpp | 36 +++-- mlir/unittests/programs/qc_programs.h | 4 + mlir/unittests/programs/qco_programs.cpp | 8 +- mlir/unittests/programs/qir_programs.cpp | 147 ++++++++++++++---- mlir/unittests/programs/qir_programs.h | 3 + .../programs/quantum_computation_programs.cpp | 109 ++++++++++++- src/ir/QuantumComputation.cpp | 6 +- 10 files changed, 295 insertions(+), 78 deletions(-) diff --git a/include/mqt-core/ir/QuantumComputation.hpp b/include/mqt-core/ir/QuantumComputation.hpp index 68f2e295b1..92e426f982 100644 --- a/include/mqt-core/ir/QuantumComputation.hpp +++ b/include/mqt-core/ir/QuantumComputation.hpp @@ -322,11 +322,12 @@ class QuantumComputation { /** * @brief Add measurements to all qubits * @param addBits Whether to add new classical bits to the circuit + * @param addBarrier Whether to add a barrier before the measurements * @details This function adds measurements to all qubits in the circuit and * appends a new classical register (named "meas") to the circuit if addBits * is true. Otherwise, qubit q is measured into classical bit q. */ - void measureAll(bool addBits = true); + void measureAll(bool addBits = true, bool addBarrier = true); void bridge(const Targets& targets); diff --git a/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp b/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp index 7a2cf23651..1087d15fd6 100644 --- a/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp +++ b/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp @@ -849,7 +849,15 @@ OwningOpRef translateQuantumComputationToQC( MLIRContext* context, const ::qc::QuantumComputation& quantumComputation) { // Create and initialize the builder (creates module and main function) QCProgramBuilder builder(context); - builder.initialize(); + SmallVector resultTypes(quantumComputation.getNcbits()); + for (auto i = 0; i < quantumComputation.getNcbits(); ++i) { + resultTypes[i] = builder.getI1Type(); + } + if (quantumComputation.getNcbits() == 0) { + // Without classical bits, we instead return an exit code 0. + resultTypes.push_back(builder.getI64Type()); + } + builder.initialize(resultTypes); // Allocate quantum registers using the builder const auto qregs = allocateQregs(builder, quantumComputation); @@ -876,7 +884,9 @@ OwningOpRef translateQuantumComputationToQC( // Finalize and return the module (adds return statement and transfers // ownership) - return builder.finalize(); + return quantumComputation.getNcbits() == 0 + ? builder.finalize({builder.intConstant(0)}) + : builder.finalize(state.results); } } // namespace mlir diff --git a/mlir/unittests/Compiler/test_compiler_pipeline.cpp b/mlir/unittests/Compiler/test_compiler_pipeline.cpp index 86f000e9ea..c452465b01 100644 --- a/mlir/unittests/Compiler/test_compiler_pipeline.cpp +++ b/mlir/unittests/Compiler/test_compiler_pipeline.cpp @@ -290,23 +290,23 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(mlir::qc::staticQubitsWithInv), MQT_NAMED_BUILDER(mlir::qc::staticQubitsWithInv), MQT_NAMED_BUILDER(mlir::qir::staticQubitsWithInv), false}, - CompilerPipelineTestCase{"AllocQubit", - MQT_NAMED_BUILDER(qc::allocQubit), nullptr, - MQT_NAMED_BUILDER(mlir::qc::emptyQC), - MQT_NAMED_BUILDER(mlir::qir::emptyQIR)}, - CompilerPipelineTestCase{"AllocQubitRegister", - MQT_NAMED_BUILDER(qc::allocQubitRegister), - nullptr, MQT_NAMED_BUILDER(mlir::qc::emptyQC), - MQT_NAMED_BUILDER(mlir::qir::emptyQIR)}, + CompilerPipelineTestCase{ + "AllocQubit", MQT_NAMED_BUILDER(qc::allocQubit), nullptr, + MQT_NAMED_BUILDER(mlir::qc::alloc1QubitRegister), + MQT_NAMED_BUILDER(mlir::qir::alloc1QubitRegister)}, + CompilerPipelineTestCase{ + "AllocQubitRegister", MQT_NAMED_BUILDER(qc::allocQubitRegister), + nullptr, MQT_NAMED_BUILDER(mlir::qc::allocQubitRegister), + MQT_NAMED_BUILDER(mlir::qir::allocQubitRegister)}, CompilerPipelineTestCase{ "AllocMultipleQubitRegisters", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegisters), nullptr, - MQT_NAMED_BUILDER(mlir::qc::emptyQC), - MQT_NAMED_BUILDER(mlir::qir::emptyQIR)}, - CompilerPipelineTestCase{"AllocLargeRegister", - MQT_NAMED_BUILDER(qc::allocLargeRegister), - nullptr, MQT_NAMED_BUILDER(mlir::qc::emptyQC), - MQT_NAMED_BUILDER(mlir::qir::emptyQIR)}, + MQT_NAMED_BUILDER(mlir::qc::allocMultipleQubitRegisters), + MQT_NAMED_BUILDER(mlir::qir::allocMultipleQubitRegisters)}, + CompilerPipelineTestCase{ + "AllocLargeRegister", MQT_NAMED_BUILDER(qc::allocLargeRegister), + nullptr, MQT_NAMED_BUILDER(mlir::qc::allocLargeRegister), + MQT_NAMED_BUILDER(mlir::qir::allocQubitRegister)}, CompilerPipelineTestCase{ "SingleMeasurementToSingleBit", MQT_NAMED_BUILDER(qc::singleMeasurementToSingleBit), nullptr, @@ -354,19 +354,20 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(qc::globalPhase), nullptr, MQT_NAMED_BUILDER(mlir::qc::globalPhase), MQT_NAMED_BUILDER(mlir::qir::globalPhase)}, - CompilerPipelineTestCase{"Identity", MQT_NAMED_BUILDER(qc::identity), - nullptr, MQT_NAMED_BUILDER(mlir::qc::emptyQC), - MQT_NAMED_BUILDER(mlir::qir::emptyQIR)}, + CompilerPipelineTestCase{ + "Identity", MQT_NAMED_BUILDER(qc::identity), nullptr, + MQT_NAMED_BUILDER(mlir::qc::alloc1QubitRegister), + MQT_NAMED_BUILDER(mlir::qir::alloc1QubitRegister)}, CompilerPipelineTestCase{ "SingleControlledIdentity", MQT_NAMED_BUILDER(qc::singleControlledIdentity), nullptr, - MQT_NAMED_BUILDER(mlir::qc::emptyQC), - MQT_NAMED_BUILDER(mlir::qir::emptyQIR)}, + MQT_NAMED_BUILDER(mlir::qc::allocQubitRegister), + MQT_NAMED_BUILDER(mlir::qir::allocQubitRegister)}, CompilerPipelineTestCase{ "MultipleControlledIdentity", MQT_NAMED_BUILDER(qc::multipleControlledIdentity), nullptr, - MQT_NAMED_BUILDER(mlir::qc::emptyQC), - MQT_NAMED_BUILDER(mlir::qir::emptyQIR)}, + MQT_NAMED_BUILDER(mlir::qc::alloc1QubitRegister), + MQT_NAMED_BUILDER(mlir::qir::alloc1QubitRegister)}, CompilerPipelineTestCase{"X", MQT_NAMED_BUILDER(qc::x), nullptr, MQT_NAMED_BUILDER(mlir::qc::x), MQT_NAMED_BUILDER(mlir::qir::x)}, diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index 3ad29bd7df..c707a7ff00 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -59,6 +59,12 @@ allocMultipleQubitRegistersWithOps(QCProgramBuilder& b) { return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}); } +std::pair, SmallVector> +alloc1QubitRegister(QCProgramBuilder& b) { + auto q = b.allocQubitRegister(1); + return measureAndReturn(b, {q[0]}); +} + std::pair, SmallVector> allocQubitRegister(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); @@ -179,8 +185,8 @@ std::pair, SmallVector> singleMeasurementToSingleBit(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); - b.measure(q[0], c[0]); - return measureAndReturn(b, {q[0]}); + const auto outcome = b.measure(q[0], c[0]); + return {{outcome}, {b.getI1Type()}}; } std::pair, SmallVector> @@ -189,18 +195,18 @@ repeatedMeasurementToSameBit(QCProgramBuilder& b) { const auto& c = b.allocClassicalBitRegister(1); b.measure(q[0], c[0]); b.measure(q[0], c[0]); - b.measure(q[0], c[0]); - return measureAndReturn(b, {q[0]}); + auto c3 = b.measure(q[0], c[0]); + return {{c3}, {b.getI1Type()}}; } std::pair, SmallVector> repeatedMeasurementToDifferentBits(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(3); - b.measure(q[0], c[0]); - b.measure(q[0], c[1]); - b.measure(q[0], c[2]); - return measureAndReturn(b, {q[0]}); + auto c1 = b.measure(q[0], c[0]); + auto c2 = b.measure(q[0], c[1]); + auto c3 = b.measure(q[0], c[2]); + return {{c1, c2, c3}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; } std::pair, SmallVector> @@ -208,17 +214,17 @@ multipleClassicalRegistersAndMeasurements(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); const auto& c0 = b.allocClassicalBitRegister(1, "c0"); const auto& c1 = b.allocClassicalBitRegister(2, "c1"); - b.measure(q[0], c0[0]); - b.measure(q[1], c1[0]); - b.measure(q[2], c1[1]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + const auto b1 = b.measure(q[0], c0[0]); + const auto b2 = b.measure(q[1], c1[0]); + const auto b3 = b.measure(q[2], c1[1]); + return {{b1, b2, b3}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; } std::pair, SmallVector> measurementWithoutRegisters(QCProgramBuilder& b) { auto q = b.allocQubit(); - b.measure(q); - return measureAndReturn(b, {q}); + auto c = b.measure(q); + return {{c}, {b.getI1Type()}}; } std::pair, SmallVector> @@ -276,7 +282,7 @@ repeatedResetAfterSingleOp(QCProgramBuilder& b) { std::pair, SmallVector> globalPhase(QCProgramBuilder& b) { b.gphase(0.123); - return measureAndReturn(b, {}); + return {{b.intConstant(0)}, {b.getI64Type()}}; } std::pair, SmallVector> diff --git a/mlir/unittests/programs/qc_programs.h b/mlir/unittests/programs/qc_programs.h index da53e92ac5..eee8754ce2 100644 --- a/mlir/unittests/programs/qc_programs.h +++ b/mlir/unittests/programs/qc_programs.h @@ -28,6 +28,10 @@ emptyQC(QCProgramBuilder& builder); std::pair, SmallVector> allocQubit(QCProgramBuilder& b); +/// Allocates a qubit register of size `1`. +std::pair, SmallVector> +alloc1QubitRegister(QCProgramBuilder& b); + /// Allocates a qubit register of size `2`. std::pair, SmallVector> allocQubitRegister(QCProgramBuilder& b); diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 2e752fd501..85b8080ed8 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -175,10 +175,10 @@ std::pair, SmallVector> repeatedMeasurementToSameBit(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); - auto [q1, c1] = b.measure(q[0], c[0]); - auto [q2, c2] = b.measure(q1, c[0]); + auto [q1, _c1] = b.measure(q[0], c[0]); + auto [q2, _c2] = b.measure(q1, c[0]); auto [q3, c3] = b.measure(q2, c[0]); - return {{c1, c2, c3}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; + return {{c3}, {b.getI1Type()}}; } std::pair, SmallVector> @@ -264,7 +264,7 @@ repeatedResetAfterSingleOp(QCOProgramBuilder& b) { std::pair, SmallVector> globalPhase(QCOProgramBuilder& b) { b.gphase(0.123); - return measureAndReturn(b, {}); + return {{b.intConstant(0)}, {b.getI64Type()}}; } std::pair, SmallVector> diff --git a/mlir/unittests/programs/qir_programs.cpp b/mlir/unittests/programs/qir_programs.cpp index 769297d3e6..8fb5b513e3 100644 --- a/mlir/unittests/programs/qir_programs.cpp +++ b/mlir/unittests/programs/qir_programs.cpp @@ -23,32 +23,99 @@ #include +/** + * @brief Creates a struct value using an `llvm.poison` operation with the given + * types. + * @param b The QIRProgramBuilder used to create the struct. + * @param types The types of the elements in the struct. + * @return The created struct value. + */ +mlir::Value createStruct(mlir::qir::QIRProgramBuilder& b, + mlir::SmallVector types) { + auto structType = + mlir::LLVM::LLVMStructType::getLiteral(b.getContext(), types); + mlir::Value structValue = mlir::LLVM::PoisonOp::create(b, structType); + return structValue; +} + +/** + * @brief Collects measurement outcomes into a struct value. + * @param b The QIRProgramBuilder used to create the struct. + * @param outcomes The measurement outcomes to be read and collected. + * @param structValue The struct value to insert the measurement outcomes into. + * @return The struct value with the measurement outcomes inserted. + */ +mlir::Value +collectMeasurementOutcomesInStruct(mlir::qir::QIRProgramBuilder& b, + mlir::SmallVector outcomes, + mlir::Value structValue) { + int64_t index = 0; + for (auto bit : outcomes) { + auto c = b.readResult(bit); + auto insert = mlir::LLVM::InsertValueOp::create( + b, structValue, c, mlir::ArrayRef(index++)); + structValue = insert.getResult(); + } + return structValue; +} + +/** + * @brief Measures the given qubits and returns the measurement outcomes as a + * struct value or a single `i1`. + * @param b The QIRProgramBuilder used to perform the measurements and create + * the struct. + * @param qubits The qubits to be measured. + * @param inRegister Whether to store the results in a classical result array or + * not. + * @return A pair containing the result value and its type. + */ static std::pair measureAndReturn(mlir::qir::QIRProgramBuilder& b, - mlir::SmallVector qubits) { + mlir::SmallVector qubits, bool inRegister) { if (qubits.empty()) { auto zeroConst = b.intConstant(0); return {zeroConst, b.getI64Type()}; } + mlir::qir::QIRProgramBuilder::ClassicalRegister resultArray; + if (inRegister) { + resultArray = b.allocClassicalBitRegister(qubits.size(), "meas"); + } + if (qubits.size() == 1) { - auto outcome = b.measure(qubits[0], 0); + auto outcome = inRegister ? b.measure(qubits[0], resultArray[0]) + : b.measure(qubits[0], 0); auto result = b.readResult(outcome); return {result, b.getI1Type()}; } llvm::SmallVector elementTypes(qubits.size(), b.getI1Type()); - auto structType = - mlir::LLVM::LLVMStructType::getLiteral(b.getContext(), elementTypes); - mlir::Value structValue = mlir::LLVM::PoisonOp::create(b, structType); + mlir::Value structValue = createStruct(b, elementTypes); for (auto i = 0L; i < qubits.size(); ++i) { - auto outcome = b.measure(qubits[i], i); + auto outcome = inRegister ? b.measure(qubits[i], resultArray[i]) + : b.measure(qubits[i], i); auto result = b.readResult(outcome); auto insert = mlir::LLVM::InsertValueOp::create(b, structValue, result, i); structValue = insert.getResult(); } - return {structValue, structType}; + return {structValue, structValue.getType()}; +} + +/** + * @brief Measures the given qubits and returns the measurement outcomes as a + * struct value or a single `i1`. + * + * @detail The measurement outcomes are stored in a classical result array. + * @param b The QIRProgramBuilder used to perform the measurements and create + * the struct. + * @param qubits The qubits to be measured. + * @return The result value and its type as a pair. + */ +static std::pair +measureAndReturn(mlir::qir::QIRProgramBuilder& b, + mlir::SmallVector qubits) { + return measureAndReturn(b, qubits, true); } namespace mlir::qir { @@ -61,6 +128,11 @@ std::pair allocQubit(QIRProgramBuilder& b) { return measureAndReturn(b, {q}); } +std::pair alloc1QubitRegister(QIRProgramBuilder& b) { + auto q = b.allocQubitRegister(1); + return measureAndReturn(b, {q[0]}); +} + std::pair allocQubitRegister(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); return measureAndReturn(b, {q[0], q[1]}); @@ -92,7 +164,7 @@ std::pair allocLargeRegister(QIRProgramBuilder& b) { std::pair staticQubits(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); - return measureAndReturn(b, {q0, q1}); + return measureAndReturn(b, {q0, q1}, false); } std::pair staticQubitsWithOps(QIRProgramBuilder& b) { @@ -100,7 +172,7 @@ std::pair staticQubitsWithOps(QIRProgramBuilder& b) { auto q1 = b.staticQubit(1); b.h(q0); b.h(q1); - return measureAndReturn(b, {q0, q1}); + return measureAndReturn(b, {q0, q1}, false); } std::pair staticQubitsWithParametricOps(QIRProgramBuilder& b) { @@ -108,27 +180,27 @@ std::pair staticQubitsWithParametricOps(QIRProgramBuilder& b) { auto q1 = b.staticQubit(1); b.rx(std::numbers::pi / 4., q0); b.p(std::numbers::pi / 2., q1); - return measureAndReturn(b, {q0, q1}); + return measureAndReturn(b, {q0, q1}, false); } std::pair staticQubitsWithTwoTargetOps(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.rzz(0.123, q0, q1); - return measureAndReturn(b, {q0, q1}); + return measureAndReturn(b, {q0, q1}, false); } std::pair staticQubitsWithCtrl(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.cx(q0, q1); - return measureAndReturn(b, {q0, q1}); + return measureAndReturn(b, {q0, q1}, false); } std::pair staticQubitsWithInv(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); b.tdg(q0); - return measureAndReturn(b, {q0}); + return measureAndReturn(b, {q0}, false); } std::pair staticQubitsWithDuplicates(QIRProgramBuilder& b) { @@ -141,7 +213,7 @@ std::pair staticQubitsWithDuplicates(QIRProgramBuilder& b) { b.rzz(0.123, q0b, q1b); b.cx(q0b, q1b); b.tdg(q0a); - return measureAndReturn(b, {q0b, q1b}); + return measureAndReturn(b, {q0b, q1b}, false); } std::pair staticQubitsCanonical(QIRProgramBuilder& b) { @@ -152,27 +224,28 @@ std::pair staticQubitsCanonical(QIRProgramBuilder& b) { b.rzz(0.123, q0, q1); b.cx(q0, q1); b.tdg(q0); - return measureAndReturn(b, {q0, q1}); + return measureAndReturn(b, {q0, q1}, false); } std::pair mixedStaticThenDynamicQubit(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.allocQubit(); - return measureAndReturn(b, {q0, q1}); + return measureAndReturn(b, {q0, q1}, false); } std::pair mixedDynamicRegisterThenStaticQubit(QIRProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); auto q1 = b.staticQubit(0); - return measureAndReturn(b, {q0[0], q0[1], q1}); + return measureAndReturn(b, {q0[0], q0[1], q1}, false); } std::pair singleMeasurementToSingleBit(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto c = b.allocClassicalBitRegister(1); - b.measure(q[0], c[0]); - return measureAndReturn(b, {q[0]}); + const auto v = b.measure(q[0], c[0]); + const auto read = b.readResult(v); + return {read, b.getI1Type()}; } std::pair repeatedMeasurementToSameBit(QIRProgramBuilder& b) { @@ -180,18 +253,23 @@ std::pair repeatedMeasurementToSameBit(QIRProgramBuilder& b) { const auto c = b.allocClassicalBitRegister(1); b.measure(q[0], c[0]); b.measure(q[0], c[0]); - b.measure(q[0], c[0]); - return measureAndReturn(b, {q[0]}); + auto b3 = b.measure(q[0], c[0]); + auto c3 = b.readResult(b3); + return {c3, b.getI1Type()}; } std::pair repeatedMeasurementToDifferentBits(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto c = b.allocClassicalBitRegister(3); - b.measure(q[0], c[0]); - b.measure(q[0], c[1]); - b.measure(q[0], c[2]); - return measureAndReturn(b, {q[0]}); + auto b1 = b.measure(q[0], c[0]); + auto b2 = b.measure(q[0], c[1]); + auto b3 = b.measure(q[0], c[2]); + auto structValue = + createStruct(b, {b.getI1Type(), b.getI1Type(), b.getI1Type()}); + auto filledStruct = + collectMeasurementOutcomesInStruct(b, {b1, b2, b3}, structValue); + return {filledStruct, filledStruct.getType()}; } std::pair @@ -199,16 +277,21 @@ multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); const auto& c0 = b.allocClassicalBitRegister(1, "c0"); const auto& c1 = b.allocClassicalBitRegister(2, "c1"); - b.measure(q[0], c0[0]); - b.measure(q[1], c1[0]); - b.measure(q[2], c1[1]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + auto b1 = b.measure(q[0], c0[0]); + auto b2 = b.measure(q[1], c1[0]); + auto b3 = b.measure(q[2], c1[1]); + auto structValue = + createStruct(b, {b.getI1Type(), b.getI1Type(), b.getI1Type()}); + auto filledStruct = + collectMeasurementOutcomesInStruct(b, {b1, b2, b3}, structValue); + return {filledStruct, filledStruct.getType()}; } std::pair measurementWithoutRegisters(QIRProgramBuilder& b) { auto q = b.allocQubit(); - b.measure(q, 0); - return measureAndReturn(b, {q}); + auto bit = b.measure(q, 0); + auto c = b.readResult(bit); + return {c, b.getI1Type()}; } std::pair resetQubitWithoutOp(QIRProgramBuilder& b) { @@ -355,7 +438,7 @@ std::pair multipleControlledH(QIRProgramBuilder& b) { std::pair hWithoutRegister(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); - return measureAndReturn(b, {q}); + return measureAndReturn(b, {q}, false); } std::pair s(QIRProgramBuilder& b) { diff --git a/mlir/unittests/programs/qir_programs.h b/mlir/unittests/programs/qir_programs.h index 80e1cea79a..de0d66d333 100644 --- a/mlir/unittests/programs/qir_programs.h +++ b/mlir/unittests/programs/qir_programs.h @@ -27,6 +27,9 @@ std::pair emptyQIR(QIRProgramBuilder& builder); /// Allocates a single qubit. std::pair allocQubit(QIRProgramBuilder& b); +/// Allocates a qubit register of size `1`. +std::pair alloc1QubitRegister(QIRProgramBuilder& b); + /// Allocates a qubit register of size `2`. std::pair allocQubitRegister(QIRProgramBuilder& b); diff --git a/mlir/unittests/programs/quantum_computation_programs.cpp b/mlir/unittests/programs/quantum_computation_programs.cpp index f0b9b305cd..133ba5e736 100644 --- a/mlir/unittests/programs/quantum_computation_programs.cpp +++ b/mlir/unittests/programs/quantum_computation_programs.cpp @@ -22,19 +22,27 @@ namespace qc { -void allocQubit(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); } +void allocQubit(QuantumComputation& comp) { + auto qr = comp.addQubitRegister(1, "q"); + comp.measureAll(true, false); +} void allocQubitRegister(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); + comp.measureAll(true, false); } void allocMultipleQubitRegisters(QuantumComputation& comp) { comp.addQubitRegister(2, "reg0"); comp.addQubitRegister(3, "reg1"); + comp.measureAll(true, false); } void allocLargeRegister(QuantumComputation& comp) { comp.addQubitRegister(100, "q"); + comp.addClassicalRegister(2, "meas"); + comp.measure(0, 0); + comp.measure(99, 1); } void singleMeasurementToSingleBit(QuantumComputation& comp) { @@ -72,6 +80,7 @@ void resetQubitAfterSingleOp(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.h(0); comp.reset(0); + comp.measureAll(true, false); } void resetMultipleQubitsAfterSingleOp(QuantumComputation& comp) { @@ -80,6 +89,7 @@ void resetMultipleQubitsAfterSingleOp(QuantumComputation& comp) { comp.reset(0); comp.h(1); comp.reset(1); + comp.measureAll(true, false); } void repeatedResetAfterSingleOp(QuantumComputation& comp) { @@ -88,6 +98,7 @@ void repeatedResetAfterSingleOp(QuantumComputation& comp) { comp.reset(0); comp.reset(0); comp.reset(0); + comp.measureAll(true, false); } void globalPhase(QuantumComputation& comp) { comp.gphase(0.123); } @@ -95,451 +106,542 @@ void globalPhase(QuantumComputation& comp) { comp.gphase(0.123); } void identity(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.i(0); + comp.measureAll(true, false); } void singleControlledIdentity(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.ci(1, 0); + comp.measureAll(true, false); } void multipleControlledIdentity(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mci({2, 1}, 0); + comp.addClassicalRegister(1, "meas"); + comp.measure(0, 0); } void x(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.x(0); + comp.measureAll(true, false); } void singleControlledX(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.cx(0, 1); + comp.measureAll(true, false); } void multipleControlledX(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcx({0, 1}, 2); + comp.measureAll(true, false); } void y(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.y(0); + comp.measureAll(true, false); } void singleControlledY(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.cy(0, 1); + comp.measureAll(true, false); } void multipleControlledY(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcy({0, 1}, 2); + comp.measureAll(true, false); } void z(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.z(0); + comp.measureAll(true, false); } void singleControlledZ(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.cz(0, 1); + comp.measureAll(true, false); } void multipleControlledZ(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcz({0, 1}, 2); + comp.measureAll(true, false); } void h(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.h(0); + comp.measureAll(true, false); } void singleControlledH(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.ch(0, 1); + comp.measureAll(true, false); } void multipleControlledH(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mch({0, 1}, 2); + comp.measureAll(true, false); } void s(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.s(0); + comp.measureAll(true, false); } void singleControlledS(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.cs(0, 1); + comp.measureAll(true, false); } void multipleControlledS(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcs({0, 1}, 2); + comp.measureAll(true, false); } void sdg(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.sdg(0); + comp.measureAll(true, false); } void singleControlledSdg(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.csdg(0, 1); + comp.measureAll(true, false); } void multipleControlledSdg(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcsdg({0, 1}, 2); + comp.measureAll(true, false); } void t_(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.t(0); + comp.measureAll(true, false); } void singleControlledT(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.ct(0, 1); + comp.measureAll(true, false); } void multipleControlledT(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mct({0, 1}, 2); + comp.measureAll(true, false); } void tdg(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.tdg(0); + comp.measureAll(true, false); } void singleControlledTdg(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.ctdg(0, 1); + comp.measureAll(true, false); } void multipleControlledTdg(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mctdg({0, 1}, 2); + comp.measureAll(true, false); } void sx(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.sx(0); + comp.measureAll(true, false); } void singleControlledSx(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.csx(0, 1); + comp.measureAll(true, false); } void multipleControlledSx(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcsx({0, 1}, 2); + comp.measureAll(true, false); } void sxdg(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.sxdg(0); + comp.measureAll(true, false); } void singleControlledSxdg(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.csxdg(0, 1); + comp.measureAll(true, false); } void multipleControlledSxdg(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcsxdg({0, 1}, 2); + comp.measureAll(true, false); } void rx(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.rx(0.123, 0); + comp.measureAll(true, false); } void singleControlledRx(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.crx(0.123, 0, 1); + comp.measureAll(true, false); } void multipleControlledRx(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcrx(0.123, {0, 1}, 2); + comp.measureAll(true, false); } void ry(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.ry(0.456, 0); + comp.measureAll(true, false); } void singleControlledRy(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.cry(0.456, 0, 1); + comp.measureAll(true, false); } void multipleControlledRy(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcry(0.456, {0, 1}, 2); + comp.measureAll(true, false); } void rz(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.rz(0.789, 0); + comp.measureAll(true, false); } void singleControlledRz(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.crz(0.789, 0, 1); + comp.measureAll(true, false); } void multipleControlledRz(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcrz(0.789, {0, 1}, 2); + comp.measureAll(true, false); } void p(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.p(0.123, 0); + comp.measureAll(true, false); } void singleControlledP(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.cp(0.123, 0, 1); + comp.measureAll(true, false); } void multipleControlledP(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcp(0.123, {0, 1}, 2); + comp.measureAll(true, false); } void r(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.r(0.123, 0.456, 0); + comp.measureAll(true, false); } void singleControlledR(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.cr(0.123, 0.456, 0, 1); + comp.measureAll(true, false); } void multipleControlledR(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcr(0.123, 0.456, {0, 1}, 2); + comp.measureAll(true, false); } void u2(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.u2(0.234, 0.567, 0); + comp.measureAll(true, false); } void singleControlledU2(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.cu2(0.234, 0.567, 0, 1); + comp.measureAll(true, false); } void multipleControlledU2(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcu2(0.234, 0.567, {0, 1}, 2); + comp.measureAll(true, false); } void u(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.u(0.1, 0.2, 0.3, 0); + comp.measureAll(true, false); } void singleControlledU(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.cu(0.1, 0.2, 0.3, 0, 1); + comp.measureAll(true, false); } void multipleControlledU(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.mcu(0.1, 0.2, 0.3, {0, 1}, 2); + comp.measureAll(true, false); } void swap(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.swap(0, 1); + comp.measureAll(true, false); } void singleControlledSwap(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.cswap(0, 1, 2); + comp.measureAll(true, false); } void multipleControlledSwap(QuantumComputation& comp) { comp.addQubitRegister(4, "q"); comp.mcswap({0, 1}, 2, 3); + comp.measureAll(true, false); } void iswap(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.iswap(0, 1); + comp.measureAll(true, false); } void singleControlledIswap(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.ciswap(0, 1, 2); + comp.measureAll(true, false); } void multipleControlledIswap(QuantumComputation& comp) { comp.addQubitRegister(4, "q"); comp.mciswap({0, 1}, 2, 3); + comp.measureAll(true, false); } void inverseIswap(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.iswapdg(0, 1); + comp.measureAll(true, false); } void inverseMultipleControlledIswap(QuantumComputation& comp) { comp.addQubitRegister(4, "q"); comp.mciswapdg({0, 1}, 2, 3); + comp.measureAll(true, false); } void dcx(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.dcx(0, 1); + comp.measureAll(true, false); } void singleControlledDcx(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.cdcx(0, 1, 2); + comp.measureAll(true, false); } void multipleControlledDcx(QuantumComputation& comp) { comp.addQubitRegister(4, "q"); comp.mcdcx({0, 1}, 2, 3); + comp.measureAll(true, false); } void ecr(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.ecr(0, 1); + comp.measureAll(true, false); } void singleControlledEcr(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.cecr(0, 1, 2); + comp.measureAll(true, false); } void multipleControlledEcr(QuantumComputation& comp) { comp.addQubitRegister(4, "q"); comp.mcecr({0, 1}, 2, 3); + comp.measureAll(true, false); } void rxx(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.rxx(0.123, 0, 1); + comp.measureAll(true, false); } void singleControlledRxx(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.crxx(0.123, 0, 1, 2); + comp.measureAll(true, false); } void multipleControlledRxx(QuantumComputation& comp) { comp.addQubitRegister(4, "q"); comp.mcrxx(0.123, {0, 1}, 2, 3); + comp.measureAll(true, false); } void tripleControlledRxx(QuantumComputation& comp) { comp.addQubitRegister(5, "q"); comp.mcrxx(0.123, {0, 1, 2}, 3, 4); + comp.measureAll(true, false); } void ryy(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.ryy(0.123, 0, 1); + comp.measureAll(true, false); } void singleControlledRyy(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.cryy(0.123, 0, 1, 2); + comp.measureAll(true, false); } void multipleControlledRyy(QuantumComputation& comp) { comp.addQubitRegister(4, "q"); comp.mcryy(0.123, {0, 1}, 2, 3); + comp.measureAll(true, false); } void rzx(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.rzx(0.123, 0, 1); + comp.measureAll(true, false); } void singleControlledRzx(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.crzx(0.123, 0, 1, 2); + comp.measureAll(true, false); } void multipleControlledRzx(QuantumComputation& comp) { comp.addQubitRegister(4, "q"); comp.mcrzx(0.123, {0, 1}, 2, 3); + comp.measureAll(true, false); } void rzz(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.rzz(0.123, 0, 1); + comp.measureAll(true, false); } void singleControlledRzz(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.crzz(0.123, 0, 1, 2); + comp.measureAll(true, false); } void multipleControlledRzz(QuantumComputation& comp) { comp.addQubitRegister(4, "q"); comp.mcrzz(0.123, {0, 1}, 2, 3); + comp.measureAll(true, false); } void xxPlusYY(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.xx_plus_yy(0.123, 0.456, 0, 1); + comp.measureAll(true, false); } void singleControlledXxPlusYY(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.cxx_plus_yy(0.123, 0.456, 0, 1, 2); + comp.measureAll(true, false); } void multipleControlledXxPlusYY(QuantumComputation& comp) { comp.addQubitRegister(4, "q"); comp.mcxx_plus_yy(0.123, 0.456, {0, 1}, 2, 3); + comp.measureAll(true, false); } void xxMinusYY(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.xx_minus_yy(0.123, 0.456, 0, 1); + comp.measureAll(true, false); } void singleControlledXxMinusYY(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.cxx_minus_yy(0.123, 0.456, 0, 1, 2); + comp.measureAll(true, false); } void multipleControlledXxMinusYY(QuantumComputation& comp) { comp.addQubitRegister(4, "q"); comp.mcxx_minus_yy(0.123, 0.456, {0, 1}, 2, 3); + comp.measureAll(true, false); } void barrier(QuantumComputation& comp) { comp.addQubitRegister(1, "q"); comp.barrier(0); + comp.measureAll(true, false); } void barrierTwoQubits(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); comp.barrier({0, 1}); + comp.measureAll(true, false); } void barrierMultipleQubits(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); comp.barrier({0, 1, 2}); + comp.measureAll(true, false); } void ctrlTwo(QuantumComputation& comp) { @@ -551,6 +653,7 @@ void ctrlTwo(QuantumComputation& comp) { compound.addControl(0); compound.addControl(1); comp.emplace_back(std::move(compound)); + comp.measureAll(true, false); } void ctrlTwoMixed(QuantumComputation& comp) { @@ -562,6 +665,7 @@ void ctrlTwoMixed(QuantumComputation& comp) { compound.addControl(0); compound.addControl(1); comp.emplace_back(std::move(compound)); + comp.measureAll(true, false); } void simpleIf(QuantumComputation& comp) { @@ -570,6 +674,7 @@ void simpleIf(QuantumComputation& comp) { comp.h(q[0]); comp.measure(q[0], c[0]); comp.if_(X, q[0], c[0]); + comp.measureAll(true, false); } void ifTwoQubits(QuantumComputation& comp) { @@ -583,6 +688,7 @@ void ifTwoQubits(QuantumComputation& comp) { IfElseOperation ifElse( std::make_unique(std::move(compound)), nullptr, c[0]); comp.emplace_back(std::move(ifElse)); + comp.measureAll(true, false); } void ifElse(QuantumComputation& comp) { @@ -592,6 +698,7 @@ void ifElse(QuantumComputation& comp) { comp.measure(q[0], c[0]); comp.ifElse(std::make_unique(q[0], X), std::make_unique(q[0], Z), c[0]); + comp.measureAll(true, false); } } // namespace qc diff --git a/src/ir/QuantumComputation.cpp b/src/ir/QuantumComputation.cpp index e0b63f17b0..7b018582fd 100644 --- a/src/ir/QuantumComputation.cpp +++ b/src/ir/QuantumComputation.cpp @@ -1541,7 +1541,7 @@ void QuantumComputation::measure(const Targets& qubits, emplace_back(qubits, bits); } -void QuantumComputation::measureAll(const bool addBits) { +void QuantumComputation::measureAll(const bool addBits, const bool addBarrier) { if (addBits) { addClassicalRegister(getNqubits(), "meas"); } @@ -1553,7 +1553,9 @@ void QuantumComputation::measureAll(const bool addBits) { throw std::runtime_error(ss.str()); } - barrier(); + if (addBarrier) { + barrier(); + } Qubit start = 0U; if (addBits) { start = static_cast(classicalRegisters.at("meas").getStartIndex()); From 8726654518870b7b67afbf83b960d64eaa77cd97 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Wed, 24 Jun 2026 16:58:39 +0200 Subject: [PATCH 32/80] fix(mlir): :bug: fix issues with qco_ir_matrix --- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 12 ++-- .../Dialect/QCO/IR/test_qco_ir_matrix.cpp | 35 +++++------ mlir/unittests/programs/qco_programs.cpp | 58 +++++++++++-------- 3 files changed, 54 insertions(+), 51 deletions(-) diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index f6a39ada17..6e10f8c1d0 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -78,8 +78,7 @@ TEST_P(QCOTest, ProgramEquivalence) { const auto name = " (" + GetParam().name + ")"; mqt::test::DeferredPrinter printer; - auto program = - QCOProgramBuilder::buildWithReturn(context.get(), programBuilder.fn); + auto program = QCOProgramBuilder::build(context.get(), programBuilder.fn); ASSERT_TRUE(program); printer.record(program.get(), "Original QCO IR" + name); EXPECT_TRUE(verify(*program).succeeded()); @@ -88,8 +87,7 @@ TEST_P(QCOTest, ProgramEquivalence) { printer.record(program.get(), "Canonicalized QCO IR" + name); EXPECT_TRUE(verify(*program).succeeded()); - auto reference = - QCOProgramBuilder::buildWithReturn(context.get(), referenceBuilder.fn); + auto reference = QCOProgramBuilder::build(context.get(), referenceBuilder.fn); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QCO IR" + name); EXPECT_TRUE(verify(*reference).succeeded()); @@ -261,8 +259,8 @@ TEST_F(QCOTest, DirectIfBuilder) { EXPECT_TRUE(runQCOCleanupPipeline(directBuilder.get()).succeeded()); EXPECT_TRUE(verify(*directBuilder).succeeded()); - auto refBuilder = QCOProgramBuilder::buildWithReturn( - context.get(), MQT_NAMED_BUILDER(simpleIf).fn); + auto refBuilder = + QCOProgramBuilder::build(context.get(), MQT_NAMED_BUILDER(simpleIf).fn); ASSERT_TRUE(refBuilder); EXPECT_TRUE(verify(*refBuilder).succeeded()); EXPECT_TRUE(runQCOCleanupPipeline(refBuilder.get()).succeeded()); @@ -306,7 +304,7 @@ TEST_F(QCOTest, IfOpParser) { EXPECT_TRUE(runQCOCleanupPipeline(parsedSourceModule.get()).succeeded()); EXPECT_TRUE(verify(*parsedSourceModule).succeeded()); - auto refBuilder = QCOProgramBuilder::buildWithReturn( + auto refBuilder = QCOProgramBuilder::build( context.get(), MQT_NAMED_BUILDER(ifOneQubitOneTensor).fn); ASSERT_TRUE(refBuilder); EXPECT_TRUE(verify(*refBuilder).succeeded()); diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp index 19251af49e..a381a343ea 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp @@ -78,8 +78,7 @@ class QCOMatrixTest : public testing::TestWithParam { /// \name QCO/Modifiers/CtrlOp.cpp /// @{ TEST_F(QCOMatrixTest, CXOpMatrix) { - auto moduleOp = - QCOProgramBuilder::buildWithReturn(context.get(), singleControlledX); + auto moduleOp = QCOProgramBuilder::build(context.get(), singleControlledX); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -102,8 +101,7 @@ TEST_F(QCOMatrixTest, CXOpMatrix) { /// \name QCO/Modifiers/InvOp.cpp /// @{ TEST_F(QCOMatrixTest, InverseIswapOpMatrix) { - auto moduleOp = - QCOProgramBuilder::buildWithReturn(context.get(), inverseIswap); + auto moduleOp = QCOProgramBuilder::build(context.get(), inverseIswap); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -156,8 +154,7 @@ TEST_F(QCOMatrixTest, ECROpMatrix) { /// \name QCO/Operations/StandardGates/GphaseOp.cpp /// @{ TEST_F(QCOMatrixTest, GPhaseOpMatrix) { - auto moduleOp = - QCOProgramBuilder::buildWithReturn(context.get(), globalPhase); + auto moduleOp = QCOProgramBuilder::build(context.get(), globalPhase); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -222,7 +219,7 @@ TEST_F(QCOMatrixTest, iSWAPOpMatrix) { /// \name QCO/Operations/StandardGates/POp.cpp /// @{ TEST_F(QCOMatrixTest, POpMatrix) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), p); + auto moduleOp = QCOProgramBuilder::build(context.get(), p); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -242,7 +239,7 @@ TEST_F(QCOMatrixTest, POpMatrix) { /// \name QCO/Operations/StandardGates/ROp.cpp /// @{ TEST_F(QCOMatrixTest, ROpMatrix) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), r); + auto moduleOp = QCOProgramBuilder::build(context.get(), r); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -262,7 +259,7 @@ TEST_F(QCOMatrixTest, ROpMatrix) { /// \name QCO/Operations/StandardGates/RxOp.cpp /// @{ TEST_F(QCOMatrixTest, RXOpMatrix) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), rx); + auto moduleOp = QCOProgramBuilder::build(context.get(), rx); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -283,7 +280,7 @@ TEST_F(QCOMatrixTest, RXOpMatrix) { /// \name QCO/Operations/StandardGates/RxxOp.cpp /// @{ TEST_F(QCOMatrixTest, RXXOpMatrix) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), rxx); + auto moduleOp = QCOProgramBuilder::build(context.get(), rxx); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -303,7 +300,7 @@ TEST_F(QCOMatrixTest, RXXOpMatrix) { /// \name QCO/Operations/StandardGates/RyOp.cpp /// @{ TEST_F(QCOMatrixTest, RYOpMatrix) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), ry); + auto moduleOp = QCOProgramBuilder::build(context.get(), ry); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -324,7 +321,7 @@ TEST_F(QCOMatrixTest, RYOpMatrix) { /// \name QCO/Operations/StandardGates/RyyOp.cpp /// @{ TEST_F(QCOMatrixTest, RYYOpMatrix) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), ryy); + auto moduleOp = QCOProgramBuilder::build(context.get(), ryy); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -344,7 +341,7 @@ TEST_F(QCOMatrixTest, RYYOpMatrix) { /// \name QCO/Operations/StandardGates/RzOp.cpp /// @{ TEST_F(QCOMatrixTest, RZOpMatrix) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), rz); + auto moduleOp = QCOProgramBuilder::build(context.get(), rz); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -365,7 +362,7 @@ TEST_F(QCOMatrixTest, RZOpMatrix) { /// \name QCO/Operations/StandardGates/RzxOp.cpp /// @{ TEST_F(QCOMatrixTest, RZXOpMatrix) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), rzx); + auto moduleOp = QCOProgramBuilder::build(context.get(), rzx); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -385,7 +382,7 @@ TEST_F(QCOMatrixTest, RZXOpMatrix) { /// \name QCO/Operations/StandardGates/RzzOp.cpp /// @{ TEST_F(QCOMatrixTest, RZZOpMatrix) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), rzz); + auto moduleOp = QCOProgramBuilder::build(context.get(), rzz); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -510,7 +507,7 @@ TEST_F(QCOMatrixTest, TdgOpMatrix) { /// \name QCO/Operations/StandardGates/U2Op.cpp /// @{ TEST_F(QCOMatrixTest, U2OpMatrix) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), u2); + auto moduleOp = QCOProgramBuilder::build(context.get(), u2); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -531,7 +528,7 @@ TEST_F(QCOMatrixTest, U2OpMatrix) { /// \name QCO/Operations/StandardGates/UOp.cpp /// @{ TEST_F(QCOMatrixTest, UOpMatrix) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), u); + auto moduleOp = QCOProgramBuilder::build(context.get(), u); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -567,7 +564,7 @@ TEST_F(QCOMatrixTest, XOpMatrix) { /// \name QCO/Operations/StandardGates/XxMinusYyOp.cpp /// @{ TEST_F(QCOMatrixTest, XXMinusYYOpMatrix) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), xxMinusYY); + auto moduleOp = QCOProgramBuilder::build(context.get(), xxMinusYY); ASSERT_TRUE(moduleOp); // Get the operation from the module @@ -588,7 +585,7 @@ TEST_F(QCOMatrixTest, XXMinusYYOpMatrix) { /// \name QCO/Operations/StandardGates/XxPlusYyOp.cpp /// @{ TEST_F(QCOMatrixTest, XXPlusYYOp) { - auto moduleOp = QCOProgramBuilder::buildWithReturn(context.get(), xxPlusYY); + auto moduleOp = QCOProgramBuilder::build(context.get(), xxPlusYY); ASSERT_TRUE(moduleOp); // Get the operation from the module diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 85b8080ed8..6848ffc420 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -287,7 +287,7 @@ inverseGlobalPhase(QCOProgramBuilder& b) { b.gphase(-0.123); return SmallVector{}; }); - return measureAndReturn(b, {}); + return {{b.intConstant(0)}, {b.getI64Type()}}; } std::pair, SmallVector> @@ -472,23 +472,23 @@ std::pair, SmallVector> twoX(QCOProgramBuilder& b) { std::pair, SmallVector> controlledTwoX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.ctrl(q[0], q[1], [&](ValueRange targets) { + auto res = b.ctrl(q[0], q[1], [&](ValueRange targets) { auto q = b.x(targets[0]); q = b.x(q); return SmallVector{q}; }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {res.first[0], res.second[0]}); } std::pair, SmallVector> inverseTwoX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv(q[0], [&](ValueRange qubits) { + auto res = b.inv(q[0], [&](ValueRange qubits) { auto q = b.x(qubits[0]); q = b.x(q); return SmallVector{q}; }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res[0]}); } std::pair, SmallVector> y(QCOProgramBuilder& b) { @@ -3005,8 +3005,9 @@ std::pair, SmallVector> emptyCtrl(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rxx(0.123, q[0], q[1]); - b.ctrl(q[0], q[1], [&](ValueRange targets) { return targets; }); - return measureAndReturn(b, {q[0], q[1]}); + auto [res0, res1] = + b.ctrl(q[0], q[1], [&](ValueRange targets) { return targets; }); + return measureAndReturn(b, {res0[0], res1[0]}); } std::pair, SmallVector> @@ -3107,33 +3108,35 @@ ctrlInvSandwich(QCOProgramBuilder& b) { std::pair, SmallVector> ctrlTwo(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.ctrl({q[0], q[1]}, {q[2], q[3]}, [&](ValueRange targets) { + auto res = b.ctrl({q[0], q[1]}, {q[2], q[3]}, [&](ValueRange targets) { auto i0 = targets[0]; auto i1 = targets[1]; i0 = b.x(i0); std::tie(i0, i1) = b.rxx(0.123, i0, i1); return SmallVector{i0, i1}; }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn( + b, {res.first[0], res.first[1], res.second[0], res.second[1]}); } std::pair, SmallVector> ctrlTwoMixed(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.ctrl({q[0], q[1]}, {q[2], q[3]}, [&](ValueRange targets) { + auto res = b.ctrl({q[0], q[1]}, {q[2], q[3]}, [&](ValueRange targets) { auto i0 = targets[0]; auto i1 = targets[1]; std::tie(i0, i1) = b.cx(i0, i1); std::tie(i0, i1) = b.rxx(0.123, i0, i1); return SmallVector{i0, i1}; }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn( + b, {res.first[0], res.first[1], res.second[0], res.second[1]}); } std::pair, SmallVector> nestedCtrlTwo(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - b.ctrl(q[0], {q[1], q[2], q[3]}, [&](ValueRange targets) { + auto res = b.ctrl(q[0], {q[1], q[2], q[3]}, [&](ValueRange targets) { const auto& [controlsOut, targetsOut] = b.ctrl( targets[0], {targets[1], targets[2]}, [&](ValueRange innerTargets) { auto i0 = innerTargets[0]; @@ -3144,13 +3147,14 @@ nestedCtrlTwo(QCOProgramBuilder& b) { }); return llvm::to_vector(llvm::concat(controlsOut, targetsOut)); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn( + b, {res.first[0], res.second[0], res.second[1], res.second[2]}); } std::pair, SmallVector> ctrlInvTwo(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.ctrl(q[0], {q[1], q[2]}, [&](ValueRange targets) { + auto res = b.ctrl(q[0], {q[1], q[2]}, [&](ValueRange targets) { auto inner = b.inv(targets, [&](ValueRange qubits) { auto i0 = qubits[0]; auto i1 = qubits[1]; @@ -3160,15 +3164,15 @@ ctrlInvTwo(QCOProgramBuilder& b) { }); return llvm::to_vector(inner); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {res.first[0], res.second[0], res.second[1]}); } std::pair, SmallVector> emptyInv(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rxx(0.123, q[0], q[1]); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { return qubits; }); - return measureAndReturn(b, {q[0], q[1]}); + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { return qubits; }); + return measureAndReturn(b, {res[0], res[1]}); } std::pair, SmallVector> @@ -3229,20 +3233,20 @@ invCtrlSandwich(QCOProgramBuilder& b) { std::pair, SmallVector> invTwo(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto i0 = qubits[0]; auto i1 = qubits[1]; i0 = b.x(i0); std::tie(i0, i1) = b.rxx(0.123, i0, i1); return SmallVector{i0, i1}; }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {res[0], res[1]}); } std::pair, SmallVector> invCtrlTwo(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.ctrl({qubits[0]}, {qubits[1], qubits[2]}, [&](ValueRange targets) { auto i0 = targets[0]; @@ -3253,7 +3257,7 @@ invCtrlTwo(QCOProgramBuilder& b) { }); return llvm::to_vector(llvm::concat(controlsOut, targetsOut)); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {res[0], res[1], res[2]}); } std::pair, SmallVector> @@ -3502,7 +3506,8 @@ qtensorChain(QCOProgramBuilder& b) { return measureAndReturn(b, {}); } -void qtensorAlternativeChain(QCOProgramBuilder& b) { +std::pair, SmallVector> +qtensorAlternativeChain(QCOProgramBuilder& b) { Value q0; Value q1; Value q2; @@ -3522,7 +3527,8 @@ void qtensorAlternativeChain(QCOProgramBuilder& b) { return measureAndReturn(b, {}); } -void simpleWhileReset(QCOProgramBuilder& b) { +std::pair, SmallVector> +simpleWhileReset(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.h(q0); auto scfWhile = b.scfWhile( @@ -3694,14 +3700,15 @@ nestedIfOpForLoop(QCOProgramBuilder& b) { return measureAndReturn(b, {ifRes[0], ifRes[1]}); } -void nestedIfOpForLoopWithAngle(QCOProgramBuilder& b) { +std::pair, SmallVector> +nestedIfOpForLoopWithAngle(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); auto theta1 = b.floatConstant(0.123); auto theta2 = b.floatConstant(0.456); auto q1 = b.h(q0); auto [q2, cond] = b.measure(q1); - b.qcoIf( + auto res = b.qcoIf( cond, {reg.value, q2}, [&](ValueRange args) { auto q3 = b.rx(theta1, args[1]); @@ -3717,6 +3724,7 @@ void nestedIfOpForLoopWithAngle(QCOProgramBuilder& b) { }); return SmallVector{scfFor[0], args[1]}; }); + return measureAndReturn(b, {res[0]}); } } // namespace mlir::qco From 2851aeef34e0545c438355d87e04ed2d14f36efe Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 25 Jun 2026 14:52:29 +0200 Subject: [PATCH 33/80] test(mlir): :white_check_mark: pass QC->QCO and QC->QIR-Adaptive tests --- .../Conversion/QCToQCO/test_qc_to_qco.cpp | 4 +- .../test_qc_to_qir_adaptive.cpp | 551 ++++++++------- mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp | 6 +- mlir/unittests/programs/qc_programs.cpp | 13 +- mlir/unittests/programs/qco_programs.cpp | 34 +- mlir/unittests/programs/qir_programs.cpp | 646 ++++++++++++++---- mlir/unittests/programs/qir_programs.h | 129 ++++ 7 files changed, 956 insertions(+), 427 deletions(-) diff --git a/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp b/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp index cae1dc0009..03ff96e5b1 100644 --- a/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp +++ b/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp @@ -144,7 +144,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(qco::staticQubitsWithInv)}, QCToQCOTestCase{"AllocDeallocPair", MQT_NAMED_BUILDER(qc::allocDeallocPair), - MQT_NAMED_BUILDER(qco::allocSinkPair)})); + MQT_NAMED_BUILDER(qco::emptyQCO)})); /// @} /// \name QCToQCO/Modifiers/CtrlOp.cpp @@ -252,7 +252,7 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(QCIDOpTest, QCToQCOTest, testing::Values(QCToQCOTestCase{ "Identity", MQT_NAMED_BUILDER(qc::identity), - MQT_NAMED_BUILDER(qco::emptyQCO)})); + MQT_NAMED_BUILDER(qco::alloc1QubitRegister)})); /// @} /// \name QCToQCO/Operations/StandardGates/IswapOp.cpp diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp index ffc609fadf..6fe05636f9 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp @@ -45,7 +45,8 @@ struct QCToQIRAdaptiveTestCase { mqt::test::NamedBuilder, SmallVector>> programBuilder; - mqt::test::NamedBuilder referenceBuilder; + mqt::test::NamedBuilder> + referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCToQIRAdaptiveTestCase& info); @@ -126,17 +127,20 @@ TEST_P(QCToQIRAdaptiveTest, ProgramEquivalence) { INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveBarrierOpTest, QCToQIRAdaptiveTest, testing::Values( - QCToQIRAdaptiveTestCase{"Barrier", MQT_NAMED_BUILDER(qc::barrier), - MQT_NAMED_BUILDER(qir::emptyQIR)}, - QCToQIRAdaptiveTestCase{"BarrierTwoQubits", - MQT_NAMED_BUILDER(qc::barrierTwoQubits), - MQT_NAMED_BUILDER(qir::emptyQIR)}, - QCToQIRAdaptiveTestCase{"BarrierMultipleQubits", - MQT_NAMED_BUILDER(qc::barrierMultipleQubits), - MQT_NAMED_BUILDER(qir::emptyQIR)}, - QCToQIRAdaptiveTestCase{"SingleControlledBarrier", - MQT_NAMED_BUILDER(qc::singleControlledBarrier), - MQT_NAMED_BUILDER(qir::emptyQIR)})); + QCToQIRAdaptiveTestCase{ + "Barrier", MQT_NAMED_BUILDER(qc::barrier), + MQT_NAMED_BUILDER(qir::alloc1QubitRegister)}, + QCToQIRAdaptiveTestCase{ + "BarrierTwoQubits", MQT_NAMED_BUILDER(qc::barrierTwoQubits), + MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + QCToQIRAdaptiveTestCase{ + "BarrierMultipleQubits", + MQT_NAMED_BUILDER(qc::barrierMultipleQubits), + MQT_NAMED_BUILDER(qir::alloc3QubitRegister)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledBarrier", + MQT_NAMED_BUILDER(qc::singleControlledBarrier), + MQT_NAMED_BUILDER(qir::allocQubitRegister)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/DcxOp.cpp @@ -144,15 +148,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveDCXOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"DCX", MQT_NAMED_BUILDER(qc::dcx), - MQT_NAMED_BUILDER(qir::dcx)}, + MQT_NAMED_BUILDER(qir::dcx)}, QCToQIRAdaptiveTestCase{ "SingleControlledDCX", MQT_NAMED_BUILDER(qc::singleControlledDcx), - MQT_NAMED_BUILDER(qir::singleControlledDcx)}, + MQT_NAMED_BUILDER(qir::singleControlledDcx)}, QCToQIRAdaptiveTestCase{ "MultipleControlledDCX", MQT_NAMED_BUILDER(qc::multipleControlledDcx), - MQT_NAMED_BUILDER(qir::multipleControlledDcx)})); + MQT_NAMED_BUILDER(qir::multipleControlledDcx)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/EcrOp.cpp @@ -160,15 +164,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveECROpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"ECR", MQT_NAMED_BUILDER(qc::ecr), - MQT_NAMED_BUILDER(qir::ecr)}, + MQT_NAMED_BUILDER(qir::ecr)}, QCToQIRAdaptiveTestCase{ "SingleControlledECR", MQT_NAMED_BUILDER(qc::singleControlledEcr), - MQT_NAMED_BUILDER(qir::singleControlledEcr)}, + MQT_NAMED_BUILDER(qir::singleControlledEcr)}, QCToQIRAdaptiveTestCase{ "MultipleControlledECR", MQT_NAMED_BUILDER(qc::multipleControlledEcr), - MQT_NAMED_BUILDER(qir::multipleControlledEcr)})); + MQT_NAMED_BUILDER(qir::multipleControlledEcr)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/GphaseOp.cpp @@ -176,7 +180,7 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(QCToQIRAdaptiveGPhaseOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{ "GlobalPhase", MQT_NAMED_BUILDER(qc::globalPhase), - MQT_NAMED_BUILDER(qir::globalPhase)})); + MQT_NAMED_BUILDER(qir::globalPhase)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/HOp.cpp @@ -185,16 +189,16 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveHOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"H", MQT_NAMED_BUILDER(qc::h), - MQT_NAMED_BUILDER(qir::h)}, - QCToQIRAdaptiveTestCase{"SingleControlledH", - MQT_NAMED_BUILDER(qc::singleControlledH), - MQT_NAMED_BUILDER(qir::singleControlledH)}, - QCToQIRAdaptiveTestCase{"MultipleControlledH", - MQT_NAMED_BUILDER(qc::multipleControlledH), - MQT_NAMED_BUILDER(qir::multipleControlledH)}, - QCToQIRAdaptiveTestCase{"HWithoutRegister", - MQT_NAMED_BUILDER(qc::hWithoutRegister), - MQT_NAMED_BUILDER(qir::hWithoutRegister)})); + MQT_NAMED_BUILDER(qir::h)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledH", MQT_NAMED_BUILDER(qc::singleControlledH), + MQT_NAMED_BUILDER(qir::singleControlledH)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledH", MQT_NAMED_BUILDER(qc::multipleControlledH), + MQT_NAMED_BUILDER(qir::multipleControlledH)}, + QCToQIRAdaptiveTestCase{ + "HWithoutRegister", MQT_NAMED_BUILDER(qc::hWithoutRegister), + MQT_NAMED_BUILDER(qir::hWithoutRegister)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/IdOp.cpp @@ -203,14 +207,15 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveIDOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"Identity", MQT_NAMED_BUILDER(qc::identity), - MQT_NAMED_BUILDER(qir::identity)}, - QCToQIRAdaptiveTestCase{"SingleControlledIdentity", - MQT_NAMED_BUILDER(qc::singleControlledIdentity), - MQT_NAMED_BUILDER(qir::identity)}, + MQT_NAMED_BUILDER(qir::identity)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledIdentity", + MQT_NAMED_BUILDER(qc::singleControlledIdentity), + MQT_NAMED_BUILDER(qir::twoQubitsOneIdentity)}, QCToQIRAdaptiveTestCase{ "MultipleControlledIdentity", MQT_NAMED_BUILDER(qc::multipleControlledIdentity), - MQT_NAMED_BUILDER(qir::identity)})); + MQT_NAMED_BUILDER(qir::threeQubitsOneIdentity)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/IswapOp.cpp @@ -219,59 +224,63 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveiSWAPOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"iSWAP", MQT_NAMED_BUILDER(qc::iswap), - MQT_NAMED_BUILDER(qir::iswap)}, - QCToQIRAdaptiveTestCase{"SingleControllediSWAP", - MQT_NAMED_BUILDER(qc::singleControlledIswap), - MQT_NAMED_BUILDER(qir::singleControlledIswap)}, + MQT_NAMED_BUILDER(qir::iswap)}, + QCToQIRAdaptiveTestCase{ + "SingleControllediSWAP", + MQT_NAMED_BUILDER(qc::singleControlledIswap), + MQT_NAMED_BUILDER(qir::singleControlledIswap)}, QCToQIRAdaptiveTestCase{ "MultipleControllediSWAP", MQT_NAMED_BUILDER(qc::multipleControlledIswap), - MQT_NAMED_BUILDER(qir::multipleControlledIswap)})); + MQT_NAMED_BUILDER(qir::multipleControlledIswap)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/POp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptivePOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"P", MQT_NAMED_BUILDER(qc::p), - MQT_NAMED_BUILDER(qir::p)}, - QCToQIRAdaptiveTestCase{"SingleControlledP", - MQT_NAMED_BUILDER(qc::singleControlledP), - MQT_NAMED_BUILDER(qir::singleControlledP)}, - QCToQIRAdaptiveTestCase{"MultipleControlledP", - MQT_NAMED_BUILDER(qc::multipleControlledP), - MQT_NAMED_BUILDER(qir::multipleControlledP)})); + testing::Values(QCToQIRAdaptiveTestCase{"P", MQT_NAMED_BUILDER(qc::p), + MQT_NAMED_BUILDER(qir::p)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledP", + MQT_NAMED_BUILDER(qc::singleControlledP), + MQT_NAMED_BUILDER(qir::singleControlledP)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledP", + MQT_NAMED_BUILDER(qc::multipleControlledP), + MQT_NAMED_BUILDER(qir::multipleControlledP)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/ROp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveROpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"R", MQT_NAMED_BUILDER(qc::r), - MQT_NAMED_BUILDER(qir::r)}, - QCToQIRAdaptiveTestCase{"SingleControlledR", - MQT_NAMED_BUILDER(qc::singleControlledR), - MQT_NAMED_BUILDER(qir::singleControlledR)}, - QCToQIRAdaptiveTestCase{"MultipleControlledR", - MQT_NAMED_BUILDER(qc::multipleControlledR), - MQT_NAMED_BUILDER(qir::multipleControlledR)})); + testing::Values(QCToQIRAdaptiveTestCase{"R", MQT_NAMED_BUILDER(qc::r), + MQT_NAMED_BUILDER(qir::r)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledR", + MQT_NAMED_BUILDER(qc::singleControlledR), + MQT_NAMED_BUILDER(qir::singleControlledR)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledR", + MQT_NAMED_BUILDER(qc::multipleControlledR), + MQT_NAMED_BUILDER(qir::multipleControlledR)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRXOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"RX", MQT_NAMED_BUILDER(qc::rx), - MQT_NAMED_BUILDER(qir::rx)}, - QCToQIRAdaptiveTestCase{"SingleControlledRX", - MQT_NAMED_BUILDER(qc::singleControlledRx), - MQT_NAMED_BUILDER(qir::singleControlledRx)}, - QCToQIRAdaptiveTestCase{"MultipleControlledRX", - MQT_NAMED_BUILDER(qc::multipleControlledRx), - MQT_NAMED_BUILDER(qir::multipleControlledRx)})); + testing::Values(QCToQIRAdaptiveTestCase{"RX", MQT_NAMED_BUILDER(qc::rx), + MQT_NAMED_BUILDER(qir::rx)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledRX", + MQT_NAMED_BUILDER(qc::singleControlledRx), + MQT_NAMED_BUILDER(qir::singleControlledRx)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledRX", + MQT_NAMED_BUILDER(qc::multipleControlledRx), + MQT_NAMED_BUILDER(qir::multipleControlledRx)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RxxOp.cpp @@ -279,30 +288,31 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRXXOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"RXX", MQT_NAMED_BUILDER(qc::rxx), - MQT_NAMED_BUILDER(qir::rxx)}, + MQT_NAMED_BUILDER(qir::rxx)}, QCToQIRAdaptiveTestCase{ "SingleControlledRXX", MQT_NAMED_BUILDER(qc::singleControlledRxx), - MQT_NAMED_BUILDER(qir::singleControlledRxx)}, + MQT_NAMED_BUILDER(qir::singleControlledRxx)}, QCToQIRAdaptiveTestCase{ "MultipleControlledRXX", MQT_NAMED_BUILDER(qc::multipleControlledRxx), - MQT_NAMED_BUILDER(qir::multipleControlledRxx)})); + MQT_NAMED_BUILDER(qir::multipleControlledRxx)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRYOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"RY", MQT_NAMED_BUILDER(qc::ry), - MQT_NAMED_BUILDER(qir::ry)}, - QCToQIRAdaptiveTestCase{"SingleControlledRY", - MQT_NAMED_BUILDER(qc::singleControlledRy), - MQT_NAMED_BUILDER(qir::singleControlledRy)}, - QCToQIRAdaptiveTestCase{"MultipleControlledRY", - MQT_NAMED_BUILDER(qc::multipleControlledRy), - MQT_NAMED_BUILDER(qir::multipleControlledRy)})); + testing::Values(QCToQIRAdaptiveTestCase{"RY", MQT_NAMED_BUILDER(qc::ry), + MQT_NAMED_BUILDER(qir::ry)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledRY", + MQT_NAMED_BUILDER(qc::singleControlledRy), + MQT_NAMED_BUILDER(qir::singleControlledRy)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledRY", + MQT_NAMED_BUILDER(qc::multipleControlledRy), + MQT_NAMED_BUILDER(qir::multipleControlledRy)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RyyOp.cpp @@ -310,30 +320,31 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRYYOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"RYY", MQT_NAMED_BUILDER(qc::ryy), - MQT_NAMED_BUILDER(qir::ryy)}, + MQT_NAMED_BUILDER(qir::ryy)}, QCToQIRAdaptiveTestCase{ "SingleControlledRYY", MQT_NAMED_BUILDER(qc::singleControlledRyy), - MQT_NAMED_BUILDER(qir::singleControlledRyy)}, + MQT_NAMED_BUILDER(qir::singleControlledRyy)}, QCToQIRAdaptiveTestCase{ "MultipleControlledRYY", MQT_NAMED_BUILDER(qc::multipleControlledRyy), - MQT_NAMED_BUILDER(qir::multipleControlledRyy)})); + MQT_NAMED_BUILDER(qir::multipleControlledRyy)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RzOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRZOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"RZ", MQT_NAMED_BUILDER(qc::rz), - MQT_NAMED_BUILDER(qir::rz)}, - QCToQIRAdaptiveTestCase{"SingleControlledRZ", - MQT_NAMED_BUILDER(qc::singleControlledRz), - MQT_NAMED_BUILDER(qir::singleControlledRz)}, - QCToQIRAdaptiveTestCase{"MultipleControlledRZ", - MQT_NAMED_BUILDER(qc::multipleControlledRz), - MQT_NAMED_BUILDER(qir::multipleControlledRz)})); + testing::Values(QCToQIRAdaptiveTestCase{"RZ", MQT_NAMED_BUILDER(qc::rz), + MQT_NAMED_BUILDER(qir::rz)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledRZ", + MQT_NAMED_BUILDER(qc::singleControlledRz), + MQT_NAMED_BUILDER(qir::singleControlledRz)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledRZ", + MQT_NAMED_BUILDER(qc::multipleControlledRz), + MQT_NAMED_BUILDER(qir::multipleControlledRz)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RzxOp.cpp @@ -341,15 +352,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRZXOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"RZX", MQT_NAMED_BUILDER(qc::rzx), - MQT_NAMED_BUILDER(qir::rzx)}, + MQT_NAMED_BUILDER(qir::rzx)}, QCToQIRAdaptiveTestCase{ "SingleControlledRZX", MQT_NAMED_BUILDER(qc::singleControlledRzx), - MQT_NAMED_BUILDER(qir::singleControlledRzx)}, + MQT_NAMED_BUILDER(qir::singleControlledRzx)}, QCToQIRAdaptiveTestCase{ "MultipleControlledRZX", MQT_NAMED_BUILDER(qc::multipleControlledRzx), - MQT_NAMED_BUILDER(qir::multipleControlledRzx)})); + MQT_NAMED_BUILDER(qir::multipleControlledRzx)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RzzOp.cpp @@ -357,30 +368,31 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRZZOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"RZZ", MQT_NAMED_BUILDER(qc::rzz), - MQT_NAMED_BUILDER(qir::rzz)}, + MQT_NAMED_BUILDER(qir::rzz)}, QCToQIRAdaptiveTestCase{ "SingleControlledRZZ", MQT_NAMED_BUILDER(qc::singleControlledRzz), - MQT_NAMED_BUILDER(qir::singleControlledRzz)}, + MQT_NAMED_BUILDER(qir::singleControlledRzz)}, QCToQIRAdaptiveTestCase{ "MultipleControlledRZZ", MQT_NAMED_BUILDER(qc::multipleControlledRzz), - MQT_NAMED_BUILDER(qir::multipleControlledRzz)})); + MQT_NAMED_BUILDER(qir::multipleControlledRzz)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"S", MQT_NAMED_BUILDER(qc::s), - MQT_NAMED_BUILDER(qir::s)}, - QCToQIRAdaptiveTestCase{"SingleControlledS", - MQT_NAMED_BUILDER(qc::singleControlledS), - MQT_NAMED_BUILDER(qir::singleControlledS)}, - QCToQIRAdaptiveTestCase{"MultipleControlledS", - MQT_NAMED_BUILDER(qc::multipleControlledS), - MQT_NAMED_BUILDER(qir::multipleControlledS)})); + testing::Values(QCToQIRAdaptiveTestCase{"S", MQT_NAMED_BUILDER(qc::s), + MQT_NAMED_BUILDER(qir::s)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledS", + MQT_NAMED_BUILDER(qc::singleControlledS), + MQT_NAMED_BUILDER(qir::singleControlledS)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledS", + MQT_NAMED_BUILDER(qc::multipleControlledS), + MQT_NAMED_BUILDER(qir::multipleControlledS)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SdgOp.cpp @@ -388,77 +400,79 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSdgOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"Sdg", MQT_NAMED_BUILDER(qc::sdg), - MQT_NAMED_BUILDER(qir::sdg)}, + MQT_NAMED_BUILDER(qir::sdg)}, QCToQIRAdaptiveTestCase{ "SingleControlledSdg", MQT_NAMED_BUILDER(qc::singleControlledSdg), - MQT_NAMED_BUILDER(qir::singleControlledSdg)}, + MQT_NAMED_BUILDER(qir::singleControlledSdg)}, QCToQIRAdaptiveTestCase{ "MultipleControlledSdg", MQT_NAMED_BUILDER(qc::multipleControlledSdg), - MQT_NAMED_BUILDER(qir::multipleControlledSdg)})); + MQT_NAMED_BUILDER(qir::multipleControlledSdg)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SwapOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSWAPOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"SWAP", MQT_NAMED_BUILDER(qc::swap), - MQT_NAMED_BUILDER(qir::swap)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledSWAP", - MQT_NAMED_BUILDER(qc::singleControlledSwap), - MQT_NAMED_BUILDER(qir::singleControlledSwap)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledSWAP", - MQT_NAMED_BUILDER(qc::multipleControlledSwap), - MQT_NAMED_BUILDER(qir::multipleControlledSwap)})); + testing::Values( + QCToQIRAdaptiveTestCase{"SWAP", MQT_NAMED_BUILDER(qc::swap), + MQT_NAMED_BUILDER(qir::swap)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledSWAP", MQT_NAMED_BUILDER(qc::singleControlledSwap), + MQT_NAMED_BUILDER(qir::singleControlledSwap)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledSWAP", + MQT_NAMED_BUILDER(qc::multipleControlledSwap), + MQT_NAMED_BUILDER(qir::multipleControlledSwap)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSXOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"SX", MQT_NAMED_BUILDER(qc::sx), - MQT_NAMED_BUILDER(qir::sx)}, - QCToQIRAdaptiveTestCase{"SingleControlledSX", - MQT_NAMED_BUILDER(qc::singleControlledSx), - MQT_NAMED_BUILDER(qir::singleControlledSx)}, - QCToQIRAdaptiveTestCase{"MultipleControlledSX", - MQT_NAMED_BUILDER(qc::multipleControlledSx), - MQT_NAMED_BUILDER(qir::multipleControlledSx)})); + testing::Values(QCToQIRAdaptiveTestCase{"SX", MQT_NAMED_BUILDER(qc::sx), + MQT_NAMED_BUILDER(qir::sx)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledSX", + MQT_NAMED_BUILDER(qc::singleControlledSx), + MQT_NAMED_BUILDER(qir::singleControlledSx)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledSX", + MQT_NAMED_BUILDER(qc::multipleControlledSx), + MQT_NAMED_BUILDER(qir::multipleControlledSx)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SxdgOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSXdgOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"SXdg", MQT_NAMED_BUILDER(qc::sxdg), - MQT_NAMED_BUILDER(qir::sxdg)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledSXdg", - MQT_NAMED_BUILDER(qc::singleControlledSxdg), - MQT_NAMED_BUILDER(qir::singleControlledSxdg)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledSXdg", - MQT_NAMED_BUILDER(qc::multipleControlledSxdg), - MQT_NAMED_BUILDER(qir::multipleControlledSxdg)})); + testing::Values( + QCToQIRAdaptiveTestCase{"SXdg", MQT_NAMED_BUILDER(qc::sxdg), + MQT_NAMED_BUILDER(qir::sxdg)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledSXdg", MQT_NAMED_BUILDER(qc::singleControlledSxdg), + MQT_NAMED_BUILDER(qir::singleControlledSxdg)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledSXdg", + MQT_NAMED_BUILDER(qc::multipleControlledSxdg), + MQT_NAMED_BUILDER(qir::multipleControlledSxdg)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/TOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveTOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"T", MQT_NAMED_BUILDER(qc::t_), - MQT_NAMED_BUILDER(qir::t_)}, - QCToQIRAdaptiveTestCase{"SingleControlledT", - MQT_NAMED_BUILDER(qc::singleControlledT), - MQT_NAMED_BUILDER(qir::singleControlledT)}, - QCToQIRAdaptiveTestCase{"MultipleControlledT", - MQT_NAMED_BUILDER(qc::multipleControlledT), - MQT_NAMED_BUILDER(qir::multipleControlledT)})); + testing::Values(QCToQIRAdaptiveTestCase{"T", MQT_NAMED_BUILDER(qc::t_), + MQT_NAMED_BUILDER(qir::t_)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledT", + MQT_NAMED_BUILDER(qc::singleControlledT), + MQT_NAMED_BUILDER(qir::singleControlledT)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledT", + MQT_NAMED_BUILDER(qc::multipleControlledT), + MQT_NAMED_BUILDER(qir::multipleControlledT)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/TdgOp.cpp @@ -466,124 +480,129 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveTdgOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"Tdg", MQT_NAMED_BUILDER(qc::tdg), - MQT_NAMED_BUILDER(qir::tdg)}, + MQT_NAMED_BUILDER(qir::tdg)}, QCToQIRAdaptiveTestCase{ "SingleControlledTdg", MQT_NAMED_BUILDER(qc::singleControlledTdg), - MQT_NAMED_BUILDER(qir::singleControlledTdg)}, + MQT_NAMED_BUILDER(qir::singleControlledTdg)}, QCToQIRAdaptiveTestCase{ "MultipleControlledTdg", MQT_NAMED_BUILDER(qc::multipleControlledTdg), - MQT_NAMED_BUILDER(qir::multipleControlledTdg)})); + MQT_NAMED_BUILDER(qir::multipleControlledTdg)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/U2Op.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveU2OpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"U2", MQT_NAMED_BUILDER(qc::u2), - MQT_NAMED_BUILDER(qir::u2)}, - QCToQIRAdaptiveTestCase{"SingleControlledU2", - MQT_NAMED_BUILDER(qc::singleControlledU2), - MQT_NAMED_BUILDER(qir::singleControlledU2)}, - QCToQIRAdaptiveTestCase{"MultipleControlledU2", - MQT_NAMED_BUILDER(qc::multipleControlledU2), - MQT_NAMED_BUILDER(qir::multipleControlledU2)})); + testing::Values(QCToQIRAdaptiveTestCase{"U2", MQT_NAMED_BUILDER(qc::u2), + MQT_NAMED_BUILDER(qir::u2)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledU2", + MQT_NAMED_BUILDER(qc::singleControlledU2), + MQT_NAMED_BUILDER(qir::singleControlledU2)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledU2", + MQT_NAMED_BUILDER(qc::multipleControlledU2), + MQT_NAMED_BUILDER(qir::multipleControlledU2)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/UOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveUOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"U", MQT_NAMED_BUILDER(qc::u), - MQT_NAMED_BUILDER(qir::u)}, - QCToQIRAdaptiveTestCase{"SingleControlledU", - MQT_NAMED_BUILDER(qc::singleControlledU), - MQT_NAMED_BUILDER(qir::singleControlledU)}, - QCToQIRAdaptiveTestCase{"MultipleControlledU", - MQT_NAMED_BUILDER(qc::multipleControlledU), - MQT_NAMED_BUILDER(qir::multipleControlledU)})); + testing::Values(QCToQIRAdaptiveTestCase{"U", MQT_NAMED_BUILDER(qc::u), + MQT_NAMED_BUILDER(qir::u)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledU", + MQT_NAMED_BUILDER(qc::singleControlledU), + MQT_NAMED_BUILDER(qir::singleControlledU)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledU", + MQT_NAMED_BUILDER(qc::multipleControlledU), + MQT_NAMED_BUILDER(qir::multipleControlledU)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/XOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveXOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"X", MQT_NAMED_BUILDER(qc::x), - MQT_NAMED_BUILDER(qir::x)}, - QCToQIRAdaptiveTestCase{"SingleControlledX", - MQT_NAMED_BUILDER(qc::singleControlledX), - MQT_NAMED_BUILDER(qir::singleControlledX)}, - QCToQIRAdaptiveTestCase{"MultipleControlledX", - MQT_NAMED_BUILDER(qc::multipleControlledX), - MQT_NAMED_BUILDER(qir::multipleControlledX)})); + testing::Values(QCToQIRAdaptiveTestCase{"X", MQT_NAMED_BUILDER(qc::x), + MQT_NAMED_BUILDER(qir::x)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledX", + MQT_NAMED_BUILDER(qc::singleControlledX), + MQT_NAMED_BUILDER(qir::singleControlledX)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledX", + MQT_NAMED_BUILDER(qc::multipleControlledX), + MQT_NAMED_BUILDER(qir::multipleControlledX)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/XxMinusYyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveXXMinusYYOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"XXMinusYY", - MQT_NAMED_BUILDER(qc::xxMinusYY), - MQT_NAMED_BUILDER(qir::xxMinusYY)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledXXMinusYY", - MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), - MQT_NAMED_BUILDER(qir::singleControlledXxMinusYY)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledXXMinusYY", - MQT_NAMED_BUILDER(qc::multipleControlledXxMinusYY), - MQT_NAMED_BUILDER(qir::multipleControlledXxMinusYY)})); + testing::Values( + QCToQIRAdaptiveTestCase{"XXMinusYY", MQT_NAMED_BUILDER(qc::xxMinusYY), + MQT_NAMED_BUILDER(qir::xxMinusYY)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledXXMinusYY", + MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), + MQT_NAMED_BUILDER(qir::singleControlledXxMinusYY)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledXXMinusYY", + MQT_NAMED_BUILDER(qc::multipleControlledXxMinusYY), + MQT_NAMED_BUILDER(qir::multipleControlledXxMinusYY)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/XxPlusYyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveXXPlusYYOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"XXPlusYY", - MQT_NAMED_BUILDER(qc::xxPlusYY), - MQT_NAMED_BUILDER(qir::xxPlusYY)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledXXPlusYY", - MQT_NAMED_BUILDER(qc::singleControlledXxPlusYY), - MQT_NAMED_BUILDER(qir::singleControlledXxPlusYY)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledXXPlusYY", - MQT_NAMED_BUILDER(qc::multipleControlledXxPlusYY), - MQT_NAMED_BUILDER(qir::multipleControlledXxPlusYY)})); + testing::Values( + QCToQIRAdaptiveTestCase{"XXPlusYY", MQT_NAMED_BUILDER(qc::xxPlusYY), + MQT_NAMED_BUILDER(qir::xxPlusYY)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledXXPlusYY", + MQT_NAMED_BUILDER(qc::singleControlledXxPlusYY), + MQT_NAMED_BUILDER(qir::singleControlledXxPlusYY)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledXXPlusYY", + MQT_NAMED_BUILDER(qc::multipleControlledXxPlusYY), + MQT_NAMED_BUILDER(qir::multipleControlledXxPlusYY)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/YOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveYOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"Y", MQT_NAMED_BUILDER(qc::y), - MQT_NAMED_BUILDER(qir::y)}, - QCToQIRAdaptiveTestCase{"SingleControlledY", - MQT_NAMED_BUILDER(qc::singleControlledY), - MQT_NAMED_BUILDER(qir::singleControlledY)}, - QCToQIRAdaptiveTestCase{"MultipleControlledY", - MQT_NAMED_BUILDER(qc::multipleControlledY), - MQT_NAMED_BUILDER(qir::multipleControlledY)})); + testing::Values(QCToQIRAdaptiveTestCase{"Y", MQT_NAMED_BUILDER(qc::y), + MQT_NAMED_BUILDER(qir::y)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledY", + MQT_NAMED_BUILDER(qc::singleControlledY), + MQT_NAMED_BUILDER(qir::singleControlledY)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledY", + MQT_NAMED_BUILDER(qc::multipleControlledY), + MQT_NAMED_BUILDER(qir::multipleControlledY)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/ZOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveZOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"Z", MQT_NAMED_BUILDER(qc::z), - MQT_NAMED_BUILDER(qir::z)}, - QCToQIRAdaptiveTestCase{"SingleControlledZ", - MQT_NAMED_BUILDER(qc::singleControlledZ), - MQT_NAMED_BUILDER(qir::singleControlledZ)}, - QCToQIRAdaptiveTestCase{"MultipleControlledZ", - MQT_NAMED_BUILDER(qc::multipleControlledZ), - MQT_NAMED_BUILDER(qir::multipleControlledZ)})); + testing::Values(QCToQIRAdaptiveTestCase{"Z", MQT_NAMED_BUILDER(qc::z), + MQT_NAMED_BUILDER(qir::z)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledZ", + MQT_NAMED_BUILDER(qc::singleControlledZ), + MQT_NAMED_BUILDER(qir::singleControlledZ)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledZ", + MQT_NAMED_BUILDER(qc::multipleControlledZ), + MQT_NAMED_BUILDER(qir::multipleControlledZ)})); /// @} /// \name QCToQIRAdaptive/Operations/MeasureOp.cpp @@ -594,23 +613,24 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveTestCase{ "SingleMeasurementToSingleBit", MQT_NAMED_BUILDER(qc::singleMeasurementToSingleBit), - MQT_NAMED_BUILDER(qir::singleMeasurementToSingleBit)}, + MQT_NAMED_BUILDER(qir::singleMeasurementToSingleBit)}, QCToQIRAdaptiveTestCase{ "RepeatedMeasurementToSameBit", MQT_NAMED_BUILDER(qc::repeatedMeasurementToSameBit), - MQT_NAMED_BUILDER(qir::repeatedMeasurementToSameBit)}, + MQT_NAMED_BUILDER(qir::repeatedMeasurementToSameBit)}, QCToQIRAdaptiveTestCase{ "RepeatedMeasurementToDifferentBits", MQT_NAMED_BUILDER(qc::repeatedMeasurementToDifferentBits), - MQT_NAMED_BUILDER(qir::repeatedMeasurementToDifferentBits)}, + MQT_NAMED_BUILDER(qir::repeatedMeasurementToDifferentBits)}, QCToQIRAdaptiveTestCase{ "MultipleClassicalRegistersAndMeasurements", MQT_NAMED_BUILDER(qc::multipleClassicalRegistersAndMeasurements), - MQT_NAMED_BUILDER(qir::multipleClassicalRegistersAndMeasurements)}, + MQT_NAMED_BUILDER( + qir::multipleClassicalRegistersAndMeasurements)}, QCToQIRAdaptiveTestCase{ "MeasurementWithoutRegisters", MQT_NAMED_BUILDER(qc::measurementWithoutRegisters), - MQT_NAMED_BUILDER(qir::measurementWithoutRegisters)})); + MQT_NAMED_BUILDER(qir::measurementWithoutRegisters)})); /// @} /// \name QCToQIRAdaptive/Operations/ResetOp.cpp @@ -618,28 +638,29 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveResetOpTest, QCToQIRAdaptiveTest, testing::Values( - QCToQIRAdaptiveTestCase{"ResetQubitWithoutOp", - MQT_NAMED_BUILDER(qc::resetQubitWithoutOp), - MQT_NAMED_BUILDER(qir::resetQubitWithoutOp)}, + QCToQIRAdaptiveTestCase{ + "ResetQubitWithoutOp", MQT_NAMED_BUILDER(qc::resetQubitWithoutOp), + MQT_NAMED_BUILDER(qir::resetQubitWithoutOp)}, QCToQIRAdaptiveTestCase{ "ResetMultipleQubitsWithoutOp", MQT_NAMED_BUILDER(qc::resetMultipleQubitsWithoutOp), - MQT_NAMED_BUILDER(qir::resetMultipleQubitsWithoutOp)}, - QCToQIRAdaptiveTestCase{"RepeatedResetWithoutOp", - MQT_NAMED_BUILDER(qc::repeatedResetWithoutOp), - MQT_NAMED_BUILDER(qir::repeatedResetWithoutOp)}, + MQT_NAMED_BUILDER(qir::resetMultipleQubitsWithoutOp)}, + QCToQIRAdaptiveTestCase{ + "RepeatedResetWithoutOp", + MQT_NAMED_BUILDER(qc::repeatedResetWithoutOp), + MQT_NAMED_BUILDER(qir::repeatedResetWithoutOp)}, QCToQIRAdaptiveTestCase{ "ResetQubitAfterSingleOp", MQT_NAMED_BUILDER(qc::resetQubitAfterSingleOp), - MQT_NAMED_BUILDER(qir::resetQubitAfterSingleOp)}, + MQT_NAMED_BUILDER(qir::resetQubitAfterSingleOp)}, QCToQIRAdaptiveTestCase{ "ResetMultipleQubitsAfterSingleOp", MQT_NAMED_BUILDER(qc::resetMultipleQubitsAfterSingleOp), - MQT_NAMED_BUILDER(qir::resetMultipleQubitsAfterSingleOp)}, + MQT_NAMED_BUILDER(qir::resetMultipleQubitsAfterSingleOp)}, QCToQIRAdaptiveTestCase{ "RepeatedResetAfterSingleOp", MQT_NAMED_BUILDER(qc::repeatedResetAfterSingleOp), - MQT_NAMED_BUILDER(qir::repeatedResetAfterSingleOp)})); + MQT_NAMED_BUILDER(qir::repeatedResetAfterSingleOp)})); /// @} /// \name QCToQIRAdaptive/QubitManagement/QubitManagement.cpp @@ -648,24 +669,24 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveQubitManagementTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"AllocQubit", MQT_NAMED_BUILDER(qc::allocQubit), - MQT_NAMED_BUILDER(qir::emptyQIR)}, - QCToQIRAdaptiveTestCase{"AllocQubitRegister", - MQT_NAMED_BUILDER(qc::allocQubitRegister), - MQT_NAMED_BUILDER(qir::emptyQIR)}, + MQT_NAMED_BUILDER(qir::allocQubit)}, + QCToQIRAdaptiveTestCase{ + "AllocQubitRegister", MQT_NAMED_BUILDER(qc::allocQubitRegister), + MQT_NAMED_BUILDER(qir::allocQubitRegister)}, QCToQIRAdaptiveTestCase{ "AllocMultipleQubitRegisters", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegisters), - MQT_NAMED_BUILDER(qir::emptyQIR)}, + MQT_NAMED_BUILDER(qir::allocMultipleQubitRegisters)}, QCToQIRAdaptiveTestCase{ "AllocMultipleQubitRegistersWithOps", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegistersWithOps), - MQT_NAMED_BUILDER(qir::allocMultipleQubitRegistersWithOps)}, - QCToQIRAdaptiveTestCase{"AllocLargeRegister", - MQT_NAMED_BUILDER(qc::allocLargeRegister), - MQT_NAMED_BUILDER(qir::emptyQIR)}, + MQT_NAMED_BUILDER(qir::allocMultipleQubitRegistersWithOps)}, + QCToQIRAdaptiveTestCase{ + "AllocLargeRegister", MQT_NAMED_BUILDER(qc::allocLargeRegister), + MQT_NAMED_BUILDER(qir::allocQubitRegister)}, QCToQIRAdaptiveTestCase{"StaticQubits", MQT_NAMED_BUILDER(qc::staticQubits), - MQT_NAMED_BUILDER(qir::emptyQIR)}, + MQT_NAMED_BUILDER(qir::staticQubits)}, QCToQIRAdaptiveTestCase{"StaticQubitsWithOps", MQT_NAMED_BUILDER(qc::staticQubitsWithOps), MQT_NAMED_BUILDER(qir::staticQubitsWithOps)}, @@ -685,7 +706,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(qir::staticQubitsWithInv)}, QCToQIRAdaptiveTestCase{"AllocDeallocPair", MQT_NAMED_BUILDER(qc::allocDeallocPair), - MQT_NAMED_BUILDER(qir::emptyQIR)})); + MQT_NAMED_BUILDER(qir::emptyQIR)})); /// @} /// \name QCToQIRAdaptive/Operations/IfOp.cpp @@ -694,15 +715,15 @@ INSTANTIATE_TEST_SUITE_P( SCFIfOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"SimpleIfOp", MQT_NAMED_BUILDER(qc::simpleIf), - MQT_NAMED_BUILDER(qir::simpleIf)}, + MQT_NAMED_BUILDER(qir::simpleIf)}, QCToQIRAdaptiveTestCase{"IfTwoQubits", MQT_NAMED_BUILDER(qc::ifTwoQubits), - MQT_NAMED_BUILDER(qir::ifTwoQubits)}, + MQT_NAMED_BUILDER(qir::ifTwoQubits)}, QCToQIRAdaptiveTestCase{"IfElse", MQT_NAMED_BUILDER(qc::ifElse), - MQT_NAMED_BUILDER(qir::ifElse)}, - QCToQIRAdaptiveTestCase{"NestedIfOpForLoop", - MQT_NAMED_BUILDER(qc::nestedIfOpForLoop), - MQT_NAMED_BUILDER(qir::nestedIfOpForLoop)})); + MQT_NAMED_BUILDER(qir::ifElse)}, + QCToQIRAdaptiveTestCase{ + "NestedIfOpForLoop", MQT_NAMED_BUILDER(qc::nestedIfOpForLoop), + MQT_NAMED_BUILDER(qir::nestedIfOpForLoop)})); /// @} /// \name QCToQIRAdaptive/Operations/WhileOp.cpp @@ -710,12 +731,12 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( SCFWhileOpTest, QCToQIRAdaptiveTest, testing::Values( - QCToQIRAdaptiveTestCase{"SimpleWhile", - MQT_NAMED_BUILDER(qc::simpleWhileReset), - MQT_NAMED_BUILDER(qir::simpleWhileReset)}, - QCToQIRAdaptiveTestCase{"SimpleDoWhile", - MQT_NAMED_BUILDER(qc::simpleDoWhileReset), - MQT_NAMED_BUILDER(qir::simpleDoWhileReset)})); + QCToQIRAdaptiveTestCase{ + "SimpleWhile", MQT_NAMED_BUILDER(qc::simpleWhileReset), + MQT_NAMED_BUILDER(qir::simpleWhileReset)}, + QCToQIRAdaptiveTestCase{ + "SimpleDoWhile", MQT_NAMED_BUILDER(qc::simpleDoWhileReset), + MQT_NAMED_BUILDER(qir::simpleDoWhileReset)})); /// \name QCToQIRAdaptive/Operations/ForOp.cpp /// @{ @@ -724,26 +745,28 @@ INSTANTIATE_TEST_SUITE_P( testing::Values( QCToQIRAdaptiveTestCase{"SimpleForLoop", MQT_NAMED_BUILDER(qc::simpleForLoop), - MQT_NAMED_BUILDER(qir::simpleForLoop)}, - QCToQIRAdaptiveTestCase{"NestedForLoopIfOp", - MQT_NAMED_BUILDER(qc::nestedForLoopIfOp), - MQT_NAMED_BUILDER(qir::nestedForLoopIfOp)}, - QCToQIRAdaptiveTestCase{"NestedForLoopWhileOp", - MQT_NAMED_BUILDER(qc::nestedForLoopWhileOp), - MQT_NAMED_BUILDER(qir::nestedForLoopWhileOp)}, + MQT_NAMED_BUILDER(qir::simpleForLoop)}, + QCToQIRAdaptiveTestCase{ + "NestedForLoopIfOp", MQT_NAMED_BUILDER(qc::nestedForLoopIfOp), + MQT_NAMED_BUILDER(qir::nestedForLoopIfOp)}, + QCToQIRAdaptiveTestCase{ + "NestedForLoopWhileOp", MQT_NAMED_BUILDER(qc::nestedForLoopWhileOp), + MQT_NAMED_BUILDER(qir::nestedForLoopWhileOp)}, QCToQIRAdaptiveTestCase{ "nestedForLoopCtrlOpWithSeparateQubit", MQT_NAMED_BUILDER(qc::nestedForLoopCtrlOpWithSeparateQubit), - MQT_NAMED_BUILDER(qir::nestedForLoopCtrlOpWithSeparateQubit)}, + MQT_NAMED_BUILDER( + qir::nestedForLoopCtrlOpWithSeparateQubit)}, QCToQIRAdaptiveTestCase{ "nestedForLoopCtrlOpWithExtractedQubit", MQT_NAMED_BUILDER(qc::nestedForLoopCtrlOpWithExtractedQubit), - MQT_NAMED_BUILDER(qir::nestedForLoopCtrlOpWithExtractedQubit)})); + MQT_NAMED_BUILDER( + qir::nestedForLoopCtrlOpWithExtractedQubit)})); /// \name QCToQIRAdaptive/Modifiers/CtrlOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P(QCToQIRCtrlOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{ "NestedCtrlTwo", MQT_NAMED_BUILDER(qc::ctrlTwo), - MQT_NAMED_BUILDER(qir::ctrlTwo)})); + MQT_NAMED_BUILDER(qir::ctrlTwo)})); /// @} diff --git a/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp b/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp index a753acafd5..28005233aa 100644 --- a/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp +++ b/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp @@ -32,8 +32,10 @@ namespace { struct QIRTestCase { std::string name; - mqt::test::NamedBuilder programBuilder; - mqt::test::NamedBuilder referenceBuilder; + mqt::test::NamedBuilder> + programBuilder; + mqt::test::NamedBuilder> + referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QIRTestCase& info); }; diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index c707a7ff00..aae3435c4f 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -164,7 +164,7 @@ std::pair, SmallVector> allocDeallocPair(QCProgramBuilder& b) { auto q = b.allocQubit(); b.dealloc(q); - return measureAndReturn(b, {}); + return {{b.intConstant(0)}, {b.getI64Type()}}; } std::pair, SmallVector> @@ -417,12 +417,13 @@ std::pair, SmallVector> repeatedControlledX(QCProgramBuilder& b) { auto control = b.allocQubit(); b.h(control); - mlir::SmallVector qubits = {control}; + mlir::SmallVector qubits; for (auto i = 0; i < 50; i++) { auto qubit = b.allocQubit(); b.cx(control, qubit); qubits.push_back(qubit); } + qubits.push_back(control); return measureAndReturn(b, qubits); } @@ -2048,7 +2049,7 @@ nestedIfOpForLoop(QCProgramBuilder& b) { b.h(q1); }); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], q0}); + return measureAndReturn(b, {q0}); } std::pair, SmallVector> @@ -2099,7 +2100,7 @@ nestedForLoopIfOp(QCProgramBuilder& b) { b.h(q); }); }); - return measureAndReturn(b, {reg[0], reg[1], qCond}); + return measureAndReturn(b, {qCond}); } std::pair, SmallVector> @@ -2131,7 +2132,7 @@ nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b) { b.h(q0); b.cx(control, q0); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], control}); + return measureAndReturn(b, {control}); } std::pair, SmallVector> @@ -2143,7 +2144,7 @@ nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b) { b.h(q0); b.cx(reg[0], q0); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, {reg[0]}); } } // namespace mlir::qc diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 6848ffc420..3f482c68cf 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -20,6 +20,22 @@ #include #include +static std::pair, mlir::SmallVector> +measureAndReturnQTensor(mlir::qco::QCOProgramBuilder& b, mlir::Value qTensor, + int64_t size) { + mlir::SmallVector bits; + mlir::SmallVector bitTypes; + auto i1Type = b.getI1Type(); + for (auto i = 0; i < size; ++i) { + auto [qTensorOut, qubit] = b.qtensorExtract(qTensor, i); + auto [q2, bit] = b.measure(qubit); + bits.push_back(bit); + bitTypes.push_back(i1Type); + qTensor = b.qtensorInsert(q2, qTensorOut, i); + } + return {bits, bitTypes}; +} + static std::pair, mlir::SmallVector> measureAndReturn(mlir::qco::QCOProgramBuilder& b, mlir::SmallVector qubits) { @@ -196,9 +212,9 @@ multipleClassicalRegistersAndMeasurements(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); const auto& c0 = b.allocClassicalBitRegister(1, "c0"); const auto& c1 = b.allocClassicalBitRegister(2, "c1"); - auto [q1, bit1] = b.measure(q[0], c0[0]); - auto [q2, bit2] = b.measure(q1, c1[0]); - auto [q3, bit3] = b.measure(q2, c1[1]); + auto [q0, bit1] = b.measure(q[0], c0[0]); + auto [q1, bit2] = b.measure(q[1], c1[0]); + auto [q2, bit3] = b.measure(q[2], c1[1]); return {{bit1, bit2, bit3}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; } @@ -3570,7 +3586,7 @@ simpleForLoop(QCOProgramBuilder& b) { auto insert = b.qtensorInsert(q1, t0, iv); return SmallVector{insert}; }); - return measureAndReturn(b, {scfFor[0]}); + return measureAndReturnQTensor(b, scfFor[0], 2); }; std::pair, SmallVector> @@ -3603,7 +3619,7 @@ nestedForLoopIfOp(QCOProgramBuilder& b) { }); return SmallVector{ifOp[0], q2}; }); - return measureAndReturn(b, {scfFor[0], scfFor[1]}); + return measureAndReturn(b, {scfFor[1]}); } std::pair, SmallVector> @@ -3633,7 +3649,7 @@ nestedForLoopWhileOp(QCOProgramBuilder& b) { auto insert = b.qtensorInsert(whileResult[0], t0, iv); return SmallVector{insert}; }); - return measureAndReturn(b, {scfFor[0]}); + return measureAndReturnQTensor(b, scfFor[0], 2); } std::pair, SmallVector> @@ -3653,7 +3669,7 @@ nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b) { auto insert = b.qtensorInsert(targets[0], t0, iv); return SmallVector{insert, controls[0]}; }); - return measureAndReturn(b, {scfFor[0], scfFor[1]}); + return measureAndReturn(b, {scfFor[1]}); } std::pair, SmallVector> @@ -3672,7 +3688,7 @@ nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b) { auto insert = b.qtensorInsert(targets[0], t0, iv); return SmallVector{insert, controls[0]}; }); - return measureAndReturn(b, {scfFor[0], scfFor[1]}); + return measureAndReturn(b, {scfFor[1]}); } std::pair, SmallVector> @@ -3697,7 +3713,7 @@ nestedIfOpForLoop(QCOProgramBuilder& b) { }); return SmallVector{scfFor[0], args[1]}; }); - return measureAndReturn(b, {ifRes[0], ifRes[1]}); + return measureAndReturn(b, {ifRes[1]}); } std::pair, SmallVector> diff --git a/mlir/unittests/programs/qir_programs.cpp b/mlir/unittests/programs/qir_programs.cpp index 8fb5b513e3..8db3b2fd77 100644 --- a/mlir/unittests/programs/qir_programs.cpp +++ b/mlir/unittests/programs/qir_programs.cpp @@ -59,6 +59,61 @@ collectMeasurementOutcomesInStruct(mlir::qir::QIRProgramBuilder& b, return structValue; } +/** + * @brief Measures the given qubits or reads the given results and returns the + * measurement outcomes as a struct value or a single `i1`. + * @param b The QIRProgramBuilder used to perform the measurements and create + * the struct. + * @param qubits The qubits to be measured. + * @param results The measurement results to be read. + * @param inRegister Whether to store the results in a classical result array or + * not. + * @return A pair containing the result value and its type. + */ +static std::pair measureOrReadAndReturn( + mlir::qir::QIRProgramBuilder& b, mlir::SmallVector qubits, + mlir::SmallVector results, bool inRegister) { + + if (qubits.empty() && results.empty()) { + auto zeroConst = b.intConstant(0); + return {zeroConst, b.getI64Type()}; + } + mlir::qir::QIRProgramBuilder::ClassicalRegister resultArray; + if (inRegister) { + resultArray = b.allocClassicalBitRegister(qubits.size(), "meas"); + } + + if (qubits.size() == 1 && results.empty()) { + auto outcome = inRegister ? b.measure(qubits[0], resultArray[0]) + : b.measure(qubits[0], 0); + auto result = b.readResult(outcome); + return {result, b.getI1Type()}; + } + if (results.size() == 1 && qubits.empty()) { + auto result = b.readResult(results[0]); + return {result, b.getI1Type()}; + } + + llvm::SmallVector elementTypes(qubits.size() + results.size(), + b.getI1Type()); + mlir::Value structValue = createStruct(b, elementTypes); + + for (auto i = 0L; i < results.size(); ++i) { + auto result = b.readResult(results[i]); + auto insert = mlir::LLVM::InsertValueOp::create(b, structValue, result, i); + structValue = insert.getResult(); + } + for (auto i = 0L; i < qubits.size(); ++i) { + auto outcome = inRegister ? b.measure(qubits[i], resultArray[i]) + : b.measure(qubits[i], i); + auto result = b.readResult(outcome); + auto insert = mlir::LLVM::InsertValueOp::create(b, structValue, result, + i + results.size()); + structValue = insert.getResult(); + } + return {structValue, structValue.getType()}; +} + /** * @brief Measures the given qubits and returns the measurement outcomes as a * struct value or a single `i1`. @@ -67,11 +122,13 @@ collectMeasurementOutcomesInStruct(mlir::qir::QIRProgramBuilder& b, * @param qubits The qubits to be measured. * @param inRegister Whether to store the results in a classical result array or * not. + * @param startIndex The starting index for measurement outcomes. * @return A pair containing the result value and its type. */ static std::pair measureAndReturn(mlir::qir::QIRProgramBuilder& b, - mlir::SmallVector qubits, bool inRegister) { + mlir::SmallVector qubits, bool inRegister, + int64_t startIndex) { if (qubits.empty()) { auto zeroConst = b.intConstant(0); @@ -84,7 +141,7 @@ measureAndReturn(mlir::qir::QIRProgramBuilder& b, if (qubits.size() == 1) { auto outcome = inRegister ? b.measure(qubits[0], resultArray[0]) - : b.measure(qubits[0], 0); + : b.measure(qubits[0], startIndex); auto result = b.readResult(outcome); return {result, b.getI1Type()}; } @@ -94,7 +151,7 @@ measureAndReturn(mlir::qir::QIRProgramBuilder& b, for (auto i = 0L; i < qubits.size(); ++i) { auto outcome = inRegister ? b.measure(qubits[i], resultArray[i]) - : b.measure(qubits[i], i); + : b.measure(qubits[i], startIndex + i); auto result = b.readResult(outcome); auto insert = mlir::LLVM::InsertValueOp::create(b, structValue, result, i); structValue = insert.getResult(); @@ -106,44 +163,59 @@ measureAndReturn(mlir::qir::QIRProgramBuilder& b, * @brief Measures the given qubits and returns the measurement outcomes as a * struct value or a single `i1`. * - * @detail The measurement outcomes are stored in a classical result array. + * @detail Measurement outcome indices are assumed to start at 0. + * * @param b The QIRProgramBuilder used to perform the measurements and create * the struct. * @param qubits The qubits to be measured. - * @return The result value and its type as a pair. + * @param inRegister Whether to store the results in a classical result array or + * not. + * @return A pair containing the result value and its type. */ static std::pair measureAndReturn(mlir::qir::QIRProgramBuilder& b, - mlir::SmallVector qubits) { - return measureAndReturn(b, qubits, true); + mlir::SmallVector qubits, bool inRegister) { + return measureAndReturn(b, qubits, inRegister, 0); } namespace mlir::qir { +template std::pair emptyQIR(QIRProgramBuilder& b) { - return measureAndReturn(b, {}); + return measureAndReturn(b, {}, IntoRegister); } +template std::pair allocQubit(QIRProgramBuilder& b) { auto q = b.allocQubit(); - return measureAndReturn(b, {q}); + return measureAndReturn(b, {q}, IntoRegister); } +template std::pair alloc1QubitRegister(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair allocQubitRegister(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); +} + +template +std::pair alloc3QubitRegister(QIRProgramBuilder& b) { + auto q = b.allocQubitRegister(3); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } +template std::pair allocMultipleQubitRegisters(QIRProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); auto q1 = b.allocQubitRegister(3); - return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}); + return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}, IntoRegister); } +template std::pair allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); @@ -153,12 +225,13 @@ allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b) { b.h(q1[0]); b.h(q1[1]); b.h(q1[2]); - return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}); + return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}, IntoRegister); } +template std::pair allocLargeRegister(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(100); - return measureAndReturn(b, {q[0], q[99]}); + return measureAndReturn(b, {q[0], q[99]}, IntoRegister); } std::pair staticQubits(QIRProgramBuilder& b) { @@ -240,6 +313,7 @@ mixedDynamicRegisterThenStaticQubit(QIRProgramBuilder& b) { return measureAndReturn(b, {q0[0], q0[1], q1}, false); } +template std::pair singleMeasurementToSingleBit(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto c = b.allocClassicalBitRegister(1); @@ -248,6 +322,7 @@ std::pair singleMeasurementToSingleBit(QIRProgramBuilder& b) { return {read, b.getI1Type()}; } +template std::pair repeatedMeasurementToSameBit(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto c = b.allocClassicalBitRegister(1); @@ -258,6 +333,7 @@ std::pair repeatedMeasurementToSameBit(QIRProgramBuilder& b) { return {c3, b.getI1Type()}; } +template std::pair repeatedMeasurementToDifferentBits(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); @@ -272,6 +348,7 @@ repeatedMeasurementToDifferentBits(QIRProgramBuilder& b) { return {filledStruct, filledStruct.getType()}; } +template std::pair multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); @@ -287,6 +364,7 @@ multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b) { return {filledStruct, filledStruct.getType()}; } +template std::pair measurementWithoutRegisters(QIRProgramBuilder& b) { auto q = b.allocQubit(); auto bit = b.measure(q, 0); @@ -294,589 +372,675 @@ std::pair measurementWithoutRegisters(QIRProgramBuilder& b) { return {c, b.getI1Type()}; } +template std::pair resetQubitWithoutOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair resetMultipleQubitsWithoutOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.reset(q[0]); b.reset(q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair repeatedResetWithoutOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair resetQubitAfterSingleOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.h(q[0]); b.reset(q[0]); b.h(q[1]); b.reset(q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair repeatedResetAfterSingleOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair globalPhase(QIRProgramBuilder& b) { b.gphase(0.123); - return measureAndReturn(b, {}); + return measureAndReturn(b, {}, IntoRegister); } +template std::pair identity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.id(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cid(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template +std::pair twoQubitsOneIdentity(QIRProgramBuilder& b) { + auto q = b.allocQubitRegister(2); + b.id(q[0]); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); +} + +template +std::pair threeQubitsOneIdentity(QIRProgramBuilder& b) { + auto q = b.allocQubitRegister(3); + b.id(q[0]); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); +} + +template std::pair multipleControlledIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcid({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair x(QIRProgramBuilder& b) { +template std::pair x(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.x(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledX(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cx(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledX(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcx({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair y(QIRProgramBuilder& b) { +template std::pair y(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.y(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cy(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcy({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair z(QIRProgramBuilder& b) { +template std::pair z(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.z(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledZ(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cz(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledZ(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcz({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair h(QIRProgramBuilder& b) { +template std::pair h(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledH(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ch(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledH(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mch({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } +template std::pair hWithoutRegister(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); return measureAndReturn(b, {q}, false); } -std::pair s(QIRProgramBuilder& b) { +template std::pair s(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.s(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledS(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cs(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledS(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcs({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair sdg(QIRProgramBuilder& b) { +template std::pair sdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledSdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csdg(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledSdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsdg({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair t_(QIRProgramBuilder& b) { +template std::pair t_(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.t(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledT(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ct(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledT(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mct({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair tdg(QIRProgramBuilder& b) { +template std::pair tdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.tdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledTdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ctdg(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledTdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mctdg({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair sx(QIRProgramBuilder& b) { +template std::pair sx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sx(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledSx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csx(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledSx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsx({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair sxdg(QIRProgramBuilder& b) { +template std::pair sxdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sxdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledSxdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csxdg(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledSxdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsxdg({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair rx(QIRProgramBuilder& b) { +template std::pair rx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rx(0.123, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledRx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.crx(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledRx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcrx(0.123, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair ry(QIRProgramBuilder& b) { +template std::pair ry(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.ry(0.456, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledRy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cry(0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledRy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcry(0.456, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair rz(QIRProgramBuilder& b) { +template std::pair rz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rz(0.789, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledRz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.crz(0.789, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledRz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcrz(0.789, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair p(QIRProgramBuilder& b) { +template std::pair p(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.p(0.123, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledP(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cp(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledP(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcp(0.123, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair r(QIRProgramBuilder& b) { +template std::pair r(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.r(0.123, 0.456, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledR(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cr(0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledR(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcr(0.123, 0.456, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair u2(QIRProgramBuilder& b) { +template std::pair u2(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u2(0.234, 0.567, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledU2(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cu2(0.234, 0.567, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledU2(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcu2(0.234, 0.567, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair u(QIRProgramBuilder& b) { +template std::pair u(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u(0.1, 0.2, 0.3, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister); } +template std::pair singleControlledU(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cu(0.1, 0.2, 0.3, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair multipleControlledU(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcu(0.1, 0.2, 0.3, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } -std::pair swap(QIRProgramBuilder& b) { +template std::pair swap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.swap(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair singleControlledSwap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cswap(q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } +template std::pair multipleControlledSwap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcswap({q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } +template std::pair iswap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.iswap(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair singleControlledIswap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.ciswap(q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } +template std::pair multipleControlledIswap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mciswap({q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } -std::pair dcx(QIRProgramBuilder& b) { +template std::pair dcx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.dcx(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair singleControlledDcx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cdcx(q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } +template std::pair multipleControlledDcx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcdcx({q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } -std::pair ecr(QIRProgramBuilder& b) { +template std::pair ecr(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ecr(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair singleControlledEcr(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cecr(q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } +template std::pair multipleControlledEcr(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcecr({q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } -std::pair rxx(QIRProgramBuilder& b) { +template std::pair rxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rxx(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair singleControlledRxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crxx(0.123, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } +template std::pair multipleControlledRxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } +template std::pair tripleControlledRxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(5); b.mcrxx(0.123, {q[0], q[1], q[2]}, q[3], q[4]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4]}); + return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4]}, IntoRegister); } -std::pair ryy(QIRProgramBuilder& b) { +template std::pair ryy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ryy(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair singleControlledRyy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cryy(0.123, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } +template std::pair multipleControlledRyy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcryy(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } -std::pair rzx(QIRProgramBuilder& b) { +template std::pair rzx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rzx(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair singleControlledRzx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crzx(0.123, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } +template std::pair multipleControlledRzx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrzx(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } -std::pair rzz(QIRProgramBuilder& b) { +template std::pair rzz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rzz(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair singleControlledRzz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crzz(0.123, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } +template std::pair multipleControlledRzz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrzz(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } +template std::pair xxPlusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.xx_plus_yy(0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair singleControlledXxPlusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cxx_plus_yy(0.123, 0.456, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } +template std::pair multipleControlledXxPlusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcxx_plus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } +template std::pair xxMinusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.xx_minus_yy(0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister); } +template std::pair singleControlledXxMinusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cxx_minus_yy(0.123, 0.456, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); } +template std::pair multipleControlledXxMinusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcxx_minus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } +template std::pair simpleIf(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); auto cond = b.measure(q[0], 0); b.scfIf(cond, [&] { b.x(q[0]); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister, 1); } +template std::pair ifElse(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); auto cond = b.measure(q[0], 0); b.scfIf(cond, [&] { b.x(q[0]); }, [&] { b.z(q[0]); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {q[0]}, IntoRegister, 1); } +template std::pair ifTwoQubits(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.h(q[0]); @@ -885,9 +1049,10 @@ std::pair ifTwoQubits(QIRProgramBuilder& b) { b.x(q[0]); b.x(q[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, {q[0], q[1]}, IntoRegister, 1); } +template std::pair nestedIfOpForLoop(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); @@ -901,9 +1066,10 @@ std::pair nestedIfOpForLoop(QIRProgramBuilder& b) { b.h(q1); }); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], q0}); + return measureAndReturn(b, {q0}, IntoRegister, 1); } +template std::pair simpleWhileReset(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); @@ -913,9 +1079,10 @@ std::pair simpleWhileReset(QIRProgramBuilder& b) { return measureResult; }, [&] { b.h(q); }); - return measureAndReturn(b, {q}); + return measureAndReturn(b, {q}, IntoRegister, 1); } +template std::pair simpleDoWhileReset(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.scfWhile([&] { @@ -923,18 +1090,20 @@ std::pair simpleDoWhileReset(QIRProgramBuilder& b) { auto measureResult = b.measure(q, 0); return measureResult; }); - return measureAndReturn(b, {q}); + return measureAndReturn(b, {q}, IntoRegister, 1); } +template std::pair simpleForLoop(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(2); b.scfFor(0, 2, 1, [&](Value iv) { auto q = b.load(reg.value, iv); b.h(q); }); - return measureAndReturn(b, {reg[0], reg[1]}); + return measureAndReturn(b, {reg[0], reg[1]}, IntoRegister); }; +template std::pair nestedForLoopIfOp(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto qCond = b.allocQubit(); @@ -946,9 +1115,10 @@ std::pair nestedForLoopIfOp(QIRProgramBuilder& b) { b.h(q); }); }); - return measureAndReturn(b, {reg[0], reg[1], qCond}); + return measureAndReturn(b, {qCond}, IntoRegister, 1); } +template std::pair nestedForLoopWhileOp(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(2); b.scfFor(0, 2, 1, [&](Value iv) { @@ -964,9 +1134,10 @@ std::pair nestedForLoopWhileOp(QIRProgramBuilder& b) { }, [&] { b.h(q); }); }); - return measureAndReturn(b, {reg[0], reg[1]}); + return measureAndReturn(b, {reg[0], reg[1]}, IntoRegister, 1); } +template std::pair nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(3); @@ -977,9 +1148,10 @@ nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b) { b.h(q0); b.cx(control, q0); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], control}); + return measureAndReturn(b, {control}, IntoRegister); } +template std::pair nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(4); @@ -989,14 +1161,200 @@ nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b) { b.h(q0); b.cx(reg[0], q0); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, {reg[0]}, IntoRegister); } +template std::pair ctrlTwo(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcx({q[0], q[1]}, q[2]); b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); -} - + return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); +} + +// Instantiate the templates for both IntoRegister = true and IntoRegister = +// false +template std::pair emptyQIR(QIRProgramBuilder& builder); +template std::pair allocQubit(QIRProgramBuilder& b); +template std::pair +alloc1QubitRegister(QIRProgramBuilder& b); +template std::pair allocQubitRegister(QIRProgramBuilder& b); +template std::pair +alloc3QubitRegister(QIRProgramBuilder& b); +template std::pair +allocMultipleQubitRegisters(QIRProgramBuilder& b); +template std::pair +allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b); +template std::pair allocLargeRegister(QIRProgramBuilder& b); +template std::pair +singleMeasurementToSingleBit(QIRProgramBuilder& b); +template std::pair +repeatedMeasurementToSameBit(QIRProgramBuilder& b); +template std::pair +repeatedMeasurementToDifferentBits(QIRProgramBuilder& b); +template std::pair +multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b); +template std::pair +measurementWithoutRegisters(QIRProgramBuilder& b); +template std::pair +resetQubitWithoutOp(QIRProgramBuilder& b); +template std::pair +resetMultipleQubitsWithoutOp(QIRProgramBuilder& b); +template std::pair +repeatedResetWithoutOp(QIRProgramBuilder& b); +template std::pair +resetQubitAfterSingleOp(QIRProgramBuilder& b); +template std::pair +resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b); +template std::pair +repeatedResetAfterSingleOp(QIRProgramBuilder& b); +template std::pair globalPhase(QIRProgramBuilder& b); +template std::pair identity(QIRProgramBuilder& b); +template std::pair +singleControlledIdentity(QIRProgramBuilder& b); +template std::pair +twoQubitsOneIdentity(QIRProgramBuilder& b); +template std::pair +threeQubitsOneIdentity(QIRProgramBuilder& b); +template std::pair +multipleControlledIdentity(QIRProgramBuilder& b); +template std::pair x(QIRProgramBuilder& b); +template std::pair singleControlledX(QIRProgramBuilder& b); +template std::pair +multipleControlledX(QIRProgramBuilder& b); +template std::pair y(QIRProgramBuilder& b); +template std::pair singleControlledY(QIRProgramBuilder& b); +template std::pair +multipleControlledY(QIRProgramBuilder& b); +template std::pair z(QIRProgramBuilder& b); +template std::pair singleControlledZ(QIRProgramBuilder& b); +template std::pair +multipleControlledZ(QIRProgramBuilder& b); +template std::pair h(QIRProgramBuilder& b); +template std::pair singleControlledH(QIRProgramBuilder& b); +template std::pair +multipleControlledH(QIRProgramBuilder& b); +template std::pair hWithoutRegister(QIRProgramBuilder& b); +template std::pair s(QIRProgramBuilder& b); +template std::pair singleControlledS(QIRProgramBuilder& b); +template std::pair +multipleControlledS(QIRProgramBuilder& b); +template std::pair sdg(QIRProgramBuilder& b); +template std::pair +singleControlledSdg(QIRProgramBuilder& b); +template std::pair +multipleControlledSdg(QIRProgramBuilder& b); +template std::pair t_(QIRProgramBuilder& b); +template std::pair singleControlledT(QIRProgramBuilder& b); +template std::pair +multipleControlledT(QIRProgramBuilder& b); +template std::pair tdg(QIRProgramBuilder& b); +template std::pair +singleControlledTdg(QIRProgramBuilder& b); +template std::pair +multipleControlledTdg(QIRProgramBuilder& b); +template std::pair sx(QIRProgramBuilder& b); +template std::pair singleControlledSx(QIRProgramBuilder& b); +template std::pair +multipleControlledSx(QIRProgramBuilder& b); +template std::pair sxdg(QIRProgramBuilder& b); +template std::pair +singleControlledSxdg(QIRProgramBuilder& b); +template std::pair +multipleControlledSxdg(QIRProgramBuilder& b); +template std::pair rx(QIRProgramBuilder& b); +template std::pair singleControlledRx(QIRProgramBuilder& b); +template std::pair +multipleControlledRx(QIRProgramBuilder& b); +template std::pair ry(QIRProgramBuilder& b); +template std::pair singleControlledRy(QIRProgramBuilder& b); +template std::pair +multipleControlledRy(QIRProgramBuilder& b); +template std::pair rz(QIRProgramBuilder& b); +template std::pair singleControlledRz(QIRProgramBuilder& b); +template std::pair +multipleControlledRz(QIRProgramBuilder& b); +template std::pair p(QIRProgramBuilder& b); +template std::pair singleControlledP(QIRProgramBuilder& b); +template std::pair +multipleControlledP(QIRProgramBuilder& b); +template std::pair r(QIRProgramBuilder& b); +template std::pair singleControlledR(QIRProgramBuilder& b); +template std::pair +multipleControlledR(QIRProgramBuilder& b); +template std::pair u2(QIRProgramBuilder& b); +template std::pair singleControlledU2(QIRProgramBuilder& b); +template std::pair +multipleControlledU2(QIRProgramBuilder& b); +template std::pair u(QIRProgramBuilder& b); +template std::pair singleControlledU(QIRProgramBuilder& b); +template std::pair +multipleControlledU(QIRProgramBuilder& b); +template std::pair swap(QIRProgramBuilder& b); +template std::pair +singleControlledSwap(QIRProgramBuilder& b); +template std::pair +multipleControlledSwap(QIRProgramBuilder& b); +template std::pair iswap(QIRProgramBuilder& b); +template std::pair +singleControlledIswap(QIRProgramBuilder& b); +template std::pair +multipleControlledIswap(QIRProgramBuilder& b); +template std::pair dcx(QIRProgramBuilder& b); +template std::pair +singleControlledDcx(QIRProgramBuilder& b); +template std::pair +multipleControlledDcx(QIRProgramBuilder& b); +template std::pair ecr(QIRProgramBuilder& b); +template std::pair +singleControlledEcr(QIRProgramBuilder& b); +template std::pair +multipleControlledEcr(QIRProgramBuilder& b); +template std::pair rxx(QIRProgramBuilder& b); +template std::pair +singleControlledRxx(QIRProgramBuilder& b); +template std::pair +multipleControlledRxx(QIRProgramBuilder& b); +template std::pair +tripleControlledRxx(QIRProgramBuilder& b); +template std::pair ryy(QIRProgramBuilder& b); +template std::pair +singleControlledRyy(QIRProgramBuilder& b); +template std::pair +multipleControlledRyy(QIRProgramBuilder& b); +template std::pair rzx(QIRProgramBuilder& b); +template std::pair +singleControlledRzx(QIRProgramBuilder& b); +template std::pair +multipleControlledRzx(QIRProgramBuilder& b); +template std::pair rzz(QIRProgramBuilder& b); +template std::pair +singleControlledRzz(QIRProgramBuilder& b); +template std::pair +multipleControlledRzz(QIRProgramBuilder& b); +template std::pair xxPlusYY(QIRProgramBuilder& b); +template std::pair +singleControlledXxPlusYY(QIRProgramBuilder& b); +template std::pair +multipleControlledXxPlusYY(QIRProgramBuilder& b); +template std::pair xxMinusYY(QIRProgramBuilder& b); +template std::pair +singleControlledXxMinusYY(QIRProgramBuilder& b); +template std::pair +multipleControlledXxMinusYY(QIRProgramBuilder& b); +template std::pair simpleIf(QIRProgramBuilder& b); +template std::pair ifElse(QIRProgramBuilder& b); +template std::pair ifTwoQubits(QIRProgramBuilder& b); +template std::pair nestedIfOpForLoop(QIRProgramBuilder& b); +template std::pair simpleWhileReset(QIRProgramBuilder& b); +template std::pair simpleDoWhileReset(QIRProgramBuilder& b); +template std::pair simpleForLoop(QIRProgramBuilder& b); +template std::pair nestedForLoopIfOp(QIRProgramBuilder& b); +template std::pair +nestedForLoopWhileOp(QIRProgramBuilder& b); +template std::pair +nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b); +template std::pair +nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b); +template std::pair ctrlTwo(QIRProgramBuilder& b); } // namespace mlir::qir diff --git a/mlir/unittests/programs/qir_programs.h b/mlir/unittests/programs/qir_programs.h index de0d66d333..dd7d1d81f5 100644 --- a/mlir/unittests/programs/qir_programs.h +++ b/mlir/unittests/programs/qir_programs.h @@ -20,26 +20,37 @@ namespace mlir::qir { class QIRProgramBuilder; /// Creates an empty QIR program. +template std::pair emptyQIR(QIRProgramBuilder& builder); // --- Qubit Management ----------------------------------------------------- // /// Allocates a single qubit. +template std::pair allocQubit(QIRProgramBuilder& b); /// Allocates a qubit register of size `1`. +template std::pair alloc1QubitRegister(QIRProgramBuilder& b); /// Allocates a qubit register of size `2`. +template std::pair allocQubitRegister(QIRProgramBuilder& b); +/// Allocates a qubit register of size `3`. +template +std::pair alloc3QubitRegister(QIRProgramBuilder& b); + /// Allocates two qubit registers of size `2` and `3`. +template std::pair allocMultipleQubitRegisters(QIRProgramBuilder& b); /// Allocates two qubit registers of size `2` and `3` and applies operations. +template std::pair allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b); /// Allocates a large qubit register. +template std::pair allocLargeRegister(QIRProgramBuilder& b); /// Allocates two inline qubits. @@ -81,410 +92,528 @@ mixedDynamicRegisterThenStaticQubit(QIRProgramBuilder& b); // --- MeasureOp ------------------------------------------------------------ // /// Measures a single qubit into a single classical bit. +template std::pair singleMeasurementToSingleBit(QIRProgramBuilder& b); /// Repeatedly measures a single qubit into the same classical bit. +template std::pair repeatedMeasurementToSameBit(QIRProgramBuilder& b); /// Repeatedly measures a single qubit into different classical bits. +template std::pair repeatedMeasurementToDifferentBits(QIRProgramBuilder& b); /// Measures multiple qubits into multiple classical bits. +template std::pair multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b); /// Measures a single qubit into a single classical bit, without explicitly /// allocating a quantum or classical register. +template std::pair measurementWithoutRegisters(QIRProgramBuilder& b); // --- ResetOp -------------------------------------------------------------- // /// Resets a single qubit without any operations being applied. +template std::pair resetQubitWithoutOp(QIRProgramBuilder& b); /// Resets multiple qubits without any operations being applied. +template std::pair resetMultipleQubitsWithoutOp(QIRProgramBuilder& b); /// Repeatedly resets a single qubit without any operations being applied. +template std::pair repeatedResetWithoutOp(QIRProgramBuilder& b); /// Resets a single qubit after a single operation. +template std::pair resetQubitAfterSingleOp(QIRProgramBuilder& b); /// Resets multiple qubits after a single operation. +template std::pair resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b); /// Repeatedly resets a single qubit after a single operation. +template std::pair repeatedResetAfterSingleOp(QIRProgramBuilder& b); // --- GPhaseOp ------------------------------------------------------------- // /// Creates a circuit with just a global phase. +template std::pair globalPhase(QIRProgramBuilder& b); // --- IdOp ----------------------------------------------------------------- // /// Creates a circuit with just an identity gate. +template std::pair identity(QIRProgramBuilder& b); /// Creates a controlled identity gate with a single control qubit. +template std::pair singleControlledIdentity(QIRProgramBuilder& b); +/// Creates an identity gate on a single qubit in a two-qubit register. +template +std::pair twoQubitsOneIdentity(QIRProgramBuilder& b); + +/// Creates an identity gate on a single qubit in a three-qubit register. +template +std::pair threeQubitsOneIdentity(QIRProgramBuilder& b); + /// Creates a multi-controlled identity gate with multiple control qubits. +template std::pair multipleControlledIdentity(QIRProgramBuilder& b); // --- XOp ------------------------------------------------------------------ // /// Creates a circuit with just an X gate. +template std::pair x(QIRProgramBuilder& b); /// Creates a circuit with a single controlled X gate. +template std::pair singleControlledX(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled X gate. +template std::pair multipleControlledX(QIRProgramBuilder& b); // --- YOp ------------------------------------------------------------------ // /// Creates a circuit with just a Y gate. +template std::pair y(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Y gate. +template std::pair singleControlledY(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Y gate. +template std::pair multipleControlledY(QIRProgramBuilder& b); // --- ZOp ------------------------------------------------------------------ // /// Creates a circuit with just a Z gate. +template std::pair z(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Z gate. +template std::pair singleControlledZ(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Z gate. +template std::pair multipleControlledZ(QIRProgramBuilder& b); // --- HOp ------------------------------------------------------------------ // /// Creates a circuit with just an H gate. +template std::pair h(QIRProgramBuilder& b); /// Creates a circuit with a single controlled H gate. +template std::pair singleControlledH(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled H gate. +template std::pair multipleControlledH(QIRProgramBuilder& b); /// Creates a circuit with just an H gate and no qubit register. +template std::pair hWithoutRegister(QIRProgramBuilder& b); // --- SOp ------------------------------------------------------------------ // /// Creates a circuit with just an S gate. +template std::pair s(QIRProgramBuilder& b); /// Creates a circuit with a single controlled S gate. +template std::pair singleControlledS(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled S gate. +template std::pair multipleControlledS(QIRProgramBuilder& b); // --- SdgOp ---------------------------------------------------------------- // /// Creates a circuit with just an Sdg gate. +template std::pair sdg(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Sdg gate. +template std::pair singleControlledSdg(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Sdg gate. +template std::pair multipleControlledSdg(QIRProgramBuilder& b); // --- TOp ------------------------------------------------------------------ // /// Creates a circuit with just a T gate. +template std::pair t_(QIRProgramBuilder& b); // NOLINT(*-identifier-naming) /// Creates a circuit with a single controlled T gate. +template std::pair singleControlledT(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled T gate. +template std::pair multipleControlledT(QIRProgramBuilder& b); // --- TdgOp ---------------------------------------------------------------- // /// Creates a circuit with just a Tdg gate. +template std::pair tdg(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Tdg gate. +template std::pair singleControlledTdg(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Tdg gate. +template std::pair multipleControlledTdg(QIRProgramBuilder& b); // --- SXOp ----------------------------------------------------------------- // /// Creates a circuit with just an SX gate. +template std::pair sx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled SX gate. +template std::pair singleControlledSx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled SX gate. +template std::pair multipleControlledSx(QIRProgramBuilder& b); // --- SXdgOp --------------------------------------------------------------- // /// Creates a circuit with just an SXdg gate. +template std::pair sxdg(QIRProgramBuilder& b); /// Creates a circuit with a single controlled SXdg gate. +template std::pair singleControlledSxdg(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled SXdg gate. +template std::pair multipleControlledSxdg(QIRProgramBuilder& b); // --- RXOp ----------------------------------------------------------------- // /// Creates a circuit with just an RX gate. +template std::pair rx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RX gate. +template std::pair singleControlledRx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RX gate. +template std::pair multipleControlledRx(QIRProgramBuilder& b); // --- RYOp ----------------------------------------------------------------- // /// Creates a circuit with just an RY gate. +template std::pair ry(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RY gate. +template std::pair singleControlledRy(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RY gate. +template std::pair multipleControlledRy(QIRProgramBuilder& b); // --- RZOp ----------------------------------------------------------------- // /// Creates a circuit with just an RZ gate. +template std::pair rz(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RZ gate. +template std::pair singleControlledRz(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RZ gate. +template std::pair multipleControlledRz(QIRProgramBuilder& b); // --- POp ------------------------------------------------------------------ // /// Creates a circuit with just a P gate. +template std::pair p(QIRProgramBuilder& b); /// Creates a circuit with a single controlled P gate. +template std::pair singleControlledP(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled P gate. +template std::pair multipleControlledP(QIRProgramBuilder& b); // --- ROp ------------------------------------------------------------------ // /// Creates a circuit with just an R gate. +template std::pair r(QIRProgramBuilder& b); /// Creates a circuit with a single controlled R gate. +template std::pair singleControlledR(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled R gate. +template std::pair multipleControlledR(QIRProgramBuilder& b); // --- U2Op ----------------------------------------------------------------- // /// Creates a circuit with just a U2 gate. +template std::pair u2(QIRProgramBuilder& b); /// Creates a circuit with a single controlled U2 gate. +template std::pair singleControlledU2(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled U2 gate. +template std::pair multipleControlledU2(QIRProgramBuilder& b); // --- UOp ------------------------------------------------------------------ // /// Creates a circuit with just a U gate. +template std::pair u(QIRProgramBuilder& b); /// Creates a circuit with a single controlled U gate. +template std::pair singleControlledU(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled U gate. +template std::pair multipleControlledU(QIRProgramBuilder& b); // --- SWAPOp --------------------------------------------------------------- // /// Creates a circuit with just a SWAP gate. +template std::pair swap(QIRProgramBuilder& b); /// Creates a circuit with a single controlled SWAP gate. +template std::pair singleControlledSwap(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled SWAP gate. +template std::pair multipleControlledSwap(QIRProgramBuilder& b); // --- iSWAPOp -------------------------------------------------------------- // /// Creates a circuit with just an iSWAP gate. +template std::pair iswap(QIRProgramBuilder& b); /// Creates a circuit with a single controlled iSWAP gate. +template std::pair singleControlledIswap(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled iSWAP gate. +template std::pair multipleControlledIswap(QIRProgramBuilder& b); // --- DCXOp ---------------------------------------------------------------- // /// Creates a circuit with just a DCX gate. +template std::pair dcx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled DCX gate. +template std::pair singleControlledDcx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled DCX gate. +template std::pair multipleControlledDcx(QIRProgramBuilder& b); // --- ECROp ---------------------------------------------------------------- // /// Creates a circuit with just an ECR gate. +template std::pair ecr(QIRProgramBuilder& b); /// Creates a circuit with a single controlled ECR gate. +template std::pair singleControlledEcr(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled ECR gate. +template std::pair multipleControlledEcr(QIRProgramBuilder& b); // --- RXXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RXX gate. +template std::pair rxx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RXX gate. +template std::pair singleControlledRxx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RXX gate. +template std::pair multipleControlledRxx(QIRProgramBuilder& b); /// Creates a circuit with a triple-controlled RXX gate. +template std::pair tripleControlledRxx(QIRProgramBuilder& b); // --- RYYOp ---------------------------------------------------------------- // /// Creates a circuit with just an RYY gate. +template std::pair ryy(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RYY gate. +template std::pair singleControlledRyy(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RYY gate. +template std::pair multipleControlledRyy(QIRProgramBuilder& b); // --- RZXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZX gate. +template std::pair rzx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RZX gate. +template std::pair singleControlledRzx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RZX gate. +template std::pair multipleControlledRzx(QIRProgramBuilder& b); // --- RZZOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZZ gate. +template std::pair rzz(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RZZ gate. +template std::pair singleControlledRzz(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RZZ gate. +template std::pair multipleControlledRzz(QIRProgramBuilder& b); // --- XXPlusYYOp ----------------------------------------------------------- // /// Creates a circuit with just an XXPlusYY gate. +template std::pair xxPlusYY(QIRProgramBuilder& b); /// Creates a circuit with a single controlled XXPlusYY gate. +template std::pair singleControlledXxPlusYY(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled XXPlusYY gate. +template std::pair multipleControlledXxPlusYY(QIRProgramBuilder& b); // --- XXMinusYYOp ---------------------------------------------------------- // /// Creates a circuit with just an XXMinusYY gate. +template std::pair xxMinusYY(QIRProgramBuilder& b); /// Creates a circuit with a single controlled XXMinusYY gate. +template std::pair singleControlledXxMinusYY(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled XXMinusYY gate. +template std::pair multipleControlledXxMinusYY(QIRProgramBuilder& b); // --- IfOp ----------------------------------------------------------------- // /// Creates a circuit with a simple if operation with one qubit. +template std::pair simpleIf(QIRProgramBuilder& b); /// Creates a circuit with an if operation with an else branch. +template std::pair ifElse(QIRProgramBuilder& b); /// Creates a circuit with an if operation with two qubits. +template std::pair ifTwoQubits(QIRProgramBuilder& b); /// Creates a circuit with an if operation with a nested for operation with /// a register. +template std::pair nestedIfOpForLoop(QIRProgramBuilder& b); // --- WhileOp -------------------------------------------------------------- // /// Creates a circuit with a while operation using a while loop. +template std::pair simpleWhileReset(QIRProgramBuilder& b); /// Creates a circuit with a while operation using a do-while loop. +template std::pair simpleDoWhileReset(QIRProgramBuilder& b); // --- ForOp ---------------------------------------------------------------- // /// Creates a circuit with a simple for operation with a register. +template std::pair simpleForLoop(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested if operation. +template std::pair nestedForLoopIfOp(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a nested while /// operation. +template std::pair nestedForLoopWhileOp(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is separately allocated from the /// register. +template std::pair nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is extracted from the register. +template std::pair nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b); // --- CtrlOp --------------------------------------------------------------- // /// Creates a circuit with a control modifier applied to two gates. +template std::pair ctrlTwo(QIRProgramBuilder& b); } // namespace mlir::qir From 304f53079ab05cb5390d3c092d1f5d941ecbb2bd Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 25 Jun 2026 14:59:10 +0200 Subject: [PATCH 34/80] fix(mlir): :bug: fix minor issue in `test_qco_ir` unittest --- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 6e10f8c1d0..fec7904163 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -1089,7 +1089,7 @@ INSTANTIATE_TEST_SUITE_P( QCOTestCase{"ControlledTwoX", MQT_NAMED_BUILDER(controlledTwoX), MQT_NAMED_BUILDER(alloc2QubitRegister)}, QCOTestCase{"InverseTwoX", MQT_NAMED_BUILDER(inverseTwoX), - MQT_NAMED_BUILDER(alloc2QubitRegister)})); + MQT_NAMED_BUILDER(alloc1QubitRegister)})); /// @} /// \name QCO/Operations/StandardGates/XxMinusYyOp.cpp From 29d9627d2a5f5de3a3210199a4021b6a171193b3 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 25 Jun 2026 15:10:46 +0200 Subject: [PATCH 35/80] test(mlir): :white_check_mark: pass QCO->QC tests --- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 2 +- mlir/unittests/programs/qco_programs.cpp | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index fec7904163..d2c0c276ae 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -1269,5 +1269,5 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(staticQubitsWithInv), MQT_NAMED_BUILDER(staticQubitsWithInv)}, QCOTestCase{"AllocSinkPair", MQT_NAMED_BUILDER(allocSinkPair), - MQT_NAMED_BUILDER(allocQubit)})); + MQT_NAMED_BUILDER(allocQubitNoMeasure)})); /// @} diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 3f482c68cf..5bb75c2571 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -54,7 +54,7 @@ namespace mlir::qco { std::pair, SmallVector> emptyQCO(QCOProgramBuilder& b) { - return measureAndReturn(b, {}); + return {{b.intConstant(0)}, {b.getI64Type()}}; } std::pair, SmallVector> @@ -66,7 +66,7 @@ allocQubit(QCOProgramBuilder& b) { std::pair, SmallVector> allocQubitNoMeasure(QCOProgramBuilder& b) { auto q = b.allocQubit(); - return measureAndReturn(b, {}); + return {{b.intConstant(0)}, {b.getI64Type()}}; } std::pair, SmallVector> @@ -104,7 +104,7 @@ std::pair, SmallVector> staticQubitsNoMeasure(QCOProgramBuilder& b) { auto q1 = b.staticQubit(0); auto q2 = b.staticQubit(1); - return measureAndReturn(b, {}); + return {{b.intConstant(0)}, {b.getI64Type()}}; } std::pair, SmallVector> @@ -160,9 +160,8 @@ staticQubitsWithInv(QCOProgramBuilder& b) { std::pair, SmallVector> allocSinkPair(QCOProgramBuilder& b) { auto q = b.allocQubit(); - auto [q1, c] = b.measure(q); - b.sink(q1); - return {{c}, {b.getI1Type()}}; + b.sink(q); + return {{b.intConstant(0)}, {b.getI64Type()}}; } std::pair, SmallVector> From 8ca4c966a8e4e34ce259cc6a5c2df555dee9f855 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 25 Jun 2026 15:48:57 +0200 Subject: [PATCH 36/80] test(mlir): :white_check_mark: pass quantum_computation translation tests and fix other tests where necessary --- .../test_quantum_computation_translation.cpp | 9 +- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 5 +- .../Dialect/QTensor/IR/test_qtensor_ir.cpp | 11 +- mlir/unittests/programs/qc_programs.cpp | 10 +- mlir/unittests/programs/qco_programs.cpp | 33 ++-- mlir/unittests/programs/qir_programs.cpp | 167 +++++++++++++++++- .../programs/quantum_computation_programs.cpp | 3 +- 7 files changed, 211 insertions(+), 27 deletions(-) diff --git a/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp b/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp index b47c9f97a7..b39e35ed42 100644 --- a/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp +++ b/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp @@ -36,7 +36,10 @@ namespace { struct QuantumComputationTranslationTestCase { std::string name; mqt::test::NamedBuilder<::qc::QuantumComputation> programBuilder; - mqt::test::NamedBuilder referenceBuilder; + mqt::test::NamedBuilder< + mlir::qc::QCProgramBuilder, + std::pair, llvm::SmallVector>> + referenceBuilder; friend std::ostream& operator<<(std::ostream& os, @@ -107,7 +110,7 @@ INSTANTIATE_TEST_SUITE_P( testing::Values( QuantumComputationTranslationTestCase{ "AllocQubit", MQT_NAMED_BUILDER(qc::allocQubit), - MQT_NAMED_BUILDER(mlir::qc::allocQubit)}, + MQT_NAMED_BUILDER(mlir::qc::alloc1QubitRegister)}, QuantumComputationTranslationTestCase{ "AllocQubitRegister", MQT_NAMED_BUILDER(qc::allocQubitRegister), MQT_NAMED_BUILDER(mlir::qc::allocQubitRegister)}, @@ -160,7 +163,7 @@ INSTANTIATE_TEST_SUITE_P( QuantumComputationTranslationTestCase{ "MultipleControlledIdentity", MQT_NAMED_BUILDER(qc::multipleControlledIdentity), - MQT_NAMED_BUILDER(mlir::qc::multipleControlledIdentity)}, + MQT_NAMED_BUILDER(mlir::qc::identity)}, QuantumComputationTranslationTestCase{"X", MQT_NAMED_BUILDER(qc::x), MQT_NAMED_BUILDER(mlir::qc::x)}, QuantumComputationTranslationTestCase{ diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index d2c0c276ae..ef54694351 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -235,7 +235,7 @@ TEST_F(QCOTest, CheckIfOpDeadGateElimination) { TEST_F(QCOTest, DirectIfBuilder) { // Test If construction directly QCOProgramBuilder builder(context.get()); - builder.initialize({builder.getI1Type()}); + builder.initialize({builder.getI1Type(), builder.getI1Type()}); auto c0 = arith::ConstantIndexOp::create(builder, 0); auto c1 = arith::ConstantIndexOp::create(builder, 1); auto r0 = qtensor::AllocOp::create(builder, c1); @@ -253,7 +253,8 @@ TEST_F(QCOTest, DirectIfBuilder) { extractOp.getOutTensor(), c0); qtensor::DeallocOp::create(builder, r2); - auto directBuilder = builder.finalize({finalMeasureOp.getResult()}); + auto directBuilder = + builder.finalize({measureOp.getResult(), finalMeasureOp.getResult()}); ASSERT_TRUE(directBuilder); EXPECT_TRUE(verify(*directBuilder).succeeded()); EXPECT_TRUE(runQCOCleanupPipeline(directBuilder.get()).succeeded()); diff --git a/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp b/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp index 335a7ad448..46320029c5 100644 --- a/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp +++ b/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp @@ -63,7 +63,8 @@ class QTensorTest : public ::testing::Test { /// Build a module using the QCOProgramBuilder and run the cleanup pipeline. [[nodiscard]] OwningOpRef - buildAndCanonicalize(void (*buildFn)(QCOProgramBuilder&)) const { + buildAndCanonicalize(std::pair, SmallVector> ( + *buildFn)(QCOProgramBuilder&)) const { auto module = QCOProgramBuilder::build(context.get(), buildFn); if (!module) { return {}; @@ -189,8 +190,12 @@ TEST_F(QTensorTest, AllocOpStaticTypeWithDynamicSizeOperandFailsVerification) { /// An alloc immediately followed by dealloc should be eliminated entirely. TEST_F(QTensorTest, DeallocOpAllocDeallocPairIsRemoved) { - auto canonicalized = - buildAndCanonicalize([](QCOProgramBuilder& b) { b.qtensorAlloc(3); }); + auto canonicalized = buildAndCanonicalize( + [](QCOProgramBuilder& b) + -> std::pair, SmallVector> { + b.qtensorAlloc(3); + return {{b.intConstant(0)}, {b.getI64Type()}}; + }); ASSERT_TRUE(canonicalized); EXPECT_TRUE(verify(*canonicalized).succeeded()); // Both AllocOp and DeallocOp should have been erased. diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index aae3435c4f..aa5fccd881 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -2012,7 +2012,8 @@ std::pair, SmallVector> simpleIf(QCProgramBuilder& b) { b.h(q[0]); auto cond = b.measure(q[0]); b.scfIf(cond, [&] { b.x(q[0]); }); - return measureAndReturn(b, {q[0]}); + auto res = b.measure(q[0]); + return {{cond, res}, {b.getI1Type(), b.getI1Type()}}; } std::pair, SmallVector> ifElse(QCProgramBuilder& b) { @@ -2020,7 +2021,8 @@ std::pair, SmallVector> ifElse(QCProgramBuilder& b) { b.h(q[0]); auto cond = b.measure(q[0]); b.scfIf(cond, [&] { b.x(q[0]); }, [&] { b.z(q[0]); }); - return measureAndReturn(b, {q[0]}); + auto bit = b.measure(q[0]); + return {{cond, bit}, {b.getI1Type(), b.getI1Type()}}; } std::pair, SmallVector> @@ -2032,7 +2034,9 @@ ifTwoQubits(QCProgramBuilder& b) { b.x(q[0]); b.x(q[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + auto c0 = b.measure(q[0]); + auto c1 = b.measure(q[1]); + return {{cond, c0, c1}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; } std::pair, SmallVector> diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 5bb75c2571..d9b2ecabbf 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -3285,7 +3285,8 @@ simpleIf(QCOProgramBuilder& b) { return SmallVector{innerQubit}; }); q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + auto [q1, bit] = b.measure(q[0]); + return {{measureResult, bit}, {b.getI1Type(), b.getI1Type()}}; } std::pair, SmallVector> @@ -3314,7 +3315,10 @@ ifTwoQubits(QCOProgramBuilder& b) { }); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + auto [q0_, c0] = b.measure(q[0]); + auto [q1, c1] = b.measure(q[1]); + return {{measureResult, c0, c1}, + {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; } std::pair, SmallVector> ifElse(QCOProgramBuilder& b) { @@ -3332,7 +3336,8 @@ std::pair, SmallVector> ifElse(QCOProgramBuilder& b) { return SmallVector{innerQubit}; }); q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + auto [q0_, c0] = b.measure(q[0]); + return {{measureResult, c0}, {b.getI1Type(), b.getI1Type()}}; } std::pair, SmallVector> @@ -3397,7 +3402,8 @@ nestedTrueIf(QCOProgramBuilder& b) { }); return llvm::to_vector(innerResult); }); - return measureAndReturn(b, {ifRes[0]}); + auto [q1, c] = b.measure(ifRes[0]); + return {{measureResult, c}, {b.getI1Type(), b.getI1Type()}}; } std::pair, SmallVector> @@ -3421,13 +3427,14 @@ nestedFalseIf(QCOProgramBuilder& b) { }); return llvm::to_vector(innerResult); }); - return measureAndReturn(b, {ifRes[0]}); + auto [q1, c] = b.measure(ifRes[0]); + return {{measureResult, c}, {b.getI1Type(), b.getI1Type()}}; } std::pair, SmallVector> qtensorAlloc(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); - return measureAndReturn(b, {qtensor}); + return measureAndReturn(b, {}); } std::pair, SmallVector> @@ -3443,14 +3450,14 @@ qtensorFromElements(QCOProgramBuilder& b) { auto q1 = b.allocQubit(); auto q2 = b.allocQubit(); auto t = b.qtensorFromElements({q0, q1, q2}); - return measureAndReturn(b, {t}); + return measureAndReturn(b, {}); } std::pair, SmallVector> qtensorExtract(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [t, q] = b.qtensorExtract(qtensor, 0); - return measureAndReturn(b, {t, q}); + return measureAndReturn(b, {q}); } std::pair, SmallVector> @@ -3459,7 +3466,7 @@ qtensorInsert(QCOProgramBuilder& b) { auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); auto q1 = b.h(q0); auto insertOutTensor = b.qtensorInsert(q1, extractOutTensor, 0); - return measureAndReturn(b, {insertOutTensor}); + return measureAndReturn(b, {}); } std::pair, SmallVector> @@ -3467,7 +3474,7 @@ qtensorExtractInsertIndexMismatch(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); auto insertOutTensor = b.qtensorInsert(q0, extractOutTensor, 1); - return measureAndReturn(b, {insertOutTensor}); + return measureAndReturn(b, {}); } std::pair, SmallVector> @@ -3475,7 +3482,7 @@ qtensorExtractInsertSameIndex(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); auto insertOutTensor = b.qtensorInsert(q0, extractOutTensor, 0); - return measureAndReturn(b, {insertOutTensor}); + return measureAndReturn(b, {}); } std::pair, SmallVector> @@ -3486,7 +3493,7 @@ qtensorInsertExtractIndexMismatch(QCOProgramBuilder& b) { auto insertOutTensor = b.qtensorInsert(q1, extractOutTensor, 0); auto [extractOutTensor1, q2] = b.qtensorExtract(insertOutTensor, 1); auto insertOutTensor1 = b.qtensorInsert(q2, extractOutTensor1, 0); - return measureAndReturn(b, {insertOutTensor1}); + return measureAndReturn(b, {}); } std::pair, SmallVector> @@ -3497,7 +3504,7 @@ qtensorInsertExtractSameIndex(QCOProgramBuilder& b) { auto insertOutTensor = b.qtensorInsert(q1, extractOutTensor, 0); auto [extractOutTensor1, q2] = b.qtensorExtract(insertOutTensor, 0); auto insertOutTensor1 = b.qtensorInsert(q2, extractOutTensor1, 0); - return measureAndReturn(b, {insertOutTensor1}); + return measureAndReturn(b, {}); } std::pair, SmallVector> diff --git a/mlir/unittests/programs/qir_programs.cpp b/mlir/unittests/programs/qir_programs.cpp index 8db3b2fd77..8094587a0d 100644 --- a/mlir/unittests/programs/qir_programs.cpp +++ b/mlir/unittests/programs/qir_programs.cpp @@ -1172,8 +1172,7 @@ std::pair ctrlTwo(QIRProgramBuilder& b) { return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } -// Instantiate the templates for both IntoRegister = true and IntoRegister = -// false +// Instantiate the templates for IntoRegister = false template std::pair emptyQIR(QIRProgramBuilder& builder); template std::pair allocQubit(QIRProgramBuilder& b); template std::pair @@ -1357,4 +1356,168 @@ nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b); template std::pair nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b); template std::pair ctrlTwo(QIRProgramBuilder& b); + +// Instantiate the templates for IntoRegister = true +template std::pair emptyQIR(QIRProgramBuilder& builder); +template std::pair allocQubit(QIRProgramBuilder& b); +template std::pair alloc1QubitRegister(QIRProgramBuilder& b); +template std::pair allocQubitRegister(QIRProgramBuilder& b); +template std::pair alloc3QubitRegister(QIRProgramBuilder& b); +template std::pair +allocMultipleQubitRegisters(QIRProgramBuilder& b); +template std::pair +allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b); +template std::pair allocLargeRegister(QIRProgramBuilder& b); +template std::pair +singleMeasurementToSingleBit(QIRProgramBuilder& b); +template std::pair +repeatedMeasurementToSameBit(QIRProgramBuilder& b); +template std::pair +repeatedMeasurementToDifferentBits(QIRProgramBuilder& b); +template std::pair +multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b); +template std::pair +measurementWithoutRegisters(QIRProgramBuilder& b); +template std::pair resetQubitWithoutOp(QIRProgramBuilder& b); +template std::pair +resetMultipleQubitsWithoutOp(QIRProgramBuilder& b); +template std::pair +repeatedResetWithoutOp(QIRProgramBuilder& b); +template std::pair +resetQubitAfterSingleOp(QIRProgramBuilder& b); +template std::pair +resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b); +template std::pair +repeatedResetAfterSingleOp(QIRProgramBuilder& b); +template std::pair globalPhase(QIRProgramBuilder& b); +template std::pair identity(QIRProgramBuilder& b); +template std::pair +singleControlledIdentity(QIRProgramBuilder& b); +template std::pair +twoQubitsOneIdentity(QIRProgramBuilder& b); +template std::pair +threeQubitsOneIdentity(QIRProgramBuilder& b); +template std::pair +multipleControlledIdentity(QIRProgramBuilder& b); +template std::pair x(QIRProgramBuilder& b); +template std::pair singleControlledX(QIRProgramBuilder& b); +template std::pair multipleControlledX(QIRProgramBuilder& b); +template std::pair y(QIRProgramBuilder& b); +template std::pair singleControlledY(QIRProgramBuilder& b); +template std::pair multipleControlledY(QIRProgramBuilder& b); +template std::pair z(QIRProgramBuilder& b); +template std::pair singleControlledZ(QIRProgramBuilder& b); +template std::pair multipleControlledZ(QIRProgramBuilder& b); +template std::pair h(QIRProgramBuilder& b); +template std::pair singleControlledH(QIRProgramBuilder& b); +template std::pair multipleControlledH(QIRProgramBuilder& b); +template std::pair hWithoutRegister(QIRProgramBuilder& b); +template std::pair s(QIRProgramBuilder& b); +template std::pair singleControlledS(QIRProgramBuilder& b); +template std::pair multipleControlledS(QIRProgramBuilder& b); +template std::pair sdg(QIRProgramBuilder& b); +template std::pair singleControlledSdg(QIRProgramBuilder& b); +template std::pair +multipleControlledSdg(QIRProgramBuilder& b); +template std::pair t_(QIRProgramBuilder& b); +template std::pair singleControlledT(QIRProgramBuilder& b); +template std::pair multipleControlledT(QIRProgramBuilder& b); +template std::pair tdg(QIRProgramBuilder& b); +template std::pair singleControlledTdg(QIRProgramBuilder& b); +template std::pair +multipleControlledTdg(QIRProgramBuilder& b); +template std::pair sx(QIRProgramBuilder& b); +template std::pair singleControlledSx(QIRProgramBuilder& b); +template std::pair +multipleControlledSx(QIRProgramBuilder& b); +template std::pair sxdg(QIRProgramBuilder& b); +template std::pair +singleControlledSxdg(QIRProgramBuilder& b); +template std::pair +multipleControlledSxdg(QIRProgramBuilder& b); +template std::pair rx(QIRProgramBuilder& b); +template std::pair singleControlledRx(QIRProgramBuilder& b); +template std::pair +multipleControlledRx(QIRProgramBuilder& b); +template std::pair ry(QIRProgramBuilder& b); +template std::pair singleControlledRy(QIRProgramBuilder& b); +template std::pair +multipleControlledRy(QIRProgramBuilder& b); +template std::pair rz(QIRProgramBuilder& b); +template std::pair singleControlledRz(QIRProgramBuilder& b); +template std::pair +multipleControlledRz(QIRProgramBuilder& b); +template std::pair p(QIRProgramBuilder& b); +template std::pair singleControlledP(QIRProgramBuilder& b); +template std::pair multipleControlledP(QIRProgramBuilder& b); +template std::pair r(QIRProgramBuilder& b); +template std::pair singleControlledR(QIRProgramBuilder& b); +template std::pair multipleControlledR(QIRProgramBuilder& b); +template std::pair u2(QIRProgramBuilder& b); +template std::pair singleControlledU2(QIRProgramBuilder& b); +template std::pair +multipleControlledU2(QIRProgramBuilder& b); +template std::pair u(QIRProgramBuilder& b); +template std::pair singleControlledU(QIRProgramBuilder& b); +template std::pair multipleControlledU(QIRProgramBuilder& b); +template std::pair swap(QIRProgramBuilder& b); +template std::pair +singleControlledSwap(QIRProgramBuilder& b); +template std::pair +multipleControlledSwap(QIRProgramBuilder& b); +template std::pair iswap(QIRProgramBuilder& b); +template std::pair +singleControlledIswap(QIRProgramBuilder& b); +template std::pair +multipleControlledIswap(QIRProgramBuilder& b); +template std::pair dcx(QIRProgramBuilder& b); +template std::pair singleControlledDcx(QIRProgramBuilder& b); +template std::pair +multipleControlledDcx(QIRProgramBuilder& b); +template std::pair ecr(QIRProgramBuilder& b); +template std::pair singleControlledEcr(QIRProgramBuilder& b); +template std::pair +multipleControlledEcr(QIRProgramBuilder& b); +template std::pair rxx(QIRProgramBuilder& b); +template std::pair singleControlledRxx(QIRProgramBuilder& b); +template std::pair +multipleControlledRxx(QIRProgramBuilder& b); +template std::pair tripleControlledRxx(QIRProgramBuilder& b); +template std::pair ryy(QIRProgramBuilder& b); +template std::pair singleControlledRyy(QIRProgramBuilder& b); +template std::pair +multipleControlledRyy(QIRProgramBuilder& b); +template std::pair rzx(QIRProgramBuilder& b); +template std::pair singleControlledRzx(QIRProgramBuilder& b); +template std::pair +multipleControlledRzx(QIRProgramBuilder& b); +template std::pair rzz(QIRProgramBuilder& b); +template std::pair singleControlledRzz(QIRProgramBuilder& b); +template std::pair +multipleControlledRzz(QIRProgramBuilder& b); +template std::pair xxPlusYY(QIRProgramBuilder& b); +template std::pair +singleControlledXxPlusYY(QIRProgramBuilder& b); +template std::pair +multipleControlledXxPlusYY(QIRProgramBuilder& b); +template std::pair xxMinusYY(QIRProgramBuilder& b); +template std::pair +singleControlledXxMinusYY(QIRProgramBuilder& b); +template std::pair +multipleControlledXxMinusYY(QIRProgramBuilder& b); +template std::pair simpleIf(QIRProgramBuilder& b); +template std::pair ifElse(QIRProgramBuilder& b); +template std::pair ifTwoQubits(QIRProgramBuilder& b); +template std::pair nestedIfOpForLoop(QIRProgramBuilder& b); +template std::pair simpleWhileReset(QIRProgramBuilder& b); +template std::pair simpleDoWhileReset(QIRProgramBuilder& b); +template std::pair simpleForLoop(QIRProgramBuilder& b); +template std::pair nestedForLoopIfOp(QIRProgramBuilder& b); +template std::pair +nestedForLoopWhileOp(QIRProgramBuilder& b); +template std::pair +nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b); +template std::pair +nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b); +template std::pair ctrlTwo(QIRProgramBuilder& b); } // namespace mlir::qir diff --git a/mlir/unittests/programs/quantum_computation_programs.cpp b/mlir/unittests/programs/quantum_computation_programs.cpp index 133ba5e736..4f8d99254a 100644 --- a/mlir/unittests/programs/quantum_computation_programs.cpp +++ b/mlir/unittests/programs/quantum_computation_programs.cpp @@ -674,7 +674,8 @@ void simpleIf(QuantumComputation& comp) { comp.h(q[0]); comp.measure(q[0], c[0]); comp.if_(X, q[0], c[0]); - comp.measureAll(true, false); + const auto& c2 = comp.addClassicalRegister(1, "meas"); + comp.measure(q[0], c2[0]); } void ifTwoQubits(QuantumComputation& comp) { From 7ae38984e22664400007c99f386a72b315684dd7 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Mon, 6 Jul 2026 16:38:09 +0200 Subject: [PATCH 37/80] feat(mlir): :sparkles: update qc->qir conversion to handle return values This commit was created with major help from Gemini 3.1 Pro and Claude Opus 4.6 --- .../Conversion/QCToQIR/QIRCommon/QIRCommon.h | 33 ++ .../Dialect/QIR/Builder/QIRProgramBuilder.h | 12 +- .../QCToQIR/QIRAdaptive/QCToQIRAdaptive.cpp | 21 +- .../QCToQIR/QIRBase/QCToQIRBase.cpp | 17 +- .../QCToQIR/QIRCommon/QIRCommon.cpp | 40 ++ .../Dialect/QIR/Builder/QIRProgramBuilder.cpp | 30 +- .../QCToQIRBase/test_qc_to_qir_base.cpp | 422 +++++++++-------- mlir/unittests/programs/qir_programs.cpp | 430 ++++++------------ 8 files changed, 511 insertions(+), 494 deletions(-) diff --git a/mlir/include/mlir/Conversion/QCToQIR/QIRCommon/QIRCommon.h b/mlir/include/mlir/Conversion/QCToQIR/QIRCommon/QIRCommon.h index c92bf5f9d2..d519460775 100644 --- a/mlir/include/mlir/Conversion/QCToQIR/QIRCommon/QIRCommon.h +++ b/mlir/include/mlir/Conversion/QCToQIR/QIRCommon/QIRCommon.h @@ -70,6 +70,15 @@ struct LoweringState : QIRMetadata { Block* measurementsBlock{}; Block* outputBlock{}; + /// Set of MeasureOps whose results should be recorded in the output. + DenseSet returnedMeasurements; + + /// Set of array register names that should be recorded in the output. + DenseSet recordedArrays; + + /// Set of unnamed result indices that should be recorded in the output. + DenseSet recordedIndices; + /// The qubit allocation mode used in the module AllocationMode allocationMode = AllocationMode::Unset; @@ -155,4 +164,28 @@ void populateQCToQIRPatterns(RewritePatternSet& patterns, void addOutputRecording(LLVM::LLVMFuncOp& main, MLIRContext* ctx, LoweringState& state); +/** + * @brief Strips returned measurement results from function return statements + * + * @details + * Walks all `func::ReturnOp` operations in the module to identify operands + * that are directly defined by a `qc::MeasureOp`. For each such operand: + * - The defining `MeasureOp` is added to `state.returnedMeasurements` so that + * it will be included in the QIR output recording. + * - The operand is removed from the return statement. + * + * Non-measurement return values are preserved. After stripping, the enclosing + * `func::FuncOp` function type is updated to match the new return operands. + * + * This must be called **before** func-to-LLVM conversion, while + * `func::ReturnOp` and `qc::MeasureOp` are still in the IR. + * + * Return values that are indirectly computed from measurement outcomes remain + * unaffected. + * + * @param moduleOp The top-level module operation to walk + * @param state The lowering state; `returnedMeasurements` is populated + */ +void stripReturnedMeasurements(Operation* moduleOp, LoweringState& state); + } // namespace mlir diff --git a/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h b/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h index d8f5bd3173..059c91edd8 100644 --- a/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h @@ -323,6 +323,7 @@ class QIRProgramBuilder final : public ImplicitLocOpBuilder { * * @param qubit The qubit to measure * @param resultIndex The classical bit index for result pointer + * @param record Whether the measurement should be recorded in the output * @return An LLVM pointer to the measurement result * * @par Example: @@ -343,7 +344,7 @@ class QIRProgramBuilder final : public ImplicitLocOpBuilder { * !llvm.ptr) -> () * ``` */ - Value measure(Value qubit, int64_t resultIndex); + Value measure(Value qubit, int64_t resultIndex, bool record = true); /** * @brief Measure a qubit into a classical register @@ -356,6 +357,7 @@ class QIRProgramBuilder final : public ImplicitLocOpBuilder { * * @param qubit The qubit to measure * @param bit The classical bit to store the result + * @param record Whether the measurement should be recorded in the output * @return An LLVM pointer to the measurement result * * @par Example: @@ -379,7 +381,7 @@ class QIRProgramBuilder final : public ImplicitLocOpBuilder { * : (i64, !llvm.ptr, !llvm.ptr) -> () * ``` */ - Value measure(Value qubit, const Bit& bit); + Value measure(Value qubit, const Bit& bit, bool record = true); /** * @brief Reset a qubit to |0⟩ state @@ -1138,6 +1140,12 @@ class QIRProgramBuilder final : public ImplicitLocOpBuilder { /// Map from result index to result pointer for non-register results DenseMap resultPtrs; + /// Set of array register names that should be recorded in the output. + DenseSet recordedArrays; + + /// Set of unnamed result indices that should be recorded in the output. + DenseSet recordedIndices; + /// Map from register to their loaded indices DenseMap> loadedQubits; diff --git a/mlir/lib/Conversion/QCToQIR/QIRAdaptive/QCToQIRAdaptive.cpp b/mlir/lib/Conversion/QCToQIR/QIRAdaptive/QCToQIRAdaptive.cpp index bdd7ead97c..e3e155cc8c 100644 --- a/mlir/lib/Conversion/QCToQIR/QIRAdaptive/QCToQIRAdaptive.cpp +++ b/mlir/lib/Conversion/QCToQIR/QIRAdaptive/QCToQIRAdaptive.cpp @@ -380,6 +380,9 @@ struct ConvertQCMeasureOp final : StatefulOpConversionPattern { // Get result pointer Value result; + const bool shouldRecord = + state.returnedMeasurements.contains(op.getOperation()); + if (op.getRegisterName() && op.getRegisterSize() && op.getRegisterIndex()) { state.useArrays = true; const auto registerName = op.getRegisterName().value(); @@ -388,6 +391,10 @@ struct ConvertQCMeasureOp final : StatefulOpConversionPattern { const auto registerIndex = static_cast(op.getRegisterIndex().value()); + if (shouldRecord) { + state.recordedArrays.insert(state.stringSaver.save(registerName)); + } + // Create result register if it does not exist yet if (!resultArrays.contains(registerName)) { auto fnSig = LLVM::LLVMFunctionType::get( @@ -423,9 +430,12 @@ struct ConvertQCMeasureOp final : StatefulOpConversionPattern { result = loadedResults.at({registerName, registerIndex}); } else { rewriter.setInsertionPoint(state.entryBlock->getTerminator()); - result = createPointerFromIndex(rewriter, op.getLoc(), resultPtrs.size()); - resultPtrs.try_emplace(resultPtrs.size(), result); - state.numResults++; + auto index = state.numResults++; + if (shouldRecord) { + state.recordedIndices.insert(index); + } + result = createPointerFromIndex(rewriter, op.getLoc(), index); + resultPtrs.try_emplace(index, result); } rewriter.restoreInsertionPoint(savedInsertionPoint); @@ -653,7 +663,10 @@ struct QCToQIRAdaptive final : impl::QCToQIRAdaptiveBase { } } - // Stage 2: Convert func dialect to LLVM + // Stage 2.0: Strip returned measurements from func::ReturnOp + stripReturnedMeasurements(moduleOp, state); + + // Stage 2.1: Convert func dialect to LLVM { RewritePatternSet funcPatterns(ctx); target.addIllegalDialect(); diff --git a/mlir/lib/Conversion/QCToQIR/QIRBase/QCToQIRBase.cpp b/mlir/lib/Conversion/QCToQIR/QIRBase/QCToQIRBase.cpp index 74638efaae..9d8fe20984 100644 --- a/mlir/lib/Conversion/QCToQIR/QIRBase/QCToQIRBase.cpp +++ b/mlir/lib/Conversion/QCToQIR/QIRBase/QCToQIRBase.cpp @@ -220,6 +220,8 @@ struct ConvertQCMeasureOp final : StatefulOpConversionPattern { // Get result pointer Value result; int64_t resultIndex = 0; + const bool shouldRecord = + state.returnedMeasurements.contains(op.getOperation()); if (op.getRegisterIndex() && op.getRegisterName() && op.getRegisterSize()) { const auto registerName = op.getRegisterName().value(); @@ -234,7 +236,11 @@ struct ConvertQCMeasureOp final : StatefulOpConversionPattern { resultIndex = state.registerOffsets[registerName] + static_cast(registerIndex); } else { - resultIndex = static_cast(state.numResults); + resultIndex = static_cast(state.numResults++); + } + + if (shouldRecord) { + state.recordedIndices.insert(resultIndex); } if (resultPtrs.contains(resultIndex)) { @@ -416,7 +422,12 @@ struct QCToQIRBase final : impl::QCToQIRBaseBase { target.addLegalDialect(); - // Stage 1: Convert func dialect to LLVM + LoweringState state; + + // Stage 1.0: Strip returned measurements from func::ReturnOp + stripReturnedMeasurements(moduleOp, state); + + // Stage 1.1: Convert func dialect to LLVM { RewritePatternSet funcPatterns(ctx); target.addIllegalDialect(); @@ -436,8 +447,6 @@ struct QCToQIRBase final : impl::QCToQIRBaseBase { return; } - LoweringState state; - // Stage 2: Create block structure ensureBlocks(main, state); diff --git a/mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp b/mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp index f197002ddd..62e0ae7132 100644 --- a/mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp +++ b/mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include #include @@ -431,6 +433,9 @@ void addOutputRecording(LLVM::LLVMFuncOp& main, MLIRContext* ctx, auto fnDec = getOrCreateFunctionDeclaration(builder, main, QIR_RECORD_OUTPUT, fnSig); for (const auto& [index, ptr] : resultPtrs) { + if (!state.recordedIndices.contains(index)) { + continue; + } auto label = createResultLabel(builder, main, "__unnamed__" + std::to_string(index)) .getResult(); @@ -445,6 +450,9 @@ void addOutputRecording(LLVM::LLVMFuncOp& main, MLIRContext* ctx, auto fnDec = getOrCreateFunctionDeclaration(builder, main, QIR_ARRAY_RECORD_OUTPUT, fnSig); for (const auto& [name, results] : resultArrays) { + if (!state.recordedArrays.contains(name)) { + continue; + } auto size = results.getDefiningOp().getArraySize(); auto label = createResultLabel(builder, main, name).getResult(); LLVM::CallOp::create(builder, main->getLoc(), fnDec, @@ -468,4 +476,36 @@ void populateQCToQIRPatterns(RewritePatternSet& patterns, &state); } +void stripReturnedMeasurements(Operation* moduleOp, LoweringState& state) { + moduleOp->walk([&](func::FuncOp funcOp) { + funcOp.walk([&](func::ReturnOp returnOp) { + SmallVector keptOperands; + SmallVector keptReturnTypes; + + for (auto operand : returnOp.getOperands()) { + if (auto measureOp = operand.getDefiningOp()) { + state.returnedMeasurements.insert(measureOp.getOperation()); + } else { + keptOperands.push_back(operand); + keptReturnTypes.push_back(operand.getType()); + } + } + + if (keptOperands.empty() && !returnOp.getOperands().empty()) { + OpBuilder builder(returnOp); + auto zero = + arith::ConstantIntOp::create(builder, returnOp.getLoc(), 0, 64); + keptOperands.push_back(zero); + keptReturnTypes.push_back(zero.getType()); + } + + returnOp.getOperandsMutable().assign(keptOperands); + + funcOp.setFunctionType(FunctionType::get( + funcOp.getContext(), funcOp.getFunctionType().getInputs(), + keptReturnTypes)); + }); + }); +} + } // namespace mlir diff --git a/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp b/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp index 2943de2dc7..904e94b551 100644 --- a/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp +++ b/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp @@ -357,7 +357,8 @@ QIRProgramBuilder::allocClassicalBitRegister(const int64_t size, return {.name = name, .size = size}; } -Value QIRProgramBuilder::measure(Value qubit, const int64_t resultIndex) { +Value QIRProgramBuilder::measure(Value qubit, const int64_t resultIndex, + bool record) { checkFinalized(); if (resultIndex < 0) { @@ -386,10 +387,14 @@ Value QIRProgramBuilder::measure(Value qubit, const int64_t resultIndex) { getOrCreateFunctionDeclaration(*this, module, QIR_MEASURE, mzSig); LLVM::CallOp::create(*this, mzDec, ValueRange{qubit, result}); + if (record) { + recordedIndices.insert(resultIndex); + } + return result; } -Value QIRProgramBuilder::measure(Value qubit, const Bit& bit) { +Value QIRProgramBuilder::measure(Value qubit, const Bit& bit, bool record) { checkFinalized(); const InsertionGuard guard(*this); @@ -410,6 +415,21 @@ Value QIRProgramBuilder::measure(Value qubit, const Bit& bit) { getOrCreateFunctionDeclaration(*this, module, QIR_MEASURE, fnSig); LLVM::CallOp::create(*this, fnDec, ValueRange{qubit, result}); + if (record) { + if (profile == Profile::Adaptive) { + recordedArrays.insert(stringSaver.save(bit.registerName)); + } else { + // In the base profile we don't have recorded arrays, so we need to + // find the index of the result and record that instead. + for (const auto& [index, ptr] : resultPtrs) { + if (ptr == result) { + recordedIndices.insert(index); + break; + } + } + } + } + return result; } @@ -976,6 +996,9 @@ void QIRProgramBuilder::generateOutputRecording() { getOrCreateFunctionDeclaration(*this, module, QIR_RECORD_OUTPUT, fnSig); // Create output recording for each result pointer for (const auto& [index, ptr] : resultPtrs) { + if (!recordedIndices.contains(index)) { + continue; + } auto label = createResultLabel(*this, module, "__unnamed__" + std::to_string(index)) .getResult(); @@ -990,6 +1013,9 @@ void QIRProgramBuilder::generateOutputRecording() { QIR_ARRAY_RECORD_OUTPUT, fnSig); // Create output recording for each register for (const auto& [name, results] : resultArrays) { + if (!recordedArrays.contains(name)) { + continue; + } auto size = results.getDefiningOp().getArraySize(); auto label = createResultLabel(*this, module, name).getResult(); LLVM::CallOp::create(*this, fnDec, ValueRange{size, results, label}); diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp index 0999355b6e..15f7fa0177 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp @@ -45,7 +45,8 @@ struct QCToQIRBaseTestCase { mqt::test::NamedBuilder, SmallVector>> programBuilder; - mqt::test::NamedBuilder referenceBuilder; + mqt::test::NamedBuilder> + referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCToQIRBaseTestCase& info); @@ -125,46 +126,49 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseBarrierOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Barrier", MQT_NAMED_BUILDER(qc::barrier), - MQT_NAMED_BUILDER(qir::emptyQIR)}, + MQT_NAMED_BUILDER(qir::alloc1QubitRegister)}, QCToQIRBaseTestCase{"BarrierTwoQubits", MQT_NAMED_BUILDER(qc::barrierTwoQubits), - MQT_NAMED_BUILDER(qir::emptyQIR)}, + MQT_NAMED_BUILDER(qir::allocQubitRegister)}, QCToQIRBaseTestCase{"BarrierMultipleQubits", MQT_NAMED_BUILDER(qc::barrierMultipleQubits), - MQT_NAMED_BUILDER(qir::emptyQIR)}, - QCToQIRBaseTestCase{"SingleControlledBarrier", - MQT_NAMED_BUILDER(qc::singleControlledBarrier), - MQT_NAMED_BUILDER(qir::emptyQIR)})); + MQT_NAMED_BUILDER(qir::alloc3QubitRegister)}, + QCToQIRBaseTestCase{ + "SingleControlledBarrier", + MQT_NAMED_BUILDER(qc::singleControlledBarrier), + MQT_NAMED_BUILDER(qir::allocQubitRegister)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/DcxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseDCXOpTest, QCToQIRBaseTest, - testing::Values( - QCToQIRBaseTestCase{"DCX", MQT_NAMED_BUILDER(qc::dcx), - MQT_NAMED_BUILDER(qir::dcx)}, - QCToQIRBaseTestCase{"SingleControlledDCX", - MQT_NAMED_BUILDER(qc::singleControlledDcx), - MQT_NAMED_BUILDER(qir::singleControlledDcx)}, - QCToQIRBaseTestCase{"MultipleControlledDCX", - MQT_NAMED_BUILDER(qc::multipleControlledDcx), - MQT_NAMED_BUILDER(qir::multipleControlledDcx)})); + testing::Values(QCToQIRBaseTestCase{"DCX", MQT_NAMED_BUILDER(qc::dcx), + MQT_NAMED_BUILDER(qir::dcx)}, + QCToQIRBaseTestCase{ + "SingleControlledDCX", + MQT_NAMED_BUILDER(qc::singleControlledDcx), + MQT_NAMED_BUILDER(qir::singleControlledDcx)}, + QCToQIRBaseTestCase{ + "MultipleControlledDCX", + MQT_NAMED_BUILDER(qc::multipleControlledDcx), + MQT_NAMED_BUILDER(qir::multipleControlledDcx)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/EcrOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseECROpTest, QCToQIRBaseTest, - testing::Values( - QCToQIRBaseTestCase{"ECR", MQT_NAMED_BUILDER(qc::ecr), - MQT_NAMED_BUILDER(qir::ecr)}, - QCToQIRBaseTestCase{"SingleControlledECR", - MQT_NAMED_BUILDER(qc::singleControlledEcr), - MQT_NAMED_BUILDER(qir::singleControlledEcr)}, - QCToQIRBaseTestCase{"MultipleControlledECR", - MQT_NAMED_BUILDER(qc::multipleControlledEcr), - MQT_NAMED_BUILDER(qir::multipleControlledEcr)})); + testing::Values(QCToQIRBaseTestCase{"ECR", MQT_NAMED_BUILDER(qc::ecr), + MQT_NAMED_BUILDER(qir::ecr)}, + QCToQIRBaseTestCase{ + "SingleControlledECR", + MQT_NAMED_BUILDER(qc::singleControlledEcr), + MQT_NAMED_BUILDER(qir::singleControlledEcr)}, + QCToQIRBaseTestCase{ + "MultipleControlledECR", + MQT_NAMED_BUILDER(qc::multipleControlledEcr), + MQT_NAMED_BUILDER(qir::multipleControlledEcr)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/GphaseOp.cpp @@ -172,7 +176,7 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(QCToQIRBaseGPhaseOpTest, QCToQIRBaseTest, testing::Values(QCToQIRBaseTestCase{ "GlobalPhase", MQT_NAMED_BUILDER(qc::globalPhase), - MQT_NAMED_BUILDER(qir::globalPhase)})); + MQT_NAMED_BUILDER(qir::globalPhase)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/HOp.cpp @@ -181,16 +185,16 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseHOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"H", MQT_NAMED_BUILDER(qc::h), - MQT_NAMED_BUILDER(qir::h)}, + MQT_NAMED_BUILDER(qir::h)}, QCToQIRBaseTestCase{"SingleControlledH", MQT_NAMED_BUILDER(qc::singleControlledH), - MQT_NAMED_BUILDER(qir::singleControlledH)}, + MQT_NAMED_BUILDER(qir::singleControlledH)}, QCToQIRBaseTestCase{"MultipleControlledH", MQT_NAMED_BUILDER(qc::multipleControlledH), - MQT_NAMED_BUILDER(qir::multipleControlledH)}, + MQT_NAMED_BUILDER(qir::multipleControlledH)}, QCToQIRBaseTestCase{"HWithoutRegister", MQT_NAMED_BUILDER(qc::hWithoutRegister), - MQT_NAMED_BUILDER(qir::hWithoutRegister)})); + MQT_NAMED_BUILDER(qir::hWithoutRegister)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/IdOp.cpp @@ -199,13 +203,15 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseIDOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Identity", MQT_NAMED_BUILDER(qc::identity), - MQT_NAMED_BUILDER(qir::identity)}, - QCToQIRBaseTestCase{"SingleControlledIdentity", - MQT_NAMED_BUILDER(qc::singleControlledIdentity), - MQT_NAMED_BUILDER(qir::identity)}, - QCToQIRBaseTestCase{"MultipleControlledIdentity", - MQT_NAMED_BUILDER(qc::multipleControlledIdentity), - MQT_NAMED_BUILDER(qir::identity)})); + MQT_NAMED_BUILDER(qir::identity)}, + QCToQIRBaseTestCase{ + "SingleControlledIdentity", + MQT_NAMED_BUILDER(qc::singleControlledIdentity), + MQT_NAMED_BUILDER(qir::twoQubitsOneIdentity)}, + QCToQIRBaseTestCase{ + "MultipleControlledIdentity", + MQT_NAMED_BUILDER(qc::multipleControlledIdentity), + MQT_NAMED_BUILDER(qir::threeQubitsOneIdentity)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/IswapOp.cpp @@ -214,13 +220,15 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseiSWAPOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"iSWAP", MQT_NAMED_BUILDER(qc::iswap), - MQT_NAMED_BUILDER(qir::iswap)}, - QCToQIRBaseTestCase{"SingleControllediSWAP", - MQT_NAMED_BUILDER(qc::singleControlledIswap), - MQT_NAMED_BUILDER(qir::singleControlledIswap)}, - QCToQIRBaseTestCase{"MultipleControllediSWAP", - MQT_NAMED_BUILDER(qc::multipleControlledIswap), - MQT_NAMED_BUILDER(qir::multipleControlledIswap)})); + MQT_NAMED_BUILDER(qir::iswap)}, + QCToQIRBaseTestCase{ + "SingleControllediSWAP", + MQT_NAMED_BUILDER(qc::singleControlledIswap), + MQT_NAMED_BUILDER(qir::singleControlledIswap)}, + QCToQIRBaseTestCase{ + "MultipleControllediSWAP", + MQT_NAMED_BUILDER(qc::multipleControlledIswap), + MQT_NAMED_BUILDER(qir::multipleControlledIswap)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/POp.cpp @@ -229,13 +237,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBasePOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"P", MQT_NAMED_BUILDER(qc::p), - MQT_NAMED_BUILDER(qir::p)}, + MQT_NAMED_BUILDER(qir::p)}, QCToQIRBaseTestCase{"SingleControlledP", MQT_NAMED_BUILDER(qc::singleControlledP), - MQT_NAMED_BUILDER(qir::singleControlledP)}, - QCToQIRBaseTestCase{"MultipleControlledP", - MQT_NAMED_BUILDER(qc::multipleControlledP), - MQT_NAMED_BUILDER(qir::multipleControlledP)})); + MQT_NAMED_BUILDER(qir::singleControlledP)}, + QCToQIRBaseTestCase{ + "MultipleControlledP", MQT_NAMED_BUILDER(qc::multipleControlledP), + MQT_NAMED_BUILDER(qir::multipleControlledP)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/ROp.cpp @@ -244,13 +252,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseROpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"R", MQT_NAMED_BUILDER(qc::r), - MQT_NAMED_BUILDER(qir::r)}, + MQT_NAMED_BUILDER(qir::r)}, QCToQIRBaseTestCase{"SingleControlledR", MQT_NAMED_BUILDER(qc::singleControlledR), - MQT_NAMED_BUILDER(qir::singleControlledR)}, - QCToQIRBaseTestCase{"MultipleControlledR", - MQT_NAMED_BUILDER(qc::multipleControlledR), - MQT_NAMED_BUILDER(qir::multipleControlledR)})); + MQT_NAMED_BUILDER(qir::singleControlledR)}, + QCToQIRBaseTestCase{ + "MultipleControlledR", MQT_NAMED_BUILDER(qc::multipleControlledR), + MQT_NAMED_BUILDER(qir::multipleControlledR)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RxOp.cpp @@ -259,28 +267,29 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRXOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RX", MQT_NAMED_BUILDER(qc::rx), - MQT_NAMED_BUILDER(qir::rx)}, + MQT_NAMED_BUILDER(qir::rx)}, QCToQIRBaseTestCase{"SingleControlledRX", MQT_NAMED_BUILDER(qc::singleControlledRx), - MQT_NAMED_BUILDER(qir::singleControlledRx)}, - QCToQIRBaseTestCase{"MultipleControlledRX", - MQT_NAMED_BUILDER(qc::multipleControlledRx), - MQT_NAMED_BUILDER(qir::multipleControlledRx)})); + MQT_NAMED_BUILDER(qir::singleControlledRx)}, + QCToQIRBaseTestCase{ + "MultipleControlledRX", MQT_NAMED_BUILDER(qc::multipleControlledRx), + MQT_NAMED_BUILDER(qir::multipleControlledRx)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RxxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRXXOpTest, QCToQIRBaseTest, - testing::Values( - QCToQIRBaseTestCase{"RXX", MQT_NAMED_BUILDER(qc::rxx), - MQT_NAMED_BUILDER(qir::rxx)}, - QCToQIRBaseTestCase{"SingleControlledRXX", - MQT_NAMED_BUILDER(qc::singleControlledRxx), - MQT_NAMED_BUILDER(qir::singleControlledRxx)}, - QCToQIRBaseTestCase{"MultipleControlledRXX", - MQT_NAMED_BUILDER(qc::multipleControlledRxx), - MQT_NAMED_BUILDER(qir::multipleControlledRxx)})); + testing::Values(QCToQIRBaseTestCase{"RXX", MQT_NAMED_BUILDER(qc::rxx), + MQT_NAMED_BUILDER(qir::rxx)}, + QCToQIRBaseTestCase{ + "SingleControlledRXX", + MQT_NAMED_BUILDER(qc::singleControlledRxx), + MQT_NAMED_BUILDER(qir::singleControlledRxx)}, + QCToQIRBaseTestCase{ + "MultipleControlledRXX", + MQT_NAMED_BUILDER(qc::multipleControlledRxx), + MQT_NAMED_BUILDER(qir::multipleControlledRxx)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RyOp.cpp @@ -289,28 +298,29 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RY", MQT_NAMED_BUILDER(qc::ry), - MQT_NAMED_BUILDER(qir::ry)}, + MQT_NAMED_BUILDER(qir::ry)}, QCToQIRBaseTestCase{"SingleControlledRY", MQT_NAMED_BUILDER(qc::singleControlledRy), - MQT_NAMED_BUILDER(qir::singleControlledRy)}, - QCToQIRBaseTestCase{"MultipleControlledRY", - MQT_NAMED_BUILDER(qc::multipleControlledRy), - MQT_NAMED_BUILDER(qir::multipleControlledRy)})); + MQT_NAMED_BUILDER(qir::singleControlledRy)}, + QCToQIRBaseTestCase{ + "MultipleControlledRY", MQT_NAMED_BUILDER(qc::multipleControlledRy), + MQT_NAMED_BUILDER(qir::multipleControlledRy)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RyyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRYYOpTest, QCToQIRBaseTest, - testing::Values( - QCToQIRBaseTestCase{"RYY", MQT_NAMED_BUILDER(qc::ryy), - MQT_NAMED_BUILDER(qir::ryy)}, - QCToQIRBaseTestCase{"SingleControlledRYY", - MQT_NAMED_BUILDER(qc::singleControlledRyy), - MQT_NAMED_BUILDER(qir::singleControlledRyy)}, - QCToQIRBaseTestCase{"MultipleControlledRYY", - MQT_NAMED_BUILDER(qc::multipleControlledRyy), - MQT_NAMED_BUILDER(qir::multipleControlledRyy)})); + testing::Values(QCToQIRBaseTestCase{"RYY", MQT_NAMED_BUILDER(qc::ryy), + MQT_NAMED_BUILDER(qir::ryy)}, + QCToQIRBaseTestCase{ + "SingleControlledRYY", + MQT_NAMED_BUILDER(qc::singleControlledRyy), + MQT_NAMED_BUILDER(qir::singleControlledRyy)}, + QCToQIRBaseTestCase{ + "MultipleControlledRYY", + MQT_NAMED_BUILDER(qc::multipleControlledRyy), + MQT_NAMED_BUILDER(qir::multipleControlledRyy)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RzOp.cpp @@ -319,43 +329,45 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRZOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RZ", MQT_NAMED_BUILDER(qc::rz), - MQT_NAMED_BUILDER(qir::rz)}, + MQT_NAMED_BUILDER(qir::rz)}, QCToQIRBaseTestCase{"SingleControlledRZ", MQT_NAMED_BUILDER(qc::singleControlledRz), - MQT_NAMED_BUILDER(qir::singleControlledRz)}, - QCToQIRBaseTestCase{"MultipleControlledRZ", - MQT_NAMED_BUILDER(qc::multipleControlledRz), - MQT_NAMED_BUILDER(qir::multipleControlledRz)})); + MQT_NAMED_BUILDER(qir::singleControlledRz)}, + QCToQIRBaseTestCase{ + "MultipleControlledRZ", MQT_NAMED_BUILDER(qc::multipleControlledRz), + MQT_NAMED_BUILDER(qir::multipleControlledRz)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RzxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRZXOpTest, QCToQIRBaseTest, - testing::Values( - QCToQIRBaseTestCase{"RZX", MQT_NAMED_BUILDER(qc::rzx), - MQT_NAMED_BUILDER(qir::rzx)}, - QCToQIRBaseTestCase{"SingleControlledRZX", - MQT_NAMED_BUILDER(qc::singleControlledRzx), - MQT_NAMED_BUILDER(qir::singleControlledRzx)}, - QCToQIRBaseTestCase{"MultipleControlledRZX", - MQT_NAMED_BUILDER(qc::multipleControlledRzx), - MQT_NAMED_BUILDER(qir::multipleControlledRzx)})); + testing::Values(QCToQIRBaseTestCase{"RZX", MQT_NAMED_BUILDER(qc::rzx), + MQT_NAMED_BUILDER(qir::rzx)}, + QCToQIRBaseTestCase{ + "SingleControlledRZX", + MQT_NAMED_BUILDER(qc::singleControlledRzx), + MQT_NAMED_BUILDER(qir::singleControlledRzx)}, + QCToQIRBaseTestCase{ + "MultipleControlledRZX", + MQT_NAMED_BUILDER(qc::multipleControlledRzx), + MQT_NAMED_BUILDER(qir::multipleControlledRzx)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RzzOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRZZOpTest, QCToQIRBaseTest, - testing::Values( - QCToQIRBaseTestCase{"RZZ", MQT_NAMED_BUILDER(qc::rzz), - MQT_NAMED_BUILDER(qir::rzz)}, - QCToQIRBaseTestCase{"SingleControlledRZZ", - MQT_NAMED_BUILDER(qc::singleControlledRzz), - MQT_NAMED_BUILDER(qir::singleControlledRzz)}, - QCToQIRBaseTestCase{"MultipleControlledRZZ", - MQT_NAMED_BUILDER(qc::multipleControlledRzz), - MQT_NAMED_BUILDER(qir::multipleControlledRzz)})); + testing::Values(QCToQIRBaseTestCase{"RZZ", MQT_NAMED_BUILDER(qc::rzz), + MQT_NAMED_BUILDER(qir::rzz)}, + QCToQIRBaseTestCase{ + "SingleControlledRZZ", + MQT_NAMED_BUILDER(qc::singleControlledRzz), + MQT_NAMED_BUILDER(qir::singleControlledRzz)}, + QCToQIRBaseTestCase{ + "MultipleControlledRZZ", + MQT_NAMED_BUILDER(qc::multipleControlledRzz), + MQT_NAMED_BUILDER(qir::multipleControlledRzz)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SOp.cpp @@ -364,28 +376,29 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"S", MQT_NAMED_BUILDER(qc::s), - MQT_NAMED_BUILDER(qir::s)}, + MQT_NAMED_BUILDER(qir::s)}, QCToQIRBaseTestCase{"SingleControlledS", MQT_NAMED_BUILDER(qc::singleControlledS), - MQT_NAMED_BUILDER(qir::singleControlledS)}, - QCToQIRBaseTestCase{"MultipleControlledS", - MQT_NAMED_BUILDER(qc::multipleControlledS), - MQT_NAMED_BUILDER(qir::multipleControlledS)})); + MQT_NAMED_BUILDER(qir::singleControlledS)}, + QCToQIRBaseTestCase{ + "MultipleControlledS", MQT_NAMED_BUILDER(qc::multipleControlledS), + MQT_NAMED_BUILDER(qir::multipleControlledS)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SdgOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSdgOpTest, QCToQIRBaseTest, - testing::Values( - QCToQIRBaseTestCase{"Sdg", MQT_NAMED_BUILDER(qc::sdg), - MQT_NAMED_BUILDER(qir::sdg)}, - QCToQIRBaseTestCase{"SingleControlledSdg", - MQT_NAMED_BUILDER(qc::singleControlledSdg), - MQT_NAMED_BUILDER(qir::singleControlledSdg)}, - QCToQIRBaseTestCase{"MultipleControlledSdg", - MQT_NAMED_BUILDER(qc::multipleControlledSdg), - MQT_NAMED_BUILDER(qir::multipleControlledSdg)})); + testing::Values(QCToQIRBaseTestCase{"Sdg", MQT_NAMED_BUILDER(qc::sdg), + MQT_NAMED_BUILDER(qir::sdg)}, + QCToQIRBaseTestCase{ + "SingleControlledSdg", + MQT_NAMED_BUILDER(qc::singleControlledSdg), + MQT_NAMED_BUILDER(qir::singleControlledSdg)}, + QCToQIRBaseTestCase{ + "MultipleControlledSdg", + MQT_NAMED_BUILDER(qc::multipleControlledSdg), + MQT_NAMED_BUILDER(qir::multipleControlledSdg)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SwapOp.cpp @@ -394,13 +407,14 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSWAPOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"SWAP", MQT_NAMED_BUILDER(qc::swap), - MQT_NAMED_BUILDER(qir::swap)}, - QCToQIRBaseTestCase{"SingleControlledSWAP", - MQT_NAMED_BUILDER(qc::singleControlledSwap), - MQT_NAMED_BUILDER(qir::singleControlledSwap)}, - QCToQIRBaseTestCase{"MultipleControlledSWAP", - MQT_NAMED_BUILDER(qc::multipleControlledSwap), - MQT_NAMED_BUILDER(qir::multipleControlledSwap)})); + MQT_NAMED_BUILDER(qir::swap)}, + QCToQIRBaseTestCase{ + "SingleControlledSWAP", MQT_NAMED_BUILDER(qc::singleControlledSwap), + MQT_NAMED_BUILDER(qir::singleControlledSwap)}, + QCToQIRBaseTestCase{ + "MultipleControlledSWAP", + MQT_NAMED_BUILDER(qc::multipleControlledSwap), + MQT_NAMED_BUILDER(qir::multipleControlledSwap)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SxOp.cpp @@ -409,13 +423,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSXOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"SX", MQT_NAMED_BUILDER(qc::sx), - MQT_NAMED_BUILDER(qir::sx)}, + MQT_NAMED_BUILDER(qir::sx)}, QCToQIRBaseTestCase{"SingleControlledSX", MQT_NAMED_BUILDER(qc::singleControlledSx), - MQT_NAMED_BUILDER(qir::singleControlledSx)}, - QCToQIRBaseTestCase{"MultipleControlledSX", - MQT_NAMED_BUILDER(qc::multipleControlledSx), - MQT_NAMED_BUILDER(qir::multipleControlledSx)})); + MQT_NAMED_BUILDER(qir::singleControlledSx)}, + QCToQIRBaseTestCase{ + "MultipleControlledSX", MQT_NAMED_BUILDER(qc::multipleControlledSx), + MQT_NAMED_BUILDER(qir::multipleControlledSx)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SxdgOp.cpp @@ -424,13 +438,14 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSXdgOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"SXdg", MQT_NAMED_BUILDER(qc::sxdg), - MQT_NAMED_BUILDER(qir::sxdg)}, - QCToQIRBaseTestCase{"SingleControlledSXdg", - MQT_NAMED_BUILDER(qc::singleControlledSxdg), - MQT_NAMED_BUILDER(qir::singleControlledSxdg)}, - QCToQIRBaseTestCase{"MultipleControlledSXdg", - MQT_NAMED_BUILDER(qc::multipleControlledSxdg), - MQT_NAMED_BUILDER(qir::multipleControlledSxdg)})); + MQT_NAMED_BUILDER(qir::sxdg)}, + QCToQIRBaseTestCase{ + "SingleControlledSXdg", MQT_NAMED_BUILDER(qc::singleControlledSxdg), + MQT_NAMED_BUILDER(qir::singleControlledSxdg)}, + QCToQIRBaseTestCase{ + "MultipleControlledSXdg", + MQT_NAMED_BUILDER(qc::multipleControlledSxdg), + MQT_NAMED_BUILDER(qir::multipleControlledSxdg)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/TOp.cpp @@ -439,28 +454,29 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseTOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"T", MQT_NAMED_BUILDER(qc::t_), - MQT_NAMED_BUILDER(qir::t_)}, + MQT_NAMED_BUILDER(qir::t_)}, QCToQIRBaseTestCase{"SingleControlledT", MQT_NAMED_BUILDER(qc::singleControlledT), - MQT_NAMED_BUILDER(qir::singleControlledT)}, - QCToQIRBaseTestCase{"MultipleControlledT", - MQT_NAMED_BUILDER(qc::multipleControlledT), - MQT_NAMED_BUILDER(qir::multipleControlledT)})); + MQT_NAMED_BUILDER(qir::singleControlledT)}, + QCToQIRBaseTestCase{ + "MultipleControlledT", MQT_NAMED_BUILDER(qc::multipleControlledT), + MQT_NAMED_BUILDER(qir::multipleControlledT)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/TdgOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseTdgOpTest, QCToQIRBaseTest, - testing::Values( - QCToQIRBaseTestCase{"Tdg", MQT_NAMED_BUILDER(qc::tdg), - MQT_NAMED_BUILDER(qir::tdg)}, - QCToQIRBaseTestCase{"SingleControlledTdg", - MQT_NAMED_BUILDER(qc::singleControlledTdg), - MQT_NAMED_BUILDER(qir::singleControlledTdg)}, - QCToQIRBaseTestCase{"MultipleControlledTdg", - MQT_NAMED_BUILDER(qc::multipleControlledTdg), - MQT_NAMED_BUILDER(qir::multipleControlledTdg)})); + testing::Values(QCToQIRBaseTestCase{"Tdg", MQT_NAMED_BUILDER(qc::tdg), + MQT_NAMED_BUILDER(qir::tdg)}, + QCToQIRBaseTestCase{ + "SingleControlledTdg", + MQT_NAMED_BUILDER(qc::singleControlledTdg), + MQT_NAMED_BUILDER(qir::singleControlledTdg)}, + QCToQIRBaseTestCase{ + "MultipleControlledTdg", + MQT_NAMED_BUILDER(qc::multipleControlledTdg), + MQT_NAMED_BUILDER(qir::multipleControlledTdg)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/U2Op.cpp @@ -469,13 +485,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseU2OpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"U2", MQT_NAMED_BUILDER(qc::u2), - MQT_NAMED_BUILDER(qir::u2)}, + MQT_NAMED_BUILDER(qir::u2)}, QCToQIRBaseTestCase{"SingleControlledU2", MQT_NAMED_BUILDER(qc::singleControlledU2), - MQT_NAMED_BUILDER(qir::singleControlledU2)}, - QCToQIRBaseTestCase{"MultipleControlledU2", - MQT_NAMED_BUILDER(qc::multipleControlledU2), - MQT_NAMED_BUILDER(qir::multipleControlledU2)})); + MQT_NAMED_BUILDER(qir::singleControlledU2)}, + QCToQIRBaseTestCase{ + "MultipleControlledU2", MQT_NAMED_BUILDER(qc::multipleControlledU2), + MQT_NAMED_BUILDER(qir::multipleControlledU2)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/UOp.cpp @@ -484,13 +500,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseUOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"U", MQT_NAMED_BUILDER(qc::u), - MQT_NAMED_BUILDER(qir::u)}, + MQT_NAMED_BUILDER(qir::u)}, QCToQIRBaseTestCase{"SingleControlledU", MQT_NAMED_BUILDER(qc::singleControlledU), - MQT_NAMED_BUILDER(qir::singleControlledU)}, - QCToQIRBaseTestCase{"MultipleControlledU", - MQT_NAMED_BUILDER(qc::multipleControlledU), - MQT_NAMED_BUILDER(qir::multipleControlledU)})); + MQT_NAMED_BUILDER(qir::singleControlledU)}, + QCToQIRBaseTestCase{ + "MultipleControlledU", MQT_NAMED_BUILDER(qc::multipleControlledU), + MQT_NAMED_BUILDER(qir::multipleControlledU)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/XOp.cpp @@ -499,13 +515,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseXOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"X", MQT_NAMED_BUILDER(qc::x), - MQT_NAMED_BUILDER(qir::x)}, + MQT_NAMED_BUILDER(qir::x)}, QCToQIRBaseTestCase{"SingleControlledX", MQT_NAMED_BUILDER(qc::singleControlledX), - MQT_NAMED_BUILDER(qir::singleControlledX)}, - QCToQIRBaseTestCase{"MultipleControlledX", - MQT_NAMED_BUILDER(qc::multipleControlledX), - MQT_NAMED_BUILDER(qir::multipleControlledX)})); + MQT_NAMED_BUILDER(qir::singleControlledX)}, + QCToQIRBaseTestCase{ + "MultipleControlledX", MQT_NAMED_BUILDER(qc::multipleControlledX), + MQT_NAMED_BUILDER(qir::multipleControlledX)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/XxMinusYyOp.cpp @@ -514,14 +530,15 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseXXMinusYYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"XXMinusYY", MQT_NAMED_BUILDER(qc::xxMinusYY), - MQT_NAMED_BUILDER(qir::xxMinusYY)}, - QCToQIRBaseTestCase{"SingleControlledXXMinusYY", - MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), - MQT_NAMED_BUILDER(qir::singleControlledXxMinusYY)}, + MQT_NAMED_BUILDER(qir::xxMinusYY)}, + QCToQIRBaseTestCase{ + "SingleControlledXXMinusYY", + MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), + MQT_NAMED_BUILDER(qir::singleControlledXxMinusYY)}, QCToQIRBaseTestCase{ "MultipleControlledXXMinusYY", MQT_NAMED_BUILDER(qc::multipleControlledXxMinusYY), - MQT_NAMED_BUILDER(qir::multipleControlledXxMinusYY)})); + MQT_NAMED_BUILDER(qir::multipleControlledXxMinusYY)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/XxPlusYyOp.cpp @@ -530,14 +547,15 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseXXPlusYYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"XXPlusYY", MQT_NAMED_BUILDER(qc::xxPlusYY), - MQT_NAMED_BUILDER(qir::xxPlusYY)}, - QCToQIRBaseTestCase{"SingleControlledXXPlusYY", - MQT_NAMED_BUILDER(qc::singleControlledXxPlusYY), - MQT_NAMED_BUILDER(qir::singleControlledXxPlusYY)}, + MQT_NAMED_BUILDER(qir::xxPlusYY)}, + QCToQIRBaseTestCase{ + "SingleControlledXXPlusYY", + MQT_NAMED_BUILDER(qc::singleControlledXxPlusYY), + MQT_NAMED_BUILDER(qir::singleControlledXxPlusYY)}, QCToQIRBaseTestCase{ "MultipleControlledXXPlusYY", MQT_NAMED_BUILDER(qc::multipleControlledXxPlusYY), - MQT_NAMED_BUILDER(qir::multipleControlledXxPlusYY)})); + MQT_NAMED_BUILDER(qir::multipleControlledXxPlusYY)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/YOp.cpp @@ -546,13 +564,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Y", MQT_NAMED_BUILDER(qc::y), - MQT_NAMED_BUILDER(qir::y)}, + MQT_NAMED_BUILDER(qir::y)}, QCToQIRBaseTestCase{"SingleControlledY", MQT_NAMED_BUILDER(qc::singleControlledY), - MQT_NAMED_BUILDER(qir::singleControlledY)}, - QCToQIRBaseTestCase{"MultipleControlledY", - MQT_NAMED_BUILDER(qc::multipleControlledY), - MQT_NAMED_BUILDER(qir::multipleControlledY)})); + MQT_NAMED_BUILDER(qir::singleControlledY)}, + QCToQIRBaseTestCase{ + "MultipleControlledY", MQT_NAMED_BUILDER(qc::multipleControlledY), + MQT_NAMED_BUILDER(qir::multipleControlledY)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/ZOp.cpp @@ -561,13 +579,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseZOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Z", MQT_NAMED_BUILDER(qc::z), - MQT_NAMED_BUILDER(qir::z)}, + MQT_NAMED_BUILDER(qir::z)}, QCToQIRBaseTestCase{"SingleControlledZ", MQT_NAMED_BUILDER(qc::singleControlledZ), - MQT_NAMED_BUILDER(qir::singleControlledZ)}, - QCToQIRBaseTestCase{"MultipleControlledZ", - MQT_NAMED_BUILDER(qc::multipleControlledZ), - MQT_NAMED_BUILDER(qir::multipleControlledZ)})); + MQT_NAMED_BUILDER(qir::singleControlledZ)}, + QCToQIRBaseTestCase{ + "MultipleControlledZ", MQT_NAMED_BUILDER(qc::multipleControlledZ), + MQT_NAMED_BUILDER(qir::multipleControlledZ)})); /// @} /// \name QCToQIRBase/Operations/MeasureOp.cpp @@ -578,23 +596,24 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseTestCase{ "SingleMeasurementToSingleBit", MQT_NAMED_BUILDER(qc::singleMeasurementToSingleBit), - MQT_NAMED_BUILDER(qir::singleMeasurementToSingleBit)}, + MQT_NAMED_BUILDER(qir::singleMeasurementToSingleBit)}, QCToQIRBaseTestCase{ "RepeatedMeasurementToSameBit", MQT_NAMED_BUILDER(qc::repeatedMeasurementToSameBit), - MQT_NAMED_BUILDER(qir::repeatedMeasurementToSameBit)}, + MQT_NAMED_BUILDER(qir::repeatedMeasurementToSameBit)}, QCToQIRBaseTestCase{ "RepeatedMeasurementToDifferentBits", MQT_NAMED_BUILDER(qc::repeatedMeasurementToDifferentBits), - MQT_NAMED_BUILDER(qir::repeatedMeasurementToDifferentBits)}, + MQT_NAMED_BUILDER(qir::repeatedMeasurementToDifferentBits)}, QCToQIRBaseTestCase{ "MultipleClassicalRegistersAndMeasurements", MQT_NAMED_BUILDER(qc::multipleClassicalRegistersAndMeasurements), - MQT_NAMED_BUILDER(qir::multipleClassicalRegistersAndMeasurements)}, + MQT_NAMED_BUILDER( + qir::multipleClassicalRegistersAndMeasurements)}, QCToQIRBaseTestCase{ "MeasurementWithoutRegisters", MQT_NAMED_BUILDER(qc::measurementWithoutRegisters), - MQT_NAMED_BUILDER(qir::measurementWithoutRegisters)})); + MQT_NAMED_BUILDER(qir::measurementWithoutRegisters)})); /// @} /// \name QCToQIRBase/QubitManagement/QubitManagement.cpp @@ -603,22 +622,23 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseQubitManagementTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"AllocQubit", MQT_NAMED_BUILDER(qc::allocQubit), - MQT_NAMED_BUILDER(qir::emptyQIR)}, + MQT_NAMED_BUILDER(qir::allocQubit)}, QCToQIRBaseTestCase{"AllocQubitRegister", MQT_NAMED_BUILDER(qc::allocQubitRegister), - MQT_NAMED_BUILDER(qir::emptyQIR)}, - QCToQIRBaseTestCase{"AllocMultipleQubitRegisters", - MQT_NAMED_BUILDER(qc::allocMultipleQubitRegisters), - MQT_NAMED_BUILDER(qir::emptyQIR)}, + MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + QCToQIRBaseTestCase{ + "AllocMultipleQubitRegisters", + MQT_NAMED_BUILDER(qc::allocMultipleQubitRegisters), + MQT_NAMED_BUILDER(qir::allocMultipleQubitRegisters)}, QCToQIRBaseTestCase{ "AllocMultipleQubitRegistersWithOps", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegistersWithOps), - MQT_NAMED_BUILDER(qir::allocMultipleQubitRegistersWithOps)}, + MQT_NAMED_BUILDER(qir::allocMultipleQubitRegistersWithOps)}, QCToQIRBaseTestCase{"AllocLargeRegister", MQT_NAMED_BUILDER(qc::allocLargeRegister), - MQT_NAMED_BUILDER(qir::emptyQIR)}, + MQT_NAMED_BUILDER(qir::allocQubitRegister)}, QCToQIRBaseTestCase{"StaticQubits", MQT_NAMED_BUILDER(qc::staticQubits), - MQT_NAMED_BUILDER(qir::emptyQIR)}, + MQT_NAMED_BUILDER(qir::staticQubits)}, QCToQIRBaseTestCase{"StaticQubitsWithOps", MQT_NAMED_BUILDER(qc::staticQubitsWithOps), MQT_NAMED_BUILDER(qir::staticQubitsWithOps)}, @@ -638,5 +658,5 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(qir::staticQubitsWithInv)}, QCToQIRBaseTestCase{"AllocDeallocPair", MQT_NAMED_BUILDER(qc::allocDeallocPair), - MQT_NAMED_BUILDER(qir::emptyQIR)})); + MQT_NAMED_BUILDER(qir::emptyQIR)})); /// @} diff --git a/mlir/unittests/programs/qir_programs.cpp b/mlir/unittests/programs/qir_programs.cpp index 8094587a0d..6d3b1dd98c 100644 --- a/mlir/unittests/programs/qir_programs.cpp +++ b/mlir/unittests/programs/qir_programs.cpp @@ -23,97 +23,6 @@ #include -/** - * @brief Creates a struct value using an `llvm.poison` operation with the given - * types. - * @param b The QIRProgramBuilder used to create the struct. - * @param types The types of the elements in the struct. - * @return The created struct value. - */ -mlir::Value createStruct(mlir::qir::QIRProgramBuilder& b, - mlir::SmallVector types) { - auto structType = - mlir::LLVM::LLVMStructType::getLiteral(b.getContext(), types); - mlir::Value structValue = mlir::LLVM::PoisonOp::create(b, structType); - return structValue; -} - -/** - * @brief Collects measurement outcomes into a struct value. - * @param b The QIRProgramBuilder used to create the struct. - * @param outcomes The measurement outcomes to be read and collected. - * @param structValue The struct value to insert the measurement outcomes into. - * @return The struct value with the measurement outcomes inserted. - */ -mlir::Value -collectMeasurementOutcomesInStruct(mlir::qir::QIRProgramBuilder& b, - mlir::SmallVector outcomes, - mlir::Value structValue) { - int64_t index = 0; - for (auto bit : outcomes) { - auto c = b.readResult(bit); - auto insert = mlir::LLVM::InsertValueOp::create( - b, structValue, c, mlir::ArrayRef(index++)); - structValue = insert.getResult(); - } - return structValue; -} - -/** - * @brief Measures the given qubits or reads the given results and returns the - * measurement outcomes as a struct value or a single `i1`. - * @param b The QIRProgramBuilder used to perform the measurements and create - * the struct. - * @param qubits The qubits to be measured. - * @param results The measurement results to be read. - * @param inRegister Whether to store the results in a classical result array or - * not. - * @return A pair containing the result value and its type. - */ -static std::pair measureOrReadAndReturn( - mlir::qir::QIRProgramBuilder& b, mlir::SmallVector qubits, - mlir::SmallVector results, bool inRegister) { - - if (qubits.empty() && results.empty()) { - auto zeroConst = b.intConstant(0); - return {zeroConst, b.getI64Type()}; - } - mlir::qir::QIRProgramBuilder::ClassicalRegister resultArray; - if (inRegister) { - resultArray = b.allocClassicalBitRegister(qubits.size(), "meas"); - } - - if (qubits.size() == 1 && results.empty()) { - auto outcome = inRegister ? b.measure(qubits[0], resultArray[0]) - : b.measure(qubits[0], 0); - auto result = b.readResult(outcome); - return {result, b.getI1Type()}; - } - if (results.size() == 1 && qubits.empty()) { - auto result = b.readResult(results[0]); - return {result, b.getI1Type()}; - } - - llvm::SmallVector elementTypes(qubits.size() + results.size(), - b.getI1Type()); - mlir::Value structValue = createStruct(b, elementTypes); - - for (auto i = 0L; i < results.size(); ++i) { - auto result = b.readResult(results[i]); - auto insert = mlir::LLVM::InsertValueOp::create(b, structValue, result, i); - structValue = insert.getResult(); - } - for (auto i = 0L; i < qubits.size(); ++i) { - auto outcome = inRegister ? b.measure(qubits[i], resultArray[i]) - : b.measure(qubits[i], i); - auto result = b.readResult(outcome); - auto insert = mlir::LLVM::InsertValueOp::create(b, structValue, result, - i + results.size()); - structValue = insert.getResult(); - } - return {structValue, structValue.getType()}; -} - /** * @brief Measures the given qubits and returns the measurement outcomes as a * struct value or a single `i1`. @@ -126,9 +35,9 @@ static std::pair measureOrReadAndReturn( * @return A pair containing the result value and its type. */ static std::pair -measureAndReturn(mlir::qir::QIRProgramBuilder& b, +measureAndRecord(mlir::qir::QIRProgramBuilder& b, mlir::SmallVector qubits, bool inRegister, - int64_t startIndex) { + int64_t startIndex = 0) { if (qubits.empty()) { auto zeroConst = b.intConstant(0); @@ -139,80 +48,50 @@ measureAndReturn(mlir::qir::QIRProgramBuilder& b, resultArray = b.allocClassicalBitRegister(qubits.size(), "meas"); } - if (qubits.size() == 1) { - auto outcome = inRegister ? b.measure(qubits[0], resultArray[0]) - : b.measure(qubits[0], startIndex); - auto result = b.readResult(outcome); - return {result, b.getI1Type()}; - } - - llvm::SmallVector elementTypes(qubits.size(), b.getI1Type()); - mlir::Value structValue = createStruct(b, elementTypes); - for (auto i = 0L; i < qubits.size(); ++i) { - auto outcome = inRegister ? b.measure(qubits[i], resultArray[i]) - : b.measure(qubits[i], startIndex + i); - auto result = b.readResult(outcome); - auto insert = mlir::LLVM::InsertValueOp::create(b, structValue, result, i); - structValue = insert.getResult(); + inRegister ? b.measure(qubits[i], resultArray[i]) + : b.measure(qubits[i], startIndex + i); } - return {structValue, structValue.getType()}; -} -/** - * @brief Measures the given qubits and returns the measurement outcomes as a - * struct value or a single `i1`. - * - * @detail Measurement outcome indices are assumed to start at 0. - * - * @param b The QIRProgramBuilder used to perform the measurements and create - * the struct. - * @param qubits The qubits to be measured. - * @param inRegister Whether to store the results in a classical result array or - * not. - * @return A pair containing the result value and its type. - */ -static std::pair -measureAndReturn(mlir::qir::QIRProgramBuilder& b, - mlir::SmallVector qubits, bool inRegister) { - return measureAndReturn(b, qubits, inRegister, 0); + auto zeroConst = b.intConstant(0); + return {zeroConst, b.getI64Type()}; } namespace mlir::qir { template std::pair emptyQIR(QIRProgramBuilder& b) { - return measureAndReturn(b, {}, IntoRegister); + return measureAndRecord(b, {}, IntoRegister); } template std::pair allocQubit(QIRProgramBuilder& b) { auto q = b.allocQubit(); - return measureAndReturn(b, {q}, IntoRegister); + return measureAndRecord(b, {q}, IntoRegister); } template std::pair alloc1QubitRegister(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair allocQubitRegister(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair alloc3QubitRegister(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair allocMultipleQubitRegisters(QIRProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); auto q1 = b.allocQubitRegister(3); - return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}, IntoRegister); + return measureAndRecord(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}, IntoRegister); } template @@ -225,19 +104,19 @@ allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b) { b.h(q1[0]); b.h(q1[1]); b.h(q1[2]); - return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}, IntoRegister); + return measureAndRecord(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}, IntoRegister); } template std::pair allocLargeRegister(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(100); - return measureAndReturn(b, {q[0], q[99]}, IntoRegister); + return measureAndRecord(b, {q[0], q[99]}, IntoRegister); } std::pair staticQubits(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); - return measureAndReturn(b, {q0, q1}, false); + return measureAndRecord(b, {q0, q1}, false); } std::pair staticQubitsWithOps(QIRProgramBuilder& b) { @@ -245,7 +124,7 @@ std::pair staticQubitsWithOps(QIRProgramBuilder& b) { auto q1 = b.staticQubit(1); b.h(q0); b.h(q1); - return measureAndReturn(b, {q0, q1}, false); + return measureAndRecord(b, {q0, q1}, false); } std::pair staticQubitsWithParametricOps(QIRProgramBuilder& b) { @@ -253,27 +132,27 @@ std::pair staticQubitsWithParametricOps(QIRProgramBuilder& b) { auto q1 = b.staticQubit(1); b.rx(std::numbers::pi / 4., q0); b.p(std::numbers::pi / 2., q1); - return measureAndReturn(b, {q0, q1}, false); + return measureAndRecord(b, {q0, q1}, false); } std::pair staticQubitsWithTwoTargetOps(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.rzz(0.123, q0, q1); - return measureAndReturn(b, {q0, q1}, false); + return measureAndRecord(b, {q0, q1}, false); } std::pair staticQubitsWithCtrl(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.cx(q0, q1); - return measureAndReturn(b, {q0, q1}, false); + return measureAndRecord(b, {q0, q1}, false); } std::pair staticQubitsWithInv(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); b.tdg(q0); - return measureAndReturn(b, {q0}, false); + return measureAndRecord(b, {q0}, false); } std::pair staticQubitsWithDuplicates(QIRProgramBuilder& b) { @@ -286,7 +165,7 @@ std::pair staticQubitsWithDuplicates(QIRProgramBuilder& b) { b.rzz(0.123, q0b, q1b); b.cx(q0b, q1b); b.tdg(q0a); - return measureAndReturn(b, {q0b, q1b}, false); + return measureAndRecord(b, {q0b, q1b}, false); } std::pair staticQubitsCanonical(QIRProgramBuilder& b) { @@ -297,29 +176,28 @@ std::pair staticQubitsCanonical(QIRProgramBuilder& b) { b.rzz(0.123, q0, q1); b.cx(q0, q1); b.tdg(q0); - return measureAndReturn(b, {q0, q1}, false); + return measureAndRecord(b, {q0, q1}, false); } std::pair mixedStaticThenDynamicQubit(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.allocQubit(); - return measureAndReturn(b, {q0, q1}, false); + return measureAndRecord(b, {q0, q1}, false); } std::pair mixedDynamicRegisterThenStaticQubit(QIRProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); auto q1 = b.staticQubit(0); - return measureAndReturn(b, {q0[0], q0[1], q1}, false); + return measureAndRecord(b, {q0[0], q0[1], q1}, false); } template std::pair singleMeasurementToSingleBit(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto c = b.allocClassicalBitRegister(1); - const auto v = b.measure(q[0], c[0]); - const auto read = b.readResult(v); - return {read, b.getI1Type()}; + b.measure(q[0], c[0]); + return {b.intConstant(0), b.getI64Type()}; } template @@ -328,9 +206,8 @@ std::pair repeatedMeasurementToSameBit(QIRProgramBuilder& b) { const auto c = b.allocClassicalBitRegister(1); b.measure(q[0], c[0]); b.measure(q[0], c[0]); - auto b3 = b.measure(q[0], c[0]); - auto c3 = b.readResult(b3); - return {c3, b.getI1Type()}; + b.measure(q[0], c[0]); + return {b.intConstant(0), b.getI64Type()}; } template @@ -338,14 +215,10 @@ std::pair repeatedMeasurementToDifferentBits(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto c = b.allocClassicalBitRegister(3); - auto b1 = b.measure(q[0], c[0]); - auto b2 = b.measure(q[0], c[1]); - auto b3 = b.measure(q[0], c[2]); - auto structValue = - createStruct(b, {b.getI1Type(), b.getI1Type(), b.getI1Type()}); - auto filledStruct = - collectMeasurementOutcomesInStruct(b, {b1, b2, b3}, structValue); - return {filledStruct, filledStruct.getType()}; + b.measure(q[0], c[0]); + b.measure(q[0], c[1]); + b.measure(q[0], c[2]); + return {b.intConstant(0), b.getI64Type()}; } template @@ -354,29 +227,24 @@ multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); const auto& c0 = b.allocClassicalBitRegister(1, "c0"); const auto& c1 = b.allocClassicalBitRegister(2, "c1"); - auto b1 = b.measure(q[0], c0[0]); - auto b2 = b.measure(q[1], c1[0]); - auto b3 = b.measure(q[2], c1[1]); - auto structValue = - createStruct(b, {b.getI1Type(), b.getI1Type(), b.getI1Type()}); - auto filledStruct = - collectMeasurementOutcomesInStruct(b, {b1, b2, b3}, structValue); - return {filledStruct, filledStruct.getType()}; + b.measure(q[0], c0[0]); + b.measure(q[1], c1[0]); + b.measure(q[2], c1[1]); + return {b.intConstant(0), b.getI64Type()}; } template std::pair measurementWithoutRegisters(QIRProgramBuilder& b) { auto q = b.allocQubit(); auto bit = b.measure(q, 0); - auto c = b.readResult(bit); - return {c, b.getI1Type()}; + return {b.intConstant(0), b.getI64Type()}; } template std::pair resetQubitWithoutOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template @@ -384,7 +252,7 @@ std::pair resetMultipleQubitsWithoutOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.reset(q[0]); b.reset(q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template @@ -393,7 +261,7 @@ std::pair repeatedResetWithoutOp(QIRProgramBuilder& b) { b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template @@ -401,7 +269,7 @@ std::pair resetQubitAfterSingleOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template @@ -411,7 +279,7 @@ std::pair resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b) { b.reset(q[0]); b.h(q[1]); b.reset(q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template @@ -421,605 +289,605 @@ std::pair repeatedResetAfterSingleOp(QIRProgramBuilder& b) { b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair globalPhase(QIRProgramBuilder& b) { b.gphase(0.123); - return measureAndReturn(b, {}, IntoRegister); + return measureAndRecord(b, {}, IntoRegister); } template std::pair identity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.id(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cid(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair twoQubitsOneIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.id(q[0]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair threeQubitsOneIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.id(q[0]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair multipleControlledIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcid({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair x(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.x(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledX(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cx(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledX(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcx({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair y(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.y(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cy(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcy({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair z(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.z(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledZ(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cz(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledZ(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcz({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair h(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledH(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ch(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledH(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mch({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair hWithoutRegister(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); - return measureAndReturn(b, {q}, false); + return measureAndRecord(b, {q}, false); } template std::pair s(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.s(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledS(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cs(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledS(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcs({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair sdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sdg(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledSdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csdg(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledSdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsdg({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair t_(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.t(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledT(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ct(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledT(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mct({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair tdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.tdg(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledTdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ctdg(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledTdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mctdg({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair sx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sx(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledSx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csx(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledSx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsx({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair sxdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sxdg(q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledSxdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csxdg(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledSxdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsxdg({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair rx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rx(0.123, q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledRx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.crx(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledRx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcrx(0.123, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair ry(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.ry(0.456, q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledRy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cry(0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledRy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcry(0.456, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair rz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rz(0.789, q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledRz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.crz(0.789, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledRz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcrz(0.789, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair p(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.p(0.123, q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledP(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cp(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledP(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcp(0.123, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair r(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.r(0.123, 0.456, q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledR(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cr(0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledR(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcr(0.123, 0.456, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair u2(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u2(0.234, 0.567, q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledU2(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cu2(0.234, 0.567, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledU2(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcu2(0.234, 0.567, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair u(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u(0.1, 0.2, 0.3, q[0]); - return measureAndReturn(b, {q[0]}, IntoRegister); + return measureAndRecord(b, {q[0]}, IntoRegister); } template std::pair singleControlledU(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cu(0.1, 0.2, 0.3, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair multipleControlledU(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcu(0.1, 0.2, 0.3, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair swap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.swap(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair singleControlledSwap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cswap(q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair multipleControlledSwap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcswap({q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } template std::pair iswap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.iswap(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair singleControlledIswap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.ciswap(q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair multipleControlledIswap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mciswap({q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } template std::pair dcx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.dcx(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair singleControlledDcx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cdcx(q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair multipleControlledDcx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcdcx({q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } template std::pair ecr(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ecr(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair singleControlledEcr(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cecr(q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair multipleControlledEcr(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcecr({q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } template std::pair rxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rxx(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair singleControlledRxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crxx(0.123, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair multipleControlledRxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } template std::pair tripleControlledRxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(5); b.mcrxx(0.123, {q[0], q[1], q[2]}, q[3], q[4]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2], q[3], q[4]}, IntoRegister); } template std::pair ryy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ryy(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair singleControlledRyy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cryy(0.123, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair multipleControlledRyy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcryy(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } template std::pair rzx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rzx(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair singleControlledRzx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crzx(0.123, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair multipleControlledRzx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrzx(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } template std::pair rzz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rzz(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair singleControlledRzz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crzz(0.123, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair multipleControlledRzz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrzz(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } template std::pair xxPlusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.xx_plus_yy(0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair singleControlledXxPlusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cxx_plus_yy(0.123, 0.456, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair multipleControlledXxPlusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcxx_plus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } template std::pair xxMinusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.xx_minus_yy(0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair singleControlledXxMinusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cxx_minus_yy(0.123, 0.456, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } template std::pair multipleControlledXxMinusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcxx_minus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } template @@ -1028,7 +896,7 @@ std::pair simpleIf(QIRProgramBuilder& b) { b.h(q[0]); auto cond = b.measure(q[0], 0); b.scfIf(cond, [&] { b.x(q[0]); }); - return measureAndReturn(b, {q[0]}, IntoRegister, 1); + return measureAndRecord(b, {q[0]}, IntoRegister, 1); } template @@ -1037,7 +905,7 @@ std::pair ifElse(QIRProgramBuilder& b) { b.h(q[0]); auto cond = b.measure(q[0], 0); b.scfIf(cond, [&] { b.x(q[0]); }, [&] { b.z(q[0]); }); - return measureAndReturn(b, {q[0]}, IntoRegister, 1); + return measureAndRecord(b, {q[0]}, IntoRegister, 1); } template @@ -1049,7 +917,7 @@ std::pair ifTwoQubits(QIRProgramBuilder& b) { b.x(q[0]); b.x(q[1]); }); - return measureAndReturn(b, {q[0], q[1]}, IntoRegister, 1); + return measureAndRecord(b, {q[0], q[1]}, IntoRegister, 1); } template @@ -1057,7 +925,7 @@ std::pair nestedIfOpForLoop(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); b.h(q0); - auto cond = b.measure(q0, 0); + auto cond = b.measure(q0, 0, false); b.scfIf( cond, [&] { b.h(q0); }, [&] { @@ -1066,7 +934,7 @@ std::pair nestedIfOpForLoop(QIRProgramBuilder& b) { b.h(q1); }); }); - return measureAndReturn(b, {q0}, IntoRegister, 1); + return measureAndRecord(b, {q0}, IntoRegister, 1); } template @@ -1075,11 +943,11 @@ std::pair simpleWhileReset(QIRProgramBuilder& b) { b.h(q); b.scfWhile( [&] { - auto measureResult = b.measure(q, 0); + auto measureResult = b.measure(q, 0, false); return measureResult; }, [&] { b.h(q); }); - return measureAndReturn(b, {q}, IntoRegister, 1); + return measureAndRecord(b, {q}, IntoRegister, 1); } template @@ -1087,10 +955,10 @@ std::pair simpleDoWhileReset(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.scfWhile([&] { b.h(q); - auto measureResult = b.measure(q, 0); + auto measureResult = b.measure(q, 0, false); return measureResult; }); - return measureAndReturn(b, {q}, IntoRegister, 1); + return measureAndRecord(b, {q}, IntoRegister, 1); } template @@ -1100,7 +968,7 @@ std::pair simpleForLoop(QIRProgramBuilder& b) { auto q = b.load(reg.value, iv); b.h(q); }); - return measureAndReturn(b, {reg[0], reg[1]}, IntoRegister); + return measureAndRecord(b, {reg[0], reg[1]}, IntoRegister); }; template @@ -1109,13 +977,13 @@ std::pair nestedForLoopIfOp(QIRProgramBuilder& b) { auto qCond = b.allocQubit(); b.scfFor(0, 2, 1, [&](Value iv) { b.h(qCond); - auto cond = b.measure(qCond, 0); + auto cond = b.measure(qCond, 0, false); b.scfIf(cond, [&] { auto q = b.load(reg.value, iv); b.h(q); }); }); - return measureAndReturn(b, {qCond}, IntoRegister, 1); + return measureAndRecord(b, {qCond}, IntoRegister, 1); } template @@ -1129,12 +997,12 @@ std::pair nestedForLoopWhileOp(QIRProgramBuilder& b) { auto q = b.load(reg.value, iv); b.scfWhile( [&] { - auto measureResult = b.measure(q, 0); + auto measureResult = b.measure(q, 0, false); return measureResult; }, [&] { b.h(q); }); }); - return measureAndReturn(b, {reg[0], reg[1]}, IntoRegister, 1); + return measureAndRecord(b, {reg[0], reg[1]}, IntoRegister, 1); } template @@ -1148,7 +1016,7 @@ nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b) { b.h(q0); b.cx(control, q0); }); - return measureAndReturn(b, {control}, IntoRegister); + return measureAndRecord(b, {control}, IntoRegister); } template @@ -1161,7 +1029,7 @@ nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b) { b.h(q0); b.cx(reg[0], q0); }); - return measureAndReturn(b, {reg[0]}, IntoRegister); + return measureAndRecord(b, {reg[0]}, IntoRegister); } template @@ -1169,7 +1037,7 @@ std::pair ctrlTwo(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcx({q[0], q[1]}, q[2]); b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); } // Instantiate the templates for IntoRegister = false From 05673322351e2c37200f3e34e26d4331f39799c3 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Mon, 6 Jul 2026 16:49:02 +0200 Subject: [PATCH 38/80] feat(mlir): :recycle: change default value of qir_programs template argument `InRegister` to false --- .../Compiler/test_compiler_pipeline.cpp | 215 +++---- .../test_qc_to_qir_adaptive.cpp | 537 +++++++++--------- .../QCToQIRBase/test_qc_to_qir_base.cpp | 409 +++++++------ mlir/unittests/programs/qir_programs.h | 240 ++++---- 4 files changed, 684 insertions(+), 717 deletions(-) diff --git a/mlir/unittests/Compiler/test_compiler_pipeline.cpp b/mlir/unittests/Compiler/test_compiler_pipeline.cpp index c452465b01..fad33c9561 100644 --- a/mlir/unittests/Compiler/test_compiler_pipeline.cpp +++ b/mlir/unittests/Compiler/test_compiler_pipeline.cpp @@ -293,35 +293,36 @@ INSTANTIATE_TEST_SUITE_P( CompilerPipelineTestCase{ "AllocQubit", MQT_NAMED_BUILDER(qc::allocQubit), nullptr, MQT_NAMED_BUILDER(mlir::qc::alloc1QubitRegister), - MQT_NAMED_BUILDER(mlir::qir::alloc1QubitRegister)}, + MQT_NAMED_BUILDER(mlir::qir::alloc1QubitRegister)}, CompilerPipelineTestCase{ "AllocQubitRegister", MQT_NAMED_BUILDER(qc::allocQubitRegister), nullptr, MQT_NAMED_BUILDER(mlir::qc::allocQubitRegister), - MQT_NAMED_BUILDER(mlir::qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(mlir::qir::allocQubitRegister)}, CompilerPipelineTestCase{ "AllocMultipleQubitRegisters", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegisters), nullptr, MQT_NAMED_BUILDER(mlir::qc::allocMultipleQubitRegisters), - MQT_NAMED_BUILDER(mlir::qir::allocMultipleQubitRegisters)}, + MQT_NAMED_BUILDER(mlir::qir::allocMultipleQubitRegisters)}, CompilerPipelineTestCase{ "AllocLargeRegister", MQT_NAMED_BUILDER(qc::allocLargeRegister), nullptr, MQT_NAMED_BUILDER(mlir::qc::allocLargeRegister), - MQT_NAMED_BUILDER(mlir::qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(mlir::qir::allocQubitRegister)}, CompilerPipelineTestCase{ "SingleMeasurementToSingleBit", MQT_NAMED_BUILDER(qc::singleMeasurementToSingleBit), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleMeasurementToSingleBit), - MQT_NAMED_BUILDER(mlir::qir::singleMeasurementToSingleBit)}, + MQT_NAMED_BUILDER(mlir::qir::singleMeasurementToSingleBit)}, CompilerPipelineTestCase{ "RepeatedMeasurementToSameBit", MQT_NAMED_BUILDER(qc::repeatedMeasurementToSameBit), nullptr, MQT_NAMED_BUILDER(mlir::qc::repeatedMeasurementToSameBit), - MQT_NAMED_BUILDER(mlir::qir::repeatedMeasurementToSameBit)}, + MQT_NAMED_BUILDER(mlir::qir::repeatedMeasurementToSameBit)}, CompilerPipelineTestCase{ "RepeatedMeasurementToDifferentBits", MQT_NAMED_BUILDER(qc::repeatedMeasurementToDifferentBits), nullptr, MQT_NAMED_BUILDER(mlir::qc::repeatedMeasurementToDifferentBits), - MQT_NAMED_BUILDER(mlir::qir::repeatedMeasurementToDifferentBits)}, + MQT_NAMED_BUILDER( + mlir::qir::repeatedMeasurementToDifferentBits)}, CompilerPipelineTestCase{ "MultipleClassicalRegistersAndMeasurements", MQT_NAMED_BUILDER(qc::multipleClassicalRegistersAndMeasurements), @@ -334,263 +335,265 @@ INSTANTIATE_TEST_SUITE_P( "MeasurementWithoutRegisters", nullptr, MQT_NAMED_BUILDER(mlir::qc::measurementWithoutRegisters), MQT_NAMED_BUILDER(mlir::qc::measurementWithoutRegisters), - MQT_NAMED_BUILDER(mlir::qir::measurementWithoutRegisters), false}, + MQT_NAMED_BUILDER(mlir::qir::measurementWithoutRegisters), + false}, CompilerPipelineTestCase{ "ResetQubitAfterSingleOp", MQT_NAMED_BUILDER(qc::resetQubitAfterSingleOp), nullptr, MQT_NAMED_BUILDER(mlir::qc::resetQubitAfterSingleOp), - MQT_NAMED_BUILDER(mlir::qir::resetQubitAfterSingleOp)}, + MQT_NAMED_BUILDER(mlir::qir::resetQubitAfterSingleOp)}, CompilerPipelineTestCase{ "ResetMultipleQubitsAfterSingleOp", MQT_NAMED_BUILDER(qc::resetMultipleQubitsAfterSingleOp), nullptr, MQT_NAMED_BUILDER(mlir::qc::resetMultipleQubitsAfterSingleOp), - MQT_NAMED_BUILDER(mlir::qir::resetMultipleQubitsAfterSingleOp)}, + MQT_NAMED_BUILDER( + mlir::qir::resetMultipleQubitsAfterSingleOp)}, CompilerPipelineTestCase{ "RepeatedResetAfterSingleOp", MQT_NAMED_BUILDER(qc::repeatedResetAfterSingleOp), nullptr, MQT_NAMED_BUILDER(mlir::qc::resetQubitAfterSingleOp), - MQT_NAMED_BUILDER(mlir::qir::resetQubitAfterSingleOp)}, - CompilerPipelineTestCase{"GlobalPhase", - MQT_NAMED_BUILDER(qc::globalPhase), nullptr, - MQT_NAMED_BUILDER(mlir::qc::globalPhase), - MQT_NAMED_BUILDER(mlir::qir::globalPhase)}, + MQT_NAMED_BUILDER(mlir::qir::resetQubitAfterSingleOp)}, + CompilerPipelineTestCase{ + "GlobalPhase", MQT_NAMED_BUILDER(qc::globalPhase), nullptr, + MQT_NAMED_BUILDER(mlir::qc::globalPhase), + MQT_NAMED_BUILDER(mlir::qir::globalPhase)}, CompilerPipelineTestCase{ "Identity", MQT_NAMED_BUILDER(qc::identity), nullptr, MQT_NAMED_BUILDER(mlir::qc::alloc1QubitRegister), - MQT_NAMED_BUILDER(mlir::qir::alloc1QubitRegister)}, + MQT_NAMED_BUILDER(mlir::qir::alloc1QubitRegister)}, CompilerPipelineTestCase{ "SingleControlledIdentity", MQT_NAMED_BUILDER(qc::singleControlledIdentity), nullptr, MQT_NAMED_BUILDER(mlir::qc::allocQubitRegister), - MQT_NAMED_BUILDER(mlir::qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(mlir::qir::allocQubitRegister)}, CompilerPipelineTestCase{ "MultipleControlledIdentity", MQT_NAMED_BUILDER(qc::multipleControlledIdentity), nullptr, MQT_NAMED_BUILDER(mlir::qc::alloc1QubitRegister), - MQT_NAMED_BUILDER(mlir::qir::alloc1QubitRegister)}, + MQT_NAMED_BUILDER(mlir::qir::alloc1QubitRegister)}, CompilerPipelineTestCase{"X", MQT_NAMED_BUILDER(qc::x), nullptr, MQT_NAMED_BUILDER(mlir::qc::x), - MQT_NAMED_BUILDER(mlir::qir::x)}, + MQT_NAMED_BUILDER(mlir::qir::x)}, CompilerPipelineTestCase{ "SingleControlledX", MQT_NAMED_BUILDER(qc::singleControlledX), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledX), - MQT_NAMED_BUILDER(mlir::qir::singleControlledX)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledX)}, CompilerPipelineTestCase{ "MultipleControlledX", MQT_NAMED_BUILDER(qc::multipleControlledX), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledX), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledX)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledX)}, CompilerPipelineTestCase{"Y", MQT_NAMED_BUILDER(qc::y), nullptr, MQT_NAMED_BUILDER(mlir::qc::y), - MQT_NAMED_BUILDER(mlir::qir::y)}, + MQT_NAMED_BUILDER(mlir::qir::y)}, CompilerPipelineTestCase{ "SingleControlledY", MQT_NAMED_BUILDER(qc::singleControlledY), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledY), - MQT_NAMED_BUILDER(mlir::qir::singleControlledY)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledY)}, CompilerPipelineTestCase{ "MultipleControlledY", MQT_NAMED_BUILDER(qc::multipleControlledY), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledY), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledY)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledY)}, CompilerPipelineTestCase{"Z", MQT_NAMED_BUILDER(qc::z), nullptr, MQT_NAMED_BUILDER(mlir::qc::z), - MQT_NAMED_BUILDER(mlir::qir::z)}, + MQT_NAMED_BUILDER(mlir::qir::z)}, CompilerPipelineTestCase{ "SingleControlledZ", MQT_NAMED_BUILDER(qc::singleControlledZ), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledZ), - MQT_NAMED_BUILDER(mlir::qir::singleControlledZ)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledZ)}, CompilerPipelineTestCase{ "MultipleControlledZ", MQT_NAMED_BUILDER(qc::multipleControlledZ), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledZ), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledZ)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledZ)}, CompilerPipelineTestCase{"H", MQT_NAMED_BUILDER(qc::h), nullptr, MQT_NAMED_BUILDER(mlir::qc::h), - MQT_NAMED_BUILDER(mlir::qir::h)}, + MQT_NAMED_BUILDER(mlir::qir::h)}, CompilerPipelineTestCase{ "SingleControlledH", MQT_NAMED_BUILDER(qc::singleControlledH), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledH), - MQT_NAMED_BUILDER(mlir::qir::singleControlledH)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledH)}, CompilerPipelineTestCase{ "MultipleControlledH", MQT_NAMED_BUILDER(qc::multipleControlledH), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledH), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledH)}, - CompilerPipelineTestCase{"HWithoutRegister", nullptr, - MQT_NAMED_BUILDER(mlir::qc::hWithoutRegister), - MQT_NAMED_BUILDER(mlir::qc::hWithoutRegister), - MQT_NAMED_BUILDER(mlir::qir::hWithoutRegister), - false}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledH)}, + CompilerPipelineTestCase{ + "HWithoutRegister", nullptr, + MQT_NAMED_BUILDER(mlir::qc::hWithoutRegister), + MQT_NAMED_BUILDER(mlir::qc::hWithoutRegister), + MQT_NAMED_BUILDER(mlir::qir::hWithoutRegister), false}, CompilerPipelineTestCase{"S", MQT_NAMED_BUILDER(qc::s), nullptr, MQT_NAMED_BUILDER(mlir::qc::s), - MQT_NAMED_BUILDER(mlir::qir::s)}, + MQT_NAMED_BUILDER(mlir::qir::s)}, CompilerPipelineTestCase{ "SingleControlledS", MQT_NAMED_BUILDER(qc::singleControlledS), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledS), - MQT_NAMED_BUILDER(mlir::qir::singleControlledS)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledS)}, CompilerPipelineTestCase{ "MultipleControlledS", MQT_NAMED_BUILDER(qc::multipleControlledS), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledS), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledS)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledS)}, CompilerPipelineTestCase{"Sdg", MQT_NAMED_BUILDER(qc::sdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::sdg), - MQT_NAMED_BUILDER(mlir::qir::sdg)}, + MQT_NAMED_BUILDER(mlir::qir::sdg)}, CompilerPipelineTestCase{ "SingleControlledSdg", MQT_NAMED_BUILDER(qc::singleControlledSdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledSdg), - MQT_NAMED_BUILDER(mlir::qir::singleControlledSdg)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledSdg)}, CompilerPipelineTestCase{ "MultipleControlledSdg", MQT_NAMED_BUILDER(qc::multipleControlledSdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledSdg), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledSdg)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledSdg)}, CompilerPipelineTestCase{"T", MQT_NAMED_BUILDER(qc::t_), nullptr, MQT_NAMED_BUILDER(mlir::qc::t_), - MQT_NAMED_BUILDER(mlir::qir::t_)}, + MQT_NAMED_BUILDER(mlir::qir::t_)}, CompilerPipelineTestCase{ "SingleControlledT", MQT_NAMED_BUILDER(qc::singleControlledT), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledT), - MQT_NAMED_BUILDER(mlir::qir::singleControlledT)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledT)}, CompilerPipelineTestCase{ "MultipleControlledT", MQT_NAMED_BUILDER(qc::multipleControlledT), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledT), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledT)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledT)}, CompilerPipelineTestCase{"Tdg", MQT_NAMED_BUILDER(qc::tdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::tdg), - MQT_NAMED_BUILDER(mlir::qir::tdg)}, + MQT_NAMED_BUILDER(mlir::qir::tdg)}, CompilerPipelineTestCase{ "SingleControlledTdg", MQT_NAMED_BUILDER(qc::singleControlledTdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledTdg), - MQT_NAMED_BUILDER(mlir::qir::singleControlledTdg)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledTdg)}, CompilerPipelineTestCase{ "MultipleControlledTdg", MQT_NAMED_BUILDER(qc::multipleControlledTdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledTdg), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledTdg)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledTdg)}, CompilerPipelineTestCase{"SX", MQT_NAMED_BUILDER(qc::sx), nullptr, MQT_NAMED_BUILDER(mlir::qc::sx), - MQT_NAMED_BUILDER(mlir::qir::sx)}, + MQT_NAMED_BUILDER(mlir::qir::sx)}, CompilerPipelineTestCase{ "SingleControlledSX", MQT_NAMED_BUILDER(qc::singleControlledSx), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledSx), - MQT_NAMED_BUILDER(mlir::qir::singleControlledSx)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledSx)}, CompilerPipelineTestCase{ "MultipleControlledSX", MQT_NAMED_BUILDER(qc::multipleControlledSx), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledSx), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledSx)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledSx)}, CompilerPipelineTestCase{"SXdg", MQT_NAMED_BUILDER(qc::sxdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::sxdg), - MQT_NAMED_BUILDER(mlir::qir::sxdg)}, + MQT_NAMED_BUILDER(mlir::qir::sxdg)}, CompilerPipelineTestCase{ "SingleControlledSXdg", MQT_NAMED_BUILDER(qc::singleControlledSxdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledSxdg), - MQT_NAMED_BUILDER(mlir::qir::singleControlledSxdg)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledSxdg)}, CompilerPipelineTestCase{ "MultipleControlledSXdg", MQT_NAMED_BUILDER(qc::multipleControlledSxdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledSxdg), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledSxdg)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledSxdg)}, CompilerPipelineTestCase{"RX", MQT_NAMED_BUILDER(qc::rx), nullptr, MQT_NAMED_BUILDER(mlir::qc::rx), - MQT_NAMED_BUILDER(mlir::qir::rx)}, + MQT_NAMED_BUILDER(mlir::qir::rx)}, CompilerPipelineTestCase{ "SingleControlledRX", MQT_NAMED_BUILDER(qc::singleControlledRx), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRx), - MQT_NAMED_BUILDER(mlir::qir::singleControlledRx)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledRx)}, CompilerPipelineTestCase{ "MultipleControlledRX", MQT_NAMED_BUILDER(qc::multipleControlledRx), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRx), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledRx)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledRx)}, CompilerPipelineTestCase{"RY", MQT_NAMED_BUILDER(qc::ry), nullptr, MQT_NAMED_BUILDER(mlir::qc::ry), - MQT_NAMED_BUILDER(mlir::qir::ry)}, + MQT_NAMED_BUILDER(mlir::qir::ry)}, CompilerPipelineTestCase{ "SingleControlledRY", MQT_NAMED_BUILDER(qc::singleControlledRy), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRy), - MQT_NAMED_BUILDER(mlir::qir::singleControlledRy)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledRy)}, CompilerPipelineTestCase{ "MultipleControlledRY", MQT_NAMED_BUILDER(qc::multipleControlledRy), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRy), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledRy)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledRy)}, CompilerPipelineTestCase{"RZ", MQT_NAMED_BUILDER(qc::rz), nullptr, MQT_NAMED_BUILDER(mlir::qc::rz), - MQT_NAMED_BUILDER(mlir::qir::rz)}, + MQT_NAMED_BUILDER(mlir::qir::rz)}, CompilerPipelineTestCase{ "SingleControlledRZ", MQT_NAMED_BUILDER(qc::singleControlledRz), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRz), - MQT_NAMED_BUILDER(mlir::qir::singleControlledRz)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledRz)}, CompilerPipelineTestCase{ "MultipleControlledRZ", MQT_NAMED_BUILDER(qc::multipleControlledRz), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRz), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledRz)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledRz)}, CompilerPipelineTestCase{"P", MQT_NAMED_BUILDER(qc::p), nullptr, MQT_NAMED_BUILDER(mlir::qc::p), - MQT_NAMED_BUILDER(mlir::qir::p)}, + MQT_NAMED_BUILDER(mlir::qir::p)}, CompilerPipelineTestCase{ "SingleControlledP", MQT_NAMED_BUILDER(qc::singleControlledP), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledP), - MQT_NAMED_BUILDER(mlir::qir::singleControlledP)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledP)}, CompilerPipelineTestCase{ "MultipleControlledP", MQT_NAMED_BUILDER(qc::multipleControlledP), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledP), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledP)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledP)}, CompilerPipelineTestCase{"R", MQT_NAMED_BUILDER(qc::r), nullptr, MQT_NAMED_BUILDER(mlir::qc::r), - MQT_NAMED_BUILDER(mlir::qir::r)}, + MQT_NAMED_BUILDER(mlir::qir::r)}, CompilerPipelineTestCase{ "SingleControlledR", MQT_NAMED_BUILDER(qc::singleControlledR), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledR), - MQT_NAMED_BUILDER(mlir::qir::singleControlledR)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledR)}, CompilerPipelineTestCase{ "MultipleControlledR", MQT_NAMED_BUILDER(qc::multipleControlledR), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledR), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledR)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledR)}, CompilerPipelineTestCase{"U2", MQT_NAMED_BUILDER(qc::u2), nullptr, MQT_NAMED_BUILDER(mlir::qc::u2), - MQT_NAMED_BUILDER(mlir::qir::u2)}, + MQT_NAMED_BUILDER(mlir::qir::u2)}, CompilerPipelineTestCase{ "SingleControlledU2", MQT_NAMED_BUILDER(qc::singleControlledU2), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledU2), - MQT_NAMED_BUILDER(mlir::qir::singleControlledU2)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledU2)}, CompilerPipelineTestCase{ "MultipleControlledU2", MQT_NAMED_BUILDER(qc::multipleControlledU2), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledU2), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledU2)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledU2)}, CompilerPipelineTestCase{"U", MQT_NAMED_BUILDER(qc::u), nullptr, MQT_NAMED_BUILDER(mlir::qc::u), - MQT_NAMED_BUILDER(mlir::qir::u)}, + MQT_NAMED_BUILDER(mlir::qir::u)}, CompilerPipelineTestCase{ "SingleControlledU", MQT_NAMED_BUILDER(qc::singleControlledU), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledU), - MQT_NAMED_BUILDER(mlir::qir::singleControlledU)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledU)}, CompilerPipelineTestCase{ "MultipleControlledU", MQT_NAMED_BUILDER(qc::multipleControlledU), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledU), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledU)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledU)}, CompilerPipelineTestCase{"SWAP", MQT_NAMED_BUILDER(qc::swap), nullptr, MQT_NAMED_BUILDER(mlir::qc::swap), - MQT_NAMED_BUILDER(mlir::qir::swap)}, + MQT_NAMED_BUILDER(mlir::qir::swap)}, CompilerPipelineTestCase{ "SingleControlledSWAP", MQT_NAMED_BUILDER(qc::singleControlledSwap), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledSwap), - MQT_NAMED_BUILDER(mlir::qir::singleControlledSwap)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledSwap)}, CompilerPipelineTestCase{ "MultipleControlledSWAP", MQT_NAMED_BUILDER(qc::multipleControlledSwap), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledSwap), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledSwap)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledSwap)}, CompilerPipelineTestCase{"iSWAP", MQT_NAMED_BUILDER(qc::iswap), nullptr, MQT_NAMED_BUILDER(mlir::qc::iswap), - MQT_NAMED_BUILDER(mlir::qir::iswap)}, + MQT_NAMED_BUILDER(mlir::qir::iswap)}, CompilerPipelineTestCase{ "SingleControllediSWAP", MQT_NAMED_BUILDER(qc::singleControlledIswap), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledIswap), - MQT_NAMED_BUILDER(mlir::qir::singleControlledIswap)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledIswap)}, CompilerPipelineTestCase{ "MultipleControllediSWAP", MQT_NAMED_BUILDER(qc::multipleControlledIswap), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledIswap), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledIswap)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledIswap)}, CompilerPipelineTestCase{ "InverseISWAP", MQT_NAMED_BUILDER(qc::inverseIswap), nullptr, MQT_NAMED_BUILDER(mlir::qc::inverseIswap), nullptr, true, false}, @@ -601,109 +604,109 @@ INSTANTIATE_TEST_SUITE_P( nullptr, true, false}, CompilerPipelineTestCase{"DCX", MQT_NAMED_BUILDER(qc::dcx), nullptr, MQT_NAMED_BUILDER(mlir::qc::dcx), - MQT_NAMED_BUILDER(mlir::qir::dcx)}, + MQT_NAMED_BUILDER(mlir::qir::dcx)}, CompilerPipelineTestCase{ "SingleControlledDCX", MQT_NAMED_BUILDER(qc::singleControlledDcx), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledDcx), - MQT_NAMED_BUILDER(mlir::qir::singleControlledDcx)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledDcx)}, CompilerPipelineTestCase{ "MultipleControlledDCX", MQT_NAMED_BUILDER(qc::multipleControlledDcx), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledDcx), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledDcx)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledDcx)}, CompilerPipelineTestCase{"ECR", MQT_NAMED_BUILDER(qc::ecr), nullptr, MQT_NAMED_BUILDER(mlir::qc::ecr), - MQT_NAMED_BUILDER(mlir::qir::ecr)}, + MQT_NAMED_BUILDER(mlir::qir::ecr)}, CompilerPipelineTestCase{ "SingleControlledECR", MQT_NAMED_BUILDER(qc::singleControlledEcr), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledEcr), - MQT_NAMED_BUILDER(mlir::qir::singleControlledEcr)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledEcr)}, CompilerPipelineTestCase{ "MultipleControlledECR", MQT_NAMED_BUILDER(qc::multipleControlledEcr), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledEcr), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledEcr)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledEcr)}, CompilerPipelineTestCase{"RXX", MQT_NAMED_BUILDER(qc::rxx), nullptr, MQT_NAMED_BUILDER(mlir::qc::rxx), - MQT_NAMED_BUILDER(mlir::qir::rxx)}, + MQT_NAMED_BUILDER(mlir::qir::rxx)}, CompilerPipelineTestCase{ "SingleControlledRXX", MQT_NAMED_BUILDER(qc::singleControlledRxx), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRxx), - MQT_NAMED_BUILDER(mlir::qir::singleControlledRxx)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledRxx)}, CompilerPipelineTestCase{ "MultipleControlledRXX", MQT_NAMED_BUILDER(qc::multipleControlledRxx), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRxx), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledRxx)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledRxx)}, CompilerPipelineTestCase{ "TripleControlledRXX", MQT_NAMED_BUILDER(qc::tripleControlledRxx), nullptr, MQT_NAMED_BUILDER(mlir::qc::tripleControlledRxx), - MQT_NAMED_BUILDER(mlir::qir::tripleControlledRxx)}, + MQT_NAMED_BUILDER(mlir::qir::tripleControlledRxx)}, CompilerPipelineTestCase{"RYY", MQT_NAMED_BUILDER(qc::ryy), nullptr, MQT_NAMED_BUILDER(mlir::qc::ryy), - MQT_NAMED_BUILDER(mlir::qir::ryy)}, + MQT_NAMED_BUILDER(mlir::qir::ryy)}, CompilerPipelineTestCase{ "SingleControlledRYY", MQT_NAMED_BUILDER(qc::singleControlledRyy), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRyy), - MQT_NAMED_BUILDER(mlir::qir::singleControlledRyy)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledRyy)}, CompilerPipelineTestCase{ "MultipleControlledRYY", MQT_NAMED_BUILDER(qc::multipleControlledRyy), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRyy), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledRyy)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledRyy)}, CompilerPipelineTestCase{"RZX", MQT_NAMED_BUILDER(qc::rzx), nullptr, MQT_NAMED_BUILDER(mlir::qc::rzx), - MQT_NAMED_BUILDER(mlir::qir::rzx)}, + MQT_NAMED_BUILDER(mlir::qir::rzx)}, CompilerPipelineTestCase{ "SingleControlledRZX", MQT_NAMED_BUILDER(qc::singleControlledRzx), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRzx), - MQT_NAMED_BUILDER(mlir::qir::singleControlledRzx)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledRzx)}, CompilerPipelineTestCase{ "MultipleControlledRZX", MQT_NAMED_BUILDER(qc::multipleControlledRzx), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRzx), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledRzx)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledRzx)}, CompilerPipelineTestCase{"RZZ", MQT_NAMED_BUILDER(qc::rzz), nullptr, MQT_NAMED_BUILDER(mlir::qc::rzz), - MQT_NAMED_BUILDER(mlir::qir::rzz)}, + MQT_NAMED_BUILDER(mlir::qir::rzz)}, CompilerPipelineTestCase{ "SingleControlledRZZ", MQT_NAMED_BUILDER(qc::singleControlledRzz), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRzz), - MQT_NAMED_BUILDER(mlir::qir::singleControlledRzz)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledRzz)}, CompilerPipelineTestCase{ "MultipleControlledRZZ", MQT_NAMED_BUILDER(qc::multipleControlledRzz), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRzz), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledRzz)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledRzz)}, CompilerPipelineTestCase{"XXPlusYY", MQT_NAMED_BUILDER(qc::xxPlusYY), nullptr, MQT_NAMED_BUILDER(mlir::qc::xxPlusYY), - MQT_NAMED_BUILDER(mlir::qir::xxPlusYY)}, + MQT_NAMED_BUILDER(mlir::qir::xxPlusYY)}, CompilerPipelineTestCase{ "SingleControlledXXPlusYY", MQT_NAMED_BUILDER(qc::singleControlledXxPlusYY), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledXxPlusYY), - MQT_NAMED_BUILDER(mlir::qir::singleControlledXxPlusYY)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledXxPlusYY)}, CompilerPipelineTestCase{ "MultipleControlledXXPlusYY", MQT_NAMED_BUILDER(qc::multipleControlledXxPlusYY), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledXxPlusYY), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledXxPlusYY)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledXxPlusYY)}, CompilerPipelineTestCase{"XXMinusYY", MQT_NAMED_BUILDER(qc::xxMinusYY), nullptr, MQT_NAMED_BUILDER(mlir::qc::xxMinusYY), - MQT_NAMED_BUILDER(mlir::qir::xxMinusYY)}, + MQT_NAMED_BUILDER(mlir::qir::xxMinusYY)}, CompilerPipelineTestCase{ "SingleControlledXXMinusYY", MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledXxMinusYY), - MQT_NAMED_BUILDER(mlir::qir::singleControlledXxMinusYY)}, + MQT_NAMED_BUILDER(mlir::qir::singleControlledXxMinusYY)}, CompilerPipelineTestCase{ "MultipleControlledXXMinusYY", MQT_NAMED_BUILDER(qc::multipleControlledXxMinusYY), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledXxMinusYY), - MQT_NAMED_BUILDER(mlir::qir::multipleControlledXxMinusYY)}, + MQT_NAMED_BUILDER(mlir::qir::multipleControlledXxMinusYY)}, CompilerPipelineTestCase{"CtrlTwo", MQT_NAMED_BUILDER(qc::ctrlTwo), nullptr, MQT_NAMED_BUILDER(mlir::qc::ctrlTwo), - MQT_NAMED_BUILDER(mlir::qir::ctrlTwo)})); + MQT_NAMED_BUILDER(mlir::qir::ctrlTwo)})); } // namespace mqt::test::compiler diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp index 6fe05636f9..afde92dab8 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp @@ -127,20 +127,17 @@ TEST_P(QCToQIRAdaptiveTest, ProgramEquivalence) { INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveBarrierOpTest, QCToQIRAdaptiveTest, testing::Values( - QCToQIRAdaptiveTestCase{ - "Barrier", MQT_NAMED_BUILDER(qc::barrier), - MQT_NAMED_BUILDER(qir::alloc1QubitRegister)}, - QCToQIRAdaptiveTestCase{ - "BarrierTwoQubits", MQT_NAMED_BUILDER(qc::barrierTwoQubits), - MQT_NAMED_BUILDER(qir::allocQubitRegister)}, - QCToQIRAdaptiveTestCase{ - "BarrierMultipleQubits", - MQT_NAMED_BUILDER(qc::barrierMultipleQubits), - MQT_NAMED_BUILDER(qir::alloc3QubitRegister)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledBarrier", - MQT_NAMED_BUILDER(qc::singleControlledBarrier), - MQT_NAMED_BUILDER(qir::allocQubitRegister)})); + QCToQIRAdaptiveTestCase{"Barrier", MQT_NAMED_BUILDER(qc::barrier), + MQT_NAMED_BUILDER(qir::alloc1QubitRegister)}, + QCToQIRAdaptiveTestCase{"BarrierTwoQubits", + MQT_NAMED_BUILDER(qc::barrierTwoQubits), + MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + QCToQIRAdaptiveTestCase{"BarrierMultipleQubits", + MQT_NAMED_BUILDER(qc::barrierMultipleQubits), + MQT_NAMED_BUILDER(qir::alloc3QubitRegister)}, + QCToQIRAdaptiveTestCase{"SingleControlledBarrier", + MQT_NAMED_BUILDER(qc::singleControlledBarrier), + MQT_NAMED_BUILDER(qir::allocQubitRegister)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/DcxOp.cpp @@ -148,15 +145,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveDCXOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"DCX", MQT_NAMED_BUILDER(qc::dcx), - MQT_NAMED_BUILDER(qir::dcx)}, + MQT_NAMED_BUILDER(qir::dcx)}, QCToQIRAdaptiveTestCase{ "SingleControlledDCX", MQT_NAMED_BUILDER(qc::singleControlledDcx), - MQT_NAMED_BUILDER(qir::singleControlledDcx)}, + MQT_NAMED_BUILDER(qir::singleControlledDcx)}, QCToQIRAdaptiveTestCase{ "MultipleControlledDCX", MQT_NAMED_BUILDER(qc::multipleControlledDcx), - MQT_NAMED_BUILDER(qir::multipleControlledDcx)})); + MQT_NAMED_BUILDER(qir::multipleControlledDcx)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/EcrOp.cpp @@ -164,15 +161,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveECROpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"ECR", MQT_NAMED_BUILDER(qc::ecr), - MQT_NAMED_BUILDER(qir::ecr)}, + MQT_NAMED_BUILDER(qir::ecr)}, QCToQIRAdaptiveTestCase{ "SingleControlledECR", MQT_NAMED_BUILDER(qc::singleControlledEcr), - MQT_NAMED_BUILDER(qir::singleControlledEcr)}, + MQT_NAMED_BUILDER(qir::singleControlledEcr)}, QCToQIRAdaptiveTestCase{ "MultipleControlledECR", MQT_NAMED_BUILDER(qc::multipleControlledEcr), - MQT_NAMED_BUILDER(qir::multipleControlledEcr)})); + MQT_NAMED_BUILDER(qir::multipleControlledEcr)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/GphaseOp.cpp @@ -180,7 +177,7 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(QCToQIRAdaptiveGPhaseOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{ "GlobalPhase", MQT_NAMED_BUILDER(qc::globalPhase), - MQT_NAMED_BUILDER(qir::globalPhase)})); + MQT_NAMED_BUILDER(qir::globalPhase)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/HOp.cpp @@ -189,16 +186,16 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveHOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"H", MQT_NAMED_BUILDER(qc::h), - MQT_NAMED_BUILDER(qir::h)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledH", MQT_NAMED_BUILDER(qc::singleControlledH), - MQT_NAMED_BUILDER(qir::singleControlledH)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledH", MQT_NAMED_BUILDER(qc::multipleControlledH), - MQT_NAMED_BUILDER(qir::multipleControlledH)}, - QCToQIRAdaptiveTestCase{ - "HWithoutRegister", MQT_NAMED_BUILDER(qc::hWithoutRegister), - MQT_NAMED_BUILDER(qir::hWithoutRegister)})); + MQT_NAMED_BUILDER(qir::h)}, + QCToQIRAdaptiveTestCase{"SingleControlledH", + MQT_NAMED_BUILDER(qc::singleControlledH), + MQT_NAMED_BUILDER(qir::singleControlledH)}, + QCToQIRAdaptiveTestCase{"MultipleControlledH", + MQT_NAMED_BUILDER(qc::multipleControlledH), + MQT_NAMED_BUILDER(qir::multipleControlledH)}, + QCToQIRAdaptiveTestCase{"HWithoutRegister", + MQT_NAMED_BUILDER(qc::hWithoutRegister), + MQT_NAMED_BUILDER(qir::hWithoutRegister)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/IdOp.cpp @@ -207,15 +204,14 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveIDOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"Identity", MQT_NAMED_BUILDER(qc::identity), - MQT_NAMED_BUILDER(qir::identity)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledIdentity", - MQT_NAMED_BUILDER(qc::singleControlledIdentity), - MQT_NAMED_BUILDER(qir::twoQubitsOneIdentity)}, + MQT_NAMED_BUILDER(qir::identity)}, + QCToQIRAdaptiveTestCase{"SingleControlledIdentity", + MQT_NAMED_BUILDER(qc::singleControlledIdentity), + MQT_NAMED_BUILDER(qir::twoQubitsOneIdentity)}, QCToQIRAdaptiveTestCase{ "MultipleControlledIdentity", MQT_NAMED_BUILDER(qc::multipleControlledIdentity), - MQT_NAMED_BUILDER(qir::threeQubitsOneIdentity)})); + MQT_NAMED_BUILDER(qir::threeQubitsOneIdentity)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/IswapOp.cpp @@ -224,63 +220,59 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveiSWAPOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"iSWAP", MQT_NAMED_BUILDER(qc::iswap), - MQT_NAMED_BUILDER(qir::iswap)}, - QCToQIRAdaptiveTestCase{ - "SingleControllediSWAP", - MQT_NAMED_BUILDER(qc::singleControlledIswap), - MQT_NAMED_BUILDER(qir::singleControlledIswap)}, + MQT_NAMED_BUILDER(qir::iswap)}, + QCToQIRAdaptiveTestCase{"SingleControllediSWAP", + MQT_NAMED_BUILDER(qc::singleControlledIswap), + MQT_NAMED_BUILDER(qir::singleControlledIswap)}, QCToQIRAdaptiveTestCase{ "MultipleControllediSWAP", MQT_NAMED_BUILDER(qc::multipleControlledIswap), - MQT_NAMED_BUILDER(qir::multipleControlledIswap)})); + MQT_NAMED_BUILDER(qir::multipleControlledIswap)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/POp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptivePOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"P", MQT_NAMED_BUILDER(qc::p), - MQT_NAMED_BUILDER(qir::p)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledP", - MQT_NAMED_BUILDER(qc::singleControlledP), - MQT_NAMED_BUILDER(qir::singleControlledP)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledP", - MQT_NAMED_BUILDER(qc::multipleControlledP), - MQT_NAMED_BUILDER(qir::multipleControlledP)})); + testing::Values( + QCToQIRAdaptiveTestCase{"P", MQT_NAMED_BUILDER(qc::p), + MQT_NAMED_BUILDER(qir::p)}, + QCToQIRAdaptiveTestCase{"SingleControlledP", + MQT_NAMED_BUILDER(qc::singleControlledP), + MQT_NAMED_BUILDER(qir::singleControlledP)}, + QCToQIRAdaptiveTestCase{"MultipleControlledP", + MQT_NAMED_BUILDER(qc::multipleControlledP), + MQT_NAMED_BUILDER(qir::multipleControlledP)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/ROp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveROpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"R", MQT_NAMED_BUILDER(qc::r), - MQT_NAMED_BUILDER(qir::r)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledR", - MQT_NAMED_BUILDER(qc::singleControlledR), - MQT_NAMED_BUILDER(qir::singleControlledR)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledR", - MQT_NAMED_BUILDER(qc::multipleControlledR), - MQT_NAMED_BUILDER(qir::multipleControlledR)})); + testing::Values( + QCToQIRAdaptiveTestCase{"R", MQT_NAMED_BUILDER(qc::r), + MQT_NAMED_BUILDER(qir::r)}, + QCToQIRAdaptiveTestCase{"SingleControlledR", + MQT_NAMED_BUILDER(qc::singleControlledR), + MQT_NAMED_BUILDER(qir::singleControlledR)}, + QCToQIRAdaptiveTestCase{"MultipleControlledR", + MQT_NAMED_BUILDER(qc::multipleControlledR), + MQT_NAMED_BUILDER(qir::multipleControlledR)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRXOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"RX", MQT_NAMED_BUILDER(qc::rx), - MQT_NAMED_BUILDER(qir::rx)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledRX", - MQT_NAMED_BUILDER(qc::singleControlledRx), - MQT_NAMED_BUILDER(qir::singleControlledRx)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledRX", - MQT_NAMED_BUILDER(qc::multipleControlledRx), - MQT_NAMED_BUILDER(qir::multipleControlledRx)})); + testing::Values( + QCToQIRAdaptiveTestCase{"RX", MQT_NAMED_BUILDER(qc::rx), + MQT_NAMED_BUILDER(qir::rx)}, + QCToQIRAdaptiveTestCase{"SingleControlledRX", + MQT_NAMED_BUILDER(qc::singleControlledRx), + MQT_NAMED_BUILDER(qir::singleControlledRx)}, + QCToQIRAdaptiveTestCase{"MultipleControlledRX", + MQT_NAMED_BUILDER(qc::multipleControlledRx), + MQT_NAMED_BUILDER(qir::multipleControlledRx)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RxxOp.cpp @@ -288,31 +280,30 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRXXOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"RXX", MQT_NAMED_BUILDER(qc::rxx), - MQT_NAMED_BUILDER(qir::rxx)}, + MQT_NAMED_BUILDER(qir::rxx)}, QCToQIRAdaptiveTestCase{ "SingleControlledRXX", MQT_NAMED_BUILDER(qc::singleControlledRxx), - MQT_NAMED_BUILDER(qir::singleControlledRxx)}, + MQT_NAMED_BUILDER(qir::singleControlledRxx)}, QCToQIRAdaptiveTestCase{ "MultipleControlledRXX", MQT_NAMED_BUILDER(qc::multipleControlledRxx), - MQT_NAMED_BUILDER(qir::multipleControlledRxx)})); + MQT_NAMED_BUILDER(qir::multipleControlledRxx)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRYOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"RY", MQT_NAMED_BUILDER(qc::ry), - MQT_NAMED_BUILDER(qir::ry)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledRY", - MQT_NAMED_BUILDER(qc::singleControlledRy), - MQT_NAMED_BUILDER(qir::singleControlledRy)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledRY", - MQT_NAMED_BUILDER(qc::multipleControlledRy), - MQT_NAMED_BUILDER(qir::multipleControlledRy)})); + testing::Values( + QCToQIRAdaptiveTestCase{"RY", MQT_NAMED_BUILDER(qc::ry), + MQT_NAMED_BUILDER(qir::ry)}, + QCToQIRAdaptiveTestCase{"SingleControlledRY", + MQT_NAMED_BUILDER(qc::singleControlledRy), + MQT_NAMED_BUILDER(qir::singleControlledRy)}, + QCToQIRAdaptiveTestCase{"MultipleControlledRY", + MQT_NAMED_BUILDER(qc::multipleControlledRy), + MQT_NAMED_BUILDER(qir::multipleControlledRy)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RyyOp.cpp @@ -320,31 +311,30 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRYYOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"RYY", MQT_NAMED_BUILDER(qc::ryy), - MQT_NAMED_BUILDER(qir::ryy)}, + MQT_NAMED_BUILDER(qir::ryy)}, QCToQIRAdaptiveTestCase{ "SingleControlledRYY", MQT_NAMED_BUILDER(qc::singleControlledRyy), - MQT_NAMED_BUILDER(qir::singleControlledRyy)}, + MQT_NAMED_BUILDER(qir::singleControlledRyy)}, QCToQIRAdaptiveTestCase{ "MultipleControlledRYY", MQT_NAMED_BUILDER(qc::multipleControlledRyy), - MQT_NAMED_BUILDER(qir::multipleControlledRyy)})); + MQT_NAMED_BUILDER(qir::multipleControlledRyy)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RzOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRZOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"RZ", MQT_NAMED_BUILDER(qc::rz), - MQT_NAMED_BUILDER(qir::rz)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledRZ", - MQT_NAMED_BUILDER(qc::singleControlledRz), - MQT_NAMED_BUILDER(qir::singleControlledRz)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledRZ", - MQT_NAMED_BUILDER(qc::multipleControlledRz), - MQT_NAMED_BUILDER(qir::multipleControlledRz)})); + testing::Values( + QCToQIRAdaptiveTestCase{"RZ", MQT_NAMED_BUILDER(qc::rz), + MQT_NAMED_BUILDER(qir::rz)}, + QCToQIRAdaptiveTestCase{"SingleControlledRZ", + MQT_NAMED_BUILDER(qc::singleControlledRz), + MQT_NAMED_BUILDER(qir::singleControlledRz)}, + QCToQIRAdaptiveTestCase{"MultipleControlledRZ", + MQT_NAMED_BUILDER(qc::multipleControlledRz), + MQT_NAMED_BUILDER(qir::multipleControlledRz)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RzxOp.cpp @@ -352,15 +342,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRZXOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"RZX", MQT_NAMED_BUILDER(qc::rzx), - MQT_NAMED_BUILDER(qir::rzx)}, + MQT_NAMED_BUILDER(qir::rzx)}, QCToQIRAdaptiveTestCase{ "SingleControlledRZX", MQT_NAMED_BUILDER(qc::singleControlledRzx), - MQT_NAMED_BUILDER(qir::singleControlledRzx)}, + MQT_NAMED_BUILDER(qir::singleControlledRzx)}, QCToQIRAdaptiveTestCase{ "MultipleControlledRZX", MQT_NAMED_BUILDER(qc::multipleControlledRzx), - MQT_NAMED_BUILDER(qir::multipleControlledRzx)})); + MQT_NAMED_BUILDER(qir::multipleControlledRzx)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RzzOp.cpp @@ -368,31 +358,30 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRZZOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"RZZ", MQT_NAMED_BUILDER(qc::rzz), - MQT_NAMED_BUILDER(qir::rzz)}, + MQT_NAMED_BUILDER(qir::rzz)}, QCToQIRAdaptiveTestCase{ "SingleControlledRZZ", MQT_NAMED_BUILDER(qc::singleControlledRzz), - MQT_NAMED_BUILDER(qir::singleControlledRzz)}, + MQT_NAMED_BUILDER(qir::singleControlledRzz)}, QCToQIRAdaptiveTestCase{ "MultipleControlledRZZ", MQT_NAMED_BUILDER(qc::multipleControlledRzz), - MQT_NAMED_BUILDER(qir::multipleControlledRzz)})); + MQT_NAMED_BUILDER(qir::multipleControlledRzz)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"S", MQT_NAMED_BUILDER(qc::s), - MQT_NAMED_BUILDER(qir::s)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledS", - MQT_NAMED_BUILDER(qc::singleControlledS), - MQT_NAMED_BUILDER(qir::singleControlledS)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledS", - MQT_NAMED_BUILDER(qc::multipleControlledS), - MQT_NAMED_BUILDER(qir::multipleControlledS)})); + testing::Values( + QCToQIRAdaptiveTestCase{"S", MQT_NAMED_BUILDER(qc::s), + MQT_NAMED_BUILDER(qir::s)}, + QCToQIRAdaptiveTestCase{"SingleControlledS", + MQT_NAMED_BUILDER(qc::singleControlledS), + MQT_NAMED_BUILDER(qir::singleControlledS)}, + QCToQIRAdaptiveTestCase{"MultipleControlledS", + MQT_NAMED_BUILDER(qc::multipleControlledS), + MQT_NAMED_BUILDER(qir::multipleControlledS)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SdgOp.cpp @@ -400,79 +389,77 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSdgOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"Sdg", MQT_NAMED_BUILDER(qc::sdg), - MQT_NAMED_BUILDER(qir::sdg)}, + MQT_NAMED_BUILDER(qir::sdg)}, QCToQIRAdaptiveTestCase{ "SingleControlledSdg", MQT_NAMED_BUILDER(qc::singleControlledSdg), - MQT_NAMED_BUILDER(qir::singleControlledSdg)}, + MQT_NAMED_BUILDER(qir::singleControlledSdg)}, QCToQIRAdaptiveTestCase{ "MultipleControlledSdg", MQT_NAMED_BUILDER(qc::multipleControlledSdg), - MQT_NAMED_BUILDER(qir::multipleControlledSdg)})); + MQT_NAMED_BUILDER(qir::multipleControlledSdg)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SwapOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSWAPOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"SWAP", MQT_NAMED_BUILDER(qc::swap), - MQT_NAMED_BUILDER(qir::swap)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledSWAP", MQT_NAMED_BUILDER(qc::singleControlledSwap), - MQT_NAMED_BUILDER(qir::singleControlledSwap)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledSWAP", - MQT_NAMED_BUILDER(qc::multipleControlledSwap), - MQT_NAMED_BUILDER(qir::multipleControlledSwap)})); + testing::Values(QCToQIRAdaptiveTestCase{"SWAP", MQT_NAMED_BUILDER(qc::swap), + MQT_NAMED_BUILDER(qir::swap)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledSWAP", + MQT_NAMED_BUILDER(qc::singleControlledSwap), + MQT_NAMED_BUILDER(qir::singleControlledSwap)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledSWAP", + MQT_NAMED_BUILDER(qc::multipleControlledSwap), + MQT_NAMED_BUILDER(qir::multipleControlledSwap)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSXOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"SX", MQT_NAMED_BUILDER(qc::sx), - MQT_NAMED_BUILDER(qir::sx)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledSX", - MQT_NAMED_BUILDER(qc::singleControlledSx), - MQT_NAMED_BUILDER(qir::singleControlledSx)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledSX", - MQT_NAMED_BUILDER(qc::multipleControlledSx), - MQT_NAMED_BUILDER(qir::multipleControlledSx)})); + testing::Values( + QCToQIRAdaptiveTestCase{"SX", MQT_NAMED_BUILDER(qc::sx), + MQT_NAMED_BUILDER(qir::sx)}, + QCToQIRAdaptiveTestCase{"SingleControlledSX", + MQT_NAMED_BUILDER(qc::singleControlledSx), + MQT_NAMED_BUILDER(qir::singleControlledSx)}, + QCToQIRAdaptiveTestCase{"MultipleControlledSX", + MQT_NAMED_BUILDER(qc::multipleControlledSx), + MQT_NAMED_BUILDER(qir::multipleControlledSx)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SxdgOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSXdgOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"SXdg", MQT_NAMED_BUILDER(qc::sxdg), - MQT_NAMED_BUILDER(qir::sxdg)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledSXdg", MQT_NAMED_BUILDER(qc::singleControlledSxdg), - MQT_NAMED_BUILDER(qir::singleControlledSxdg)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledSXdg", - MQT_NAMED_BUILDER(qc::multipleControlledSxdg), - MQT_NAMED_BUILDER(qir::multipleControlledSxdg)})); + testing::Values(QCToQIRAdaptiveTestCase{"SXdg", MQT_NAMED_BUILDER(qc::sxdg), + MQT_NAMED_BUILDER(qir::sxdg)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledSXdg", + MQT_NAMED_BUILDER(qc::singleControlledSxdg), + MQT_NAMED_BUILDER(qir::singleControlledSxdg)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledSXdg", + MQT_NAMED_BUILDER(qc::multipleControlledSxdg), + MQT_NAMED_BUILDER(qir::multipleControlledSxdg)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/TOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveTOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"T", MQT_NAMED_BUILDER(qc::t_), - MQT_NAMED_BUILDER(qir::t_)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledT", - MQT_NAMED_BUILDER(qc::singleControlledT), - MQT_NAMED_BUILDER(qir::singleControlledT)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledT", - MQT_NAMED_BUILDER(qc::multipleControlledT), - MQT_NAMED_BUILDER(qir::multipleControlledT)})); + testing::Values( + QCToQIRAdaptiveTestCase{"T", MQT_NAMED_BUILDER(qc::t_), + MQT_NAMED_BUILDER(qir::t_)}, + QCToQIRAdaptiveTestCase{"SingleControlledT", + MQT_NAMED_BUILDER(qc::singleControlledT), + MQT_NAMED_BUILDER(qir::singleControlledT)}, + QCToQIRAdaptiveTestCase{"MultipleControlledT", + MQT_NAMED_BUILDER(qc::multipleControlledT), + MQT_NAMED_BUILDER(qir::multipleControlledT)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/TdgOp.cpp @@ -480,129 +467,124 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveTdgOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"Tdg", MQT_NAMED_BUILDER(qc::tdg), - MQT_NAMED_BUILDER(qir::tdg)}, + MQT_NAMED_BUILDER(qir::tdg)}, QCToQIRAdaptiveTestCase{ "SingleControlledTdg", MQT_NAMED_BUILDER(qc::singleControlledTdg), - MQT_NAMED_BUILDER(qir::singleControlledTdg)}, + MQT_NAMED_BUILDER(qir::singleControlledTdg)}, QCToQIRAdaptiveTestCase{ "MultipleControlledTdg", MQT_NAMED_BUILDER(qc::multipleControlledTdg), - MQT_NAMED_BUILDER(qir::multipleControlledTdg)})); + MQT_NAMED_BUILDER(qir::multipleControlledTdg)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/U2Op.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveU2OpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"U2", MQT_NAMED_BUILDER(qc::u2), - MQT_NAMED_BUILDER(qir::u2)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledU2", - MQT_NAMED_BUILDER(qc::singleControlledU2), - MQT_NAMED_BUILDER(qir::singleControlledU2)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledU2", - MQT_NAMED_BUILDER(qc::multipleControlledU2), - MQT_NAMED_BUILDER(qir::multipleControlledU2)})); + testing::Values( + QCToQIRAdaptiveTestCase{"U2", MQT_NAMED_BUILDER(qc::u2), + MQT_NAMED_BUILDER(qir::u2)}, + QCToQIRAdaptiveTestCase{"SingleControlledU2", + MQT_NAMED_BUILDER(qc::singleControlledU2), + MQT_NAMED_BUILDER(qir::singleControlledU2)}, + QCToQIRAdaptiveTestCase{"MultipleControlledU2", + MQT_NAMED_BUILDER(qc::multipleControlledU2), + MQT_NAMED_BUILDER(qir::multipleControlledU2)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/UOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveUOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"U", MQT_NAMED_BUILDER(qc::u), - MQT_NAMED_BUILDER(qir::u)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledU", - MQT_NAMED_BUILDER(qc::singleControlledU), - MQT_NAMED_BUILDER(qir::singleControlledU)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledU", - MQT_NAMED_BUILDER(qc::multipleControlledU), - MQT_NAMED_BUILDER(qir::multipleControlledU)})); + testing::Values( + QCToQIRAdaptiveTestCase{"U", MQT_NAMED_BUILDER(qc::u), + MQT_NAMED_BUILDER(qir::u)}, + QCToQIRAdaptiveTestCase{"SingleControlledU", + MQT_NAMED_BUILDER(qc::singleControlledU), + MQT_NAMED_BUILDER(qir::singleControlledU)}, + QCToQIRAdaptiveTestCase{"MultipleControlledU", + MQT_NAMED_BUILDER(qc::multipleControlledU), + MQT_NAMED_BUILDER(qir::multipleControlledU)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/XOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveXOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"X", MQT_NAMED_BUILDER(qc::x), - MQT_NAMED_BUILDER(qir::x)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledX", - MQT_NAMED_BUILDER(qc::singleControlledX), - MQT_NAMED_BUILDER(qir::singleControlledX)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledX", - MQT_NAMED_BUILDER(qc::multipleControlledX), - MQT_NAMED_BUILDER(qir::multipleControlledX)})); + testing::Values( + QCToQIRAdaptiveTestCase{"X", MQT_NAMED_BUILDER(qc::x), + MQT_NAMED_BUILDER(qir::x)}, + QCToQIRAdaptiveTestCase{"SingleControlledX", + MQT_NAMED_BUILDER(qc::singleControlledX), + MQT_NAMED_BUILDER(qir::singleControlledX)}, + QCToQIRAdaptiveTestCase{"MultipleControlledX", + MQT_NAMED_BUILDER(qc::multipleControlledX), + MQT_NAMED_BUILDER(qir::multipleControlledX)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/XxMinusYyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveXXMinusYYOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"XXMinusYY", MQT_NAMED_BUILDER(qc::xxMinusYY), - MQT_NAMED_BUILDER(qir::xxMinusYY)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledXXMinusYY", - MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), - MQT_NAMED_BUILDER(qir::singleControlledXxMinusYY)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledXXMinusYY", - MQT_NAMED_BUILDER(qc::multipleControlledXxMinusYY), - MQT_NAMED_BUILDER(qir::multipleControlledXxMinusYY)})); + testing::Values(QCToQIRAdaptiveTestCase{"XXMinusYY", + MQT_NAMED_BUILDER(qc::xxMinusYY), + MQT_NAMED_BUILDER(qir::xxMinusYY)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledXXMinusYY", + MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), + MQT_NAMED_BUILDER(qir::singleControlledXxMinusYY)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledXXMinusYY", + MQT_NAMED_BUILDER(qc::multipleControlledXxMinusYY), + MQT_NAMED_BUILDER(qir::multipleControlledXxMinusYY)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/XxPlusYyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveXXPlusYYOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"XXPlusYY", MQT_NAMED_BUILDER(qc::xxPlusYY), - MQT_NAMED_BUILDER(qir::xxPlusYY)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledXXPlusYY", - MQT_NAMED_BUILDER(qc::singleControlledXxPlusYY), - MQT_NAMED_BUILDER(qir::singleControlledXxPlusYY)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledXXPlusYY", - MQT_NAMED_BUILDER(qc::multipleControlledXxPlusYY), - MQT_NAMED_BUILDER(qir::multipleControlledXxPlusYY)})); + testing::Values(QCToQIRAdaptiveTestCase{"XXPlusYY", + MQT_NAMED_BUILDER(qc::xxPlusYY), + MQT_NAMED_BUILDER(qir::xxPlusYY)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledXXPlusYY", + MQT_NAMED_BUILDER(qc::singleControlledXxPlusYY), + MQT_NAMED_BUILDER(qir::singleControlledXxPlusYY)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledXXPlusYY", + MQT_NAMED_BUILDER(qc::multipleControlledXxPlusYY), + MQT_NAMED_BUILDER(qir::multipleControlledXxPlusYY)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/YOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveYOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"Y", MQT_NAMED_BUILDER(qc::y), - MQT_NAMED_BUILDER(qir::y)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledY", - MQT_NAMED_BUILDER(qc::singleControlledY), - MQT_NAMED_BUILDER(qir::singleControlledY)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledY", - MQT_NAMED_BUILDER(qc::multipleControlledY), - MQT_NAMED_BUILDER(qir::multipleControlledY)})); + testing::Values( + QCToQIRAdaptiveTestCase{"Y", MQT_NAMED_BUILDER(qc::y), + MQT_NAMED_BUILDER(qir::y)}, + QCToQIRAdaptiveTestCase{"SingleControlledY", + MQT_NAMED_BUILDER(qc::singleControlledY), + MQT_NAMED_BUILDER(qir::singleControlledY)}, + QCToQIRAdaptiveTestCase{"MultipleControlledY", + MQT_NAMED_BUILDER(qc::multipleControlledY), + MQT_NAMED_BUILDER(qir::multipleControlledY)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/ZOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveZOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"Z", MQT_NAMED_BUILDER(qc::z), - MQT_NAMED_BUILDER(qir::z)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledZ", - MQT_NAMED_BUILDER(qc::singleControlledZ), - MQT_NAMED_BUILDER(qir::singleControlledZ)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledZ", - MQT_NAMED_BUILDER(qc::multipleControlledZ), - MQT_NAMED_BUILDER(qir::multipleControlledZ)})); + testing::Values( + QCToQIRAdaptiveTestCase{"Z", MQT_NAMED_BUILDER(qc::z), + MQT_NAMED_BUILDER(qir::z)}, + QCToQIRAdaptiveTestCase{"SingleControlledZ", + MQT_NAMED_BUILDER(qc::singleControlledZ), + MQT_NAMED_BUILDER(qir::singleControlledZ)}, + QCToQIRAdaptiveTestCase{"MultipleControlledZ", + MQT_NAMED_BUILDER(qc::multipleControlledZ), + MQT_NAMED_BUILDER(qir::multipleControlledZ)})); /// @} /// \name QCToQIRAdaptive/Operations/MeasureOp.cpp @@ -613,15 +595,15 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveTestCase{ "SingleMeasurementToSingleBit", MQT_NAMED_BUILDER(qc::singleMeasurementToSingleBit), - MQT_NAMED_BUILDER(qir::singleMeasurementToSingleBit)}, + MQT_NAMED_BUILDER(qir::singleMeasurementToSingleBit)}, QCToQIRAdaptiveTestCase{ "RepeatedMeasurementToSameBit", MQT_NAMED_BUILDER(qc::repeatedMeasurementToSameBit), - MQT_NAMED_BUILDER(qir::repeatedMeasurementToSameBit)}, + MQT_NAMED_BUILDER(qir::repeatedMeasurementToSameBit)}, QCToQIRAdaptiveTestCase{ "RepeatedMeasurementToDifferentBits", MQT_NAMED_BUILDER(qc::repeatedMeasurementToDifferentBits), - MQT_NAMED_BUILDER(qir::repeatedMeasurementToDifferentBits)}, + MQT_NAMED_BUILDER(qir::repeatedMeasurementToDifferentBits)}, QCToQIRAdaptiveTestCase{ "MultipleClassicalRegistersAndMeasurements", MQT_NAMED_BUILDER(qc::multipleClassicalRegistersAndMeasurements), @@ -630,7 +612,7 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveTestCase{ "MeasurementWithoutRegisters", MQT_NAMED_BUILDER(qc::measurementWithoutRegisters), - MQT_NAMED_BUILDER(qir::measurementWithoutRegisters)})); + MQT_NAMED_BUILDER(qir::measurementWithoutRegisters)})); /// @} /// \name QCToQIRAdaptive/Operations/ResetOp.cpp @@ -638,29 +620,28 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveResetOpTest, QCToQIRAdaptiveTest, testing::Values( - QCToQIRAdaptiveTestCase{ - "ResetQubitWithoutOp", MQT_NAMED_BUILDER(qc::resetQubitWithoutOp), - MQT_NAMED_BUILDER(qir::resetQubitWithoutOp)}, + QCToQIRAdaptiveTestCase{"ResetQubitWithoutOp", + MQT_NAMED_BUILDER(qc::resetQubitWithoutOp), + MQT_NAMED_BUILDER(qir::resetQubitWithoutOp)}, QCToQIRAdaptiveTestCase{ "ResetMultipleQubitsWithoutOp", MQT_NAMED_BUILDER(qc::resetMultipleQubitsWithoutOp), - MQT_NAMED_BUILDER(qir::resetMultipleQubitsWithoutOp)}, - QCToQIRAdaptiveTestCase{ - "RepeatedResetWithoutOp", - MQT_NAMED_BUILDER(qc::repeatedResetWithoutOp), - MQT_NAMED_BUILDER(qir::repeatedResetWithoutOp)}, + MQT_NAMED_BUILDER(qir::resetMultipleQubitsWithoutOp)}, + QCToQIRAdaptiveTestCase{"RepeatedResetWithoutOp", + MQT_NAMED_BUILDER(qc::repeatedResetWithoutOp), + MQT_NAMED_BUILDER(qir::repeatedResetWithoutOp)}, QCToQIRAdaptiveTestCase{ "ResetQubitAfterSingleOp", MQT_NAMED_BUILDER(qc::resetQubitAfterSingleOp), - MQT_NAMED_BUILDER(qir::resetQubitAfterSingleOp)}, + MQT_NAMED_BUILDER(qir::resetQubitAfterSingleOp)}, QCToQIRAdaptiveTestCase{ "ResetMultipleQubitsAfterSingleOp", MQT_NAMED_BUILDER(qc::resetMultipleQubitsAfterSingleOp), - MQT_NAMED_BUILDER(qir::resetMultipleQubitsAfterSingleOp)}, + MQT_NAMED_BUILDER(qir::resetMultipleQubitsAfterSingleOp)}, QCToQIRAdaptiveTestCase{ "RepeatedResetAfterSingleOp", MQT_NAMED_BUILDER(qc::repeatedResetAfterSingleOp), - MQT_NAMED_BUILDER(qir::repeatedResetAfterSingleOp)})); + MQT_NAMED_BUILDER(qir::repeatedResetAfterSingleOp)})); /// @} /// \name QCToQIRAdaptive/QubitManagement/QubitManagement.cpp @@ -669,21 +650,21 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveQubitManagementTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"AllocQubit", MQT_NAMED_BUILDER(qc::allocQubit), - MQT_NAMED_BUILDER(qir::allocQubit)}, - QCToQIRAdaptiveTestCase{ - "AllocQubitRegister", MQT_NAMED_BUILDER(qc::allocQubitRegister), - MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(qir::allocQubit)}, + QCToQIRAdaptiveTestCase{"AllocQubitRegister", + MQT_NAMED_BUILDER(qc::allocQubitRegister), + MQT_NAMED_BUILDER(qir::allocQubitRegister)}, QCToQIRAdaptiveTestCase{ "AllocMultipleQubitRegisters", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegisters), - MQT_NAMED_BUILDER(qir::allocMultipleQubitRegisters)}, + MQT_NAMED_BUILDER(qir::allocMultipleQubitRegisters)}, QCToQIRAdaptiveTestCase{ "AllocMultipleQubitRegistersWithOps", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegistersWithOps), - MQT_NAMED_BUILDER(qir::allocMultipleQubitRegistersWithOps)}, - QCToQIRAdaptiveTestCase{ - "AllocLargeRegister", MQT_NAMED_BUILDER(qc::allocLargeRegister), - MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(qir::allocMultipleQubitRegistersWithOps)}, + QCToQIRAdaptiveTestCase{"AllocLargeRegister", + MQT_NAMED_BUILDER(qc::allocLargeRegister), + MQT_NAMED_BUILDER(qir::allocQubitRegister)}, QCToQIRAdaptiveTestCase{"StaticQubits", MQT_NAMED_BUILDER(qc::staticQubits), MQT_NAMED_BUILDER(qir::staticQubits)}, @@ -706,7 +687,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(qir::staticQubitsWithInv)}, QCToQIRAdaptiveTestCase{"AllocDeallocPair", MQT_NAMED_BUILDER(qc::allocDeallocPair), - MQT_NAMED_BUILDER(qir::emptyQIR)})); + MQT_NAMED_BUILDER(qir::emptyQIR)})); /// @} /// \name QCToQIRAdaptive/Operations/IfOp.cpp @@ -715,15 +696,15 @@ INSTANTIATE_TEST_SUITE_P( SCFIfOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"SimpleIfOp", MQT_NAMED_BUILDER(qc::simpleIf), - MQT_NAMED_BUILDER(qir::simpleIf)}, + MQT_NAMED_BUILDER(qir::simpleIf)}, QCToQIRAdaptiveTestCase{"IfTwoQubits", MQT_NAMED_BUILDER(qc::ifTwoQubits), - MQT_NAMED_BUILDER(qir::ifTwoQubits)}, + MQT_NAMED_BUILDER(qir::ifTwoQubits)}, QCToQIRAdaptiveTestCase{"IfElse", MQT_NAMED_BUILDER(qc::ifElse), - MQT_NAMED_BUILDER(qir::ifElse)}, - QCToQIRAdaptiveTestCase{ - "NestedIfOpForLoop", MQT_NAMED_BUILDER(qc::nestedIfOpForLoop), - MQT_NAMED_BUILDER(qir::nestedIfOpForLoop)})); + MQT_NAMED_BUILDER(qir::ifElse)}, + QCToQIRAdaptiveTestCase{"NestedIfOpForLoop", + MQT_NAMED_BUILDER(qc::nestedIfOpForLoop), + MQT_NAMED_BUILDER(qir::nestedIfOpForLoop)})); /// @} /// \name QCToQIRAdaptive/Operations/WhileOp.cpp @@ -731,12 +712,12 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( SCFWhileOpTest, QCToQIRAdaptiveTest, testing::Values( - QCToQIRAdaptiveTestCase{ - "SimpleWhile", MQT_NAMED_BUILDER(qc::simpleWhileReset), - MQT_NAMED_BUILDER(qir::simpleWhileReset)}, - QCToQIRAdaptiveTestCase{ - "SimpleDoWhile", MQT_NAMED_BUILDER(qc::simpleDoWhileReset), - MQT_NAMED_BUILDER(qir::simpleDoWhileReset)})); + QCToQIRAdaptiveTestCase{"SimpleWhile", + MQT_NAMED_BUILDER(qc::simpleWhileReset), + MQT_NAMED_BUILDER(qir::simpleWhileReset)}, + QCToQIRAdaptiveTestCase{"SimpleDoWhile", + MQT_NAMED_BUILDER(qc::simpleDoWhileReset), + MQT_NAMED_BUILDER(qir::simpleDoWhileReset)})); /// \name QCToQIRAdaptive/Operations/ForOp.cpp /// @{ @@ -745,13 +726,13 @@ INSTANTIATE_TEST_SUITE_P( testing::Values( QCToQIRAdaptiveTestCase{"SimpleForLoop", MQT_NAMED_BUILDER(qc::simpleForLoop), - MQT_NAMED_BUILDER(qir::simpleForLoop)}, - QCToQIRAdaptiveTestCase{ - "NestedForLoopIfOp", MQT_NAMED_BUILDER(qc::nestedForLoopIfOp), - MQT_NAMED_BUILDER(qir::nestedForLoopIfOp)}, - QCToQIRAdaptiveTestCase{ - "NestedForLoopWhileOp", MQT_NAMED_BUILDER(qc::nestedForLoopWhileOp), - MQT_NAMED_BUILDER(qir::nestedForLoopWhileOp)}, + MQT_NAMED_BUILDER(qir::simpleForLoop)}, + QCToQIRAdaptiveTestCase{"NestedForLoopIfOp", + MQT_NAMED_BUILDER(qc::nestedForLoopIfOp), + MQT_NAMED_BUILDER(qir::nestedForLoopIfOp)}, + QCToQIRAdaptiveTestCase{"NestedForLoopWhileOp", + MQT_NAMED_BUILDER(qc::nestedForLoopWhileOp), + MQT_NAMED_BUILDER(qir::nestedForLoopWhileOp)}, QCToQIRAdaptiveTestCase{ "nestedForLoopCtrlOpWithSeparateQubit", MQT_NAMED_BUILDER(qc::nestedForLoopCtrlOpWithSeparateQubit), @@ -768,5 +749,5 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(QCToQIRCtrlOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{ "NestedCtrlTwo", MQT_NAMED_BUILDER(qc::ctrlTwo), - MQT_NAMED_BUILDER(qir::ctrlTwo)})); + MQT_NAMED_BUILDER(qir::ctrlTwo)})); /// @} diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp index 15f7fa0177..9f08355a93 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp @@ -126,49 +126,46 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseBarrierOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Barrier", MQT_NAMED_BUILDER(qc::barrier), - MQT_NAMED_BUILDER(qir::alloc1QubitRegister)}, + MQT_NAMED_BUILDER(qir::alloc1QubitRegister)}, QCToQIRBaseTestCase{"BarrierTwoQubits", MQT_NAMED_BUILDER(qc::barrierTwoQubits), - MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(qir::allocQubitRegister)}, QCToQIRBaseTestCase{"BarrierMultipleQubits", MQT_NAMED_BUILDER(qc::barrierMultipleQubits), - MQT_NAMED_BUILDER(qir::alloc3QubitRegister)}, - QCToQIRBaseTestCase{ - "SingleControlledBarrier", - MQT_NAMED_BUILDER(qc::singleControlledBarrier), - MQT_NAMED_BUILDER(qir::allocQubitRegister)})); + MQT_NAMED_BUILDER(qir::alloc3QubitRegister)}, + QCToQIRBaseTestCase{"SingleControlledBarrier", + MQT_NAMED_BUILDER(qc::singleControlledBarrier), + MQT_NAMED_BUILDER(qir::allocQubitRegister)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/DcxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseDCXOpTest, QCToQIRBaseTest, - testing::Values(QCToQIRBaseTestCase{"DCX", MQT_NAMED_BUILDER(qc::dcx), - MQT_NAMED_BUILDER(qir::dcx)}, - QCToQIRBaseTestCase{ - "SingleControlledDCX", - MQT_NAMED_BUILDER(qc::singleControlledDcx), - MQT_NAMED_BUILDER(qir::singleControlledDcx)}, - QCToQIRBaseTestCase{ - "MultipleControlledDCX", - MQT_NAMED_BUILDER(qc::multipleControlledDcx), - MQT_NAMED_BUILDER(qir::multipleControlledDcx)})); + testing::Values( + QCToQIRBaseTestCase{"DCX", MQT_NAMED_BUILDER(qc::dcx), + MQT_NAMED_BUILDER(qir::dcx)}, + QCToQIRBaseTestCase{"SingleControlledDCX", + MQT_NAMED_BUILDER(qc::singleControlledDcx), + MQT_NAMED_BUILDER(qir::singleControlledDcx)}, + QCToQIRBaseTestCase{"MultipleControlledDCX", + MQT_NAMED_BUILDER(qc::multipleControlledDcx), + MQT_NAMED_BUILDER(qir::multipleControlledDcx)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/EcrOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseECROpTest, QCToQIRBaseTest, - testing::Values(QCToQIRBaseTestCase{"ECR", MQT_NAMED_BUILDER(qc::ecr), - MQT_NAMED_BUILDER(qir::ecr)}, - QCToQIRBaseTestCase{ - "SingleControlledECR", - MQT_NAMED_BUILDER(qc::singleControlledEcr), - MQT_NAMED_BUILDER(qir::singleControlledEcr)}, - QCToQIRBaseTestCase{ - "MultipleControlledECR", - MQT_NAMED_BUILDER(qc::multipleControlledEcr), - MQT_NAMED_BUILDER(qir::multipleControlledEcr)})); + testing::Values( + QCToQIRBaseTestCase{"ECR", MQT_NAMED_BUILDER(qc::ecr), + MQT_NAMED_BUILDER(qir::ecr)}, + QCToQIRBaseTestCase{"SingleControlledECR", + MQT_NAMED_BUILDER(qc::singleControlledEcr), + MQT_NAMED_BUILDER(qir::singleControlledEcr)}, + QCToQIRBaseTestCase{"MultipleControlledECR", + MQT_NAMED_BUILDER(qc::multipleControlledEcr), + MQT_NAMED_BUILDER(qir::multipleControlledEcr)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/GphaseOp.cpp @@ -176,7 +173,7 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(QCToQIRBaseGPhaseOpTest, QCToQIRBaseTest, testing::Values(QCToQIRBaseTestCase{ "GlobalPhase", MQT_NAMED_BUILDER(qc::globalPhase), - MQT_NAMED_BUILDER(qir::globalPhase)})); + MQT_NAMED_BUILDER(qir::globalPhase)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/HOp.cpp @@ -185,16 +182,16 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseHOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"H", MQT_NAMED_BUILDER(qc::h), - MQT_NAMED_BUILDER(qir::h)}, + MQT_NAMED_BUILDER(qir::h)}, QCToQIRBaseTestCase{"SingleControlledH", MQT_NAMED_BUILDER(qc::singleControlledH), - MQT_NAMED_BUILDER(qir::singleControlledH)}, + MQT_NAMED_BUILDER(qir::singleControlledH)}, QCToQIRBaseTestCase{"MultipleControlledH", MQT_NAMED_BUILDER(qc::multipleControlledH), - MQT_NAMED_BUILDER(qir::multipleControlledH)}, + MQT_NAMED_BUILDER(qir::multipleControlledH)}, QCToQIRBaseTestCase{"HWithoutRegister", MQT_NAMED_BUILDER(qc::hWithoutRegister), - MQT_NAMED_BUILDER(qir::hWithoutRegister)})); + MQT_NAMED_BUILDER(qir::hWithoutRegister)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/IdOp.cpp @@ -203,15 +200,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseIDOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Identity", MQT_NAMED_BUILDER(qc::identity), - MQT_NAMED_BUILDER(qir::identity)}, - QCToQIRBaseTestCase{ - "SingleControlledIdentity", - MQT_NAMED_BUILDER(qc::singleControlledIdentity), - MQT_NAMED_BUILDER(qir::twoQubitsOneIdentity)}, - QCToQIRBaseTestCase{ - "MultipleControlledIdentity", - MQT_NAMED_BUILDER(qc::multipleControlledIdentity), - MQT_NAMED_BUILDER(qir::threeQubitsOneIdentity)})); + MQT_NAMED_BUILDER(qir::identity)}, + QCToQIRBaseTestCase{"SingleControlledIdentity", + MQT_NAMED_BUILDER(qc::singleControlledIdentity), + MQT_NAMED_BUILDER(qir::twoQubitsOneIdentity)}, + QCToQIRBaseTestCase{"MultipleControlledIdentity", + MQT_NAMED_BUILDER(qc::multipleControlledIdentity), + MQT_NAMED_BUILDER(qir::threeQubitsOneIdentity)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/IswapOp.cpp @@ -220,15 +215,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseiSWAPOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"iSWAP", MQT_NAMED_BUILDER(qc::iswap), - MQT_NAMED_BUILDER(qir::iswap)}, - QCToQIRBaseTestCase{ - "SingleControllediSWAP", - MQT_NAMED_BUILDER(qc::singleControlledIswap), - MQT_NAMED_BUILDER(qir::singleControlledIswap)}, - QCToQIRBaseTestCase{ - "MultipleControllediSWAP", - MQT_NAMED_BUILDER(qc::multipleControlledIswap), - MQT_NAMED_BUILDER(qir::multipleControlledIswap)})); + MQT_NAMED_BUILDER(qir::iswap)}, + QCToQIRBaseTestCase{"SingleControllediSWAP", + MQT_NAMED_BUILDER(qc::singleControlledIswap), + MQT_NAMED_BUILDER(qir::singleControlledIswap)}, + QCToQIRBaseTestCase{"MultipleControllediSWAP", + MQT_NAMED_BUILDER(qc::multipleControlledIswap), + MQT_NAMED_BUILDER(qir::multipleControlledIswap)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/POp.cpp @@ -237,13 +230,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBasePOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"P", MQT_NAMED_BUILDER(qc::p), - MQT_NAMED_BUILDER(qir::p)}, + MQT_NAMED_BUILDER(qir::p)}, QCToQIRBaseTestCase{"SingleControlledP", MQT_NAMED_BUILDER(qc::singleControlledP), - MQT_NAMED_BUILDER(qir::singleControlledP)}, - QCToQIRBaseTestCase{ - "MultipleControlledP", MQT_NAMED_BUILDER(qc::multipleControlledP), - MQT_NAMED_BUILDER(qir::multipleControlledP)})); + MQT_NAMED_BUILDER(qir::singleControlledP)}, + QCToQIRBaseTestCase{"MultipleControlledP", + MQT_NAMED_BUILDER(qc::multipleControlledP), + MQT_NAMED_BUILDER(qir::multipleControlledP)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/ROp.cpp @@ -252,13 +245,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseROpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"R", MQT_NAMED_BUILDER(qc::r), - MQT_NAMED_BUILDER(qir::r)}, + MQT_NAMED_BUILDER(qir::r)}, QCToQIRBaseTestCase{"SingleControlledR", MQT_NAMED_BUILDER(qc::singleControlledR), - MQT_NAMED_BUILDER(qir::singleControlledR)}, - QCToQIRBaseTestCase{ - "MultipleControlledR", MQT_NAMED_BUILDER(qc::multipleControlledR), - MQT_NAMED_BUILDER(qir::multipleControlledR)})); + MQT_NAMED_BUILDER(qir::singleControlledR)}, + QCToQIRBaseTestCase{"MultipleControlledR", + MQT_NAMED_BUILDER(qc::multipleControlledR), + MQT_NAMED_BUILDER(qir::multipleControlledR)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RxOp.cpp @@ -267,29 +260,28 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRXOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RX", MQT_NAMED_BUILDER(qc::rx), - MQT_NAMED_BUILDER(qir::rx)}, + MQT_NAMED_BUILDER(qir::rx)}, QCToQIRBaseTestCase{"SingleControlledRX", MQT_NAMED_BUILDER(qc::singleControlledRx), - MQT_NAMED_BUILDER(qir::singleControlledRx)}, - QCToQIRBaseTestCase{ - "MultipleControlledRX", MQT_NAMED_BUILDER(qc::multipleControlledRx), - MQT_NAMED_BUILDER(qir::multipleControlledRx)})); + MQT_NAMED_BUILDER(qir::singleControlledRx)}, + QCToQIRBaseTestCase{"MultipleControlledRX", + MQT_NAMED_BUILDER(qc::multipleControlledRx), + MQT_NAMED_BUILDER(qir::multipleControlledRx)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RxxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRXXOpTest, QCToQIRBaseTest, - testing::Values(QCToQIRBaseTestCase{"RXX", MQT_NAMED_BUILDER(qc::rxx), - MQT_NAMED_BUILDER(qir::rxx)}, - QCToQIRBaseTestCase{ - "SingleControlledRXX", - MQT_NAMED_BUILDER(qc::singleControlledRxx), - MQT_NAMED_BUILDER(qir::singleControlledRxx)}, - QCToQIRBaseTestCase{ - "MultipleControlledRXX", - MQT_NAMED_BUILDER(qc::multipleControlledRxx), - MQT_NAMED_BUILDER(qir::multipleControlledRxx)})); + testing::Values( + QCToQIRBaseTestCase{"RXX", MQT_NAMED_BUILDER(qc::rxx), + MQT_NAMED_BUILDER(qir::rxx)}, + QCToQIRBaseTestCase{"SingleControlledRXX", + MQT_NAMED_BUILDER(qc::singleControlledRxx), + MQT_NAMED_BUILDER(qir::singleControlledRxx)}, + QCToQIRBaseTestCase{"MultipleControlledRXX", + MQT_NAMED_BUILDER(qc::multipleControlledRxx), + MQT_NAMED_BUILDER(qir::multipleControlledRxx)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RyOp.cpp @@ -298,29 +290,28 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RY", MQT_NAMED_BUILDER(qc::ry), - MQT_NAMED_BUILDER(qir::ry)}, + MQT_NAMED_BUILDER(qir::ry)}, QCToQIRBaseTestCase{"SingleControlledRY", MQT_NAMED_BUILDER(qc::singleControlledRy), - MQT_NAMED_BUILDER(qir::singleControlledRy)}, - QCToQIRBaseTestCase{ - "MultipleControlledRY", MQT_NAMED_BUILDER(qc::multipleControlledRy), - MQT_NAMED_BUILDER(qir::multipleControlledRy)})); + MQT_NAMED_BUILDER(qir::singleControlledRy)}, + QCToQIRBaseTestCase{"MultipleControlledRY", + MQT_NAMED_BUILDER(qc::multipleControlledRy), + MQT_NAMED_BUILDER(qir::multipleControlledRy)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RyyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRYYOpTest, QCToQIRBaseTest, - testing::Values(QCToQIRBaseTestCase{"RYY", MQT_NAMED_BUILDER(qc::ryy), - MQT_NAMED_BUILDER(qir::ryy)}, - QCToQIRBaseTestCase{ - "SingleControlledRYY", - MQT_NAMED_BUILDER(qc::singleControlledRyy), - MQT_NAMED_BUILDER(qir::singleControlledRyy)}, - QCToQIRBaseTestCase{ - "MultipleControlledRYY", - MQT_NAMED_BUILDER(qc::multipleControlledRyy), - MQT_NAMED_BUILDER(qir::multipleControlledRyy)})); + testing::Values( + QCToQIRBaseTestCase{"RYY", MQT_NAMED_BUILDER(qc::ryy), + MQT_NAMED_BUILDER(qir::ryy)}, + QCToQIRBaseTestCase{"SingleControlledRYY", + MQT_NAMED_BUILDER(qc::singleControlledRyy), + MQT_NAMED_BUILDER(qir::singleControlledRyy)}, + QCToQIRBaseTestCase{"MultipleControlledRYY", + MQT_NAMED_BUILDER(qc::multipleControlledRyy), + MQT_NAMED_BUILDER(qir::multipleControlledRyy)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RzOp.cpp @@ -329,45 +320,43 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRZOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RZ", MQT_NAMED_BUILDER(qc::rz), - MQT_NAMED_BUILDER(qir::rz)}, + MQT_NAMED_BUILDER(qir::rz)}, QCToQIRBaseTestCase{"SingleControlledRZ", MQT_NAMED_BUILDER(qc::singleControlledRz), - MQT_NAMED_BUILDER(qir::singleControlledRz)}, - QCToQIRBaseTestCase{ - "MultipleControlledRZ", MQT_NAMED_BUILDER(qc::multipleControlledRz), - MQT_NAMED_BUILDER(qir::multipleControlledRz)})); + MQT_NAMED_BUILDER(qir::singleControlledRz)}, + QCToQIRBaseTestCase{"MultipleControlledRZ", + MQT_NAMED_BUILDER(qc::multipleControlledRz), + MQT_NAMED_BUILDER(qir::multipleControlledRz)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RzxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRZXOpTest, QCToQIRBaseTest, - testing::Values(QCToQIRBaseTestCase{"RZX", MQT_NAMED_BUILDER(qc::rzx), - MQT_NAMED_BUILDER(qir::rzx)}, - QCToQIRBaseTestCase{ - "SingleControlledRZX", - MQT_NAMED_BUILDER(qc::singleControlledRzx), - MQT_NAMED_BUILDER(qir::singleControlledRzx)}, - QCToQIRBaseTestCase{ - "MultipleControlledRZX", - MQT_NAMED_BUILDER(qc::multipleControlledRzx), - MQT_NAMED_BUILDER(qir::multipleControlledRzx)})); + testing::Values( + QCToQIRBaseTestCase{"RZX", MQT_NAMED_BUILDER(qc::rzx), + MQT_NAMED_BUILDER(qir::rzx)}, + QCToQIRBaseTestCase{"SingleControlledRZX", + MQT_NAMED_BUILDER(qc::singleControlledRzx), + MQT_NAMED_BUILDER(qir::singleControlledRzx)}, + QCToQIRBaseTestCase{"MultipleControlledRZX", + MQT_NAMED_BUILDER(qc::multipleControlledRzx), + MQT_NAMED_BUILDER(qir::multipleControlledRzx)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RzzOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRZZOpTest, QCToQIRBaseTest, - testing::Values(QCToQIRBaseTestCase{"RZZ", MQT_NAMED_BUILDER(qc::rzz), - MQT_NAMED_BUILDER(qir::rzz)}, - QCToQIRBaseTestCase{ - "SingleControlledRZZ", - MQT_NAMED_BUILDER(qc::singleControlledRzz), - MQT_NAMED_BUILDER(qir::singleControlledRzz)}, - QCToQIRBaseTestCase{ - "MultipleControlledRZZ", - MQT_NAMED_BUILDER(qc::multipleControlledRzz), - MQT_NAMED_BUILDER(qir::multipleControlledRzz)})); + testing::Values( + QCToQIRBaseTestCase{"RZZ", MQT_NAMED_BUILDER(qc::rzz), + MQT_NAMED_BUILDER(qir::rzz)}, + QCToQIRBaseTestCase{"SingleControlledRZZ", + MQT_NAMED_BUILDER(qc::singleControlledRzz), + MQT_NAMED_BUILDER(qir::singleControlledRzz)}, + QCToQIRBaseTestCase{"MultipleControlledRZZ", + MQT_NAMED_BUILDER(qc::multipleControlledRzz), + MQT_NAMED_BUILDER(qir::multipleControlledRzz)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SOp.cpp @@ -376,29 +365,28 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"S", MQT_NAMED_BUILDER(qc::s), - MQT_NAMED_BUILDER(qir::s)}, + MQT_NAMED_BUILDER(qir::s)}, QCToQIRBaseTestCase{"SingleControlledS", MQT_NAMED_BUILDER(qc::singleControlledS), - MQT_NAMED_BUILDER(qir::singleControlledS)}, - QCToQIRBaseTestCase{ - "MultipleControlledS", MQT_NAMED_BUILDER(qc::multipleControlledS), - MQT_NAMED_BUILDER(qir::multipleControlledS)})); + MQT_NAMED_BUILDER(qir::singleControlledS)}, + QCToQIRBaseTestCase{"MultipleControlledS", + MQT_NAMED_BUILDER(qc::multipleControlledS), + MQT_NAMED_BUILDER(qir::multipleControlledS)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SdgOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSdgOpTest, QCToQIRBaseTest, - testing::Values(QCToQIRBaseTestCase{"Sdg", MQT_NAMED_BUILDER(qc::sdg), - MQT_NAMED_BUILDER(qir::sdg)}, - QCToQIRBaseTestCase{ - "SingleControlledSdg", - MQT_NAMED_BUILDER(qc::singleControlledSdg), - MQT_NAMED_BUILDER(qir::singleControlledSdg)}, - QCToQIRBaseTestCase{ - "MultipleControlledSdg", - MQT_NAMED_BUILDER(qc::multipleControlledSdg), - MQT_NAMED_BUILDER(qir::multipleControlledSdg)})); + testing::Values( + QCToQIRBaseTestCase{"Sdg", MQT_NAMED_BUILDER(qc::sdg), + MQT_NAMED_BUILDER(qir::sdg)}, + QCToQIRBaseTestCase{"SingleControlledSdg", + MQT_NAMED_BUILDER(qc::singleControlledSdg), + MQT_NAMED_BUILDER(qir::singleControlledSdg)}, + QCToQIRBaseTestCase{"MultipleControlledSdg", + MQT_NAMED_BUILDER(qc::multipleControlledSdg), + MQT_NAMED_BUILDER(qir::multipleControlledSdg)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SwapOp.cpp @@ -407,14 +395,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSWAPOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"SWAP", MQT_NAMED_BUILDER(qc::swap), - MQT_NAMED_BUILDER(qir::swap)}, - QCToQIRBaseTestCase{ - "SingleControlledSWAP", MQT_NAMED_BUILDER(qc::singleControlledSwap), - MQT_NAMED_BUILDER(qir::singleControlledSwap)}, - QCToQIRBaseTestCase{ - "MultipleControlledSWAP", - MQT_NAMED_BUILDER(qc::multipleControlledSwap), - MQT_NAMED_BUILDER(qir::multipleControlledSwap)})); + MQT_NAMED_BUILDER(qir::swap)}, + QCToQIRBaseTestCase{"SingleControlledSWAP", + MQT_NAMED_BUILDER(qc::singleControlledSwap), + MQT_NAMED_BUILDER(qir::singleControlledSwap)}, + QCToQIRBaseTestCase{"MultipleControlledSWAP", + MQT_NAMED_BUILDER(qc::multipleControlledSwap), + MQT_NAMED_BUILDER(qir::multipleControlledSwap)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SxOp.cpp @@ -423,13 +410,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSXOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"SX", MQT_NAMED_BUILDER(qc::sx), - MQT_NAMED_BUILDER(qir::sx)}, + MQT_NAMED_BUILDER(qir::sx)}, QCToQIRBaseTestCase{"SingleControlledSX", MQT_NAMED_BUILDER(qc::singleControlledSx), - MQT_NAMED_BUILDER(qir::singleControlledSx)}, - QCToQIRBaseTestCase{ - "MultipleControlledSX", MQT_NAMED_BUILDER(qc::multipleControlledSx), - MQT_NAMED_BUILDER(qir::multipleControlledSx)})); + MQT_NAMED_BUILDER(qir::singleControlledSx)}, + QCToQIRBaseTestCase{"MultipleControlledSX", + MQT_NAMED_BUILDER(qc::multipleControlledSx), + MQT_NAMED_BUILDER(qir::multipleControlledSx)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SxdgOp.cpp @@ -438,14 +425,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSXdgOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"SXdg", MQT_NAMED_BUILDER(qc::sxdg), - MQT_NAMED_BUILDER(qir::sxdg)}, - QCToQIRBaseTestCase{ - "SingleControlledSXdg", MQT_NAMED_BUILDER(qc::singleControlledSxdg), - MQT_NAMED_BUILDER(qir::singleControlledSxdg)}, - QCToQIRBaseTestCase{ - "MultipleControlledSXdg", - MQT_NAMED_BUILDER(qc::multipleControlledSxdg), - MQT_NAMED_BUILDER(qir::multipleControlledSxdg)})); + MQT_NAMED_BUILDER(qir::sxdg)}, + QCToQIRBaseTestCase{"SingleControlledSXdg", + MQT_NAMED_BUILDER(qc::singleControlledSxdg), + MQT_NAMED_BUILDER(qir::singleControlledSxdg)}, + QCToQIRBaseTestCase{"MultipleControlledSXdg", + MQT_NAMED_BUILDER(qc::multipleControlledSxdg), + MQT_NAMED_BUILDER(qir::multipleControlledSxdg)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/TOp.cpp @@ -454,29 +440,28 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseTOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"T", MQT_NAMED_BUILDER(qc::t_), - MQT_NAMED_BUILDER(qir::t_)}, + MQT_NAMED_BUILDER(qir::t_)}, QCToQIRBaseTestCase{"SingleControlledT", MQT_NAMED_BUILDER(qc::singleControlledT), - MQT_NAMED_BUILDER(qir::singleControlledT)}, - QCToQIRBaseTestCase{ - "MultipleControlledT", MQT_NAMED_BUILDER(qc::multipleControlledT), - MQT_NAMED_BUILDER(qir::multipleControlledT)})); + MQT_NAMED_BUILDER(qir::singleControlledT)}, + QCToQIRBaseTestCase{"MultipleControlledT", + MQT_NAMED_BUILDER(qc::multipleControlledT), + MQT_NAMED_BUILDER(qir::multipleControlledT)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/TdgOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseTdgOpTest, QCToQIRBaseTest, - testing::Values(QCToQIRBaseTestCase{"Tdg", MQT_NAMED_BUILDER(qc::tdg), - MQT_NAMED_BUILDER(qir::tdg)}, - QCToQIRBaseTestCase{ - "SingleControlledTdg", - MQT_NAMED_BUILDER(qc::singleControlledTdg), - MQT_NAMED_BUILDER(qir::singleControlledTdg)}, - QCToQIRBaseTestCase{ - "MultipleControlledTdg", - MQT_NAMED_BUILDER(qc::multipleControlledTdg), - MQT_NAMED_BUILDER(qir::multipleControlledTdg)})); + testing::Values( + QCToQIRBaseTestCase{"Tdg", MQT_NAMED_BUILDER(qc::tdg), + MQT_NAMED_BUILDER(qir::tdg)}, + QCToQIRBaseTestCase{"SingleControlledTdg", + MQT_NAMED_BUILDER(qc::singleControlledTdg), + MQT_NAMED_BUILDER(qir::singleControlledTdg)}, + QCToQIRBaseTestCase{"MultipleControlledTdg", + MQT_NAMED_BUILDER(qc::multipleControlledTdg), + MQT_NAMED_BUILDER(qir::multipleControlledTdg)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/U2Op.cpp @@ -485,13 +470,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseU2OpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"U2", MQT_NAMED_BUILDER(qc::u2), - MQT_NAMED_BUILDER(qir::u2)}, + MQT_NAMED_BUILDER(qir::u2)}, QCToQIRBaseTestCase{"SingleControlledU2", MQT_NAMED_BUILDER(qc::singleControlledU2), - MQT_NAMED_BUILDER(qir::singleControlledU2)}, - QCToQIRBaseTestCase{ - "MultipleControlledU2", MQT_NAMED_BUILDER(qc::multipleControlledU2), - MQT_NAMED_BUILDER(qir::multipleControlledU2)})); + MQT_NAMED_BUILDER(qir::singleControlledU2)}, + QCToQIRBaseTestCase{"MultipleControlledU2", + MQT_NAMED_BUILDER(qc::multipleControlledU2), + MQT_NAMED_BUILDER(qir::multipleControlledU2)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/UOp.cpp @@ -500,13 +485,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseUOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"U", MQT_NAMED_BUILDER(qc::u), - MQT_NAMED_BUILDER(qir::u)}, + MQT_NAMED_BUILDER(qir::u)}, QCToQIRBaseTestCase{"SingleControlledU", MQT_NAMED_BUILDER(qc::singleControlledU), - MQT_NAMED_BUILDER(qir::singleControlledU)}, - QCToQIRBaseTestCase{ - "MultipleControlledU", MQT_NAMED_BUILDER(qc::multipleControlledU), - MQT_NAMED_BUILDER(qir::multipleControlledU)})); + MQT_NAMED_BUILDER(qir::singleControlledU)}, + QCToQIRBaseTestCase{"MultipleControlledU", + MQT_NAMED_BUILDER(qc::multipleControlledU), + MQT_NAMED_BUILDER(qir::multipleControlledU)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/XOp.cpp @@ -515,13 +500,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseXOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"X", MQT_NAMED_BUILDER(qc::x), - MQT_NAMED_BUILDER(qir::x)}, + MQT_NAMED_BUILDER(qir::x)}, QCToQIRBaseTestCase{"SingleControlledX", MQT_NAMED_BUILDER(qc::singleControlledX), - MQT_NAMED_BUILDER(qir::singleControlledX)}, - QCToQIRBaseTestCase{ - "MultipleControlledX", MQT_NAMED_BUILDER(qc::multipleControlledX), - MQT_NAMED_BUILDER(qir::multipleControlledX)})); + MQT_NAMED_BUILDER(qir::singleControlledX)}, + QCToQIRBaseTestCase{"MultipleControlledX", + MQT_NAMED_BUILDER(qc::multipleControlledX), + MQT_NAMED_BUILDER(qir::multipleControlledX)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/XxMinusYyOp.cpp @@ -530,15 +515,14 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseXXMinusYYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"XXMinusYY", MQT_NAMED_BUILDER(qc::xxMinusYY), - MQT_NAMED_BUILDER(qir::xxMinusYY)}, - QCToQIRBaseTestCase{ - "SingleControlledXXMinusYY", - MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), - MQT_NAMED_BUILDER(qir::singleControlledXxMinusYY)}, + MQT_NAMED_BUILDER(qir::xxMinusYY)}, + QCToQIRBaseTestCase{"SingleControlledXXMinusYY", + MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), + MQT_NAMED_BUILDER(qir::singleControlledXxMinusYY)}, QCToQIRBaseTestCase{ "MultipleControlledXXMinusYY", MQT_NAMED_BUILDER(qc::multipleControlledXxMinusYY), - MQT_NAMED_BUILDER(qir::multipleControlledXxMinusYY)})); + MQT_NAMED_BUILDER(qir::multipleControlledXxMinusYY)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/XxPlusYyOp.cpp @@ -547,15 +531,14 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseXXPlusYYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"XXPlusYY", MQT_NAMED_BUILDER(qc::xxPlusYY), - MQT_NAMED_BUILDER(qir::xxPlusYY)}, - QCToQIRBaseTestCase{ - "SingleControlledXXPlusYY", - MQT_NAMED_BUILDER(qc::singleControlledXxPlusYY), - MQT_NAMED_BUILDER(qir::singleControlledXxPlusYY)}, + MQT_NAMED_BUILDER(qir::xxPlusYY)}, + QCToQIRBaseTestCase{"SingleControlledXXPlusYY", + MQT_NAMED_BUILDER(qc::singleControlledXxPlusYY), + MQT_NAMED_BUILDER(qir::singleControlledXxPlusYY)}, QCToQIRBaseTestCase{ "MultipleControlledXXPlusYY", MQT_NAMED_BUILDER(qc::multipleControlledXxPlusYY), - MQT_NAMED_BUILDER(qir::multipleControlledXxPlusYY)})); + MQT_NAMED_BUILDER(qir::multipleControlledXxPlusYY)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/YOp.cpp @@ -564,13 +547,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Y", MQT_NAMED_BUILDER(qc::y), - MQT_NAMED_BUILDER(qir::y)}, + MQT_NAMED_BUILDER(qir::y)}, QCToQIRBaseTestCase{"SingleControlledY", MQT_NAMED_BUILDER(qc::singleControlledY), - MQT_NAMED_BUILDER(qir::singleControlledY)}, - QCToQIRBaseTestCase{ - "MultipleControlledY", MQT_NAMED_BUILDER(qc::multipleControlledY), - MQT_NAMED_BUILDER(qir::multipleControlledY)})); + MQT_NAMED_BUILDER(qir::singleControlledY)}, + QCToQIRBaseTestCase{"MultipleControlledY", + MQT_NAMED_BUILDER(qc::multipleControlledY), + MQT_NAMED_BUILDER(qir::multipleControlledY)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/ZOp.cpp @@ -579,13 +562,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseZOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Z", MQT_NAMED_BUILDER(qc::z), - MQT_NAMED_BUILDER(qir::z)}, + MQT_NAMED_BUILDER(qir::z)}, QCToQIRBaseTestCase{"SingleControlledZ", MQT_NAMED_BUILDER(qc::singleControlledZ), - MQT_NAMED_BUILDER(qir::singleControlledZ)}, - QCToQIRBaseTestCase{ - "MultipleControlledZ", MQT_NAMED_BUILDER(qc::multipleControlledZ), - MQT_NAMED_BUILDER(qir::multipleControlledZ)})); + MQT_NAMED_BUILDER(qir::singleControlledZ)}, + QCToQIRBaseTestCase{"MultipleControlledZ", + MQT_NAMED_BUILDER(qc::multipleControlledZ), + MQT_NAMED_BUILDER(qir::multipleControlledZ)})); /// @} /// \name QCToQIRBase/Operations/MeasureOp.cpp @@ -596,15 +579,15 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseTestCase{ "SingleMeasurementToSingleBit", MQT_NAMED_BUILDER(qc::singleMeasurementToSingleBit), - MQT_NAMED_BUILDER(qir::singleMeasurementToSingleBit)}, + MQT_NAMED_BUILDER(qir::singleMeasurementToSingleBit)}, QCToQIRBaseTestCase{ "RepeatedMeasurementToSameBit", MQT_NAMED_BUILDER(qc::repeatedMeasurementToSameBit), - MQT_NAMED_BUILDER(qir::repeatedMeasurementToSameBit)}, + MQT_NAMED_BUILDER(qir::repeatedMeasurementToSameBit)}, QCToQIRBaseTestCase{ "RepeatedMeasurementToDifferentBits", MQT_NAMED_BUILDER(qc::repeatedMeasurementToDifferentBits), - MQT_NAMED_BUILDER(qir::repeatedMeasurementToDifferentBits)}, + MQT_NAMED_BUILDER(qir::repeatedMeasurementToDifferentBits)}, QCToQIRBaseTestCase{ "MultipleClassicalRegistersAndMeasurements", MQT_NAMED_BUILDER(qc::multipleClassicalRegistersAndMeasurements), @@ -613,7 +596,7 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseTestCase{ "MeasurementWithoutRegisters", MQT_NAMED_BUILDER(qc::measurementWithoutRegisters), - MQT_NAMED_BUILDER(qir::measurementWithoutRegisters)})); + MQT_NAMED_BUILDER(qir::measurementWithoutRegisters)})); /// @} /// \name QCToQIRBase/QubitManagement/QubitManagement.cpp @@ -622,21 +605,21 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseQubitManagementTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"AllocQubit", MQT_NAMED_BUILDER(qc::allocQubit), - MQT_NAMED_BUILDER(qir::allocQubit)}, + MQT_NAMED_BUILDER(qir::allocQubit)}, QCToQIRBaseTestCase{"AllocQubitRegister", MQT_NAMED_BUILDER(qc::allocQubitRegister), - MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(qir::allocQubitRegister)}, QCToQIRBaseTestCase{ "AllocMultipleQubitRegisters", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegisters), - MQT_NAMED_BUILDER(qir::allocMultipleQubitRegisters)}, + MQT_NAMED_BUILDER(qir::allocMultipleQubitRegisters)}, QCToQIRBaseTestCase{ "AllocMultipleQubitRegistersWithOps", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegistersWithOps), - MQT_NAMED_BUILDER(qir::allocMultipleQubitRegistersWithOps)}, + MQT_NAMED_BUILDER(qir::allocMultipleQubitRegistersWithOps)}, QCToQIRBaseTestCase{"AllocLargeRegister", MQT_NAMED_BUILDER(qc::allocLargeRegister), - MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(qir::allocQubitRegister)}, QCToQIRBaseTestCase{"StaticQubits", MQT_NAMED_BUILDER(qc::staticQubits), MQT_NAMED_BUILDER(qir::staticQubits)}, QCToQIRBaseTestCase{"StaticQubitsWithOps", @@ -658,5 +641,5 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(qir::staticQubitsWithInv)}, QCToQIRBaseTestCase{"AllocDeallocPair", MQT_NAMED_BUILDER(qc::allocDeallocPair), - MQT_NAMED_BUILDER(qir::emptyQIR)})); + MQT_NAMED_BUILDER(qir::emptyQIR)})); /// @} diff --git a/mlir/unittests/programs/qir_programs.h b/mlir/unittests/programs/qir_programs.h index dd7d1d81f5..c2ce7deeea 100644 --- a/mlir/unittests/programs/qir_programs.h +++ b/mlir/unittests/programs/qir_programs.h @@ -20,37 +20,37 @@ namespace mlir::qir { class QIRProgramBuilder; /// Creates an empty QIR program. -template +template std::pair emptyQIR(QIRProgramBuilder& builder); // --- Qubit Management ----------------------------------------------------- // /// Allocates a single qubit. -template +template std::pair allocQubit(QIRProgramBuilder& b); /// Allocates a qubit register of size `1`. -template +template std::pair alloc1QubitRegister(QIRProgramBuilder& b); /// Allocates a qubit register of size `2`. -template +template std::pair allocQubitRegister(QIRProgramBuilder& b); /// Allocates a qubit register of size `3`. -template +template std::pair alloc3QubitRegister(QIRProgramBuilder& b); /// Allocates two qubit registers of size `2` and `3`. -template +template std::pair allocMultipleQubitRegisters(QIRProgramBuilder& b); /// Allocates two qubit registers of size `2` and `3` and applies operations. -template +template std::pair allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b); /// Allocates a large qubit register. -template +template std::pair allocLargeRegister(QIRProgramBuilder& b); /// Allocates two inline qubits. @@ -92,528 +92,528 @@ mixedDynamicRegisterThenStaticQubit(QIRProgramBuilder& b); // --- MeasureOp ------------------------------------------------------------ // /// Measures a single qubit into a single classical bit. -template +template std::pair singleMeasurementToSingleBit(QIRProgramBuilder& b); /// Repeatedly measures a single qubit into the same classical bit. -template +template std::pair repeatedMeasurementToSameBit(QIRProgramBuilder& b); /// Repeatedly measures a single qubit into different classical bits. -template +template std::pair repeatedMeasurementToDifferentBits(QIRProgramBuilder& b); /// Measures multiple qubits into multiple classical bits. -template +template std::pair multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b); /// Measures a single qubit into a single classical bit, without explicitly /// allocating a quantum or classical register. -template +template std::pair measurementWithoutRegisters(QIRProgramBuilder& b); // --- ResetOp -------------------------------------------------------------- // /// Resets a single qubit without any operations being applied. -template +template std::pair resetQubitWithoutOp(QIRProgramBuilder& b); /// Resets multiple qubits without any operations being applied. -template +template std::pair resetMultipleQubitsWithoutOp(QIRProgramBuilder& b); /// Repeatedly resets a single qubit without any operations being applied. -template +template std::pair repeatedResetWithoutOp(QIRProgramBuilder& b); /// Resets a single qubit after a single operation. -template +template std::pair resetQubitAfterSingleOp(QIRProgramBuilder& b); /// Resets multiple qubits after a single operation. -template +template std::pair resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b); /// Repeatedly resets a single qubit after a single operation. -template +template std::pair repeatedResetAfterSingleOp(QIRProgramBuilder& b); // --- GPhaseOp ------------------------------------------------------------- // /// Creates a circuit with just a global phase. -template +template std::pair globalPhase(QIRProgramBuilder& b); // --- IdOp ----------------------------------------------------------------- // /// Creates a circuit with just an identity gate. -template +template std::pair identity(QIRProgramBuilder& b); /// Creates a controlled identity gate with a single control qubit. -template +template std::pair singleControlledIdentity(QIRProgramBuilder& b); /// Creates an identity gate on a single qubit in a two-qubit register. -template +template std::pair twoQubitsOneIdentity(QIRProgramBuilder& b); /// Creates an identity gate on a single qubit in a three-qubit register. -template +template std::pair threeQubitsOneIdentity(QIRProgramBuilder& b); /// Creates a multi-controlled identity gate with multiple control qubits. -template +template std::pair multipleControlledIdentity(QIRProgramBuilder& b); // --- XOp ------------------------------------------------------------------ // /// Creates a circuit with just an X gate. -template +template std::pair x(QIRProgramBuilder& b); /// Creates a circuit with a single controlled X gate. -template +template std::pair singleControlledX(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled X gate. -template +template std::pair multipleControlledX(QIRProgramBuilder& b); // --- YOp ------------------------------------------------------------------ // /// Creates a circuit with just a Y gate. -template +template std::pair y(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Y gate. -template +template std::pair singleControlledY(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Y gate. -template +template std::pair multipleControlledY(QIRProgramBuilder& b); // --- ZOp ------------------------------------------------------------------ // /// Creates a circuit with just a Z gate. -template +template std::pair z(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Z gate. -template +template std::pair singleControlledZ(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Z gate. -template +template std::pair multipleControlledZ(QIRProgramBuilder& b); // --- HOp ------------------------------------------------------------------ // /// Creates a circuit with just an H gate. -template +template std::pair h(QIRProgramBuilder& b); /// Creates a circuit with a single controlled H gate. -template +template std::pair singleControlledH(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled H gate. -template +template std::pair multipleControlledH(QIRProgramBuilder& b); /// Creates a circuit with just an H gate and no qubit register. -template +template std::pair hWithoutRegister(QIRProgramBuilder& b); // --- SOp ------------------------------------------------------------------ // /// Creates a circuit with just an S gate. -template +template std::pair s(QIRProgramBuilder& b); /// Creates a circuit with a single controlled S gate. -template +template std::pair singleControlledS(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled S gate. -template +template std::pair multipleControlledS(QIRProgramBuilder& b); // --- SdgOp ---------------------------------------------------------------- // /// Creates a circuit with just an Sdg gate. -template +template std::pair sdg(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Sdg gate. -template +template std::pair singleControlledSdg(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Sdg gate. -template +template std::pair multipleControlledSdg(QIRProgramBuilder& b); // --- TOp ------------------------------------------------------------------ // /// Creates a circuit with just a T gate. -template +template std::pair t_(QIRProgramBuilder& b); // NOLINT(*-identifier-naming) /// Creates a circuit with a single controlled T gate. -template +template std::pair singleControlledT(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled T gate. -template +template std::pair multipleControlledT(QIRProgramBuilder& b); // --- TdgOp ---------------------------------------------------------------- // /// Creates a circuit with just a Tdg gate. -template +template std::pair tdg(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Tdg gate. -template +template std::pair singleControlledTdg(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Tdg gate. -template +template std::pair multipleControlledTdg(QIRProgramBuilder& b); // --- SXOp ----------------------------------------------------------------- // /// Creates a circuit with just an SX gate. -template +template std::pair sx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled SX gate. -template +template std::pair singleControlledSx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled SX gate. -template +template std::pair multipleControlledSx(QIRProgramBuilder& b); // --- SXdgOp --------------------------------------------------------------- // /// Creates a circuit with just an SXdg gate. -template +template std::pair sxdg(QIRProgramBuilder& b); /// Creates a circuit with a single controlled SXdg gate. -template +template std::pair singleControlledSxdg(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled SXdg gate. -template +template std::pair multipleControlledSxdg(QIRProgramBuilder& b); // --- RXOp ----------------------------------------------------------------- // /// Creates a circuit with just an RX gate. -template +template std::pair rx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RX gate. -template +template std::pair singleControlledRx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RX gate. -template +template std::pair multipleControlledRx(QIRProgramBuilder& b); // --- RYOp ----------------------------------------------------------------- // /// Creates a circuit with just an RY gate. -template +template std::pair ry(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RY gate. -template +template std::pair singleControlledRy(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RY gate. -template +template std::pair multipleControlledRy(QIRProgramBuilder& b); // --- RZOp ----------------------------------------------------------------- // /// Creates a circuit with just an RZ gate. -template +template std::pair rz(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RZ gate. -template +template std::pair singleControlledRz(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RZ gate. -template +template std::pair multipleControlledRz(QIRProgramBuilder& b); // --- POp ------------------------------------------------------------------ // /// Creates a circuit with just a P gate. -template +template std::pair p(QIRProgramBuilder& b); /// Creates a circuit with a single controlled P gate. -template +template std::pair singleControlledP(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled P gate. -template +template std::pair multipleControlledP(QIRProgramBuilder& b); // --- ROp ------------------------------------------------------------------ // /// Creates a circuit with just an R gate. -template +template std::pair r(QIRProgramBuilder& b); /// Creates a circuit with a single controlled R gate. -template +template std::pair singleControlledR(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled R gate. -template +template std::pair multipleControlledR(QIRProgramBuilder& b); // --- U2Op ----------------------------------------------------------------- // /// Creates a circuit with just a U2 gate. -template +template std::pair u2(QIRProgramBuilder& b); /// Creates a circuit with a single controlled U2 gate. -template +template std::pair singleControlledU2(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled U2 gate. -template +template std::pair multipleControlledU2(QIRProgramBuilder& b); // --- UOp ------------------------------------------------------------------ // /// Creates a circuit with just a U gate. -template +template std::pair u(QIRProgramBuilder& b); /// Creates a circuit with a single controlled U gate. -template +template std::pair singleControlledU(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled U gate. -template +template std::pair multipleControlledU(QIRProgramBuilder& b); // --- SWAPOp --------------------------------------------------------------- // /// Creates a circuit with just a SWAP gate. -template +template std::pair swap(QIRProgramBuilder& b); /// Creates a circuit with a single controlled SWAP gate. -template +template std::pair singleControlledSwap(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled SWAP gate. -template +template std::pair multipleControlledSwap(QIRProgramBuilder& b); // --- iSWAPOp -------------------------------------------------------------- // /// Creates a circuit with just an iSWAP gate. -template +template std::pair iswap(QIRProgramBuilder& b); /// Creates a circuit with a single controlled iSWAP gate. -template +template std::pair singleControlledIswap(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled iSWAP gate. -template +template std::pair multipleControlledIswap(QIRProgramBuilder& b); // --- DCXOp ---------------------------------------------------------------- // /// Creates a circuit with just a DCX gate. -template +template std::pair dcx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled DCX gate. -template +template std::pair singleControlledDcx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled DCX gate. -template +template std::pair multipleControlledDcx(QIRProgramBuilder& b); // --- ECROp ---------------------------------------------------------------- // /// Creates a circuit with just an ECR gate. -template +template std::pair ecr(QIRProgramBuilder& b); /// Creates a circuit with a single controlled ECR gate. -template +template std::pair singleControlledEcr(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled ECR gate. -template +template std::pair multipleControlledEcr(QIRProgramBuilder& b); // --- RXXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RXX gate. -template +template std::pair rxx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RXX gate. -template +template std::pair singleControlledRxx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RXX gate. -template +template std::pair multipleControlledRxx(QIRProgramBuilder& b); /// Creates a circuit with a triple-controlled RXX gate. -template +template std::pair tripleControlledRxx(QIRProgramBuilder& b); // --- RYYOp ---------------------------------------------------------------- // /// Creates a circuit with just an RYY gate. -template +template std::pair ryy(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RYY gate. -template +template std::pair singleControlledRyy(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RYY gate. -template +template std::pair multipleControlledRyy(QIRProgramBuilder& b); // --- RZXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZX gate. -template +template std::pair rzx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RZX gate. -template +template std::pair singleControlledRzx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RZX gate. -template +template std::pair multipleControlledRzx(QIRProgramBuilder& b); // --- RZZOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZZ gate. -template +template std::pair rzz(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RZZ gate. -template +template std::pair singleControlledRzz(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RZZ gate. -template +template std::pair multipleControlledRzz(QIRProgramBuilder& b); // --- XXPlusYYOp ----------------------------------------------------------- // /// Creates a circuit with just an XXPlusYY gate. -template +template std::pair xxPlusYY(QIRProgramBuilder& b); /// Creates a circuit with a single controlled XXPlusYY gate. -template +template std::pair singleControlledXxPlusYY(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled XXPlusYY gate. -template +template std::pair multipleControlledXxPlusYY(QIRProgramBuilder& b); // --- XXMinusYYOp ---------------------------------------------------------- // /// Creates a circuit with just an XXMinusYY gate. -template +template std::pair xxMinusYY(QIRProgramBuilder& b); /// Creates a circuit with a single controlled XXMinusYY gate. -template +template std::pair singleControlledXxMinusYY(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled XXMinusYY gate. -template +template std::pair multipleControlledXxMinusYY(QIRProgramBuilder& b); // --- IfOp ----------------------------------------------------------------- // /// Creates a circuit with a simple if operation with one qubit. -template +template std::pair simpleIf(QIRProgramBuilder& b); /// Creates a circuit with an if operation with an else branch. -template +template std::pair ifElse(QIRProgramBuilder& b); /// Creates a circuit with an if operation with two qubits. -template +template std::pair ifTwoQubits(QIRProgramBuilder& b); /// Creates a circuit with an if operation with a nested for operation with /// a register. -template +template std::pair nestedIfOpForLoop(QIRProgramBuilder& b); // --- WhileOp -------------------------------------------------------------- // /// Creates a circuit with a while operation using a while loop. -template +template std::pair simpleWhileReset(QIRProgramBuilder& b); /// Creates a circuit with a while operation using a do-while loop. -template +template std::pair simpleDoWhileReset(QIRProgramBuilder& b); // --- ForOp ---------------------------------------------------------------- // /// Creates a circuit with a simple for operation with a register. -template +template std::pair simpleForLoop(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested if operation. -template +template std::pair nestedForLoopIfOp(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a nested while /// operation. -template +template std::pair nestedForLoopWhileOp(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is separately allocated from the /// register. -template +template std::pair nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is extracted from the register. -template +template std::pair nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b); // --- CtrlOp --------------------------------------------------------------- // /// Creates a circuit with a control modifier applied to two gates. -template +template std::pair ctrlTwo(QIRProgramBuilder& b); } // namespace mlir::qir From bba85e86e8ef751234cbeb932db6ebb4a56cf388 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Mon, 6 Jul 2026 17:21:17 +0200 Subject: [PATCH 39/80] fix: :bug: fix QuantumComputation python bindings for new parameter --- bindings/ir/register_quantum_computation.cpp | 6 ++++-- python/mqt/core/ir/__init__.pyi | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bindings/ir/register_quantum_computation.cpp b/bindings/ir/register_quantum_computation.cpp index 618d52e7e4..3dc239b511 100644 --- a/bindings/ir/register_quantum_computation.cpp +++ b/bindings/ir/register_quantum_computation.cpp @@ -2003,15 +2003,17 @@ This method is equivalent to calling :meth:`measure` multiple times. qubits: The qubits to measure cbits: The classical bits to store the results)pb"); qc.def("measure_all", &qc::QuantumComputation::measureAll, nb::kw_only(), - "add_bits"_a = true, + "add_bits"_a = true, "add_barrier"_a = true, R"pb(Measure all qubits and store the results in classical bits. Details: If `add_bits` is `True`, a new classical register (named "`meas`") with the same size as the number of qubits will be added to the circuit and the results will be stored in it. If `add_bits` is `False`, the classical register must already exist and have a sufficient number of bits to store the results. + If `add_barrier` is `True`, a barrier is added before the measurements. Args: - add_bits: Whether to explicitly add a classical register)pb"); + add_bits: Whether to explicitly add a classical register + add_barrier: Whether to add a barrier before the measurements)pb"); qc.def("reset", nb::overload_cast(&qc::QuantumComputation::reset), "q"_a, R"pb(Add a reset operation to the circuit. diff --git a/python/mqt/core/ir/__init__.pyi b/python/mqt/core/ir/__init__.pyi index 69ea76967a..b95847f98b 100644 --- a/python/mqt/core/ir/__init__.pyi +++ b/python/mqt/core/ir/__init__.pyi @@ -1850,15 +1850,17 @@ class QuantumComputation(MutableSequence[operations.Operation]): cbits: The classical bits to store the results """ - def measure_all(self, *, add_bits: bool = True) -> None: + def measure_all(self, *, add_bits: bool = True, add_barrier: bool = True) -> None: """Measure all qubits and store the results in classical bits. Details: If `add_bits` is `True`, a new classical register (named "`meas`") with the same size as the number of qubits will be added to the circuit and the results will be stored in it. If `add_bits` is `False`, the classical register must already exist and have a sufficient number of bits to store the results. + If `add_barrier` is `True`, a barrier is added before the measurements. Args: add_bits: Whether to explicitly add a classical register + add_barrier: Whether to add a barrier before the measurements """ @overload From 62f1ab5aababe8d7c24cc165b3724171edc94ca8 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Mon, 6 Jul 2026 18:01:54 +0200 Subject: [PATCH 40/80] chore(mlir): :recycle: get rid of remaining helper files --- .../cmake_test_discovery_365918a72a.json | 1754 ----------------- .../cmake_test_discovery_02ef7f1542.json | 646 ------ test/dd/cmake_test_discovery_ec2b1aa6e1.json | 1622 --------------- .../cmake_test_discovery_d92b282818.json | 919 --------- test/na/cmake_test_discovery_250b2f6e91.json | 138 -- .../cmake_test_discovery_d3ec408c45.json | 22 - .../dd/cmake_test_discovery_e4d6740af8.json | 264 --- .../na/cmake_test_discovery_c9108a12c6.json | 291 --- .../sc/cmake_test_discovery_b685f933aa.json | 230 --- .../cmake_test_discovery_19da466dc8.json | 574 ------ .../cmake_test_discovery_f490d2a913.json | 30 - .../cmake_test_discovery_a54bc9ca40.json | 296 --- test/zx/cmake_test_discovery_de31622abe.json | 566 ------ 13 files changed, 7352 deletions(-) delete mode 100644 test/algorithms/cmake_test_discovery_365918a72a.json delete mode 100644 test/circuit_optimizer/cmake_test_discovery_02ef7f1542.json delete mode 100644 test/dd/cmake_test_discovery_ec2b1aa6e1.json delete mode 100644 test/fomac/cmake_test_discovery_d92b282818.json delete mode 100644 test/na/cmake_test_discovery_250b2f6e91.json delete mode 100644 test/na/fomac/cmake_test_discovery_d3ec408c45.json delete mode 100644 test/qdmi/devices/dd/cmake_test_discovery_e4d6740af8.json delete mode 100644 test/qdmi/devices/na/cmake_test_discovery_c9108a12c6.json delete mode 100644 test/qdmi/devices/sc/cmake_test_discovery_b685f933aa.json delete mode 100644 test/qdmi/driver/cmake_test_discovery_19da466dc8.json delete mode 100644 test/qir/runner/cmake_test_discovery_f490d2a913.json delete mode 100644 test/qir/runtime/cmake_test_discovery_a54bc9ca40.json delete mode 100644 test/zx/cmake_test_discovery_de31622abe.json diff --git a/test/algorithms/cmake_test_discovery_365918a72a.json b/test/algorithms/cmake_test_discovery_365918a72a.json deleted file mode 100644 index e43f93d3eb..0000000000 --- a/test/algorithms/cmake_test_discovery_365918a72a.json +++ /dev/null @@ -1,1754 +0,0 @@ -{ - "tests": 278, - "name": "AllTests", - "testsuites": [ - { - "name": "StatePreparation", - "tests": 2, - "testsuite": [ - { - "name": "StatePreparationAmplitudesNotNormalized", - "file": "\/workspaces\/core\/test\/algorithms\/test_statepreparation.cpp", - "line": 87 - }, - { - "name": "StatePreparationsAmplitudesNotPowerOf2", - "file": "\/workspaces\/core\/test\/algorithms\/test_statepreparation.cpp", - "line": 95 - } - ] - }, - { - "name": "BernsteinVazirani", - "tests": 2, - "testsuite": [ - { - "name": "LargeCircuit", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 90 - }, - { - "name": "DynamicCircuit", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 105 - } - ] - }, - { - "name": "WState\/WState", - "tests": 19, - "testsuite": [ - { - "name": "FunctionTest\/1_qubits", - "value_param": "1", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/8_qubits", - "value_param": "8", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/15_qubits", - "value_param": "15", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/22_qubits", - "value_param": "22", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/29_qubits", - "value_param": "29", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/36_qubits", - "value_param": "36", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/43_qubits", - "value_param": "43", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/50_qubits", - "value_param": "50", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/57_qubits", - "value_param": "57", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/64_qubits", - "value_param": "64", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/71_qubits", - "value_param": "71", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/78_qubits", - "value_param": "78", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/85_qubits", - "value_param": "85", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/92_qubits", - "value_param": "92", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/99_qubits", - "value_param": "99", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/106_qubits", - "value_param": "106", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/113_qubits", - "value_param": "113", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/120_qubits", - "value_param": "120", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/127_qubits", - "value_param": "127", - "file": "\/workspaces\/core\/test\/algorithms\/test_wstate.cpp", - "line": 51 - } - ] - }, - { - "name": "StatePreparation\/StatePreparation", - "tests": 6, - "testsuite": [ - { - "name": "StatePreparationCircuitSimulation\/0", - "value_param": "{ (0.707107,0), (-0.707107,0) }", - "file": "\/workspaces\/core\/test\/algorithms\/test_statepreparation.cpp", - "line": 72 - }, - { - "name": "StatePreparationCircuitSimulation\/1", - "value_param": "{ (0.707107,0), (0,-0.707107) }", - "file": "\/workspaces\/core\/test\/algorithms\/test_statepreparation.cpp", - "line": 72 - }, - { - "name": "StatePreparationCircuitSimulation\/2", - "value_param": "{ (0,0), (0.707107,0), (-0.707107,0), (0,0) }", - "file": "\/workspaces\/core\/test\/algorithms\/test_statepreparation.cpp", - "line": 72 - }, - { - "name": "StatePreparationCircuitSimulation\/3", - "value_param": "{ (0.27735,0), (-0.27735,0), (0.27735,-0.27735), (0,0.83205) }", - "file": "\/workspaces\/core\/test\/algorithms\/test_statepreparation.cpp", - "line": 72 - }, - { - "name": "StatePreparationCircuitSimulation\/4", - "value_param": "{ (0.25,0), (0.25,0), (0.25,0), (0.25,0), (0.25,0), (0.25,0), (0.25,0), (0.75,0) }", - "file": "\/workspaces\/core\/test\/algorithms\/test_statepreparation.cpp", - "line": 72 - }, - { - "name": "StatePreparationCircuitSimulation\/5", - "value_param": "{ (0.25,0), (0,0.25), (0.25,0), (0,0.25), (0,0.25), (0.25,0), (0.25,0), (0.75,0) }", - "file": "\/workspaces\/core\/test\/algorithms\/test_statepreparation.cpp", - "line": 72 - } - ] - }, - { - "name": "RandomClifford\/RandomClifford", - "tests": 16, - "testsuite": [ - { - "name": "simulate\/1_qubits", - "value_param": "1", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 46 - }, - { - "name": "simulate\/2_qubits", - "value_param": "2", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 46 - }, - { - "name": "simulate\/3_qubits", - "value_param": "3", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 46 - }, - { - "name": "simulate\/4_qubits", - "value_param": "4", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 46 - }, - { - "name": "simulate\/5_qubits", - "value_param": "5", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 46 - }, - { - "name": "simulate\/6_qubits", - "value_param": "6", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 46 - }, - { - "name": "simulate\/7_qubits", - "value_param": "7", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 46 - }, - { - "name": "simulate\/8_qubits", - "value_param": "8", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 46 - }, - { - "name": "buildFunctionality\/1_qubits", - "value_param": "1", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 60 - }, - { - "name": "buildFunctionality\/2_qubits", - "value_param": "2", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 60 - }, - { - "name": "buildFunctionality\/3_qubits", - "value_param": "3", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 60 - }, - { - "name": "buildFunctionality\/4_qubits", - "value_param": "4", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 60 - }, - { - "name": "buildFunctionality\/5_qubits", - "value_param": "5", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 60 - }, - { - "name": "buildFunctionality\/6_qubits", - "value_param": "6", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 60 - }, - { - "name": "buildFunctionality\/7_qubits", - "value_param": "7", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 60 - }, - { - "name": "buildFunctionality\/8_qubits", - "value_param": "8", - "file": "\/workspaces\/core\/test\/algorithms\/test_random_clifford.cpp", - "line": 60 - } - ] - }, - { - "name": "QPE\/QPE", - "tests": 28, - "testsuite": [ - { - "name": "QPETest\/100_pi_1", - "value_param": "(1, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 137 - }, - { - "name": "QPETest\/50_pi_2", - "value_param": "(0.5, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 137 - }, - { - "name": "QPETest\/25_pi_3", - "value_param": "(0.25, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 137 - }, - { - "name": "QPETest\/37_pi_3", - "value_param": "(0.375, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 137 - }, - { - "name": "QPETest\/37_pi_4", - "value_param": "(0.375, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 137 - }, - { - "name": "QPETest\/9_pi_5", - "value_param": "(0.09375, 5)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 137 - }, - { - "name": "QPETest\/9_pi_6", - "value_param": "(0.09375, 6)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 137 - }, - { - "name": "IQPETest\/100_pi_1", - "value_param": "(1, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 173 - }, - { - "name": "IQPETest\/50_pi_2", - "value_param": "(0.5, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 173 - }, - { - "name": "IQPETest\/25_pi_3", - "value_param": "(0.25, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 173 - }, - { - "name": "IQPETest\/37_pi_3", - "value_param": "(0.375, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 173 - }, - { - "name": "IQPETest\/37_pi_4", - "value_param": "(0.375, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 173 - }, - { - "name": "IQPETest\/9_pi_5", - "value_param": "(0.09375, 5)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 173 - }, - { - "name": "IQPETest\/9_pi_6", - "value_param": "(0.09375, 6)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 173 - }, - { - "name": "DynamicEquivalenceSimulation\/100_pi_1", - "value_param": "(1, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 218 - }, - { - "name": "DynamicEquivalenceSimulation\/50_pi_2", - "value_param": "(0.5, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 218 - }, - { - "name": "DynamicEquivalenceSimulation\/25_pi_3", - "value_param": "(0.25, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 218 - }, - { - "name": "DynamicEquivalenceSimulation\/37_pi_3", - "value_param": "(0.375, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 218 - }, - { - "name": "DynamicEquivalenceSimulation\/37_pi_4", - "value_param": "(0.375, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 218 - }, - { - "name": "DynamicEquivalenceSimulation\/9_pi_5", - "value_param": "(0.09375, 5)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 218 - }, - { - "name": "DynamicEquivalenceSimulation\/9_pi_6", - "value_param": "(0.09375, 6)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 218 - }, - { - "name": "DynamicEquivalenceFunctionality\/100_pi_1", - "value_param": "(1, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 251 - }, - { - "name": "DynamicEquivalenceFunctionality\/50_pi_2", - "value_param": "(0.5, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 251 - }, - { - "name": "DynamicEquivalenceFunctionality\/25_pi_3", - "value_param": "(0.25, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 251 - }, - { - "name": "DynamicEquivalenceFunctionality\/37_pi_3", - "value_param": "(0.375, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 251 - }, - { - "name": "DynamicEquivalenceFunctionality\/37_pi_4", - "value_param": "(0.375, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 251 - }, - { - "name": "DynamicEquivalenceFunctionality\/9_pi_5", - "value_param": "(0.09375, 5)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 251 - }, - { - "name": "DynamicEquivalenceFunctionality\/9_pi_6", - "value_param": "(0.09375, 6)", - "file": "\/workspaces\/core\/test\/algorithms\/test_qpe.cpp", - "line": 251 - } - ] - }, - { - "name": "QFT\/QFT", - "tests": 30, - "testsuite": [ - { - "name": "Functionality\/0_qubits", - "value_param": "0", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 83 - }, - { - "name": "Functionality\/3_qubits", - "value_param": "3", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 83 - }, - { - "name": "Functionality\/6_qubits", - "value_param": "6", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 83 - }, - { - "name": "Functionality\/9_qubits", - "value_param": "9", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 83 - }, - { - "name": "Functionality\/12_qubits", - "value_param": "12", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 83 - }, - { - "name": "Functionality\/15_qubits", - "value_param": "15", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 83 - }, - { - "name": "FunctionalityRecursive\/0_qubits", - "value_param": "0", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 126 - }, - { - "name": "FunctionalityRecursive\/3_qubits", - "value_param": "3", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 126 - }, - { - "name": "FunctionalityRecursive\/6_qubits", - "value_param": "6", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 126 - }, - { - "name": "FunctionalityRecursive\/9_qubits", - "value_param": "9", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 126 - }, - { - "name": "FunctionalityRecursive\/12_qubits", - "value_param": "12", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 126 - }, - { - "name": "FunctionalityRecursive\/15_qubits", - "value_param": "15", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 126 - }, - { - "name": "Simulation\/0_qubits", - "value_param": "0", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 169 - }, - { - "name": "Simulation\/3_qubits", - "value_param": "3", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 169 - }, - { - "name": "Simulation\/6_qubits", - "value_param": "6", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 169 - }, - { - "name": "Simulation\/9_qubits", - "value_param": "9", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 169 - }, - { - "name": "Simulation\/12_qubits", - "value_param": "12", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 169 - }, - { - "name": "Simulation\/15_qubits", - "value_param": "15", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 169 - }, - { - "name": "FunctionalityRecursiveEquality\/0_qubits", - "value_param": "0", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 206 - }, - { - "name": "FunctionalityRecursiveEquality\/3_qubits", - "value_param": "3", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 206 - }, - { - "name": "FunctionalityRecursiveEquality\/6_qubits", - "value_param": "6", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 206 - }, - { - "name": "FunctionalityRecursiveEquality\/9_qubits", - "value_param": "9", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 206 - }, - { - "name": "FunctionalityRecursiveEquality\/12_qubits", - "value_param": "12", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 206 - }, - { - "name": "FunctionalityRecursiveEquality\/15_qubits", - "value_param": "15", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 206 - }, - { - "name": "SimulationSampling\/0_qubits", - "value_param": "0", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 226 - }, - { - "name": "SimulationSampling\/3_qubits", - "value_param": "3", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 226 - }, - { - "name": "SimulationSampling\/6_qubits", - "value_param": "6", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 226 - }, - { - "name": "SimulationSampling\/9_qubits", - "value_param": "9", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 226 - }, - { - "name": "SimulationSampling\/12_qubits", - "value_param": "12", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 226 - }, - { - "name": "SimulationSampling\/15_qubits", - "value_param": "15", - "file": "\/workspaces\/core\/test\/algorithms\/test_qft.cpp", - "line": 226 - } - ] - }, - { - "name": "Grover\/Grover", - "tests": 75, - "testsuite": [ - { - "name": "Functionality\/3_qubits_0", - "value_param": "(2, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/3_qubits_1", - "value_param": "(2, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/3_qubits_2", - "value_param": "(2, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/3_qubits_3", - "value_param": "(2, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/3_qubits_4", - "value_param": "(2, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/6_qubits_0", - "value_param": "(5, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/6_qubits_1", - "value_param": "(5, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/6_qubits_2", - "value_param": "(5, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/6_qubits_3", - "value_param": "(5, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/6_qubits_4", - "value_param": "(5, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/9_qubits_0", - "value_param": "(8, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/9_qubits_1", - "value_param": "(8, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/9_qubits_2", - "value_param": "(8, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/9_qubits_3", - "value_param": "(8, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/9_qubits_4", - "value_param": "(8, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/12_qubits_0", - "value_param": "(11, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/12_qubits_1", - "value_param": "(11, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/12_qubits_2", - "value_param": "(11, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/12_qubits_3", - "value_param": "(11, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/12_qubits_4", - "value_param": "(11, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/15_qubits_0", - "value_param": "(14, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/15_qubits_1", - "value_param": "(14, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/15_qubits_2", - "value_param": "(14, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/15_qubits_3", - "value_param": "(14, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "Functionality\/15_qubits_4", - "value_param": "(14, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 89 - }, - { - "name": "FunctionalityRecursive\/3_qubits_0", - "value_param": "(2, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/3_qubits_1", - "value_param": "(2, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/3_qubits_2", - "value_param": "(2, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/3_qubits_3", - "value_param": "(2, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/3_qubits_4", - "value_param": "(2, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/6_qubits_0", - "value_param": "(5, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/6_qubits_1", - "value_param": "(5, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/6_qubits_2", - "value_param": "(5, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/6_qubits_3", - "value_param": "(5, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/6_qubits_4", - "value_param": "(5, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/9_qubits_0", - "value_param": "(8, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/9_qubits_1", - "value_param": "(8, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/9_qubits_2", - "value_param": "(8, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/9_qubits_3", - "value_param": "(8, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/9_qubits_4", - "value_param": "(8, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/12_qubits_0", - "value_param": "(11, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/12_qubits_1", - "value_param": "(11, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/12_qubits_2", - "value_param": "(11, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/12_qubits_3", - "value_param": "(11, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/12_qubits_4", - "value_param": "(11, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/15_qubits_0", - "value_param": "(14, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/15_qubits_1", - "value_param": "(14, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/15_qubits_2", - "value_param": "(14, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/15_qubits_3", - "value_param": "(14, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "FunctionalityRecursive\/15_qubits_4", - "value_param": "(14, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 128 - }, - { - "name": "Simulation\/3_qubits_0", - "value_param": "(2, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/3_qubits_1", - "value_param": "(2, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/3_qubits_2", - "value_param": "(2, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/3_qubits_3", - "value_param": "(2, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/3_qubits_4", - "value_param": "(2, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/6_qubits_0", - "value_param": "(5, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/6_qubits_1", - "value_param": "(5, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/6_qubits_2", - "value_param": "(5, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/6_qubits_3", - "value_param": "(5, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/6_qubits_4", - "value_param": "(5, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/9_qubits_0", - "value_param": "(8, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/9_qubits_1", - "value_param": "(8, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/9_qubits_2", - "value_param": "(8, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/9_qubits_3", - "value_param": "(8, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/9_qubits_4", - "value_param": "(8, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/12_qubits_0", - "value_param": "(11, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/12_qubits_1", - "value_param": "(11, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/12_qubits_2", - "value_param": "(11, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/12_qubits_3", - "value_param": "(11, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/12_qubits_4", - "value_param": "(11, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/15_qubits_0", - "value_param": "(14, 0)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/15_qubits_1", - "value_param": "(14, 1)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/15_qubits_2", - "value_param": "(14, 2)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/15_qubits_3", - "value_param": "(14, 3)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - }, - { - "name": "Simulation\/15_qubits_4", - "value_param": "(14, 4)", - "file": "\/workspaces\/core\/test\/algorithms\/test_grover.cpp", - "line": 182 - } - ] - }, - { - "name": "Entanglement\/Entanglement", - "tests": 26, - "testsuite": [ - { - "name": "FunctionTest\/2_qubits", - "value_param": "2", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/9_qubits", - "value_param": "9", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/16_qubits", - "value_param": "16", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/23_qubits", - "value_param": "23", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/30_qubits", - "value_param": "30", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/37_qubits", - "value_param": "37", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/44_qubits", - "value_param": "44", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/51_qubits", - "value_param": "51", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/58_qubits", - "value_param": "58", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/65_qubits", - "value_param": "65", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/72_qubits", - "value_param": "72", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/79_qubits", - "value_param": "79", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "FunctionTest\/86_qubits", - "value_param": "86", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 51 - }, - { - "name": "GHZRoutineFunctionTest\/2_qubits", - "value_param": "2", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - }, - { - "name": "GHZRoutineFunctionTest\/9_qubits", - "value_param": "9", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - }, - { - "name": "GHZRoutineFunctionTest\/16_qubits", - "value_param": "16", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - }, - { - "name": "GHZRoutineFunctionTest\/23_qubits", - "value_param": "23", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - }, - { - "name": "GHZRoutineFunctionTest\/30_qubits", - "value_param": "30", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - }, - { - "name": "GHZRoutineFunctionTest\/37_qubits", - "value_param": "37", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - }, - { - "name": "GHZRoutineFunctionTest\/44_qubits", - "value_param": "44", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - }, - { - "name": "GHZRoutineFunctionTest\/51_qubits", - "value_param": "51", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - }, - { - "name": "GHZRoutineFunctionTest\/58_qubits", - "value_param": "58", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - }, - { - "name": "GHZRoutineFunctionTest\/65_qubits", - "value_param": "65", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - }, - { - "name": "GHZRoutineFunctionTest\/72_qubits", - "value_param": "72", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - }, - { - "name": "GHZRoutineFunctionTest\/79_qubits", - "value_param": "79", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - }, - { - "name": "GHZRoutineFunctionTest\/86_qubits", - "value_param": "86", - "file": "\/workspaces\/core\/test\/algorithms\/test_entanglement.cpp", - "line": 60 - } - ] - }, - { - "name": "BernsteinVazirani\/BernsteinVazirani", - "tests": 30, - "testsuite": [ - { - "name": "FunctionTest\/bv_0", - "value_param": "0", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 52 - }, - { - "name": "FunctionTest\/bv_3", - "value_param": "3", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 52 - }, - { - "name": "FunctionTest\/bv_63", - "value_param": "63", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 52 - }, - { - "name": "FunctionTest\/bv_170", - "value_param": "170", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 52 - }, - { - "name": "FunctionTest\/bv_819", - "value_param": "819", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 52 - }, - { - "name": "FunctionTest\/bv_4032", - "value_param": "4032", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 52 - }, - { - "name": "FunctionTest\/bv_33153", - "value_param": "33153", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 52 - }, - { - "name": "FunctionTest\/bv_87381", - "value_param": "87381", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 52 - }, - { - "name": "FunctionTest\/bv_16777215", - "value_param": "16777215", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 52 - }, - { - "name": "FunctionTest\/bv_1234567891011", - "value_param": "1234567891011", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 52 - }, - { - "name": "FunctionTestDynamic\/bv_0", - "value_param": "0", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 71 - }, - { - "name": "FunctionTestDynamic\/bv_3", - "value_param": "3", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 71 - }, - { - "name": "FunctionTestDynamic\/bv_63", - "value_param": "63", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 71 - }, - { - "name": "FunctionTestDynamic\/bv_170", - "value_param": "170", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 71 - }, - { - "name": "FunctionTestDynamic\/bv_819", - "value_param": "819", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 71 - }, - { - "name": "FunctionTestDynamic\/bv_4032", - "value_param": "4032", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 71 - }, - { - "name": "FunctionTestDynamic\/bv_33153", - "value_param": "33153", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 71 - }, - { - "name": "FunctionTestDynamic\/bv_87381", - "value_param": "87381", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 71 - }, - { - "name": "FunctionTestDynamic\/bv_16777215", - "value_param": "16777215", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 71 - }, - { - "name": "FunctionTestDynamic\/bv_1234567891011", - "value_param": "1234567891011", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 71 - }, - { - "name": "DynamicEquivalenceSimulation\/bv_0", - "value_param": "0", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 120 - }, - { - "name": "DynamicEquivalenceSimulation\/bv_3", - "value_param": "3", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 120 - }, - { - "name": "DynamicEquivalenceSimulation\/bv_63", - "value_param": "63", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 120 - }, - { - "name": "DynamicEquivalenceSimulation\/bv_170", - "value_param": "170", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 120 - }, - { - "name": "DynamicEquivalenceSimulation\/bv_819", - "value_param": "819", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 120 - }, - { - "name": "DynamicEquivalenceSimulation\/bv_4032", - "value_param": "4032", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 120 - }, - { - "name": "DynamicEquivalenceSimulation\/bv_33153", - "value_param": "33153", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 120 - }, - { - "name": "DynamicEquivalenceSimulation\/bv_87381", - "value_param": "87381", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 120 - }, - { - "name": "DynamicEquivalenceSimulation\/bv_16777215", - "value_param": "16777215", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 120 - }, - { - "name": "DynamicEquivalenceSimulation\/bv_1234567891011", - "value_param": "1234567891011", - "file": "\/workspaces\/core\/test\/algorithms\/test_bernsteinvazirani.cpp", - "line": 120 - } - ] - }, - { - "name": "Eval\/DynamicCircuitEvalExactQPE", - "tests": 13, - "testsuite": [ - { - "name": "UnitaryTransformation\/1_qubit", - "value_param": "1", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - }, - { - "name": "UnitaryTransformation\/6_qubits", - "value_param": "6", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - }, - { - "name": "UnitaryTransformation\/11_qubits", - "value_param": "11", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - }, - { - "name": "UnitaryTransformation\/16_qubits", - "value_param": "16", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - }, - { - "name": "UnitaryTransformation\/21_qubits", - "value_param": "21", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - }, - { - "name": "UnitaryTransformation\/26_qubits", - "value_param": "26", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - }, - { - "name": "UnitaryTransformation\/31_qubits", - "value_param": "31", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - }, - { - "name": "UnitaryTransformation\/36_qubits", - "value_param": "36", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - }, - { - "name": "UnitaryTransformation\/41_qubits", - "value_param": "41", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - }, - { - "name": "UnitaryTransformation\/46_qubits", - "value_param": "46", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - }, - { - "name": "UnitaryTransformation\/51_qubits", - "value_param": "51", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - }, - { - "name": "UnitaryTransformation\/56_qubits", - "value_param": "56", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - }, - { - "name": "UnitaryTransformation\/61_qubits", - "value_param": "61", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 122 - } - ] - }, - { - "name": "Eval\/DynamicCircuitEvalInexactQPE", - "tests": 5, - "testsuite": [ - { - "name": "UnitaryTransformation\/1_qubit", - "value_param": "1", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 295 - }, - { - "name": "UnitaryTransformation\/4_qubits", - "value_param": "4", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 295 - }, - { - "name": "UnitaryTransformation\/7_qubits", - "value_param": "7", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 295 - }, - { - "name": "UnitaryTransformation\/10_qubits", - "value_param": "10", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 295 - }, - { - "name": "UnitaryTransformation\/13_qubits", - "value_param": "13", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 295 - } - ] - }, - { - "name": "Eval\/DynamicCircuitEvalBV", - "tests": 13, - "testsuite": [ - { - "name": "UnitaryTransformation\/1_qubit", - "value_param": "1", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - }, - { - "name": "UnitaryTransformation\/6_qubits", - "value_param": "6", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - }, - { - "name": "UnitaryTransformation\/11_qubits", - "value_param": "11", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - }, - { - "name": "UnitaryTransformation\/16_qubits", - "value_param": "16", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - }, - { - "name": "UnitaryTransformation\/21_qubits", - "value_param": "21", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - }, - { - "name": "UnitaryTransformation\/26_qubits", - "value_param": "26", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - }, - { - "name": "UnitaryTransformation\/31_qubits", - "value_param": "31", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - }, - { - "name": "UnitaryTransformation\/36_qubits", - "value_param": "36", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - }, - { - "name": "UnitaryTransformation\/41_qubits", - "value_param": "41", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - }, - { - "name": "UnitaryTransformation\/46_qubits", - "value_param": "46", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - }, - { - "name": "UnitaryTransformation\/51_qubits", - "value_param": "51", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - }, - { - "name": "UnitaryTransformation\/56_qubits", - "value_param": "56", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - }, - { - "name": "UnitaryTransformation\/61_qubits", - "value_param": "61", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 412 - } - ] - }, - { - "name": "Eval\/DynamicCircuitEvalQFT", - "tests": 13, - "testsuite": [ - { - "name": "UnitaryTransformation\/1_qubit", - "value_param": "1", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - }, - { - "name": "UnitaryTransformation\/6_qubits", - "value_param": "6", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - }, - { - "name": "UnitaryTransformation\/11_qubits", - "value_param": "11", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - }, - { - "name": "UnitaryTransformation\/16_qubits", - "value_param": "16", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - }, - { - "name": "UnitaryTransformation\/21_qubits", - "value_param": "21", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - }, - { - "name": "UnitaryTransformation\/26_qubits", - "value_param": "26", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - }, - { - "name": "UnitaryTransformation\/31_qubits", - "value_param": "31", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - }, - { - "name": "UnitaryTransformation\/36_qubits", - "value_param": "36", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - }, - { - "name": "UnitaryTransformation\/41_qubits", - "value_param": "41", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - }, - { - "name": "UnitaryTransformation\/46_qubits", - "value_param": "46", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - }, - { - "name": "UnitaryTransformation\/51_qubits", - "value_param": "51", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - }, - { - "name": "UnitaryTransformation\/56_qubits", - "value_param": "56", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - }, - { - "name": "UnitaryTransformation\/61_qubits", - "value_param": "61", - "file": "\/workspaces\/core\/test\/algorithms\/eval_dynamic_circuits.cpp", - "line": 525 - } - ] - } - ] -} diff --git a/test/circuit_optimizer/cmake_test_discovery_02ef7f1542.json b/test/circuit_optimizer/cmake_test_discovery_02ef7f1542.json deleted file mode 100644 index 57f91f3191..0000000000 --- a/test/circuit_optimizer/cmake_test_discovery_02ef7f1542.json +++ /dev/null @@ -1,646 +0,0 @@ -{ - "tests": 110, - "name": "AllTests", - "testsuites": [ - { - "name": "SwapReconstruction", - "tests": 3, - "testsuite": [ - { - "name": "fuseCxToSwap", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_swap_reconstruction.cpp", - "line": 20 - }, - { - "name": "replaceCxToSwapAtEnd", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_swap_reconstruction.cpp", - "line": 34 - }, - { - "name": "replaceCxToSwap", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_swap_reconstruction.cpp", - "line": 55 - } - ] - }, - { - "name": "SingleQubitGateFusion", - "tests": 7, - "testsuite": [ - { - "name": "CollapseCompoundOperationToStandard", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_single_qubit_gate_fusion.cpp", - "line": 21 - }, - { - "name": "eliminateCompoundOperation", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_single_qubit_gate_fusion.cpp", - "line": 35 - }, - { - "name": "eliminateInverseInCompoundOperation", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_single_qubit_gate_fusion.cpp", - "line": 49 - }, - { - "name": "unknownInverseInCompoundOperation", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_single_qubit_gate_fusion.cpp", - "line": 63 - }, - { - "name": "repeatedCancellationInSingleQubitGateFusion", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_single_qubit_gate_fusion.cpp", - "line": 76 - }, - { - "name": "emptyCompoundGatesRemovedInSingleQubitGateFusion", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_single_qubit_gate_fusion.cpp", - "line": 92 - }, - { - "name": "SingleQubitGateCount", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_single_qubit_gate_fusion.cpp", - "line": 107 - } - ] - }, - { - "name": "ReplaceMCXwithMCZ", - "tests": 4, - "testsuite": [ - { - "name": "replaceCXwithCZ", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_replace_mcx_with_mcz.cpp", - "line": 23 - }, - { - "name": "replaceCCXwithCCZ", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_replace_mcx_with_mcz.cpp", - "line": 38 - }, - { - "name": "replaceCXwithCZinCompoundOperation", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_replace_mcx_with_mcz.cpp", - "line": 56 - }, - { - "name": "testToffoliSequenceSimplification", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_replace_mcx_with_mcz.cpp", - "line": 79 - } - ] - }, - { - "name": "RemoveOperation", - "tests": 5, - "testsuite": [ - { - "name": "removeIdentities", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_operation.cpp", - "line": 22 - }, - { - "name": "removeSingleQubitGates", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_operation.cpp", - "line": 38 - }, - { - "name": "removeMultiQubitGates", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_operation.cpp", - "line": 53 - }, - { - "name": "removeMoves", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_operation.cpp", - "line": 68 - }, - { - "name": "removeGateInCompoundOperation", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_operation.cpp", - "line": 82 - } - ] - }, - { - "name": "RemoveFinalMeasurements", - "tests": 7, - "testsuite": [ - { - "name": "removeFinalMeasurements", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_final_measurements.cpp", - "line": 25 - }, - { - "name": "removeFinalMeasurementsTwoQubitMeasurement", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_final_measurements.cpp", - "line": 51 - }, - { - "name": "removeFinalMeasurementsCompound", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_final_measurements.cpp", - "line": 76 - }, - { - "name": "removeFinalMeasurementsCompoundDegraded", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_final_measurements.cpp", - "line": 104 - }, - { - "name": "removeFinalMeasurementsCompoundEmpty", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_final_measurements.cpp", - "line": 129 - }, - { - "name": "removeFinalMeasurementsWithOperationsInFront", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_final_measurements.cpp", - "line": 148 - }, - { - "name": "removeFinalMeasurementsWithBarrier", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_final_measurements.cpp", - "line": 162 - } - ] - }, - { - "name": "RemoveDiagonalGateBeforeMeasure", - "tests": 7, - "testsuite": [ - { - "name": "removeDiagonalSingleQubitBeforeMeasure", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_diagonal_gates_before_measure.cpp", - "line": 21 - }, - { - "name": "removeDiagonalCompoundOpBeforeMeasure", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_diagonal_gates_before_measure.cpp", - "line": 35 - }, - { - "name": "removeDiagonalTwoQubitGateBeforeMeasure", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_diagonal_gates_before_measure.cpp", - "line": 51 - }, - { - "name": "leaveGateBeforeMeasure", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_diagonal_gates_before_measure.cpp", - "line": 65 - }, - { - "name": "removeComplexGateBeforeMeasure", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_diagonal_gates_before_measure.cpp", - "line": 79 - }, - { - "name": "removeSimpleCompoundOpBeforeMeasure", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_diagonal_gates_before_measure.cpp", - "line": 100 - }, - { - "name": "removePartOfCompoundOpBeforeMeasure", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_remove_diagonal_gates_before_measure.cpp", - "line": 115 - } - ] - }, - { - "name": "FlattenOperations", - "tests": 3, - "testsuite": [ - { - "name": "FlattenRandomClifford", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_flatten_operations.cpp", - "line": 27 - }, - { - "name": "FlattenRecursive", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_flatten_operations.cpp", - "line": 41 - }, - { - "name": "FlattenCustomOnly", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_flatten_operations.cpp", - "line": 72 - } - ] - }, - { - "name": "EliminateResets", - "tests": 5, - "testsuite": [ - { - "name": "basicTest", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_eliminate_resets.cpp", - "line": 26 - }, - { - "name": "testIf", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_eliminate_resets.cpp", - "line": 84 - }, - { - "name": "testIfElse", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_eliminate_resets.cpp", - "line": 134 - }, - { - "name": "testMultipleTargetReset", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_eliminate_resets.cpp", - "line": 191 - }, - { - "name": "testCompoundOperation", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_eliminate_resets.cpp", - "line": 234 - } - ] - }, - { - "name": "ElidePermutations", - "tests": 9, - "testsuite": [ - { - "name": "emptyCircuit", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_elide_permutations.cpp", - "line": 22 - }, - { - "name": "simpleSwap", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_elide_permutations.cpp", - "line": 28 - }, - { - "name": "simpleInitialLayout", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_elide_permutations.cpp", - "line": 46 - }, - { - "name": "applyPermutationCompound", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_elide_permutations.cpp", - "line": 66 - }, - { - "name": "compoundOperation", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_elide_permutations.cpp", - "line": 85 - }, - { - "name": "compoundOperation2", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_elide_permutations.cpp", - "line": 111 - }, - { - "name": "compoundOperation3", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_elide_permutations.cpp", - "line": 133 - }, - { - "name": "compoundOperation4", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_elide_permutations.cpp", - "line": 152 - }, - { - "name": "nonUnitaryOperation", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_elide_permutations.cpp", - "line": 175 - } - ] - }, - { - "name": "DeferMeasurements", - "tests": 10, - "testsuite": [ - { - "name": "basicTestIf", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_defer_measurements.cpp", - "line": 26 - }, - { - "name": "basicTestIfElse", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_defer_measurements.cpp", - "line": 88 - }, - { - "name": "measurementBetweenMeasurementAndIfElse", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_defer_measurements.cpp", - "line": 164 - }, - { - "name": "twoIfElse", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_defer_measurements.cpp", - "line": 236 - }, - { - "name": "correctOrder", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_defer_measurements.cpp", - "line": 321 - }, - { - "name": "twoIfElseCorrectOrder", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_defer_measurements.cpp", - "line": 393 - }, - { - "name": "errorOnImplicitReset", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_defer_measurements.cpp", - "line": 477 - }, - { - "name": "errorOnMultiQubitRegister", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_defer_measurements.cpp", - "line": 500 - }, - { - "name": "preserveOutputPermutationWithoutMeasurements", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_defer_measurements.cpp", - "line": 529 - }, - { - "name": "isDynamicOnRepeatedMeasurements", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_defer_measurements.cpp", - "line": 545 - } - ] - }, - { - "name": "DecomposeSwap", - "tests": 4, - "testsuite": [ - { - "name": "decomposeSWAPsUndirectedArchitecture", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_decompose_swap.cpp", - "line": 22 - }, - { - "name": "decomposeSWAPsDirectedArchitecture", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_decompose_swap.cpp", - "line": 50 - }, - { - "name": "decomposeSWAPsCompound", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_decompose_swap.cpp", - "line": 105 - }, - { - "name": "decomposeSWAPsCompoundDirected", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_decompose_swap.cpp", - "line": 127 - } - ] - }, - { - "name": "CliffordBlocks", - "tests": 16, - "testsuite": [ - { - "name": "emptyCircuit", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 20 - }, - { - "name": "singleGate", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 26 - }, - { - "name": "largerGatethenBlock", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 36 - }, - { - "name": "CliffordBlockDepth", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 53 - }, - { - "name": "CliffordBlockWidth", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 72 - }, - { - "name": "keepOrder", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 89 - }, - { - "name": "twoCliffordBlocks", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 112 - }, - { - "name": "nonCliffordSingleQubit", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 136 - }, - { - "name": "SingleNonClifford3Qubit", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 152 - }, - { - "name": "TwoCliffordBlocks3Qubit", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 178 - }, - { - "name": "shiftedNonClifford", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 208 - }, - { - "name": "nonCliffordBeginning", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 237 - }, - { - "name": "threeQubitnonClifford", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 259 - }, - { - "name": "handleCompoundOperation", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 288 - }, - { - "name": "handleCompoundOperation2", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 312 - }, - { - "name": "barrierNotinBlock", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_clifford_blocks.cpp", - "line": 335 - } - ] - }, - { - "name": "CollectBlocks", - "tests": 15, - "testsuite": [ - { - "name": "emptyCircuit", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 19 - }, - { - "name": "singleGate", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 25 - }, - { - "name": "collectMultipleSingleQubitGates", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 35 - }, - { - "name": "mergeBlocks", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 49 - }, - { - "name": "mergeBlocks2", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 62 - }, - { - "name": "addToMultiQubitBlock", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 77 - }, - { - "name": "gateTooBig", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 89 - }, - { - "name": "gateTooBig2", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 102 - }, - { - "name": "gateTooBig3", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 115 - }, - { - "name": "endingBlocks", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 128 - }, - { - "name": "endingBlocks2", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 141 - }, - { - "name": "interruptBlock", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 154 - }, - { - "name": "unprocessableAtBegin", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 167 - }, - { - "name": "handleCompoundOperation", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 179 - }, - { - "name": "handleCompoundOperation2", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_collect_blocks.cpp", - "line": 193 - } - ] - }, - { - "name": "CancelCNOTs", - "tests": 5, - "testsuite": [ - { - "name": "CNOTCancellation1", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_cancel_cnots.cpp", - "line": 18 - }, - { - "name": "CNOTCancellation2", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_cancel_cnots.cpp", - "line": 27 - }, - { - "name": "CNOTCancellation3", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_cancel_cnots.cpp", - "line": 36 - }, - { - "name": "CNOTCancellation4", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_cancel_cnots.cpp", - "line": 54 - }, - { - "name": "CNOTCancellation5", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_cancel_cnots.cpp", - "line": 72 - } - ] - }, - { - "name": "BackpropagateOutputPermutation", - "tests": 10, - "testsuite": [ - { - "name": "FullySpecified", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_backpropagate_output_permutation.cpp", - "line": 17 - }, - { - "name": "PartiallySpecifiedQubitAvailable", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_backpropagate_output_permutation.cpp", - "line": 30 - }, - { - "name": "FullySpecifiedWithSWAP", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_backpropagate_output_permutation.cpp", - "line": 43 - }, - { - "name": "PartiallySpecifiedWithSWAP", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_backpropagate_output_permutation.cpp", - "line": 58 - }, - { - "name": "PartiallySpecifiedWithSWAP2", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_backpropagate_output_permutation.cpp", - "line": 72 - }, - { - "name": "PartiallySpecifiedWithSWAP3", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_backpropagate_output_permutation.cpp", - "line": 86 - }, - { - "name": "CompoundOperation", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_backpropagate_output_permutation.cpp", - "line": 99 - }, - { - "name": "PartiallySpecifiedNotAMissingQubit", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_backpropagate_output_permutation.cpp", - "line": 118 - }, - { - "name": "PartiallySpecifiedNotAMissingQubit2", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_backpropagate_output_permutation.cpp", - "line": 134 - }, - { - "name": "PartiallySpecifiedNotAMissingQubit3", - "file": "\/workspaces\/core\/test\/circuit_optimizer\/test_backpropagate_output_permutation.cpp", - "line": 150 - } - ] - } - ] -} diff --git a/test/dd/cmake_test_discovery_ec2b1aa6e1.json b/test/dd/cmake_test_discovery_ec2b1aa6e1.json deleted file mode 100644 index 7eddfc77c7..0000000000 --- a/test/dd/cmake_test_discovery_ec2b1aa6e1.json +++ /dev/null @@ -1,1622 +0,0 @@ -{ - "tests": 292, - "name": "AllTests", - "testsuites": [ - { - "name": "StateGenerationTest", - "tests": 23, - "testsuite": [ - { - "name": "MakeZero", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 54 - }, - { - "name": "MakeBasis", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 76 - }, - { - "name": "MakeBasisDifficult", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 101 - }, - { - "name": "MakeGHZ", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 129 - }, - { - "name": "MakeGHZZeroQubits", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 153 - }, - { - "name": "MakeW", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 166 - }, - { - "name": "MakeWZeroQubits", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 194 - }, - { - "name": "FromVectorZero", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 207 - }, - { - "name": "FromVectorScalar", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 222 - }, - { - "name": "FromVector", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 239 - }, - { - "name": "MakeZeroInvalidArguments", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 270 - }, - { - "name": "MakeBasisInvalidArguments", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 280 - }, - { - "name": "MakeGHZInvalidArguments", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 294 - }, - { - "name": "MakeWInvalidArguments", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 304 - }, - { - "name": "FromVectorInvalidArguments", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 319 - }, - { - "name": "GenerateExponential", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 335 - }, - { - "name": "GenerateExponentialWithSeed", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 362 - }, - { - "name": "GenerateRandomOneQubit", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 389 - }, - { - "name": "GenerateRandomRoundRobin", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 414 - }, - { - "name": "GenerateRandomRoundRobinWithSeed", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 446 - }, - { - "name": "GenerateRandomRandom", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 479 - }, - { - "name": "GenerateRandomRandomWithSeed", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 511 - }, - { - "name": "GenerateRandomInvalidArguments", - "file": "\/workspaces\/core\/test\/dd\/test_state_generation.cpp", - "line": 544 - } - ] - }, - { - "name": "DDPackageTest", - "tests": 96, - "testsuite": [ - { - "name": "TrivialTest", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 51 - }, - { - "name": "BellState", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 71 - }, - { - "name": "QFTState", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 138 - }, - { - "name": "CorruptedBellState", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 265 - }, - { - "name": "InvalidStandardOperation", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 286 - }, - { - "name": "PrintNoneGateType", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 305 - }, - { - "name": "NegativeControl", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 311 - }, - { - "name": "IdentityTrace", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 320 - }, - { - "name": "CNotKronTrace", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 327 - }, - { - "name": "PartialIdentityTrace", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 335 - }, - { - "name": "PartialSWapMatTrace", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 342 - }, - { - "name": "PartialTraceKeepInnerQubits", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 355 - }, - { - "name": "TraceComplexity", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 380 - }, - { - "name": "KeepBottomQubitsPartialTraceComplexity", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 398 - }, - { - "name": "PartialTraceComplexity", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 427 - }, - { - "name": "StateGenerationManipulation", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 459 - }, - { - "name": "VectorSerializationTest", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 475 - }, - { - "name": "BellMatrix", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 495 - }, - { - "name": "MatrixSerializationTest", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 577 - }, - { - "name": "SerializationErrors", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 597 - }, - { - "name": "Ancillaries", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 648 - }, - { - "name": "GarbageVector", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 684 - }, - { - "name": "GarbageMatrix", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 718 - }, - { - "name": "ReduceGarbageVector", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 755 - }, - { - "name": "ReduceGarbageVectorTGate", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 777 - }, - { - "name": "ReduceGarbageMatrix", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 798 - }, - { - "name": "ReduceGarbageMatrix2", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 839 - }, - { - "name": "ReduceGarbageMatrixNoGarbage", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 872 - }, - { - "name": "ReduceGarbageMatrixTGate", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 891 - }, - { - "name": "InvalidMakeBasisStateAndGate", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 917 - }, - { - "name": "PackageReset", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 923 - }, - { - "name": "ResetClearsRoots", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 945 - }, - { - "name": "DuplicatetrackDoesNotLeaveStaleRoot", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 966 - }, - { - "name": "Inverse", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 996 - }, - { - "name": "trackTwiceThenuntrackTwice", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1015 - }, - { - "name": "UniqueTableAllocation", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1044 - }, - { - "name": "SpecialCaseTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1067 - }, - { - "name": "KroneckerProduct", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1101 - }, - { - "name": "KroneckerProductVectors", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1119 - }, - { - "name": "KroneckerIdentityHandling", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1128 - }, - { - "name": "NearZeroNormalize", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1150 - }, - { - "name": "DestructiveMeasurementAll", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1207 - }, - { - "name": "DestructiveMeasurementOne", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1232 - }, - { - "name": "ExportPolarPhaseFormatted", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1253 - }, - { - "name": "BasicNumericInstabilityTest", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1322 - }, - { - "name": "BasicNumericStabilityTest", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1376 - }, - { - "name": "NormalizationNumericStabilityTest", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1405 - }, - { - "name": "FidelityOfMeasurementOutcomes", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1421 - }, - { - "name": "CloseToIdentity", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1439 - }, - { - "name": "CloseToIdentityWithGarbageAtTheBeginning", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1472 - }, - { - "name": "CloseToIdentityWithGarbageAtTheEnd", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1497 - }, - { - "name": "CloseToIdentityWithGarbageInTheMiddle", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1526 - }, - { - "name": "calCulpDistance", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1555 - }, - { - "name": "stateFromVectorBell", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1564 - }, - { - "name": "stateFromVectorEmpty", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1586 - }, - { - "name": "stateFromVectorNoPowerOfTwo", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1592 - }, - { - "name": "stateFromScalar", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1598 - }, - { - "name": "expectationValueGlobalOperators", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1606 - }, - { - "name": "expectationValueLocalOperators", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1636 - }, - { - "name": "expectationValueExceptions", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1656 - }, - { - "name": "DDFromSingleQubitMatrix", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1666 - }, - { - "name": "DDFromTwoQubitMatrix", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1677 - }, - { - "name": "DDFromTwoQubitAsymmetricalMatrix", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1689 - }, - { - "name": "DDFromThreeQubitMatrix", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1703 - }, - { - "name": "DDFromEmptyMatrix", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1719 - }, - { - "name": "DDFromNonPowerOfTwoMatrix", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1727 - }, - { - "name": "DDFromNonSquareMatrix", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1735 - }, - { - "name": "DDFromSingleElementMatrix", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1743 - }, - { - "name": "TwoQubitControlledGateDDConstruction", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1757 - }, - { - "name": "TwoQubitControlledGateDDConstructionNegativeControls", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1784 - }, - { - "name": "SWAPGateDDConstruction", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1821 - }, - { - "name": "PeresGateDDConstruction", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1844 - }, - { - "name": "iSWAPGateDDConstruction", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1875 - }, - { - "name": "DCXGateDDConstruction", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1930 - }, - { - "name": "RZZGateDDConstruction", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1951 - }, - { - "name": "RYYGateDDConstruction", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 1993 - }, - { - "name": "RXXGateDDConstruction", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2040 - }, - { - "name": "RZXGateDDConstruction", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2083 - }, - { - "name": "ECRGateDDConstruction", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2124 - }, - { - "name": "XXMinusYYGateDDConstruction", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2151 - }, - { - "name": "XXPlusYYGateDDConstruction", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2217 - }, - { - "name": "InnerProductTopNodeConjugation", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2281 - }, - { - "name": "DDNodeLeakRegressionTest", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2306 - }, - { - "name": "CTPerformanceRegressionTest", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2323 - }, - { - "name": "DataStructureStatistics", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2342 - }, - { - "name": "DDStatistics", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2359 - }, - { - "name": "ReduceAncillaRegression", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2383 - }, - { - "name": "VectorConjugate", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2398 - }, - { - "name": "ReduceAncillaIdentity", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2427 - }, - { - "name": "ReduceAncillaIdentityBeforeFirstNode", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2439 - }, - { - "name": "ReduceAncillaIdentityAfterLastNode", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2453 - }, - { - "name": "ReduceAncillaIdentityBetweenTwoNodes", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2466 - }, - { - "name": "ReduceGarbageIdentity", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2483 - }, - { - "name": "ReduceGarbageIdentityBeforeFirstNode", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2500 - }, - { - "name": "ReduceGarbageIdentityAfterLastNode", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2520 - }, - { - "name": "ReduceGarbageIdentityBetweenTwoNodes", - "file": "\/workspaces\/core\/test\/dd\/test_package.cpp", - "line": 2540 - } - ] - }, - { - "name": "VectorFunctionality", - "tests": 15, - "testsuite": [ - { - "name": "GetValueByPathTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 29 - }, - { - "name": "GetValueByIndexTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 34 - }, - { - "name": "GetValueByIndexEndianness", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 39 - }, - { - "name": "GetVectorTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 50 - }, - { - "name": "GetVectorRoundtrip", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 55 - }, - { - "name": "GetVectorTolerance", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 64 - }, - { - "name": "GetSparseVectorTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 76 - }, - { - "name": "GetSparseVectorConsistency", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 83 - }, - { - "name": "GetSparseVectorTolerance", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 95 - }, - { - "name": "PrintVectorTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 110 - }, - { - "name": "PrintVector", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 121 - }, - { - "name": "AddToVectorTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 133 - }, - { - "name": "AddToVector", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 139 - }, - { - "name": "SizeTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 150 - }, - { - "name": "SizeBellState", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 155 - } - ] - }, - { - "name": "MatrixFunctionality", - "tests": 13, - "testsuite": [ - { - "name": "GetValueByPathTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 166 - }, - { - "name": "GetValueByIndexTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 171 - }, - { - "name": "GetValueByIndexEndianness", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 176 - }, - { - "name": "GetMatrixTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 198 - }, - { - "name": "GetMatrixRoundtrip", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 203 - }, - { - "name": "GetMatrixTolerance", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 225 - }, - { - "name": "GetSparseMatrixTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 254 - }, - { - "name": "GetSparseMatrixConsistency", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 261 - }, - { - "name": "GetSparseMatrixTolerance", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 281 - }, - { - "name": "PrintMatrixTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 308 - }, - { - "name": "PrintMatrix", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 319 - }, - { - "name": "SizeTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 339 - }, - { - "name": "SizeBellState", - "file": "\/workspaces\/core\/test\/dd\/test_edge_functionality.cpp", - "line": 344 - } - ] - }, - { - "name": "DDFunctionality", - "tests": 12, - "testsuite": [ - { - "name": "BuildCircuit", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 245 - }, - { - "name": "NonUnitary", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 342 - }, - { - "name": "CircuitEquivalence", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 369 - }, - { - "name": "ChangePermutation", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 399 - }, - { - "name": "FuseTwoSingleQubitGates", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 424 - }, - { - "name": "FuseThreeSingleQubitGates", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 455 - }, - { - "name": "FuseNoSingleQubitGates", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 489 - }, - { - "name": "FuseSingleQubitGatesAcrossOtherGates", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 523 - }, - { - "name": "IfElseOperationConditions", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 556 - }, - { - "name": "IfElseOperationElseBranch", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 584 - }, - { - "name": "VectorKroneckerWithTerminal", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 601 - }, - { - "name": "DynamicCircuitSimulationWithSWAP", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 620 - } - ] - }, - { - "name": "CNTest", - "tests": 18, - "testsuite": [ - { - "name": "ComplexNumberCreation", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 42 - }, - { - "name": "NearZeroLookup", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 77 - }, - { - "name": "SortedBuckets", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 82 - }, - { - "name": "GarbageCollectSomeInBucket", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 114 - }, - { - "name": "LookupInNeighbouringBuckets", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 148 - }, - { - "name": "NumberPrintingToString", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 248 - }, - { - "name": "ComplexTableAllocation", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 427 - }, - { - "name": "DoubleHitInFindOrInsert", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 459 - }, - { - "name": "DoubleHitAcrossBuckets", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 478 - }, - { - "name": "exactlyZeroComparison", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 505 - }, - { - "name": "exactlyOneComparison", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 512 - }, - { - "name": "ExportConditionalFormat1", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 519 - }, - { - "name": "ExportConditionalFormat2", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 523 - }, - { - "name": "ExportConditionalFormat3", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 527 - }, - { - "name": "ExportConditionalFormat4", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 531 - }, - { - "name": "ExportConditionalFormat5", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 535 - }, - { - "name": "ExportConditionalFormat6", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 541 - }, - { - "name": "ExportConditionalFormat7", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 545 - } - ] - }, - { - "name": "DDComplexTest", - "tests": 5, - "testsuite": [ - { - "name": "LowestFractions", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 236 - }, - { - "name": "NumberPrintingFormattedFractions", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 265 - }, - { - "name": "NumberPrintingFormattedFractionsSqrt", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 325 - }, - { - "name": "NumberPrintingFormattedFractionsPi", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 371 - }, - { - "name": "NumberPrintingFormattedFloating", - "file": "\/workspaces\/core\/test\/dd\/test_complex.cpp", - "line": 417 - } - ] - }, - { - "name": "ApproximationTest", - "tests": 8, - "testsuite": [ - { - "name": "OneQubitKeepAllBudgetZero", - "file": "\/workspaces\/core\/test\/dd\/test_approximations.cpp", - "line": 45 - }, - { - "name": "OneQubitKeepAllBudgetTooSmall", - "file": "\/workspaces\/core\/test\/dd\/test_approximations.cpp", - "line": 78 - }, - { - "name": "OneQubitRemoveTerminalEdge", - "file": "\/workspaces\/core\/test\/dd\/test_approximations.cpp", - "line": 111 - }, - { - "name": "TwoQubitRemoveNode", - "file": "\/workspaces\/core\/test\/dd\/test_approximations.cpp", - "line": 144 - }, - { - "name": "TwoQubitCorrectlyRebuilt", - "file": "\/workspaces\/core\/test\/dd\/test_approximations.cpp", - "line": 190 - }, - { - "name": "ThreeQubitRemoveNodeWithChildren", - "file": "\/workspaces\/core\/test\/dd\/test_approximations.cpp", - "line": 241 - }, - { - "name": "ThreeQubitRemoveUnconnected", - "file": "\/workspaces\/core\/test\/dd\/test_approximations.cpp", - "line": 287 - }, - { - "name": "NodesVisited", - "file": "\/workspaces\/core\/test\/dd\/test_approximations.cpp", - "line": 334 - } - ] - }, - { - "name": "Parameters\/DDFunctionality", - "tests": 102, - "testsuite": [ - { - "name": "StandardOpBuildInverseBuild\/gphase", - "value_param": "gphase", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/i", - "value_param": "i", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/h", - "value_param": "h", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/x", - "value_param": "x", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/y", - "value_param": "y", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/z", - "value_param": "z", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/s", - "value_param": "s", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/sdg", - "value_param": "sdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/t", - "value_param": "t", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/tdg", - "value_param": "tdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/sx", - "value_param": "sx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/sxdg", - "value_param": "sxdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/v", - "value_param": "v", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/vdg", - "value_param": "vdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/u", - "value_param": "u", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/u2", - "value_param": "u2", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/p", - "value_param": "p", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/r", - "value_param": "r", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/rx", - "value_param": "rx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/ry", - "value_param": "ry", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/rz", - "value_param": "rz", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/peres", - "value_param": "peres", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/peresdg", - "value_param": "peresdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/swap", - "value_param": "swap", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/iswap", - "value_param": "iswap", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/iswapdg", - "value_param": "iswapdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/dcx", - "value_param": "dcx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/ecr", - "value_param": "ecr", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/rxx", - "value_param": "rxx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/ryy", - "value_param": "ryy", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/rzz", - "value_param": "rzz", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/rzx", - "value_param": "rzx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/xx_minus_yy", - "value_param": "xx_minus_yy", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "StandardOpBuildInverseBuild\/xx_plus_yy", - "value_param": "xx_plus_yy", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 73 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/gphase", - "value_param": "gphase", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/i", - "value_param": "i", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/h", - "value_param": "h", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/x", - "value_param": "x", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/y", - "value_param": "y", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/z", - "value_param": "z", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/s", - "value_param": "s", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/sdg", - "value_param": "sdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/t", - "value_param": "t", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/tdg", - "value_param": "tdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/sx", - "value_param": "sx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/sxdg", - "value_param": "sxdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/v", - "value_param": "v", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/vdg", - "value_param": "vdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/u", - "value_param": "u", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/u2", - "value_param": "u2", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/p", - "value_param": "p", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/r", - "value_param": "r", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/rx", - "value_param": "rx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/ry", - "value_param": "ry", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/rz", - "value_param": "rz", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/peres", - "value_param": "peres", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/peresdg", - "value_param": "peresdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/swap", - "value_param": "swap", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/iswap", - "value_param": "iswap", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/iswapdg", - "value_param": "iswapdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/dcx", - "value_param": "dcx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/ecr", - "value_param": "ecr", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/rxx", - "value_param": "rxx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/ryy", - "value_param": "ryy", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/rzz", - "value_param": "rzz", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/rzx", - "value_param": "rzx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/xx_minus_yy", - "value_param": "xx_minus_yy", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardOpBuildInverseBuild\/xx_plus_yy", - "value_param": "xx_plus_yy", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 129 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/gphase", - "value_param": "gphase", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/i", - "value_param": "i", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/h", - "value_param": "h", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/x", - "value_param": "x", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/y", - "value_param": "y", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/z", - "value_param": "z", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/s", - "value_param": "s", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/sdg", - "value_param": "sdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/t", - "value_param": "t", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/tdg", - "value_param": "tdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/sx", - "value_param": "sx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/sxdg", - "value_param": "sxdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/v", - "value_param": "v", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/vdg", - "value_param": "vdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/u", - "value_param": "u", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/u2", - "value_param": "u2", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/p", - "value_param": "p", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/r", - "value_param": "r", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/rx", - "value_param": "rx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/ry", - "value_param": "ry", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/rz", - "value_param": "rz", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/peres", - "value_param": "peres", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/peresdg", - "value_param": "peresdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/swap", - "value_param": "swap", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/iswap", - "value_param": "iswap", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/iswapdg", - "value_param": "iswapdg", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/dcx", - "value_param": "dcx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/ecr", - "value_param": "ecr", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/rxx", - "value_param": "rxx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/ryy", - "value_param": "ryy", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/rzz", - "value_param": "rzz", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/rzx", - "value_param": "rzx", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/xx_minus_yy", - "value_param": "xx_minus_yy", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - }, - { - "name": "ControlledStandardNegOpBuildInverseBuild\/xx_plus_yy", - "value_param": "xx_plus_yy", - "file": "\/workspaces\/core\/test\/dd\/test_dd_functionality.cpp", - "line": 186 - } - ] - } - ] -} diff --git a/test/fomac/cmake_test_discovery_d92b282818.json b/test/fomac/cmake_test_discovery_d92b282818.json deleted file mode 100644 index ddb07275fa..0000000000 --- a/test/fomac/cmake_test_discovery_d92b282818.json +++ /dev/null @@ -1,919 +0,0 @@ -{ - "tests": 149, - "name": "AllTests", - "testsuites": [ - { - "name": "FoMaCTest", - "tests": 6, - "testsuite": [ - { - "name": "StatusToString", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 111 - }, - { - "name": "SitePropertyToString", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 128 - }, - { - "name": "OperationPropertyToString", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 151 - }, - { - "name": "DevicePropertyToString", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 175 - }, - { - "name": "SessionPropertyToString", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 207 - }, - { - "name": "ThrowIfError", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 211 - } - ] - }, - { - "name": "DDSimulatorDeviceTest", - "tests": 2, - "testsuite": [ - { - "name": "SubmitJobReturnsValidJob", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 538 - }, - { - "name": "SubmitJobPreservesNumShots", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 559 - } - ] - }, - { - "name": "JobTest", - "tests": 7, - "testsuite": [ - { - "name": "IdIsUnique", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 580 - }, - { - "name": "StatusProgresses", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 593 - }, - { - "name": "GetCountsReturnsValidHistogram", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 601 - }, - { - "name": "MultipleGetCountsCalls", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 621 - }, - { - "name": "GetShotsReturnsValidShots", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 630 - }, - { - "name": "CancelJob", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 654 - }, - { - "name": "CancelCompletedJobThrows", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 680 - } - ] - }, - { - "name": "SimulatorJobTest", - "tests": 4, - "testsuite": [ - { - "name": "getDenseStateVectorReturnsValidState", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 690 - }, - { - "name": "getDenseProbabilitiesReturnsValidProbabilities", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 704 - }, - { - "name": "getSparseStateVectorReturnsValidState", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 718 - }, - { - "name": "getSparseProbabilitiesReturnsValidProbabilities", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 735 - } - ] - }, - { - "name": "AuthenticationTest", - "tests": 10, - "testsuite": [ - { - "name": "SessionParameterToString", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 751 - }, - { - "name": "SessionConstructionWithToken", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 766 - }, - { - "name": "SessionConstructionWithAuthUrl", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 783 - }, - { - "name": "SessionConstructionWithAuthFile", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 845 - }, - { - "name": "SessionConstructionWithUsernamePassword", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 871 - }, - { - "name": "SessionConstructionWithProjectId", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 889 - }, - { - "name": "SessionConstructionWithMultipleParameters", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 895 - }, - { - "name": "SessionConstructionWithCustomParameters", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 904 - }, - { - "name": "SessionGetDevicesReturnsList", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 966 - }, - { - "name": "SessionMultipleInstances", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 979 - } - ] - }, - { - "name": "DeviceTest\/DeviceTest", - "tests": 45, - "testsuite": [ - { - "name": "Name\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 237 - }, - { - "name": "Name\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 237 - }, - { - "name": "Name\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 237 - }, - { - "name": "Version\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 241 - }, - { - "name": "Version\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 241 - }, - { - "name": "Version\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 241 - }, - { - "name": "Status\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 245 - }, - { - "name": "Status\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 245 - }, - { - "name": "Status\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 245 - }, - { - "name": "LibraryVersion\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 249 - }, - { - "name": "LibraryVersion\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 249 - }, - { - "name": "LibraryVersion\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 249 - }, - { - "name": "QubitsNum\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 253 - }, - { - "name": "QubitsNum\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 253 - }, - { - "name": "QubitsNum\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 253 - }, - { - "name": "Sites\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 257 - }, - { - "name": "Sites\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 257 - }, - { - "name": "Sites\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 257 - }, - { - "name": "CouplingMap\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 261 - }, - { - "name": "CouplingMap\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 261 - }, - { - "name": "CouplingMap\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 261 - }, - { - "name": "NeedsCalibration\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 265 - }, - { - "name": "NeedsCalibration\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 265 - }, - { - "name": "NeedsCalibration\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 265 - }, - { - "name": "LengthUnit\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 269 - }, - { - "name": "LengthUnit\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 269 - }, - { - "name": "LengthUnit\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 269 - }, - { - "name": "LengthScaleFactor\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 273 - }, - { - "name": "LengthScaleFactor\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 273 - }, - { - "name": "LengthScaleFactor\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 273 - }, - { - "name": "DurationUnit\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 277 - }, - { - "name": "DurationUnit\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 277 - }, - { - "name": "DurationUnit\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 277 - }, - { - "name": "DurationScaleFactor\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 281 - }, - { - "name": "DurationScaleFactor\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 281 - }, - { - "name": "DurationScaleFactor\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 281 - }, - { - "name": "MinAtomDistance\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 285 - }, - { - "name": "MinAtomDistance\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 285 - }, - { - "name": "MinAtomDistance\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 285 - }, - { - "name": "SupportedProgramFormats\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 289 - }, - { - "name": "SupportedProgramFormats\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 289 - }, - { - "name": "SupportedProgramFormats\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 289 - }, - { - "name": "RegularSitesAndZones\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 521 - }, - { - "name": "RegularSitesAndZones\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 521 - }, - { - "name": "RegularSitesAndZones\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 521 - } - ] - }, - { - "name": "SiteTest\/SiteTest", - "tests": 39, - "testsuite": [ - { - "name": "Index\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 293 - }, - { - "name": "Index\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 293 - }, - { - "name": "Index\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 293 - }, - { - "name": "T1\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 299 - }, - { - "name": "T1\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 299 - }, - { - "name": "T1\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 299 - }, - { - "name": "T2\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 305 - }, - { - "name": "T2\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 305 - }, - { - "name": "T2\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 305 - }, - { - "name": "Name\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 311 - }, - { - "name": "Name\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 311 - }, - { - "name": "Name\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 311 - }, - { - "name": "XCoordinate\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 317 - }, - { - "name": "XCoordinate\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 317 - }, - { - "name": "XCoordinate\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 317 - }, - { - "name": "YCoordinate\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 323 - }, - { - "name": "YCoordinate\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 323 - }, - { - "name": "YCoordinate\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 323 - }, - { - "name": "ZCoordinate\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 329 - }, - { - "name": "ZCoordinate\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 329 - }, - { - "name": "ZCoordinate\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 329 - }, - { - "name": "IsZone\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 335 - }, - { - "name": "IsZone\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 335 - }, - { - "name": "IsZone\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 335 - }, - { - "name": "XExtent\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 341 - }, - { - "name": "XExtent\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 341 - }, - { - "name": "XExtent\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 341 - }, - { - "name": "YExtent\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 347 - }, - { - "name": "YExtent\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 347 - }, - { - "name": "YExtent\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 347 - }, - { - "name": "ZExtent\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 353 - }, - { - "name": "ZExtent\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 353 - }, - { - "name": "ZExtent\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 353 - }, - { - "name": "ModuleIndex\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 359 - }, - { - "name": "ModuleIndex\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 359 - }, - { - "name": "ModuleIndex\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 359 - }, - { - "name": "SubmoduleIndex\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 365 - }, - { - "name": "SubmoduleIndex\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 365 - }, - { - "name": "SubmoduleIndex\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 365 - } - ] - }, - { - "name": "OperationTest\/OperationTest", - "tests": 36, - "testsuite": [ - { - "name": "Name\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 371 - }, - { - "name": "Name\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 371 - }, - { - "name": "Name\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 371 - }, - { - "name": "QubitsNum\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 377 - }, - { - "name": "QubitsNum\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 377 - }, - { - "name": "QubitsNum\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 377 - }, - { - "name": "ParametersNum\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 383 - }, - { - "name": "ParametersNum\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 383 - }, - { - "name": "ParametersNum\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 383 - }, - { - "name": "Duration\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 389 - }, - { - "name": "Duration\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 389 - }, - { - "name": "Duration\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 389 - }, - { - "name": "Fidelity\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 425 - }, - { - "name": "Fidelity\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 425 - }, - { - "name": "Fidelity\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 425 - }, - { - "name": "InteractionRadius\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 461 - }, - { - "name": "InteractionRadius\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 461 - }, - { - "name": "InteractionRadius\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 461 - }, - { - "name": "BlockingRadius\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 467 - }, - { - "name": "BlockingRadius\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 467 - }, - { - "name": "BlockingRadius\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 467 - }, - { - "name": "IdlingFidelity\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 473 - }, - { - "name": "IdlingFidelity\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 473 - }, - { - "name": "IdlingFidelity\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 473 - }, - { - "name": "IsZoned\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 479 - }, - { - "name": "IsZoned\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 479 - }, - { - "name": "IsZoned\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 479 - }, - { - "name": "Sites\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 485 - }, - { - "name": "Sites\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 485 - }, - { - "name": "Sites\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 485 - }, - { - "name": "SitePairs\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 491 - }, - { - "name": "SitePairs\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 491 - }, - { - "name": "SitePairs\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 491 - }, - { - "name": "MeanShuttlingSpeed\/MQT_NA_Default_QDMI_Device", - "value_param": "0x625fbfe62310", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 515 - }, - { - "name": "MeanShuttlingSpeed\/MQT_SC_Default_QDMI_Device", - "value_param": "0x625fbfe67d10", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 515 - }, - { - "name": "MeanShuttlingSpeed\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "0x625fbfe73520", - "file": "\/workspaces\/core\/test\/fomac\/test_fomac.cpp", - "line": 515 - } - ] - } - ] -} diff --git a/test/na/cmake_test_discovery_250b2f6e91.json b/test/na/cmake_test_discovery_250b2f6e91.json deleted file mode 100644 index f303f78e7f..0000000000 --- a/test/na/cmake_test_discovery_250b2f6e91.json +++ /dev/null @@ -1,138 +0,0 @@ -{ - "tests": 24, - "name": "AllTests", - "testsuites": [ - { - "name": "NAComputation", - "tests": 10, - "testsuite": [ - { - "name": "Atom", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 32 - }, - { - "name": "Zone", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 40 - }, - { - "name": "ZonesExtent", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 47 - }, - { - "name": "Location", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 55 - }, - { - "name": "LocalRXOp", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 66 - }, - { - "name": "LocalRZOp", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 72 - }, - { - "name": "General", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 78 - }, - { - "name": "EmptyPrint", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 126 - }, - { - "name": "GetPositionOfAtomAfterOperation", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 249 - }, - { - "name": "NonMovingAtomsViolateRowOrderConstraint", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 260 - } - ] - }, - { - "name": "NAComputationValidateAODConstraints", - "tests": 14, - "testsuite": [ - { - "name": "AtomAlreadyLoaded", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 157 - }, - { - "name": "AtomNotLoaded", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 165 - }, - { - "name": "DuplicateAtomsInShuttle", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 169 - }, - { - "name": "DuplicateEndPoints", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 176 - }, - { - "name": "ColumnPreserving1", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 183 - }, - { - "name": "RowPreserving1", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 190 - }, - { - "name": "ColumnPreserving2", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 197 - }, - { - "name": "RowPreserving2", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 204 - }, - { - "name": "ColumnPreserving3", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 212 - }, - { - "name": "RowPreserving3", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 219 - }, - { - "name": "DuplicateAtomsInRz", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 226 - }, - { - "name": "DuplicateAtoms", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 230 - }, - { - "name": "RowPreserving4", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 235 - }, - { - "name": "StoreStoredAtom", - "file": "\/workspaces\/core\/test\/na\/test_nacomputation.cpp", - "line": 242 - } - ] - } - ] -} diff --git a/test/na/fomac/cmake_test_discovery_d3ec408c45.json b/test/na/fomac/cmake_test_discovery_d3ec408c45.json deleted file mode 100644 index 3b5c38512b..0000000000 --- a/test/na/fomac/cmake_test_discovery_d3ec408c45.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "tests": 2, - "name": "AllTests", - "testsuites": [ - { - "name": "TestNAFoMaC", - "tests": 2, - "testsuite": [ - { - "name": "TrapsJSONRoundTrip", - "file": "\/workspaces\/core\/test\/na\/fomac\/test_fomac.cpp", - "line": 35 - }, - { - "name": "FullJSONRoundTrip", - "file": "\/workspaces\/core\/test\/na\/fomac\/test_fomac.cpp", - "line": 51 - } - ] - } - ] -} diff --git a/test/qdmi/devices/dd/cmake_test_discovery_e4d6740af8.json b/test/qdmi/devices/dd/cmake_test_discovery_e4d6740af8.json deleted file mode 100644 index 9b7f6fe272..0000000000 --- a/test/qdmi/devices/dd/cmake_test_discovery_e4d6740af8.json +++ /dev/null @@ -1,264 +0,0 @@ -{ - "tests": 36, - "name": "AllTests", - "testsuites": [ - { - "name": "DeviceStatus", - "tests": 2, - "testsuite": [ - { - "name": "TransitionsBusyThenIdleAfterJob", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/device_status_test.cpp", - "line": 35 - }, - { - "name": "MultipleConcurrentJobsKeepBusyUntilLastFinishes", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/device_status_test.cpp", - "line": 69 - } - ] - }, - { - "name": "Concurrency", - "tests": 3, - "testsuite": [ - { - "name": "ConcurrentStatevectorReads", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/concurrency_test.cpp", - "line": 27 - }, - { - "name": "ConcurrentHistogramReads", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/concurrency_test.cpp", - "line": 58 - }, - { - "name": "ConcurrentCheckDuringRun", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/concurrency_test.cpp", - "line": 97 - } - ] - }, - { - "name": "ErrorHandling", - "tests": 6, - "testsuite": [ - { - "name": "NullptrArguments", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/error_handling_test.cpp", - "line": 31 - }, - { - "name": "GetResultsBeforeDone", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/error_handling_test.cpp", - "line": 74 - }, - { - "name": "MaxEnums", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/error_handling_test.cpp", - "line": 94 - }, - { - "name": "CustomEnums", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/error_handling_test.cpp", - "line": 139 - }, - { - "name": "BadState", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/error_handling_test.cpp", - "line": 263 - }, - { - "name": "MalformedProgramFailsForBothModes", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/error_handling_test.cpp", - "line": 291 - } - ] - }, - { - "name": "ResultsProbabilities", - "tests": 2, - "testsuite": [ - { - "name": "DenseSumToOneAndBufferTooSmall", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/results_probabilities_test.cpp", - "line": 24 - }, - { - "name": "SparseSumToOneAndBufferTooSmall", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/results_probabilities_test.cpp", - "line": 52 - } - ] - }, - { - "name": "ResultsStatevector", - "tests": 3, - "testsuite": [ - { - "name": "DenseNormalizedAndBufferTooSmall", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/results_statevector_test.cpp", - "line": 25 - }, - { - "name": "SparseNormalizedAndBufferTooSmall", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/results_statevector_test.cpp", - "line": 53 - }, - { - "name": "HistogramRequestsInvalidWithShotsZero", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/results_statevector_test.cpp", - "line": 90 - } - ] - }, - { - "name": "ResultsSampling", - "tests": 3, - "testsuite": [ - { - "name": "HistogramKeysAndValuesSumToShots", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/results_sampling_test.cpp", - "line": 24 - }, - { - "name": "BufferTooSmallErrors", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/results_sampling_test.cpp", - "line": 43 - }, - { - "name": "StateAndProbRequestsAreInvalidWhenShotsPositive", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/results_sampling_test.cpp", - "line": 72 - } - ] - }, - { - "name": "JobLifecycle", - "tests": 6, - "testsuite": [ - { - "name": "SubmitAndWaitSampling", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/job_lifecycle_test.cpp", - "line": 24 - }, - { - "name": "SubmitAndWaitStatevector", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/job_lifecycle_test.cpp", - "line": 34 - }, - { - "name": "WaitInvalidBeforeSubmitAndIdempotentAfterDone", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/job_lifecycle_test.cpp", - "line": 44 - }, - { - "name": "WaitTimeoutPath", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/job_lifecycle_test.cpp", - "line": 59 - }, - { - "name": "CancelFromCreatedAndFromRunningAndFromDone", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/job_lifecycle_test.cpp", - "line": 75 - }, - { - "name": "FreeWhileRunningWaitsForCompletion", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/job_lifecycle_test.cpp", - "line": 108 - } - ] - }, - { - "name": "JobParameters", - "tests": 2, - "testsuite": [ - { - "name": "SetAndQueryBasics", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/job_parameters_test.cpp", - "line": 25 - }, - { - "name": "ProgramFormatSupport", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/job_parameters_test.cpp", - "line": 88 - } - ] - }, - { - "name": "SessionLifecycle", - "tests": 2, - "testsuite": [ - { - "name": "AllocAndInit", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/session_lifecycle_test.cpp", - "line": 23 - }, - { - "name": "InitBadStateAndInvalidArg", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/session_lifecycle_test.cpp", - "line": 28 - } - ] - }, - { - "name": "SessionParameters", - "tests": 1, - "testsuite": [ - { - "name": "SetParameterBehaviors", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/session_lifecycle_test.cpp", - "line": 41 - } - ] - }, - { - "name": "DeviceProperties", - "tests": 4, - "testsuite": [ - { - "name": "BasicStringsAndSizes", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/device_properties_test.cpp", - "line": 27 - }, - { - "name": "UnitsAndScales", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/device_properties_test.cpp", - "line": 68 - }, - { - "name": "SitesAndOperationsLists", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/device_properties_test.cpp", - "line": 113 - }, - { - "name": "QubitsNumAvailable", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/device_properties_test.cpp", - "line": 123 - } - ] - }, - { - "name": "SiteProperties", - "tests": 1, - "testsuite": [ - { - "name": "IndexAvailable", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/device_properties_test.cpp", - "line": 133 - } - ] - }, - { - "name": "OperationProperties", - "tests": 1, - "testsuite": [ - { - "name": "BasicQueries", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/dd\/device_properties_test.cpp", - "line": 151 - } - ] - } - ] -} diff --git a/test/qdmi/devices/na/cmake_test_discovery_c9108a12c6.json b/test/qdmi/devices/na/cmake_test_discovery_c9108a12c6.json deleted file mode 100644 index 873239bdcf..0000000000 --- a/test/qdmi/devices/na/cmake_test_discovery_c9108a12c6.json +++ /dev/null @@ -1,291 +0,0 @@ -{ - "tests": 51, - "name": "AllTests", - "testsuites": [ - { - "name": "NaQDMISpecificationTest", - "tests": 23, - "testsuite": [ - { - "name": "SessionAlloc", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 148 - }, - { - "name": "SessionInit", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 153 - }, - { - "name": "SessionSetParameter", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 159 - }, - { - "name": "JobCreate", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 177 - }, - { - "name": "JobSetParameter", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 194 - }, - { - "name": "JobQueryProperty", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 211 - }, - { - "name": "JobSubmit", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 241 - }, - { - "name": "JobCancel", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 250 - }, - { - "name": "JobCheck", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 260 - }, - { - "name": "JobWait", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 271 - }, - { - "name": "JobGetResults", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 282 - }, - { - "name": "QueryDeviceProperty", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 297 - }, - { - "name": "QuerySiteProperty", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 317 - }, - { - "name": "QueryOperationProperty", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 334 - }, - { - "name": "QueryDeviceName", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 350 - }, - { - "name": "QueryDeviceVersion", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 365 - }, - { - "name": "QueryDeviceLibraryVersion", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 380 - }, - { - "name": "QueryDeviceLengthUnit", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 396 - }, - { - "name": "QueryDeviceDurationUnit", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 417 - }, - { - "name": "QueryDeviceMinAtomDistance", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 438 - }, - { - "name": "QuerySiteIndex", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 446 - }, - { - "name": "QueryOperationName", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 457 - }, - { - "name": "QueryDeviceQubitNum", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 474 - } - ] - }, - { - "name": "NaQDMIJobSpecificationTest", - "tests": 8, - "testsuite": [ - { - "name": "JobSetParameter", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 200 - }, - { - "name": "JobQueryProperty", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 217 - }, - { - "name": "QueryJobId", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 226 - }, - { - "name": "JobSubmit", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 245 - }, - { - "name": "JobCancel", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 254 - }, - { - "name": "JobCheck", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 265 - }, - { - "name": "JobWait", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 276 - }, - { - "name": "JobGetResults", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 288 - } - ] - }, - { - "name": "NADeviceTest", - "tests": 2, - "testsuite": [ - { - "name": "QuerySiteData", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 510 - }, - { - "name": "QueryOperationData", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_device.cpp", - "line": 589 - } - ] - }, - { - "name": "NaExecutableTest", - "tests": 13, - "testsuite": [ - { - "name": "Version", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 31 - }, - { - "name": "MissingSubcommand", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 59 - }, - { - "name": "UnknownSubcommand", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 81 - }, - { - "name": "SchemaUnknownOption", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 103 - }, - { - "name": "SchemaMissingFile", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 125 - }, - { - "name": "ValidateInvalidJson", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 147 - }, - { - "name": "GenerateMissingFile", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 162 - }, - { - "name": "Usage", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 184 - }, - { - "name": "SchemaUsage", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 208 - }, - { - "name": "ValidateUsage", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 232 - }, - { - "name": "GenerateUsage", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 256 - }, - { - "name": "RoundTrip", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 280 - }, - { - "name": "RoundTripFile", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_app.cpp", - "line": 323 - } - ] - }, - { - "name": "NaGeneratorTest", - "tests": 5, - "testsuite": [ - { - "name": "WriteJSONSchema", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_generator.cpp", - "line": 43 - }, - { - "name": "DurationUnitNanosecond", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_generator.cpp", - "line": 55 - }, - { - "name": "DurationUnitInvalid", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_generator.cpp", - "line": 68 - }, - { - "name": "LengthUnitNanometer", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_generator.cpp", - "line": 78 - }, - { - "name": "LengthUnitInvalid", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/na\/test_generator.cpp", - "line": 91 - } - ] - } - ] -} diff --git a/test/qdmi/devices/sc/cmake_test_discovery_b685f933aa.json b/test/qdmi/devices/sc/cmake_test_discovery_b685f933aa.json deleted file mode 100644 index e0148fb5ea..0000000000 --- a/test/qdmi/devices/sc/cmake_test_discovery_b685f933aa.json +++ /dev/null @@ -1,230 +0,0 @@ -{ - "tests": 40, - "name": "AllTests", - "testsuites": [ - { - "name": "ScQDMISpecificationTest", - "tests": 18, - "testsuite": [ - { - "name": "SessionAlloc", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 93 - }, - { - "name": "SessionInit", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 98 - }, - { - "name": "SessionSetParameter", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 104 - }, - { - "name": "JobCreate", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 123 - }, - { - "name": "JobSetParameter", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 141 - }, - { - "name": "JobQueryProperty", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 158 - }, - { - "name": "JobSubmit", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 188 - }, - { - "name": "JobCancel", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 197 - }, - { - "name": "JobCheck", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 207 - }, - { - "name": "JobWait", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 218 - }, - { - "name": "JobGetResults", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 229 - }, - { - "name": "QueryDeviceProperty", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 244 - }, - { - "name": "QuerySiteProperty", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 264 - }, - { - "name": "QueryDeviceName", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 281 - }, - { - "name": "QueryDeviceVersion", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 296 - }, - { - "name": "QueryDeviceLibraryVersion", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 311 - }, - { - "name": "QuerySiteIndex", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 327 - }, - { - "name": "QueryDeviceQubitNum", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 338 - } - ] - }, - { - "name": "ScQDMIJobSpecificationTest", - "tests": 8, - "testsuite": [ - { - "name": "JobSetParameter", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 147 - }, - { - "name": "JobQueryProperty", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 164 - }, - { - "name": "QueryJobId", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 173 - }, - { - "name": "JobSubmit", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 192 - }, - { - "name": "JobCancel", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 201 - }, - { - "name": "JobCheck", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 212 - }, - { - "name": "JobWait", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 223 - }, - { - "name": "JobGetResults", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_device.cpp", - "line": 235 - } - ] - }, - { - "name": "ScExecutableTest", - "tests": 13, - "testsuite": [ - { - "name": "Version", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 31 - }, - { - "name": "MissingSubcommand", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 59 - }, - { - "name": "UnknownSubcommand", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 81 - }, - { - "name": "SchemaUnknownOption", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 103 - }, - { - "name": "SchemaMissingFile", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 125 - }, - { - "name": "ValidateInvalidJson", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 147 - }, - { - "name": "GenerateMissingFile", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 162 - }, - { - "name": "Usage", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 184 - }, - { - "name": "SchemaUsage", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 208 - }, - { - "name": "ValidateUsage", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 232 - }, - { - "name": "GenerateUsage", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 256 - }, - { - "name": "RoundTrip", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 280 - }, - { - "name": "RoundTripFile", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_app.cpp", - "line": 323 - } - ] - }, - { - "name": "ScGeneratorTest", - "tests": 1, - "testsuite": [ - { - "name": "WriteJSONSchema", - "file": "\/workspaces\/core\/test\/qdmi\/devices\/sc\/test_generator.cpp", - "line": 41 - } - ] - } - ] -} diff --git a/test/qdmi/driver/cmake_test_discovery_19da466dc8.json b/test/qdmi/driver/cmake_test_discovery_19da466dc8.json deleted file mode 100644 index 6a6f038f57..0000000000 --- a/test/qdmi/driver/cmake_test_discovery_19da466dc8.json +++ /dev/null @@ -1,574 +0,0 @@ -{ - "tests": 92, - "name": "AllTests", - "testsuites": [ - { - "name": "DeviceSessionConfigTest", - "tests": 7, - "testsuite": [ - { - "name": "AddDynamicDeviceLibraryWithBaseUrl", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 522 - }, - { - "name": "AddDynamicDeviceLibraryWithCustomParameters", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 532 - }, - { - "name": "AddDynamicDeviceLibraryWithAuthToken", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 556 - }, - { - "name": "AddDynamicDeviceLibraryWithAuthFile", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 567 - }, - { - "name": "AddDynamicDeviceLibraryWithUsernamePassword", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 579 - }, - { - "name": "AddDynamicDeviceLibraryWithAllParameters", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 591 - }, - { - "name": "IdempotentLoadingWithDifferentConfigs", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 621 - } - ] - }, - { - "name": "DynamicDeviceLibraryTest", - "tests": 1, - "testsuite": [ - { - "name": "addDynamicDeviceLibraryReturnsDevice", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 654 - } - ] - }, - { - "name": "DefaultDevices\/DriverTest", - "tests": 63, - "testsuite": [ - { - "name": "SessionSetParameter\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 127 - }, - { - "name": "SessionSetParameter\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 127 - }, - { - "name": "SessionSetParameter\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 127 - }, - { - "name": "JobCreate\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 146 - }, - { - "name": "JobCreate\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 146 - }, - { - "name": "JobCreate\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 146 - }, - { - "name": "JobSetParameter\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 154 - }, - { - "name": "JobSetParameter\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 154 - }, - { - "name": "JobSetParameter\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 154 - }, - { - "name": "JobQueryProperty\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 175 - }, - { - "name": "JobQueryProperty\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 175 - }, - { - "name": "JobQueryProperty\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 175 - }, - { - "name": "JobSubmit\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 215 - }, - { - "name": "JobSubmit\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 215 - }, - { - "name": "JobSubmit\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 215 - }, - { - "name": "JobCancel\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 224 - }, - { - "name": "JobCancel\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 224 - }, - { - "name": "JobCancel\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 224 - }, - { - "name": "JobCheck\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 234 - }, - { - "name": "JobCheck\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 234 - }, - { - "name": "JobCheck\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 234 - }, - { - "name": "JobWait\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 244 - }, - { - "name": "JobWait\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 244 - }, - { - "name": "JobWait\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 244 - }, - { - "name": "JobGetResults\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 254 - }, - { - "name": "JobGetResults\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 254 - }, - { - "name": "JobGetResults\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 254 - }, - { - "name": "QueryDeviceProperty\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 267 - }, - { - "name": "QueryDeviceProperty\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 267 - }, - { - "name": "QueryDeviceProperty\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 267 - }, - { - "name": "QuerySiteProperty\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 276 - }, - { - "name": "QuerySiteProperty\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 276 - }, - { - "name": "QuerySiteProperty\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 276 - }, - { - "name": "QueryOperationProperty\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 285 - }, - { - "name": "QueryOperationProperty\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 285 - }, - { - "name": "QueryOperationProperty\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 285 - }, - { - "name": "QueryDeviceVersion\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 296 - }, - { - "name": "QueryDeviceVersion\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 296 - }, - { - "name": "QueryDeviceVersion\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 296 - }, - { - "name": "QueryDeviceLibraryVersion\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 311 - }, - { - "name": "QueryDeviceLibraryVersion\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 311 - }, - { - "name": "QueryDeviceLibraryVersion\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 311 - }, - { - "name": "QueryNumQubits\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 326 - }, - { - "name": "QueryNumQubits\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 326 - }, - { - "name": "QueryNumQubits\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 326 - }, - { - "name": "QuerySites\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 336 - }, - { - "name": "QuerySites\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 336 - }, - { - "name": "QuerySites\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 336 - }, - { - "name": "QueryOperations\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 380 - }, - { - "name": "QueryOperations\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 380 - }, - { - "name": "QueryOperations\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 380 - }, - { - "name": "SessionAlloc\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 455 - }, - { - "name": "SessionAlloc\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 455 - }, - { - "name": "SessionAlloc\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 455 - }, - { - "name": "SessionInit\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 459 - }, - { - "name": "SessionInit\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 459 - }, - { - "name": "SessionInit\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 459 - }, - { - "name": "QuerySessionProperty\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 466 - }, - { - "name": "QuerySessionProperty\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 466 - }, - { - "name": "QuerySessionProperty\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 466 - }, - { - "name": "QueryNeedsCalibration\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 493 - }, - { - "name": "QueryNeedsCalibration\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 493 - }, - { - "name": "QueryNeedsCalibration\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 493 - } - ] - }, - { - "name": "DefaultDevices\/DriverJobTest", - "tests": 21, - "testsuite": [ - { - "name": "JobSetParameter\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 159 - }, - { - "name": "JobSetParameter\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 159 - }, - { - "name": "JobSetParameter\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 159 - }, - { - "name": "JobQueryProperty\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 181 - }, - { - "name": "JobQueryProperty\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 181 - }, - { - "name": "JobQueryProperty\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 181 - }, - { - "name": "JobSubmit\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 219 - }, - { - "name": "JobSubmit\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 219 - }, - { - "name": "JobSubmit\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 219 - }, - { - "name": "JobCancel\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 228 - }, - { - "name": "JobCancel\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 228 - }, - { - "name": "JobCancel\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 228 - }, - { - "name": "JobCheck\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 238 - }, - { - "name": "JobCheck\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 238 - }, - { - "name": "JobCheck\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 238 - }, - { - "name": "JobWait\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 248 - }, - { - "name": "JobWait\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 248 - }, - { - "name": "JobWait\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 248 - }, - { - "name": "JobGetResults\/MQT_NA_Default_QDMI_Device", - "value_param": "\"MQT NA Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 260 - }, - { - "name": "JobGetResults\/MQT_Core_DDSIM_QDMI_Device", - "value_param": "\"MQT Core DDSIM QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 260 - }, - { - "name": "JobGetResults\/MQT_SC_Default_QDMI_Device", - "value_param": "\"MQT SC Default QDMI Device\"", - "file": "\/workspaces\/core\/test\/qdmi\/driver\/test_driver.cpp", - "line": 260 - } - ] - } - ] -} diff --git a/test/qir/runner/cmake_test_discovery_f490d2a913.json b/test/qir/runner/cmake_test_discovery_f490d2a913.json deleted file mode 100644 index 1cc65c36e8..0000000000 --- a/test/qir/runner/cmake_test_discovery_f490d2a913.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "tests": 3, - "name": "AllTests", - "testsuites": [ - { - "name": "QIRRunnerTest\/QIRRunnerTest", - "tests": 3, - "testsuite": [ - { - "name": "QIRFile\/BellPairDynamic", - "value_param": "\"\/workspaces\/core\/test\/qir\/BellPairDynamic.ll\"", - "file": "\/workspaces\/core\/test\/qir\/runner\/test_qir_runner.cpp", - "line": 37 - }, - { - "name": "QIRFile\/BellPairStatic", - "value_param": "\"\/workspaces\/core\/test\/qir\/BellPairStatic.ll\"", - "file": "\/workspaces\/core\/test\/qir\/runner\/test_qir_runner.cpp", - "line": 37 - }, - { - "name": "QIRFile\/GHZ4Dynamic", - "value_param": "\"\/workspaces\/core\/test\/qir\/GHZ4Dynamic.ll\"", - "file": "\/workspaces\/core\/test\/qir\/runner\/test_qir_runner.cpp", - "line": 37 - } - ] - } - ] -} diff --git a/test/qir/runtime/cmake_test_discovery_a54bc9ca40.json b/test/qir/runtime/cmake_test_discovery_a54bc9ca40.json deleted file mode 100644 index b22ad9692f..0000000000 --- a/test/qir/runtime/cmake_test_discovery_a54bc9ca40.json +++ /dev/null @@ -1,296 +0,0 @@ -{ - "tests": 55, - "name": "AllTests", - "testsuites": [ - { - "name": "QIRRuntimeTest", - "tests": 52, - "testsuite": [ - { - "name": "XGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 45 - }, - { - "name": "YGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 51 - }, - { - "name": "ZGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 57 - }, - { - "name": "HGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 63 - }, - { - "name": "SGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 69 - }, - { - "name": "SdgGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 75 - }, - { - "name": "SXGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 81 - }, - { - "name": "SXdgGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 87 - }, - { - "name": "SqrtXGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 93 - }, - { - "name": "SqrtXdgGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 99 - }, - { - "name": "TGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 105 - }, - { - "name": "TdgGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 111 - }, - { - "name": "RGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 117 - }, - { - "name": "PRXGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 123 - }, - { - "name": "RXGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 129 - }, - { - "name": "RYGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 135 - }, - { - "name": "RZGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 141 - }, - { - "name": "PGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 147 - }, - { - "name": "RXXGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 153 - }, - { - "name": "RYYGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 160 - }, - { - "name": "RZZGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 167 - }, - { - "name": "RZXGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 174 - }, - { - "name": "UGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 181 - }, - { - "name": "U3Gate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 187 - }, - { - "name": "U2Gate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 193 - }, - { - "name": "U1Gate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 199 - }, - { - "name": "CU1Gate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 205 - }, - { - "name": "CU3Gate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 212 - }, - { - "name": "CNotGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 219 - }, - { - "name": "CXGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 226 - }, - { - "name": "CYGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 233 - }, - { - "name": "CZGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 240 - }, - { - "name": "CHGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 247 - }, - { - "name": "SwapGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 254 - }, - { - "name": "CSwapGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 269 - }, - { - "name": "CRZGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 277 - }, - { - "name": "CRYGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 284 - }, - { - "name": "CRXGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 291 - }, - { - "name": "CPGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 298 - }, - { - "name": "CCXGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 305 - }, - { - "name": "CCYGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 313 - }, - { - "name": "CCZGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 321 - }, - { - "name": "MGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 329 - }, - { - "name": "MeasureGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 335 - }, - { - "name": "MzGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 341 - }, - { - "name": "ResetGate", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 348 - }, - { - "name": "BellPairStatic", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 354 - }, - { - "name": "BellPairDynamic", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 372 - }, - { - "name": "BellPairStaticReverse", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 392 - }, - { - "name": "BellPairDynamicReverse", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 410 - }, - { - "name": "GHZ4Static", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 430 - }, - { - "name": "GHZ4Dynamic", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 459 - } - ] - }, - { - "name": "QIRExecutablesTest\/QIRFilesTest", - "tests": 3, - "testsuite": [ - { - "name": "Executables\/mqt_core_qir_bell_pair_dynamic_ll", - "value_param": "\"\/workspaces\/core\/build\/release\/test\/qir\/runtime\/mqt-core-qir-bell-pair-dynamic-ll\"", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 528 - }, - { - "name": "Executables\/mqt_core_qir_bell_pair_static_ll", - "value_param": "\"\/workspaces\/core\/build\/release\/test\/qir\/runtime\/mqt-core-qir-bell-pair-static-ll\"", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 528 - }, - { - "name": "Executables\/mqt_core_qir_g_h_z4_dynamic_ll", - "value_param": "\"\/workspaces\/core\/build\/release\/test\/qir\/runtime\/mqt-core-qir-g-h-z4-dynamic-ll\"", - "file": "\/workspaces\/core\/test\/qir\/runtime\/test_qir_runtime.cpp", - "line": 528 - } - ] - } - ] -} diff --git a/test/zx/cmake_test_discovery_de31622abe.json b/test/zx/cmake_test_discovery_de31622abe.json deleted file mode 100644 index 7e6f7b271f..0000000000 --- a/test/zx/cmake_test_discovery_de31622abe.json +++ /dev/null @@ -1,566 +0,0 @@ -{ - "tests": 106, - "name": "AllTests", - "testsuites": [ - { - "name": "ZXFunctionalityTest", - "tests": 45, - "testsuite": [ - { - "name": "parseQasm", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 64 - }, - { - "name": "complexCircuit", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 116 - }, - { - "name": "nestedCompoundGate", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 155 - }, - { - "name": "Phase", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 174 - }, - { - "name": "Compound", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 189 - }, - { - "name": "CRZ", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 207 - }, - { - "name": "CCZ", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 221 - }, - { - "name": "MCX", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 234 - }, - { - "name": "MCX0", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 245 - }, - { - "name": "MCX1", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 256 - }, - { - "name": "MCZ", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 268 - }, - { - "name": "MCZ0", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 279 - }, - { - "name": "MCZ1", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 290 - }, - { - "name": "MCZ2", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 301 - }, - { - "name": "MCRZ", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 314 - }, - { - "name": "MCRZ0", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 326 - }, - { - "name": "MCRZ1", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 337 - }, - { - "name": "UnsupportedControl", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 348 - }, - { - "name": "UnsupportedControl2", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 358 - }, - { - "name": "UnsupportedControl3", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 368 - }, - { - "name": "UnsupportedTwoTargetControl", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 378 - }, - { - "name": "InitialLayout", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 388 - }, - { - "name": "FromSymbolic", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 404 - }, - { - "name": "RZ", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 417 - }, - { - "name": "ISWAP", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 427 - }, - { - "name": "XXplusYY", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 443 - }, - { - "name": "XXminusYY", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 469 - }, - { - "name": "SWAP", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 495 - }, - { - "name": "CSWAP", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 507 - }, - { - "name": "MCSWAP", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 519 - }, - { - "name": "MCRzz", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 531 - }, - { - "name": "MCRxx", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 542 - }, - { - "name": "MCRzx", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 553 - }, - { - "name": "MCRx0", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 564 - }, - { - "name": "MCRx1", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 573 - }, - { - "name": "MCRx2", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 582 - }, - { - "name": "MCRx3", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 591 - }, - { - "name": "MCPhase", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 600 - }, - { - "name": "MCS", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 610 - }, - { - "name": "MCSdg", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 620 - }, - { - "name": "MCT", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 630 - }, - { - "name": "MCTdg", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 640 - }, - { - "name": "MCPhase2", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 650 - }, - { - "name": "MCS2", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 660 - }, - { - "name": "MCT2", - "file": "\/workspaces\/core\/test\/zx\/test_zx_functionality.cpp", - "line": 670 - } - ] - }, - { - "name": "ZXDiagramTest", - "tests": 11, - "testsuite": [ - { - "name": "createDiagram", - "file": "\/workspaces\/core\/test\/zx\/test_zx.cpp", - "line": 61 - }, - { - "name": "deletions", - "file": "\/workspaces\/core\/test\/zx\/test_zx.cpp", - "line": 105 - }, - { - "name": "graphLike", - "file": "\/workspaces\/core\/test\/zx\/test_zx.cpp", - "line": 116 - }, - { - "name": "adjoint", - "file": "\/workspaces\/core\/test\/zx\/test_zx.cpp", - "line": 151 - }, - { - "name": "approximate", - "file": "\/workspaces\/core\/test\/zx\/test_zx.cpp", - "line": 186 - }, - { - "name": "ancilla", - "file": "\/workspaces\/core\/test\/zx\/test_zx.cpp", - "line": 201 - }, - { - "name": "RemoveScalarSubDiagram", - "file": "\/workspaces\/core\/test\/zx\/test_zx.cpp", - "line": 233 - }, - { - "name": "AdjMat", - "file": "\/workspaces\/core\/test\/zx\/test_zx.cpp", - "line": 248 - }, - { - "name": "ConnectedSet", - "file": "\/workspaces\/core\/test\/zx\/test_zx.cpp", - "line": 266 - }, - { - "name": "EdgeTypePrinting", - "file": "\/workspaces\/core\/test\/zx\/test_zx.cpp", - "line": 281 - }, - { - "name": "VertexTypePrinting", - "file": "\/workspaces\/core\/test\/zx\/test_zx.cpp", - "line": 304 - } - ] - }, - { - "name": "SimplifyTest", - "tests": 19, - "testsuite": [ - { - "name": "idSimp", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 63 - }, - { - "name": "idSimp2", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 76 - }, - { - "name": "spiderFusion", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 91 - }, - { - "name": "spiderFusion2", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 110 - }, - { - "name": "spiderFusionParallelEdges", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 133 - }, - { - "name": "localComp", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 148 - }, - { - "name": "pivotPauli", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 194 - }, - { - "name": "interiorClifford", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 242 - }, - { - "name": "interiorClifford2", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 257 - }, - { - "name": "nonPauliPivot", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 287 - }, - { - "name": "pauliPivot2", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 315 - }, - { - "name": "gadgetSimp", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 335 - }, - { - "name": "gadgetSimp2", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 367 - }, - { - "name": "fullReduce2", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 392 - }, - { - "name": "fullReduceApprox", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 423 - }, - { - "name": "fullReduceNotApprox", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 454 - }, - { - "name": "idSymbolic", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 485 - }, - { - "name": "equivalenceSymbolic", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 504 - }, - { - "name": "OnlyDeletedVertices", - "file": "\/workspaces\/core\/test\/zx\/test_simplify.cpp", - "line": 594 - } - ] - }, - { - "name": "RationalTest", - "tests": 16, - "testsuite": [ - { - "name": "normalize", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 24 - }, - { - "name": "fromDouble", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 29 - }, - { - "name": "fromDouble2", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 34 - }, - { - "name": "fromDouble3", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 39 - }, - { - "name": "fromDouble4", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 44 - }, - { - "name": "fromDouble5", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 49 - }, - { - "name": "fromDouble6", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 54 - }, - { - "name": "add", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 59 - }, - { - "name": "add2", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 67 - }, - { - "name": "sub", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 75 - }, - { - "name": "sub2", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 83 - }, - { - "name": "mul", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 91 - }, - { - "name": "mul2", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 99 - }, - { - "name": "div", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 107 - }, - { - "name": "approximateDivPi", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 115 - }, - { - "name": "approximate", - "file": "\/workspaces\/core\/test\/zx\/test_rational.cpp", - "line": 120 - } - ] - }, - { - "name": "ExpressionTest", - "tests": 15, - "testsuite": [ - { - "name": "basicOps1", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 36 - }, - { - "name": "basicOps2", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 56 - }, - { - "name": "mult", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 84 - }, - { - "name": "div", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 104 - }, - { - "name": "Commutativity", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 118 - }, - { - "name": "Associativity", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 127 - }, - { - "name": "Distributive", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 136 - }, - { - "name": "Variable", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 148 - }, - { - "name": "SumNegation", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 155 - }, - { - "name": "SumMult", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 164 - }, - { - "name": "CliffordRounding", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 169 - }, - { - "name": "Clifford", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 182 - }, - { - "name": "Convertability", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 200 - }, - { - "name": "Instantiation", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 207 - }, - { - "name": "Arithmetic", - "file": "\/workspaces\/core\/test\/zx\/test_expression.cpp", - "line": 220 - } - ] - } - ] -} From fc9a6635c7238f1a2f945742e00cbd22bf18cc1a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Jul 2026 09:09:25 +0000 Subject: [PATCH 41/80] =?UTF-8?q?=F0=9F=8E=A8=20pre-commit=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9cb08762a..160f5e9f7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,8 +48,8 @@ releases may include breaking changes. [#1513], [#1521], [#1542], [#1548], [#1550], [#1554], [#1567], [#1569], [#1570], [#1572], [#1573], [#1580], [#1602], [#1620], [#1623], [#1624], [#1626], [#1627], [#1635], [#1638], [#1673], [#1675], [#1700], [#1710], - [#1717], [#1728], [#1730], [#1749], [#1751], [#1755], [#1762], [#1765], - [#1780], [#1781], [#1782], [#1787], [#1806], [#1807], [#1808], [#1823], + [#1717], [#1728], [#1730], [#1749], [#1751], [#1755], [#1762], [#1765], + [#1780], [#1781], [#1782], [#1787], [#1806], [#1807], [#1808], [#1823], [#1824], [#1830]) ([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**], [**@simon1hofmann**]) From f18025b3a553af7f36839e48f59f8476a3242ce7 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 7 Jul 2026 12:44:33 +0200 Subject: [PATCH 42/80] fix(mlir): :bug: fix issues after merge --- CHANGELOG.md | 4 +- .../Dialect/QCO/IR/test_qco_ir_matrix.cpp | 21 -------- mlir/unittests/programs/qco_programs.cpp | 54 +++++++++++++++---- mlir/unittests/programs/qco_programs.h | 23 +++++--- 4 files changed, 64 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9cb08762a..160f5e9f7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,8 +48,8 @@ releases may include breaking changes. [#1513], [#1521], [#1542], [#1548], [#1550], [#1554], [#1567], [#1569], [#1570], [#1572], [#1573], [#1580], [#1602], [#1620], [#1623], [#1624], [#1626], [#1627], [#1635], [#1638], [#1673], [#1675], [#1700], [#1710], - [#1717], [#1728], [#1730], [#1749], [#1751], [#1755], [#1762], [#1765], - [#1780], [#1781], [#1782], [#1787], [#1806], [#1807], [#1808], [#1823], + [#1717], [#1728], [#1730], [#1749], [#1751], [#1755], [#1762], [#1765], + [#1780], [#1781], [#1782], [#1787], [#1806], [#1807], [#1808], [#1823], [#1824], [#1830]) ([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**], [**@simon1hofmann**]) diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp index c1c351bc5e..51c8a013ab 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp @@ -64,27 +64,6 @@ expectedMatrixFromComputation(const Fn& build, dd::buildFunctionality(comp, *package).getMatrix(numQubits)); } -static void controlledXH(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(2); - b.ctrl(q[0], q[1], [&](ValueRange targets) { - auto wire = b.x(targets[0]); - wire = b.h(wire); - return SmallVector{wire}; - }); -} - -static void controlledInverseHT(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(2); - b.ctrl(q[0], q[1], [&](ValueRange targets) { - auto wire = b.inv({targets[0]}, [&](ValueRange innerTargets) { - auto inner = b.h(innerTargets[0]); - inner = b.t(inner); - return SmallVector{inner}; - })[0]; - return SmallVector{wire}; - }); -} - namespace { struct QCOMatrixTestCase { diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index f8ac6bdf5f..eb58122150 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -506,28 +506,34 @@ inverseTwoX(QCOProgramBuilder& b) { return measureAndReturn(b, {res[0]}); } -void inverseGphaseX(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseGphaseX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv(q[0], [&](ValueRange qubits) { + auto res = b.inv(q[0], [&](ValueRange qubits) { b.gphase(-0.123); return SmallVector{b.x(qubits[0])}; }); + return measureAndReturn(b, {res[0]}); } -void inverseGphaseBarrier(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseGphaseBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv(q[0], [&](ValueRange qubits) -> SmallVector { + auto res = b.inv(q[0], [&](ValueRange qubits) -> SmallVector { b.gphase(0.123); return {b.barrier({qubits[0]})[0]}; }); + return measureAndReturn(b, {res[0]}); } -void inverseTwoBarriersInInv(QCOProgramBuilder& b) { +std::pair, SmallVector> +inverseTwoBarriersInInv(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.inv(q[0], [&](ValueRange qubits) -> SmallVector { + auto res = b.inv(q[0], [&](ValueRange qubits) -> SmallVector { auto q0 = b.barrier({qubits[0]})[0]; return {b.barrier({q0})[0]}; }); + return measureAndReturn(b, {res[0]}); } std::pair, SmallVector> y(QCOProgramBuilder& b) { @@ -1736,10 +1742,11 @@ canonicalizeRToRy(QCOProgramBuilder& b) { return measureAndReturn(b, {q[0]}); } -void twoR(QCOProgramBuilder& b) { +std::pair, SmallVector> twoR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.r(0.045, 0.456, q[0]); q[0] = b.r(0.078, 0.456, q[0]); + return measureAndReturn(b, {q[0]}); } std::pair, SmallVector> u2(QCOProgramBuilder& b) { @@ -2883,10 +2890,12 @@ twoXxPlusYYOppositePhase(QCOProgramBuilder& b) { return measureAndReturn(b, {q[0], q[1]}); } -void twoXxPlusYYSwappedTargets(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoXxPlusYYSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.xx_plus_yy(0.045, 0.456, q[0], q[1]); std::tie(q[1], q[0]) = b.xx_plus_yy(0.078, 0.456, q[1], q[0]); + return measureAndReturn(b, {q[0], q[1]}); } std::pair, SmallVector> @@ -2984,10 +2993,12 @@ twoXxMinusYYOppositePhase(QCOProgramBuilder& b) { return measureAndReturn(b, {q[0], q[1]}); } -void twoXxMinusYYSwappedTargets(QCOProgramBuilder& b) { +std::pair, SmallVector> +twoXxMinusYYSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.xx_minus_yy(0.045, 0.456, q[0], q[1]); std::tie(q[1], q[0]) = b.xx_minus_yy(0.078, 0.456, q[1], q[0]); + return measureAndReturn(b, {q[0], q[1]}); } std::pair, SmallVector> barrier(QCOProgramBuilder& b) { @@ -3791,4 +3802,29 @@ nestedIfOpForLoopWithAngle(QCOProgramBuilder& b) { return measureAndReturn(b, {res[0]}); } +std::pair, SmallVector> +controlledXH(QCOProgramBuilder& b) { + auto q = b.allocQubitRegister(2); + auto [ctrl, targ] = b.ctrl(q[0], q[1], [&](ValueRange targets) { + auto wire = b.x(targets[0]); + wire = b.h(wire); + return SmallVector{wire}; + }); + return measureAndReturn(b, {ctrl[0], targ[0]}); +} + +std::pair, SmallVector> +controlledInverseHT(QCOProgramBuilder& b) { + auto q = b.allocQubitRegister(2); + auto [ctrl, targ] = b.ctrl(q[0], q[1], [&](ValueRange targets) { + auto wire = b.inv({targets[0]}, [&](ValueRange innerTargets) { + auto inner = b.h(innerTargets[0]); + inner = b.t(inner); + return SmallVector{inner}; + })[0]; + return SmallVector{wire}; + }); + return measureAndReturn(b, {ctrl[0], targ[0]}); +} + } // namespace mlir::qco diff --git a/mlir/unittests/programs/qco_programs.h b/mlir/unittests/programs/qco_programs.h index c1b324f52f..db408f9b65 100644 --- a/mlir/unittests/programs/qco_programs.h +++ b/mlir/unittests/programs/qco_programs.h @@ -244,15 +244,18 @@ inverseTwoX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a global phase and an /// X gate. -void inverseGphaseX(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseGphaseX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a global phase and a /// barrier. -void inverseGphaseBarrier(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseGphaseBarrier(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to two consecutive /// barriers. -void inverseTwoBarriersInInv(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseTwoBarriersInInv(QCOProgramBuilder& b); // --- YOp ------------------------------------------------------------------ // @@ -739,7 +742,7 @@ std::pair, SmallVector> canonicalizeRToRy(QCOProgramBuilder& b); /// Creates a circuit with two R gates in a row with the same `phi`. -void twoR(QCOProgramBuilder& b); +std::pair, SmallVector> twoR(QCOProgramBuilder& b); // --- U2Op ----------------------------------------------------------------- // @@ -1172,7 +1175,8 @@ std::pair, SmallVector> twoXxPlusYYOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with two XXPlusYY gates in a row with swapped targets. -void twoXxPlusYYSwappedTargets(QCOProgramBuilder& b); +std::pair, SmallVector> +twoXxPlusYYSwappedTargets(QCOProgramBuilder& b); // --- XXMinusYYOp ---------------------------------------------------------- // @@ -1210,7 +1214,8 @@ std::pair, SmallVector> twoXxMinusYYOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with two XXMinusYY gates in a row with swapped targets. -void twoXxMinusYYSwappedTargets(QCOProgramBuilder& b); +std::pair, SmallVector> +twoXxMinusYYSwappedTargets(QCOProgramBuilder& b); // --- BarrierOp ------------------------------------------------------------ // @@ -1447,4 +1452,10 @@ qtensorChain(QCOProgramBuilder& b); std::pair, SmallVector> qtensorAlternativeChain(QCOProgramBuilder& b); +std::pair, SmallVector> +controlledXH(QCOProgramBuilder& b); + +std::pair, SmallVector> +controlledInverseHT(QCOProgramBuilder& b); + } // namespace mlir::qco From afd395dc7a8d424db92453134ccdc4e2563c706b Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 7 Jul 2026 12:54:18 +0200 Subject: [PATCH 43/80] fix(mlir): :sparkles: fix leftover merging error --- mlir/lib/Conversion/QCToQIR/QIRAdaptive/QCToQIRAdaptive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/lib/Conversion/QCToQIR/QIRAdaptive/QCToQIRAdaptive.cpp b/mlir/lib/Conversion/QCToQIR/QIRAdaptive/QCToQIRAdaptive.cpp index 9138fb867b..80a30c19bd 100644 --- a/mlir/lib/Conversion/QCToQIR/QIRAdaptive/QCToQIRAdaptive.cpp +++ b/mlir/lib/Conversion/QCToQIR/QIRAdaptive/QCToQIRAdaptive.cpp @@ -422,7 +422,7 @@ struct ConvertQCMeasureOp final : StatefulOpConversionPattern { result = loadedResults.at({registerName, registerIndex}); } else { rewriter.setInsertionPoint(state.entryBlock->getTerminator()); - auto index = state.numResults++; + auto index = resultPtrs.size(); if (shouldRecord) { state.recordedIndices.insert(index); } From aeb9838bbdaea5214076718e4d46d83050781c53 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 7 Jul 2026 14:48:39 +0200 Subject: [PATCH 44/80] feat(mlir): :recycle: return QASM3 `output` values in resulting `QC` program and pass corresponding tests --- include/mqt-core/qasm3/Parser.hpp | 2 +- include/mqt-core/qasm3/Statement.hpp | 9 +- .../QC/Translation/TranslateQASM3ToQC.cpp | 39 ++- .../QC/Translation/test_qasm3_translation.cpp | 63 ++++- mlir/unittests/programs/qasm_programs.cpp | 245 +++++++++++++++++- mlir/unittests/programs/qc_programs.cpp | 16 +- mlir/unittests/programs/qc_programs.h | 8 + src/qasm3/Parser.cpp | 13 +- 8 files changed, 363 insertions(+), 32 deletions(-) diff --git a/include/mqt-core/qasm3/Parser.hpp b/include/mqt-core/qasm3/Parser.hpp index b93f679945..72831862da 100644 --- a/include/mqt-core/qasm3/Parser.hpp +++ b/include/mqt-core/qasm3/Parser.hpp @@ -114,7 +114,7 @@ class Parser final { std::shared_ptr parseBarrierStatement(); - std::shared_ptr parseDeclaration(bool isConst); + std::shared_ptr parseDeclaration(bool isConst, bool isOutput); std::shared_ptr parseGateDefinition(); diff --git a/include/mqt-core/qasm3/Statement.hpp b/include/mqt-core/qasm3/Statement.hpp index 258c7a7900..31f09b5ccb 100644 --- a/include/mqt-core/qasm3/Statement.hpp +++ b/include/mqt-core/qasm3/Statement.hpp @@ -347,15 +347,18 @@ class DeclarationStatement final public std::enable_shared_from_this { public: bool isConst; + bool isOutput; std::variant, std::shared_ptr> type; std::string identifier; std::shared_ptr expression; DeclarationStatement(std::shared_ptr debug, const bool declIsConst, - std::shared_ptr ty, std::string id, + bool declIsOutput, std::shared_ptr ty, + std::string id, std::shared_ptr expr) - : Statement(std::move(debug)), isConst(declIsConst), type(ty), - identifier(std::move(id)), expression(std::move(expr)) {} + : Statement(std::move(debug)), isConst(declIsConst), + isOutput(declIsOutput), type(ty), identifier(std::move(id)), + expression(std::move(expr)) {} void accept(InstVisitor* visitor) override; }; diff --git a/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp b/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp index bfc7bfe989..12d9127894 100644 --- a/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp +++ b/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp @@ -220,7 +220,36 @@ class MLIRQasmImporter final : public qasm3::InstVisitor { } } - OwningOpRef finalize() { return builder.finalize(); } + OwningOpRef finalize() { + if (outputRegisters.empty()) { + return builder.finalize(); + } + + // Collect measurement results for all output bit registers + SmallVector returnValues; + SmallVector returnTypes; + auto i1Type = builder.getI1Type(); + for (const auto& regName : outputRegisters) { + auto it = bitValues.find(regName); + if (it == bitValues.end()) { + llvm::errs() << "Output register '" << regName + << "' was never measured.\n"; + return nullptr; + } + for (auto bit : it->second) { + if (!bit) { + llvm::errs() << "Not all bits of output register '" << regName + << "' have been measured.\n"; + return nullptr; + } + returnValues.push_back(bit); + returnTypes.push_back(i1Type); + } + } + + builder.retype(returnTypes); + return builder.finalize(returnValues); + } private: QCProgramBuilder builder; @@ -238,6 +267,9 @@ class MLIRQasmImporter final : public qasm3::InstVisitor { /// Map from classical-register name to measurement results. llvm::StringMap> bitValues; + /// Names of classical registers declared as output, in declaration order. + SmallVector outputRegisters; + /// Map from gate identifier to OpenQASM 3 definition. llvm::StringMap> gates; @@ -361,6 +393,11 @@ class MLIRQasmImporter final : public qasm3::InstVisitor { case qasm3::Int: case qasm3::Uint: { classicalRegisters[id] = builder.allocClassicalBitRegister(size, id); + if ((stmt->isOutput || openQASM2CompatMode) && + sizedType->type == qasm3::Bit) { + // We return `output` bits in QASM3, or all named bits in QASM2. + outputRegisters.push_back(id); + } break; } default: diff --git a/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp b/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp index b18c858b2d..9331efde8b 100644 --- a/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp +++ b/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp @@ -37,7 +37,9 @@ namespace { struct QASM3TranslationTestCase { std::string name; std::string source; - mqt::test::NamedBuilder referenceBuilder; + mqt::test::NamedBuilder, SmallVector>> + referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QASM3TranslationTestCase& test); @@ -67,32 +69,53 @@ class QASM3TranslationTest } // namespace -static void twoX(qc::QCProgramBuilder& b) { +static std::pair, SmallVector> +twoX(qc::QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.x(q[0]); b.x(q[1]); + auto c0 = b.measure(q[0]); + auto c1 = b.measure(q[1]); + return {{c0, c1}, {b.getI1Type(), b.getI1Type()}}; } -static void singleNegControlledX(qc::QCProgramBuilder& b) { +static std::pair, SmallVector> +singleNegControlledX(qc::QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.x(q[0]); b.cx(q[0], q[1]); b.x(q[0]); + auto c0 = b.measure(q[0]); + auto c1 = b.measure(q[1]); + return {{c0, c1}, {b.getI1Type(), b.getI1Type()}}; } -static void tripleControlledX(qc::QCProgramBuilder& b) { +static std::pair, SmallVector> +tripleControlledX(qc::QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcx({q[0], q[1], q[2]}, q[3]); + auto c0 = b.measure(q[0]); + auto c1 = b.measure(q[1]); + auto c2 = b.measure(q[2]); + auto c3 = b.measure(q[3]); + return {{c0, c1, c2, c3}, + {b.getI1Type(), b.getI1Type(), b.getI1Type(), b.getI1Type()}}; } -static void mixedControlledX(qc::QCProgramBuilder& b) { +static std::pair, SmallVector> +mixedControlledX(qc::QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.x(q[1]); b.mcx({q[0], q[1]}, q[2]); b.x(q[1]); + auto c0 = b.measure(q[0]); + auto c1 = b.measure(q[1]); + auto c2 = b.measure(q[2]); + return {{c0, c1, c2}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; } -static void twoMixedControlledX(qc::QCProgramBuilder& b) { +static std::pair, SmallVector> +twoMixedControlledX(qc::QCProgramBuilder& b) { auto q1 = b.allocQubitRegister(2); auto q2 = b.allocQubitRegister(2); auto q3 = b.allocQubitRegister(2); @@ -102,15 +125,27 @@ static void twoMixedControlledX(qc::QCProgramBuilder& b) { b.x(q2[1]); b.mcx({q1[1], q2[1]}, q3[1]); b.x(q2[1]); + auto c0 = b.measure(q1[0]); + auto c1 = b.measure(q1[1]); + auto c2 = b.measure(q2[0]); + auto c3 = b.measure(q2[1]); + auto c4 = b.measure(q3[0]); + auto c5 = b.measure(q3[1]); + return {{c0, c1, c2, c3, c4, c5}, + {b.getI1Type(), b.getI1Type(), b.getI1Type(), b.getI1Type(), + b.getI1Type(), b.getI1Type()}}; } -static void ifNot(qc::QCProgramBuilder& b) { +static std::pair, SmallVector> +ifNot(qc::QCProgramBuilder& b) { auto trueValue = b.boolConstant(true); auto q = b.allocQubitRegister(1); b.h(q[0]); auto c = b.measure(q[0]); auto cond = arith::XOrIOp::create(b, c, trueValue).getResult(); b.scfIf(cond, [&] { b.x(q[0]); }); + auto out = b.measure(q[0]); + return {{out}, {b.getI1Type()}}; } TEST_P(QASM3TranslationTest, ProgramEquivalence) { @@ -147,7 +182,7 @@ INSTANTIATE_TEST_SUITE_P( testing::Values( QASM3TranslationTestCase{"AllocQubit", qasm::allocQubit, - MQT_NAMED_BUILDER(qc::allocQubit)}, + MQT_NAMED_BUILDER(qc::alloc1QubitRegister)}, QASM3TranslationTestCase{"AllocQubitRegister", qasm::allocQubitRegister, MQT_NAMED_BUILDER(qc::allocQubitRegister)}, QASM3TranslationTestCase{ @@ -185,12 +220,12 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(qc::inverseGlobalPhase)}, QASM3TranslationTestCase{"Identity", qasm::identity, MQT_NAMED_BUILDER(qc::identity)}, - QASM3TranslationTestCase{ - "SingleControlledIdentity", qasm::singleControlledIdentity, - MQT_NAMED_BUILDER(qc::singleControlledIdentity)}, - QASM3TranslationTestCase{ - "MultipleControlledIdentity", qasm::multipleControlledIdentity, - MQT_NAMED_BUILDER(qc::multipleControlledIdentity)}, + QASM3TranslationTestCase{"SingleControlledIdentity", + qasm::singleControlledIdentity, + MQT_NAMED_BUILDER(qc::twoQubitsOneIdentity)}, + QASM3TranslationTestCase{"MultipleControlledIdentity", + qasm::multipleControlledIdentity, + MQT_NAMED_BUILDER(qc::threeQubitsOneIdentity)}, QASM3TranslationTestCase{"X", qasm::x, MQT_NAMED_BUILDER(qc::x)}, QASM3TranslationTestCase{"TwoX", qasm::twoX, MQT_NAMED_BUILDER(twoX)}, QASM3TranslationTestCase{"SingleControlledX", qasm::singleControlledX, diff --git a/mlir/unittests/programs/qasm_programs.cpp b/mlir/unittests/programs/qasm_programs.cpp index 2386d7e8c7..fcd60b0868 100644 --- a/mlir/unittests/programs/qasm_programs.cpp +++ b/mlir/unittests/programs/qasm_programs.cpp @@ -18,35 +18,46 @@ namespace mlir::qasm { const std::string allocQubit = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit q; +output bit c; +c = measure q; )qasm"; const std::string allocQubitRegister = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; +output bit[2] c; +c = measure q; )qasm"; const std::string allocMultipleQubitRegisters = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q0; qubit[3] q1; +output bit[2] c0; +output bit[3] c1; +c0 = measure q0; +c1 = measure q1; )qasm"; const std::string allocLargeRegister = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[100] q; +output bit[2] c; +c[0] = measure q[0]; +c[1] = measure q[99]; )qasm"; const std::string singleMeasurementToSingleBit = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; -bit[1] c; +output bit[1] c; measure q[0] -> c[0]; )qasm"; const std::string repeatedMeasurementToSameBit = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; -bit[1] c; +output bit[1] c; measure q[0] -> c[0]; measure q[0] -> c[0]; measure q[0] -> c[0]; @@ -55,7 +66,7 @@ measure q[0] -> c[0]; const std::string repeatedMeasurementToDifferentBits = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; -bit[3] c; +output bit[3] c; measure q[0] -> c[0]; measure q[0] -> c[1]; measure q[0] -> c[2]; @@ -65,8 +76,8 @@ const std::string multipleClassicalRegistersAndMeasurements = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; -bit[1] c0; -bit[2] c1; +output bit[1] c0; +output bit[2] c1; measure q[0] -> c0[0]; measure q[1] -> c1[0]; measure q[2] -> c1[1]; @@ -75,26 +86,32 @@ measure q[2] -> c1[1]; const std::string resetQubitAfterSingleOp = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; +output bit[1] c; h q[0]; reset q[0]; +c = measure q; )qasm"; const std::string resetMultipleQubitsAfterSingleOp = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; +output bit[2] c; h q[0]; reset q[0]; h q[1]; reset q[1]; +c = measure q; )qasm"; const std::string repeatedResetAfterSingleOp = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; +output bit[1] c; h q[0]; reset q[0]; reset q[0]; reset q[0]; +c = measure q; )qasm"; const std::string globalPhase = R"qasm(OPENQASM 3.0; @@ -111,60 +128,80 @@ const std::string identity = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; id q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledIdentity = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ id q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledIdentity = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ id q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string x = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; x q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string twoX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; x q; +output bit[2] c; +c = measure q; )qasm"; const std::string singleControlledX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ x q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string singleNegControlledX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; negctrl @ x q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ x q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string tripleControlledXOpenQASM2 = R"qasm(OPENQASM 2.0; include "qelib1.inc"; +creg c[4]; qreg q[4]; cccx q[0], q[1], q[2], q[3]; +measure q -> c; )qasm"; const std::string mixedControlledX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ negctrl @ x q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string twoMixedControlledX = R"qasm(OPENQASM 3.0; @@ -173,522 +210,700 @@ qubit[2] q1; qubit[2] q2; qubit[2] q3; ctrl @ negctrl @ x q1, q2, q3; +output bit[2] c1; +output bit[2] c2; +output bit[2] c3; +c1 = measure q1; +c2 = measure q2; +c3 = measure q3; )qasm"; const std::string inverseX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; inv @ x q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string inverseMultipleControlledX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; inv @ ctrl(2) @ x q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string y = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; y q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ y q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ y q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string z = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; z q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledZ = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ z q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledZ = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ z q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string h = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; h q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledH = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ h q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledH = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ h q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string s = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; s q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledS = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ s q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledS = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ s q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string sdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; sdg q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledSdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ sdg q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledSdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ sdg q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string t_ = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; t q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledT = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ t q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledT = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ t q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string tdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; tdg q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledTdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ tdg q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledTdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ tdg q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string sx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; sx q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledSx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ sx q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledSx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ sx q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string sxdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; sxdg q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledSxdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ sxdg q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledSxdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ sxdg q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string rx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; rx(0.123) q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledRx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ rx(0.123) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledRx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ rx(0.123) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string ry = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; ry(0.456) q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledRy = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ ry(0.456) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledRy = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ ry(0.456) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string rz = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; rz(0.789) q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledRz = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ rz(0.789) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledRz = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ rz(0.789) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string p = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; p(0.123) q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledP = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ p(0.123) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledP = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ p(0.123) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string r = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; r(0.123, 0.456) q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledR = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ r(0.123, 0.456) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledR = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ r(0.123, 0.456) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string u2 = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; u2(0.234, 0.567) q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledU2 = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ u2(0.234, 0.567) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledU2 = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ u2(0.234, 0.567) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string u = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; u(0.1, 0.2, 0.3) q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string singleControlledU = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ u(0.1, 0.2, 0.3) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string multipleControlledU = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ u(0.1, 0.2, 0.3) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string swap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; swap q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string singleControlledSwap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ swap q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string multipleControlledSwap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ swap q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string iswap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; iswap q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string singleControlledIswap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ iswap q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string multipleControlledIswap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ iswap q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string inverseIswap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; inv @ iswap q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string inverseMultipleControlledIswap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; inv @ ctrl(2) @ iswap q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string dcx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; dcx q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string singleControlledDcx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ dcx q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string multipleControlledDcx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ dcx q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string ecr = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ecr q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string singleControlledEcr = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ ecr q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string multipleControlledEcr = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ ecr q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string rxx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; rxx(0.123) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string singleControlledRxx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ rxx(0.123) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string multipleControlledRxx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ rxx(0.123) q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string tripleControlledRxx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[5] q; ctrl(3) @ rxx(0.123) q[0], q[1], q[2], q[3], q[4]; +output bit[5] c; +c = measure q; )qasm"; const std::string ryy = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ryy(0.123) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string singleControlledRyy = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ ryy(0.123) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string multipleControlledRyy = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ ryy(0.123) q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string rzx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; rzx(0.123) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string singleControlledRzx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ rzx(0.123) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string multipleControlledRzx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ rzx(0.123) q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string rzz = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; rzz(0.123) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string singleControlledRzz = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ rzz(0.123) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string multipleControlledRzz = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ rzz(0.123) q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string xxPlusYY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; xx_plus_yy(0.123, 0.456) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string singleControlledXxPlusYY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ xx_plus_yy(0.123, 0.456) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string multipleControlledXxPlusYY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ xx_plus_yy(0.123, 0.456) q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string xxMinusYY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; xx_minus_yy(0.123, 0.456) q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string singleControlledXxMinusYY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ xx_minus_yy(0.123, 0.456) q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string multipleControlledXxMinusYY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ xx_minus_yy(0.123, 0.456) q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string barrier = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; barrier q[0]; +output bit[1] c; +c = measure q; )qasm"; const std::string barrierTwoQubits = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; barrier q[0], q[1]; +output bit[2] c; +c = measure q; )qasm"; const std::string barrierMultipleQubits = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; barrier q[0], q[1], q[2]; +output bit[3] c; +c = measure q; )qasm"; const std::string ctrlTwo = R"qasm(OPENQASM 3.0; @@ -699,6 +914,8 @@ gate compound q0, q1 { rxx(0.123) q0, q1; } ctrl(2) @ compound q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string ctrlTwoMixed = R"qasm(OPENQASM 3.0; @@ -709,16 +926,20 @@ gate compound q0, q1 { rxx(0.123) q0, q1; } ctrl(2) @ compound q[0], q[1], q[2], q[3]; +output bit[4] c; +c = measure q; )qasm"; const std::string simpleIf = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; h q[0]; -bit c = measure q[0]; +output bit c = measure q[0]; if (c) { x q[0]; } +output bit[1] out; +out = measure q; )qasm"; const std::string ifNot = R"qasm(OPENQASM 3.0; @@ -729,17 +950,21 @@ bit c = measure q[0]; if (!c) { x q[0]; } +output bit[1] out; +out = measure q; )qasm"; const std::string ifTwoQubits = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; h q[0]; -bit c = measure q[0]; +output bit c = measure q[0]; if (c) { x q[0]; x q[1]; } +output bit[2] out; +out = measure q; )qasm"; const std::string ifEmptyThen = R"qasm(OPENQASM 3.0; @@ -751,18 +976,22 @@ if (c) { } else { x q[0]; } +output bit[1] out; +out = measure q; )qasm"; const std::string ifElse = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; h q[0]; -bit c = measure q[0]; +output bit c = measure q[0]; if (c) { x q[0]; } else { z q[0]; } +output bit[1] out; +out = measure q; )qasm"; } // namespace mlir::qasm diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index aa5fccd881..2a8039173c 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -317,7 +317,7 @@ trivialControlledGlobalPhase(QCProgramBuilder& b) { std::pair, SmallVector> inverseGlobalPhase(QCProgramBuilder& b) { b.inv({}, [&](ValueRange /*qubits*/) { b.gphase(-0.123); }); - return measureAndReturn(b, {}); + return {{b.intConstant(0)}, {b.getI64Type()}}; } std::pair, SmallVector> @@ -341,6 +341,20 @@ singleControlledIdentity(QCProgramBuilder& b) { return measureAndReturn(b, {q[0], q[1]}); } +std::pair, SmallVector> +twoQubitsOneIdentity(QCProgramBuilder& b) { + auto q = b.allocQubitRegister(2); + b.id(q[1]); + return measureAndReturn(b, {q[0], q[1]}); +} + +std::pair, SmallVector> +threeQubitsOneIdentity(QCProgramBuilder& b) { + auto q = b.allocQubitRegister(3); + b.id(q[2]); + return measureAndReturn(b, {q[0], q[1], q[2]}); +} + std::pair, SmallVector> multipleControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); diff --git a/mlir/unittests/programs/qc_programs.h b/mlir/unittests/programs/qc_programs.h index eee8754ce2..2614850da4 100644 --- a/mlir/unittests/programs/qc_programs.h +++ b/mlir/unittests/programs/qc_programs.h @@ -186,6 +186,14 @@ std::pair, SmallVector> identity(QCProgramBuilder& b); std::pair, SmallVector> singleControlledIdentity(QCProgramBuilder& b); +/// Creates an identity gate on a single qubit in a two-qubit register. +std::pair, SmallVector> +twoQubitsOneIdentity(QCProgramBuilder& b); + +/// Creates an identity gate on a single qubit in a three-qubit register. +std::pair, SmallVector> +threeQubitsOneIdentity(QCProgramBuilder& b); + /// Creates a multi-controlled identity gate with multiple control qubits. std::pair, SmallVector> multipleControlledIdentity(QCProgramBuilder& b); diff --git a/src/qasm3/Parser.cpp b/src/qasm3/Parser.cpp index 04ae35473b..ce45d9f1f2 100644 --- a/src/qasm3/Parser.cpp +++ b/src/qasm3/Parser.cpp @@ -168,7 +168,11 @@ std::shared_ptr Parser::parseStatement() { if (current().kind == Token::Kind::Const) { scan(); - return parseDeclaration(true); + return parseDeclaration(true, false); + } + if (current().kind == Token::Kind::Output) { + scan(); + return parseDeclaration(false, true); } if (current().kind == Token::Kind::Int || @@ -181,7 +185,7 @@ std::shared_ptr Parser::parseStatement() { current().kind == Token::Kind::Duration || current().kind == Token::Kind::CReg || current().kind == Token::Kind::Qreg) { - return parseDeclaration(false); + return parseDeclaration(false, false); } if (current().kind == Token::Kind::InitialLayout) { @@ -558,7 +562,8 @@ std::shared_ptr Parser::parseGateOperand() { return std::make_shared(parseIndexedIdentifier()); } -std::shared_ptr Parser::parseDeclaration(bool isConst) { +std::shared_ptr Parser::parseDeclaration(bool isConst, + bool isOutput) { auto const tBegin = current(); auto [type, isOldStyleDeclaration] = parseType(); Token const identifier = expect(Token::Kind::Identifier); @@ -588,7 +593,7 @@ std::shared_ptr Parser::parseDeclaration(bool isConst) { auto const tEnd = expect(Token::Kind::Semicolon); auto statement = std::make_shared(DeclarationStatement{ - makeDebugInfo(tBegin, tEnd), isConst, type, name, expression}); + makeDebugInfo(tBegin, tEnd), isConst, isOutput, type, name, expression}); return statement; } From bb8152fb71d4fe5b70dcfefa8636dda522047e50 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 7 Jul 2026 16:21:27 +0200 Subject: [PATCH 45/80] test(mlir): :sparkles: pass decomposition tests --- .../test_euler_decomposition.cpp | 111 +++++++++++++----- 1 file changed, 79 insertions(+), 32 deletions(-) diff --git a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp index 90041fbccd..4cc98fc095 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp @@ -99,6 +99,20 @@ class EulerSynthesisExactTest : public testing::TestWithParam< std::tuple> {}; +static std::pair, mlir::SmallVector> +measureAndReturn(mlir::qco::QCOProgramBuilder& b, + mlir::SmallVector qubits) { + mlir::SmallVector bits; + mlir::SmallVector bitTypes; + auto i1Type = b.getI1Type(); + for (const auto& q : qubits) { + auto [q2, bit] = b.measure(q); + bits.push_back(bit); + bitTypes.push_back(i1Type); + } + return {bits, bitTypes}; +} + } // namespace //===----------------------------------------------------------------------===// @@ -765,7 +779,8 @@ static void runFuseInParent(MLIRContext* ctx, ProgramT program, // --- Fuse program fixtures --- // -static void singleQubitRunWithSingleQubitGate(QCOProgramBuilder& b) { +static std::pair, SmallVector> +singleQubitRunWithSingleQubitGate(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); q[0] = b.t(q[0]); @@ -774,44 +789,56 @@ static void singleQubitRunWithSingleQubitGate(QCOProgramBuilder& b) { return {b.sx(targets[0])}; })[0]; q[0] = b.ry(-0.456, q[0]); + return measureAndReturn(b, {q[0]}); } -static void singleQubitRunsSplitByTwoQGate(QCOProgramBuilder& b) { +static std::pair, SmallVector> +singleQubitRunsSplitByTwoQGate(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); q[0] = b.h(q[0]); q[0] = b.t(q[0]); std::tie(q[0], q[1]) = b.swap(q[0], q[1]); q[0] = b.rz(0.321, q[0]); q[0] = b.sx(q[0]); + return measureAndReturn(b, {q[0]}); } -static void singleQubitRunsSplitByBarrier(QCOProgramBuilder& b) { +static std::pair, SmallVector> +singleQubitRunsSplitByBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); q[0] = b.t(q[0]); q[0] = b.barrier({q[0]})[0]; q[0] = b.rz(0.321, q[0]); q[0] = b.sx(q[0]); + return measureAndReturn(b, {q[0]}); } -static void singleNonBasisGate(QCOProgramBuilder& b) { +static std::pair, SmallVector> +singleNonBasisGate(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); + return measureAndReturn(b, {q[0]}); } -static void singlePauliX(QCOProgramBuilder& b) { +static std::pair, SmallVector> +singlePauliX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.x(q[0]); + return measureAndReturn(b, {q[0]}); } -static void canonicalZYZRun(QCOProgramBuilder& b) { +static std::pair, SmallVector> +canonicalZYZRun(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rz(0.3, q[0]); q[0] = b.ry(0.5, q[0]); q[0] = b.rz(0.7, q[0]); + return measureAndReturn(b, {q[0]}); } -static void overlongZYZRun(QCOProgramBuilder& b) { +static std::pair, SmallVector> +overlongZYZRun(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rz(0.3, q[0]); q[0] = b.ry(0.5, q[0]); @@ -819,27 +846,34 @@ static void overlongZYZRun(QCOProgramBuilder& b) { q[0] = b.ry(0.9, q[0]); q[0] = b.rz(1.1, q[0]); q[0] = b.ry(1.3, q[0]); + return measureAndReturn(b, {q[0]}); } -static void overlongZSXXMixedPureZRun(QCOProgramBuilder& b) { +static std::pair, SmallVector> +overlongZSXXMixedPureZRun(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sx(q[0]); q[0] = b.rz(std::numbers::pi, q[0]); q[0] = b.sx(q[0]); + return measureAndReturn(b, {q[0]}); } -static void singleQubitRunInScfFor(QCOProgramBuilder& b) { +static std::pair, SmallVector> +singleQubitRunInScfFor(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - b.scfFor(0, 1, 1, ValueRange{q[0]}, [&b](Value, ValueRange iterArgs) { - Value wire = iterArgs[0]; - wire = b.h(wire); - wire = b.t(wire); - wire = b.rz(0.123, wire); - return SmallVector{wire}; - }); + auto res = + b.scfFor(0, 1, 1, ValueRange{q[0]}, [&b](Value, ValueRange iterArgs) { + Value wire = iterArgs[0]; + wire = b.h(wire); + wire = b.t(wire); + wire = b.rz(0.123, wire); + return SmallVector{wire}; + }); + return measureAndReturn(b, {res[0]}); } -static void xInverseTwoX(QCOProgramBuilder& b) { +static std::pair, SmallVector> +xInverseTwoX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.x(q[0]); q[0] = b.inv({q[0]}, [&b](ValueRange targets) { @@ -848,9 +882,11 @@ static void xInverseTwoX(QCOProgramBuilder& b) { return SmallVector{wire}; })[0]; q[0] = b.x(q[0]); + return measureAndReturn(b, {q[0]}); } -static void inverseMultiQubitBodySingleQubitRun(QCOProgramBuilder& b) { +static std::pair, SmallVector> +inverseMultiQubitBodySingleQubitRun(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto outs = b.inv({q[0], q[1]}, [&b](ValueRange targets) -> SmallVector { @@ -860,11 +896,13 @@ static void inverseMultiQubitBodySingleQubitRun(QCOProgramBuilder& b) { }); q[0] = outs[0]; q[1] = outs[1]; + return measureAndReturn(b, {q[0]}); } -static void controlledInverseHT(QCOProgramBuilder& b) { +static std::pair, SmallVector> +controlledInverseHT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.ctrl(q[0], q[1], [&b](ValueRange targets) { + auto res = b.ctrl(q[0], q[1], [&b](ValueRange targets) { auto wire = b.inv({targets[0]}, [&b](ValueRange innerTargets) { auto inner = b.h(innerTargets[0]); inner = b.t(inner); @@ -872,24 +910,31 @@ static void controlledInverseHT(QCOProgramBuilder& b) { })[0]; return SmallVector{wire}; }); + return measureAndReturn(b, {res.second[0]}); } -static void controlledH(QCOProgramBuilder& b) { +static std::pair, SmallVector> +controlledH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.ctrl(q[0], q[1], - [&b](ValueRange targets) { return SmallVector{b.h(targets[0])}; }); + auto res = b.ctrl(q[0], q[1], [&b](ValueRange targets) { + return SmallVector{b.h(targets[0])}; + }); + return measureAndReturn(b, {res.second[0]}); } -static void singleQubitRunsSplitByScfFor(QCOProgramBuilder& b) { +static std::pair, SmallVector> +singleQubitRunsSplitByScfFor(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); q[0] = b.t(q[0]); - b.scfFor(0, 1, 1, ValueRange{q[0]}, [&b](Value, ValueRange iterArgs) { - Value wire = iterArgs[0]; - wire = b.rz(0.321, wire); - wire = b.sx(wire); - return SmallVector{wire}; - }); + auto res = + b.scfFor(0, 1, 1, ValueRange{q[0]}, [&b](Value, ValueRange iterArgs) { + Value wire = iterArgs[0]; + wire = b.rz(0.321, wire); + wire = b.sx(wire); + return SmallVector{wire}; + }); + return measureAndReturn(b, {res[0]}); } //===----------------------------------------------------------------------===// @@ -910,7 +955,8 @@ TEST(FuseSingleQubitUnitaryRunsTest, FusesProgramsAllBases) { fx.setUp(); struct Case { - void (*program)(QCOProgramBuilder&); + std::pair, SmallVector> (*program)( + QCOProgramBuilder&); void (*extra)(func::FuncOp, StringRef); }; const std::array cases = {{ @@ -990,7 +1036,8 @@ TEST(FuseSingleQubitUnitaryRunsTest, DoesNotFuseAcrossBoundariesAllBases) { fx.setUp(); struct Case { - void (*program)(QCOProgramBuilder&); + std::pair, SmallVector> (*program)( + QCOProgramBuilder&); void (*check)(func::FuncOp, StringRef, MLIRContext*); }; const std::array cases = {{ From 973cf439484cceef632a607f409d058f628a5359 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 7 Jul 2026 17:30:38 +0200 Subject: [PATCH 46/80] chore(mlir): :recycle: move implementation of dead gate removal to SinkOp --- .../include/mlir/Dialect/QCO/IR/QCODialect.td | 2 - mlir/include/mlir/Dialect/QCO/IR/QCOOps.td | 4 +- .../Dialect/QCO/IR/Operations/MeasureOp.cpp | 27 --------- .../lib/Dialect/QCO/IR/Operations/ResetOp.cpp | 19 +------ mlir/lib/Dialect/QCO/IR/QCOOps.cpp | 31 ---------- .../Dialect/QCO/IR/QubitManagement/SinkOp.cpp | 57 ++++++++++++++++++- mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp | 37 ++++++------ 7 files changed, 79 insertions(+), 98 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/IR/QCODialect.td b/mlir/include/mlir/Dialect/QCO/IR/QCODialect.td index e7d98a0367..62d1f5bba4 100644 --- a/mlir/include/mlir/Dialect/QCO/IR/QCODialect.td +++ b/mlir/include/mlir/Dialect/QCO/IR/QCODialect.td @@ -38,8 +38,6 @@ def QCODialect : Dialect { let cppNamespace = "::mlir::qco"; let useDefaultTypePrinterParser = 1; - - let hasCanonicalizer = 1; } #endif // MLIR_DIALECT_QCO_IR_QCODIALECT_TD diff --git a/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td b/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td index f546ab94cb..1f4074e566 100644 --- a/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td +++ b/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td @@ -135,7 +135,6 @@ def MeasureOp : QCOOp<"measure", [Pure]> { }]>]; let hasVerifier = 1; - let hasCanonicalizer = 1; } def ResetOp : QCOOp<"reset", [Idempotent, SameOperandsAndResultType, Pure]> { @@ -1303,6 +1302,9 @@ def IfOp /// Return the yield of the else-block. YieldOp elseYield(); + Value getInputForOutput(Value output); + Value getOutputForInput(Value input); + /// Return the result that corresponds to the given qubit operand, /// or "empty" OpResult on failure. OpResult getTiedResult(OpOperand* qubit); diff --git a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp index b2107f7836..3353235e99 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp @@ -18,28 +18,6 @@ using namespace mlir; using namespace mlir::qco; -namespace { - -/** - * @brief Remove dead measurements. - */ -struct DeadMeasurementRemoval final : OpRewritePattern { - using OpRewritePattern::OpRewritePattern; - - LogicalResult matchAndRewrite(MeasureOp op, - PatternRewriter& rewriter) const override { - if (!checkDeadGate(op)) { - return failure(); - } - - rewriter.replaceAllUsesWith(op.getQubitOut(), op.getQubitIn()); - rewriter.eraseOp(op); - return success(); - } -}; - -} // namespace - LogicalResult MeasureOp::verify() { const auto registerName = getRegisterName(); const auto registerSize = getRegisterSize(); @@ -62,8 +40,3 @@ LogicalResult MeasureOp::verify() { } return success(); } - -void MeasureOp::getCanonicalizationPatterns(RewritePatternSet& results, - MLIRContext* context) { - results.add(context); -} diff --git a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp index 0886ba39a6..856f7c8a3b 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp @@ -102,23 +102,6 @@ struct RemoveResetAfterExtract final : OpRewritePattern { } }; -/** - * @brief Remove dead resets. - */ -struct DeadResetRemoval final : OpRewritePattern { - using OpRewritePattern::OpRewritePattern; - - LogicalResult matchAndRewrite(ResetOp op, - PatternRewriter& rewriter) const override { - if (!checkDeadGate(op)) { - return failure(); - } - - rewriter.replaceOp(op, op->getOperands()); - return success(); - } -}; - } // namespace OpFoldResult ResetOp::fold(FoldAdaptor /*adaptor*/) { @@ -131,5 +114,5 @@ OpFoldResult ResetOp::fold(FoldAdaptor /*adaptor*/) { void ResetOp::getCanonicalizationPatterns(RewritePatternSet& results, MLIRContext* context) { - results.add(context); + results.add(context); } diff --git a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp index 81fb68f925..ffa9796353 100644 --- a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp +++ b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp @@ -35,33 +35,6 @@ using namespace mlir; using namespace mlir::qco; -//===----------------------------------------------------------------------===// -// Dialect-Level Canonicalizers -//===----------------------------------------------------------------------===// - -namespace { - -/** - * @brief Remove dead gates. - */ -struct DeadGateElimination final - : public OpInterfaceRewritePattern { - - explicit DeadGateElimination(MLIRContext* context) - : OpInterfaceRewritePattern(context) {} - - LogicalResult matchAndRewrite(UnitaryOpInterface op, - PatternRewriter& rewriter) const override { - if (!checkDeadGate(op)) { - return failure(); - } - - rewriter.replaceOp(op, op.getInputQubits()); - return success(); - } -}; -} // namespace - //===----------------------------------------------------------------------===// // Custom Parsers //===----------------------------------------------------------------------===// @@ -221,10 +194,6 @@ void QCODialect::initialize() { >(); } -void QCODialect::getCanonicalizationPatterns(RewritePatternSet& results) const { - results.add(getContext()); -} - //===----------------------------------------------------------------------===// // Types //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp index ec8b33b833..03ca2d0637 100644 --- a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp @@ -9,7 +9,9 @@ */ #include "mlir/Dialect/QCO/IR/QCOOps.h" +#include "mlir/Dialect/QCO/QCOUtils.h" +#include #include #include #include @@ -39,9 +41,62 @@ struct RemoveAllocSinkPair final : OpRewritePattern { } }; +/** + * @brief Remove dead gates. + */ +struct DeadGateElimination final : public OpRewritePattern { + + explicit DeadGateElimination(MLIRContext* context) + : OpRewritePattern(context) {} + + LogicalResult matchAndRewrite(SinkOp op, + PatternRewriter& rewriter) const override { + Value currentValue = op.getQubit(); + auto* currentOp = currentValue.getDefiningOp(); + bool success = false; + while (currentOp != nullptr) { + if (!checkDeadGate(currentOp)) { + break; + } + + currentValue = + TypeSwitch(currentOp) + .Case([&](auto measureOp) { + rewriter.replaceAllUsesWith(measureOp.getQubitOut(), + measureOp.getQubitIn()); + rewriter.eraseOp(measureOp); + return measureOp.getQubitIn(); + }) + .Case([&](auto ifOp) { + auto newValue = ifOp.getInputForOutput(currentValue); + rewriter.replaceOp(ifOp, ifOp.getQubits()); + return newValue; + }) + .Case([&](auto resetOp) { + rewriter.replaceOp(resetOp, resetOp->getOperands()); + return resetOp.getQubitIn(); + }) + .Case([&](auto unitaryOp) { + auto newValue = unitaryOp.getInputForOutput(currentValue); + rewriter.replaceOp(unitaryOp, unitaryOp.getInputQubits()); + return newValue; + }) + .Default([&](auto) { return nullptr; }); + + if (currentValue == nullptr) { + break; + } + currentOp = currentValue.getDefiningOp(); + success = true; + } + + return llvm::success(success); + } +}; + } // namespace void SinkOp::getCanonicalizationPatterns(RewritePatternSet& results, MLIRContext* context) { - results.add(context); + results.add(context); } diff --git a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp index 36aa10828e..e0ad05a1d6 100644 --- a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp @@ -235,29 +235,11 @@ struct ConditionPropagation : public OpRewritePattern { return success(changed); } }; - -/** - * @brief Remove dead `IfOp` instructions. - */ -struct DeadIfRemoval final : OpRewritePattern { - using OpRewritePattern::OpRewritePattern; - - LogicalResult matchAndRewrite(IfOp op, - PatternRewriter& rewriter) const override { - if (!checkDeadGate(op)) { - return failure(); - } - - rewriter.replaceOp(op, op.getQubits()); - return success(); - } -}; } // namespace void IfOp::getCanonicalizationPatterns(RewritePatternSet& results, MLIRContext* context) { results.add(context); - results.add(context); populateRegionBranchOpInterfaceCanonicalizationPatterns( results, IfOp::getOperationName()); } @@ -300,6 +282,25 @@ LogicalResult IfOp::verify() { return success(); } +Value IfOp::getInputForOutput(Value output) { + auto resultCount = getResults().size(); + for (size_t i = 0; i < resultCount; ++i) { + if (output == getResult(i)) { + return getQubits()[i]; + } + } + llvm::reportFatalUsageError("Given qubit is not an output of the operation"); +} +Value IfOp::getOutputForInput(Value input) { + auto resultCount = getResults().size(); + for (size_t i = 0; i < resultCount; ++i) { + if (input == getQubits()[i]) { + return getResult(i); + } + } + llvm::reportFatalUsageError("Given qubit is not an input of the operation"); +} + OpResult IfOp::getTiedResult(OpOperand* qubit) { if (qubit->getOwner() != getOperation()) { return {}; From 12aa9d1b0ec01e774fa4d484e8d0e4e524f1c576 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 7 Jul 2026 17:40:36 +0200 Subject: [PATCH 47/80] feat(mlir): :sparkles: allow jeff translation to keep return values --- mlir/lib/Conversion/QCOToJeff/QCOToJeff.cpp | 8 +------- mlir/unittests/programs/qco_programs.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/mlir/lib/Conversion/QCOToJeff/QCOToJeff.cpp b/mlir/lib/Conversion/QCOToJeff/QCOToJeff.cpp index e18452a780..7f2cfa6578 100644 --- a/mlir/lib/Conversion/QCOToJeff/QCOToJeff.cpp +++ b/mlir/lib/Conversion/QCOToJeff/QCOToJeff.cpp @@ -1236,17 +1236,11 @@ struct ConvertQCOMainToJeff final : StatefulOpConversionPattern { getState().entryPointName = op.getSymName(); - // Update function signature and remove passthrough attribute + // Remove passthrough attribute from function signature rewriter.startOpModification(op); - op.setType(FunctionType::get(rewriter.getContext(), {}, {})); op->removeAttr("passthrough"); rewriter.finalizeOpModification(op); - // Replace return operation - rewriter.setInsertionPointToEnd(block); - func::ReturnOp::create(rewriter, returnOp->getLoc()); - rewriter.eraseOp(returnOp); - return success(); } }; diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index eb58122150..69ac02ea91 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -3348,11 +3348,11 @@ ifWithAngle(QCOProgramBuilder& b) { auto theta = b.floatConstant(0.123); auto q0 = b.h(q[0]); auto [measuredQubit, measureResult] = b.measure(q0); - b.qcoIf(measureResult, measuredQubit, [&](ValueRange args) { + q0 = b.qcoIf(measureResult, measuredQubit, [&](ValueRange args) { auto innerQubit = b.rx(theta, args[0]); return SmallVector{innerQubit}; - }); - return measureAndReturn(b, {q[0]}); + })[0]; + return measureAndReturn(b, {q0}); } std::pair, SmallVector> @@ -3659,7 +3659,8 @@ forLoopWithAngle(QCOProgramBuilder& b) { auto insert = b.qtensorInsert(q1, t0, iv); return SmallVector{insert}; }); - return measureAndReturn(b, {scfFor[0]}); + auto [newReg, q] = b.qtensorExtract(scfFor[0], 0); + return measureAndReturn(b, {q}); } std::pair, SmallVector> @@ -3799,7 +3800,7 @@ nestedIfOpForLoopWithAngle(QCOProgramBuilder& b) { }); return SmallVector{scfFor[0], args[1]}; }); - return measureAndReturn(b, {res[0]}); + return measureAndReturn(b, {res[1]}); } std::pair, SmallVector> From ff48f9361b5d2e5ff510c48963d577402d68e408 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 7 Jul 2026 17:49:59 +0200 Subject: [PATCH 48/80] fix(mlir): :rotating_light: potential fix to compiler error --- mlir/unittests/Compiler/test_compiler_pipeline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/unittests/Compiler/test_compiler_pipeline.cpp b/mlir/unittests/Compiler/test_compiler_pipeline.cpp index 78fc009fda..df3c3e68c4 100644 --- a/mlir/unittests/Compiler/test_compiler_pipeline.cpp +++ b/mlir/unittests/Compiler/test_compiler_pipeline.cpp @@ -330,7 +330,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER( mlir::qc::multipleClassicalRegistersAndMeasurements), MQT_NAMED_BUILDER( - mlir::qir::multipleClassicalRegistersAndMeasurements)}, + mlir::qir::multipleClassicalRegistersAndMeasurements)}, CompilerPipelineTestCase{ "MeasurementWithoutRegisters", nullptr, MQT_NAMED_BUILDER(mlir::qc::measurementWithoutRegisters), From dc8994407c682313aa099b2f5d3fbbc12dc9cd8d Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 7 Jul 2026 18:04:20 +0200 Subject: [PATCH 49/80] fix(mlir): :rotating_light: fix compiler issue by providing <> for default-value templates --- .../test_qc_to_qir_adaptive.cpp | 320 +++++++------- .../QCToQIRBase/test_qc_to_qir_base.cpp | 218 +++++----- mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp | 391 +++++++++--------- 3 files changed, 470 insertions(+), 459 deletions(-) diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp index e569eaa553..7741052c93 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp @@ -128,16 +128,16 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveBarrierOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"Barrier", MQT_NAMED_BUILDER(qc::barrier), - MQT_NAMED_BUILDER(qir::alloc1QubitRegister)}, + MQT_NAMED_BUILDER(qir::alloc1QubitRegister<>)}, QCToQIRAdaptiveTestCase{"BarrierTwoQubits", MQT_NAMED_BUILDER(qc::barrierTwoQubits), - MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(qir::allocQubitRegister<>)}, QCToQIRAdaptiveTestCase{"BarrierMultipleQubits", MQT_NAMED_BUILDER(qc::barrierMultipleQubits), - MQT_NAMED_BUILDER(qir::alloc3QubitRegister)}, + MQT_NAMED_BUILDER(qir::alloc3QubitRegister<>)}, QCToQIRAdaptiveTestCase{"SingleControlledBarrier", MQT_NAMED_BUILDER(qc::singleControlledBarrier), - MQT_NAMED_BUILDER(qir::allocQubitRegister)})); + MQT_NAMED_BUILDER(qir::allocQubitRegister<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/DcxOp.cpp @@ -145,15 +145,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveDCXOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"DCX", MQT_NAMED_BUILDER(qc::dcx), - MQT_NAMED_BUILDER(qir::dcx)}, + MQT_NAMED_BUILDER(qir::dcx<>)}, QCToQIRAdaptiveTestCase{ "SingleControlledDCX", MQT_NAMED_BUILDER(qc::singleControlledDcx), - MQT_NAMED_BUILDER(qir::singleControlledDcx)}, + MQT_NAMED_BUILDER(qir::singleControlledDcx<>)}, QCToQIRAdaptiveTestCase{ "MultipleControlledDCX", MQT_NAMED_BUILDER(qc::multipleControlledDcx), - MQT_NAMED_BUILDER(qir::multipleControlledDcx)})); + MQT_NAMED_BUILDER(qir::multipleControlledDcx<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/EcrOp.cpp @@ -161,15 +161,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveECROpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"ECR", MQT_NAMED_BUILDER(qc::ecr), - MQT_NAMED_BUILDER(qir::ecr)}, + MQT_NAMED_BUILDER(qir::ecr<>)}, QCToQIRAdaptiveTestCase{ "SingleControlledECR", MQT_NAMED_BUILDER(qc::singleControlledEcr), - MQT_NAMED_BUILDER(qir::singleControlledEcr)}, + MQT_NAMED_BUILDER(qir::singleControlledEcr<>)}, QCToQIRAdaptiveTestCase{ "MultipleControlledECR", MQT_NAMED_BUILDER(qc::multipleControlledEcr), - MQT_NAMED_BUILDER(qir::multipleControlledEcr)})); + MQT_NAMED_BUILDER(qir::multipleControlledEcr<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/GphaseOp.cpp @@ -177,7 +177,7 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(QCToQIRAdaptiveGPhaseOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{ "GlobalPhase", MQT_NAMED_BUILDER(qc::globalPhase), - MQT_NAMED_BUILDER(qir::globalPhase)})); + MQT_NAMED_BUILDER(qir::globalPhase<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/HOp.cpp @@ -186,16 +186,16 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveHOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"H", MQT_NAMED_BUILDER(qc::h), - MQT_NAMED_BUILDER(qir::h)}, + MQT_NAMED_BUILDER(qir::h<>)}, QCToQIRAdaptiveTestCase{"SingleControlledH", MQT_NAMED_BUILDER(qc::singleControlledH), - MQT_NAMED_BUILDER(qir::singleControlledH)}, + MQT_NAMED_BUILDER(qir::singleControlledH<>)}, QCToQIRAdaptiveTestCase{"MultipleControlledH", MQT_NAMED_BUILDER(qc::multipleControlledH), - MQT_NAMED_BUILDER(qir::multipleControlledH)}, + MQT_NAMED_BUILDER(qir::multipleControlledH<>)}, QCToQIRAdaptiveTestCase{"HWithoutRegister", MQT_NAMED_BUILDER(qc::hWithoutRegister), - MQT_NAMED_BUILDER(qir::hWithoutRegister)})); + MQT_NAMED_BUILDER(qir::hWithoutRegister<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/IdOp.cpp @@ -204,30 +204,31 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveIDOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"Identity", MQT_NAMED_BUILDER(qc::identity), - MQT_NAMED_BUILDER(qir::identity)}, + MQT_NAMED_BUILDER(qir::identity<>)}, QCToQIRAdaptiveTestCase{"SingleControlledIdentity", MQT_NAMED_BUILDER(qc::singleControlledIdentity), - MQT_NAMED_BUILDER(qir::twoQubitsOneIdentity)}, + MQT_NAMED_BUILDER(qir::twoQubitsOneIdentity<>)}, QCToQIRAdaptiveTestCase{ "MultipleControlledIdentity", MQT_NAMED_BUILDER(qc::multipleControlledIdentity), - MQT_NAMED_BUILDER(qir::threeQubitsOneIdentity)})); + MQT_NAMED_BUILDER(qir::threeQubitsOneIdentity<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/IswapOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveiSWAPOpTest, QCToQIRAdaptiveTest, - testing::Values( - QCToQIRAdaptiveTestCase{"iSWAP", MQT_NAMED_BUILDER(qc::iswap), - MQT_NAMED_BUILDER(qir::iswap)}, - QCToQIRAdaptiveTestCase{"SingleControllediSWAP", - MQT_NAMED_BUILDER(qc::singleControlledIswap), - MQT_NAMED_BUILDER(qir::singleControlledIswap)}, - QCToQIRAdaptiveTestCase{ - "MultipleControllediSWAP", - MQT_NAMED_BUILDER(qc::multipleControlledIswap), - MQT_NAMED_BUILDER(qir::multipleControlledIswap)})); + testing::Values(QCToQIRAdaptiveTestCase{"iSWAP", + MQT_NAMED_BUILDER(qc::iswap), + MQT_NAMED_BUILDER(qir::iswap<>)}, + QCToQIRAdaptiveTestCase{ + "SingleControllediSWAP", + MQT_NAMED_BUILDER(qc::singleControlledIswap), + MQT_NAMED_BUILDER(qir::singleControlledIswap<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControllediSWAP", + MQT_NAMED_BUILDER(qc::multipleControlledIswap), + MQT_NAMED_BUILDER(qir::multipleControlledIswap<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/POp.cpp @@ -236,13 +237,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptivePOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"P", MQT_NAMED_BUILDER(qc::p), - MQT_NAMED_BUILDER(qir::p)}, + MQT_NAMED_BUILDER(qir::p<>)}, QCToQIRAdaptiveTestCase{"SingleControlledP", MQT_NAMED_BUILDER(qc::singleControlledP), - MQT_NAMED_BUILDER(qir::singleControlledP)}, - QCToQIRAdaptiveTestCase{"MultipleControlledP", - MQT_NAMED_BUILDER(qc::multipleControlledP), - MQT_NAMED_BUILDER(qir::multipleControlledP)})); + MQT_NAMED_BUILDER(qir::singleControlledP<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledP", MQT_NAMED_BUILDER(qc::multipleControlledP), + MQT_NAMED_BUILDER(qir::multipleControlledP<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/ROp.cpp @@ -251,13 +252,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveROpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"R", MQT_NAMED_BUILDER(qc::r), - MQT_NAMED_BUILDER(qir::r)}, + MQT_NAMED_BUILDER(qir::r<>)}, QCToQIRAdaptiveTestCase{"SingleControlledR", MQT_NAMED_BUILDER(qc::singleControlledR), - MQT_NAMED_BUILDER(qir::singleControlledR)}, - QCToQIRAdaptiveTestCase{"MultipleControlledR", - MQT_NAMED_BUILDER(qc::multipleControlledR), - MQT_NAMED_BUILDER(qir::multipleControlledR)})); + MQT_NAMED_BUILDER(qir::singleControlledR<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledR", MQT_NAMED_BUILDER(qc::multipleControlledR), + MQT_NAMED_BUILDER(qir::multipleControlledR<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RxOp.cpp @@ -266,13 +267,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRXOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"RX", MQT_NAMED_BUILDER(qc::rx), - MQT_NAMED_BUILDER(qir::rx)}, + MQT_NAMED_BUILDER(qir::rx<>)}, QCToQIRAdaptiveTestCase{"SingleControlledRX", MQT_NAMED_BUILDER(qc::singleControlledRx), - MQT_NAMED_BUILDER(qir::singleControlledRx)}, - QCToQIRAdaptiveTestCase{"MultipleControlledRX", - MQT_NAMED_BUILDER(qc::multipleControlledRx), - MQT_NAMED_BUILDER(qir::multipleControlledRx)})); + MQT_NAMED_BUILDER(qir::singleControlledRx<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledRX", MQT_NAMED_BUILDER(qc::multipleControlledRx), + MQT_NAMED_BUILDER(qir::multipleControlledRx<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RxxOp.cpp @@ -280,15 +281,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRXXOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"RXX", MQT_NAMED_BUILDER(qc::rxx), - MQT_NAMED_BUILDER(qir::rxx)}, + MQT_NAMED_BUILDER(qir::rxx<>)}, QCToQIRAdaptiveTestCase{ "SingleControlledRXX", MQT_NAMED_BUILDER(qc::singleControlledRxx), - MQT_NAMED_BUILDER(qir::singleControlledRxx)}, + MQT_NAMED_BUILDER(qir::singleControlledRxx<>)}, QCToQIRAdaptiveTestCase{ "MultipleControlledRXX", MQT_NAMED_BUILDER(qc::multipleControlledRxx), - MQT_NAMED_BUILDER(qir::multipleControlledRxx)})); + MQT_NAMED_BUILDER(qir::multipleControlledRxx<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RyOp.cpp @@ -297,13 +298,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRYOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"RY", MQT_NAMED_BUILDER(qc::ry), - MQT_NAMED_BUILDER(qir::ry)}, + MQT_NAMED_BUILDER(qir::ry<>)}, QCToQIRAdaptiveTestCase{"SingleControlledRY", MQT_NAMED_BUILDER(qc::singleControlledRy), - MQT_NAMED_BUILDER(qir::singleControlledRy)}, - QCToQIRAdaptiveTestCase{"MultipleControlledRY", - MQT_NAMED_BUILDER(qc::multipleControlledRy), - MQT_NAMED_BUILDER(qir::multipleControlledRy)})); + MQT_NAMED_BUILDER(qir::singleControlledRy<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledRY", MQT_NAMED_BUILDER(qc::multipleControlledRy), + MQT_NAMED_BUILDER(qir::multipleControlledRy<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RyyOp.cpp @@ -311,15 +312,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRYYOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"RYY", MQT_NAMED_BUILDER(qc::ryy), - MQT_NAMED_BUILDER(qir::ryy)}, + MQT_NAMED_BUILDER(qir::ryy<>)}, QCToQIRAdaptiveTestCase{ "SingleControlledRYY", MQT_NAMED_BUILDER(qc::singleControlledRyy), - MQT_NAMED_BUILDER(qir::singleControlledRyy)}, + MQT_NAMED_BUILDER(qir::singleControlledRyy<>)}, QCToQIRAdaptiveTestCase{ "MultipleControlledRYY", MQT_NAMED_BUILDER(qc::multipleControlledRyy), - MQT_NAMED_BUILDER(qir::multipleControlledRyy)})); + MQT_NAMED_BUILDER(qir::multipleControlledRyy<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RzOp.cpp @@ -328,13 +329,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRZOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"RZ", MQT_NAMED_BUILDER(qc::rz), - MQT_NAMED_BUILDER(qir::rz)}, + MQT_NAMED_BUILDER(qir::rz<>)}, QCToQIRAdaptiveTestCase{"SingleControlledRZ", MQT_NAMED_BUILDER(qc::singleControlledRz), - MQT_NAMED_BUILDER(qir::singleControlledRz)}, - QCToQIRAdaptiveTestCase{"MultipleControlledRZ", - MQT_NAMED_BUILDER(qc::multipleControlledRz), - MQT_NAMED_BUILDER(qir::multipleControlledRz)})); + MQT_NAMED_BUILDER(qir::singleControlledRz<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledRZ", MQT_NAMED_BUILDER(qc::multipleControlledRz), + MQT_NAMED_BUILDER(qir::multipleControlledRz<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RzxOp.cpp @@ -342,15 +343,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRZXOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"RZX", MQT_NAMED_BUILDER(qc::rzx), - MQT_NAMED_BUILDER(qir::rzx)}, + MQT_NAMED_BUILDER(qir::rzx<>)}, QCToQIRAdaptiveTestCase{ "SingleControlledRZX", MQT_NAMED_BUILDER(qc::singleControlledRzx), - MQT_NAMED_BUILDER(qir::singleControlledRzx)}, + MQT_NAMED_BUILDER(qir::singleControlledRzx<>)}, QCToQIRAdaptiveTestCase{ "MultipleControlledRZX", MQT_NAMED_BUILDER(qc::multipleControlledRzx), - MQT_NAMED_BUILDER(qir::multipleControlledRzx)})); + MQT_NAMED_BUILDER(qir::multipleControlledRzx<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/RzzOp.cpp @@ -358,15 +359,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveRZZOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"RZZ", MQT_NAMED_BUILDER(qc::rzz), - MQT_NAMED_BUILDER(qir::rzz)}, + MQT_NAMED_BUILDER(qir::rzz<>)}, QCToQIRAdaptiveTestCase{ "SingleControlledRZZ", MQT_NAMED_BUILDER(qc::singleControlledRzz), - MQT_NAMED_BUILDER(qir::singleControlledRzz)}, + MQT_NAMED_BUILDER(qir::singleControlledRzz<>)}, QCToQIRAdaptiveTestCase{ "MultipleControlledRZZ", MQT_NAMED_BUILDER(qc::multipleControlledRzz), - MQT_NAMED_BUILDER(qir::multipleControlledRzz)})); + MQT_NAMED_BUILDER(qir::multipleControlledRzz<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SOp.cpp @@ -375,13 +376,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"S", MQT_NAMED_BUILDER(qc::s), - MQT_NAMED_BUILDER(qir::s)}, + MQT_NAMED_BUILDER(qir::s<>)}, QCToQIRAdaptiveTestCase{"SingleControlledS", MQT_NAMED_BUILDER(qc::singleControlledS), - MQT_NAMED_BUILDER(qir::singleControlledS)}, - QCToQIRAdaptiveTestCase{"MultipleControlledS", - MQT_NAMED_BUILDER(qc::multipleControlledS), - MQT_NAMED_BUILDER(qir::multipleControlledS)})); + MQT_NAMED_BUILDER(qir::singleControlledS<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledS", MQT_NAMED_BUILDER(qc::multipleControlledS), + MQT_NAMED_BUILDER(qir::multipleControlledS<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SdgOp.cpp @@ -389,15 +390,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSdgOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"Sdg", MQT_NAMED_BUILDER(qc::sdg), - MQT_NAMED_BUILDER(qir::sdg)}, + MQT_NAMED_BUILDER(qir::sdg<>)}, QCToQIRAdaptiveTestCase{ "SingleControlledSdg", MQT_NAMED_BUILDER(qc::singleControlledSdg), - MQT_NAMED_BUILDER(qir::singleControlledSdg)}, + MQT_NAMED_BUILDER(qir::singleControlledSdg<>)}, QCToQIRAdaptiveTestCase{ "MultipleControlledSdg", MQT_NAMED_BUILDER(qc::multipleControlledSdg), - MQT_NAMED_BUILDER(qir::multipleControlledSdg)})); + MQT_NAMED_BUILDER(qir::multipleControlledSdg<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SwapOp.cpp @@ -405,15 +406,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSWAPOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"SWAP", MQT_NAMED_BUILDER(qc::swap), - MQT_NAMED_BUILDER(qir::swap)}, + MQT_NAMED_BUILDER(qir::swap<>)}, QCToQIRAdaptiveTestCase{ "SingleControlledSWAP", MQT_NAMED_BUILDER(qc::singleControlledSwap), - MQT_NAMED_BUILDER(qir::singleControlledSwap)}, + MQT_NAMED_BUILDER(qir::singleControlledSwap<>)}, QCToQIRAdaptiveTestCase{ "MultipleControlledSWAP", MQT_NAMED_BUILDER(qc::multipleControlledSwap), - MQT_NAMED_BUILDER(qir::multipleControlledSwap)})); + MQT_NAMED_BUILDER(qir::multipleControlledSwap<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SxOp.cpp @@ -422,13 +423,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSXOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"SX", MQT_NAMED_BUILDER(qc::sx), - MQT_NAMED_BUILDER(qir::sx)}, + MQT_NAMED_BUILDER(qir::sx<>)}, QCToQIRAdaptiveTestCase{"SingleControlledSX", MQT_NAMED_BUILDER(qc::singleControlledSx), - MQT_NAMED_BUILDER(qir::singleControlledSx)}, - QCToQIRAdaptiveTestCase{"MultipleControlledSX", - MQT_NAMED_BUILDER(qc::multipleControlledSx), - MQT_NAMED_BUILDER(qir::multipleControlledSx)})); + MQT_NAMED_BUILDER(qir::singleControlledSx<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledSX", MQT_NAMED_BUILDER(qc::multipleControlledSx), + MQT_NAMED_BUILDER(qir::multipleControlledSx<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/SxdgOp.cpp @@ -436,15 +437,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveSXdgOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"SXdg", MQT_NAMED_BUILDER(qc::sxdg), - MQT_NAMED_BUILDER(qir::sxdg)}, + MQT_NAMED_BUILDER(qir::sxdg<>)}, QCToQIRAdaptiveTestCase{ "SingleControlledSXdg", MQT_NAMED_BUILDER(qc::singleControlledSxdg), - MQT_NAMED_BUILDER(qir::singleControlledSxdg)}, + MQT_NAMED_BUILDER(qir::singleControlledSxdg<>)}, QCToQIRAdaptiveTestCase{ "MultipleControlledSXdg", MQT_NAMED_BUILDER(qc::multipleControlledSxdg), - MQT_NAMED_BUILDER(qir::multipleControlledSxdg)})); + MQT_NAMED_BUILDER(qir::multipleControlledSxdg<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/TOp.cpp @@ -453,13 +454,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveTOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"T", MQT_NAMED_BUILDER(qc::t_), - MQT_NAMED_BUILDER(qir::t_)}, + MQT_NAMED_BUILDER(qir::t_<>)}, QCToQIRAdaptiveTestCase{"SingleControlledT", MQT_NAMED_BUILDER(qc::singleControlledT), - MQT_NAMED_BUILDER(qir::singleControlledT)}, - QCToQIRAdaptiveTestCase{"MultipleControlledT", - MQT_NAMED_BUILDER(qc::multipleControlledT), - MQT_NAMED_BUILDER(qir::multipleControlledT)})); + MQT_NAMED_BUILDER(qir::singleControlledT<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledT", MQT_NAMED_BUILDER(qc::multipleControlledT), + MQT_NAMED_BUILDER(qir::multipleControlledT<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/TdgOp.cpp @@ -467,15 +468,15 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveTdgOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"Tdg", MQT_NAMED_BUILDER(qc::tdg), - MQT_NAMED_BUILDER(qir::tdg)}, + MQT_NAMED_BUILDER(qir::tdg<>)}, QCToQIRAdaptiveTestCase{ "SingleControlledTdg", MQT_NAMED_BUILDER(qc::singleControlledTdg), - MQT_NAMED_BUILDER(qir::singleControlledTdg)}, + MQT_NAMED_BUILDER(qir::singleControlledTdg<>)}, QCToQIRAdaptiveTestCase{ "MultipleControlledTdg", MQT_NAMED_BUILDER(qc::multipleControlledTdg), - MQT_NAMED_BUILDER(qir::multipleControlledTdg)})); + MQT_NAMED_BUILDER(qir::multipleControlledTdg<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/U2Op.cpp @@ -484,13 +485,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveU2OpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"U2", MQT_NAMED_BUILDER(qc::u2), - MQT_NAMED_BUILDER(qir::u2)}, + MQT_NAMED_BUILDER(qir::u2<>)}, QCToQIRAdaptiveTestCase{"SingleControlledU2", MQT_NAMED_BUILDER(qc::singleControlledU2), - MQT_NAMED_BUILDER(qir::singleControlledU2)}, - QCToQIRAdaptiveTestCase{"MultipleControlledU2", - MQT_NAMED_BUILDER(qc::multipleControlledU2), - MQT_NAMED_BUILDER(qir::multipleControlledU2)})); + MQT_NAMED_BUILDER(qir::singleControlledU2<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledU2", MQT_NAMED_BUILDER(qc::multipleControlledU2), + MQT_NAMED_BUILDER(qir::multipleControlledU2<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/UOp.cpp @@ -499,13 +500,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveUOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"U", MQT_NAMED_BUILDER(qc::u), - MQT_NAMED_BUILDER(qir::u)}, + MQT_NAMED_BUILDER(qir::u<>)}, QCToQIRAdaptiveTestCase{"SingleControlledU", MQT_NAMED_BUILDER(qc::singleControlledU), - MQT_NAMED_BUILDER(qir::singleControlledU)}, - QCToQIRAdaptiveTestCase{"MultipleControlledU", - MQT_NAMED_BUILDER(qc::multipleControlledU), - MQT_NAMED_BUILDER(qir::multipleControlledU)})); + MQT_NAMED_BUILDER(qir::singleControlledU<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledU", MQT_NAMED_BUILDER(qc::multipleControlledU), + MQT_NAMED_BUILDER(qir::multipleControlledU<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/XOp.cpp @@ -514,30 +515,30 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveXOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"X", MQT_NAMED_BUILDER(qc::x), - MQT_NAMED_BUILDER(qir::x)}, + MQT_NAMED_BUILDER(qir::x<>)}, QCToQIRAdaptiveTestCase{"SingleControlledX", MQT_NAMED_BUILDER(qc::singleControlledX), - MQT_NAMED_BUILDER(qir::singleControlledX)}, - QCToQIRAdaptiveTestCase{"MultipleControlledX", - MQT_NAMED_BUILDER(qc::multipleControlledX), - MQT_NAMED_BUILDER(qir::multipleControlledX)})); + MQT_NAMED_BUILDER(qir::singleControlledX<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledX", MQT_NAMED_BUILDER(qc::multipleControlledX), + MQT_NAMED_BUILDER(qir::multipleControlledX<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/XxMinusYyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveXXMinusYYOpTest, QCToQIRAdaptiveTest, - testing::Values(QCToQIRAdaptiveTestCase{"XXMinusYY", - MQT_NAMED_BUILDER(qc::xxMinusYY), - MQT_NAMED_BUILDER(qir::xxMinusYY)}, - QCToQIRAdaptiveTestCase{ - "SingleControlledXXMinusYY", - MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), - MQT_NAMED_BUILDER(qir::singleControlledXxMinusYY)}, - QCToQIRAdaptiveTestCase{ - "MultipleControlledXXMinusYY", - MQT_NAMED_BUILDER(qc::multipleControlledXxMinusYY), - MQT_NAMED_BUILDER(qir::multipleControlledXxMinusYY)})); + testing::Values( + QCToQIRAdaptiveTestCase{"XXMinusYY", MQT_NAMED_BUILDER(qc::xxMinusYY), + MQT_NAMED_BUILDER(qir::xxMinusYY<>)}, + QCToQIRAdaptiveTestCase{ + "SingleControlledXXMinusYY", + MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), + MQT_NAMED_BUILDER(qir::singleControlledXxMinusYY<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledXXMinusYY", + MQT_NAMED_BUILDER(qc::multipleControlledXxMinusYY), + MQT_NAMED_BUILDER(qir::multipleControlledXxMinusYY<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/XxPlusYyOp.cpp @@ -546,15 +547,15 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveXXPlusYYOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{"XXPlusYY", MQT_NAMED_BUILDER(qc::xxPlusYY), - MQT_NAMED_BUILDER(qir::xxPlusYY)}, + MQT_NAMED_BUILDER(qir::xxPlusYY<>)}, QCToQIRAdaptiveTestCase{ "SingleControlledXXPlusYY", MQT_NAMED_BUILDER(qc::singleControlledXxPlusYY), - MQT_NAMED_BUILDER(qir::singleControlledXxPlusYY)}, + MQT_NAMED_BUILDER(qir::singleControlledXxPlusYY<>)}, QCToQIRAdaptiveTestCase{ "MultipleControlledXXPlusYY", MQT_NAMED_BUILDER(qc::multipleControlledXxPlusYY), - MQT_NAMED_BUILDER(qir::multipleControlledXxPlusYY)})); + MQT_NAMED_BUILDER(qir::multipleControlledXxPlusYY<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/YOp.cpp @@ -563,13 +564,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveYOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"Y", MQT_NAMED_BUILDER(qc::y), - MQT_NAMED_BUILDER(qir::y)}, + MQT_NAMED_BUILDER(qir::y<>)}, QCToQIRAdaptiveTestCase{"SingleControlledY", MQT_NAMED_BUILDER(qc::singleControlledY), - MQT_NAMED_BUILDER(qir::singleControlledY)}, - QCToQIRAdaptiveTestCase{"MultipleControlledY", - MQT_NAMED_BUILDER(qc::multipleControlledY), - MQT_NAMED_BUILDER(qir::multipleControlledY)})); + MQT_NAMED_BUILDER(qir::singleControlledY<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledY", MQT_NAMED_BUILDER(qc::multipleControlledY), + MQT_NAMED_BUILDER(qir::multipleControlledY<>)})); /// @} /// \name QCToQIRAdaptive/Operations/StandardGates/ZOp.cpp @@ -578,13 +579,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveZOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"Z", MQT_NAMED_BUILDER(qc::z), - MQT_NAMED_BUILDER(qir::z)}, + MQT_NAMED_BUILDER(qir::z<>)}, QCToQIRAdaptiveTestCase{"SingleControlledZ", MQT_NAMED_BUILDER(qc::singleControlledZ), - MQT_NAMED_BUILDER(qir::singleControlledZ)}, - QCToQIRAdaptiveTestCase{"MultipleControlledZ", - MQT_NAMED_BUILDER(qc::multipleControlledZ), - MQT_NAMED_BUILDER(qir::multipleControlledZ)})); + MQT_NAMED_BUILDER(qir::singleControlledZ<>)}, + QCToQIRAdaptiveTestCase{ + "MultipleControlledZ", MQT_NAMED_BUILDER(qc::multipleControlledZ), + MQT_NAMED_BUILDER(qir::multipleControlledZ<>)})); /// @} /// \name QCToQIRAdaptive/Operations/MeasureOp.cpp @@ -595,15 +596,15 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveTestCase{ "SingleMeasurementToSingleBit", MQT_NAMED_BUILDER(qc::singleMeasurementToSingleBit), - MQT_NAMED_BUILDER(qir::singleMeasurementToSingleBit)}, + MQT_NAMED_BUILDER(qir::singleMeasurementToSingleBit<>)}, QCToQIRAdaptiveTestCase{ "RepeatedMeasurementToSameBit", MQT_NAMED_BUILDER(qc::repeatedMeasurementToSameBit), - MQT_NAMED_BUILDER(qir::repeatedMeasurementToSameBit)}, + MQT_NAMED_BUILDER(qir::repeatedMeasurementToSameBit<>)}, QCToQIRAdaptiveTestCase{ "RepeatedMeasurementToDifferentBits", MQT_NAMED_BUILDER(qc::repeatedMeasurementToDifferentBits), - MQT_NAMED_BUILDER(qir::repeatedMeasurementToDifferentBits)}, + MQT_NAMED_BUILDER(qir::repeatedMeasurementToDifferentBits<>)}, QCToQIRAdaptiveTestCase{ "MultipleClassicalRegistersAndMeasurements", MQT_NAMED_BUILDER(qc::multipleClassicalRegistersAndMeasurements), @@ -612,7 +613,7 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveTestCase{ "MeasurementWithoutRegisters", MQT_NAMED_BUILDER(qc::measurementWithoutRegisters), - MQT_NAMED_BUILDER(qir::measurementWithoutRegisters)})); + MQT_NAMED_BUILDER(qir::measurementWithoutRegisters<>)})); /// @} /// \name QCToQIRAdaptive/Operations/ResetOp.cpp @@ -622,26 +623,27 @@ INSTANTIATE_TEST_SUITE_P( testing::Values( QCToQIRAdaptiveTestCase{"ResetQubitWithoutOp", MQT_NAMED_BUILDER(qc::resetQubitWithoutOp), - MQT_NAMED_BUILDER(qir::resetQubitWithoutOp)}, + MQT_NAMED_BUILDER(qir::resetQubitWithoutOp<>)}, QCToQIRAdaptiveTestCase{ "ResetMultipleQubitsWithoutOp", MQT_NAMED_BUILDER(qc::resetMultipleQubitsWithoutOp), - MQT_NAMED_BUILDER(qir::resetMultipleQubitsWithoutOp)}, - QCToQIRAdaptiveTestCase{"RepeatedResetWithoutOp", - MQT_NAMED_BUILDER(qc::repeatedResetWithoutOp), - MQT_NAMED_BUILDER(qir::repeatedResetWithoutOp)}, + MQT_NAMED_BUILDER(qir::resetMultipleQubitsWithoutOp<>)}, + QCToQIRAdaptiveTestCase{ + "RepeatedResetWithoutOp", + MQT_NAMED_BUILDER(qc::repeatedResetWithoutOp), + MQT_NAMED_BUILDER(qir::repeatedResetWithoutOp<>)}, QCToQIRAdaptiveTestCase{ "ResetQubitAfterSingleOp", MQT_NAMED_BUILDER(qc::resetQubitAfterSingleOp), - MQT_NAMED_BUILDER(qir::resetQubitAfterSingleOp)}, + MQT_NAMED_BUILDER(qir::resetQubitAfterSingleOp<>)}, QCToQIRAdaptiveTestCase{ "ResetMultipleQubitsAfterSingleOp", MQT_NAMED_BUILDER(qc::resetMultipleQubitsAfterSingleOp), - MQT_NAMED_BUILDER(qir::resetMultipleQubitsAfterSingleOp)}, + MQT_NAMED_BUILDER(qir::resetMultipleQubitsAfterSingleOp<>)}, QCToQIRAdaptiveTestCase{ "RepeatedResetAfterSingleOp", MQT_NAMED_BUILDER(qc::repeatedResetAfterSingleOp), - MQT_NAMED_BUILDER(qir::repeatedResetAfterSingleOp)})); + MQT_NAMED_BUILDER(qir::repeatedResetAfterSingleOp<>)})); /// @} /// \name QCToQIRAdaptive/QubitManagement/QubitManagement.cpp @@ -650,21 +652,21 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRAdaptiveQubitManagementTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"AllocQubit", MQT_NAMED_BUILDER(qc::allocQubit), - MQT_NAMED_BUILDER(qir::allocQubit)}, + MQT_NAMED_BUILDER(qir::allocQubit<>)}, QCToQIRAdaptiveTestCase{"AllocQubitRegister", MQT_NAMED_BUILDER(qc::allocQubitRegister), - MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(qir::allocQubitRegister<>)}, QCToQIRAdaptiveTestCase{ "AllocMultipleQubitRegisters", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegisters), - MQT_NAMED_BUILDER(qir::allocMultipleQubitRegisters)}, + MQT_NAMED_BUILDER(qir::allocMultipleQubitRegisters<>)}, QCToQIRAdaptiveTestCase{ "AllocMultipleQubitRegistersWithOps", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegistersWithOps), - MQT_NAMED_BUILDER(qir::allocMultipleQubitRegistersWithOps)}, + MQT_NAMED_BUILDER(qir::allocMultipleQubitRegistersWithOps<>)}, QCToQIRAdaptiveTestCase{"AllocLargeRegister", MQT_NAMED_BUILDER(qc::allocLargeRegister), - MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(qir::allocQubitRegister<>)}, QCToQIRAdaptiveTestCase{"StaticQubits", MQT_NAMED_BUILDER(qc::staticQubits), MQT_NAMED_BUILDER(qir::staticQubits)}, @@ -687,7 +689,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(qir::staticQubitsWithInv)}, QCToQIRAdaptiveTestCase{"AllocDeallocPair", MQT_NAMED_BUILDER(qc::allocDeallocPair), - MQT_NAMED_BUILDER(qir::emptyQIR)})); + MQT_NAMED_BUILDER(qir::emptyQIR<>)})); /// @} /// \name QCToQIRAdaptive/Operations/IfOp.cpp @@ -696,15 +698,15 @@ INSTANTIATE_TEST_SUITE_P( SCFIfOpTest, QCToQIRAdaptiveTest, testing::Values( QCToQIRAdaptiveTestCase{"SimpleIfOp", MQT_NAMED_BUILDER(qc::simpleIf), - MQT_NAMED_BUILDER(qir::simpleIf)}, + MQT_NAMED_BUILDER(qir::simpleIf<>)}, QCToQIRAdaptiveTestCase{"IfTwoQubits", MQT_NAMED_BUILDER(qc::ifTwoQubits), - MQT_NAMED_BUILDER(qir::ifTwoQubits)}, + MQT_NAMED_BUILDER(qir::ifTwoQubits<>)}, QCToQIRAdaptiveTestCase{"IfElse", MQT_NAMED_BUILDER(qc::ifElse), - MQT_NAMED_BUILDER(qir::ifElse)}, + MQT_NAMED_BUILDER(qir::ifElse<>)}, QCToQIRAdaptiveTestCase{"NestedIfOpForLoop", MQT_NAMED_BUILDER(qc::nestedIfOpForLoop), - MQT_NAMED_BUILDER(qir::nestedIfOpForLoop)})); + MQT_NAMED_BUILDER(qir::nestedIfOpForLoop<>)})); /// @} /// \name QCToQIRAdaptive/Operations/WhileOp.cpp @@ -714,10 +716,10 @@ INSTANTIATE_TEST_SUITE_P( testing::Values( QCToQIRAdaptiveTestCase{"SimpleWhile", MQT_NAMED_BUILDER(qc::simpleWhileReset), - MQT_NAMED_BUILDER(qir::simpleWhileReset)}, + MQT_NAMED_BUILDER(qir::simpleWhileReset<>)}, QCToQIRAdaptiveTestCase{"SimpleDoWhile", MQT_NAMED_BUILDER(qc::simpleDoWhileReset), - MQT_NAMED_BUILDER(qir::simpleDoWhileReset)})); + MQT_NAMED_BUILDER(qir::simpleDoWhileReset<>)})); /// \name QCToQIRAdaptive/Operations/ForOp.cpp /// @{ @@ -726,13 +728,13 @@ INSTANTIATE_TEST_SUITE_P( testing::Values( QCToQIRAdaptiveTestCase{"SimpleForLoop", MQT_NAMED_BUILDER(qc::simpleForLoop), - MQT_NAMED_BUILDER(qir::simpleForLoop)}, + MQT_NAMED_BUILDER(qir::simpleForLoop<>)}, QCToQIRAdaptiveTestCase{"NestedForLoopIfOp", MQT_NAMED_BUILDER(qc::nestedForLoopIfOp), - MQT_NAMED_BUILDER(qir::nestedForLoopIfOp)}, + MQT_NAMED_BUILDER(qir::nestedForLoopIfOp<>)}, QCToQIRAdaptiveTestCase{"NestedForLoopWhileOp", MQT_NAMED_BUILDER(qc::nestedForLoopWhileOp), - MQT_NAMED_BUILDER(qir::nestedForLoopWhileOp)}, + MQT_NAMED_BUILDER(qir::nestedForLoopWhileOp<>)}, QCToQIRAdaptiveTestCase{ "nestedForLoopCtrlOpWithSeparateQubit", MQT_NAMED_BUILDER(qc::nestedForLoopCtrlOpWithSeparateQubit), @@ -749,5 +751,5 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(QCToQIRCtrlOpTest, QCToQIRAdaptiveTest, testing::Values(QCToQIRAdaptiveTestCase{ "NestedCtrlTwo", MQT_NAMED_BUILDER(qc::ctrlTwo), - MQT_NAMED_BUILDER(qir::ctrlTwo)})); + MQT_NAMED_BUILDER(qir::ctrlTwo<>)})); /// @} diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp index 42a6ebfda9..ecbbc0b62e 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp @@ -126,16 +126,16 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseBarrierOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Barrier", MQT_NAMED_BUILDER(qc::barrier), - MQT_NAMED_BUILDER(qir::alloc1QubitRegister)}, + MQT_NAMED_BUILDER(qir::alloc1QubitRegister<>)}, QCToQIRBaseTestCase{"BarrierTwoQubits", MQT_NAMED_BUILDER(qc::barrierTwoQubits), - MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(qir::allocQubitRegister<>)}, QCToQIRBaseTestCase{"BarrierMultipleQubits", MQT_NAMED_BUILDER(qc::barrierMultipleQubits), - MQT_NAMED_BUILDER(qir::alloc3QubitRegister)}, + MQT_NAMED_BUILDER(qir::alloc3QubitRegister<>)}, QCToQIRBaseTestCase{"SingleControlledBarrier", MQT_NAMED_BUILDER(qc::singleControlledBarrier), - MQT_NAMED_BUILDER(qir::allocQubitRegister)})); + MQT_NAMED_BUILDER(qir::allocQubitRegister<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/DcxOp.cpp @@ -144,13 +144,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseDCXOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"DCX", MQT_NAMED_BUILDER(qc::dcx), - MQT_NAMED_BUILDER(qir::dcx)}, + MQT_NAMED_BUILDER(qir::dcx<>)}, QCToQIRBaseTestCase{"SingleControlledDCX", MQT_NAMED_BUILDER(qc::singleControlledDcx), - MQT_NAMED_BUILDER(qir::singleControlledDcx)}, + MQT_NAMED_BUILDER(qir::singleControlledDcx<>)}, QCToQIRBaseTestCase{"MultipleControlledDCX", MQT_NAMED_BUILDER(qc::multipleControlledDcx), - MQT_NAMED_BUILDER(qir::multipleControlledDcx)})); + MQT_NAMED_BUILDER(qir::multipleControlledDcx<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/EcrOp.cpp @@ -159,13 +159,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseECROpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"ECR", MQT_NAMED_BUILDER(qc::ecr), - MQT_NAMED_BUILDER(qir::ecr)}, + MQT_NAMED_BUILDER(qir::ecr<>)}, QCToQIRBaseTestCase{"SingleControlledECR", MQT_NAMED_BUILDER(qc::singleControlledEcr), - MQT_NAMED_BUILDER(qir::singleControlledEcr)}, + MQT_NAMED_BUILDER(qir::singleControlledEcr<>)}, QCToQIRBaseTestCase{"MultipleControlledECR", MQT_NAMED_BUILDER(qc::multipleControlledEcr), - MQT_NAMED_BUILDER(qir::multipleControlledEcr)})); + MQT_NAMED_BUILDER(qir::multipleControlledEcr<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/GphaseOp.cpp @@ -173,7 +173,7 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(QCToQIRBaseGPhaseOpTest, QCToQIRBaseTest, testing::Values(QCToQIRBaseTestCase{ "GlobalPhase", MQT_NAMED_BUILDER(qc::globalPhase), - MQT_NAMED_BUILDER(qir::globalPhase)})); + MQT_NAMED_BUILDER(qir::globalPhase<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/HOp.cpp @@ -182,16 +182,16 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseHOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"H", MQT_NAMED_BUILDER(qc::h), - MQT_NAMED_BUILDER(qir::h)}, + MQT_NAMED_BUILDER(qir::h<>)}, QCToQIRBaseTestCase{"SingleControlledH", MQT_NAMED_BUILDER(qc::singleControlledH), - MQT_NAMED_BUILDER(qir::singleControlledH)}, + MQT_NAMED_BUILDER(qir::singleControlledH<>)}, QCToQIRBaseTestCase{"MultipleControlledH", MQT_NAMED_BUILDER(qc::multipleControlledH), - MQT_NAMED_BUILDER(qir::multipleControlledH)}, + MQT_NAMED_BUILDER(qir::multipleControlledH<>)}, QCToQIRBaseTestCase{"HWithoutRegister", MQT_NAMED_BUILDER(qc::hWithoutRegister), - MQT_NAMED_BUILDER(qir::hWithoutRegister)})); + MQT_NAMED_BUILDER(qir::hWithoutRegister<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/IdOp.cpp @@ -200,28 +200,29 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseIDOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Identity", MQT_NAMED_BUILDER(qc::identity), - MQT_NAMED_BUILDER(qir::identity)}, + MQT_NAMED_BUILDER(qir::identity<>)}, QCToQIRBaseTestCase{"SingleControlledIdentity", MQT_NAMED_BUILDER(qc::singleControlledIdentity), - MQT_NAMED_BUILDER(qir::twoQubitsOneIdentity)}, + MQT_NAMED_BUILDER(qir::twoQubitsOneIdentity<>)}, QCToQIRBaseTestCase{"MultipleControlledIdentity", MQT_NAMED_BUILDER(qc::multipleControlledIdentity), - MQT_NAMED_BUILDER(qir::threeQubitsOneIdentity)})); + MQT_NAMED_BUILDER(qir::threeQubitsOneIdentity<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/IswapOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseiSWAPOpTest, QCToQIRBaseTest, - testing::Values( - QCToQIRBaseTestCase{"iSWAP", MQT_NAMED_BUILDER(qc::iswap), - MQT_NAMED_BUILDER(qir::iswap)}, - QCToQIRBaseTestCase{"SingleControllediSWAP", - MQT_NAMED_BUILDER(qc::singleControlledIswap), - MQT_NAMED_BUILDER(qir::singleControlledIswap)}, - QCToQIRBaseTestCase{"MultipleControllediSWAP", - MQT_NAMED_BUILDER(qc::multipleControlledIswap), - MQT_NAMED_BUILDER(qir::multipleControlledIswap)})); + testing::Values(QCToQIRBaseTestCase{"iSWAP", MQT_NAMED_BUILDER(qc::iswap), + MQT_NAMED_BUILDER(qir::iswap<>)}, + QCToQIRBaseTestCase{ + "SingleControllediSWAP", + MQT_NAMED_BUILDER(qc::singleControlledIswap), + MQT_NAMED_BUILDER(qir::singleControlledIswap<>)}, + QCToQIRBaseTestCase{ + "MultipleControllediSWAP", + MQT_NAMED_BUILDER(qc::multipleControlledIswap), + MQT_NAMED_BUILDER(qir::multipleControlledIswap<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/POp.cpp @@ -230,13 +231,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBasePOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"P", MQT_NAMED_BUILDER(qc::p), - MQT_NAMED_BUILDER(qir::p)}, + MQT_NAMED_BUILDER(qir::p<>)}, QCToQIRBaseTestCase{"SingleControlledP", MQT_NAMED_BUILDER(qc::singleControlledP), - MQT_NAMED_BUILDER(qir::singleControlledP)}, + MQT_NAMED_BUILDER(qir::singleControlledP<>)}, QCToQIRBaseTestCase{"MultipleControlledP", MQT_NAMED_BUILDER(qc::multipleControlledP), - MQT_NAMED_BUILDER(qir::multipleControlledP)})); + MQT_NAMED_BUILDER(qir::multipleControlledP<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/ROp.cpp @@ -245,13 +246,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseROpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"R", MQT_NAMED_BUILDER(qc::r), - MQT_NAMED_BUILDER(qir::r)}, + MQT_NAMED_BUILDER(qir::r<>)}, QCToQIRBaseTestCase{"SingleControlledR", MQT_NAMED_BUILDER(qc::singleControlledR), - MQT_NAMED_BUILDER(qir::singleControlledR)}, + MQT_NAMED_BUILDER(qir::singleControlledR<>)}, QCToQIRBaseTestCase{"MultipleControlledR", MQT_NAMED_BUILDER(qc::multipleControlledR), - MQT_NAMED_BUILDER(qir::multipleControlledR)})); + MQT_NAMED_BUILDER(qir::multipleControlledR<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RxOp.cpp @@ -260,13 +261,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRXOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RX", MQT_NAMED_BUILDER(qc::rx), - MQT_NAMED_BUILDER(qir::rx)}, + MQT_NAMED_BUILDER(qir::rx<>)}, QCToQIRBaseTestCase{"SingleControlledRX", MQT_NAMED_BUILDER(qc::singleControlledRx), - MQT_NAMED_BUILDER(qir::singleControlledRx)}, + MQT_NAMED_BUILDER(qir::singleControlledRx<>)}, QCToQIRBaseTestCase{"MultipleControlledRX", MQT_NAMED_BUILDER(qc::multipleControlledRx), - MQT_NAMED_BUILDER(qir::multipleControlledRx)})); + MQT_NAMED_BUILDER(qir::multipleControlledRx<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RxxOp.cpp @@ -275,13 +276,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRXXOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RXX", MQT_NAMED_BUILDER(qc::rxx), - MQT_NAMED_BUILDER(qir::rxx)}, + MQT_NAMED_BUILDER(qir::rxx<>)}, QCToQIRBaseTestCase{"SingleControlledRXX", MQT_NAMED_BUILDER(qc::singleControlledRxx), - MQT_NAMED_BUILDER(qir::singleControlledRxx)}, + MQT_NAMED_BUILDER(qir::singleControlledRxx<>)}, QCToQIRBaseTestCase{"MultipleControlledRXX", MQT_NAMED_BUILDER(qc::multipleControlledRxx), - MQT_NAMED_BUILDER(qir::multipleControlledRxx)})); + MQT_NAMED_BUILDER(qir::multipleControlledRxx<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RyOp.cpp @@ -290,13 +291,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RY", MQT_NAMED_BUILDER(qc::ry), - MQT_NAMED_BUILDER(qir::ry)}, + MQT_NAMED_BUILDER(qir::ry<>)}, QCToQIRBaseTestCase{"SingleControlledRY", MQT_NAMED_BUILDER(qc::singleControlledRy), - MQT_NAMED_BUILDER(qir::singleControlledRy)}, + MQT_NAMED_BUILDER(qir::singleControlledRy<>)}, QCToQIRBaseTestCase{"MultipleControlledRY", MQT_NAMED_BUILDER(qc::multipleControlledRy), - MQT_NAMED_BUILDER(qir::multipleControlledRy)})); + MQT_NAMED_BUILDER(qir::multipleControlledRy<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RyyOp.cpp @@ -305,13 +306,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRYYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RYY", MQT_NAMED_BUILDER(qc::ryy), - MQT_NAMED_BUILDER(qir::ryy)}, + MQT_NAMED_BUILDER(qir::ryy<>)}, QCToQIRBaseTestCase{"SingleControlledRYY", MQT_NAMED_BUILDER(qc::singleControlledRyy), - MQT_NAMED_BUILDER(qir::singleControlledRyy)}, + MQT_NAMED_BUILDER(qir::singleControlledRyy<>)}, QCToQIRBaseTestCase{"MultipleControlledRYY", MQT_NAMED_BUILDER(qc::multipleControlledRyy), - MQT_NAMED_BUILDER(qir::multipleControlledRyy)})); + MQT_NAMED_BUILDER(qir::multipleControlledRyy<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RzOp.cpp @@ -320,13 +321,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRZOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RZ", MQT_NAMED_BUILDER(qc::rz), - MQT_NAMED_BUILDER(qir::rz)}, + MQT_NAMED_BUILDER(qir::rz<>)}, QCToQIRBaseTestCase{"SingleControlledRZ", MQT_NAMED_BUILDER(qc::singleControlledRz), - MQT_NAMED_BUILDER(qir::singleControlledRz)}, + MQT_NAMED_BUILDER(qir::singleControlledRz<>)}, QCToQIRBaseTestCase{"MultipleControlledRZ", MQT_NAMED_BUILDER(qc::multipleControlledRz), - MQT_NAMED_BUILDER(qir::multipleControlledRz)})); + MQT_NAMED_BUILDER(qir::multipleControlledRz<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RzxOp.cpp @@ -335,13 +336,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRZXOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RZX", MQT_NAMED_BUILDER(qc::rzx), - MQT_NAMED_BUILDER(qir::rzx)}, + MQT_NAMED_BUILDER(qir::rzx<>)}, QCToQIRBaseTestCase{"SingleControlledRZX", MQT_NAMED_BUILDER(qc::singleControlledRzx), - MQT_NAMED_BUILDER(qir::singleControlledRzx)}, + MQT_NAMED_BUILDER(qir::singleControlledRzx<>)}, QCToQIRBaseTestCase{"MultipleControlledRZX", MQT_NAMED_BUILDER(qc::multipleControlledRzx), - MQT_NAMED_BUILDER(qir::multipleControlledRzx)})); + MQT_NAMED_BUILDER(qir::multipleControlledRzx<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/RzzOp.cpp @@ -350,13 +351,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseRZZOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"RZZ", MQT_NAMED_BUILDER(qc::rzz), - MQT_NAMED_BUILDER(qir::rzz)}, + MQT_NAMED_BUILDER(qir::rzz<>)}, QCToQIRBaseTestCase{"SingleControlledRZZ", MQT_NAMED_BUILDER(qc::singleControlledRzz), - MQT_NAMED_BUILDER(qir::singleControlledRzz)}, + MQT_NAMED_BUILDER(qir::singleControlledRzz<>)}, QCToQIRBaseTestCase{"MultipleControlledRZZ", MQT_NAMED_BUILDER(qc::multipleControlledRzz), - MQT_NAMED_BUILDER(qir::multipleControlledRzz)})); + MQT_NAMED_BUILDER(qir::multipleControlledRzz<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SOp.cpp @@ -365,13 +366,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"S", MQT_NAMED_BUILDER(qc::s), - MQT_NAMED_BUILDER(qir::s)}, + MQT_NAMED_BUILDER(qir::s<>)}, QCToQIRBaseTestCase{"SingleControlledS", MQT_NAMED_BUILDER(qc::singleControlledS), - MQT_NAMED_BUILDER(qir::singleControlledS)}, + MQT_NAMED_BUILDER(qir::singleControlledS<>)}, QCToQIRBaseTestCase{"MultipleControlledS", MQT_NAMED_BUILDER(qc::multipleControlledS), - MQT_NAMED_BUILDER(qir::multipleControlledS)})); + MQT_NAMED_BUILDER(qir::multipleControlledS<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SdgOp.cpp @@ -380,13 +381,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSdgOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Sdg", MQT_NAMED_BUILDER(qc::sdg), - MQT_NAMED_BUILDER(qir::sdg)}, + MQT_NAMED_BUILDER(qir::sdg<>)}, QCToQIRBaseTestCase{"SingleControlledSdg", MQT_NAMED_BUILDER(qc::singleControlledSdg), - MQT_NAMED_BUILDER(qir::singleControlledSdg)}, + MQT_NAMED_BUILDER(qir::singleControlledSdg<>)}, QCToQIRBaseTestCase{"MultipleControlledSdg", MQT_NAMED_BUILDER(qc::multipleControlledSdg), - MQT_NAMED_BUILDER(qir::multipleControlledSdg)})); + MQT_NAMED_BUILDER(qir::multipleControlledSdg<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SwapOp.cpp @@ -395,13 +396,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSWAPOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"SWAP", MQT_NAMED_BUILDER(qc::swap), - MQT_NAMED_BUILDER(qir::swap)}, + MQT_NAMED_BUILDER(qir::swap<>)}, QCToQIRBaseTestCase{"SingleControlledSWAP", MQT_NAMED_BUILDER(qc::singleControlledSwap), - MQT_NAMED_BUILDER(qir::singleControlledSwap)}, + MQT_NAMED_BUILDER(qir::singleControlledSwap<>)}, QCToQIRBaseTestCase{"MultipleControlledSWAP", MQT_NAMED_BUILDER(qc::multipleControlledSwap), - MQT_NAMED_BUILDER(qir::multipleControlledSwap)})); + MQT_NAMED_BUILDER(qir::multipleControlledSwap<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SxOp.cpp @@ -410,13 +411,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSXOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"SX", MQT_NAMED_BUILDER(qc::sx), - MQT_NAMED_BUILDER(qir::sx)}, + MQT_NAMED_BUILDER(qir::sx<>)}, QCToQIRBaseTestCase{"SingleControlledSX", MQT_NAMED_BUILDER(qc::singleControlledSx), - MQT_NAMED_BUILDER(qir::singleControlledSx)}, + MQT_NAMED_BUILDER(qir::singleControlledSx<>)}, QCToQIRBaseTestCase{"MultipleControlledSX", MQT_NAMED_BUILDER(qc::multipleControlledSx), - MQT_NAMED_BUILDER(qir::multipleControlledSx)})); + MQT_NAMED_BUILDER(qir::multipleControlledSx<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/SxdgOp.cpp @@ -425,13 +426,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseSXdgOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"SXdg", MQT_NAMED_BUILDER(qc::sxdg), - MQT_NAMED_BUILDER(qir::sxdg)}, + MQT_NAMED_BUILDER(qir::sxdg<>)}, QCToQIRBaseTestCase{"SingleControlledSXdg", MQT_NAMED_BUILDER(qc::singleControlledSxdg), - MQT_NAMED_BUILDER(qir::singleControlledSxdg)}, + MQT_NAMED_BUILDER(qir::singleControlledSxdg<>)}, QCToQIRBaseTestCase{"MultipleControlledSXdg", MQT_NAMED_BUILDER(qc::multipleControlledSxdg), - MQT_NAMED_BUILDER(qir::multipleControlledSxdg)})); + MQT_NAMED_BUILDER(qir::multipleControlledSxdg<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/TOp.cpp @@ -440,13 +441,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseTOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"T", MQT_NAMED_BUILDER(qc::t_), - MQT_NAMED_BUILDER(qir::t_)}, + MQT_NAMED_BUILDER(qir::t_<>)}, QCToQIRBaseTestCase{"SingleControlledT", MQT_NAMED_BUILDER(qc::singleControlledT), - MQT_NAMED_BUILDER(qir::singleControlledT)}, + MQT_NAMED_BUILDER(qir::singleControlledT<>)}, QCToQIRBaseTestCase{"MultipleControlledT", MQT_NAMED_BUILDER(qc::multipleControlledT), - MQT_NAMED_BUILDER(qir::multipleControlledT)})); + MQT_NAMED_BUILDER(qir::multipleControlledT<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/TdgOp.cpp @@ -455,13 +456,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseTdgOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Tdg", MQT_NAMED_BUILDER(qc::tdg), - MQT_NAMED_BUILDER(qir::tdg)}, + MQT_NAMED_BUILDER(qir::tdg<>)}, QCToQIRBaseTestCase{"SingleControlledTdg", MQT_NAMED_BUILDER(qc::singleControlledTdg), - MQT_NAMED_BUILDER(qir::singleControlledTdg)}, + MQT_NAMED_BUILDER(qir::singleControlledTdg<>)}, QCToQIRBaseTestCase{"MultipleControlledTdg", MQT_NAMED_BUILDER(qc::multipleControlledTdg), - MQT_NAMED_BUILDER(qir::multipleControlledTdg)})); + MQT_NAMED_BUILDER(qir::multipleControlledTdg<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/U2Op.cpp @@ -470,13 +471,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseU2OpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"U2", MQT_NAMED_BUILDER(qc::u2), - MQT_NAMED_BUILDER(qir::u2)}, + MQT_NAMED_BUILDER(qir::u2<>)}, QCToQIRBaseTestCase{"SingleControlledU2", MQT_NAMED_BUILDER(qc::singleControlledU2), - MQT_NAMED_BUILDER(qir::singleControlledU2)}, + MQT_NAMED_BUILDER(qir::singleControlledU2<>)}, QCToQIRBaseTestCase{"MultipleControlledU2", MQT_NAMED_BUILDER(qc::multipleControlledU2), - MQT_NAMED_BUILDER(qir::multipleControlledU2)})); + MQT_NAMED_BUILDER(qir::multipleControlledU2<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/UOp.cpp @@ -485,13 +486,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseUOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"U", MQT_NAMED_BUILDER(qc::u), - MQT_NAMED_BUILDER(qir::u)}, + MQT_NAMED_BUILDER(qir::u<>)}, QCToQIRBaseTestCase{"SingleControlledU", MQT_NAMED_BUILDER(qc::singleControlledU), - MQT_NAMED_BUILDER(qir::singleControlledU)}, + MQT_NAMED_BUILDER(qir::singleControlledU<>)}, QCToQIRBaseTestCase{"MultipleControlledU", MQT_NAMED_BUILDER(qc::multipleControlledU), - MQT_NAMED_BUILDER(qir::multipleControlledU)})); + MQT_NAMED_BUILDER(qir::multipleControlledU<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/XOp.cpp @@ -500,13 +501,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseXOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"X", MQT_NAMED_BUILDER(qc::x), - MQT_NAMED_BUILDER(qir::x)}, + MQT_NAMED_BUILDER(qir::x<>)}, QCToQIRBaseTestCase{"SingleControlledX", MQT_NAMED_BUILDER(qc::singleControlledX), - MQT_NAMED_BUILDER(qir::singleControlledX)}, + MQT_NAMED_BUILDER(qir::singleControlledX<>)}, QCToQIRBaseTestCase{"MultipleControlledX", MQT_NAMED_BUILDER(qc::multipleControlledX), - MQT_NAMED_BUILDER(qir::multipleControlledX)})); + MQT_NAMED_BUILDER(qir::multipleControlledX<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/XxMinusYyOp.cpp @@ -515,14 +516,15 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseXXMinusYYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"XXMinusYY", MQT_NAMED_BUILDER(qc::xxMinusYY), - MQT_NAMED_BUILDER(qir::xxMinusYY)}, - QCToQIRBaseTestCase{"SingleControlledXXMinusYY", - MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), - MQT_NAMED_BUILDER(qir::singleControlledXxMinusYY)}, + MQT_NAMED_BUILDER(qir::xxMinusYY<>)}, + QCToQIRBaseTestCase{ + "SingleControlledXXMinusYY", + MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), + MQT_NAMED_BUILDER(qir::singleControlledXxMinusYY<>)}, QCToQIRBaseTestCase{ "MultipleControlledXXMinusYY", MQT_NAMED_BUILDER(qc::multipleControlledXxMinusYY), - MQT_NAMED_BUILDER(qir::multipleControlledXxMinusYY)})); + MQT_NAMED_BUILDER(qir::multipleControlledXxMinusYY<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/XxPlusYyOp.cpp @@ -531,14 +533,14 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseXXPlusYYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"XXPlusYY", MQT_NAMED_BUILDER(qc::xxPlusYY), - MQT_NAMED_BUILDER(qir::xxPlusYY)}, + MQT_NAMED_BUILDER(qir::xxPlusYY<>)}, QCToQIRBaseTestCase{"SingleControlledXXPlusYY", MQT_NAMED_BUILDER(qc::singleControlledXxPlusYY), - MQT_NAMED_BUILDER(qir::singleControlledXxPlusYY)}, + MQT_NAMED_BUILDER(qir::singleControlledXxPlusYY<>)}, QCToQIRBaseTestCase{ "MultipleControlledXXPlusYY", MQT_NAMED_BUILDER(qc::multipleControlledXxPlusYY), - MQT_NAMED_BUILDER(qir::multipleControlledXxPlusYY)})); + MQT_NAMED_BUILDER(qir::multipleControlledXxPlusYY<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/YOp.cpp @@ -547,13 +549,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseYOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Y", MQT_NAMED_BUILDER(qc::y), - MQT_NAMED_BUILDER(qir::y)}, + MQT_NAMED_BUILDER(qir::y<>)}, QCToQIRBaseTestCase{"SingleControlledY", MQT_NAMED_BUILDER(qc::singleControlledY), - MQT_NAMED_BUILDER(qir::singleControlledY)}, + MQT_NAMED_BUILDER(qir::singleControlledY<>)}, QCToQIRBaseTestCase{"MultipleControlledY", MQT_NAMED_BUILDER(qc::multipleControlledY), - MQT_NAMED_BUILDER(qir::multipleControlledY)})); + MQT_NAMED_BUILDER(qir::multipleControlledY<>)})); /// @} /// \name QCToQIRBase/Operations/StandardGates/ZOp.cpp @@ -562,13 +564,13 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseZOpTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"Z", MQT_NAMED_BUILDER(qc::z), - MQT_NAMED_BUILDER(qir::z)}, + MQT_NAMED_BUILDER(qir::z<>)}, QCToQIRBaseTestCase{"SingleControlledZ", MQT_NAMED_BUILDER(qc::singleControlledZ), - MQT_NAMED_BUILDER(qir::singleControlledZ)}, + MQT_NAMED_BUILDER(qir::singleControlledZ<>)}, QCToQIRBaseTestCase{"MultipleControlledZ", MQT_NAMED_BUILDER(qc::multipleControlledZ), - MQT_NAMED_BUILDER(qir::multipleControlledZ)})); + MQT_NAMED_BUILDER(qir::multipleControlledZ<>)})); /// @} /// \name QCToQIRBase/Operations/MeasureOp.cpp @@ -579,15 +581,15 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseTestCase{ "SingleMeasurementToSingleBit", MQT_NAMED_BUILDER(qc::singleMeasurementToSingleBit), - MQT_NAMED_BUILDER(qir::singleMeasurementToSingleBit)}, + MQT_NAMED_BUILDER(qir::singleMeasurementToSingleBit<>)}, QCToQIRBaseTestCase{ "RepeatedMeasurementToSameBit", MQT_NAMED_BUILDER(qc::repeatedMeasurementToSameBit), - MQT_NAMED_BUILDER(qir::repeatedMeasurementToSameBit)}, + MQT_NAMED_BUILDER(qir::repeatedMeasurementToSameBit<>)}, QCToQIRBaseTestCase{ "RepeatedMeasurementToDifferentBits", MQT_NAMED_BUILDER(qc::repeatedMeasurementToDifferentBits), - MQT_NAMED_BUILDER(qir::repeatedMeasurementToDifferentBits)}, + MQT_NAMED_BUILDER(qir::repeatedMeasurementToDifferentBits<>)}, QCToQIRBaseTestCase{ "MultipleClassicalRegistersAndMeasurements", MQT_NAMED_BUILDER(qc::multipleClassicalRegistersAndMeasurements), @@ -596,7 +598,7 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseTestCase{ "MeasurementWithoutRegisters", MQT_NAMED_BUILDER(qc::measurementWithoutRegisters), - MQT_NAMED_BUILDER(qir::measurementWithoutRegisters)})); + MQT_NAMED_BUILDER(qir::measurementWithoutRegisters<>)})); /// @} /// \name QCToQIRBase/QubitManagement/QubitManagement.cpp @@ -605,21 +607,21 @@ INSTANTIATE_TEST_SUITE_P( QCToQIRBaseQubitManagementTest, QCToQIRBaseTest, testing::Values( QCToQIRBaseTestCase{"AllocQubit", MQT_NAMED_BUILDER(qc::allocQubit), - MQT_NAMED_BUILDER(qir::allocQubit)}, + MQT_NAMED_BUILDER(qir::allocQubit<>)}, QCToQIRBaseTestCase{"AllocQubitRegister", MQT_NAMED_BUILDER(qc::allocQubitRegister), - MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(qir::allocQubitRegister<>)}, QCToQIRBaseTestCase{ "AllocMultipleQubitRegisters", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegisters), - MQT_NAMED_BUILDER(qir::allocMultipleQubitRegisters)}, + MQT_NAMED_BUILDER(qir::allocMultipleQubitRegisters<>)}, QCToQIRBaseTestCase{ "AllocMultipleQubitRegistersWithOps", MQT_NAMED_BUILDER(qc::allocMultipleQubitRegistersWithOps), - MQT_NAMED_BUILDER(qir::allocMultipleQubitRegistersWithOps)}, + MQT_NAMED_BUILDER(qir::allocMultipleQubitRegistersWithOps<>)}, QCToQIRBaseTestCase{"AllocLargeRegister", MQT_NAMED_BUILDER(qc::allocLargeRegister), - MQT_NAMED_BUILDER(qir::allocQubitRegister)}, + MQT_NAMED_BUILDER(qir::allocQubitRegister<>)}, QCToQIRBaseTestCase{"StaticQubits", MQT_NAMED_BUILDER(qc::staticQubits), MQT_NAMED_BUILDER(qir::staticQubits)}, QCToQIRBaseTestCase{"StaticQubitsWithOps", @@ -641,5 +643,5 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(qir::staticQubitsWithInv)}, QCToQIRBaseTestCase{"AllocDeallocPair", MQT_NAMED_BUILDER(qc::allocDeallocPair), - MQT_NAMED_BUILDER(qir::emptyQIR)})); + MQT_NAMED_BUILDER(qir::emptyQIR<>)})); /// @} diff --git a/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp b/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp index 21ae937f0f..717064b19a 100644 --- a/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp +++ b/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp @@ -114,36 +114,36 @@ TEST_F(QIRTest, BuilderRejectsMixedStaticAndDynamicQubitAllocationModes) { /// @{ INSTANTIATE_TEST_SUITE_P( QIRDCXOpTest, QIRTest, - testing::Values(QIRTestCase{"DCX", MQT_NAMED_BUILDER(dcx), - MQT_NAMED_BUILDER(dcx)}, + testing::Values(QIRTestCase{"DCX", MQT_NAMED_BUILDER(dcx<>), + MQT_NAMED_BUILDER(dcx<>)}, QIRTestCase{"SingleControlledDCX", - MQT_NAMED_BUILDER(singleControlledDcx), - MQT_NAMED_BUILDER(singleControlledDcx)}, + MQT_NAMED_BUILDER(singleControlledDcx<>), + MQT_NAMED_BUILDER(singleControlledDcx<>)}, QIRTestCase{"MultipleControlledDCX", - MQT_NAMED_BUILDER(multipleControlledDcx), - MQT_NAMED_BUILDER(multipleControlledDcx)})); + MQT_NAMED_BUILDER(multipleControlledDcx<>), + MQT_NAMED_BUILDER(multipleControlledDcx<>)})); /// @} /// \name QIR/Operations/StandardGates/EcrOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRECROpTest, QIRTest, - testing::Values(QIRTestCase{"ECR", MQT_NAMED_BUILDER(ecr), - MQT_NAMED_BUILDER(ecr)}, + testing::Values(QIRTestCase{"ECR", MQT_NAMED_BUILDER(ecr<>), + MQT_NAMED_BUILDER(ecr<>)}, QIRTestCase{"SingleControlledECR", - MQT_NAMED_BUILDER(singleControlledEcr), - MQT_NAMED_BUILDER(singleControlledEcr)}, + MQT_NAMED_BUILDER(singleControlledEcr<>), + MQT_NAMED_BUILDER(singleControlledEcr<>)}, QIRTestCase{"MultipleControlledECR", - MQT_NAMED_BUILDER(multipleControlledEcr), - MQT_NAMED_BUILDER(multipleControlledEcr)})); + MQT_NAMED_BUILDER(multipleControlledEcr<>), + MQT_NAMED_BUILDER(multipleControlledEcr<>)})); /// @} /// \name QIR/Operations/StandardGates/GphaseOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P(QIRGPhaseOpTest, QIRTest, testing::Values(QIRTestCase{ - "GlobalPhase", MQT_NAMED_BUILDER(globalPhase), - MQT_NAMED_BUILDER(globalPhase)})); + "GlobalPhase", MQT_NAMED_BUILDER(globalPhase<>), + MQT_NAMED_BUILDER(globalPhase<>)})); /// @} /// \name QIR/Operations/StandardGates/HOp.cpp @@ -151,41 +151,41 @@ INSTANTIATE_TEST_SUITE_P(QIRGPhaseOpTest, QIRTest, INSTANTIATE_TEST_SUITE_P( QIRHOpTest, QIRTest, testing::Values( - QIRTestCase{"H", MQT_NAMED_BUILDER(h), MQT_NAMED_BUILDER(h)}, - QIRTestCase{"SingleControlledH", MQT_NAMED_BUILDER(singleControlledH), - MQT_NAMED_BUILDER(singleControlledH)}, + QIRTestCase{"H", MQT_NAMED_BUILDER(h<>), MQT_NAMED_BUILDER(h<>)}, + QIRTestCase{"SingleControlledH", MQT_NAMED_BUILDER(singleControlledH<>), + MQT_NAMED_BUILDER(singleControlledH<>)}, QIRTestCase{"MultipleControlledH", - MQT_NAMED_BUILDER(multipleControlledH), - MQT_NAMED_BUILDER(multipleControlledH)})); + MQT_NAMED_BUILDER(multipleControlledH<>), + MQT_NAMED_BUILDER(multipleControlledH<>)})); /// @} /// \name QIR/Operations/StandardGates/IdOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRIDOpTest, QIRTest, - testing::Values(QIRTestCase{"Identity", MQT_NAMED_BUILDER(identity), - MQT_NAMED_BUILDER(identity)}, + testing::Values(QIRTestCase{"Identity", MQT_NAMED_BUILDER(identity<>), + MQT_NAMED_BUILDER(identity<>)}, QIRTestCase{"SingleControlledIdentity", - MQT_NAMED_BUILDER(singleControlledIdentity), - MQT_NAMED_BUILDER(singleControlledIdentity)}, + MQT_NAMED_BUILDER(singleControlledIdentity<>), + MQT_NAMED_BUILDER(singleControlledIdentity<>)}, QIRTestCase{ "MultipleControlledIdentity", - MQT_NAMED_BUILDER(multipleControlledIdentity), - MQT_NAMED_BUILDER(multipleControlledIdentity)})); + MQT_NAMED_BUILDER(multipleControlledIdentity<>), + MQT_NAMED_BUILDER(multipleControlledIdentity<>)})); /// @} /// \name QIR/Operations/StandardGates/IswapOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRiSWAPOpTest, QIRTest, - testing::Values(QIRTestCase{"iSWAP", MQT_NAMED_BUILDER(iswap), - MQT_NAMED_BUILDER(iswap)}, + testing::Values(QIRTestCase{"iSWAP", MQT_NAMED_BUILDER(iswap<>), + MQT_NAMED_BUILDER(iswap<>)}, QIRTestCase{"SingleControllediSWAP", - MQT_NAMED_BUILDER(singleControlledIswap), - MQT_NAMED_BUILDER(singleControlledIswap)}, + MQT_NAMED_BUILDER(singleControlledIswap<>), + MQT_NAMED_BUILDER(singleControlledIswap<>)}, QIRTestCase{"MultipleControllediSWAP", - MQT_NAMED_BUILDER(multipleControlledIswap), - MQT_NAMED_BUILDER(multipleControlledIswap)})); + MQT_NAMED_BUILDER(multipleControlledIswap<>), + MQT_NAMED_BUILDER(multipleControlledIswap<>)})); /// @} /// \name QIR/Operations/StandardGates/POp.cpp @@ -193,12 +193,12 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QIRPOpTest, QIRTest, testing::Values( - QIRTestCase{"P", MQT_NAMED_BUILDER(p), MQT_NAMED_BUILDER(p)}, - QIRTestCase{"SingleControlledP", MQT_NAMED_BUILDER(singleControlledP), - MQT_NAMED_BUILDER(singleControlledP)}, + QIRTestCase{"P", MQT_NAMED_BUILDER(p<>), MQT_NAMED_BUILDER(p<>)}, + QIRTestCase{"SingleControlledP", MQT_NAMED_BUILDER(singleControlledP<>), + MQT_NAMED_BUILDER(singleControlledP<>)}, QIRTestCase{"MultipleControlledP", - MQT_NAMED_BUILDER(multipleControlledP), - MQT_NAMED_BUILDER(multipleControlledP)})); + MQT_NAMED_BUILDER(multipleControlledP<>), + MQT_NAMED_BUILDER(multipleControlledP<>)})); /// @} /// \name QIR/Operations/StandardGates/ROp.cpp @@ -206,107 +206,110 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QIRROpTest, QIRTest, testing::Values( - QIRTestCase{"R", MQT_NAMED_BUILDER(r), MQT_NAMED_BUILDER(r)}, - QIRTestCase{"SingleControlledR", MQT_NAMED_BUILDER(singleControlledR), - MQT_NAMED_BUILDER(singleControlledR)}, + QIRTestCase{"R", MQT_NAMED_BUILDER(r<>), MQT_NAMED_BUILDER(r<>)}, + QIRTestCase{"SingleControlledR", MQT_NAMED_BUILDER(singleControlledR<>), + MQT_NAMED_BUILDER(singleControlledR<>)}, QIRTestCase{"MultipleControlledR", - MQT_NAMED_BUILDER(multipleControlledR), - MQT_NAMED_BUILDER(multipleControlledR)})); + MQT_NAMED_BUILDER(multipleControlledR<>), + MQT_NAMED_BUILDER(multipleControlledR<>)})); /// @} /// \name QIR/Operations/StandardGates/RxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRRXOpTest, QIRTest, - testing::Values( - QIRTestCase{"RX", MQT_NAMED_BUILDER(rx), MQT_NAMED_BUILDER(rx)}, - QIRTestCase{"SingleControlledRX", MQT_NAMED_BUILDER(singleControlledRx), - MQT_NAMED_BUILDER(singleControlledRx)}, - QIRTestCase{"MultipleControlledRX", - MQT_NAMED_BUILDER(multipleControlledRx), - MQT_NAMED_BUILDER(multipleControlledRx)})); + testing::Values(QIRTestCase{"RX", MQT_NAMED_BUILDER(rx<>), + MQT_NAMED_BUILDER(rx<>)}, + QIRTestCase{"SingleControlledRX", + MQT_NAMED_BUILDER(singleControlledRx<>), + MQT_NAMED_BUILDER(singleControlledRx<>)}, + QIRTestCase{"MultipleControlledRX", + MQT_NAMED_BUILDER(multipleControlledRx<>), + MQT_NAMED_BUILDER(multipleControlledRx<>)})); /// @} /// \name QIR/Operations/StandardGates/RxxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRRXXOpTest, QIRTest, - testing::Values(QIRTestCase{"RXX", MQT_NAMED_BUILDER(rxx), - MQT_NAMED_BUILDER(rxx)}, + testing::Values(QIRTestCase{"RXX", MQT_NAMED_BUILDER(rxx<>), + MQT_NAMED_BUILDER(rxx<>)}, QIRTestCase{"SingleControlledRXX", - MQT_NAMED_BUILDER(singleControlledRxx), - MQT_NAMED_BUILDER(singleControlledRxx)}, + MQT_NAMED_BUILDER(singleControlledRxx<>), + MQT_NAMED_BUILDER(singleControlledRxx<>)}, QIRTestCase{"MultipleControlledRXX", - MQT_NAMED_BUILDER(multipleControlledRxx), - MQT_NAMED_BUILDER(multipleControlledRxx)})); + MQT_NAMED_BUILDER(multipleControlledRxx<>), + MQT_NAMED_BUILDER(multipleControlledRxx<>)})); /// @} /// \name QIR/Operations/StandardGates/RyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRRYOpTest, QIRTest, - testing::Values( - QIRTestCase{"RY", MQT_NAMED_BUILDER(ry), MQT_NAMED_BUILDER(ry)}, - QIRTestCase{"SingleControlledRY", MQT_NAMED_BUILDER(singleControlledRy), - MQT_NAMED_BUILDER(singleControlledRy)}, - QIRTestCase{"MultipleControlledRY", - MQT_NAMED_BUILDER(multipleControlledRy), - MQT_NAMED_BUILDER(multipleControlledRy)})); + testing::Values(QIRTestCase{"RY", MQT_NAMED_BUILDER(ry<>), + MQT_NAMED_BUILDER(ry<>)}, + QIRTestCase{"SingleControlledRY", + MQT_NAMED_BUILDER(singleControlledRy<>), + MQT_NAMED_BUILDER(singleControlledRy<>)}, + QIRTestCase{"MultipleControlledRY", + MQT_NAMED_BUILDER(multipleControlledRy<>), + MQT_NAMED_BUILDER(multipleControlledRy<>)})); /// @} /// \name QIR/Operations/StandardGates/RyyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRRYYOpTest, QIRTest, - testing::Values(QIRTestCase{"RYY", MQT_NAMED_BUILDER(ryy), - MQT_NAMED_BUILDER(ryy)}, + testing::Values(QIRTestCase{"RYY", MQT_NAMED_BUILDER(ryy<>), + MQT_NAMED_BUILDER(ryy<>)}, QIRTestCase{"SingleControlledRYY", - MQT_NAMED_BUILDER(singleControlledRyy), - MQT_NAMED_BUILDER(singleControlledRyy)}, + MQT_NAMED_BUILDER(singleControlledRyy<>), + MQT_NAMED_BUILDER(singleControlledRyy<>)}, QIRTestCase{"MultipleControlledRYY", - MQT_NAMED_BUILDER(multipleControlledRyy), - MQT_NAMED_BUILDER(multipleControlledRyy)})); + MQT_NAMED_BUILDER(multipleControlledRyy<>), + MQT_NAMED_BUILDER(multipleControlledRyy<>)})); /// @} /// \name QIR/Operations/StandardGates/RzOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRRZOpTest, QIRTest, - testing::Values( - QIRTestCase{"RZ", MQT_NAMED_BUILDER(rz), MQT_NAMED_BUILDER(rz)}, - QIRTestCase{"SingleControlledRZ", MQT_NAMED_BUILDER(singleControlledRz), - MQT_NAMED_BUILDER(singleControlledRz)}, - QIRTestCase{"MultipleControlledRZ", - MQT_NAMED_BUILDER(multipleControlledRz), - MQT_NAMED_BUILDER(multipleControlledRz)})); + testing::Values(QIRTestCase{"RZ", MQT_NAMED_BUILDER(rz<>), + MQT_NAMED_BUILDER(rz<>)}, + QIRTestCase{"SingleControlledRZ", + MQT_NAMED_BUILDER(singleControlledRz<>), + MQT_NAMED_BUILDER(singleControlledRz<>)}, + QIRTestCase{"MultipleControlledRZ", + MQT_NAMED_BUILDER(multipleControlledRz<>), + MQT_NAMED_BUILDER(multipleControlledRz<>)})); /// @} /// \name QIR/Operations/StandardGates/RzxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRRZXOpTest, QIRTest, - testing::Values(QIRTestCase{"RZX", MQT_NAMED_BUILDER(rzx), - MQT_NAMED_BUILDER(rzx)}, + testing::Values(QIRTestCase{"RZX", MQT_NAMED_BUILDER(rzx<>), + MQT_NAMED_BUILDER(rzx<>)}, QIRTestCase{"SingleControlledRZX", - MQT_NAMED_BUILDER(singleControlledRzx), - MQT_NAMED_BUILDER(singleControlledRzx)}, + MQT_NAMED_BUILDER(singleControlledRzx<>), + MQT_NAMED_BUILDER(singleControlledRzx<>)}, QIRTestCase{"MultipleControlledRZX", - MQT_NAMED_BUILDER(multipleControlledRzx), - MQT_NAMED_BUILDER(multipleControlledRzx)})); + MQT_NAMED_BUILDER(multipleControlledRzx<>), + MQT_NAMED_BUILDER(multipleControlledRzx<>)})); /// @} /// \name QIR/Operations/StandardGates/RzzOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRRZZOpTest, QIRTest, - testing::Values(QIRTestCase{"RZZ", MQT_NAMED_BUILDER(rzz), - MQT_NAMED_BUILDER(rzz)}, + testing::Values(QIRTestCase{"RZZ", MQT_NAMED_BUILDER(rzz<>), + MQT_NAMED_BUILDER(rzz<>)}, QIRTestCase{"SingleControlledRZZ", - MQT_NAMED_BUILDER(singleControlledRzz), - MQT_NAMED_BUILDER(singleControlledRzz)}, + MQT_NAMED_BUILDER(singleControlledRzz<>), + MQT_NAMED_BUILDER(singleControlledRzz<>)}, QIRTestCase{"MultipleControlledRZZ", - MQT_NAMED_BUILDER(multipleControlledRzz), - MQT_NAMED_BUILDER(multipleControlledRzz)})); + MQT_NAMED_BUILDER(multipleControlledRzz<>), + MQT_NAMED_BUILDER(multipleControlledRzz<>)})); /// @} /// \name QIR/Operations/StandardGates/SOp.cpp @@ -314,67 +317,68 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QIRSOpTest, QIRTest, testing::Values( - QIRTestCase{"S", MQT_NAMED_BUILDER(s), MQT_NAMED_BUILDER(s)}, - QIRTestCase{"SingleControlledS", MQT_NAMED_BUILDER(singleControlledS), - MQT_NAMED_BUILDER(singleControlledS)}, + QIRTestCase{"S", MQT_NAMED_BUILDER(s<>), MQT_NAMED_BUILDER(s<>)}, + QIRTestCase{"SingleControlledS", MQT_NAMED_BUILDER(singleControlledS<>), + MQT_NAMED_BUILDER(singleControlledS<>)}, QIRTestCase{"MultipleControlledS", - MQT_NAMED_BUILDER(multipleControlledS), - MQT_NAMED_BUILDER(multipleControlledS)})); + MQT_NAMED_BUILDER(multipleControlledS<>), + MQT_NAMED_BUILDER(multipleControlledS<>)})); /// @} /// \name QIR/Operations/StandardGates/SdgOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRSdgOpTest, QIRTest, - testing::Values(QIRTestCase{"Sdg", MQT_NAMED_BUILDER(sdg), - MQT_NAMED_BUILDER(sdg)}, + testing::Values(QIRTestCase{"Sdg", MQT_NAMED_BUILDER(sdg<>), + MQT_NAMED_BUILDER(sdg<>)}, QIRTestCase{"SingleControlledSdg", - MQT_NAMED_BUILDER(singleControlledSdg), - MQT_NAMED_BUILDER(singleControlledSdg)}, + MQT_NAMED_BUILDER(singleControlledSdg<>), + MQT_NAMED_BUILDER(singleControlledSdg<>)}, QIRTestCase{"MultipleControlledSdg", - MQT_NAMED_BUILDER(multipleControlledSdg), - MQT_NAMED_BUILDER(multipleControlledSdg)})); + MQT_NAMED_BUILDER(multipleControlledSdg<>), + MQT_NAMED_BUILDER(multipleControlledSdg<>)})); /// @} /// \name QIR/Operations/StandardGates/SwapOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRSWAPOpTest, QIRTest, - testing::Values(QIRTestCase{"SWAP", MQT_NAMED_BUILDER(swap), - MQT_NAMED_BUILDER(swap)}, + testing::Values(QIRTestCase{"SWAP", MQT_NAMED_BUILDER(swap<>), + MQT_NAMED_BUILDER(swap<>)}, QIRTestCase{"SingleControlledSWAP", - MQT_NAMED_BUILDER(singleControlledSwap), - MQT_NAMED_BUILDER(singleControlledSwap)}, + MQT_NAMED_BUILDER(singleControlledSwap<>), + MQT_NAMED_BUILDER(singleControlledSwap<>)}, QIRTestCase{"MultipleControlledSWAP", - MQT_NAMED_BUILDER(multipleControlledSwap), - MQT_NAMED_BUILDER(multipleControlledSwap)})); + MQT_NAMED_BUILDER(multipleControlledSwap<>), + MQT_NAMED_BUILDER(multipleControlledSwap<>)})); /// @} /// \name QIR/Operations/StandardGates/SxOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRSXOpTest, QIRTest, - testing::Values( - QIRTestCase{"SX", MQT_NAMED_BUILDER(sx), MQT_NAMED_BUILDER(sx)}, - QIRTestCase{"SingleControlledSX", MQT_NAMED_BUILDER(singleControlledSx), - MQT_NAMED_BUILDER(singleControlledSx)}, - QIRTestCase{"MultipleControlledSX", - MQT_NAMED_BUILDER(multipleControlledSx), - MQT_NAMED_BUILDER(multipleControlledSx)})); + testing::Values(QIRTestCase{"SX", MQT_NAMED_BUILDER(sx<>), + MQT_NAMED_BUILDER(sx<>)}, + QIRTestCase{"SingleControlledSX", + MQT_NAMED_BUILDER(singleControlledSx<>), + MQT_NAMED_BUILDER(singleControlledSx<>)}, + QIRTestCase{"MultipleControlledSX", + MQT_NAMED_BUILDER(multipleControlledSx<>), + MQT_NAMED_BUILDER(multipleControlledSx<>)})); /// @} /// \name QIR/Operations/StandardGates/SxdgOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRSXdgOpTest, QIRTest, - testing::Values(QIRTestCase{"SXdg", MQT_NAMED_BUILDER(sxdg), - MQT_NAMED_BUILDER(sxdg)}, + testing::Values(QIRTestCase{"SXdg", MQT_NAMED_BUILDER(sxdg<>), + MQT_NAMED_BUILDER(sxdg<>)}, QIRTestCase{"SingleControlledSXdg", - MQT_NAMED_BUILDER(singleControlledSxdg), - MQT_NAMED_BUILDER(singleControlledSxdg)}, + MQT_NAMED_BUILDER(singleControlledSxdg<>), + MQT_NAMED_BUILDER(singleControlledSxdg<>)}, QIRTestCase{"MultipleControlledSXdg", - MQT_NAMED_BUILDER(multipleControlledSxdg), - MQT_NAMED_BUILDER(multipleControlledSxdg)})); + MQT_NAMED_BUILDER(multipleControlledSxdg<>), + MQT_NAMED_BUILDER(multipleControlledSxdg<>)})); /// @} /// \name QIR/Operations/StandardGates/TOp.cpp @@ -382,39 +386,40 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QIRTOpTest, QIRTest, testing::Values( - QIRTestCase{"T", MQT_NAMED_BUILDER(t_), MQT_NAMED_BUILDER(t_)}, - QIRTestCase{"SingleControlledT", MQT_NAMED_BUILDER(singleControlledT), - MQT_NAMED_BUILDER(singleControlledT)}, + QIRTestCase{"T", MQT_NAMED_BUILDER(t_<>), MQT_NAMED_BUILDER(t_<>)}, + QIRTestCase{"SingleControlledT", MQT_NAMED_BUILDER(singleControlledT<>), + MQT_NAMED_BUILDER(singleControlledT<>)}, QIRTestCase{"MultipleControlledT", - MQT_NAMED_BUILDER(multipleControlledT), - MQT_NAMED_BUILDER(multipleControlledT)})); + MQT_NAMED_BUILDER(multipleControlledT<>), + MQT_NAMED_BUILDER(multipleControlledT<>)})); /// @} /// \name QIR/Operations/StandardGates/TdgOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRTdgOpTest, QIRTest, - testing::Values(QIRTestCase{"Tdg", MQT_NAMED_BUILDER(tdg), - MQT_NAMED_BUILDER(tdg)}, + testing::Values(QIRTestCase{"Tdg", MQT_NAMED_BUILDER(tdg<>), + MQT_NAMED_BUILDER(tdg<>)}, QIRTestCase{"SingleControlledTdg", - MQT_NAMED_BUILDER(singleControlledTdg), - MQT_NAMED_BUILDER(singleControlledTdg)}, + MQT_NAMED_BUILDER(singleControlledTdg<>), + MQT_NAMED_BUILDER(singleControlledTdg<>)}, QIRTestCase{"MultipleControlledTdg", - MQT_NAMED_BUILDER(multipleControlledTdg), - MQT_NAMED_BUILDER(multipleControlledTdg)})); + MQT_NAMED_BUILDER(multipleControlledTdg<>), + MQT_NAMED_BUILDER(multipleControlledTdg<>)})); /// @} /// \name QIR/Operations/StandardGates/U2Op.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRU2OpTest, QIRTest, - testing::Values( - QIRTestCase{"U2", MQT_NAMED_BUILDER(u2), MQT_NAMED_BUILDER(u2)}, - QIRTestCase{"SingleControlledU2", MQT_NAMED_BUILDER(singleControlledU2), - MQT_NAMED_BUILDER(singleControlledU2)}, - QIRTestCase{"MultipleControlledU2", - MQT_NAMED_BUILDER(multipleControlledU2), - MQT_NAMED_BUILDER(multipleControlledU2)})); + testing::Values(QIRTestCase{"U2", MQT_NAMED_BUILDER(u2<>), + MQT_NAMED_BUILDER(u2<>)}, + QIRTestCase{"SingleControlledU2", + MQT_NAMED_BUILDER(singleControlledU2<>), + MQT_NAMED_BUILDER(singleControlledU2<>)}, + QIRTestCase{"MultipleControlledU2", + MQT_NAMED_BUILDER(multipleControlledU2<>), + MQT_NAMED_BUILDER(multipleControlledU2<>)})); /// @} /// \name QIR/Operations/StandardGates/UOp.cpp @@ -422,12 +427,12 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QIRUOpTest, QIRTest, testing::Values( - QIRTestCase{"U", MQT_NAMED_BUILDER(u), MQT_NAMED_BUILDER(u)}, - QIRTestCase{"SingleControlledU", MQT_NAMED_BUILDER(singleControlledU), - MQT_NAMED_BUILDER(singleControlledU)}, + QIRTestCase{"U", MQT_NAMED_BUILDER(u<>), MQT_NAMED_BUILDER(u<>)}, + QIRTestCase{"SingleControlledU", MQT_NAMED_BUILDER(singleControlledU<>), + MQT_NAMED_BUILDER(singleControlledU<>)}, QIRTestCase{"MultipleControlledU", - MQT_NAMED_BUILDER(multipleControlledU), - MQT_NAMED_BUILDER(multipleControlledU)})); + MQT_NAMED_BUILDER(multipleControlledU<>), + MQT_NAMED_BUILDER(multipleControlledU<>)})); /// @} /// \name QIR/Operations/StandardGates/XOp.cpp @@ -435,42 +440,42 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QIRXOpTest, QIRTest, testing::Values( - QIRTestCase{"X", MQT_NAMED_BUILDER(x), MQT_NAMED_BUILDER(x)}, - QIRTestCase{"SingleControlledX", MQT_NAMED_BUILDER(singleControlledX), - MQT_NAMED_BUILDER(singleControlledX)}, + QIRTestCase{"X", MQT_NAMED_BUILDER(x<>), MQT_NAMED_BUILDER(x<>)}, + QIRTestCase{"SingleControlledX", MQT_NAMED_BUILDER(singleControlledX<>), + MQT_NAMED_BUILDER(singleControlledX<>)}, QIRTestCase{"MultipleControlledX", - MQT_NAMED_BUILDER(multipleControlledX), - MQT_NAMED_BUILDER(multipleControlledX)})); + MQT_NAMED_BUILDER(multipleControlledX<>), + MQT_NAMED_BUILDER(multipleControlledX<>)})); /// @} /// \name QIR/Operations/StandardGates/XxMinusYyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRXXMinusYYOpTest, QIRTest, - testing::Values(QIRTestCase{"XXMinusYY", MQT_NAMED_BUILDER(xxMinusYY), - MQT_NAMED_BUILDER(xxMinusYY)}, + testing::Values(QIRTestCase{"XXMinusYY", MQT_NAMED_BUILDER(xxMinusYY<>), + MQT_NAMED_BUILDER(xxMinusYY<>)}, QIRTestCase{"SingleControlledXXMinusYY", - MQT_NAMED_BUILDER(singleControlledXxMinusYY), - MQT_NAMED_BUILDER(singleControlledXxMinusYY)}, + MQT_NAMED_BUILDER(singleControlledXxMinusYY<>), + MQT_NAMED_BUILDER(singleControlledXxMinusYY<>)}, QIRTestCase{ "MultipleControlledXXMinusYY", - MQT_NAMED_BUILDER(multipleControlledXxMinusYY), - MQT_NAMED_BUILDER(multipleControlledXxMinusYY)})); + MQT_NAMED_BUILDER(multipleControlledXxMinusYY<>), + MQT_NAMED_BUILDER(multipleControlledXxMinusYY<>)})); /// @} /// \name QIR/Operations/StandardGates/XxPlusYyOp.cpp /// @{ INSTANTIATE_TEST_SUITE_P( QIRXXPlusYYOpTest, QIRTest, - testing::Values(QIRTestCase{"XXPlusYY", MQT_NAMED_BUILDER(xxPlusYY), - MQT_NAMED_BUILDER(xxPlusYY)}, + testing::Values(QIRTestCase{"XXPlusYY", MQT_NAMED_BUILDER(xxPlusYY<>), + MQT_NAMED_BUILDER(xxPlusYY<>)}, QIRTestCase{"SingleControlledXXPlusYY", - MQT_NAMED_BUILDER(singleControlledXxPlusYY), - MQT_NAMED_BUILDER(singleControlledXxPlusYY)}, + MQT_NAMED_BUILDER(singleControlledXxPlusYY<>), + MQT_NAMED_BUILDER(singleControlledXxPlusYY<>)}, QIRTestCase{ "MultipleControlledXXPlusYY", - MQT_NAMED_BUILDER(multipleControlledXxPlusYY), - MQT_NAMED_BUILDER(multipleControlledXxPlusYY)})); + MQT_NAMED_BUILDER(multipleControlledXxPlusYY<>), + MQT_NAMED_BUILDER(multipleControlledXxPlusYY<>)})); /// @} /// \name QIR/Operations/StandardGates/YOp.cpp @@ -478,12 +483,12 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QIRYOpTest, QIRTest, testing::Values( - QIRTestCase{"Y", MQT_NAMED_BUILDER(y), MQT_NAMED_BUILDER(y)}, - QIRTestCase{"SingleControlledY", MQT_NAMED_BUILDER(singleControlledY), - MQT_NAMED_BUILDER(singleControlledY)}, + QIRTestCase{"Y", MQT_NAMED_BUILDER(y<>), MQT_NAMED_BUILDER(y<>)}, + QIRTestCase{"SingleControlledY", MQT_NAMED_BUILDER(singleControlledY<>), + MQT_NAMED_BUILDER(singleControlledY<>)}, QIRTestCase{"MultipleControlledY", - MQT_NAMED_BUILDER(multipleControlledY), - MQT_NAMED_BUILDER(multipleControlledY)})); + MQT_NAMED_BUILDER(multipleControlledY<>), + MQT_NAMED_BUILDER(multipleControlledY<>)})); /// @} /// \name QIR/Operations/StandardGates/ZOp.cpp @@ -491,12 +496,12 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QIRZOpTest, QIRTest, testing::Values( - QIRTestCase{"Z", MQT_NAMED_BUILDER(z), MQT_NAMED_BUILDER(z)}, - QIRTestCase{"SingleControlledZ", MQT_NAMED_BUILDER(singleControlledZ), - MQT_NAMED_BUILDER(singleControlledZ)}, + QIRTestCase{"Z", MQT_NAMED_BUILDER(z<>), MQT_NAMED_BUILDER(z<>)}, + QIRTestCase{"SingleControlledZ", MQT_NAMED_BUILDER(singleControlledZ<>), + MQT_NAMED_BUILDER(singleControlledZ<>)}, QIRTestCase{"MultipleControlledZ", - MQT_NAMED_BUILDER(multipleControlledZ), - MQT_NAMED_BUILDER(multipleControlledZ)})); + MQT_NAMED_BUILDER(multipleControlledZ<>), + MQT_NAMED_BUILDER(multipleControlledZ<>)})); /// @} /// \name QIR/Operations/MeasureOp.cpp @@ -505,14 +510,14 @@ INSTANTIATE_TEST_SUITE_P( QIRMeasureOpTest, QIRTest, testing::Values( QIRTestCase{"SingleMeasurementToSingleBit", - MQT_NAMED_BUILDER(singleMeasurementToSingleBit), - MQT_NAMED_BUILDER(singleMeasurementToSingleBit)}, + MQT_NAMED_BUILDER(singleMeasurementToSingleBit<>), + MQT_NAMED_BUILDER(singleMeasurementToSingleBit<>)}, QIRTestCase{"RepeatedMeasurementToSameBit", - MQT_NAMED_BUILDER(repeatedMeasurementToSameBit), - MQT_NAMED_BUILDER(repeatedMeasurementToSameBit)}, + MQT_NAMED_BUILDER(repeatedMeasurementToSameBit<>), + MQT_NAMED_BUILDER(repeatedMeasurementToSameBit<>)}, QIRTestCase{"RepeatedMeasurementToDifferentBits", - MQT_NAMED_BUILDER(repeatedMeasurementToDifferentBits), - MQT_NAMED_BUILDER(repeatedMeasurementToDifferentBits)})); + MQT_NAMED_BUILDER(repeatedMeasurementToDifferentBits<>), + MQT_NAMED_BUILDER(repeatedMeasurementToDifferentBits<>)})); /// @} /// \name QIR/Operations/ResetOp.cpp @@ -521,23 +526,23 @@ INSTANTIATE_TEST_SUITE_P( QIRResetOpTest, QIRTest, testing::Values( QIRTestCase{"ResetQubitWithoutOp", - MQT_NAMED_BUILDER(resetQubitWithoutOp), - MQT_NAMED_BUILDER(resetQubitWithoutOp)}, + MQT_NAMED_BUILDER(resetQubitWithoutOp<>), + MQT_NAMED_BUILDER(resetQubitWithoutOp<>)}, QIRTestCase{"ResetMultipleQubitsWithoutOp", - MQT_NAMED_BUILDER(resetMultipleQubitsWithoutOp), - MQT_NAMED_BUILDER(resetMultipleQubitsWithoutOp)}, + MQT_NAMED_BUILDER(resetMultipleQubitsWithoutOp<>), + MQT_NAMED_BUILDER(resetMultipleQubitsWithoutOp<>)}, QIRTestCase{"RepeatedResetWithoutOp", - MQT_NAMED_BUILDER(repeatedResetWithoutOp), - MQT_NAMED_BUILDER(repeatedResetWithoutOp)}, + MQT_NAMED_BUILDER(repeatedResetWithoutOp<>), + MQT_NAMED_BUILDER(repeatedResetWithoutOp<>)}, QIRTestCase{"ResetQubitAfterSingleOp", - MQT_NAMED_BUILDER(resetQubitAfterSingleOp), - MQT_NAMED_BUILDER(resetQubitAfterSingleOp)}, + MQT_NAMED_BUILDER(resetQubitAfterSingleOp<>), + MQT_NAMED_BUILDER(resetQubitAfterSingleOp<>)}, QIRTestCase{"ResetMultipleQubitsAfterSingleOp", - MQT_NAMED_BUILDER(resetMultipleQubitsAfterSingleOp), - MQT_NAMED_BUILDER(resetMultipleQubitsAfterSingleOp)}, + MQT_NAMED_BUILDER(resetMultipleQubitsAfterSingleOp<>), + MQT_NAMED_BUILDER(resetMultipleQubitsAfterSingleOp<>)}, QIRTestCase{"RepeatedResetAfterSingleOp", - MQT_NAMED_BUILDER(repeatedResetAfterSingleOp), - MQT_NAMED_BUILDER(repeatedResetAfterSingleOp)})); + MQT_NAMED_BUILDER(repeatedResetAfterSingleOp<>), + MQT_NAMED_BUILDER(repeatedResetAfterSingleOp<>)})); /// @} /// \name QIR/QubitManagement/QubitManagement.cpp @@ -545,15 +550,17 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QIRQubitManagementTest, QIRTest, testing::Values( - QIRTestCase{"AllocQubit", MQT_NAMED_BUILDER(allocQubit), - MQT_NAMED_BUILDER(allocQubit)}, - QIRTestCase{"AllocQubitRegister", MQT_NAMED_BUILDER(allocQubitRegister), - MQT_NAMED_BUILDER(allocQubitRegister)}, + QIRTestCase{"AllocQubit", MQT_NAMED_BUILDER(allocQubit<>), + MQT_NAMED_BUILDER(allocQubit<>)}, + QIRTestCase{"AllocQubitRegister", + MQT_NAMED_BUILDER(allocQubitRegister<>), + MQT_NAMED_BUILDER(allocQubitRegister<>)}, QIRTestCase{"AllocMultipleQubitRegisters", - MQT_NAMED_BUILDER(allocMultipleQubitRegisters), - MQT_NAMED_BUILDER(allocMultipleQubitRegisters)}, - QIRTestCase{"AllocLargeRegister", MQT_NAMED_BUILDER(allocLargeRegister), - MQT_NAMED_BUILDER(allocLargeRegister)}, + MQT_NAMED_BUILDER(allocMultipleQubitRegisters<>), + MQT_NAMED_BUILDER(allocMultipleQubitRegisters<>)}, + QIRTestCase{"AllocLargeRegister", + MQT_NAMED_BUILDER(allocLargeRegister<>), + MQT_NAMED_BUILDER(allocLargeRegister<>)}, QIRTestCase{"StaticQubits", MQT_NAMED_BUILDER(staticQubits), MQT_NAMED_BUILDER(staticQubits)}, QIRTestCase{"StaticQubitsWithOps", From 67d21dd36c9b408ac60e4c4d5dea4ec7139ffe7a Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 7 Jul 2026 18:37:01 +0200 Subject: [PATCH 50/80] ci: :green_heart: add `--np-editable` to nox stubs session because it causes an error otherwise --- noxfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/noxfile.py b/noxfile.py index a80ca6ba80..7c2269fee9 100755 --- a/noxfile.py +++ b/noxfile.py @@ -218,6 +218,7 @@ def stubs(session: nox.Session) -> None: session.run( "uv", "sync", + "--no-editable", "--no-dev", "--group", "build", From 6dbd019fdba3c58d0165d7c29e59a20743d10540 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Tue, 7 Jul 2026 18:43:54 +0200 Subject: [PATCH 51/80] chore(mlir): :rotating_light: potential fix to most linter issues --- .../TranslateQuantumComputationToQC.cpp | 1 + .../Dialect/QCO/IR/Operations/MeasureOp.cpp | 2 -- .../lib/Dialect/QCO/IR/Operations/ResetOp.cpp | 1 - mlir/lib/Dialect/QCO/IR/QCOOps.cpp | 4 --- .../Dialect/QCO/IR/QubitManagement/SinkOp.cpp | 4 +++ mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp | 3 ++- .../Compiler/test_compiler_pipeline.cpp | 4 +++ .../JeffRoundTrip/test_jeff_round_trip.cpp | 4 +++ .../Conversion/QCOToQC/test_qco_to_qc.cpp | 4 +++ .../Conversion/QCToQCO/test_qc_to_qco.cpp | 4 +++ .../test_qc_to_qir_adaptive.cpp | 4 +++ .../QCToQIRBase/test_qc_to_qir_base.cpp | 4 +++ mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp | 4 +++ .../QC/Translation/test_qasm3_translation.cpp | 4 +++ .../test_quantum_computation_translation.cpp | 4 +++ mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 3 +++ .../Dialect/QCO/IR/test_qco_ir_matrix.cpp | 3 +++ .../test_euler_decomposition.cpp | 4 +-- mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp | 4 +++ .../Dialect/QTensor/IR/test_qtensor_ir.cpp | 4 +++ mlir/unittests/programs/qc_programs.cpp | 6 ++--- mlir/unittests/programs/qc_programs.h | 1 + mlir/unittests/programs/qco_programs.cpp | 25 +++++++++++-------- 23 files changed, 77 insertions(+), 24 deletions(-) diff --git a/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp b/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp index 1087d15fd6..f9d0f21371 100644 --- a/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp +++ b/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include diff --git a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp index 3353235e99..9048910f2c 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp @@ -9,10 +9,8 @@ */ #include "mlir/Dialect/QCO/IR/QCOOps.h" -#include "mlir/Dialect/QCO/QCOUtils.h" #include -#include #include using namespace mlir; diff --git a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp index 856f7c8a3b..8832162354 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/ResetOp.cpp @@ -9,7 +9,6 @@ */ #include "mlir/Dialect/QCO/IR/QCOOps.h" -#include "mlir/Dialect/QCO/QCOUtils.h" #include "mlir/Dialect/QTensor/IR/QTensorOps.h" #include "mlir/Dialect/QTensor/IR/QTensorUtils.h" diff --git a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp index ffa9796353..f1cb23a849 100644 --- a/mlir/lib/Dialect/QCO/IR/QCOOps.cpp +++ b/mlir/lib/Dialect/QCO/IR/QCOOps.cpp @@ -11,17 +11,13 @@ #include "mlir/Dialect/QCO/IR/QCOOps.h" #include "mlir/Dialect/QCO/IR/QCODialect.h" // IWYU pragma: associated -#include "mlir/Dialect/QCO/IR/QCOInterfaces.h" -#include "mlir/Dialect/QCO/QCOUtils.h" #include "mlir/Dialect/Utils/Utils.h" #include #include -#include #include #include #include -#include #include #include #include diff --git a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp index 03ca2d0637..02d76e4b79 100644 --- a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp @@ -8,13 +8,17 @@ * Licensed under the MIT License */ +#include "mlir/Dialect/QCO/IR/QCOInterfaces.h" #include "mlir/Dialect/QCO/IR/QCOOps.h" #include "mlir/Dialect/QCO/QCOUtils.h" #include #include +#include #include +#include #include +#include using namespace mlir; using namespace mlir::qco; diff --git a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp index e0ad05a1d6..ed6c3bca41 100644 --- a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp @@ -9,11 +9,11 @@ */ #include "mlir/Dialect/QCO/IR/QCOOps.h" -#include "mlir/Dialect/QCO/QCOUtils.h" #include #include #include +#include #include #include #include @@ -29,6 +29,7 @@ #include #include +#include using namespace mlir; using namespace mlir::qco; diff --git a/mlir/unittests/Compiler/test_compiler_pipeline.cpp b/mlir/unittests/Compiler/test_compiler_pipeline.cpp index df3c3e68c4..37e6990b12 100644 --- a/mlir/unittests/Compiler/test_compiler_pipeline.cpp +++ b/mlir/unittests/Compiler/test_compiler_pipeline.cpp @@ -34,13 +34,17 @@ #include #include #include +#include +#include #include #include +#include #include #include #include #include +#include namespace mqt::test::compiler { diff --git a/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp b/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp index dcef2f4d34..6e3672abaf 100644 --- a/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp +++ b/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp @@ -27,14 +27,18 @@ #include #include #include +#include +#include #include #include +#include #include #include #include #include #include +#include using namespace mlir; diff --git a/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp b/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp index 6a2801f873..266a5f52cb 100644 --- a/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp +++ b/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp @@ -27,13 +27,17 @@ #include #include #include +#include +#include #include #include +#include #include #include #include #include +#include using namespace mlir; diff --git a/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp b/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp index 03ff96e5b1..f9d2050e03 100644 --- a/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp +++ b/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp @@ -27,13 +27,17 @@ #include #include #include +#include +#include #include #include +#include #include #include #include #include +#include using namespace mlir; diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp index 7741052c93..4e083edaf7 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp @@ -27,14 +27,18 @@ #include #include #include +#include +#include #include #include +#include #include #include #include #include #include +#include using namespace mlir; diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp index ecbbc0b62e..78e888fdbe 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp @@ -27,14 +27,18 @@ #include #include #include +#include +#include #include #include +#include #include #include #include #include #include +#include using namespace mlir; diff --git a/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp b/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp index 63257ae7cb..eae4e47344 100644 --- a/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp +++ b/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp @@ -21,12 +21,16 @@ #include #include #include +#include +#include #include +#include #include #include #include #include +#include using namespace mlir; using namespace mlir::qc; diff --git a/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp b/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp index 9331efde8b..899b333e44 100644 --- a/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp +++ b/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp @@ -24,11 +24,15 @@ #include #include #include +#include +#include #include +#include #include #include #include +#include using namespace mlir; diff --git a/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp b/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp index b39e35ed42..4d04f0ebb7 100644 --- a/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp +++ b/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp @@ -25,11 +25,15 @@ #include #include #include +#include +#include #include +#include #include #include #include +#include namespace { diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 29b11364fc..e837112887 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include #include @@ -31,6 +33,7 @@ #include #include #include +#include using namespace mlir; using namespace mlir::qco; diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp index 51c8a013ab..b7b8f01509 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include @@ -35,6 +37,7 @@ #include #include #include +#include using namespace mlir; using namespace qco; diff --git a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp index 4cc98fc095..e21097725d 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp @@ -99,9 +99,9 @@ class EulerSynthesisExactTest : public testing::TestWithParam< std::tuple> {}; -static std::pair, mlir::SmallVector> +std::pair, mlir::SmallVector> measureAndReturn(mlir::qco::QCOProgramBuilder& b, - mlir::SmallVector qubits) { + const mlir::SmallVector& qubits) { mlir::SmallVector bits; mlir::SmallVector bitTypes; auto i1Type = b.getI1Type(); diff --git a/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp b/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp index 717064b19a..8922399a3b 100644 --- a/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp +++ b/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp @@ -18,12 +18,16 @@ #include #include #include +#include +#include #include +#include #include #include #include #include +#include using namespace mlir; using namespace qir; diff --git a/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp b/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp index 46320029c5..9d09672131 100644 --- a/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp +++ b/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp @@ -33,7 +33,10 @@ #include #include #include +#include +#include #include +#include #include #include @@ -41,6 +44,7 @@ #include #include #include +#include using namespace mlir; using namespace mlir::qtensor; diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index 2a8039173c..fdd99819e3 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -14,16 +14,16 @@ #include #include -#include +#include +#include #include #include -#include #include static std::pair, mlir::SmallVector> measureAndReturn(mlir::qc::QCProgramBuilder& b, - mlir::SmallVector qubits) { + const mlir::SmallVector& qubits) { mlir::SmallVector bits; mlir::SmallVector bitTypes; auto i1Type = b.getI1Type(); diff --git a/mlir/unittests/programs/qc_programs.h b/mlir/unittests/programs/qc_programs.h index 2614850da4..8129227bfd 100644 --- a/mlir/unittests/programs/qc_programs.h +++ b/mlir/unittests/programs/qc_programs.h @@ -10,6 +10,7 @@ #pragma once +#include #include #include diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 69ac02ea91..bf37df4ac2 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -14,11 +14,14 @@ #include #include -#include +#include +#include #include +#include #include -#include +#include +#include static std::pair, mlir::SmallVector> measureAndReturnQTensor(mlir::qco::QCOProgramBuilder& b, mlir::Value qTensor, @@ -38,7 +41,7 @@ measureAndReturnQTensor(mlir::qco::QCOProgramBuilder& b, mlir::Value qTensor, static std::pair, mlir::SmallVector> measureAndReturn(mlir::qco::QCOProgramBuilder& b, - mlir::SmallVector qubits) { + const mlir::SmallVector& qubits) { mlir::SmallVector bits; mlir::SmallVector bitTypes; auto i1Type = b.getI1Type(); @@ -65,7 +68,7 @@ allocQubit(QCOProgramBuilder& b) { std::pair, SmallVector> allocQubitNoMeasure(QCOProgramBuilder& b) { - auto q = b.allocQubit(); + (void)b.allocQubit(); return {{b.intConstant(0)}, {b.getI64Type()}}; } @@ -102,8 +105,8 @@ allocLargeRegister(QCOProgramBuilder& b) { std::pair, SmallVector> staticQubitsNoMeasure(QCOProgramBuilder& b) { - auto q1 = b.staticQubit(0); - auto q2 = b.staticQubit(1); + (void)b.staticQubit(0); + (void)b.staticQubit(1); return {{b.intConstant(0)}, {b.getI64Type()}}; } @@ -3486,7 +3489,7 @@ nestedFalseIf(QCOProgramBuilder& b) { std::pair, SmallVector> qtensorAlloc(QCOProgramBuilder& b) { - auto qtensor = b.qtensorAlloc(3); + (void)b.qtensorAlloc(3); return measureAndReturn(b, {}); } @@ -3502,7 +3505,7 @@ qtensorFromElements(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.allocQubit(); auto q2 = b.allocQubit(); - auto t = b.qtensorFromElements({q0, q1, q2}); + (void)b.qtensorFromElements({q0, q1, q2}); return measureAndReturn(b, {}); } @@ -3518,7 +3521,7 @@ qtensorInsert(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); auto q1 = b.h(q0); - auto insertOutTensor = b.qtensorInsert(q1, extractOutTensor, 0); + (void)b.qtensorInsert(q1, extractOutTensor, 0); return measureAndReturn(b, {}); } @@ -3526,7 +3529,7 @@ std::pair, SmallVector> qtensorExtractInsertIndexMismatch(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); - auto insertOutTensor = b.qtensorInsert(q0, extractOutTensor, 1); + (void)b.qtensorInsert(q0, extractOutTensor, 1); return measureAndReturn(b, {}); } @@ -3534,7 +3537,7 @@ std::pair, SmallVector> qtensorExtractInsertSameIndex(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); - auto insertOutTensor = b.qtensorInsert(q0, extractOutTensor, 0); + (void)b.qtensorInsert(q0, extractOutTensor, 0); return measureAndReturn(b, {}); } From b5fcbb0cc1b9e902b2181c9f1cbbaa58a0ba5121 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Wed, 8 Jul 2026 12:45:07 +0200 Subject: [PATCH 52/80] fix(mlir): :rotating_light: fix compiler issue with imports --- mlir/unittests/programs/qc_programs.cpp | 1 + mlir/unittests/programs/qco_programs.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index fdd99819e3..d38933f65e 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index bf37df4ac2..b5e7d95972 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include From 92eb0c76109c54fa64936cd8f3c502f624d88701 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Wed, 8 Jul 2026 13:43:18 +0200 Subject: [PATCH 53/80] fix(mlir): :recycle: fix some test errors and some linter issues --- mlir/include/mlir/Dialect/QCO/QCOUtils.h | 18 -------- .../Dialect/QCO/IR/Operations/MeasureOp.cpp | 1 - .../Dialect/QCO/IR/QubitManagement/SinkOp.cpp | 19 ++++++++ mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp | 23 ++++------ .../test_euler_decomposition.cpp | 2 +- mlir/unittests/programs/qc_programs.cpp | 45 +++++++++++++++---- mlir/unittests/programs/qc_programs.h | 16 +++++++ mlir/unittests/programs/qco_programs.cpp | 7 +-- mlir/unittests/programs/qco_programs.h | 1 + mlir/unittests/programs/qir_programs.cpp | 19 ++++---- mlir/unittests/programs/qir_programs.h | 1 - .../programs/quantum_computation_programs.h | 5 --- 12 files changed, 95 insertions(+), 62 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/QCOUtils.h b/mlir/include/mlir/Dialect/QCO/QCOUtils.h index 4ac13fd288..f08db99293 100644 --- a/mlir/include/mlir/Dialect/QCO/QCOUtils.h +++ b/mlir/include/mlir/Dialect/QCO/QCOUtils.h @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -261,21 +260,4 @@ LogicalResult mergeXXPlusMinusYY(OpType op, PatternRewriter& rewriter) { return mergeTwoTargetOneParameterImpl(op, nextOp, rewriter, true); } -/** - * @brief Check if given quantum operation is unused (i.e., only used by - * sinks and no memory effects). - * - * @param op The operation to check. - * @return bool True if the operation is unused, false otherwise. - */ -inline bool checkDeadGate(Operation* op) { - if (!isMemoryEffectFree(op)) { - // This ignores operations and regions that have children with memory - // effects, which should never be considered dead. - return false; - } - return llvm::all_of(op->getUsers(), - [](Operation* user) { return isa(user); }); -} - } // namespace mlir::qco diff --git a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp index 9048910f2c..b76a2d0471 100644 --- a/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/Operations/MeasureOp.cpp @@ -10,7 +10,6 @@ #include "mlir/Dialect/QCO/IR/QCOOps.h" -#include #include using namespace mlir; diff --git a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp index 02d76e4b79..07b9202cbf 100644 --- a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp @@ -13,10 +13,12 @@ #include "mlir/Dialect/QCO/QCOUtils.h" #include +#include #include #include #include #include +#include #include #include @@ -25,6 +27,23 @@ using namespace mlir::qco; namespace { +/** + * @brief Check if given quantum operation is unused (i.e., only used by + * sinks and no memory effects). + * + * @param op The operation to check. + * @return bool True if the operation is unused, false otherwise. + */ +inline bool checkDeadGate(Operation* op) { + if (!isMemoryEffectFree(op)) { + // This ignores operations and regions that have children with memory + // effects, which should never be considered dead. + return false; + } + return llvm::all_of(op->getUsers(), + [](Operation* user) { return isa(user); }); +} + /** * @brief Remove matching alloc/static and sink pairs without operations * between them. diff --git a/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp b/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp index eae4e47344..7b0bdbbab1 100644 --- a/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp +++ b/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp @@ -218,7 +218,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(barrierMultipleQubits)}, QCTestCase{"SingleControlledBarrier", MQT_NAMED_BUILDER(singleControlledBarrier), - MQT_NAMED_BUILDER(barrier)}, + MQT_NAMED_BUILDER(twoQubitsOneBarrier)}, QCTestCase{"InverseBarrier", MQT_NAMED_BUILDER(inverseBarrier), MQT_NAMED_BUILDER(barrier)})); @@ -292,7 +292,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(singleControlledP)}, QCTestCase{"TrivialControlledGlobalPhase", MQT_NAMED_BUILDER(trivialControlledGlobalPhase), - MQT_NAMED_BUILDER(globalPhase)}, + MQT_NAMED_BUILDER(globalPhaseAndMeasure)}, QCTestCase{"InverseGlobalPhase", MQT_NAMED_BUILDER(inverseGlobalPhase), MQT_NAMED_BUILDER(globalPhase)}, QCTestCase{"InverseMultipleControlledGlobalPhase", @@ -331,13 +331,13 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(identity)}, QCTestCase{"SingleControlledIdentity", MQT_NAMED_BUILDER(singleControlledIdentity), - MQT_NAMED_BUILDER(identity)}, + MQT_NAMED_BUILDER(twoQubitsOneIdentity)}, QCTestCase{"MultipleControlledIdentity", MQT_NAMED_BUILDER(multipleControlledIdentity), - MQT_NAMED_BUILDER(identity)}, + MQT_NAMED_BUILDER(threeQubitsOneIdentity)}, QCTestCase{"NestedControlledIdentity", MQT_NAMED_BUILDER(nestedControlledIdentity), - MQT_NAMED_BUILDER(identity)}, + MQT_NAMED_BUILDER(threeQubitsOneIdentity)}, QCTestCase{"TrivialControlledIdentity", MQT_NAMED_BUILDER(trivialControlledIdentity), MQT_NAMED_BUILDER(identity)}, @@ -345,7 +345,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(identity)}, QCTestCase{"InverseMultipleControlledIdentity", MQT_NAMED_BUILDER(inverseMultipleControlledIdentity), - MQT_NAMED_BUILDER(identity)})); + MQT_NAMED_BUILDER(threeQubitsOneIdentity)})); /// @} /// \name QC/Operations/StandardGates/IswapOp.cpp @@ -921,16 +921,11 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( QCQubitManagementTest, QCTest, testing::Values( - QCTestCase{"AllocQubit", MQT_NAMED_BUILDER(allocQubit), - MQT_NAMED_BUILDER(emptyQC)}, - QCTestCase{"AllocQubitRegister", MQT_NAMED_BUILDER(allocQubitRegister), - MQT_NAMED_BUILDER(emptyQC)}, - QCTestCase{"AllocMultipleQubitRegisters", - MQT_NAMED_BUILDER(allocMultipleQubitRegisters), + QCTestCase{"AllocQubit", MQT_NAMED_BUILDER(allocQubitNoMeasure), MQT_NAMED_BUILDER(emptyQC)}, QCTestCase{"AllocLargeRegister", MQT_NAMED_BUILDER(allocLargeRegister), - MQT_NAMED_BUILDER(emptyQC)}, - QCTestCase{"StaticQubits", MQT_NAMED_BUILDER(staticQubits), + MQT_NAMED_BUILDER(allocQubitRegister)}, + QCTestCase{"StaticQubits", MQT_NAMED_BUILDER(staticQubitsNoMeasure), MQT_NAMED_BUILDER(emptyQC)}, QCTestCase{"StaticQubitsWithOps", MQT_NAMED_BUILDER(staticQubitsWithOps), diff --git a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp index e21097725d..e01a4563a2 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp @@ -99,7 +99,7 @@ class EulerSynthesisExactTest : public testing::TestWithParam< std::tuple> {}; -std::pair, mlir::SmallVector> +static std::pair, mlir::SmallVector> measureAndReturn(mlir::qco::QCOProgramBuilder& b, const mlir::SmallVector& qubits) { mlir::SmallVector bits; diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index d38933f65e..5732bfbd9b 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include // NOLINT(misc-include-cleaner) #include #include #include @@ -37,9 +37,8 @@ measureAndReturn(mlir::qc::QCProgramBuilder& b, namespace mlir::qc { -std::pair, SmallVector> -emptyQC([[maybe_unused]] QCProgramBuilder& builder) { - return measureAndReturn(builder, {}); +std::pair, SmallVector> emptyQC(QCProgramBuilder& b) { + return {{b.intConstant(0)}, {b.getI64Type()}}; } std::pair, SmallVector> @@ -48,6 +47,12 @@ allocQubit(QCProgramBuilder& b) { return measureAndReturn(b, {q}); } +std::pair, SmallVector> +allocQubitNoMeasure(QCProgramBuilder& b) { + auto q = b.allocQubit(); + return {{b.intConstant(0)}, {b.getI64Type()}}; +} + std::pair, SmallVector> allocMultipleQubitRegistersWithOps(QCProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); @@ -92,6 +97,13 @@ staticQubits(QCProgramBuilder& b) { return measureAndReturn(b, {q0, q1}); } +std::pair, SmallVector> +staticQubitsNoMeasure(QCProgramBuilder& b) { + auto q0 = b.staticQubit(0); + auto q1 = b.staticQubit(1); + return {{b.intConstant(0)}, {b.getI64Type()}}; +} + std::pair, SmallVector> staticQubitsWithOps(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); @@ -286,6 +298,13 @@ globalPhase(QCProgramBuilder& b) { return {{b.intConstant(0)}, {b.getI64Type()}}; } +std::pair, SmallVector> +globalPhaseAndMeasure(QCProgramBuilder& b) { + auto q = b.allocQubitRegister(1); + b.gphase(0.123); + return measureAndReturn(b, {q[0]}); +} + std::pair, SmallVector> singleControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); @@ -305,7 +324,7 @@ nestedControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.ctrl(q[0], {q[1]}, [&](ValueRange targets) { b.cgphase(0.123, targets[0]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, {q[0], q[1]}); } std::pair, SmallVector> @@ -338,7 +357,7 @@ std::pair, SmallVector> identity(QCProgramBuilder& b) { std::pair, SmallVector> singleControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.cid(q[1], q[0]); + b.cid(q[0], q[1]); return measureAndReturn(b, {q[0], q[1]}); } @@ -359,15 +378,22 @@ threeQubitsOneIdentity(QCProgramBuilder& b) { std::pair, SmallVector> multipleControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.mcid({q[2], q[1]}, q[0]); + b.mcid({q[0], q[1]}, q[2]); return measureAndReturn(b, {q[0], q[1], q[2]}); } +std::pair, SmallVector> +twoQubitsOneBarrier(QCProgramBuilder& b) { + auto q = b.allocQubitRegister(2); + b.barrier(q[0]); + return measureAndReturn(b, {q[0], q[1]}); +} + std::pair, SmallVector> nestedControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.ctrl(q[2], {q[0], q[1]}, - [&](ValueRange targets) { b.cid(targets[1], targets[0]); }); + b.ctrl(q[0], {q[1], q[2]}, + [&](ValueRange targets) { b.cid(targets[0], targets[1]); }); return measureAndReturn(b, {q[0], q[1], q[2]}); } @@ -1999,6 +2025,7 @@ invCtrlSandwich(QCProgramBuilder& b) { }); }); }); + return measureAndReturn(b, {q[0], q[1], q[2]}); } std::pair, SmallVector> invTwo(QCProgramBuilder& b) { diff --git a/mlir/unittests/programs/qc_programs.h b/mlir/unittests/programs/qc_programs.h index 8129227bfd..a4c59088ca 100644 --- a/mlir/unittests/programs/qc_programs.h +++ b/mlir/unittests/programs/qc_programs.h @@ -29,6 +29,10 @@ emptyQC(QCProgramBuilder& builder); std::pair, SmallVector> allocQubit(QCProgramBuilder& b); +/// Allocates a single qubit without measuring it. +std::pair, SmallVector> +allocQubitNoMeasure(QCProgramBuilder& b); + /// Allocates a qubit register of size `1`. std::pair, SmallVector> alloc1QubitRegister(QCProgramBuilder& b); @@ -53,6 +57,10 @@ allocLargeRegister(QCProgramBuilder& b); std::pair, SmallVector> staticQubits(QCProgramBuilder& b); +/// Allocates two inline qubits without measuring them. +std::pair, SmallVector> +staticQubitsNoMeasure(QCProgramBuilder& b); + /// Allocates two static qubits and applies operations. std::pair, SmallVector> staticQubitsWithOps(QCProgramBuilder& b); @@ -153,6 +161,10 @@ repeatedResetAfterSingleOp(QCProgramBuilder& b); std::pair, SmallVector> globalPhase(QCProgramBuilder& b); +/// Creates a circuit with just a global phase and a single measured qubit. +std::pair, SmallVector> +globalPhaseAndMeasure(QCProgramBuilder& b); + /// Creates a controlled global phase gate with a single control qubit. std::pair, SmallVector> singleControlledGlobalPhase(QCProgramBuilder& b); @@ -199,6 +211,10 @@ threeQubitsOneIdentity(QCProgramBuilder& b); std::pair, SmallVector> multipleControlledIdentity(QCProgramBuilder& b); +/// Creates an barrier gate on a single qubit in a two-qubit register. +std::pair, SmallVector> +twoQubitsOneBarrier(QCProgramBuilder& b); + /// Creates a circuit with a nested controlled identity gate. std::pair, SmallVector> nestedControlledIdentity(QCProgramBuilder& b); diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index b5e7d95972..a6d2456923 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -14,13 +14,14 @@ #include #include -#include +#include // NOLINT(misc-include-cleaner) #include #include #include #include #include +#include #include #include @@ -3549,7 +3550,7 @@ qtensorInsertExtractIndexMismatch(QCOProgramBuilder& b) { auto q1 = b.h(q0); auto insertOutTensor = b.qtensorInsert(q1, extractOutTensor, 0); auto [extractOutTensor1, q2] = b.qtensorExtract(insertOutTensor, 1); - auto insertOutTensor1 = b.qtensorInsert(q2, extractOutTensor1, 0); + (void)b.qtensorInsert(q2, extractOutTensor1, 0); return measureAndReturn(b, {}); } @@ -3560,7 +3561,7 @@ qtensorInsertExtractSameIndex(QCOProgramBuilder& b) { auto q1 = b.h(q0); auto insertOutTensor = b.qtensorInsert(q1, extractOutTensor, 0); auto [extractOutTensor1, q2] = b.qtensorExtract(insertOutTensor, 0); - auto insertOutTensor1 = b.qtensorInsert(q2, extractOutTensor1, 0); + (void)b.qtensorInsert(q2, extractOutTensor1, 0); return measureAndReturn(b, {}); } diff --git a/mlir/unittests/programs/qco_programs.h b/mlir/unittests/programs/qco_programs.h index db408f9b65..958b693ec4 100644 --- a/mlir/unittests/programs/qco_programs.h +++ b/mlir/unittests/programs/qco_programs.h @@ -10,6 +10,7 @@ #pragma once +#include #include #include diff --git a/mlir/unittests/programs/qir_programs.cpp b/mlir/unittests/programs/qir_programs.cpp index 6d3b1dd98c..42ec705132 100644 --- a/mlir/unittests/programs/qir_programs.cpp +++ b/mlir/unittests/programs/qir_programs.cpp @@ -13,15 +13,13 @@ #include "mlir/Dialect/QIR/Builder/QIRProgramBuilder.h" #include -#include -#include -#include -#include -#include -#include +#include +#include #include +#include #include +#include /** * @brief Measures the given qubits and returns the measurement outcomes as a @@ -45,7 +43,8 @@ measureAndRecord(mlir::qir::QIRProgramBuilder& b, } mlir::qir::QIRProgramBuilder::ClassicalRegister resultArray; if (inRegister) { - resultArray = b.allocClassicalBitRegister(qubits.size(), "meas"); + resultArray = b.allocClassicalBitRegister( + static_cast(qubits.size()), "meas"); } for (auto i = 0L; i < qubits.size(); ++i) { @@ -460,7 +459,7 @@ std::pair multipleControlledSdg(QIRProgramBuilder& b) { return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } -template std::pair t_(QIRProgramBuilder& b) { +template std::pair t(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.t(q[0]); return measureAndRecord(b, {q[0]}, IntoRegister); @@ -1111,7 +1110,7 @@ template std::pair singleControlledSdg(QIRProgramBuilder& b); template std::pair multipleControlledSdg(QIRProgramBuilder& b); -template std::pair t_(QIRProgramBuilder& b); +template std::pair t(QIRProgramBuilder& b); template std::pair singleControlledT(QIRProgramBuilder& b); template std::pair multipleControlledT(QIRProgramBuilder& b); @@ -1287,7 +1286,7 @@ template std::pair sdg(QIRProgramBuilder& b); template std::pair singleControlledSdg(QIRProgramBuilder& b); template std::pair multipleControlledSdg(QIRProgramBuilder& b); -template std::pair t_(QIRProgramBuilder& b); +template std::pair t(QIRProgramBuilder& b); template std::pair singleControlledT(QIRProgramBuilder& b); template std::pair multipleControlledT(QIRProgramBuilder& b); template std::pair tdg(QIRProgramBuilder& b); diff --git a/mlir/unittests/programs/qir_programs.h b/mlir/unittests/programs/qir_programs.h index c2ce7deeea..c5b2d9df00 100644 --- a/mlir/unittests/programs/qir_programs.h +++ b/mlir/unittests/programs/qir_programs.h @@ -12,7 +12,6 @@ #include #include -#include #include diff --git a/mlir/unittests/programs/quantum_computation_programs.h b/mlir/unittests/programs/quantum_computation_programs.h index b4555e4dfb..f6dab6e1c2 100644 --- a/mlir/unittests/programs/quantum_computation_programs.h +++ b/mlir/unittests/programs/quantum_computation_programs.h @@ -10,11 +10,6 @@ #pragma once -#include -#include - -#include - namespace qc { class QuantumComputation; From 20468cf1ee3b0d1a7cb3476c1f6a9e72d5feaa79 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Wed, 8 Jul 2026 13:58:14 +0200 Subject: [PATCH 54/80] fix(mlir): :bug: fix compilation error --- mlir/unittests/programs/qir_programs.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mlir/unittests/programs/qir_programs.cpp b/mlir/unittests/programs/qir_programs.cpp index 42ec705132..fd1e011174 100644 --- a/mlir/unittests/programs/qir_programs.cpp +++ b/mlir/unittests/programs/qir_programs.cpp @@ -459,7 +459,7 @@ std::pair multipleControlledSdg(QIRProgramBuilder& b) { return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } -template std::pair t(QIRProgramBuilder& b) { +template std::pair t_(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.t(q[0]); return measureAndRecord(b, {q[0]}, IntoRegister); @@ -1110,7 +1110,7 @@ template std::pair singleControlledSdg(QIRProgramBuilder& b); template std::pair multipleControlledSdg(QIRProgramBuilder& b); -template std::pair t(QIRProgramBuilder& b); +template std::pair t_(QIRProgramBuilder& b); template std::pair singleControlledT(QIRProgramBuilder& b); template std::pair multipleControlledT(QIRProgramBuilder& b); @@ -1286,7 +1286,7 @@ template std::pair sdg(QIRProgramBuilder& b); template std::pair singleControlledSdg(QIRProgramBuilder& b); template std::pair multipleControlledSdg(QIRProgramBuilder& b); -template std::pair t(QIRProgramBuilder& b); +template std::pair t_(QIRProgramBuilder& b); template std::pair singleControlledT(QIRProgramBuilder& b); template std::pair multipleControlledT(QIRProgramBuilder& b); template std::pair tdg(QIRProgramBuilder& b); From 5917c1b21660c211587e974d347e9ed8fcda54b8 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Wed, 8 Jul 2026 15:22:47 +0200 Subject: [PATCH 55/80] fix(mlir): :bug: fix incorrect tests nad linter issues --- mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp | 4 ++-- .../Transforms/Decomposition/test_euler_decomposition.cpp | 2 +- mlir/unittests/programs/qc_programs.cpp | 6 +++--- mlir/unittests/programs/qir_programs.cpp | 7 ++++--- mlir/unittests/programs/quantum_computation_programs.cpp | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp index 07b9202cbf..77f6660d9e 100644 --- a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp @@ -10,8 +10,8 @@ #include "mlir/Dialect/QCO/IR/QCOInterfaces.h" #include "mlir/Dialect/QCO/IR/QCOOps.h" -#include "mlir/Dialect/QCO/QCOUtils.h" +#include #include #include #include @@ -34,7 +34,7 @@ namespace { * @param op The operation to check. * @return bool True if the operation is unused, false otherwise. */ -inline bool checkDeadGate(Operation* op) { +static inline bool checkDeadGate(Operation* op) { if (!isMemoryEffectFree(op)) { // This ignores operations and regions that have children with memory // effects, which should never be considered dead. diff --git a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp index e01a4563a2..e21097725d 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp @@ -99,7 +99,7 @@ class EulerSynthesisExactTest : public testing::TestWithParam< std::tuple> {}; -static std::pair, mlir::SmallVector> +std::pair, mlir::SmallVector> measureAndReturn(mlir::qco::QCOProgramBuilder& b, const mlir::SmallVector& qubits) { mlir::SmallVector bits; diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index 5732bfbd9b..52efd604fe 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -49,7 +49,7 @@ allocQubit(QCProgramBuilder& b) { std::pair, SmallVector> allocQubitNoMeasure(QCProgramBuilder& b) { - auto q = b.allocQubit(); + b.allocQubit(); return {{b.intConstant(0)}, {b.getI64Type()}}; } @@ -99,8 +99,8 @@ staticQubits(QCProgramBuilder& b) { std::pair, SmallVector> staticQubitsNoMeasure(QCProgramBuilder& b) { - auto q0 = b.staticQubit(0); - auto q1 = b.staticQubit(1); + b.staticQubit(0); + b.staticQubit(1); return {{b.intConstant(0)}, {b.getI64Type()}}; } diff --git a/mlir/unittests/programs/qir_programs.cpp b/mlir/unittests/programs/qir_programs.cpp index fd1e011174..51ff342ca1 100644 --- a/mlir/unittests/programs/qir_programs.cpp +++ b/mlir/unittests/programs/qir_programs.cpp @@ -314,14 +314,14 @@ std::pair singleControlledIdentity(QIRProgramBuilder& b) { template std::pair twoQubitsOneIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); - b.id(q[0]); + b.id(q[1]); return measureAndRecord(b, {q[0], q[1]}, IntoRegister); } template std::pair threeQubitsOneIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); - b.id(q[0]); + b.id(q[2]); return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } @@ -459,7 +459,8 @@ std::pair multipleControlledSdg(QIRProgramBuilder& b) { return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); } -template std::pair t_(QIRProgramBuilder& b) { +template +std::pair t_(QIRProgramBuilder& b) { // NOLINT(*-identifier-naming) auto q = b.allocQubitRegister(1); b.t(q[0]); return measureAndRecord(b, {q[0]}, IntoRegister); diff --git a/mlir/unittests/programs/quantum_computation_programs.cpp b/mlir/unittests/programs/quantum_computation_programs.cpp index 4f8d99254a..41bebb3f92 100644 --- a/mlir/unittests/programs/quantum_computation_programs.cpp +++ b/mlir/unittests/programs/quantum_computation_programs.cpp @@ -111,7 +111,7 @@ void identity(QuantumComputation& comp) { void singleControlledIdentity(QuantumComputation& comp) { comp.addQubitRegister(2, "q"); - comp.ci(1, 0); + comp.ci(0, 1); comp.measureAll(true, false); } From 21f01f0ba8a16832962dfff5c88828a8cd9c9818 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 9 Jul 2026 09:38:19 +0200 Subject: [PATCH 56/80] fix(mlir): :bug: fix undefined behaviour --- mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp index 77f6660d9e..a55179b318 100644 --- a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp @@ -85,10 +85,10 @@ struct DeadGateElimination final : public OpRewritePattern { currentValue = TypeSwitch(currentOp) .Case([&](auto measureOp) { - rewriter.replaceAllUsesWith(measureOp.getQubitOut(), - measureOp.getQubitIn()); + auto newValue = measureOp.getQubitIn(); + rewriter.replaceAllUsesWith(measureOp.getQubitOut(), newValue); rewriter.eraseOp(measureOp); - return measureOp.getQubitIn(); + return newValue; }) .Case([&](auto ifOp) { auto newValue = ifOp.getInputForOutput(currentValue); @@ -96,8 +96,9 @@ struct DeadGateElimination final : public OpRewritePattern { return newValue; }) .Case([&](auto resetOp) { + auto newValue = resetOp.getQubitIn(); rewriter.replaceOp(resetOp, resetOp->getOperands()); - return resetOp.getQubitIn(); + return newValue; }) .Case([&](auto unitaryOp) { auto newValue = unitaryOp.getInputForOutput(currentValue); From 2b2d9b485c646f02d301ad689b51ac8362a38e88 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 9 Jul 2026 09:38:47 +0200 Subject: [PATCH 57/80] fix(mlir): :rotating_light: fix linter warnings --- mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp | 2 +- .../QCO/Transforms/Decomposition/test_euler_decomposition.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp index a55179b318..385c489b29 100644 --- a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp @@ -34,7 +34,7 @@ namespace { * @param op The operation to check. * @return bool True if the operation is unused, false otherwise. */ -static inline bool checkDeadGate(Operation* op) { +bool checkDeadGate(Operation* op) { if (!isMemoryEffectFree(op)) { // This ignores operations and regions that have children with memory // effects, which should never be considered dead. diff --git a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp index e21097725d..e01a4563a2 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp @@ -99,7 +99,7 @@ class EulerSynthesisExactTest : public testing::TestWithParam< std::tuple> {}; -std::pair, mlir::SmallVector> +static std::pair, mlir::SmallVector> measureAndReturn(mlir::qco::QCOProgramBuilder& b, const mlir::SmallVector& qubits) { mlir::SmallVector bits; From 065d23a250a4aa5a8a712547cb0e3bbfea571d16 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Jul 2026 09:08:07 +0000 Subject: [PATCH 58/80] =?UTF-8?q?=F0=9F=8E=A8=20pre-commit=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 10 ++-- .../Dialect/QCO/IR/test_qco_ir_matrix.cpp | 2 +- mlir/unittests/programs/qco_programs.cpp | 47 ++++++++++--------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55c17b984c..db6676a431 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,11 +42,11 @@ releases may include breaking changes. [#1513], [#1521], [#1542], [#1548], [#1550], [#1554], [#1567], [#1569], [#1570], [#1572], [#1573], [#1580], [#1602], [#1620], [#1623], [#1624], [#1626], [#1627], [#1635], [#1638], [#1673], [#1675], [#1700], [#1710], - [#1717], [#1728], [#1730], [#1749], [#1751], [#1755], [#1762], [#1765], - [#1780], [#1781], [#1782], [#1787], [#1806], [#1807], [#1808], [#1823], - [#1824], [#1830], [#1869]) ([**@burgholzer**], [**@denialhaag**], [**@taminob**], - [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**], - [**@simon1hofmann**]) + [#1717], [#1728], [#1730], [#1749], [#1751], [#1755], [#1762], [#1765], + [#1780], [#1781], [#1782], [#1787], [#1806], [#1807], [#1808], [#1823], + [#1824], [#1830], [#1869]) ([**@burgholzer**], [**@denialhaag**], + [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], + [**@MatthiasReumann**], [**@simon1hofmann**]) ### Changed diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp index 5fd6cf9459..7c1729630e 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp @@ -40,8 +40,8 @@ #include #include #include -#include #include +#include using namespace mlir; using namespace qco; diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 69861c7978..76d19db397 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -1645,7 +1645,8 @@ trivialControlledR(QCOProgramBuilder& b) { std::pair, SmallVector> inverseR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - auto res = b.inv(q[0], [&](Value qubit) { return b.r(-0.123, 0.456, qubit); }); + auto res = + b.inv(q[0], [&](Value qubit) { return b.r(-0.123, 0.456, qubit); }); q[0] = res[0]; return measureAndReturn(b, {q[0]}); } @@ -1736,8 +1737,8 @@ std::pair, SmallVector> inverseU2(QCOProgramBuilder& b) { constexpr double pi = std::numbers::pi; auto q = b.allocQubitRegister(1); - auto res = b.inv(q[0], - [&](Value qubit) { return b.u2(-0.567 + pi, -0.234 - pi, qubit); }); + auto res = b.inv( + q[0], [&](Value qubit) { return b.u2(-0.567 + pi, -0.234 - pi, qubit); }); q[0] = res[0]; return measureAndReturn(b, {q[0]}); } @@ -1828,7 +1829,8 @@ trivialControlledU(QCOProgramBuilder& b) { std::pair, SmallVector> inverseU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - auto res = b.inv(q[0], [&](Value qubit) { return b.u(-0.1, -0.3, -0.2, qubit); }); + auto res = + b.inv(q[0], [&](Value qubit) { return b.u(-0.1, -0.3, -0.2, qubit); }); q[0] = res[0]; return measureAndReturn(b, {q[0]}); } @@ -2959,7 +2961,8 @@ barrierMultipleQubits(QCOProgramBuilder& b) { std::pair, SmallVector> singleControlledBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto res = b.ctrl(q[1], q[0], [&](Value target) { return b.barrier({target})[0]; }); + auto res = + b.ctrl(q[1], q[0], [&](Value target) { return b.barrier({target})[0]; }); q[1] = res.first[0]; q[0] = res.second[0]; return measureAndReturn(b, {q[0]}); @@ -3642,14 +3645,15 @@ nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto control0 = b.allocQubit(); auto control1 = b.h(control0); - auto scfFor = b.scfFor(0, 3, 1, {reg.value, control1}, [&](Value iv, ValueRange iterArgs) { - auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); - auto q1 = b.h(q0); - auto [controlOut, targetOut] = - b.ctrl(iterArgs[1], q1, [&](Value target) { return b.x(target); }); - auto insert = b.qtensorInsert(targetOut, t0, iv); - return SmallVector{insert, controlOut}; - }); + auto scfFor = b.scfFor( + 0, 3, 1, {reg.value, control1}, [&](Value iv, ValueRange iterArgs) { + auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); + auto q1 = b.h(q0); + auto [controlOut, targetOut] = + b.ctrl(iterArgs[1], q1, [&](Value target) { return b.x(target); }); + auto insert = b.qtensorInsert(targetOut, t0, iv); + return SmallVector{insert, controlOut}; + }); return measureAndReturn(b, {scfFor[1]}); } @@ -3657,14 +3661,15 @@ std::pair, SmallVector> nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto control = b.h(reg[0]); - auto scfFor = b.scfFor(1, 4, 1, {reg.value, control}, [&](Value iv, ValueRange iterArgs) { - auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); - auto q1 = b.h(q0); - auto [controlOut, targetOut] = - b.ctrl(iterArgs[1], q1, [&](Value target) { return b.x(target); }); - auto insert = b.qtensorInsert(targetOut, t0, iv); - return SmallVector{insert, controlOut}; - }); + auto scfFor = b.scfFor( + 1, 4, 1, {reg.value, control}, [&](Value iv, ValueRange iterArgs) { + auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); + auto q1 = b.h(q0); + auto [controlOut, targetOut] = + b.ctrl(iterArgs[1], q1, [&](Value target) { return b.x(target); }); + auto insert = b.qtensorInsert(targetOut, t0, iv); + return SmallVector{insert, controlOut}; + }); return measureAndReturn(b, {scfFor[1]}); } From 98fafe68dd80640f80db157410ade45001c96ede Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 9 Jul 2026 12:41:36 +0200 Subject: [PATCH 59/80] test(mlir): :white_check_mark: pass new tests --- .../Dialect/QCO/IR/test_qco_ir_matrix.cpp | 111 +------- mlir/unittests/programs/qco_programs.cpp | 238 ++++++++++++------ mlir/unittests/programs/qco_programs.h | 27 ++ 3 files changed, 193 insertions(+), 183 deletions(-) diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp index 5fd6cf9459..aadcc08bb2 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp @@ -40,8 +40,8 @@ #include #include #include -#include #include +#include using namespace mlir; using namespace qco; @@ -70,115 +70,6 @@ expectedMatrixFromComputation(const Fn& build, const size_t numQubits = 2) { dd::buildFunctionality(comp, *package).getMatrix(numQubits)); } -static void controlledXH(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(2); - b.ctrl(q[0], q[1], [&](Value target) { - target = b.x(target); - return b.h(target); - }); -} - -static void inverseTwoRxRy(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange targets) { - auto w0 = b.rx(0.2, targets[0]); - auto w1 = b.ry(0.3, targets[1]); - return SmallVector{w0, w1}; - }); -} - -static void inverseCxThenRz(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange targets) { - auto w0 = targets[0]; - auto w1 = targets[1]; - std::tie(w0, w1) = b.cx(w0, w1); - w1 = b.rz(0.4, w1); - return SmallVector{w0, w1}; - }); -} - -static void inverseDcxThenRz(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange targets) { - auto w0 = targets[0]; - auto w1 = targets[1]; - std::tie(w0, w1) = b.dcx(w0, w1); - w1 = b.rz(0.4, w1); - return SmallVector{w0, w1}; - }); -} - -static void controlledInverseHT(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(2); - b.ctrl(q[0], q[1], [&](Value target) { - return b.inv(target, [&](Value qubit) { - qubit = b.h(qubit); - return b.t(qubit); - }); - }); -} - -static void inverseGphaseBarrierX(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(1); - b.inv(q[0], [&](Value target) { - b.gphase(0.25); - auto wire = b.barrier({target})[0]; - wire = b.x(wire); - return wire; - }); -} - -static void inverseNestedInvHAndT(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(1); - b.inv(q[0], [&](Value target) { - auto wire = b.inv(target, [&](Value inner) { return b.h(inner); }); - return b.t(wire); - }); -} - -static void inverseNestedInvHAndX(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(2); - b.inv({q[0], q[1]}, [&](ValueRange targets) { - auto w0 = b.inv(targets[0], [&](Value inner) { return b.h(inner); }); - auto w1 = b.x(targets[1]); - return SmallVector{w0, w1}; - }); -} - -static void inverseThreeWireRxRyRz(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange targets) { - auto w0 = b.rx(0.2, targets[0]); - auto w1 = b.ry(0.3, targets[1]); - auto w2 = b.rz(0.4, targets[2]); - return SmallVector{w0, w1, w2}; - }); -} - -static void inverseThreeWireNestedTwoInv(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange targets) { - auto inner = b.inv({targets[0], targets[1]}, [&](ValueRange innerTargets) { - auto w0 = b.rx(0.2, innerTargets[0]); - auto w1 = b.ry(0.3, innerTargets[1]); - return SmallVector{w0, w1}; - }); - auto w2 = b.rz(0.4, targets[2]); - return SmallVector{inner[0], inner[1], w2}; - }); -} - -static void inverseWithThreeQubitOpInBody(QCOProgramBuilder& b) { - auto q = b.allocQubitRegister(3); - b.inv({q[0], q[1], q[2]}, [&](ValueRange targets) { - auto [controls, innerTarget] = - b.ctrl({targets[0], targets[1]}, targets[2], - [&](Value inner) { return b.x(inner); }); - return SmallVector{controls[0], controls[1], innerTarget}; - }); -} - [[nodiscard]] static InvOp firstInvOp(ModuleOp module) { auto funcOp = cast(module.getBody()->front()); return *funcOp.getBody().getOps().begin(); diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 69861c7978..7c0c7b7df8 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -369,8 +369,7 @@ std::pair, SmallVector> inverseIdentity(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.id(qubit); }); - q = res[0]; - return measureAndReturn(b, {q}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -453,8 +452,7 @@ std::pair, SmallVector> inverseX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.x(qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -486,7 +484,7 @@ controlledTwoX(QCOProgramBuilder& b) { target = b.x(target); return b.x(target); }); - return measureAndReturn(b, {res.first[0], res.second[0]}); + return measureAndReturn(b, {res.first, res.second}); } std::pair, SmallVector> @@ -497,7 +495,7 @@ inverseTwoX(QCOProgramBuilder& b) { qubit = b.x(qubit); return qubit; }); - return measureAndReturn(b, {res[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -507,7 +505,7 @@ inverseGphaseX(QCOProgramBuilder& b) { b.gphase(-0.123); return b.x(qubit); }); - return measureAndReturn(b, {res[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -517,7 +515,7 @@ inverseGphaseBarrier(QCOProgramBuilder& b) { b.gphase(0.123); return b.barrier({qubit})[0]; }); - return measureAndReturn(b, {res[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -527,7 +525,7 @@ inverseTwoBarriersInInv(QCOProgramBuilder& b) { qubit = b.barrier({qubit})[0]; return b.barrier({qubit})[0]; }); - return measureAndReturn(b, {res[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> y(QCOProgramBuilder& b) { @@ -579,8 +577,7 @@ std::pair, SmallVector> inverseY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.y(qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -654,8 +651,7 @@ std::pair, SmallVector> inverseZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.z(qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -729,8 +725,7 @@ std::pair, SmallVector> inverseH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.h(qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -813,8 +808,7 @@ std::pair, SmallVector> inverseS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.s(qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -898,8 +892,7 @@ std::pair, SmallVector> inverseSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.sdg(qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -983,8 +976,7 @@ std::pair, SmallVector> inverseT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.t(qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -1068,8 +1060,7 @@ std::pair, SmallVector> inverseTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.tdg(qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -1153,8 +1144,7 @@ std::pair, SmallVector> inverseSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.sx(qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -1238,8 +1228,7 @@ std::pair, SmallVector> inverseSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.sxdg(qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -1324,8 +1313,7 @@ std::pair, SmallVector> inverseRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.rx(-0.123, qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -1408,8 +1396,7 @@ std::pair, SmallVector> inverseRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.ry(-0.456, qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -1492,8 +1479,7 @@ std::pair, SmallVector> inverseRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.rz(-0.789, qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -1569,8 +1555,7 @@ std::pair, SmallVector> inverseP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.p(-0.123, qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -1645,9 +1630,9 @@ trivialControlledR(QCOProgramBuilder& b) { std::pair, SmallVector> inverseR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - auto res = b.inv(q[0], [&](Value qubit) { return b.r(-0.123, 0.456, qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + auto res = + b.inv(q[0], [&](Value qubit) { return b.r(-0.123, 0.456, qubit); }); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -1736,10 +1721,9 @@ std::pair, SmallVector> inverseU2(QCOProgramBuilder& b) { constexpr double pi = std::numbers::pi; auto q = b.allocQubitRegister(1); - auto res = b.inv(q[0], - [&](Value qubit) { return b.u2(-0.567 + pi, -0.234 - pi, qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + auto res = b.inv( + q[0], [&](Value qubit) { return b.u2(-0.567 + pi, -0.234 - pi, qubit); }); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -1828,9 +1812,9 @@ trivialControlledU(QCOProgramBuilder& b) { std::pair, SmallVector> inverseU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - auto res = b.inv(q[0], [&](Value qubit) { return b.u(-0.1, -0.3, -0.2, qubit); }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + auto res = + b.inv(q[0], [&](Value qubit) { return b.u(-0.1, -0.3, -0.2, qubit); }); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -2959,18 +2943,16 @@ barrierMultipleQubits(QCOProgramBuilder& b) { std::pair, SmallVector> singleControlledBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto res = b.ctrl(q[1], q[0], [&](Value target) { return b.barrier({target})[0]; }); - q[1] = res.first[0]; - q[0] = res.second[0]; - return measureAndReturn(b, {q[0]}); + auto res = + b.ctrl(q[1], q[0], [&](Value target) { return b.barrier({target})[0]; }); + return measureAndReturn(b, {res.second}); } std::pair, SmallVector> inverseBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.barrier({qubit})[0]; }); - q[0] = res[0]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, {res}); } std::pair, SmallVector> @@ -3000,7 +2982,7 @@ emptyCtrl(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rxx(0.123, q[0], q[1]); auto [res0, res1] = b.ctrl(q[0], q[1], [&](Value target) { return target; }); - return measureAndReturn(b, {res0[0], res1[0]}); + return measureAndReturn(b, {res0, res1}); } std::pair, SmallVector> @@ -3642,14 +3624,15 @@ nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto control0 = b.allocQubit(); auto control1 = b.h(control0); - auto scfFor = b.scfFor(0, 3, 1, {reg.value, control1}, [&](Value iv, ValueRange iterArgs) { - auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); - auto q1 = b.h(q0); - auto [controlOut, targetOut] = - b.ctrl(iterArgs[1], q1, [&](Value target) { return b.x(target); }); - auto insert = b.qtensorInsert(targetOut, t0, iv); - return SmallVector{insert, controlOut}; - }); + auto scfFor = b.scfFor( + 0, 3, 1, {reg.value, control1}, [&](Value iv, ValueRange iterArgs) { + auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); + auto q1 = b.h(q0); + auto [controlOut, targetOut] = + b.ctrl(iterArgs[1], q1, [&](Value target) { return b.x(target); }); + auto insert = b.qtensorInsert(targetOut, t0, iv); + return SmallVector{insert, controlOut}; + }); return measureAndReturn(b, {scfFor[1]}); } @@ -3657,14 +3640,15 @@ std::pair, SmallVector> nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto control = b.h(reg[0]); - auto scfFor = b.scfFor(1, 4, 1, {reg.value, control}, [&](Value iv, ValueRange iterArgs) { - auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); - auto q1 = b.h(q0); - auto [controlOut, targetOut] = - b.ctrl(iterArgs[1], q1, [&](Value target) { return b.x(target); }); - auto insert = b.qtensorInsert(targetOut, t0, iv); - return SmallVector{insert, controlOut}; - }); + auto scfFor = b.scfFor( + 1, 4, 1, {reg.value, control}, [&](Value iv, ValueRange iterArgs) { + auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); + auto q1 = b.h(q0); + auto [controlOut, targetOut] = + b.ctrl(iterArgs[1], q1, [&](Value target) { return b.x(target); }); + auto insert = b.qtensorInsert(targetOut, t0, iv); + return SmallVector{insert, controlOut}; + }); return measureAndReturn(b, {scfFor[1]}); } @@ -3723,12 +3707,11 @@ nestedIfOpForLoopWithAngle(QCOProgramBuilder& b) { std::pair, SmallVector> controlledXH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto [ctrl, targ] = b.ctrl(q[0], q[1], [&](ValueRange targets) { - auto wire = b.x(targets[0]); - wire = b.h(wire); - return SmallVector{wire}; + auto [ctrl, targ] = b.ctrl(q[0], q[1], [&](Value target) { + target = b.x(target); + return b.h(target); }); - return measureAndReturn(b, {ctrl[0], targ[0]}); + return measureAndReturn(b, {ctrl, targ}); } std::pair, SmallVector> @@ -3745,4 +3728,113 @@ controlledInverseHT(QCOProgramBuilder& b) { return measureAndReturn(b, {ctrl[0], targ[0]}); } +std::pair, SmallVector> +inverseTwoRxRy(QCOProgramBuilder& b) { + auto q = b.allocQubitRegister(2); + auto res = b.inv({q[0], q[1]}, [&](ValueRange targets) { + auto w0 = b.rx(0.2, targets[0]); + auto w1 = b.ry(0.3, targets[1]); + return SmallVector{w0, w1}; + }); + return measureAndReturn(b, {res[0], res[1]}); +} + +std::pair, SmallVector> +inverseCxThenRz(QCOProgramBuilder& b) { + auto q = b.allocQubitRegister(2); + auto res = b.inv({q[0], q[1]}, [&](ValueRange targets) { + auto w0 = targets[0]; + auto w1 = targets[1]; + std::tie(w0, w1) = b.cx(w0, w1); + w1 = b.rz(0.4, w1); + return SmallVector{w0, w1}; + }); + return measureAndReturn(b, {res[0], res[1]}); +} + +std::pair, SmallVector> +inverseDcxThenRz(QCOProgramBuilder& b) { + auto q = b.allocQubitRegister(2); + auto res = b.inv({q[0], q[1]}, [&](ValueRange targets) { + auto w0 = targets[0]; + auto w1 = targets[1]; + std::tie(w0, w1) = b.dcx(w0, w1); + w1 = b.rz(0.4, w1); + return SmallVector{w0, w1}; + }); + return measureAndReturn(b, {res[0], res[1]}); +} + +std::pair, SmallVector> +inverseGphaseBarrierX(QCOProgramBuilder& b) { + auto q = b.allocQubitRegister(1); + auto res = b.inv(q[0], [&](Value target) { + b.gphase(0.25); + auto wire = b.barrier({target})[0]; + wire = b.x(wire); + return wire; + }); + return measureAndReturn(b, {res}); +} + +std::pair, SmallVector> +inverseNestedInvHAndT(QCOProgramBuilder& b) { + auto q = b.allocQubitRegister(1); + auto res = b.inv(q[0], [&](Value target) { + auto wire = b.inv(target, [&](Value inner) { return b.h(inner); }); + return b.t(wire); + }); + return measureAndReturn(b, {res}); +} + +std::pair, SmallVector> +inverseNestedInvHAndX(QCOProgramBuilder& b) { + auto q = b.allocQubitRegister(2); + auto res = b.inv({q[0], q[1]}, [&](ValueRange targets) { + auto w0 = b.inv(targets[0], [&](Value inner) { return b.h(inner); }); + auto w1 = b.x(targets[1]); + return SmallVector{w0, w1}; + }); + return measureAndReturn(b, {res[0], res[1]}); +} + +std::pair, SmallVector> +inverseThreeWireRxRyRz(QCOProgramBuilder& b) { + auto q = b.allocQubitRegister(3); + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange targets) { + auto w0 = b.rx(0.2, targets[0]); + auto w1 = b.ry(0.3, targets[1]); + auto w2 = b.rz(0.4, targets[2]); + return SmallVector{w0, w1, w2}; + }); + return measureAndReturn(b, {res[0], res[1], res[2]}); +} + +std::pair, SmallVector> +inverseThreeWireNestedTwoInv(QCOProgramBuilder& b) { + auto q = b.allocQubitRegister(3); + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange targets) { + auto inner = b.inv({targets[0], targets[1]}, [&](ValueRange innerTargets) { + auto w0 = b.rx(0.2, innerTargets[0]); + auto w1 = b.ry(0.3, innerTargets[1]); + return SmallVector{w0, w1}; + }); + auto w2 = b.rz(0.4, targets[2]); + return SmallVector{inner[0], inner[1], w2}; + }); + return measureAndReturn(b, {res[0], res[1], res[2]}); +} + +std::pair, SmallVector> +inverseWithThreeQubitOpInBody(QCOProgramBuilder& b) { + auto q = b.allocQubitRegister(3); + auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange targets) { + auto [controls, innerTarget] = + b.ctrl({targets[0], targets[1]}, targets[2], + [&](Value inner) { return b.x(inner); }); + return SmallVector{controls[0], controls[1], innerTarget}; + }); + return measureAndReturn(b, {res[0], res[1], res[2]}); +} + } // namespace mlir::qco diff --git a/mlir/unittests/programs/qco_programs.h b/mlir/unittests/programs/qco_programs.h index 958b693ec4..2729ddc968 100644 --- a/mlir/unittests/programs/qco_programs.h +++ b/mlir/unittests/programs/qco_programs.h @@ -1459,4 +1459,31 @@ controlledXH(QCOProgramBuilder& b); std::pair, SmallVector> controlledInverseHT(QCOProgramBuilder& b); +std::pair, SmallVector> +inverseTwoRxRy(QCOProgramBuilder& b); + +std::pair, SmallVector> +inverseCxThenRz(QCOProgramBuilder& b); + +std::pair, SmallVector> +inverseDcxThenRz(QCOProgramBuilder& b); + +std::pair, SmallVector> +inverseGphaseBarrierX(QCOProgramBuilder& b); + +std::pair, SmallVector> +inverseNestedInvHAndT(QCOProgramBuilder& b); + +std::pair, SmallVector> +inverseNestedInvHAndX(QCOProgramBuilder& b); + +std::pair, SmallVector> +inverseThreeWireRxRyRz(QCOProgramBuilder& b); + +std::pair, SmallVector> +inverseThreeWireNestedTwoInv(QCOProgramBuilder& b); + +std::pair, SmallVector> +inverseWithThreeQubitOpInBody(QCOProgramBuilder& b); + } // namespace mlir::qco From 5635099cbaf70c2e6d8f4493778d024f8a58101e Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 9 Jul 2026 12:50:20 +0200 Subject: [PATCH 60/80] test(mlir): :white_check_mark: fix incorrect test case --- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index eab8acec3e..5518a5f4d2 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -525,7 +525,7 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(trivialControlledIdentity), MQT_NAMED_BUILDER(allocQubit)}, QCOTestCase{"InverseIdentity", MQT_NAMED_BUILDER(inverseIdentity), - MQT_NAMED_BUILDER(allocQubit)}, + MQT_NAMED_BUILDER(alloc1QubitRegister)}, QCOTestCase{"InverseMultipleControlledIdentity", MQT_NAMED_BUILDER(inverseMultipleControlledIdentity), MQT_NAMED_BUILDER(alloc3QubitRegister)})); From a8e7acc5b16d45ea2722e7ecba976633a3e44604 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 9 Jul 2026 13:13:56 +0200 Subject: [PATCH 61/80] chore(mlir): :recycle: clean up further tests --- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 119 +----------------- mlir/unittests/programs/qc_programs.cpp | 3 +- mlir/unittests/programs/qco_programs.cpp | 82 ++++++++++++ mlir/unittests/programs/qco_programs.h | 17 +++ 4 files changed, 106 insertions(+), 115 deletions(-) diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 5518a5f4d2..421fb976f3 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -121,120 +121,6 @@ TEST_F(QCOTest, BuilderRejectsMixedStaticAndDynamicQubitAllocationModes) { "Cannot mix dynamic and static qubit allocation modes"); } -TEST_F(QCOTest, CheckDeadGateElimination) { - QCOProgramBuilder builder(context.get()); - builder.initialize({builder.getI1Type(), builder.getI1Type()}); - auto q0S0 = builder.allocQubit(); - auto q1S0 = builder.allocQubit(); - - auto [q0Measured, m0] = builder.measure(q0S0); - auto [q1Measured, m1] = builder.measure(q1S0); - - auto q0S1 = builder.h(q0Measured); - auto [q0S2, q1S1] = builder.cx(q0S1, q1Measured); - auto [q1S2, c1] = builder.measure(q1S1); - builder.sink(q0S2); - builder.sink(q1S2); - auto module = builder.finalize({m0, m1}); - - QCOProgramBuilder reference(context.get()); - reference.initialize({reference.getI1Type(), reference.getI1Type()}); - auto r0 = reference.allocQubit(); - auto r1 = reference.allocQubit(); - auto [r0Measured, mr0] = reference.measure(r0); - auto [r1Measured, mr1] = reference.measure(r1); - reference.sink(r0Measured); - reference.sink(r1Measured); - auto refModule = reference.finalize({mr0, mr1}); - - ASSERT_TRUE(module); - EXPECT_TRUE(verify(*module).succeeded()); - EXPECT_TRUE(runQCOCleanupPipeline(module.get()).succeeded()); - EXPECT_TRUE(verify(*module).succeeded()); - - ASSERT_TRUE(refModule); - EXPECT_TRUE(verify(*refModule).succeeded()); - EXPECT_TRUE(runQCOCleanupPipeline(refModule.get()).succeeded()); - EXPECT_TRUE(verify(*refModule).succeeded()); - - EXPECT_TRUE( - areModulesEquivalentWithPermutations(module.get(), refModule.get())); -} - -TEST_F(QCOTest, CheckIfOpDeadGateElimination) { - QCOProgramBuilder builder(context.get()); - builder.initialize(); - auto q0S0 = builder.allocQubit(); - auto q1S0 = builder.allocQubit(); - auto q0S1 = builder.h(q0S0); - auto [q0S2, c0] = builder.measure(q0S1); - - // This is an `if` with memory effects - it can't be removed. - auto q1S1 = builder.qcoIf( - c0, {q1S0}, - [&](ValueRange qubits) -> SmallVector { - auto q1Then = builder.x(qubits[0]); - builder.gphase(0.5); // This adds memory effects to the `IfOp`. - return SmallVector{q1Then}; - }, - [&](ValueRange qubits) -> SmallVector { - auto q1Else = builder.h(qubits[0]); - return SmallVector{q1Else}; - })[0]; - - // This is an `if` without memory effects - it can be removed. - auto q1S2 = builder.qcoIf( - c0, {q1S1}, - [&](ValueRange qubits) -> SmallVector { - auto q1Then = builder.x(qubits[0]); - return SmallVector{q1Then}; - }, - [&](ValueRange qubits) -> SmallVector { - auto q1Else = builder.h(qubits[0]); - return SmallVector{q1Else}; - })[0]; - builder.sink(q0S2); - builder.sink(q1S2); - auto module = builder.finalize(); - - QCOProgramBuilder reference(context.get()); - reference.initialize(); - auto r0S0 = reference.allocQubit(); - auto r1S0 = reference.allocQubit(); - auto r0S1 = reference.h(r0S0); - auto [r0S2, cr0] = reference.measure(r0S1); - - // This is an `if` with memory effects - it can't be removed. - auto r1S1 = reference.qcoIf( - cr0, {r1S0}, - [&](ValueRange qubits) -> SmallVector { - auto q1Then = reference.x(qubits[0]); - reference.gphase(0.5); // Due to memory effect, the `IfOp` stays. - return SmallVector{q1Then}; - }, - [&](ValueRange qubits) -> SmallVector { - auto q1Else = reference.h(qubits[0]); - return SmallVector{q1Else}; - })[0]; - - reference.sink(r0S2); - reference.sink(r1S1); - auto refModule = reference.finalize(); - - ASSERT_TRUE(module); - EXPECT_TRUE(verify(*module).succeeded()); - EXPECT_TRUE(runQCOCleanupPipeline(module.get()).succeeded()); - EXPECT_TRUE(verify(*module).succeeded()); - - ASSERT_TRUE(refModule); - EXPECT_TRUE(verify(*refModule).succeeded()); - EXPECT_TRUE(runQCOCleanupPipeline(refModule.get()).succeeded()); - EXPECT_TRUE(verify(*refModule).succeeded()); - - EXPECT_TRUE( - areModulesEquivalentWithPermutations(module.get(), refModule.get())); -} - TEST_F(QCOTest, DirectIfBuilder) { // Test If construction directly QCOProgramBuilder builder(context.get()); @@ -1281,6 +1167,11 @@ INSTANTIATE_TEST_SUITE_P( QCOTestCase{"StaticQubitsWithInv", MQT_NAMED_BUILDER(staticQubitsWithInv), MQT_NAMED_BUILDER(staticQubitsWithInv)}, + QCOTestCase{"DeadGateElimination", MQT_NAMED_BUILDER(deadGatesProgram), + MQT_NAMED_BUILDER(alloc2Qubits)}, + QCOTestCase{"DeadGateEliminationIfOp", + MQT_NAMED_BUILDER(deadGatesWithIfOpProgram), + MQT_NAMED_BUILDER(deadGatesWithIfOpSimplified)}, QCOTestCase{"AllocSinkPair", MQT_NAMED_BUILDER(allocSinkPair), MQT_NAMED_BUILDER(allocQubitNoMeasure)})); /// @} diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index af10651424..562911e58e 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -333,7 +333,8 @@ trivialControlledGlobalPhase(QCProgramBuilder& b) { return measureAndReturn(b, {q[0]}); } -void inverseGlobalPhase(QCProgramBuilder& b) { +std::pair, SmallVector> +inverseGlobalPhase(QCProgramBuilder& b) { b.inv(ValueRange{}, [&](ValueRange /*qubits*/) { b.gphase(-0.123); }); return {{b.intConstant(0)}, {b.getI64Type()}}; } diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 7c0c7b7df8..137db3ef1a 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -68,6 +68,13 @@ allocQubit(QCOProgramBuilder& b) { return measureAndReturn(b, {q}); } +std::pair, SmallVector> +alloc2Qubits(QCOProgramBuilder& b) { + auto q0 = b.allocQubit(); + auto q1 = b.allocQubit(); + return measureAndReturn(b, {q0, q1}); +} + std::pair, SmallVector> allocQubitNoMeasure(QCOProgramBuilder& b) { (void)b.allocQubit(); @@ -167,6 +174,81 @@ allocSinkPair(QCOProgramBuilder& b) { return {{b.intConstant(0)}, {b.getI64Type()}}; } +std::pair, SmallVector> +deadGatesProgram(QCOProgramBuilder& b) { + auto q0 = b.allocQubit(); + auto q1 = b.allocQubit(); + + auto [q0M, m0] = b.measure(q0); + auto [q1M, m1] = b.measure(q1); + + q0 = b.h(q0M); + auto [res0, res1] = b.cx(q0, q1M); + auto [_, c1] = b.measure(res1); + + return {{m0, m1}, {b.getI1Type(), b.getI1Type()}}; +} + +std::pair, SmallVector> +deadGatesWithIfOpProgram(QCOProgramBuilder& b) { + auto q0 = b.allocQubit(); + auto q1 = b.allocQubit(); + q0 = b.h(q0); + auto [r0, c0] = b.measure(q0); + q0 = r0; + + // This is an `if` with memory effects - it can't be removed. + q1 = b.qcoIf( + c0, {q1}, + [&](ValueRange qubits) -> SmallVector { + auto q1Then = b.x(qubits[0]); + b.gphase(0.5); // This adds memory effects to the `IfOp`. + return SmallVector{q1Then}; + }, + [&](ValueRange qubits) -> SmallVector { + auto q1Else = b.h(qubits[0]); + return SmallVector{q1Else}; + })[0]; + + // This is an `if` without memory effects - it can be removed. + q1 = b.qcoIf( + c0, {q1}, + [&](ValueRange qubits) -> SmallVector { + auto q1Then = b.x(qubits[0]); + return SmallVector{q1Then}; + }, + [&](ValueRange qubits) -> SmallVector { + auto q1Else = b.h(qubits[0]); + return SmallVector{q1Else}; + })[0]; + + return {{c0}, {b.getI1Type()}}; +} + +std::pair, SmallVector> +deadGatesWithIfOpSimplified(QCOProgramBuilder& b) { + auto q0 = b.allocQubit(); + auto q1 = b.allocQubit(); + q0 = b.h(q0); + auto [r0, c0] = b.measure(q0); + q0 = r0; + + // This is an `if` with memory effects - it can't be removed. + q1 = b.qcoIf( + c0, {q1}, + [&](ValueRange qubits) -> SmallVector { + auto q1Then = b.x(qubits[0]); + b.gphase(0.5); // Due to memory effect, the `IfOp` stays. + return SmallVector{q1Then}; + }, + [&](ValueRange qubits) -> SmallVector { + auto q1Else = b.h(qubits[0]); + return SmallVector{q1Else}; + })[0]; + + return {{c0}, {b.getI1Type()}}; +} + std::pair, SmallVector> mixedStaticThenDynamicQubit(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); diff --git a/mlir/unittests/programs/qco_programs.h b/mlir/unittests/programs/qco_programs.h index 2729ddc968..26d25de42b 100644 --- a/mlir/unittests/programs/qco_programs.h +++ b/mlir/unittests/programs/qco_programs.h @@ -29,6 +29,10 @@ emptyQCO(QCOProgramBuilder& builder); std::pair, SmallVector> allocQubit(QCOProgramBuilder& b); +/// Allocates two individual qubits. +std::pair, SmallVector> +alloc2Qubits(QCOProgramBuilder& b); + /// Allocates a single qubit that is not measured. std::pair, SmallVector> allocQubitNoMeasure(QCOProgramBuilder& b); @@ -85,6 +89,19 @@ staticQubitsWithInv(QCOProgramBuilder& b); std::pair, SmallVector> allocSinkPair(QCOProgramBuilder& b); +/// Allocates two qubits and performs a set of dead gates on them. +std::pair, SmallVector> +deadGatesProgram(QCOProgramBuilder& b); + +/// Allocates two qubits and performs a set of dead gates on them, including +/// `if` operations. +std::pair, SmallVector> +deadGatesWithIfOpProgram(QCOProgramBuilder& b); + +/// Allocates two qubits and performs only non-dead `if` operations. +std::pair, SmallVector> +deadGatesWithIfOpSimplified(QCOProgramBuilder& b); + // --- Invalid / mixed addressing (unit tests) -------------------------------- /// @pre `builder.initialize()`. Fatal mixed addressing: static then dynamic From af1009f833459998e06ff6c6fdcf8c9051e908be Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 9 Jul 2026 13:34:31 +0200 Subject: [PATCH 62/80] fix(mlir): :bug: fix build error in decomposition tests --- .../QCO/Transforms/Decomposition/test_euler_decomposition.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp index 526eb0bb81..03e2f8dadf 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp @@ -905,14 +905,14 @@ controlledInverseHT(QCOProgramBuilder& b) { return b.t(qubit); }); }); - return measureAndReturn(b, {res.second[0]}); + return measureAndReturn(b, {res.second}); } static std::pair, SmallVector> controlledH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.ctrl(q[0], q[1], [&b](Value target) { return b.h(target); }); - return measureAndReturn(b, {res.second[0]}); + return measureAndReturn(b, {res.second}); } static std::pair, SmallVector> From 15072966fe78e171d01eb0159054c9257531673a Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 9 Jul 2026 14:36:22 +0200 Subject: [PATCH 63/80] chore(mlir): :recycle: potentially fix remaining linter errors --- mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp | 6 +++--- .../Dialect/QCO/IR/test_qco_ir_matrix.cpp | 1 - .../Decomposition/test_euler_decomposition.cpp | 11 +++++++++-- mlir/unittests/programs/qc_programs.cpp | 7 +++++++ mlir/unittests/programs/qco_programs.cpp | 14 ++++++++++++++ mlir/unittests/programs/qir_programs.cpp | 4 ++-- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp index 385c489b29..777eb1a5aa 100644 --- a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp @@ -25,8 +25,6 @@ using namespace mlir; using namespace mlir::qco; -namespace { - /** * @brief Check if given quantum operation is unused (i.e., only used by * sinks and no memory effects). @@ -34,7 +32,7 @@ namespace { * @param op The operation to check. * @return bool True if the operation is unused, false otherwise. */ -bool checkDeadGate(Operation* op) { +static bool checkDeadGate(Operation* op) { if (!isMemoryEffectFree(op)) { // This ignores operations and regions that have children with memory // effects, which should never be considered dead. @@ -44,6 +42,8 @@ bool checkDeadGate(Operation* op) { [](Operation* user) { return isa(user); }); } +namespace { + /** * @brief Remove matching alloc/static and sink pairs without operations * between them. diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp index aadcc08bb2..00cff14514 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp @@ -40,7 +40,6 @@ #include #include #include -#include #include using namespace mlir; diff --git a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp index 03e2f8dadf..6b19442f18 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp @@ -99,6 +99,15 @@ class EulerSynthesisExactTest : public testing::TestWithParam< std::tuple> {}; +} // namespace + +/** + * @brief Measures the given qubits and return the measurement outcomes and + * their types. + * @param b The `ProgramBuilder` used to perform the measurements. + * @param qubits The qubits to be measured. + * @return A pair containing the result values and their types. + */ static std::pair, mlir::SmallVector> measureAndReturn(mlir::qco::QCOProgramBuilder& b, const mlir::SmallVector& qubits) { @@ -113,8 +122,6 @@ measureAndReturn(mlir::qco::QCOProgramBuilder& b, return {bits, bitTypes}; } -} // namespace - //===----------------------------------------------------------------------===// // Euler synthesis support //===----------------------------------------------------------------------===// diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index 562911e58e..aed927b263 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -22,6 +22,13 @@ #include #include +/** + * @brief Measures the given qubits and return the measurement outcomes and + * their types. + * @param b The `ProgramBuilder` used to perform the measurements. + * @param qubits The qubits to be measured. + * @return A pair containing the result values and their types. + */ static std::pair, mlir::SmallVector> measureAndReturn(mlir::qc::QCProgramBuilder& b, const mlir::SmallVector& qubits) { diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 137db3ef1a..77f33ac165 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -25,6 +25,13 @@ #include #include +/** + * @brief Measures the given `qtensor` and return the measurement outcomes and + * their types. + * @param b The `ProgramBuilder` used to perform the measurements. + * @param qTensor The `qtensor` to be measured. + * @return A pair containing the result values and their types. + */ static std::pair, mlir::SmallVector> measureAndReturnQTensor(mlir::qco::QCOProgramBuilder& b, mlir::Value qTensor, int64_t size) { @@ -41,6 +48,13 @@ measureAndReturnQTensor(mlir::qco::QCOProgramBuilder& b, mlir::Value qTensor, return {bits, bitTypes}; } +/** + * @brief Measures the given qubits and return the measurement outcomes and + * their types. + * @param b The `ProgramBuilder` used to perform the measurements. + * @param qubits The qubits to be measured. + * @return A pair containing the result values and their types. + */ static std::pair, mlir::SmallVector> measureAndReturn(mlir::qco::QCOProgramBuilder& b, const mlir::SmallVector& qubits) { diff --git a/mlir/unittests/programs/qir_programs.cpp b/mlir/unittests/programs/qir_programs.cpp index 51ff342ca1..551c0fad94 100644 --- a/mlir/unittests/programs/qir_programs.cpp +++ b/mlir/unittests/programs/qir_programs.cpp @@ -22,8 +22,8 @@ #include /** - * @brief Measures the given qubits and returns the measurement outcomes as a - * struct value or a single `i1`. + * @brief Measures the given qubits, records the outcomes and returns + * a single `i64` exit code with the value 0. * @param b The QIRProgramBuilder used to perform the measurements and create * the struct. * @param qubits The qubits to be measured. From e327250d20a51241c336618c6a6a6f2986c7c5d0 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 9 Jul 2026 14:42:41 +0200 Subject: [PATCH 64/80] test(mlir): :recycle: increase test coverage for PR --- .../Dialect/QIR/Builder/QIRProgramBuilder.h | 18 ------------------ .../Dialect/QIR/Builder/QIRProgramBuilder.cpp | 11 ----------- mlir/unittests/programs/qco_programs.cpp | 1 + 3 files changed, 1 insertion(+), 29 deletions(-) diff --git a/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h b/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h index 5d64e990fb..7bcf5aa0f3 100644 --- a/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h @@ -400,24 +400,6 @@ class QIRProgramBuilder final : public ImplicitLocOpBuilder { */ QIRProgramBuilder& reset(Value qubit); - /** - * @brief Read the value of the given measurement result. - * - * @details - * The value is read via `__quantum__rt__read_result`. - * - * @param result The value representing the measurement result - * @return An LLVM pointer to the measurement result - * - * @par Example: - * ```c++ - * auto result = builder.measure(q0, 0); - * auto value = builder.readResult(result); - * - * ``` - */ - Value readResult(Value result); - //===--------------------------------------------------------------------===// // Unitary Operations //===--------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp b/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp index c49d7d7a0e..0d4a65341b 100644 --- a/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp +++ b/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp @@ -445,17 +445,6 @@ QIRProgramBuilder& QIRProgramBuilder::reset(Value qubit) { return *this; } -Value QIRProgramBuilder::readResult(mlir::Value result) { - checkFinalized(); - - const auto fnSig = LLVM::LLVMFunctionType::get(getI1Type(), {ptrType}); - auto fnDec = - getOrCreateFunctionDeclaration(*this, module, QIR_READ_RESULT, fnSig); - auto readOp = LLVM::CallOp::create(*this, fnDec, result); - - return readOp.getResult(); -} - //===----------------------------------------------------------------------===// // Unitary Operations //===----------------------------------------------------------------------===// diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index 77f33ac165..f9784bf4b3 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -199,6 +199,7 @@ deadGatesProgram(QCOProgramBuilder& b) { q0 = b.h(q0M); auto [res0, res1] = b.cx(q0, q1M); auto [_, c1] = b.measure(res1); + q0 = b.reset(res0); return {{m0, m1}, {b.getI1Type(), b.getI1Type()}}; } From 7035f0de775184e154dcc11713855531f4556b45 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 9 Jul 2026 15:43:26 +0200 Subject: [PATCH 65/80] chore(mlir): :recycle: apply coderabbit suggestions --- .../mlir/Dialect/QC/Builder/QCProgramBuilder.h | 3 ++- .../mlir/Dialect/QCO/Builder/QCOProgramBuilder.h | 4 ++-- mlir/lib/Conversion/QCOToJeff/QCOToJeff.cpp | 9 ++------- mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp | 13 +++++++++++++ .../Dialect/QC/Translation/TranslateQASM3ToQC.cpp | 7 +++++++ .../Translation/TranslateQuantumComputationToQC.cpp | 11 ++++++++--- .../test_quantum_computation_translation.cpp | 2 +- .../programs/quantum_computation_programs.cpp | 5 ++--- 8 files changed, 37 insertions(+), 17 deletions(-) diff --git a/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h b/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h index 36137c0992..bc51da41ad 100644 --- a/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h @@ -1165,7 +1165,8 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder { /** * @brief Finalize the program with a given exit code and return the * constructed module - * @param returnValues Values representing the exit code to return + * @param returnValues Values representing the return values of the main + * function. * * @details * Automatically deallocates all remaining valid qubits and tensors of qubits, diff --git a/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h b/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h index 05593a8bcd..0506ee7224 100644 --- a/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h @@ -1473,7 +1473,8 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { /** * @brief Finalize the program with a given exit code and return the * constructed module - * @param returnValues Values representing the exit code to return + * @param returnValues Values representing the return values of the main + * function. * * @details * Automatically deallocates all remaining valid qubits and tensors of qubits, @@ -1492,7 +1493,6 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { /** * @brief Convenience method for building quantum programs. * @param context The MLIR context to use for building the program - * @param returnTypes The types of the values to be returned by the program. * @param buildFunc A function that takes a reference to a QCOProgramBuilder * and uses it to build the desired quantum program. The builder will be * properly initialized before calling this function, and the resulting module diff --git a/mlir/lib/Conversion/QCOToJeff/QCOToJeff.cpp b/mlir/lib/Conversion/QCOToJeff/QCOToJeff.cpp index 7f2cfa6578..0bb434e9e3 100644 --- a/mlir/lib/Conversion/QCOToJeff/QCOToJeff.cpp +++ b/mlir/lib/Conversion/QCOToJeff/QCOToJeff.cpp @@ -1194,16 +1194,11 @@ struct ConvertSCFForOpToJeff final : StatefulOpConversionPattern { * * @par Example: * ```mlir - * func.func @main() -> i64 attributes {passthrough = ["entry_point"]} { - * %0 = arith.constant 0 : i64 - * return %0 - * } + * func.func @main() -> i64 attributes {passthrough = ["entry_point"]} { ... } * ``` * is converted to * ```mlir - * func.func @main() -> () { - * return - * } + * func.func @main() -> i64 { ... } * ``` */ struct ConvertQCOMainToJeff final : StatefulOpConversionPattern { diff --git a/mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp b/mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp index 4229d99d96..965d9396bb 100644 --- a/mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp +++ b/mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp @@ -473,6 +473,19 @@ void populateQCToQIRPatterns(RewritePatternSet& patterns, void stripReturnedMeasurements(Operation* moduleOp, LoweringState& state) { moduleOp->walk([&](func::FuncOp funcOp) { + // First, check if the given function is the main entrypoint or not. + auto passthrough = funcOp->getAttrOfType("passthrough"); + bool isEntryPoint = false; + if (passthrough) { + isEntryPoint = llvm::any_of(passthrough, [](Attribute attr) { + auto strAttr = dyn_cast(attr); + return strAttr && strAttr.getValue() == "entry_point"; + }); + } + if (!isEntryPoint) { + return; + } + funcOp.walk([&](func::ReturnOp returnOp) { SmallVector keptOperands; SmallVector keptReturnTypes; diff --git a/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp b/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp index 12d9127894..c1e05f821a 100644 --- a/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp +++ b/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp @@ -236,6 +236,13 @@ class MLIRQasmImporter final : public qasm3::InstVisitor { << "' was never measured.\n"; return nullptr; } + + auto expectedSize = classicalRegisters[regName].size; + if (it->second.size() < expectedSize) { + llvm::errs() << "Not all bits of output register '" << regName + << "' have been measured.\n"; + return nullptr; + } for (auto bit : it->second) { if (!bit) { llvm::errs() << "Not all bits of output register '" << regName diff --git a/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp b/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp index f9d0f21371..a649832590 100644 --- a/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp +++ b/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp @@ -885,9 +885,14 @@ OwningOpRef translateQuantumComputationToQC( // Finalize and return the module (adds return statement and transfers // ownership) - return quantumComputation.getNcbits() == 0 - ? builder.finalize({builder.intConstant(0)}) - : builder.finalize(state.results); + if (quantumComputation.getNcbits() > 0) { + if (llvm::any_of(state.results, [](Value v) { return !v; })) { + llvm::errs() << "Not all classical bits were measured.\n"; + return nullptr; + } + return builder.finalize(state.results); + } + return builder.finalize(); } } // namespace mlir diff --git a/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp b/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp index 4d04f0ebb7..89880e8a5f 100644 --- a/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp +++ b/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp @@ -167,7 +167,7 @@ INSTANTIATE_TEST_SUITE_P( QuantumComputationTranslationTestCase{ "MultipleControlledIdentity", MQT_NAMED_BUILDER(qc::multipleControlledIdentity), - MQT_NAMED_BUILDER(mlir::qc::identity)}, + MQT_NAMED_BUILDER(mlir::qc::threeQubitsOneIdentity)}, QuantumComputationTranslationTestCase{"X", MQT_NAMED_BUILDER(qc::x), MQT_NAMED_BUILDER(mlir::qc::x)}, QuantumComputationTranslationTestCase{ diff --git a/mlir/unittests/programs/quantum_computation_programs.cpp b/mlir/unittests/programs/quantum_computation_programs.cpp index 41bebb3f92..d473a61bb4 100644 --- a/mlir/unittests/programs/quantum_computation_programs.cpp +++ b/mlir/unittests/programs/quantum_computation_programs.cpp @@ -117,9 +117,8 @@ void singleControlledIdentity(QuantumComputation& comp) { void multipleControlledIdentity(QuantumComputation& comp) { comp.addQubitRegister(3, "q"); - comp.mci({2, 1}, 0); - comp.addClassicalRegister(1, "meas"); - comp.measure(0, 0); + comp.mci({0, 1}, 2); + comp.measureAll(true, false); } void x(QuantumComputation& comp) { From 915052df02d44966c9b5becc261f0c0230840db4 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 9 Jul 2026 16:08:41 +0200 Subject: [PATCH 66/80] fix(mlir): :bug: fix failing test --- mlir/unittests/Compiler/test_compiler_pipeline.cpp | 4 ++-- mlir/unittests/programs/qc_programs.cpp | 6 ++++++ mlir/unittests/programs/qc_programs.h | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/mlir/unittests/Compiler/test_compiler_pipeline.cpp b/mlir/unittests/Compiler/test_compiler_pipeline.cpp index 37e6990b12..b3f780db87 100644 --- a/mlir/unittests/Compiler/test_compiler_pipeline.cpp +++ b/mlir/unittests/Compiler/test_compiler_pipeline.cpp @@ -373,8 +373,8 @@ INSTANTIATE_TEST_SUITE_P( CompilerPipelineTestCase{ "MultipleControlledIdentity", MQT_NAMED_BUILDER(qc::multipleControlledIdentity), nullptr, - MQT_NAMED_BUILDER(mlir::qc::alloc1QubitRegister), - MQT_NAMED_BUILDER(mlir::qir::alloc1QubitRegister)}, + MQT_NAMED_BUILDER(mlir::qc::alloc3QubitRegister), + MQT_NAMED_BUILDER(mlir::qir::alloc3QubitRegister)}, CompilerPipelineTestCase{"X", MQT_NAMED_BUILDER(qc::x), nullptr, MQT_NAMED_BUILDER(mlir::qc::x), MQT_NAMED_BUILDER(mlir::qir::x)}, diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index aed927b263..27cb8629f5 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -84,6 +84,12 @@ allocQubitRegister(QCProgramBuilder& b) { return measureAndReturn(b, {q[0], q[1]}); } +std::pair, SmallVector> +alloc3QubitRegister(QCProgramBuilder& b) { + auto q = b.allocQubitRegister(3); + return measureAndReturn(b, {q[0], q[1], q[2]}); +} + std::pair, SmallVector> allocMultipleQubitRegisters(QCProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); diff --git a/mlir/unittests/programs/qc_programs.h b/mlir/unittests/programs/qc_programs.h index a4c59088ca..5f13ec734d 100644 --- a/mlir/unittests/programs/qc_programs.h +++ b/mlir/unittests/programs/qc_programs.h @@ -41,6 +41,10 @@ alloc1QubitRegister(QCProgramBuilder& b); std::pair, SmallVector> allocQubitRegister(QCProgramBuilder& b); +/// Allocates a qubit register of size `3`. +std::pair, SmallVector> +alloc3QubitRegister(QCProgramBuilder& b); + /// Allocates two qubit registers of size `2` and `3`. std::pair, SmallVector> allocMultipleQubitRegisters(QCProgramBuilder& b); From 1dfe637730afa8473e096866e83f3c9230d70706 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 9 Jul 2026 16:15:47 +0200 Subject: [PATCH 67/80] fix(mlir): :rotating_light: fix linter issue --- mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp b/mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp index 965d9396bb..1c5c70005c 100644 --- a/mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp +++ b/mlir/lib/Conversion/QCToQIR/QIRCommon/QIRCommon.cpp @@ -15,6 +15,7 @@ #include "mlir/Dialect/QC/IR/QCOps.h" #include "mlir/Dialect/QIR/Utils/QIRUtils.h" +#include #include #include #include From 360d849bbdf5e4194d8376ea439965b2c113496e Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Thu, 9 Jul 2026 16:40:26 +0200 Subject: [PATCH 68/80] test(mlir): :white_check_mark: improve coverage --- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 421fb976f3..c0a1fbf51e 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -142,6 +142,9 @@ TEST_F(QCOTest, DirectIfBuilder) { extractOp.getOutTensor(), c0); qtensor::DeallocOp::create(builder, r2); + EXPECT_EQ(ifOp.getInputForOutput(ifOp.getResult(0)), measureOp.getQubitOut()); + EXPECT_EQ(ifOp.getOutputForInput(measureOp.getQubitOut()), ifOp.getResult(0)); + auto directBuilder = builder.finalize({measureOp.getResult(), finalMeasureOp.getResult()}); ASSERT_TRUE(directBuilder); From 3cc75220cf833f68649df0333d452c3b5efbf3ff Mon Sep 17 00:00:00 2001 From: burgholzer Date: Thu, 9 Jul 2026 23:02:13 +0200 Subject: [PATCH 69/80] :rewind: Revert change to noxfile that is no longer necessary --- noxfile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 7c2269fee9..a80ca6ba80 100755 --- a/noxfile.py +++ b/noxfile.py @@ -218,7 +218,6 @@ def stubs(session: nox.Session) -> None: session.run( "uv", "sync", - "--no-editable", "--no-dev", "--group", "build", From a33d5d3abdb870e01805d59c883c82b86485f5c6 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Thu, 9 Jul 2026 23:31:38 +0200 Subject: [PATCH 70/80] :fire: Use builtin functionality for mapping between IfOp operands and results Signed-off-by: burgholzer --- mlir/include/mlir/Dialect/QCO/IR/QCOOps.td | 3 --- .../Dialect/QCO/IR/QubitManagement/SinkOp.cpp | 4 +++- mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp | 21 ------------------- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 3 --- 4 files changed, 3 insertions(+), 28 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td b/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td index 8b0f771812..a3ee7b405c 100644 --- a/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td +++ b/mlir/include/mlir/Dialect/QCO/IR/QCOOps.td @@ -1308,9 +1308,6 @@ def IfOp /// Return the yield of the else-block. YieldOp elseYield(); - Value getInputForOutput(Value output); - Value getOutputForInput(Value input); - /// Return the result that corresponds to the given qubit operand, /// or "empty" OpResult on failure. OpResult getTiedResult(OpOperand* qubit); diff --git a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp index 777eb1a5aa..d7e4241635 100644 --- a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp @@ -91,7 +91,9 @@ struct DeadGateElimination final : public OpRewritePattern { return newValue; }) .Case([&](auto ifOp) { - auto newValue = ifOp.getInputForOutput(currentValue); + auto* tiedQubit = + ifOp.getTiedQubit(cast(currentValue)); + auto newValue = tiedQubit->get(); rewriter.replaceOp(ifOp, ifOp.getQubits()); return newValue; }) diff --git a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp index 4aa5a33dfe..1cd45a58f6 100644 --- a/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/SCF/IfOp.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -29,7 +28,6 @@ #include #include -#include using namespace mlir; using namespace mlir::qco; @@ -283,25 +281,6 @@ LogicalResult IfOp::verify() { return success(); } -Value IfOp::getInputForOutput(Value output) { - auto resultCount = getResults().size(); - for (size_t i = 0; i < resultCount; ++i) { - if (output == getResult(i)) { - return getQubits()[i]; - } - } - llvm::reportFatalUsageError("Given qubit is not an output of the operation"); -} -Value IfOp::getOutputForInput(Value input) { - auto resultCount = getResults().size(); - for (size_t i = 0; i < resultCount; ++i) { - if (input == getQubits()[i]) { - return getResult(i); - } - } - llvm::reportFatalUsageError("Given qubit is not an input of the operation"); -} - OpResult IfOp::getTiedResult(OpOperand* qubit) { if (qubit->getOwner() != getOperation()) { return {}; diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index c0a1fbf51e..421fb976f3 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -142,9 +142,6 @@ TEST_F(QCOTest, DirectIfBuilder) { extractOp.getOutTensor(), c0); qtensor::DeallocOp::create(builder, r2); - EXPECT_EQ(ifOp.getInputForOutput(ifOp.getResult(0)), measureOp.getQubitOut()); - EXPECT_EQ(ifOp.getOutputForInput(measureOp.getQubitOut()), ifOp.getResult(0)); - auto directBuilder = builder.finalize({measureOp.getResult(), finalMeasureOp.getResult()}); ASSERT_TRUE(directBuilder); From a179e8996b40ad3ae1808f76fd74321d1e00ae3b Mon Sep 17 00:00:00 2001 From: burgholzer Date: Thu, 9 Jul 2026 23:55:20 +0200 Subject: [PATCH 71/80] :truck: Move entry-point finder to common utils module Avoids accessing QCO code from QC --- mlir/include/mlir/Dialect/QCO/IR/QCODialect.h | 34 ------------------- mlir/include/mlir/Dialect/Utils/Utils.h | 34 +++++++++++++++++++ .../Dialect/QC/Builder/QCProgramBuilder.cpp | 3 +- .../QCO/Transforms/Mapping/Mapping.cpp | 1 + .../QCO/Transforms/Mapping/test_mapping.cpp | 1 + 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/mlir/include/mlir/Dialect/QCO/IR/QCODialect.h b/mlir/include/mlir/Dialect/QCO/IR/QCODialect.h index 1b08a1715a..7c0ea4fab2 100644 --- a/mlir/include/mlir/Dialect/QCO/IR/QCODialect.h +++ b/mlir/include/mlir/Dialect/QCO/IR/QCODialect.h @@ -13,9 +13,6 @@ #include "mlir/Dialect/Utils/Utils.h" #include -#include -#include -#include #include #include #include @@ -142,35 +139,4 @@ template class TargetAndParameterArityTrait { }; }; -/** - * @brief Find the entry point function with entry_point attribute - * - * @details - * Searches for the function marked with the "entry_point" attribute in - * the passthrough attributes. If multiple functions are marked, returns the - * first one encountered. - * - * @param op The module operation to search in. - * @returns the entry point function, or nullptr if not found. - */ -inline func::FuncOp getEntryPoint(ModuleOp op) { - static constexpr StringRef PASSTHROUGH_LABEL = "passthrough"; - static constexpr StringRef ENTRY_POINT_LABEL = "entry_point"; - - const auto isEntry = [](Attribute attr) { - const auto strAttr = dyn_cast(attr); - return strAttr && strAttr.getValue() == ENTRY_POINT_LABEL; - }; - - for (auto func : op.getOps()) { - if (const auto passthrough = - func->getAttrOfType(PASSTHROUGH_LABEL); - passthrough && llvm::any_of(passthrough, isEntry)) { - return func; - } - } - - return nullptr; -} - } // namespace mlir::qco diff --git a/mlir/include/mlir/Dialect/Utils/Utils.h b/mlir/include/mlir/Dialect/Utils/Utils.h index 4135ca1769..970ec6d90c 100644 --- a/mlir/include/mlir/Dialect/Utils/Utils.h +++ b/mlir/include/mlir/Dialect/Utils/Utils.h @@ -13,8 +13,11 @@ #include #include #include +#include +#include #include #include +#include #include #include #include @@ -268,4 +271,35 @@ inline void inlineModifierBody(Operation* op, Block& body, rewriter.replaceOp(op, results); } +/** + * @brief Find the entry point function with the entry_point attribute + * + * @details + * Searches for the function marked with the "entry_point" attribute in + * the passthrough attributes. If multiple functions are marked, returns the + * first one encountered. + * + * @param op The module operation to search in. + * @returns the entry point function, or nullptr if not found. + */ +inline func::FuncOp getEntryPoint(ModuleOp op) { + static constexpr StringRef PASSTHROUGH_LABEL = "passthrough"; + static constexpr StringRef ENTRY_POINT_LABEL = "entry_point"; + + const auto isEntry = [](Attribute attr) { + const auto strAttr = dyn_cast(attr); + return strAttr && strAttr.getValue() == ENTRY_POINT_LABEL; + }; + + for (auto func : op.getOps()) { + if (const auto passthrough = + func->getAttrOfType(PASSTHROUGH_LABEL); + passthrough && llvm::any_of(passthrough, isEntry)) { + return func; + } + } + + return nullptr; +} + } // namespace mlir::utils diff --git a/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp b/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp index 27c137e5ed..693222d814 100644 --- a/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp +++ b/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp @@ -31,7 +31,6 @@ #include #include -#include #include #include #include @@ -70,7 +69,7 @@ void QCProgramBuilder::initialize(TypeRange returnTypes) { } void QCProgramBuilder::retype(TypeRange returnTypes) { - auto mainFunc = qco::getEntryPoint(mlir::cast(module)); + auto mainFunc = getEntryPoint(mlir::cast(module)); if (!mainFunc) { llvm::reportFatalUsageError("Main function not found for retyping"); } diff --git a/mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp b/mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp index dd0ab588ff..7ccd1caac0 100644 --- a/mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp +++ b/mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp @@ -62,6 +62,7 @@ namespace mlir::qco { using namespace mlir::qtensor; +using namespace mlir::utils; #define GEN_PASS_DEF_MAPPINGPASS #include "mlir/Dialect/QCO/Transforms/Passes.h.inc" diff --git a/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp b/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp index 98ea6538d9..05c2bf2f74 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp @@ -41,6 +41,7 @@ using namespace mlir; using namespace mlir::qco; +using namespace mlir::utils; namespace { struct Device { From 4eba897e1192f2f664bd547ba22ddd85f8893ca6 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Fri, 10 Jul 2026 01:15:44 +0200 Subject: [PATCH 72/80] :children_crossing: Automatically deduce return types Signed-off-by: burgholzer --- .../Dialect/QC/Builder/QCProgramBuilder.h | 12 +- .../Dialect/QCO/Builder/QCOProgramBuilder.h | 12 +- .../Dialect/QIR/Builder/QIRProgramBuilder.h | 12 +- .../Dialect/QC/Builder/QCProgramBuilder.cpp | 7 +- .../Dialect/QCO/Builder/QCOProgramBuilder.cpp | 7 +- .../Dialect/QIR/Builder/QIRProgramBuilder.cpp | 7 +- .../Compiler/test_compiler_pipeline.cpp | 319 ++-- .../JeffRoundTrip/test_jeff_round_trip.cpp | 9 +- .../Conversion/QCOToQC/test_qco_to_qc.cpp | 9 +- .../Conversion/QCToQCO/test_qc_to_qco.cpp | 9 +- .../test_qc_to_qir_adaptive.cpp | 8 +- .../QCToQIRBase/test_qc_to_qir_base.cpp | 8 +- mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp | 9 +- .../QC/Translation/test_qasm3_translation.cpp | 38 +- .../test_quantum_computation_translation.cpp | 6 +- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 9 +- .../Dialect/QCO/IR/test_qco_ir_matrix.cpp | 9 +- .../test_euler_decomposition.cpp | 128 +- mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp | 7 +- .../Dialect/QTensor/IR/test_qtensor_ir.cpp | 20 +- mlir/unittests/TestCaseUtils.h | 9 + mlir/unittests/programs/qc_programs.cpp | 1318 ++++++------- mlir/unittests/programs/qc_programs.h | 778 +++----- mlir/unittests/programs/qco_programs.cpp | 1641 +++++++---------- mlir/unittests/programs/qco_programs.h | 1020 ++++------ mlir/unittests/programs/qir_programs.cpp | 1154 +++++------- mlir/unittests/programs/qir_programs.h | 302 ++- 27 files changed, 2727 insertions(+), 4140 deletions(-) diff --git a/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h b/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h index bc51da41ad..cbcee93fd4 100644 --- a/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h @@ -1163,15 +1163,15 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder { OwningOpRef finalize(); /** - * @brief Finalize the program with a given exit code and return the + * @brief Finalize the program with the given return values and return the * constructed module * @param returnValues Values representing the return values of the main * function. * * @details * Automatically deallocates all remaining valid qubits and tensors of qubits, - * adds a return statement with a given exit code, - * and transfers ownership of the module to the caller. The builder should not + * adds a return statement with the given return values, and + * transfers ownership of the module to the caller. The builder should not * be used after calling this method. * * The return values must have the types indicated by the function signature @@ -1188,14 +1188,12 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder { * @param buildFunc A function that takes a reference to a QCProgramBuilder * and uses it to build the desired quantum program. The builder will be * properly initialized before calling this function, and the resulting module - * will be finalized using the returned ValueRange after this function - * completes. + * will be finalized using the returned Values after this function completes. * @return The module containing the quantum program built by buildFunc. */ static OwningOpRef build(MLIRContext* context, - const function_ref, SmallVector>( - QCProgramBuilder&)>& buildFunc); + const function_ref(QCProgramBuilder&)>& buildFunc); private: enum class AllocationMode : uint8_t { Unset, Static, Dynamic }; diff --git a/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h b/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h index 0506ee7224..a9ba23b0da 100644 --- a/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h @@ -1471,15 +1471,15 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { OwningOpRef finalize(); /** - * @brief Finalize the program with a given exit code and return the + * @brief Finalize the program with the given return values and return the * constructed module * @param returnValues Values representing the return values of the main * function. * * @details * Automatically deallocates all remaining valid qubits and tensors of qubits, - * adds a return statement with a given exit code, - * and transfers ownership of the module to the caller. The builder should not + * adds a return statement with the given return values, and + * transfers ownership of the module to the caller. The builder should not * be used after calling this method. * * The return values must have the types indicated by the function signature @@ -1496,14 +1496,12 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { * @param buildFunc A function that takes a reference to a QCOProgramBuilder * and uses it to build the desired quantum program. The builder will be * properly initialized before calling this function, and the resulting module - * will be finalized using the returned ValueRange after this function - * completes. + * will be finalized using the returned Values after this function completes. * @return The module containing the quantum program built by buildFunc. */ static OwningOpRef build(MLIRContext* context, - const function_ref, SmallVector>( - QCOProgramBuilder&)>& buildFunc); + const function_ref(QCOProgramBuilder&)>& buildFunc); private: enum class AllocationMode : uint8_t { Unset, Static, Dynamic }; diff --git a/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h b/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h index 7bcf5aa0f3..3b0d025e82 100644 --- a/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QIR/Builder/QIRProgramBuilder.h @@ -1098,14 +1098,14 @@ class QIRProgramBuilder final : public ImplicitLocOpBuilder { OwningOpRef finalize(); /** - * @brief Finalize the program with a given exit code and return the + * @brief Finalize the program with the given return value and return the * constructed module - * @param returnValue The value representing the exit code to return + * @param returnValue The return value of the main function * * @details * Automatically deallocates all remaining valid qubits and tensors of qubits, - * adds a return statement with a given exit code, - * and transfers ownership of the module to the caller. The builder should not + * adds a return statement with the given return value, and + * transfers ownership of the module to the caller. The builder should not * be used after calling this method. * * The return value must have the type indicated by the function signature @@ -1123,12 +1123,12 @@ class QIRProgramBuilder final : public ImplicitLocOpBuilder { * and uses it to build the desired quantum program. The builder will be * properly initialized before calling this function, and the resulting module * will be finalized and returned after this function completes. + * @param profile The profile to use for the program. Defaults to Adaptive. * @return The module containing the quantum program built by buildFunc. */ static OwningOpRef build(MLIRContext* context, - const function_ref< - std::pair(QIRProgramBuilder&)>& buildFunc, + const function_ref& buildFunc, Profile profile = Profile::Adaptive); private: diff --git a/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp b/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp index 693222d814..0b6b93b1cd 100644 --- a/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp +++ b/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp @@ -714,12 +714,11 @@ OwningOpRef QCProgramBuilder::finalize(ValueRange returnValues) { OwningOpRef QCProgramBuilder::build( MLIRContext* context, - const function_ref, SmallVector>( - QCProgramBuilder&)>& buildFunc) { + const function_ref(QCProgramBuilder&)>& buildFunc) { QCProgramBuilder builder(context); builder.initialize(); - auto [result, resultTypes] = buildFunc(builder); - builder.retype(resultTypes); + auto result = buildFunc(builder); + builder.retype(ValueRange(result).getTypes()); return builder.finalize(result); } diff --git a/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp b/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp index 90f80536b8..f3feb41a37 100644 --- a/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp +++ b/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp @@ -1225,12 +1225,11 @@ OwningOpRef QCOProgramBuilder::finalize(ValueRange returnValues) { OwningOpRef QCOProgramBuilder::build( MLIRContext* context, - const function_ref, SmallVector>( - QCOProgramBuilder&)>& buildFunc) { + const function_ref(QCOProgramBuilder&)>& buildFunc) { QCOProgramBuilder builder(context); builder.initialize(); - auto [result, resultTypes] = buildFunc(builder); - builder.retype(resultTypes); + auto result = buildFunc(builder); + builder.retype(ValueRange(result).getTypes()); return builder.finalize(result); } diff --git a/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp b/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp index 0d4a65341b..0004d0ebfb 100644 --- a/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp +++ b/mlir/lib/Dialect/QIR/Builder/QIRProgramBuilder.cpp @@ -1077,13 +1077,12 @@ OwningOpRef QIRProgramBuilder::finalize(Value returnValue) { OwningOpRef QIRProgramBuilder::build( MLIRContext* context, - const function_ref(QIRProgramBuilder&)>& buildFunc, - Profile profile) { + const function_ref& buildFunc, Profile profile) { QIRProgramBuilder builder(context); builder.profile = profile; builder.initialize(); - auto [result, resultType] = buildFunc(builder); - builder.retype(resultType); + auto result = buildFunc(builder); + builder.retype(result.getType()); return builder.finalize(result); } diff --git a/mlir/unittests/Compiler/test_compiler_pipeline.cpp b/mlir/unittests/Compiler/test_compiler_pipeline.cpp index b3f780db87..8d59129b14 100644 --- a/mlir/unittests/Compiler/test_compiler_pipeline.cpp +++ b/mlir/unittests/Compiler/test_compiler_pipeline.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -48,11 +47,13 @@ namespace mqt::test::compiler { -using QCProgramBuilderFn = NamedBuilder< - mlir::qc::QCProgramBuilder, - std::pair, mlir::SmallVector>>; -using QIRProgramBuilderFn = NamedBuilder>; +using namespace mlir; +using namespace mlir::qc; +using namespace mlir::qco; +using namespace mlir::qir; + +using QCProgramBuilderFn = MultiResultBuilder; +using QIRProgramBuilderFn = SingleResultBuilder; using QuantumComputationBuilderFn = NamedBuilder<::qc::QuantumComputation>; namespace { @@ -89,46 +90,44 @@ std::ostream& operator<<(std::ostream& os, class CompilerPipelineTest : public testing::TestWithParam { protected: - std::unique_ptr context; + std::unique_ptr context; void SetUp() override { - mlir::DialectRegistry registry; - registry.insert(); - context = std::make_unique(); + DialectRegistry registry; + registry + .insert(); + context = std::make_unique(); context->appendDialectRegistry(registry); context->loadAllAvailableDialects(); } - [[nodiscard]] mlir::OwningOpRef + [[nodiscard]] OwningOpRef buildQCReference(const QCProgramBuilderFn builder) const { - auto module = mlir::qc::QCProgramBuilder::build(context.get(), builder.fn); + auto module = QCProgramBuilder::build(context.get(), builder.fn); EXPECT_TRUE(runQCCleanupPipeline(module.get()).succeeded()); return module; } - [[nodiscard]] mlir::OwningOpRef + [[nodiscard]] OwningOpRef buildQIRReference(const QIRProgramBuilderFn builder) const { - auto module = mlir::qir::QIRProgramBuilder::build( - context.get(), builder.fn, - mlir::qir::QIRProgramBuilder::Profile::Adaptive); + auto module = QIRProgramBuilder::build( + context.get(), builder.fn, QIRProgramBuilder::Profile::Adaptive); EXPECT_TRUE(runQIRCleanupPipeline(module.get(), true).succeeded()); return module; } - [[nodiscard]] mlir::OwningOpRef + [[nodiscard]] OwningOpRef parseRecordedModule(const std::string& ir) const { - return mlir::parseSourceString(ir, context.get()); + return parseSourceString(ir, context.get()); } - static void runPipeline(const mlir::ModuleOp module, const bool convertToQIR, + static void runPipeline(const ModuleOp module, const bool convertToQIR, const bool disableMergeSingleQubitRotationGates, const bool enableHadamardLifting, - mlir::CompilationRecord& record) { - mlir::QuantumCompilerConfig config; + CompilationRecord& record) { + QuantumCompilerConfig config; config.convertToQIRAdaptive = convertToQIR; config.disableMergeSingleQubitRotationGates = disableMergeSingleQubitRotationGates; @@ -136,16 +135,16 @@ class CompilerPipelineTest config.recordIntermediates = true; config.printIRAfterAllStages = true; - mlir::QuantumCompilerPipeline pipeline(config); + QuantumCompilerPipeline pipeline(config); ASSERT_TRUE(pipeline.runPipeline(module, &record).succeeded()); } void expectEquivalent(const std::string& stage, const std::string& ir, - const mlir::ModuleOp expected) const { + const ModuleOp expected) const { auto actual = parseRecordedModule(ir); ASSERT_TRUE(actual) << stage << " failed to parse"; - EXPECT_TRUE(mlir::verify(*actual).succeeded()); - EXPECT_TRUE(mlir::verify(expected).succeeded()); + EXPECT_TRUE(verify(*actual).succeeded()); + EXPECT_TRUE(verify(expected).succeeded()); EXPECT_TRUE(areModulesEquivalentWithPermutations(actual.get(), expected)); } }; @@ -157,25 +156,25 @@ TEST_P(CompilerPipelineTest, EndToEndPipeline) { const auto name = " (" + testCase.name + ")"; DeferredPrinter printer; - mlir::OwningOpRef module; + OwningOpRef module; if (testCase.startFromQuantumComputation) { ASSERT_TRUE(testCase.quantumComputationBuilder); ::qc::QuantumComputation comp; testCase.quantumComputationBuilder.fn(comp); - module = mlir::translateQuantumComputationToQC(context.get(), comp); + module = translateQuantumComputationToQC(context.get(), comp); ASSERT_TRUE(module); printer.record(module.get(), "QC Import" + name); } else { ASSERT_TRUE(testCase.qcProgramBuilder); - module = mlir::qc::QCProgramBuilder::build(context.get(), - testCase.qcProgramBuilder.fn); + module = + QCProgramBuilder::build(context.get(), testCase.qcProgramBuilder.fn); ASSERT_TRUE(module); printer.record(module.get(), "QC Input" + name); } - EXPECT_TRUE(mlir::verify(*module).succeeded()); + EXPECT_TRUE(verify(*module).succeeded()); - mlir::CompilationRecord record; + CompilationRecord record; runPipeline(module.get(), testCase.convertToQIR, false, false, record); ASSERT_TRUE(testCase.qcReferenceBuilder); @@ -214,20 +213,16 @@ TEST_P(CompilerPipelineTest, EndToEndPipeline) { * Correctness of the pass is tested in a dedicated test. */ TEST_F(CompilerPipelineTest, RotationGateMergingPass) { - auto module = mlir::qc::QCProgramBuilder::build( - context.get(), - [&](mlir::qc::QCProgramBuilder& b) - -> std::pair, - mlir::SmallVector> { + auto module = QCProgramBuilder::build( + context.get(), [&](QCProgramBuilder& b) -> SmallVector { auto q = b.allocQubit(); b.rz(1.0, q); b.rx(1.0, q); - auto m = b.measure(q); - return {{m}, {b.getI1Type()}}; + return {b.measure(q)}; }); ASSERT_TRUE(module); - mlir::CompilationRecord record; + CompilationRecord record; runPipeline(module.get(), false, false, false, record); // The outputs must differ, proving the pass ran and transformed the IR @@ -242,20 +237,16 @@ TEST_F(CompilerPipelineTest, RotationGateMergingPass) { * Correctness of the pass is tested in a dedicated test. */ TEST_F(CompilerPipelineTest, HadamardLiftingPass) { - auto module = mlir::qc::QCProgramBuilder::build( - context.get(), - [&](mlir::qc::QCProgramBuilder& b) - -> std::pair, - mlir::SmallVector> { + auto module = QCProgramBuilder::build( + context.get(), [&](QCProgramBuilder& b) -> SmallVector { auto q = b.allocQubit(); b.x(q); b.h(q); - auto m = b.measure(q); - return {{m}, {b.getI1Type()}}; + return {b.measure(q)}; }); ASSERT_TRUE(module); - mlir::CompilationRecord record; + CompilationRecord record; runPipeline(module.get(), false, true, true, record); // The outputs must differ, proving the pass ran and transformed the IR @@ -295,41 +286,42 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(mlir::qc::staticQubitsWithInv), MQT_NAMED_BUILDER(mlir::qir::staticQubitsWithInv), false}, CompilerPipelineTestCase{ - "AllocQubit", MQT_NAMED_BUILDER(qc::allocQubit), nullptr, + "AllocQubit", MQT_NAMED_BUILDER(::qc::allocQubit), nullptr, MQT_NAMED_BUILDER(mlir::qc::alloc1QubitRegister), MQT_NAMED_BUILDER(mlir::qir::alloc1QubitRegister)}, CompilerPipelineTestCase{ - "AllocQubitRegister", MQT_NAMED_BUILDER(qc::allocQubitRegister), + "AllocQubitRegister", MQT_NAMED_BUILDER(::qc::allocQubitRegister), nullptr, MQT_NAMED_BUILDER(mlir::qc::allocQubitRegister), MQT_NAMED_BUILDER(mlir::qir::allocQubitRegister)}, CompilerPipelineTestCase{ "AllocMultipleQubitRegisters", - MQT_NAMED_BUILDER(qc::allocMultipleQubitRegisters), nullptr, + MQT_NAMED_BUILDER(::qc::allocMultipleQubitRegisters), nullptr, MQT_NAMED_BUILDER(mlir::qc::allocMultipleQubitRegisters), MQT_NAMED_BUILDER(mlir::qir::allocMultipleQubitRegisters)}, CompilerPipelineTestCase{ - "AllocLargeRegister", MQT_NAMED_BUILDER(qc::allocLargeRegister), + "AllocLargeRegister", MQT_NAMED_BUILDER(::qc::allocLargeRegister), nullptr, MQT_NAMED_BUILDER(mlir::qc::allocLargeRegister), MQT_NAMED_BUILDER(mlir::qir::allocQubitRegister)}, CompilerPipelineTestCase{ "SingleMeasurementToSingleBit", - MQT_NAMED_BUILDER(qc::singleMeasurementToSingleBit), nullptr, + MQT_NAMED_BUILDER(::qc::singleMeasurementToSingleBit), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleMeasurementToSingleBit), MQT_NAMED_BUILDER(mlir::qir::singleMeasurementToSingleBit)}, CompilerPipelineTestCase{ "RepeatedMeasurementToSameBit", - MQT_NAMED_BUILDER(qc::repeatedMeasurementToSameBit), nullptr, + MQT_NAMED_BUILDER(::qc::repeatedMeasurementToSameBit), nullptr, MQT_NAMED_BUILDER(mlir::qc::repeatedMeasurementToSameBit), MQT_NAMED_BUILDER(mlir::qir::repeatedMeasurementToSameBit)}, CompilerPipelineTestCase{ "RepeatedMeasurementToDifferentBits", - MQT_NAMED_BUILDER(qc::repeatedMeasurementToDifferentBits), nullptr, + MQT_NAMED_BUILDER(::qc::repeatedMeasurementToDifferentBits), + nullptr, MQT_NAMED_BUILDER(mlir::qc::repeatedMeasurementToDifferentBits), MQT_NAMED_BUILDER( mlir::qir::repeatedMeasurementToDifferentBits)}, CompilerPipelineTestCase{ "MultipleClassicalRegistersAndMeasurements", - MQT_NAMED_BUILDER(qc::multipleClassicalRegistersAndMeasurements), + MQT_NAMED_BUILDER(::qc::multipleClassicalRegistersAndMeasurements), nullptr, MQT_NAMED_BUILDER( mlir::qc::multipleClassicalRegistersAndMeasurements), @@ -343,80 +335,80 @@ INSTANTIATE_TEST_SUITE_P( false}, CompilerPipelineTestCase{ "ResetQubitAfterSingleOp", - MQT_NAMED_BUILDER(qc::resetQubitAfterSingleOp), nullptr, + MQT_NAMED_BUILDER(::qc::resetQubitAfterSingleOp), nullptr, MQT_NAMED_BUILDER(mlir::qc::resetQubitAfterSingleOp), MQT_NAMED_BUILDER(mlir::qir::resetQubitAfterSingleOp)}, CompilerPipelineTestCase{ "ResetMultipleQubitsAfterSingleOp", - MQT_NAMED_BUILDER(qc::resetMultipleQubitsAfterSingleOp), nullptr, + MQT_NAMED_BUILDER(::qc::resetMultipleQubitsAfterSingleOp), nullptr, MQT_NAMED_BUILDER(mlir::qc::resetMultipleQubitsAfterSingleOp), MQT_NAMED_BUILDER( mlir::qir::resetMultipleQubitsAfterSingleOp)}, CompilerPipelineTestCase{ "RepeatedResetAfterSingleOp", - MQT_NAMED_BUILDER(qc::repeatedResetAfterSingleOp), nullptr, + MQT_NAMED_BUILDER(::qc::repeatedResetAfterSingleOp), nullptr, MQT_NAMED_BUILDER(mlir::qc::resetQubitAfterSingleOp), MQT_NAMED_BUILDER(mlir::qir::resetQubitAfterSingleOp)}, CompilerPipelineTestCase{ - "GlobalPhase", MQT_NAMED_BUILDER(qc::globalPhase), nullptr, + "GlobalPhase", MQT_NAMED_BUILDER(::qc::globalPhase), nullptr, MQT_NAMED_BUILDER(mlir::qc::globalPhase), MQT_NAMED_BUILDER(mlir::qir::globalPhase)}, CompilerPipelineTestCase{ - "Identity", MQT_NAMED_BUILDER(qc::identity), nullptr, + "Identity", MQT_NAMED_BUILDER(::qc::identity), nullptr, MQT_NAMED_BUILDER(mlir::qc::alloc1QubitRegister), MQT_NAMED_BUILDER(mlir::qir::alloc1QubitRegister)}, CompilerPipelineTestCase{ "SingleControlledIdentity", - MQT_NAMED_BUILDER(qc::singleControlledIdentity), nullptr, + MQT_NAMED_BUILDER(::qc::singleControlledIdentity), nullptr, MQT_NAMED_BUILDER(mlir::qc::allocQubitRegister), MQT_NAMED_BUILDER(mlir::qir::allocQubitRegister)}, CompilerPipelineTestCase{ "MultipleControlledIdentity", - MQT_NAMED_BUILDER(qc::multipleControlledIdentity), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledIdentity), nullptr, MQT_NAMED_BUILDER(mlir::qc::alloc3QubitRegister), MQT_NAMED_BUILDER(mlir::qir::alloc3QubitRegister)}, - CompilerPipelineTestCase{"X", MQT_NAMED_BUILDER(qc::x), nullptr, + CompilerPipelineTestCase{"X", MQT_NAMED_BUILDER(::qc::x), nullptr, MQT_NAMED_BUILDER(mlir::qc::x), MQT_NAMED_BUILDER(mlir::qir::x)}, CompilerPipelineTestCase{ - "SingleControlledX", MQT_NAMED_BUILDER(qc::singleControlledX), + "SingleControlledX", MQT_NAMED_BUILDER(::qc::singleControlledX), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledX), MQT_NAMED_BUILDER(mlir::qir::singleControlledX)}, CompilerPipelineTestCase{ - "MultipleControlledX", MQT_NAMED_BUILDER(qc::multipleControlledX), + "MultipleControlledX", MQT_NAMED_BUILDER(::qc::multipleControlledX), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledX), MQT_NAMED_BUILDER(mlir::qir::multipleControlledX)}, - CompilerPipelineTestCase{"Y", MQT_NAMED_BUILDER(qc::y), nullptr, + CompilerPipelineTestCase{"Y", MQT_NAMED_BUILDER(::qc::y), nullptr, MQT_NAMED_BUILDER(mlir::qc::y), MQT_NAMED_BUILDER(mlir::qir::y)}, CompilerPipelineTestCase{ - "SingleControlledY", MQT_NAMED_BUILDER(qc::singleControlledY), + "SingleControlledY", MQT_NAMED_BUILDER(::qc::singleControlledY), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledY), MQT_NAMED_BUILDER(mlir::qir::singleControlledY)}, CompilerPipelineTestCase{ - "MultipleControlledY", MQT_NAMED_BUILDER(qc::multipleControlledY), + "MultipleControlledY", MQT_NAMED_BUILDER(::qc::multipleControlledY), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledY), MQT_NAMED_BUILDER(mlir::qir::multipleControlledY)}, - CompilerPipelineTestCase{"Z", MQT_NAMED_BUILDER(qc::z), nullptr, + CompilerPipelineTestCase{"Z", MQT_NAMED_BUILDER(::qc::z), nullptr, MQT_NAMED_BUILDER(mlir::qc::z), MQT_NAMED_BUILDER(mlir::qir::z)}, CompilerPipelineTestCase{ - "SingleControlledZ", MQT_NAMED_BUILDER(qc::singleControlledZ), + "SingleControlledZ", MQT_NAMED_BUILDER(::qc::singleControlledZ), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledZ), MQT_NAMED_BUILDER(mlir::qir::singleControlledZ)}, CompilerPipelineTestCase{ - "MultipleControlledZ", MQT_NAMED_BUILDER(qc::multipleControlledZ), + "MultipleControlledZ", MQT_NAMED_BUILDER(::qc::multipleControlledZ), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledZ), MQT_NAMED_BUILDER(mlir::qir::multipleControlledZ)}, - CompilerPipelineTestCase{"H", MQT_NAMED_BUILDER(qc::h), nullptr, + CompilerPipelineTestCase{"H", MQT_NAMED_BUILDER(::qc::h), nullptr, MQT_NAMED_BUILDER(mlir::qc::h), MQT_NAMED_BUILDER(mlir::qir::h)}, CompilerPipelineTestCase{ - "SingleControlledH", MQT_NAMED_BUILDER(qc::singleControlledH), + "SingleControlledH", MQT_NAMED_BUILDER(::qc::singleControlledH), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledH), MQT_NAMED_BUILDER(mlir::qir::singleControlledH)}, CompilerPipelineTestCase{ - "MultipleControlledH", MQT_NAMED_BUILDER(qc::multipleControlledH), + "MultipleControlledH", MQT_NAMED_BUILDER(::qc::multipleControlledH), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledH), MQT_NAMED_BUILDER(mlir::qir::multipleControlledH)}, CompilerPipelineTestCase{ @@ -424,292 +416,299 @@ INSTANTIATE_TEST_SUITE_P( MQT_NAMED_BUILDER(mlir::qc::hWithoutRegister), MQT_NAMED_BUILDER(mlir::qc::hWithoutRegister), MQT_NAMED_BUILDER(mlir::qir::hWithoutRegister), false}, - CompilerPipelineTestCase{"S", MQT_NAMED_BUILDER(qc::s), nullptr, + CompilerPipelineTestCase{"S", MQT_NAMED_BUILDER(::qc::s), nullptr, MQT_NAMED_BUILDER(mlir::qc::s), MQT_NAMED_BUILDER(mlir::qir::s)}, CompilerPipelineTestCase{ - "SingleControlledS", MQT_NAMED_BUILDER(qc::singleControlledS), + "SingleControlledS", MQT_NAMED_BUILDER(::qc::singleControlledS), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledS), MQT_NAMED_BUILDER(mlir::qir::singleControlledS)}, CompilerPipelineTestCase{ - "MultipleControlledS", MQT_NAMED_BUILDER(qc::multipleControlledS), + "MultipleControlledS", MQT_NAMED_BUILDER(::qc::multipleControlledS), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledS), MQT_NAMED_BUILDER(mlir::qir::multipleControlledS)}, - CompilerPipelineTestCase{"Sdg", MQT_NAMED_BUILDER(qc::sdg), nullptr, + CompilerPipelineTestCase{"Sdg", MQT_NAMED_BUILDER(::qc::sdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::sdg), MQT_NAMED_BUILDER(mlir::qir::sdg)}, CompilerPipelineTestCase{ - "SingleControlledSdg", MQT_NAMED_BUILDER(qc::singleControlledSdg), + "SingleControlledSdg", MQT_NAMED_BUILDER(::qc::singleControlledSdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledSdg), MQT_NAMED_BUILDER(mlir::qir::singleControlledSdg)}, CompilerPipelineTestCase{ "MultipleControlledSdg", - MQT_NAMED_BUILDER(qc::multipleControlledSdg), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledSdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledSdg), MQT_NAMED_BUILDER(mlir::qir::multipleControlledSdg)}, - CompilerPipelineTestCase{"T", MQT_NAMED_BUILDER(qc::t_), nullptr, + CompilerPipelineTestCase{"T", MQT_NAMED_BUILDER(::qc::t_), nullptr, MQT_NAMED_BUILDER(mlir::qc::t_), MQT_NAMED_BUILDER(mlir::qir::t_)}, CompilerPipelineTestCase{ - "SingleControlledT", MQT_NAMED_BUILDER(qc::singleControlledT), + "SingleControlledT", MQT_NAMED_BUILDER(::qc::singleControlledT), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledT), MQT_NAMED_BUILDER(mlir::qir::singleControlledT)}, CompilerPipelineTestCase{ - "MultipleControlledT", MQT_NAMED_BUILDER(qc::multipleControlledT), + "MultipleControlledT", MQT_NAMED_BUILDER(::qc::multipleControlledT), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledT), MQT_NAMED_BUILDER(mlir::qir::multipleControlledT)}, - CompilerPipelineTestCase{"Tdg", MQT_NAMED_BUILDER(qc::tdg), nullptr, + CompilerPipelineTestCase{"Tdg", MQT_NAMED_BUILDER(::qc::tdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::tdg), MQT_NAMED_BUILDER(mlir::qir::tdg)}, CompilerPipelineTestCase{ - "SingleControlledTdg", MQT_NAMED_BUILDER(qc::singleControlledTdg), + "SingleControlledTdg", MQT_NAMED_BUILDER(::qc::singleControlledTdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledTdg), MQT_NAMED_BUILDER(mlir::qir::singleControlledTdg)}, CompilerPipelineTestCase{ "MultipleControlledTdg", - MQT_NAMED_BUILDER(qc::multipleControlledTdg), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledTdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledTdg), MQT_NAMED_BUILDER(mlir::qir::multipleControlledTdg)}, - CompilerPipelineTestCase{"SX", MQT_NAMED_BUILDER(qc::sx), nullptr, + CompilerPipelineTestCase{"SX", MQT_NAMED_BUILDER(::qc::sx), nullptr, MQT_NAMED_BUILDER(mlir::qc::sx), MQT_NAMED_BUILDER(mlir::qir::sx)}, CompilerPipelineTestCase{ - "SingleControlledSX", MQT_NAMED_BUILDER(qc::singleControlledSx), + "SingleControlledSX", MQT_NAMED_BUILDER(::qc::singleControlledSx), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledSx), MQT_NAMED_BUILDER(mlir::qir::singleControlledSx)}, CompilerPipelineTestCase{ - "MultipleControlledSX", MQT_NAMED_BUILDER(qc::multipleControlledSx), - nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledSx), + "MultipleControlledSX", + MQT_NAMED_BUILDER(::qc::multipleControlledSx), nullptr, + MQT_NAMED_BUILDER(mlir::qc::multipleControlledSx), MQT_NAMED_BUILDER(mlir::qir::multipleControlledSx)}, - CompilerPipelineTestCase{"SXdg", MQT_NAMED_BUILDER(qc::sxdg), nullptr, + CompilerPipelineTestCase{"SXdg", MQT_NAMED_BUILDER(::qc::sxdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::sxdg), MQT_NAMED_BUILDER(mlir::qir::sxdg)}, CompilerPipelineTestCase{ - "SingleControlledSXdg", MQT_NAMED_BUILDER(qc::singleControlledSxdg), - nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledSxdg), + "SingleControlledSXdg", + MQT_NAMED_BUILDER(::qc::singleControlledSxdg), nullptr, + MQT_NAMED_BUILDER(mlir::qc::singleControlledSxdg), MQT_NAMED_BUILDER(mlir::qir::singleControlledSxdg)}, CompilerPipelineTestCase{ "MultipleControlledSXdg", - MQT_NAMED_BUILDER(qc::multipleControlledSxdg), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledSxdg), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledSxdg), MQT_NAMED_BUILDER(mlir::qir::multipleControlledSxdg)}, - CompilerPipelineTestCase{"RX", MQT_NAMED_BUILDER(qc::rx), nullptr, + CompilerPipelineTestCase{"RX", MQT_NAMED_BUILDER(::qc::rx), nullptr, MQT_NAMED_BUILDER(mlir::qc::rx), MQT_NAMED_BUILDER(mlir::qir::rx)}, CompilerPipelineTestCase{ - "SingleControlledRX", MQT_NAMED_BUILDER(qc::singleControlledRx), + "SingleControlledRX", MQT_NAMED_BUILDER(::qc::singleControlledRx), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRx), MQT_NAMED_BUILDER(mlir::qir::singleControlledRx)}, CompilerPipelineTestCase{ - "MultipleControlledRX", MQT_NAMED_BUILDER(qc::multipleControlledRx), - nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRx), + "MultipleControlledRX", + MQT_NAMED_BUILDER(::qc::multipleControlledRx), nullptr, + MQT_NAMED_BUILDER(mlir::qc::multipleControlledRx), MQT_NAMED_BUILDER(mlir::qir::multipleControlledRx)}, - CompilerPipelineTestCase{"RY", MQT_NAMED_BUILDER(qc::ry), nullptr, + CompilerPipelineTestCase{"RY", MQT_NAMED_BUILDER(::qc::ry), nullptr, MQT_NAMED_BUILDER(mlir::qc::ry), MQT_NAMED_BUILDER(mlir::qir::ry)}, CompilerPipelineTestCase{ - "SingleControlledRY", MQT_NAMED_BUILDER(qc::singleControlledRy), + "SingleControlledRY", MQT_NAMED_BUILDER(::qc::singleControlledRy), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRy), MQT_NAMED_BUILDER(mlir::qir::singleControlledRy)}, CompilerPipelineTestCase{ - "MultipleControlledRY", MQT_NAMED_BUILDER(qc::multipleControlledRy), - nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRy), + "MultipleControlledRY", + MQT_NAMED_BUILDER(::qc::multipleControlledRy), nullptr, + MQT_NAMED_BUILDER(mlir::qc::multipleControlledRy), MQT_NAMED_BUILDER(mlir::qir::multipleControlledRy)}, - CompilerPipelineTestCase{"RZ", MQT_NAMED_BUILDER(qc::rz), nullptr, + CompilerPipelineTestCase{"RZ", MQT_NAMED_BUILDER(::qc::rz), nullptr, MQT_NAMED_BUILDER(mlir::qc::rz), MQT_NAMED_BUILDER(mlir::qir::rz)}, CompilerPipelineTestCase{ - "SingleControlledRZ", MQT_NAMED_BUILDER(qc::singleControlledRz), + "SingleControlledRZ", MQT_NAMED_BUILDER(::qc::singleControlledRz), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRz), MQT_NAMED_BUILDER(mlir::qir::singleControlledRz)}, CompilerPipelineTestCase{ - "MultipleControlledRZ", MQT_NAMED_BUILDER(qc::multipleControlledRz), - nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRz), + "MultipleControlledRZ", + MQT_NAMED_BUILDER(::qc::multipleControlledRz), nullptr, + MQT_NAMED_BUILDER(mlir::qc::multipleControlledRz), MQT_NAMED_BUILDER(mlir::qir::multipleControlledRz)}, - CompilerPipelineTestCase{"P", MQT_NAMED_BUILDER(qc::p), nullptr, + CompilerPipelineTestCase{"P", MQT_NAMED_BUILDER(::qc::p), nullptr, MQT_NAMED_BUILDER(mlir::qc::p), MQT_NAMED_BUILDER(mlir::qir::p)}, CompilerPipelineTestCase{ "SingleControlledP", - MQT_NAMED_BUILDER(qc::singleControlledP), nullptr, + MQT_NAMED_BUILDER(::qc::singleControlledP), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledP), MQT_NAMED_BUILDER(mlir::qir::singleControlledP)}, CompilerPipelineTestCase{ - "MultipleControlledP", MQT_NAMED_BUILDER(qc::multipleControlledP), + "MultipleControlledP", MQT_NAMED_BUILDER(::qc::multipleControlledP), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledP), MQT_NAMED_BUILDER(mlir::qir::multipleControlledP)}, - CompilerPipelineTestCase{"R", MQT_NAMED_BUILDER(qc::r), nullptr, + CompilerPipelineTestCase{"R", MQT_NAMED_BUILDER(::qc::r), nullptr, MQT_NAMED_BUILDER(mlir::qc::r), MQT_NAMED_BUILDER(mlir::qir::r)}, CompilerPipelineTestCase{ "SingleControlledR", - MQT_NAMED_BUILDER(qc::singleControlledR), nullptr, + MQT_NAMED_BUILDER(::qc::singleControlledR), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledR), MQT_NAMED_BUILDER(mlir::qir::singleControlledR)}, CompilerPipelineTestCase{ - "MultipleControlledR", MQT_NAMED_BUILDER(qc::multipleControlledR), + "MultipleControlledR", MQT_NAMED_BUILDER(::qc::multipleControlledR), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledR), MQT_NAMED_BUILDER(mlir::qir::multipleControlledR)}, - CompilerPipelineTestCase{"U2", MQT_NAMED_BUILDER(qc::u2), nullptr, + CompilerPipelineTestCase{"U2", MQT_NAMED_BUILDER(::qc::u2), nullptr, MQT_NAMED_BUILDER(mlir::qc::u2), MQT_NAMED_BUILDER(mlir::qir::u2)}, CompilerPipelineTestCase{ - "SingleControlledU2", MQT_NAMED_BUILDER(qc::singleControlledU2), + "SingleControlledU2", MQT_NAMED_BUILDER(::qc::singleControlledU2), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledU2), MQT_NAMED_BUILDER(mlir::qir::singleControlledU2)}, CompilerPipelineTestCase{ - "MultipleControlledU2", MQT_NAMED_BUILDER(qc::multipleControlledU2), - nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledU2), + "MultipleControlledU2", + MQT_NAMED_BUILDER(::qc::multipleControlledU2), nullptr, + MQT_NAMED_BUILDER(mlir::qc::multipleControlledU2), MQT_NAMED_BUILDER(mlir::qir::multipleControlledU2)}, - CompilerPipelineTestCase{"U", MQT_NAMED_BUILDER(qc::u), nullptr, + CompilerPipelineTestCase{"U", MQT_NAMED_BUILDER(::qc::u), nullptr, MQT_NAMED_BUILDER(mlir::qc::u), MQT_NAMED_BUILDER(mlir::qir::u)}, CompilerPipelineTestCase{ "SingleControlledU", - MQT_NAMED_BUILDER(qc::singleControlledU), nullptr, + MQT_NAMED_BUILDER(::qc::singleControlledU), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledU), MQT_NAMED_BUILDER(mlir::qir::singleControlledU)}, CompilerPipelineTestCase{ - "MultipleControlledU", MQT_NAMED_BUILDER(qc::multipleControlledU), + "MultipleControlledU", MQT_NAMED_BUILDER(::qc::multipleControlledU), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledU), MQT_NAMED_BUILDER(mlir::qir::multipleControlledU)}, - CompilerPipelineTestCase{"SWAP", MQT_NAMED_BUILDER(qc::swap), nullptr, + CompilerPipelineTestCase{"SWAP", MQT_NAMED_BUILDER(::qc::swap), nullptr, MQT_NAMED_BUILDER(mlir::qc::swap), MQT_NAMED_BUILDER(mlir::qir::swap)}, CompilerPipelineTestCase{ - "SingleControlledSWAP", MQT_NAMED_BUILDER(qc::singleControlledSwap), - nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledSwap), + "SingleControlledSWAP", + MQT_NAMED_BUILDER(::qc::singleControlledSwap), nullptr, + MQT_NAMED_BUILDER(mlir::qc::singleControlledSwap), MQT_NAMED_BUILDER(mlir::qir::singleControlledSwap)}, CompilerPipelineTestCase{ "MultipleControlledSWAP", - MQT_NAMED_BUILDER(qc::multipleControlledSwap), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledSwap), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledSwap), MQT_NAMED_BUILDER(mlir::qir::multipleControlledSwap)}, - CompilerPipelineTestCase{"iSWAP", MQT_NAMED_BUILDER(qc::iswap), nullptr, - MQT_NAMED_BUILDER(mlir::qc::iswap), + CompilerPipelineTestCase{"iSWAP", MQT_NAMED_BUILDER(::qc::iswap), + nullptr, MQT_NAMED_BUILDER(mlir::qc::iswap), MQT_NAMED_BUILDER(mlir::qir::iswap)}, CompilerPipelineTestCase{ "SingleControllediSWAP", - MQT_NAMED_BUILDER(qc::singleControlledIswap), nullptr, + MQT_NAMED_BUILDER(::qc::singleControlledIswap), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledIswap), MQT_NAMED_BUILDER(mlir::qir::singleControlledIswap)}, CompilerPipelineTestCase{ "MultipleControllediSWAP", - MQT_NAMED_BUILDER(qc::multipleControlledIswap), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledIswap), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledIswap), MQT_NAMED_BUILDER(mlir::qir::multipleControlledIswap)}, CompilerPipelineTestCase{ - "InverseISWAP", MQT_NAMED_BUILDER(qc::inverseIswap), nullptr, + "InverseISWAP", MQT_NAMED_BUILDER(::qc::inverseIswap), nullptr, MQT_NAMED_BUILDER(mlir::qc::inverseIswap), nullptr, true, false}, CompilerPipelineTestCase{ "InverseMultiControlledISWAP", - MQT_NAMED_BUILDER(qc::inverseMultipleControlledIswap), nullptr, + MQT_NAMED_BUILDER(::qc::inverseMultipleControlledIswap), nullptr, MQT_NAMED_BUILDER(mlir::qc::inverseMultipleControlledIswap), nullptr, true, false}, - CompilerPipelineTestCase{"DCX", MQT_NAMED_BUILDER(qc::dcx), nullptr, + CompilerPipelineTestCase{"DCX", MQT_NAMED_BUILDER(::qc::dcx), nullptr, MQT_NAMED_BUILDER(mlir::qc::dcx), MQT_NAMED_BUILDER(mlir::qir::dcx)}, CompilerPipelineTestCase{ - "SingleControlledDCX", MQT_NAMED_BUILDER(qc::singleControlledDcx), + "SingleControlledDCX", MQT_NAMED_BUILDER(::qc::singleControlledDcx), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledDcx), MQT_NAMED_BUILDER(mlir::qir::singleControlledDcx)}, CompilerPipelineTestCase{ "MultipleControlledDCX", - MQT_NAMED_BUILDER(qc::multipleControlledDcx), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledDcx), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledDcx), MQT_NAMED_BUILDER(mlir::qir::multipleControlledDcx)}, - CompilerPipelineTestCase{"ECR", MQT_NAMED_BUILDER(qc::ecr), nullptr, + CompilerPipelineTestCase{"ECR", MQT_NAMED_BUILDER(::qc::ecr), nullptr, MQT_NAMED_BUILDER(mlir::qc::ecr), MQT_NAMED_BUILDER(mlir::qir::ecr)}, CompilerPipelineTestCase{ - "SingleControlledECR", MQT_NAMED_BUILDER(qc::singleControlledEcr), + "SingleControlledECR", MQT_NAMED_BUILDER(::qc::singleControlledEcr), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledEcr), MQT_NAMED_BUILDER(mlir::qir::singleControlledEcr)}, CompilerPipelineTestCase{ "MultipleControlledECR", - MQT_NAMED_BUILDER(qc::multipleControlledEcr), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledEcr), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledEcr), MQT_NAMED_BUILDER(mlir::qir::multipleControlledEcr)}, - CompilerPipelineTestCase{"RXX", MQT_NAMED_BUILDER(qc::rxx), nullptr, + CompilerPipelineTestCase{"RXX", MQT_NAMED_BUILDER(::qc::rxx), nullptr, MQT_NAMED_BUILDER(mlir::qc::rxx), MQT_NAMED_BUILDER(mlir::qir::rxx)}, CompilerPipelineTestCase{ - "SingleControlledRXX", MQT_NAMED_BUILDER(qc::singleControlledRxx), + "SingleControlledRXX", MQT_NAMED_BUILDER(::qc::singleControlledRxx), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRxx), MQT_NAMED_BUILDER(mlir::qir::singleControlledRxx)}, CompilerPipelineTestCase{ "MultipleControlledRXX", - MQT_NAMED_BUILDER(qc::multipleControlledRxx), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledRxx), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRxx), MQT_NAMED_BUILDER(mlir::qir::multipleControlledRxx)}, CompilerPipelineTestCase{ - "TripleControlledRXX", MQT_NAMED_BUILDER(qc::tripleControlledRxx), + "TripleControlledRXX", MQT_NAMED_BUILDER(::qc::tripleControlledRxx), nullptr, MQT_NAMED_BUILDER(mlir::qc::tripleControlledRxx), MQT_NAMED_BUILDER(mlir::qir::tripleControlledRxx)}, - CompilerPipelineTestCase{"RYY", MQT_NAMED_BUILDER(qc::ryy), nullptr, + CompilerPipelineTestCase{"RYY", MQT_NAMED_BUILDER(::qc::ryy), nullptr, MQT_NAMED_BUILDER(mlir::qc::ryy), MQT_NAMED_BUILDER(mlir::qir::ryy)}, CompilerPipelineTestCase{ - "SingleControlledRYY", MQT_NAMED_BUILDER(qc::singleControlledRyy), + "SingleControlledRYY", MQT_NAMED_BUILDER(::qc::singleControlledRyy), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRyy), MQT_NAMED_BUILDER(mlir::qir::singleControlledRyy)}, CompilerPipelineTestCase{ "MultipleControlledRYY", - MQT_NAMED_BUILDER(qc::multipleControlledRyy), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledRyy), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRyy), MQT_NAMED_BUILDER(mlir::qir::multipleControlledRyy)}, - CompilerPipelineTestCase{"RZX", MQT_NAMED_BUILDER(qc::rzx), nullptr, + CompilerPipelineTestCase{"RZX", MQT_NAMED_BUILDER(::qc::rzx), nullptr, MQT_NAMED_BUILDER(mlir::qc::rzx), MQT_NAMED_BUILDER(mlir::qir::rzx)}, CompilerPipelineTestCase{ - "SingleControlledRZX", MQT_NAMED_BUILDER(qc::singleControlledRzx), + "SingleControlledRZX", MQT_NAMED_BUILDER(::qc::singleControlledRzx), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRzx), MQT_NAMED_BUILDER(mlir::qir::singleControlledRzx)}, CompilerPipelineTestCase{ "MultipleControlledRZX", - MQT_NAMED_BUILDER(qc::multipleControlledRzx), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledRzx), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRzx), MQT_NAMED_BUILDER(mlir::qir::multipleControlledRzx)}, - CompilerPipelineTestCase{"RZZ", MQT_NAMED_BUILDER(qc::rzz), nullptr, + CompilerPipelineTestCase{"RZZ", MQT_NAMED_BUILDER(::qc::rzz), nullptr, MQT_NAMED_BUILDER(mlir::qc::rzz), MQT_NAMED_BUILDER(mlir::qir::rzz)}, CompilerPipelineTestCase{ - "SingleControlledRZZ", MQT_NAMED_BUILDER(qc::singleControlledRzz), + "SingleControlledRZZ", MQT_NAMED_BUILDER(::qc::singleControlledRzz), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledRzz), MQT_NAMED_BUILDER(mlir::qir::singleControlledRzz)}, CompilerPipelineTestCase{ "MultipleControlledRZZ", - MQT_NAMED_BUILDER(qc::multipleControlledRzz), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledRzz), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledRzz), MQT_NAMED_BUILDER(mlir::qir::multipleControlledRzz)}, - CompilerPipelineTestCase{"XXPlusYY", MQT_NAMED_BUILDER(qc::xxPlusYY), + CompilerPipelineTestCase{"XXPlusYY", MQT_NAMED_BUILDER(::qc::xxPlusYY), nullptr, MQT_NAMED_BUILDER(mlir::qc::xxPlusYY), MQT_NAMED_BUILDER(mlir::qir::xxPlusYY)}, CompilerPipelineTestCase{ "SingleControlledXXPlusYY", - MQT_NAMED_BUILDER(qc::singleControlledXxPlusYY), nullptr, + MQT_NAMED_BUILDER(::qc::singleControlledXxPlusYY), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledXxPlusYY), MQT_NAMED_BUILDER(mlir::qir::singleControlledXxPlusYY)}, CompilerPipelineTestCase{ "MultipleControlledXXPlusYY", - MQT_NAMED_BUILDER(qc::multipleControlledXxPlusYY), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledXxPlusYY), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledXxPlusYY), MQT_NAMED_BUILDER(mlir::qir::multipleControlledXxPlusYY)}, - CompilerPipelineTestCase{"XXMinusYY", MQT_NAMED_BUILDER(qc::xxMinusYY), - nullptr, + CompilerPipelineTestCase{"XXMinusYY", + MQT_NAMED_BUILDER(::qc::xxMinusYY), nullptr, MQT_NAMED_BUILDER(mlir::qc::xxMinusYY), MQT_NAMED_BUILDER(mlir::qir::xxMinusYY)}, CompilerPipelineTestCase{ "SingleControlledXXMinusYY", - MQT_NAMED_BUILDER(qc::singleControlledXxMinusYY), nullptr, + MQT_NAMED_BUILDER(::qc::singleControlledXxMinusYY), nullptr, MQT_NAMED_BUILDER(mlir::qc::singleControlledXxMinusYY), MQT_NAMED_BUILDER(mlir::qir::singleControlledXxMinusYY)}, CompilerPipelineTestCase{ "MultipleControlledXXMinusYY", - MQT_NAMED_BUILDER(qc::multipleControlledXxMinusYY), nullptr, + MQT_NAMED_BUILDER(::qc::multipleControlledXxMinusYY), nullptr, MQT_NAMED_BUILDER(mlir::qc::multipleControlledXxMinusYY), MQT_NAMED_BUILDER(mlir::qir::multipleControlledXxMinusYY)}, - CompilerPipelineTestCase{"CtrlTwo", MQT_NAMED_BUILDER(qc::ctrlTwo), + CompilerPipelineTestCase{"CtrlTwo", MQT_NAMED_BUILDER(::qc::ctrlTwo), nullptr, MQT_NAMED_BUILDER(mlir::qc::ctrlTwo), MQT_NAMED_BUILDER(mlir::qir::ctrlTwo)})); diff --git a/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp b/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp index 6e3672abaf..bf69e61817 100644 --- a/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp +++ b/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -46,12 +45,8 @@ namespace { struct JeffRoundTripTestCase { std::string name; - mqt::test::NamedBuilder, SmallVector>> - programBuilder; - mqt::test::NamedBuilder, SmallVector>> - referenceBuilder; + mqt::test::MultiResultBuilder programBuilder; + mqt::test::MultiResultBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const JeffRoundTripTestCase& info); diff --git a/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp b/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp index 266a5f52cb..f52fcfb18a 100644 --- a/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp +++ b/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -45,12 +44,8 @@ namespace { struct QCOToQCTestCase { std::string name; - mqt::test::NamedBuilder, SmallVector>> - programBuilder; - mqt::test::NamedBuilder, SmallVector>> - referenceBuilder; + mqt::test::MultiResultBuilder programBuilder; + mqt::test::MultiResultBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCOToQCTestCase& info); diff --git a/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp b/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp index f9d2050e03..d62cb08c4e 100644 --- a/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp +++ b/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -45,12 +44,8 @@ namespace { struct QCToQCOTestCase { std::string name; - mqt::test::NamedBuilder, SmallVector>> - programBuilder; - mqt::test::NamedBuilder, SmallVector>> - referenceBuilder; + mqt::test::MultiResultBuilder programBuilder; + mqt::test::MultiResultBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCToQCOTestCase& info); diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp index 4e083edaf7..44deddb42c 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -46,11 +45,8 @@ namespace { struct QCToQIRAdaptiveTestCase { std::string name; - mqt::test::NamedBuilder, SmallVector>> - programBuilder; - mqt::test::NamedBuilder> - referenceBuilder; + mqt::test::MultiResultBuilder programBuilder; + mqt::test::SingleResultBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCToQIRAdaptiveTestCase& info); diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp index 78e888fdbe..ee51f68037 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -46,11 +45,8 @@ namespace { struct QCToQIRBaseTestCase { std::string name; - mqt::test::NamedBuilder, SmallVector>> - programBuilder; - mqt::test::NamedBuilder> - referenceBuilder; + mqt::test::MultiResultBuilder programBuilder; + mqt::test::SingleResultBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCToQIRBaseTestCase& info); diff --git a/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp b/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp index 5b43465a63..77569a69d8 100644 --- a/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp +++ b/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -39,12 +38,8 @@ namespace { struct QCTestCase { std::string name; - mqt::test::NamedBuilder, SmallVector>> - programBuilder; - mqt::test::NamedBuilder, SmallVector>> - referenceBuilder; + mqt::test::MultiResultBuilder programBuilder; + mqt::test::MultiResultBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCTestCase& info); }; diff --git a/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp b/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp index 899b333e44..2ecb199495 100644 --- a/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp +++ b/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -41,9 +40,7 @@ namespace { struct QASM3TranslationTestCase { std::string name; std::string source; - mqt::test::NamedBuilder, SmallVector>> - referenceBuilder; + mqt::test::MultiResultBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QASM3TranslationTestCase& test); @@ -73,41 +70,36 @@ class QASM3TranslationTest } // namespace -static std::pair, SmallVector> -twoX(qc::QCProgramBuilder& b) { +static SmallVector twoX(qc::QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.x(q[0]); b.x(q[1]); auto c0 = b.measure(q[0]); auto c1 = b.measure(q[1]); - return {{c0, c1}, {b.getI1Type(), b.getI1Type()}}; + return {c0, c1}; } -static std::pair, SmallVector> -singleNegControlledX(qc::QCProgramBuilder& b) { +static SmallVector singleNegControlledX(qc::QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.x(q[0]); b.cx(q[0], q[1]); b.x(q[0]); auto c0 = b.measure(q[0]); auto c1 = b.measure(q[1]); - return {{c0, c1}, {b.getI1Type(), b.getI1Type()}}; + return {c0, c1}; } -static std::pair, SmallVector> -tripleControlledX(qc::QCProgramBuilder& b) { +static SmallVector tripleControlledX(qc::QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcx({q[0], q[1], q[2]}, q[3]); auto c0 = b.measure(q[0]); auto c1 = b.measure(q[1]); auto c2 = b.measure(q[2]); auto c3 = b.measure(q[3]); - return {{c0, c1, c2, c3}, - {b.getI1Type(), b.getI1Type(), b.getI1Type(), b.getI1Type()}}; + return {c0, c1, c2, c3}; } -static std::pair, SmallVector> -mixedControlledX(qc::QCProgramBuilder& b) { +static SmallVector mixedControlledX(qc::QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.x(q[1]); b.mcx({q[0], q[1]}, q[2]); @@ -115,11 +107,10 @@ mixedControlledX(qc::QCProgramBuilder& b) { auto c0 = b.measure(q[0]); auto c1 = b.measure(q[1]); auto c2 = b.measure(q[2]); - return {{c0, c1, c2}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; + return {c0, c1, c2}; } -static std::pair, SmallVector> -twoMixedControlledX(qc::QCProgramBuilder& b) { +static SmallVector twoMixedControlledX(qc::QCProgramBuilder& b) { auto q1 = b.allocQubitRegister(2); auto q2 = b.allocQubitRegister(2); auto q3 = b.allocQubitRegister(2); @@ -135,13 +126,10 @@ twoMixedControlledX(qc::QCProgramBuilder& b) { auto c3 = b.measure(q2[1]); auto c4 = b.measure(q3[0]); auto c5 = b.measure(q3[1]); - return {{c0, c1, c2, c3, c4, c5}, - {b.getI1Type(), b.getI1Type(), b.getI1Type(), b.getI1Type(), - b.getI1Type(), b.getI1Type()}}; + return {c0, c1, c2, c3, c4, c5}; } -static std::pair, SmallVector> -ifNot(qc::QCProgramBuilder& b) { +static SmallVector ifNot(qc::QCProgramBuilder& b) { auto trueValue = b.boolConstant(true); auto q = b.allocQubitRegister(1); b.h(q[0]); @@ -149,7 +137,7 @@ ifNot(qc::QCProgramBuilder& b) { auto cond = arith::XOrIOp::create(b, c, trueValue).getResult(); b.scfIf(cond, [&] { b.x(q[0]); }); auto out = b.measure(q[0]); - return {{out}, {b.getI1Type()}}; + return {out}; } TEST_P(QASM3TranslationTest, ProgramEquivalence) { diff --git a/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp b/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp index 89880e8a5f..128878283b 100644 --- a/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp +++ b/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -40,9 +39,8 @@ namespace { struct QuantumComputationTranslationTestCase { std::string name; mqt::test::NamedBuilder<::qc::QuantumComputation> programBuilder; - mqt::test::NamedBuilder< - mlir::qc::QCProgramBuilder, - std::pair, llvm::SmallVector>> + mqt::test::NamedBuilder> referenceBuilder; friend std::ostream& diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 421fb976f3..4f6a7cfeea 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -42,12 +41,8 @@ namespace { struct QCOTestCase { std::string name; - mqt::test::NamedBuilder, SmallVector>> - programBuilder; - mqt::test::NamedBuilder, SmallVector>> - referenceBuilder; + mqt::test::MultiResultBuilder programBuilder; + mqt::test::MultiResultBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCOTestCase& info); }; diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp index 00cff14514..92716e3919 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -106,12 +105,8 @@ namespace { struct QCOMatrixTestCase { std::string name; - mqt::test::NamedBuilder, SmallVector>> - programBuilder; - mqt::test::NamedBuilder, SmallVector>> - referenceBuilder; + mqt::test::MultiResultBuilder programBuilder; + mqt::test::MultiResultBuilder referenceBuilder; }; class QCOMatrixTest : public testing::TestWithParam { diff --git a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp index 6b19442f18..bb41d8c78b 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp @@ -70,7 +70,7 @@ struct TestFixture { void setUp() { DialectRegistry registry; - registry.insert(); context = std::make_unique(); context->appendDialectRegistry(registry); @@ -102,24 +102,15 @@ class EulerSynthesisExactTest } // namespace /** - * @brief Measures the given qubits and return the measurement outcomes and - * their types. + * @brief Measures the given qubits and returns the measurement outcomes. * @param b The `ProgramBuilder` used to perform the measurements. * @param qubits The qubits to be measured. - * @return A pair containing the result values and their types. + * @return The result values. */ -static std::pair, mlir::SmallVector> -measureAndReturn(mlir::qco::QCOProgramBuilder& b, - const mlir::SmallVector& qubits) { - mlir::SmallVector bits; - mlir::SmallVector bitTypes; - auto i1Type = b.getI1Type(); - for (const auto& q : qubits) { - auto [q2, bit] = b.measure(q); - bits.push_back(bit); - bitTypes.push_back(i1Type); - } - return {bits, bitTypes}; +static SmallVector measureAndReturn(QCOProgramBuilder& b, + ValueRange qubits) { + return llvm::to_vector( + llvm::map_range(qubits, [&](Value q) { return b.measure(q).second; })); } //===----------------------------------------------------------------------===// @@ -155,8 +146,8 @@ template } template static void forEachBasis(Fn fn) { - const std::array bases = {"zyz", "zxz", "xzx", "xyx", - "u", "zsxx", "r"}; + constexpr std::array bases = {"zyz", "zxz", "xzx", "xyx", + "u", "zsxx", "r"}; for (const char* basis : bases) { fn(StringRef{basis}); } @@ -382,7 +373,7 @@ INSTANTIATE_TEST_SUITE_P( ZSXXShortcutCase{"ZYZNearZeroTheta", [](MLIRContext*) -> Matrix2x2 { constexpr double tol = - 0.5 * mlir::utils::TOLERANCE; + 0.5 * utils::TOLERANCE; return RZOp::unitaryMatrix(0.4) * RYOp::unitaryMatrix(tol) * RZOp::unitaryMatrix(0.3); @@ -397,23 +388,21 @@ INSTANTIATE_TEST_SUITE_P( ZSXXShortcutCase{"RYNearHalfPi", [](MLIRContext* ctx) -> Matrix2x2 { return rotationMatrix( - ctx, - (std::numbers::pi / 2.0) + - (0.5 * mlir::utils::TOLERANCE)); + ctx, (std::numbers::pi / 2.0) + + (0.5 * utils::TOLERANCE)); }, 2, 1, 0}, ZSXXShortcutCase{"RYNearZero", [](MLIRContext* ctx) -> Matrix2x2 { return rotationMatrix( - ctx, 0.5 * mlir::utils::TOLERANCE); + ctx, 0.5 * utils::TOLERANCE); }, 0, 0, 0}, ZSXXShortcutCase{"RYNearPi", [](MLIRContext* ctx) -> Matrix2x2 { return rotationMatrix( - ctx, - std::numbers::pi - - (0.5 * mlir::utils::TOLERANCE)); + ctx, std::numbers::pi - + (0.5 * utils::TOLERANCE)); }, 1, 0, 1}), [](const testing::TestParamInfo& info) { @@ -477,7 +466,7 @@ TEST(EulerSynthesisTest, RandomReconstructionAllBases) { TEST(EulerAnglesCoverageTest, ParamsZYZUsesOffDiagonal01When10IsNearZero) { Matrix2x2 matrix = RXOp::unitaryMatrix(0.4); matrix(1, 0) = Complex{0.0, 0.0}; - ASSERT_GT(std::abs(matrix(0, 1)), mlir::utils::TOLERANCE); + ASSERT_GT(std::abs(matrix(0, 1)), utils::TOLERANCE); const EulerAngles angles = anglesFromUnitary(matrix, ZYZ); EXPECT_TRUE(std::isfinite(angles.theta)); EXPECT_TRUE(std::isfinite(angles.phi)); @@ -491,9 +480,9 @@ TEST(EulerAnglesCoverageTest, PhaseOnlyDecompositionSkipsRotationGates) { const Matrix2x2 matrix = Matrix2x2::fromElements(scale, 0, 0, scale); ASSERT_FALSE(matrix.isApprox(Matrix2x2::identity())); const EulerAngles angles = anglesFromUnitary(matrix, ZYZ); - EXPECT_LE(std::abs(angles.theta), mlir::utils::TOLERANCE); - EXPECT_LE(std::abs(angles.phi), mlir::utils::TOLERANCE); - EXPECT_LE(std::abs(angles.lambda), mlir::utils::TOLERANCE); + EXPECT_LE(std::abs(angles.theta), utils::TOLERANCE); + EXPECT_LE(std::abs(angles.phi), utils::TOLERANCE); + EXPECT_LE(std::abs(angles.lambda), utils::TOLERANCE); const auto circuit = synthesizeMatrix(fx.ctx(), matrix, ZYZ); ASSERT_TRUE(succeeded(verify(*circuit.mlirModule))); EXPECT_EQ(countZYZGates(circuit.func), 0U); @@ -515,7 +504,7 @@ TEST(EulerAnglesCoverageTest, UBasisNonzeroThetaEmitsSingleUGate) { fx.setUp(); const Matrix2x2 matrix = RYOp::unitaryMatrix(1.2); const EulerAngles angles = anglesFromUnitary(matrix, U); - ASSERT_GT(std::abs(angles.theta), mlir::utils::TOLERANCE); + ASSERT_GT(std::abs(angles.theta), utils::TOLERANCE); expectSynthesizedMatrix(fx.ctx(), matrix, U, [](func::FuncOp funcOp, const Matrix2x2& /*matrix*/) { EXPECT_EQ(countOps(funcOp), 1U); @@ -528,7 +517,7 @@ TEST(EulerAnglesCoverageTest, RBasisNonzeroThetaEmitsThreeRGates) { fx.setUp(); const Matrix2x2 matrix = HOp::getUnitaryMatrix(); const EulerAngles angles = anglesFromUnitary(matrix, R); - ASSERT_GT(std::abs(angles.theta), mlir::utils::TOLERANCE); + ASSERT_GT(std::abs(angles.theta), utils::TOLERANCE); expectSynthesizedMatrix(fx.ctx(), matrix, R, [](func::FuncOp funcOp, const Matrix2x2& /*matrix*/) { EXPECT_EQ(countOps(funcOp), 3U); @@ -538,7 +527,7 @@ TEST(EulerAnglesCoverageTest, RBasisNonzeroThetaEmitsThreeRGates) { TEST(EulerAnglesCoverageTest, Mod2PiMapsPiBoundaryThroughSynthesis) { TestFixture fx; fx.setUp(); - constexpr double eps = 0.5 * mlir::utils::TOLERANCE; + constexpr double eps = 0.5 * utils::TOLERANCE; const Complex global = std::polar(1.0, std::numbers::pi - eps); const Matrix2x2 matrix = Matrix2x2::fromElements(global, 0, 0, global); expectSynthesizedMatrix(fx.ctx(), matrix, U, @@ -553,7 +542,8 @@ TEST(EulerAnglesCoverageTest, Mod2PiPreservesNonFinitePhase) { fx.setUp(); const Matrix2x2 matrix = Matrix2x2::fromElements( Complex{std::numeric_limits::quiet_NaN(), 0}, 0, 0, 1); - EXPECT_NO_FATAL_FAILURE(synthesizeMatrix(fx.ctx(), matrix, ZYZ)); + EXPECT_NO_FATAL_FAILURE(std::ignore = + synthesizeMatrix(fx.ctx(), matrix, ZYZ)); } //===----------------------------------------------------------------------===// @@ -786,7 +776,7 @@ static void runFuseInParent(MLIRContext* ctx, ProgramT program, // --- Fuse program fixtures --- // -static std::pair, SmallVector> +static SmallVector singleQubitRunWithSingleQubitGate(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); @@ -794,56 +784,50 @@ singleQubitRunWithSingleQubitGate(QCOProgramBuilder& b) { q[0] = b.rz(0.123, q[0]); q[0] = b.inv(q[0], [&b](Value qubit) { return b.sx(qubit); }); q[0] = b.ry(-0.456, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -static std::pair, SmallVector> -singleQubitRunsSplitByTwoQGate(QCOProgramBuilder& b) { +static SmallVector singleQubitRunsSplitByTwoQGate(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); q[0] = b.h(q[0]); q[0] = b.t(q[0]); std::tie(q[0], q[1]) = b.swap(q[0], q[1]); q[0] = b.rz(0.321, q[0]); q[0] = b.sx(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -static std::pair, SmallVector> -singleQubitRunsSplitByBarrier(QCOProgramBuilder& b) { +static SmallVector singleQubitRunsSplitByBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); q[0] = b.t(q[0]); q[0] = b.barrier({q[0]})[0]; q[0] = b.rz(0.321, q[0]); q[0] = b.sx(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -static std::pair, SmallVector> -singleNonBasisGate(QCOProgramBuilder& b) { +static SmallVector singleNonBasisGate(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -static std::pair, SmallVector> -singlePauliX(QCOProgramBuilder& b) { +static SmallVector singlePauliX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.x(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -static std::pair, SmallVector> -canonicalZYZRun(QCOProgramBuilder& b) { +static SmallVector canonicalZYZRun(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rz(0.3, q[0]); q[0] = b.ry(0.5, q[0]); q[0] = b.rz(0.7, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -static std::pair, SmallVector> -overlongZYZRun(QCOProgramBuilder& b) { +static SmallVector overlongZYZRun(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rz(0.3, q[0]); q[0] = b.ry(0.5, q[0]); @@ -851,20 +835,18 @@ overlongZYZRun(QCOProgramBuilder& b) { q[0] = b.ry(0.9, q[0]); q[0] = b.rz(1.1, q[0]); q[0] = b.ry(1.3, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -static std::pair, SmallVector> -overlongZSXXMixedPureZRun(QCOProgramBuilder& b) { +static SmallVector overlongZSXXMixedPureZRun(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sx(q[0]); q[0] = b.rz(std::numbers::pi, q[0]); q[0] = b.sx(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -static std::pair, SmallVector> -singleQubitRunInScfFor(QCOProgramBuilder& b) { +static SmallVector singleQubitRunInScfFor(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.scfFor(0, 1, 1, ValueRange{q[0]}, [&b](Value, ValueRange iterArgs) { @@ -874,11 +856,10 @@ singleQubitRunInScfFor(QCOProgramBuilder& b) { wire = b.rz(0.123, wire); return SmallVector{wire}; }); - return measureAndReturn(b, {res[0]}); + return measureAndReturn(b, res); } -static std::pair, SmallVector> -xInverseTwoX(QCOProgramBuilder& b) { +static SmallVector xInverseTwoX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.x(q[0]); q[0] = b.inv(q[0], [&b](Value qubit) { @@ -886,10 +867,10 @@ xInverseTwoX(QCOProgramBuilder& b) { return b.x(qubit); }); q[0] = b.x(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -static std::pair, SmallVector> +static SmallVector inverseMultiQubitBodySingleQubitRun(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto outs = @@ -900,11 +881,10 @@ inverseMultiQubitBodySingleQubitRun(QCOProgramBuilder& b) { }); q[0] = outs[0]; q[1] = outs[1]; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -static std::pair, SmallVector> -controlledInverseHT(QCOProgramBuilder& b) { +static SmallVector controlledInverseHT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.ctrl(q[0], q[1], [&b](Value target) { return b.inv(target, [&b](Value qubit) { @@ -915,15 +895,13 @@ controlledInverseHT(QCOProgramBuilder& b) { return measureAndReturn(b, {res.second}); } -static std::pair, SmallVector> -controlledH(QCOProgramBuilder& b) { +static SmallVector controlledH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.ctrl(q[0], q[1], [&b](Value target) { return b.h(target); }); return measureAndReturn(b, {res.second}); } -static std::pair, SmallVector> -singleQubitRunsSplitByScfFor(QCOProgramBuilder& b) { +static SmallVector singleQubitRunsSplitByScfFor(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); q[0] = b.t(q[0]); @@ -934,7 +912,7 @@ singleQubitRunsSplitByScfFor(QCOProgramBuilder& b) { wire = b.sx(wire); return SmallVector{wire}; }); - return measureAndReturn(b, {res[0]}); + return measureAndReturn(b, res); } //===----------------------------------------------------------------------===// @@ -955,8 +933,7 @@ TEST(FuseSingleQubitUnitaryRunsTest, FusesProgramsAllBases) { fx.setUp(); struct Case { - std::pair, SmallVector> (*program)( - QCOProgramBuilder&); + SmallVector (*program)(QCOProgramBuilder&); void (*extra)(func::FuncOp, StringRef); }; const std::array cases = {{ @@ -1036,8 +1013,7 @@ TEST(FuseSingleQubitUnitaryRunsTest, DoesNotFuseAcrossBoundariesAllBases) { fx.setUp(); struct Case { - std::pair, SmallVector> (*program)( - QCOProgramBuilder&); + SmallVector (*program)(QCOProgramBuilder&); void (*check)(func::FuncOp, StringRef, MLIRContext*); }; const std::array cases = {{ diff --git a/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp b/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp index 8922399a3b..a5f86f607e 100644 --- a/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp +++ b/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -36,10 +35,8 @@ namespace { struct QIRTestCase { std::string name; - mqt::test::NamedBuilder> - programBuilder; - mqt::test::NamedBuilder> - referenceBuilder; + mqt::test::SingleResultBuilder programBuilder; + mqt::test::SingleResultBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QIRTestCase& info); }; diff --git a/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp b/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp index 9d09672131..7282617469 100644 --- a/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp +++ b/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp @@ -66,9 +66,8 @@ class QTensorTest : public ::testing::Test { } /// Build a module using the QCOProgramBuilder and run the cleanup pipeline. - [[nodiscard]] OwningOpRef - buildAndCanonicalize(std::pair, SmallVector> ( - *buildFn)(QCOProgramBuilder&)) const { + [[nodiscard]] OwningOpRef buildAndCanonicalize( + SmallVector (*buildFn)(QCOProgramBuilder&)) const { auto module = QCOProgramBuilder::build(context.get(), buildFn); if (!module) { return {}; @@ -194,11 +193,10 @@ TEST_F(QTensorTest, AllocOpStaticTypeWithDynamicSizeOperandFailsVerification) { /// An alloc immediately followed by dealloc should be eliminated entirely. TEST_F(QTensorTest, DeallocOpAllocDeallocPairIsRemoved) { - auto canonicalized = buildAndCanonicalize( - [](QCOProgramBuilder& b) - -> std::pair, SmallVector> { + auto canonicalized = + buildAndCanonicalize([](QCOProgramBuilder& b) -> SmallVector { b.qtensorAlloc(3); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return {b.intConstant(0)}; }); ASSERT_TRUE(canonicalized); EXPECT_TRUE(verify(*canonicalized).succeeded()); @@ -425,12 +423,8 @@ TEST_F(QTensorTest, ResetAfterExtractThroughSameIndexInsertIsNotEliminated) { struct QTensorIntegrationTestCase { std::string name; - mqt::test::NamedBuilder, SmallVector>> - programBuilder; - mqt::test::NamedBuilder, SmallVector>> - referenceBuilder; + mqt::test::MultiResultBuilder programBuilder; + mqt::test::MultiResultBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QTensorIntegrationTestCase& info); diff --git a/mlir/unittests/TestCaseUtils.h b/mlir/unittests/TestCaseUtils.h index b876751074..dea345fa97 100644 --- a/mlir/unittests/TestCaseUtils.h +++ b/mlir/unittests/TestCaseUtils.h @@ -14,9 +14,11 @@ #include #include +#include #include #include #include +#include #include #include @@ -47,6 +49,13 @@ namedBuilder(const char* name, RetT (*fn)(BuilderT&)) noexcept { return NamedBuilder{name, fn}; } +template +using MultiResultBuilder = + NamedBuilder>; + +template +using SingleResultBuilder = NamedBuilder; + [[nodiscard]] constexpr const char* displayName(const char* name) noexcept { return name != nullptr ? name : ""; } diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index 27cb8629f5..14cf2bde9b 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -14,54 +14,38 @@ #include #include -#include // NOLINT(misc-include-cleaner) -#include #include #include #include -#include + +namespace mlir::qc { /** - * @brief Measures the given qubits and return the measurement outcomes and - * their types. + * @brief Measures the given qubits and returns the measurement outcomes. * @param b The `ProgramBuilder` used to perform the measurements. * @param qubits The qubits to be measured. - * @return A pair containing the result values and their types. + * @return The result values. */ -static std::pair, mlir::SmallVector> -measureAndReturn(mlir::qc::QCProgramBuilder& b, - const mlir::SmallVector& qubits) { - mlir::SmallVector bits; - mlir::SmallVector bitTypes; - auto i1Type = b.getI1Type(); - for (const auto& q : qubits) { - bits.push_back(b.measure(q)); - bitTypes.push_back(i1Type); - } - return {bits, bitTypes}; +static SmallVector measureAndReturn(QCProgramBuilder& b, + ValueRange qubits) { + return llvm::to_vector( + llvm::map_range(qubits, [&](Value q) { return b.measure(q); })); } -namespace mlir::qc { - -std::pair, SmallVector> emptyQC(QCProgramBuilder& b) { - return {{b.intConstant(0)}, {b.getI64Type()}}; -} +SmallVector emptyQC(QCProgramBuilder& b) { return {b.intConstant(0)}; } -std::pair, SmallVector> -allocQubit(QCProgramBuilder& b) { +SmallVector allocQubit(QCProgramBuilder& b) { auto q = b.allocQubit(); return measureAndReturn(b, {q}); } -std::pair, SmallVector> -allocQubitNoMeasure(QCProgramBuilder& b) { +SmallVector allocQubitNoMeasure(QCProgramBuilder& b) { b.allocQubit(); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return {b.intConstant(0)}; } -std::pair, SmallVector> -allocMultipleQubitRegistersWithOps(QCProgramBuilder& b) { +SmallVector allocMultipleQubitRegistersWithOps(QCProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); auto q1 = b.allocQubitRegister(3); b.h(q0[0]); @@ -72,53 +56,45 @@ allocMultipleQubitRegistersWithOps(QCProgramBuilder& b) { return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}); } -std::pair, SmallVector> -alloc1QubitRegister(QCProgramBuilder& b) { +SmallVector alloc1QubitRegister(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -allocQubitRegister(QCProgramBuilder& b) { +SmallVector allocQubitRegister(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -alloc3QubitRegister(QCProgramBuilder& b) { +SmallVector alloc3QubitRegister(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -allocMultipleQubitRegisters(QCProgramBuilder& b) { +SmallVector allocMultipleQubitRegisters(QCProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); auto q1 = b.allocQubitRegister(3); return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}); } -std::pair, SmallVector> -allocLargeRegister(QCProgramBuilder& b) { +SmallVector allocLargeRegister(QCProgramBuilder& b) { auto q = b.allocQubitRegister(100); return measureAndReturn(b, {q[0], q[99]}); } -std::pair, SmallVector> -staticQubits(QCProgramBuilder& b) { +SmallVector staticQubits(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsNoMeasure(QCProgramBuilder& b) { +SmallVector staticQubitsNoMeasure(QCProgramBuilder& b) { b.staticQubit(0); b.staticQubit(1); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return {b.intConstant(0)}; } -std::pair, SmallVector> -staticQubitsWithOps(QCProgramBuilder& b) { +SmallVector staticQubitsWithOps(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.h(q0); @@ -126,8 +102,7 @@ staticQubitsWithOps(QCProgramBuilder& b) { return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithParametricOps(QCProgramBuilder& b) { +SmallVector staticQubitsWithParametricOps(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.rx(std::numbers::pi / 4., q0); @@ -135,31 +110,27 @@ staticQubitsWithParametricOps(QCProgramBuilder& b) { return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithTwoTargetOps(QCProgramBuilder& b) { +SmallVector staticQubitsWithTwoTargetOps(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.rzz(0.123, q0, q1); return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithCtrl(QCProgramBuilder& b) { +SmallVector staticQubitsWithCtrl(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.cx(q0, q1); return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithInv(QCProgramBuilder& b) { +SmallVector staticQubitsWithInv(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); b.inv(q0, [&](Value qubit) { b.t(qubit); }); return measureAndReturn(b, {q0}); } -std::pair, SmallVector> -staticQubitsWithDuplicates(QCProgramBuilder& b) { +SmallVector staticQubitsWithDuplicates(QCProgramBuilder& b) { const auto q0a = b.staticQubit(0); const auto q1a = b.staticQubit(1); const auto q0b = b.staticQubit(0); @@ -173,8 +144,7 @@ staticQubitsWithDuplicates(QCProgramBuilder& b) { return measureAndReturn(b, {q0b, q1b}); } -std::pair, SmallVector> -staticQubitsCanonical(QCProgramBuilder& b) { +SmallVector staticQubitsCanonical(QCProgramBuilder& b) { const auto q0 = b.staticQubit(0); const auto q1 = b.staticQubit(1); @@ -186,56 +156,50 @@ staticQubitsCanonical(QCProgramBuilder& b) { return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -allocDeallocPair(QCProgramBuilder& b) { +SmallVector allocDeallocPair(QCProgramBuilder& b) { auto q = b.allocQubit(); b.dealloc(q); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return {b.intConstant(0)}; } -std::pair, SmallVector> -mixedStaticThenDynamicQubit(QCProgramBuilder& b) { +SmallVector mixedStaticThenDynamicQubit(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.allocQubit(); return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -mixedDynamicRegisterThenStaticQubit(QCProgramBuilder& b) { +SmallVector mixedDynamicRegisterThenStaticQubit(QCProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); auto q1 = b.staticQubit(0); return measureAndReturn(b, {q0[0], q0[1], q1}); } -std::pair, SmallVector> -singleMeasurementToSingleBit(QCProgramBuilder& b) { +SmallVector singleMeasurementToSingleBit(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); const auto outcome = b.measure(q[0], c[0]); - return {{outcome}, {b.getI1Type()}}; + return {outcome}; } -std::pair, SmallVector> -repeatedMeasurementToSameBit(QCProgramBuilder& b) { +SmallVector repeatedMeasurementToSameBit(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); b.measure(q[0], c[0]); b.measure(q[0], c[0]); auto c3 = b.measure(q[0], c[0]); - return {{c3}, {b.getI1Type()}}; + return {c3}; } -std::pair, SmallVector> -repeatedMeasurementToDifferentBits(QCProgramBuilder& b) { +SmallVector repeatedMeasurementToDifferentBits(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(3); auto c1 = b.measure(q[0], c[0]); auto c2 = b.measure(q[0], c[1]); auto c3 = b.measure(q[0], c[2]); - return {{c1, c2, c3}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; + return {c1, c2, c3}; } -std::pair, SmallVector> +SmallVector multipleClassicalRegistersAndMeasurements(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); const auto& c0 = b.allocClassicalBitRegister(1, "c0"); @@ -243,234 +207,205 @@ multipleClassicalRegistersAndMeasurements(QCProgramBuilder& b) { const auto b1 = b.measure(q[0], c0[0]); const auto b2 = b.measure(q[1], c1[0]); const auto b3 = b.measure(q[2], c1[1]); - return {{b1, b2, b3}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; + return {b1, b2, b3}; } -std::pair, SmallVector> -measurementWithoutRegisters(QCProgramBuilder& b) { +SmallVector measurementWithoutRegisters(QCProgramBuilder& b) { auto q = b.allocQubit(); auto c = b.measure(q); - return {{c}, {b.getI1Type()}}; + return {c}; } -std::pair, SmallVector> -resetQubitWithoutOp(QCProgramBuilder& b) { +SmallVector resetQubitWithoutOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -resetMultipleQubitsWithoutOp(QCProgramBuilder& b) { +SmallVector resetMultipleQubitsWithoutOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.reset(q[0]); b.reset(q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -repeatedResetWithoutOp(QCProgramBuilder& b) { +SmallVector repeatedResetWithoutOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -resetQubitAfterSingleOp(QCProgramBuilder& b) { +SmallVector resetQubitAfterSingleOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -resetMultipleQubitsAfterSingleOp(QCProgramBuilder& b) { +SmallVector resetMultipleQubitsAfterSingleOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.h(q[0]); b.reset(q[0]); b.h(q[1]); b.reset(q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -repeatedResetAfterSingleOp(QCProgramBuilder& b) { +SmallVector repeatedResetAfterSingleOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -globalPhase(QCProgramBuilder& b) { +SmallVector globalPhase(QCProgramBuilder& b) { b.gphase(0.123); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return {b.intConstant(0)}; } -std::pair, SmallVector> -globalPhaseAndMeasure(QCProgramBuilder& b) { +SmallVector globalPhaseAndMeasure(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.gphase(0.123); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledGlobalPhase(QCProgramBuilder& b) { +SmallVector singleControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.cgphase(0.123, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledGlobalPhase(QCProgramBuilder& b) { +SmallVector multipleControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcgphase(0.123, {q[0], q[1], q[2]}); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledGlobalPhase(QCProgramBuilder& b) { - auto q = b.allocQubitRegister(3); +SmallVector nestedControlledGlobalPhase(QCProgramBuilder& b) { + auto q = b.allocQubitRegister(2); b.ctrl(q[0], q[1], [&](Value target) { b.cgphase(0.123, target); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -trivialControlledGlobalPhase(QCProgramBuilder& b) { +SmallVector trivialControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcgphase(0.123, {}); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseGlobalPhase(QCProgramBuilder& b) { +SmallVector inverseGlobalPhase(QCProgramBuilder& b) { b.inv(ValueRange{}, [&](ValueRange /*qubits*/) { b.gphase(-0.123); }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return {b.intConstant(0)}; } -std::pair, SmallVector> -inverseMultipleControlledGlobalPhase(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcgphase(-0.123, qubits); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> identity(QCProgramBuilder& b) { +SmallVector identity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.id(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledIdentity(QCProgramBuilder& b) { +SmallVector singleControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cid(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoQubitsOneIdentity(QCProgramBuilder& b) { +SmallVector twoQubitsOneIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.id(q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -threeQubitsOneIdentity(QCProgramBuilder& b) { +SmallVector threeQubitsOneIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.id(q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledIdentity(QCProgramBuilder& b) { +SmallVector multipleControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcid({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoQubitsOneBarrier(QCProgramBuilder& b) { +SmallVector twoQubitsOneBarrier(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.barrier(q[0]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledIdentity(QCProgramBuilder& b) { +SmallVector nestedControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.ctrl(q[0], {q[1], q[2]}, [&](ValueRange targets) { b.cid(targets[0], targets[1]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -trivialControlledIdentity(QCProgramBuilder& b) { +SmallVector trivialControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcid({}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseIdentity(QCProgramBuilder& b) { +SmallVector inverseIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.id(qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledIdentity(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcid({qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> x(QCProgramBuilder& b) { +SmallVector x(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.x(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledX(QCProgramBuilder& b) { +SmallVector singleControlledX(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cx(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledX(QCProgramBuilder& b) { +SmallVector multipleControlledX(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcx({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledX(QCProgramBuilder& b) { +SmallVector nestedControlledX(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.cx(targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledX(QCProgramBuilder& b) { +SmallVector trivialControlledX(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcx({}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -repeatedControlledX(QCProgramBuilder& b) { +SmallVector repeatedControlledX(QCProgramBuilder& b) { auto control = b.allocQubit(); b.h(control); - mlir::SmallVector qubits; + SmallVector qubits; for (auto i = 0; i < 50; i++) { auto qubit = b.allocQubit(); b.cx(control, qubit); @@ -480,1440 +415,1279 @@ repeatedControlledX(QCProgramBuilder& b) { return measureAndReturn(b, qubits); } -std::pair, SmallVector> inverseX(QCProgramBuilder& b) { +SmallVector inverseX(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.x(qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledX(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledX(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcx({qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> y(QCProgramBuilder& b) { +SmallVector y(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.y(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledY(QCProgramBuilder& b) { +SmallVector singleControlledY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cy(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledY(QCProgramBuilder& b) { +SmallVector multipleControlledY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcy({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledY(QCProgramBuilder& b) { +SmallVector nestedControlledY(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.cy(targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledY(QCProgramBuilder& b) { +SmallVector trivialControlledY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcy({}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> inverseY(QCProgramBuilder& b) { +SmallVector inverseY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.y(qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledY(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcy({qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> z(QCProgramBuilder& b) { +SmallVector z(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.z(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledZ(QCProgramBuilder& b) { +SmallVector singleControlledZ(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cz(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledZ(QCProgramBuilder& b) { +SmallVector multipleControlledZ(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcz({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledZ(QCProgramBuilder& b) { +SmallVector nestedControlledZ(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.cz(targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledZ(QCProgramBuilder& b) { +SmallVector trivialControlledZ(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcz({}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> inverseZ(QCProgramBuilder& b) { +SmallVector inverseZ(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.z(qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledZ(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledZ(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcz({qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> h(QCProgramBuilder& b) { +SmallVector h(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledH(QCProgramBuilder& b) { +SmallVector singleControlledH(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ch(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledH(QCProgramBuilder& b) { +SmallVector multipleControlledH(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mch({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledH(QCProgramBuilder& b) { +SmallVector nestedControlledH(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.ch(targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledH(QCProgramBuilder& b) { +SmallVector trivialControlledH(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mch({}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> inverseH(QCProgramBuilder& b) { +SmallVector inverseH(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.h(qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledH(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledH(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mch({qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -hWithoutRegister(QCProgramBuilder& b) { +SmallVector hWithoutRegister(QCProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); return measureAndReturn(b, {q}); } -std::pair, SmallVector> s(QCProgramBuilder& b) { +SmallVector s(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.s(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledS(QCProgramBuilder& b) { +SmallVector singleControlledS(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cs(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledS(QCProgramBuilder& b) { +SmallVector multipleControlledS(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcs({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledS(QCProgramBuilder& b) { +SmallVector nestedControlledS(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.cs(targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledS(QCProgramBuilder& b) { +SmallVector trivialControlledS(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcs({}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> inverseS(QCProgramBuilder& b) { +SmallVector inverseS(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.s(qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledS(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledS(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcs({qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> sdg(QCProgramBuilder& b) { +SmallVector sdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledSdg(QCProgramBuilder& b) { +SmallVector singleControlledSdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csdg(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledSdg(QCProgramBuilder& b) { +SmallVector multipleControlledSdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsdg({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledSdg(QCProgramBuilder& b) { +SmallVector nestedControlledSdg(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.csdg(targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledSdg(QCProgramBuilder& b) { +SmallVector trivialControlledSdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcsdg({}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseSdg(QCProgramBuilder& b) { +SmallVector inverseSdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.sdg(qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledSdg(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledSdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcsdg({qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> t_(QCProgramBuilder& b) { +SmallVector t_(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.t(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledT(QCProgramBuilder& b) { +SmallVector singleControlledT(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ct(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledT(QCProgramBuilder& b) { +SmallVector multipleControlledT(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mct({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledT(QCProgramBuilder& b) { +SmallVector nestedControlledT(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.ct(targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledT(QCProgramBuilder& b) { +SmallVector trivialControlledT(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mct({}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> inverseT(QCProgramBuilder& b) { +SmallVector inverseT(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.t(qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledT(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledT(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mct({qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> tdg(QCProgramBuilder& b) { +SmallVector tdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.tdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledTdg(QCProgramBuilder& b) { +SmallVector singleControlledTdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ctdg(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledTdg(QCProgramBuilder& b) { +SmallVector multipleControlledTdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mctdg({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledTdg(QCProgramBuilder& b) { +SmallVector nestedControlledTdg(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.ctdg(targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledTdg(QCProgramBuilder& b) { +SmallVector trivialControlledTdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mctdg({}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseTdg(QCProgramBuilder& b) { +SmallVector inverseTdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.tdg(qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledTdg(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledTdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mctdg({qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> sx(QCProgramBuilder& b) { +SmallVector sx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sx(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledSx(QCProgramBuilder& b) { +SmallVector singleControlledSx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csx(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledSx(QCProgramBuilder& b) { +SmallVector multipleControlledSx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsx({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledSx(QCProgramBuilder& b) { +SmallVector nestedControlledSx(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.csx(targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledSx(QCProgramBuilder& b) { +SmallVector trivialControlledSx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcsx({}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseSx(QCProgramBuilder& b) { +SmallVector inverseSx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.sx(qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledSx(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledSx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcsx({qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> sxdg(QCProgramBuilder& b) { +SmallVector sxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sxdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledSxdg(QCProgramBuilder& b) { +SmallVector singleControlledSxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csxdg(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledSxdg(QCProgramBuilder& b) { +SmallVector multipleControlledSxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsxdg({q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledSxdg(QCProgramBuilder& b) { +SmallVector nestedControlledSxdg(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.csxdg(targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledSxdg(QCProgramBuilder& b) { +SmallVector trivialControlledSxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcsxdg({}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseSxdg(QCProgramBuilder& b) { +SmallVector inverseSxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.sxdg(qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledSxdg(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledSxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcsxdg({qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> rx(QCProgramBuilder& b) { +SmallVector rx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rx(0.123, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRx(QCProgramBuilder& b) { +SmallVector singleControlledRx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.crx(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRx(QCProgramBuilder& b) { +SmallVector multipleControlledRx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcrx(0.123, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRx(QCProgramBuilder& b) { +SmallVector nestedControlledRx(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.crx(0.123, targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRx(QCProgramBuilder& b) { +SmallVector trivialControlledRx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcrx(0.123, {}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRx(QCProgramBuilder& b) { +SmallVector inverseRx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.rx(-0.123, qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledRx(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledRx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcrx(-0.123, {qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> ry(QCProgramBuilder& b) { +SmallVector ry(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.ry(0.456, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRy(QCProgramBuilder& b) { +SmallVector singleControlledRy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cry(0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRy(QCProgramBuilder& b) { +SmallVector multipleControlledRy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcry(0.456, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRy(QCProgramBuilder& b) { +SmallVector nestedControlledRy(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.cry(0.456, targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRy(QCProgramBuilder& b) { +SmallVector trivialControlledRy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcry(0.456, {}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRy(QCProgramBuilder& b) { +SmallVector inverseRy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.ry(-0.456, qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledRy(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledRy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcry(-0.456, {qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> rz(QCProgramBuilder& b) { +SmallVector rz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rz(0.789, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRz(QCProgramBuilder& b) { +SmallVector singleControlledRz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.crz(0.789, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRz(QCProgramBuilder& b) { +SmallVector multipleControlledRz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcrz(0.789, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRz(QCProgramBuilder& b) { +SmallVector nestedControlledRz(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.crz(0.789, targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRz(QCProgramBuilder& b) { +SmallVector trivialControlledRz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcrz(0.789, {}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRz(QCProgramBuilder& b) { +SmallVector inverseRz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.rz(-0.789, qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledRz(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledRz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcrz(-0.789, {qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> p(QCProgramBuilder& b) { +SmallVector p(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.p(0.123, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledP(QCProgramBuilder& b) { +SmallVector singleControlledP(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cp(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledP(QCProgramBuilder& b) { +SmallVector multipleControlledP(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcp(0.123, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledP(QCProgramBuilder& b) { +SmallVector nestedControlledP(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.cp(0.123, targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledP(QCProgramBuilder& b) { +SmallVector trivialControlledP(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcp(0.123, {}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> inverseP(QCProgramBuilder& b) { +SmallVector inverseP(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.p(-0.123, qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledP(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledP(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcp(-0.123, {qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> r(QCProgramBuilder& b) { +SmallVector r(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.r(0.123, 0.456, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledR(QCProgramBuilder& b) { +SmallVector singleControlledR(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cr(0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledR(QCProgramBuilder& b) { +SmallVector multipleControlledR(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcr(0.123, 0.456, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledR(QCProgramBuilder& b) { +SmallVector nestedControlledR(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.cr(0.123, 0.456, targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledR(QCProgramBuilder& b) { +SmallVector trivialControlledR(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcr(0.123, 0.456, {}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> inverseR(QCProgramBuilder& b) { +SmallVector inverseR(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.r(-0.123, 0.456, qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledR(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledR(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcr(-0.123, 0.456, {qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> u2(QCProgramBuilder& b) { +SmallVector u2(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u2(0.234, 0.567, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledU2(QCProgramBuilder& b) { +SmallVector singleControlledU2(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cu2(0.234, 0.567, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledU2(QCProgramBuilder& b) { +SmallVector multipleControlledU2(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcu2(0.234, 0.567, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledU2(QCProgramBuilder& b) { +SmallVector nestedControlledU2(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.cu2(0.234, 0.567, targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledU2(QCProgramBuilder& b) { +SmallVector trivialControlledU2(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcu2(0.234, 0.567, {}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseU2(QCProgramBuilder& b) { +SmallVector inverseU2(QCProgramBuilder& b) { constexpr double pi = std::numbers::pi; auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.u2(-0.567 + pi, -0.234 - pi, qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledU2(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledU2(QCProgramBuilder& b) { constexpr double pi = std::numbers::pi; auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcu2(-0.567 + pi, -0.234 - pi, {qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> u(QCProgramBuilder& b) { +SmallVector u(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u(0.1, 0.2, 0.3, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledU(QCProgramBuilder& b) { +SmallVector singleControlledU(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cu(0.1, 0.2, 0.3, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledU(QCProgramBuilder& b) { +SmallVector multipleControlledU(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcu(0.1, 0.2, 0.3, {q[0], q[1]}, q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledU(QCProgramBuilder& b) { +SmallVector nestedControlledU(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); b.ctrl(reg[0], {reg[1], reg[2]}, [&](ValueRange targets) { b.cu(0.1, 0.2, 0.3, targets[0], targets[1]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledU(QCProgramBuilder& b) { +SmallVector trivialControlledU(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcu(0.1, 0.2, 0.3, {}, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> inverseU(QCProgramBuilder& b) { +SmallVector inverseU(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.u(-0.1, -0.3, -0.2, qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledU(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledU(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.mcu(-0.1, -0.3, -0.2, {qubits[0], qubits[1]}, qubits[2]); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> swap(QCProgramBuilder& b) { +SmallVector swap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.swap(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledSwap(QCProgramBuilder& b) { +SmallVector singleControlledSwap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cswap(q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledSwap(QCProgramBuilder& b) { +SmallVector multipleControlledSwap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcswap({q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledSwap(QCProgramBuilder& b) { +SmallVector nestedControlledSwap(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { b.cswap(targets[0], targets[1], targets[2]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledSwap(QCProgramBuilder& b) { +SmallVector trivialControlledSwap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcswap({}, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseSwap(QCProgramBuilder& b) { +SmallVector inverseSwap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.swap(qubits[0], qubits[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledSwap(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledSwap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { b.mcswap({qubits[0], qubits[1]}, qubits[2], qubits[3]); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> iswap(QCProgramBuilder& b) { +SmallVector iswap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.iswap(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledIswap(QCProgramBuilder& b) { +SmallVector singleControlledIswap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.ciswap(q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledIswap(QCProgramBuilder& b) { +SmallVector multipleControlledIswap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mciswap({q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledIswap(QCProgramBuilder& b) { +SmallVector nestedControlledIswap(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { b.ciswap(targets[0], targets[1], targets[2]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledIswap(QCProgramBuilder& b) { +SmallVector trivialControlledIswap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mciswap({}, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseIswap(QCProgramBuilder& b) { +SmallVector inverseIswap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.iswap(qubits[0], qubits[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledIswap(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledIswap(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { b.mciswap({qubits[0], qubits[1]}, qubits[2], qubits[3]); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> dcx(QCProgramBuilder& b) { +SmallVector dcx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.dcx(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledDcx(QCProgramBuilder& b) { +SmallVector singleControlledDcx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cdcx(q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledDcx(QCProgramBuilder& b) { +SmallVector multipleControlledDcx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcdcx({q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledDcx(QCProgramBuilder& b) { +SmallVector nestedControlledDcx(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { b.cdcx(targets[0], targets[1], targets[2]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledDcx(QCProgramBuilder& b) { +SmallVector trivialControlledDcx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcdcx({}, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseDcx(QCProgramBuilder& b) { +SmallVector inverseDcx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.dcx(qubits[1], qubits[0]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledDcx(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledDcx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv({q[0], q[1], q[3], q[2]}, [&](ValueRange qubits) { b.mcdcx({qubits[0], qubits[1]}, qubits[2], qubits[3]); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> ecr(QCProgramBuilder& b) { +SmallVector ecr(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ecr(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledEcr(QCProgramBuilder& b) { +SmallVector singleControlledEcr(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cecr(q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledEcr(QCProgramBuilder& b) { +SmallVector multipleControlledEcr(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcecr({q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledEcr(QCProgramBuilder& b) { +SmallVector nestedControlledEcr(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { b.cecr(targets[0], targets[1], targets[2]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledEcr(QCProgramBuilder& b) { +SmallVector trivialControlledEcr(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcecr({}, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseEcr(QCProgramBuilder& b) { +SmallVector inverseEcr(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.ecr(qubits[0], qubits[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledEcr(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledEcr(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { b.mcecr({qubits[0], qubits[1]}, qubits[2], qubits[3]); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> rxx(QCProgramBuilder& b) { +SmallVector rxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rxx(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRxx(QCProgramBuilder& b) { +SmallVector singleControlledRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crxx(0.123, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRxx(QCProgramBuilder& b) { +SmallVector multipleControlledRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRxx(QCProgramBuilder& b) { +SmallVector nestedControlledRxx(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { b.crxx(0.123, targets[0], targets[1], targets[2]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRxx(QCProgramBuilder& b) { +SmallVector trivialControlledRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcrxx(0.123, {}, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRxx(QCProgramBuilder& b) { +SmallVector inverseRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.rxx(-0.123, qubits[0], qubits[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledRxx(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { b.mcrxx(-0.123, {qubits[0], qubits[1]}, qubits[2], qubits[3]); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -tripleControlledRxx(QCProgramBuilder& b) { +SmallVector tripleControlledRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(5); b.mcrxx(0.123, {q[0], q[1], q[2]}, q[3], q[4]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -fourControlledRxx(QCProgramBuilder& b) { +SmallVector fourControlledRxx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(6); b.mcrxx(0.123, {q[0], q[1], q[2], q[3]}, q[4], q[5]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4], q[5]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> ryy(QCProgramBuilder& b) { +SmallVector ryy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ryy(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRyy(QCProgramBuilder& b) { +SmallVector singleControlledRyy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cryy(0.123, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRyy(QCProgramBuilder& b) { +SmallVector multipleControlledRyy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcryy(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRyy(QCProgramBuilder& b) { +SmallVector nestedControlledRyy(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { b.cryy(0.123, targets[0], targets[1], targets[2]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRyy(QCProgramBuilder& b) { +SmallVector trivialControlledRyy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcryy(0.123, {}, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRyy(QCProgramBuilder& b) { +SmallVector inverseRyy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.ryy(-0.123, qubits[0], qubits[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledRyy(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledRyy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { b.mcryy(-0.123, {qubits[0], qubits[1]}, qubits[2], qubits[3]); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> rzx(QCProgramBuilder& b) { +SmallVector rzx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rzx(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRzx(QCProgramBuilder& b) { +SmallVector singleControlledRzx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crzx(0.123, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRzx(QCProgramBuilder& b) { +SmallVector multipleControlledRzx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrzx(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRzx(QCProgramBuilder& b) { +SmallVector nestedControlledRzx(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { b.crzx(0.123, targets[0], targets[1], targets[2]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRzx(QCProgramBuilder& b) { +SmallVector trivialControlledRzx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcrzx(0.123, {}, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRzx(QCProgramBuilder& b) { +SmallVector inverseRzx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.rzx(-0.123, qubits[0], qubits[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledRzx(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledRzx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { b.mcrzx(-0.123, {qubits[0], qubits[1]}, qubits[2], qubits[3]); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> rzz(QCProgramBuilder& b) { +SmallVector rzz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rzz(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRzz(QCProgramBuilder& b) { +SmallVector singleControlledRzz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crzz(0.123, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRzz(QCProgramBuilder& b) { +SmallVector multipleControlledRzz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrzz(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRzz(QCProgramBuilder& b) { +SmallVector nestedControlledRzz(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { b.crzz(0.123, targets[0], targets[1], targets[2]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRzz(QCProgramBuilder& b) { +SmallVector trivialControlledRzz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcrzz(0.123, {}, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRzz(QCProgramBuilder& b) { +SmallVector inverseRzz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.rzz(-0.123, qubits[0], qubits[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledRzz(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledRzz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { b.mcrzz(-0.123, {qubits[0], qubits[1]}, qubits[2], qubits[3]); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> xxPlusYY(QCProgramBuilder& b) { +SmallVector xxPlusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.xx_plus_yy(0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledXxPlusYY(QCProgramBuilder& b) { +SmallVector singleControlledXxPlusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cxx_plus_yy(0.123, 0.456, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledXxPlusYY(QCProgramBuilder& b) { +SmallVector multipleControlledXxPlusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcxx_plus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledXxPlusYY(QCProgramBuilder& b) { +SmallVector nestedControlledXxPlusYY(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { b.cxx_plus_yy(0.123, 0.456, targets[0], targets[1], targets[2]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledXxPlusYY(QCProgramBuilder& b) { +SmallVector trivialControlledXxPlusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcxx_plus_yy(0.123, 0.456, {}, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseXxPlusYY(QCProgramBuilder& b) { +SmallVector inverseXxPlusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.xx_plus_yy(-0.123, 0.456, qubits[0], qubits[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledXxPlusYY(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledXxPlusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { b.mcxx_plus_yy(-0.123, 0.456, {qubits[0], qubits[1]}, qubits[2], qubits[3]); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -xxMinusYY(QCProgramBuilder& b) { +SmallVector xxMinusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.xx_minus_yy(0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledXxMinusYY(QCProgramBuilder& b) { +SmallVector singleControlledXxMinusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cxx_minus_yy(0.123, 0.456, q[0], q[1], q[2]); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledXxMinusYY(QCProgramBuilder& b) { +SmallVector multipleControlledXxMinusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcxx_minus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledXxMinusYY(QCProgramBuilder& b) { +SmallVector nestedControlledXxMinusYY(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.ctrl(reg[0], {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { b.cxx_minus_yy(0.123, 0.456, targets[0], targets[1], targets[2]); }); - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledXxMinusYY(QCProgramBuilder& b) { +SmallVector trivialControlledXxMinusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.mcxx_minus_yy(0.123, 0.456, {}, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseXxMinusYY(QCProgramBuilder& b) { +SmallVector inverseXxMinusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.xx_minus_yy(-0.123, 0.456, qubits[0], qubits[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledXxMinusYY(QCProgramBuilder& b) { +SmallVector inverseMultipleControlledXxMinusYY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { b.mcxx_minus_yy(-0.123, 0.456, {qubits[0], qubits[1]}, qubits[2], qubits[3]); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> barrier(QCProgramBuilder& b) { +SmallVector barrier(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.barrier(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -barrierTwoQubits(QCProgramBuilder& b) { +SmallVector barrierTwoQubits(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.barrier({q[0], q[1]}); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -barrierMultipleQubits(QCProgramBuilder& b) { +SmallVector barrierMultipleQubits(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.barrier({q[0], q[1], q[2]}); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledBarrier(QCProgramBuilder& b) { +SmallVector singleControlledBarrier(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ctrl(q[1], q[0], [&](Value target) { b.barrier({target}); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseBarrier(QCProgramBuilder& b) { +SmallVector inverseBarrier(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.barrier(qubit); }); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -trivialCtrl(QCProgramBuilder& b) { +SmallVector trivialCtrl(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ctrl({}, {q[0], q[1]}, [&](ValueRange targets) { b.rxx(0.123, targets[0], targets[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -emptyCtrl(QCProgramBuilder& b) { +SmallVector emptyCtrl(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rxx(0.123, q[0], q[1]); b.ctrl(q[0], q[1], [&](Value /*target*/) {}); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedCtrl(QCProgramBuilder& b) { +SmallVector nestedCtrl(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.ctrl(q[0], {q[1], q[2], q[3]}, [&](ValueRange targets) { b.ctrl(targets[0], {targets[1], targets[2]}, [&](ValueRange innerTargets) { b.rxx(0.123, innerTargets[0], innerTargets[1]); }); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -tripleNestedCtrl(QCProgramBuilder& b) { +SmallVector tripleNestedCtrl(QCProgramBuilder& b) { auto q = b.allocQubitRegister(5); b.ctrl(q[0], {q[1], q[2], q[3], q[4]}, [&](ValueRange targets) { b.ctrl(targets[0], {targets[1], targets[2], targets[3]}, @@ -1924,11 +1698,10 @@ tripleNestedCtrl(QCProgramBuilder& b) { }); }); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -doubleNestedCtrlTwoQubits(QCProgramBuilder& b) { +SmallVector doubleNestedCtrlTwoQubits(QCProgramBuilder& b) { auto q = b.allocQubitRegister(6); b.ctrl({q[0], q[1]}, {q[2], q[3], q[4], q[5]}, [&](ValueRange targets) { b.ctrl({targets[0], targets[1]}, {targets[2], targets[3]}, @@ -1936,11 +1709,10 @@ doubleNestedCtrlTwoQubits(QCProgramBuilder& b) { b.rxx(0.123, innerTargets[0], innerTargets[1]); }); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4], q[5]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -ctrlInvSandwich(QCProgramBuilder& b) { +SmallVector ctrlInvSandwich(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.ctrl(q[0], {q[1], q[2], q[3]}, [&](ValueRange targets) { b.inv(targets, [&](ValueRange qubits) { @@ -1949,30 +1721,28 @@ ctrlInvSandwich(QCProgramBuilder& b) { }); }); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> ctrlTwo(QCProgramBuilder& b) { +SmallVector ctrlTwo(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.ctrl({q[0], q[1]}, {q[2], q[3]}, [&](ValueRange targets) { b.x(targets[0]); b.rxx(0.123, targets[0], targets[1]); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -ctrlTwoMixed(QCProgramBuilder& b) { +SmallVector ctrlTwoMixed(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.ctrl({q[0], q[1]}, {q[2], q[3]}, [&](ValueRange targets) { b.cx(targets[0], targets[1]); b.rxx(0.123, targets[0], targets[1]); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedCtrlTwo(QCProgramBuilder& b) { +SmallVector nestedCtrlTwo(QCProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.ctrl(q[0], {q[1], q[2], q[3]}, [&](ValueRange targets) { b.ctrl(targets[0], {targets[1], targets[2]}, [&](ValueRange innerTargets) { @@ -1980,11 +1750,10 @@ nestedCtrlTwo(QCProgramBuilder& b) { b.rxx(0.123, innerTargets[0], innerTargets[1]); }); }); - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -ctrlInvTwo(QCProgramBuilder& b) { +SmallVector ctrlInvTwo(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.ctrl(q[0], {q[1], q[2]}, [&](ValueRange targets) { b.inv(targets, [&](ValueRange qubits) { @@ -1992,29 +1761,27 @@ ctrlInvTwo(QCProgramBuilder& b) { b.rxx(0.123, qubits[0], qubits[1]); }); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> emptyInv(QCProgramBuilder& b) { +SmallVector emptyInv(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rxx(0.123, q[0], q[1]); b.inv({q[0], q[1]}, [&](ValueRange /*targets*/) {}); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedInv(QCProgramBuilder& b) { +SmallVector nestedInv(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.inv(qubits, [&](ValueRange innerQubits) { b.rxx(0.123, innerQubits[0], innerQubits[1]); }); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -tripleNestedInv(QCProgramBuilder& b) { +SmallVector tripleNestedInv(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.inv(qubits, [&](ValueRange innerQubits) { @@ -2023,11 +1790,10 @@ tripleNestedInv(QCProgramBuilder& b) { }); }); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -invCtrlSandwich(QCProgramBuilder& b) { +SmallVector invCtrlSandwich(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.ctrl(qubits[0], {qubits[1], qubits[2]}, [&](ValueRange targets) { @@ -2036,20 +1802,19 @@ invCtrlSandwich(QCProgramBuilder& b) { }); }); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> invTwo(QCProgramBuilder& b) { +SmallVector invTwo(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.inv({q[0], q[1]}, [&](ValueRange qubits) { b.x(qubits[0]); b.rxx(0.123, qubits[0], qubits[1]); }); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -invCtrlTwo(QCProgramBuilder& b) { +SmallVector invCtrlTwo(QCProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { b.ctrl(qubits[0], {qubits[1], qubits[2]}, [&](ValueRange targets) { @@ -2057,29 +1822,28 @@ invCtrlTwo(QCProgramBuilder& b) { b.rxx(0.123, targets[0], targets[1]); }); }); - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> simpleIf(QCProgramBuilder& b) { +SmallVector simpleIf(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); auto cond = b.measure(q[0]); b.scfIf(cond, [&] { b.x(q[0]); }); auto res = b.measure(q[0]); - return {{cond, res}, {b.getI1Type(), b.getI1Type()}}; + return {cond, res}; } -std::pair, SmallVector> ifElse(QCProgramBuilder& b) { +SmallVector ifElse(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); auto cond = b.measure(q[0]); b.scfIf(cond, [&] { b.x(q[0]); }, [&] { b.z(q[0]); }); auto bit = b.measure(q[0]); - return {{cond, bit}, {b.getI1Type(), b.getI1Type()}}; + return {cond, bit}; } -std::pair, SmallVector> -ifTwoQubits(QCProgramBuilder& b) { +SmallVector ifTwoQubits(QCProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.h(q[0]); auto cond = b.measure(q[0]); @@ -2089,11 +1853,10 @@ ifTwoQubits(QCProgramBuilder& b) { }); auto c0 = b.measure(q[0]); auto c1 = b.measure(q[1]); - return {{cond, c0, c1}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; + return {cond, c0, c1}; } -std::pair, SmallVector> -nestedIfOpForLoop(QCProgramBuilder& b) { +SmallVector nestedIfOpForLoop(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); b.h(q0); @@ -2109,8 +1872,7 @@ nestedIfOpForLoop(QCProgramBuilder& b) { return measureAndReturn(b, {q0}); } -std::pair, SmallVector> -simpleWhileReset(QCProgramBuilder& b) { +SmallVector simpleWhileReset(QCProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); b.scfWhile( @@ -2122,8 +1884,7 @@ simpleWhileReset(QCProgramBuilder& b) { return measureAndReturn(b, {q}); } -std::pair, SmallVector> -simpleDoWhileReset(QCProgramBuilder& b) { +SmallVector simpleDoWhileReset(QCProgramBuilder& b) { auto q = b.allocQubit(); b.scfWhile( [&] { @@ -2135,18 +1896,16 @@ simpleDoWhileReset(QCProgramBuilder& b) { return measureAndReturn(b, {q}); } -std::pair, SmallVector> -simpleForLoop(QCProgramBuilder& b) { +SmallVector simpleForLoop(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(2); b.scfFor(0, 2, 1, [&](Value iv) { auto q = b.memrefLoad(reg.value, iv); b.h(q); }); - return measureAndReturn(b, {reg[0], reg[1]}); + return measureAndReturn(b, reg.qubits); }; -std::pair, SmallVector> -nestedForLoopIfOp(QCProgramBuilder& b) { +SmallVector nestedForLoopIfOp(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto qCond = b.allocQubit(); b.scfFor(0, 2, 1, [&](Value iv) { @@ -2160,8 +1919,7 @@ nestedForLoopIfOp(QCProgramBuilder& b) { return measureAndReturn(b, {qCond}); } -std::pair, SmallVector> -nestedForLoopWhileOp(QCProgramBuilder& b) { +SmallVector nestedForLoopWhileOp(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(2); b.scfFor(0, 2, 1, [&](Value iv) { auto q = b.memrefLoad(reg.value, iv); @@ -2176,11 +1934,10 @@ nestedForLoopWhileOp(QCProgramBuilder& b) { }, [&] { b.h(q); }); }); - return measureAndReturn(b, {reg[0], reg[1]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b) { +SmallVector nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto control = b.allocQubit(); b.h(control); @@ -2192,8 +1949,7 @@ nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b) { return measureAndReturn(b, {control}); } -std::pair, SmallVector> -nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b) { +SmallVector nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.h(reg[0]); b.scfFor(1, 4, 1, [&](Value iv) { diff --git a/mlir/unittests/programs/qc_programs.h b/mlir/unittests/programs/qc_programs.h index 5f13ec734d..fc041ca1a8 100644 --- a/mlir/unittests/programs/qc_programs.h +++ b/mlir/unittests/programs/qc_programs.h @@ -10,1162 +10,934 @@ #pragma once -#include #include #include -#include - namespace mlir::qc { class QCProgramBuilder; /// Creates an empty QC Program. -std::pair, SmallVector> -emptyQC(QCProgramBuilder& builder); +SmallVector emptyQC(QCProgramBuilder& b); // --- Qubit Management ----------------------------------------------------- // /// Allocates a single qubit. -std::pair, SmallVector> -allocQubit(QCProgramBuilder& b); +SmallVector allocQubit(QCProgramBuilder& b); /// Allocates a single qubit without measuring it. -std::pair, SmallVector> -allocQubitNoMeasure(QCProgramBuilder& b); +SmallVector allocQubitNoMeasure(QCProgramBuilder& b); /// Allocates a qubit register of size `1`. -std::pair, SmallVector> -alloc1QubitRegister(QCProgramBuilder& b); +SmallVector alloc1QubitRegister(QCProgramBuilder& b); /// Allocates a qubit register of size `2`. -std::pair, SmallVector> -allocQubitRegister(QCProgramBuilder& b); +SmallVector allocQubitRegister(QCProgramBuilder& b); /// Allocates a qubit register of size `3`. -std::pair, SmallVector> -alloc3QubitRegister(QCProgramBuilder& b); +SmallVector alloc3QubitRegister(QCProgramBuilder& b); /// Allocates two qubit registers of size `2` and `3`. -std::pair, SmallVector> -allocMultipleQubitRegisters(QCProgramBuilder& b); +SmallVector allocMultipleQubitRegisters(QCProgramBuilder& b); /// Allocates two qubit registers of size `2` and `3` and applies operations. -std::pair, SmallVector> -allocMultipleQubitRegistersWithOps(QCProgramBuilder& b); +SmallVector allocMultipleQubitRegistersWithOps(QCProgramBuilder& b); /// Allocates a large qubit register. -std::pair, SmallVector> -allocLargeRegister(QCProgramBuilder& b); +SmallVector allocLargeRegister(QCProgramBuilder& b); /// Allocates two inline qubits. -std::pair, SmallVector> -staticQubits(QCProgramBuilder& b); +SmallVector staticQubits(QCProgramBuilder& b); /// Allocates two inline qubits without measuring them. -std::pair, SmallVector> -staticQubitsNoMeasure(QCProgramBuilder& b); +SmallVector staticQubitsNoMeasure(QCProgramBuilder& b); /// Allocates two static qubits and applies operations. -std::pair, SmallVector> -staticQubitsWithOps(QCProgramBuilder& b); +SmallVector staticQubitsWithOps(QCProgramBuilder& b); /// Allocates two static qubits and applies parametric gates. -std::pair, SmallVector> -staticQubitsWithParametricOps(QCProgramBuilder& b); +SmallVector staticQubitsWithParametricOps(QCProgramBuilder& b); /// Allocates two static qubits and applies a two-target gate. -std::pair, SmallVector> -staticQubitsWithTwoTargetOps(QCProgramBuilder& b); +SmallVector staticQubitsWithTwoTargetOps(QCProgramBuilder& b); /// Allocates two static qubits and applies a controlled gate. -std::pair, SmallVector> -staticQubitsWithCtrl(QCProgramBuilder& b); +SmallVector staticQubitsWithCtrl(QCProgramBuilder& b); /// Allocates a static qubit and applies an inverse modifier. -std::pair, SmallVector> -staticQubitsWithInv(QCProgramBuilder& b); +SmallVector staticQubitsWithInv(QCProgramBuilder& b); /// Allocates duplicate static qubits and applies operations on both. -std::pair, SmallVector> -staticQubitsWithDuplicates(QCProgramBuilder& b); +SmallVector staticQubitsWithDuplicates(QCProgramBuilder& b); /// Same as `staticQubitsWithDuplicates`, but with canonical static qubit /// retrievals. -std::pair, SmallVector> -staticQubitsCanonical(QCProgramBuilder& b); +SmallVector staticQubitsCanonical(QCProgramBuilder& b); /// Allocates and explicitly deallocates a single qubit. -std::pair, SmallVector> -allocDeallocPair(QCProgramBuilder& b); +SmallVector allocDeallocPair(QCProgramBuilder& b); // --- Invalid / mixed addressing (unit tests) -------------------------------- /// @pre `builder.initialize()`. Fatal mixed addressing: static then dynamic /// alloc. -std::pair, SmallVector> -mixedStaticThenDynamicQubit(QCProgramBuilder& b); +SmallVector mixedStaticThenDynamicQubit(QCProgramBuilder& b); /// @pre `builder.initialize()`. Fatal mixed addressing: dynamic register then /// static. -std::pair, SmallVector> -mixedDynamicRegisterThenStaticQubit(QCProgramBuilder& b); +SmallVector mixedDynamicRegisterThenStaticQubit(QCProgramBuilder& b); // --- MeasureOp ------------------------------------------------------------ // /// Measures a single qubit into a single classical bit. -std::pair, SmallVector> -singleMeasurementToSingleBit(QCProgramBuilder& b); +SmallVector singleMeasurementToSingleBit(QCProgramBuilder& b); /// Repeatedly measures a single qubit into the same classical bit. -std::pair, SmallVector> -repeatedMeasurementToSameBit(QCProgramBuilder& b); +SmallVector repeatedMeasurementToSameBit(QCProgramBuilder& b); /// Repeatedly measures a single qubit into different classical bits. -std::pair, SmallVector> -repeatedMeasurementToDifferentBits(QCProgramBuilder& b); +SmallVector repeatedMeasurementToDifferentBits(QCProgramBuilder& b); /// Measures multiple qubits into multiple classical bits. -std::pair, SmallVector> +SmallVector multipleClassicalRegistersAndMeasurements(QCProgramBuilder& b); /// Measures a single qubit into a single classical bit, without explicitly /// allocating a quantum or classical register. -std::pair, SmallVector> -measurementWithoutRegisters(QCProgramBuilder& b); +SmallVector measurementWithoutRegisters(QCProgramBuilder& b); // --- ResetOp -------------------------------------------------------------- // /// Resets a single qubit without any operations being applied. -std::pair, SmallVector> -resetQubitWithoutOp(QCProgramBuilder& b); +SmallVector resetQubitWithoutOp(QCProgramBuilder& b); /// Resets multiple qubits without any operations being applied. -std::pair, SmallVector> -resetMultipleQubitsWithoutOp(QCProgramBuilder& b); +SmallVector resetMultipleQubitsWithoutOp(QCProgramBuilder& b); /// Repeatedly resets a single qubit without any operations being applied. -std::pair, SmallVector> -repeatedResetWithoutOp(QCProgramBuilder& b); +SmallVector repeatedResetWithoutOp(QCProgramBuilder& b); /// Resets a single qubit after a single operation. -std::pair, SmallVector> -resetQubitAfterSingleOp(QCProgramBuilder& b); +SmallVector resetQubitAfterSingleOp(QCProgramBuilder& b); /// Resets multiple qubits after a single operation. -std::pair, SmallVector> -resetMultipleQubitsAfterSingleOp(QCProgramBuilder& b); +SmallVector resetMultipleQubitsAfterSingleOp(QCProgramBuilder& b); /// Repeatedly resets a single qubit after a single operation. -std::pair, SmallVector> -repeatedResetAfterSingleOp(QCProgramBuilder& b); +SmallVector repeatedResetAfterSingleOp(QCProgramBuilder& b); // --- GPhaseOp ------------------------------------------------------------- // /// Creates a circuit with just a global phase. -std::pair, SmallVector> -globalPhase(QCProgramBuilder& b); +SmallVector globalPhase(QCProgramBuilder& b); /// Creates a circuit with just a global phase and a single measured qubit. -std::pair, SmallVector> -globalPhaseAndMeasure(QCProgramBuilder& b); +SmallVector globalPhaseAndMeasure(QCProgramBuilder& b); /// Creates a controlled global phase gate with a single control qubit. -std::pair, SmallVector> -singleControlledGlobalPhase(QCProgramBuilder& b); +SmallVector singleControlledGlobalPhase(QCProgramBuilder& b); /// Creates a multi-controlled global phase gate with multiple control qubits. -std::pair, SmallVector> -multipleControlledGlobalPhase(QCProgramBuilder& b); +SmallVector multipleControlledGlobalPhase(QCProgramBuilder& b); /// Creates a circuit with a nested controlled global phase gate. -std::pair, SmallVector> -nestedControlledGlobalPhase(QCProgramBuilder& b); +SmallVector nestedControlledGlobalPhase(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled global phase gate. -std::pair, SmallVector> -trivialControlledGlobalPhase(QCProgramBuilder& b); +SmallVector trivialControlledGlobalPhase(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a global phase gate. -std::pair, SmallVector> -inverseGlobalPhase(QCProgramBuilder& b); +SmallVector inverseGlobalPhase(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled global /// phase gate. -std::pair, SmallVector> -inverseMultipleControlledGlobalPhase(QCProgramBuilder& b); +SmallVector inverseMultipleControlledGlobalPhase(QCProgramBuilder& b); // --- IdOp ----------------------------------------------------------------- // /// Creates a circuit with just an identity gate. -std::pair, SmallVector> identity(QCProgramBuilder& b); +SmallVector identity(QCProgramBuilder& b); /// Creates a controlled identity gate with a single control qubit. -std::pair, SmallVector> -singleControlledIdentity(QCProgramBuilder& b); +SmallVector singleControlledIdentity(QCProgramBuilder& b); /// Creates an identity gate on a single qubit in a two-qubit register. -std::pair, SmallVector> -twoQubitsOneIdentity(QCProgramBuilder& b); +SmallVector twoQubitsOneIdentity(QCProgramBuilder& b); /// Creates an identity gate on a single qubit in a three-qubit register. -std::pair, SmallVector> -threeQubitsOneIdentity(QCProgramBuilder& b); +SmallVector threeQubitsOneIdentity(QCProgramBuilder& b); /// Creates a multi-controlled identity gate with multiple control qubits. -std::pair, SmallVector> -multipleControlledIdentity(QCProgramBuilder& b); +SmallVector multipleControlledIdentity(QCProgramBuilder& b); /// Creates an barrier gate on a single qubit in a two-qubit register. -std::pair, SmallVector> -twoQubitsOneBarrier(QCProgramBuilder& b); +SmallVector twoQubitsOneBarrier(QCProgramBuilder& b); /// Creates a circuit with a nested controlled identity gate. -std::pair, SmallVector> -nestedControlledIdentity(QCProgramBuilder& b); +SmallVector nestedControlledIdentity(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled identity gate. -std::pair, SmallVector> -trivialControlledIdentity(QCProgramBuilder& b); +SmallVector trivialControlledIdentity(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an identity gate. -std::pair, SmallVector> -inverseIdentity(QCProgramBuilder& b); +SmallVector inverseIdentity(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled identity /// gate. -std::pair, SmallVector> -inverseMultipleControlledIdentity(QCProgramBuilder& b); +SmallVector inverseMultipleControlledIdentity(QCProgramBuilder& b); // --- XOp ------------------------------------------------------------------ // /// Creates a circuit with just an X gate. -std::pair, SmallVector> x(QCProgramBuilder& b); +SmallVector x(QCProgramBuilder& b); /// Creates a circuit with a single controlled X gate. -std::pair, SmallVector> -singleControlledX(QCProgramBuilder& b); +SmallVector singleControlledX(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled X gate. -std::pair, SmallVector> -multipleControlledX(QCProgramBuilder& b); +SmallVector multipleControlledX(QCProgramBuilder& b); /// Creates a circuit with a nested controlled X gate. -std::pair, SmallVector> -nestedControlledX(QCProgramBuilder& b); +SmallVector nestedControlledX(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled X gate. -std::pair, SmallVector> -trivialControlledX(QCProgramBuilder& b); +SmallVector trivialControlledX(QCProgramBuilder& b); /// Creates a circuit with repeated controlled X gates. -std::pair, SmallVector> -repeatedControlledX(QCProgramBuilder& b); +SmallVector repeatedControlledX(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an X gate. -std::pair, SmallVector> inverseX(QCProgramBuilder& b); +SmallVector inverseX(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled X gate. -std::pair, SmallVector> -inverseMultipleControlledX(QCProgramBuilder& b); +SmallVector inverseMultipleControlledX(QCProgramBuilder& b); // --- YOp ------------------------------------------------------------------ // /// Creates a circuit with just a Y gate. -std::pair, SmallVector> y(QCProgramBuilder& b); +SmallVector y(QCProgramBuilder& b); /// Creates a circuit with a single controlled Y gate. -std::pair, SmallVector> -singleControlledY(QCProgramBuilder& b); +SmallVector singleControlledY(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled Y gate. -std::pair, SmallVector> -multipleControlledY(QCProgramBuilder& b); +SmallVector multipleControlledY(QCProgramBuilder& b); /// Creates a circuit with a nested controlled Y gate. -std::pair, SmallVector> -nestedControlledY(QCProgramBuilder& b); +SmallVector nestedControlledY(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled Y gate. -std::pair, SmallVector> -trivialControlledY(QCProgramBuilder& b); +SmallVector trivialControlledY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Y gate. -std::pair, SmallVector> inverseY(QCProgramBuilder& b); +SmallVector inverseY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Y gate. -std::pair, SmallVector> -inverseMultipleControlledY(QCProgramBuilder& b); +SmallVector inverseMultipleControlledY(QCProgramBuilder& b); // --- ZOp ------------------------------------------------------------------ // /// Creates a circuit with just a Z gate. -std::pair, SmallVector> z(QCProgramBuilder& b); +SmallVector z(QCProgramBuilder& b); /// Creates a circuit with a single controlled Z gate. -std::pair, SmallVector> -singleControlledZ(QCProgramBuilder& b); +SmallVector singleControlledZ(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled Z gate. -std::pair, SmallVector> -multipleControlledZ(QCProgramBuilder& b); +SmallVector multipleControlledZ(QCProgramBuilder& b); /// Creates a circuit with a nested controlled Z gate. -std::pair, SmallVector> -nestedControlledZ(QCProgramBuilder& b); +SmallVector nestedControlledZ(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled Z gate. -std::pair, SmallVector> -trivialControlledZ(QCProgramBuilder& b); +SmallVector trivialControlledZ(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Z gate. -std::pair, SmallVector> inverseZ(QCProgramBuilder& b); +SmallVector inverseZ(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Z gate. -std::pair, SmallVector> -inverseMultipleControlledZ(QCProgramBuilder& b); +SmallVector inverseMultipleControlledZ(QCProgramBuilder& b); // --- HOp ------------------------------------------------------------------ // /// Creates a circuit with just an H gate. -std::pair, SmallVector> h(QCProgramBuilder& b); +SmallVector h(QCProgramBuilder& b); /// Creates a circuit with a single controlled H gate. -std::pair, SmallVector> -singleControlledH(QCProgramBuilder& b); +SmallVector singleControlledH(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled H gate. -std::pair, SmallVector> -multipleControlledH(QCProgramBuilder& b); +SmallVector multipleControlledH(QCProgramBuilder& b); /// Creates a circuit with a nested controlled H gate. -std::pair, SmallVector> -nestedControlledH(QCProgramBuilder& b); +SmallVector nestedControlledH(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled H gate. -std::pair, SmallVector> -trivialControlledH(QCProgramBuilder& b); +SmallVector trivialControlledH(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an H gate. -std::pair, SmallVector> inverseH(QCProgramBuilder& b); +SmallVector inverseH(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled H gate. -std::pair, SmallVector> -inverseMultipleControlledH(QCProgramBuilder& b); +SmallVector inverseMultipleControlledH(QCProgramBuilder& b); /// Creates a circuit with just an H gate and no qubit register. -std::pair, SmallVector> -hWithoutRegister(QCProgramBuilder& b); +SmallVector hWithoutRegister(QCProgramBuilder& b); // --- SOp ------------------------------------------------------------------ // /// Creates a circuit with just an S gate. -std::pair, SmallVector> s(QCProgramBuilder& b); +SmallVector s(QCProgramBuilder& b); /// Creates a circuit with a single controlled S gate. -std::pair, SmallVector> -singleControlledS(QCProgramBuilder& b); +SmallVector singleControlledS(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled S gate. -std::pair, SmallVector> -multipleControlledS(QCProgramBuilder& b); +SmallVector multipleControlledS(QCProgramBuilder& b); /// Creates a circuit with a nested controlled S gate. -std::pair, SmallVector> -nestedControlledS(QCProgramBuilder& b); +SmallVector nestedControlledS(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled S gate. -std::pair, SmallVector> -trivialControlledS(QCProgramBuilder& b); +SmallVector trivialControlledS(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an S gate. -std::pair, SmallVector> inverseS(QCProgramBuilder& b); +SmallVector inverseS(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled S gate. -std::pair, SmallVector> -inverseMultipleControlledS(QCProgramBuilder& b); +SmallVector inverseMultipleControlledS(QCProgramBuilder& b); // --- SdgOp ---------------------------------------------------------------- // /// Creates a circuit with just an Sdg gate. -std::pair, SmallVector> sdg(QCProgramBuilder& b); +SmallVector sdg(QCProgramBuilder& b); /// Creates a circuit with a single controlled Sdg gate. -std::pair, SmallVector> -singleControlledSdg(QCProgramBuilder& b); +SmallVector singleControlledSdg(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled Sdg gate. -std::pair, SmallVector> -multipleControlledSdg(QCProgramBuilder& b); +SmallVector multipleControlledSdg(QCProgramBuilder& b); /// Creates a circuit with a nested controlled Sdg gate. -std::pair, SmallVector> -nestedControlledSdg(QCProgramBuilder& b); +SmallVector nestedControlledSdg(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled Sdg gate. -std::pair, SmallVector> -trivialControlledSdg(QCProgramBuilder& b); +SmallVector trivialControlledSdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an Sdg gate. -std::pair, SmallVector> -inverseSdg(QCProgramBuilder& b); +SmallVector inverseSdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Sdg gate. -std::pair, SmallVector> -inverseMultipleControlledSdg(QCProgramBuilder& b); +SmallVector inverseMultipleControlledSdg(QCProgramBuilder& b); // --- TOp ------------------------------------------------------------------ // /// Creates a circuit with just a T gate. -std::pair, SmallVector> -t_(QCProgramBuilder& b); // NOLINT(*-identifier-naming) +SmallVector t_(QCProgramBuilder& b); // NOLINT(*-identifier-naming) /// Creates a circuit with a single controlled T gate. -std::pair, SmallVector> -singleControlledT(QCProgramBuilder& b); +SmallVector singleControlledT(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled T gate. -std::pair, SmallVector> -multipleControlledT(QCProgramBuilder& b); +SmallVector multipleControlledT(QCProgramBuilder& b); /// Creates a circuit with a nested controlled T gate. -std::pair, SmallVector> -nestedControlledT(QCProgramBuilder& b); +SmallVector nestedControlledT(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled T gate. -std::pair, SmallVector> -trivialControlledT(QCProgramBuilder& b); +SmallVector trivialControlledT(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a T gate. -std::pair, SmallVector> inverseT(QCProgramBuilder& b); +SmallVector inverseT(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled T gate. -std::pair, SmallVector> -inverseMultipleControlledT(QCProgramBuilder& b); +SmallVector inverseMultipleControlledT(QCProgramBuilder& b); // --- TdgOp ---------------------------------------------------------------- // /// Creates a circuit with just a Tdg gate. -std::pair, SmallVector> tdg(QCProgramBuilder& b); +SmallVector tdg(QCProgramBuilder& b); /// Creates a circuit with a single controlled Tdg gate. -std::pair, SmallVector> -singleControlledTdg(QCProgramBuilder& b); +SmallVector singleControlledTdg(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled Tdg gate. -std::pair, SmallVector> -multipleControlledTdg(QCProgramBuilder& b); +SmallVector multipleControlledTdg(QCProgramBuilder& b); /// Creates a circuit with a nested controlled Tdg gate. -std::pair, SmallVector> -nestedControlledTdg(QCProgramBuilder& b); +SmallVector nestedControlledTdg(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled Tdg gate. -std::pair, SmallVector> -trivialControlledTdg(QCProgramBuilder& b); +SmallVector trivialControlledTdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Tdg gate. -std::pair, SmallVector> -inverseTdg(QCProgramBuilder& b); +SmallVector inverseTdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Tdg gate. -std::pair, SmallVector> -inverseMultipleControlledTdg(QCProgramBuilder& b); +SmallVector inverseMultipleControlledTdg(QCProgramBuilder& b); // --- SXOp ----------------------------------------------------------------- // /// Creates a circuit with just an SX gate. -std::pair, SmallVector> sx(QCProgramBuilder& b); +SmallVector sx(QCProgramBuilder& b); /// Creates a circuit with a single controlled SX gate. -std::pair, SmallVector> -singleControlledSx(QCProgramBuilder& b); +SmallVector singleControlledSx(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled SX gate. -std::pair, SmallVector> -multipleControlledSx(QCProgramBuilder& b); +SmallVector multipleControlledSx(QCProgramBuilder& b); /// Creates a circuit with a nested controlled SX gate. -std::pair, SmallVector> -nestedControlledSx(QCProgramBuilder& b); +SmallVector nestedControlledSx(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled SX gate. -std::pair, SmallVector> -trivialControlledSx(QCProgramBuilder& b); +SmallVector trivialControlledSx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an SX gate. -std::pair, SmallVector> inverseSx(QCProgramBuilder& b); +SmallVector inverseSx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SX gate. -std::pair, SmallVector> -inverseMultipleControlledSx(QCProgramBuilder& b); +SmallVector inverseMultipleControlledSx(QCProgramBuilder& b); // --- SXdgOp --------------------------------------------------------------- // /// Creates a circuit with just an SXdg gate. -std::pair, SmallVector> sxdg(QCProgramBuilder& b); +SmallVector sxdg(QCProgramBuilder& b); /// Creates a circuit with a single controlled SXdg gate. -std::pair, SmallVector> -singleControlledSxdg(QCProgramBuilder& b); +SmallVector singleControlledSxdg(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled SXdg gate. -std::pair, SmallVector> -multipleControlledSxdg(QCProgramBuilder& b); +SmallVector multipleControlledSxdg(QCProgramBuilder& b); /// Creates a circuit with a nested controlled SXdg gate. -std::pair, SmallVector> -nestedControlledSxdg(QCProgramBuilder& b); +SmallVector nestedControlledSxdg(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled SXdg gate. -std::pair, SmallVector> -trivialControlledSxdg(QCProgramBuilder& b); +SmallVector trivialControlledSxdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an SXdg gate. -std::pair, SmallVector> -inverseSxdg(QCProgramBuilder& b); +SmallVector inverseSxdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SXdg /// gate. -std::pair, SmallVector> -inverseMultipleControlledSxdg(QCProgramBuilder& b); +SmallVector inverseMultipleControlledSxdg(QCProgramBuilder& b); // --- RXOp ----------------------------------------------------------------- // /// Creates a circuit with just an RX gate. -std::pair, SmallVector> rx(QCProgramBuilder& b); +SmallVector rx(QCProgramBuilder& b); /// Creates a circuit with a single controlled RX gate. -std::pair, SmallVector> -singleControlledRx(QCProgramBuilder& b); +SmallVector singleControlledRx(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RX gate. -std::pair, SmallVector> -multipleControlledRx(QCProgramBuilder& b); +SmallVector multipleControlledRx(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RX gate. -std::pair, SmallVector> -nestedControlledRx(QCProgramBuilder& b); +SmallVector nestedControlledRx(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RX gate. -std::pair, SmallVector> -trivialControlledRx(QCProgramBuilder& b); +SmallVector trivialControlledRx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RX gate. -std::pair, SmallVector> inverseRx(QCProgramBuilder& b); +SmallVector inverseRx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RX gate. -std::pair, SmallVector> -inverseMultipleControlledRx(QCProgramBuilder& b); +SmallVector inverseMultipleControlledRx(QCProgramBuilder& b); // --- RYOp ----------------------------------------------------------------- // /// Creates a circuit with just an RY gate. -std::pair, SmallVector> ry(QCProgramBuilder& b); +SmallVector ry(QCProgramBuilder& b); /// Creates a circuit with a single controlled RY gate. -std::pair, SmallVector> -singleControlledRy(QCProgramBuilder& b); +SmallVector singleControlledRy(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RY gate. -std::pair, SmallVector> -multipleControlledRy(QCProgramBuilder& b); +SmallVector multipleControlledRy(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RY gate. -std::pair, SmallVector> -nestedControlledRy(QCProgramBuilder& b); +SmallVector nestedControlledRy(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RY gate. -std::pair, SmallVector> -trivialControlledRy(QCProgramBuilder& b); +SmallVector trivialControlledRy(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RY gate. -std::pair, SmallVector> inverseRy(QCProgramBuilder& b); +SmallVector inverseRy(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RY gate. -std::pair, SmallVector> -inverseMultipleControlledRy(QCProgramBuilder& b); +SmallVector inverseMultipleControlledRy(QCProgramBuilder& b); // --- RZOp ----------------------------------------------------------------- // /// Creates a circuit with just an RZ gate. -std::pair, SmallVector> rz(QCProgramBuilder& b); +SmallVector rz(QCProgramBuilder& b); /// Creates a circuit with a single controlled RZ gate. -std::pair, SmallVector> -singleControlledRz(QCProgramBuilder& b); +SmallVector singleControlledRz(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RZ gate. -std::pair, SmallVector> -multipleControlledRz(QCProgramBuilder& b); +SmallVector multipleControlledRz(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RZ gate. -std::pair, SmallVector> -nestedControlledRz(QCProgramBuilder& b); +SmallVector nestedControlledRz(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RZ gate. -std::pair, SmallVector> -trivialControlledRz(QCProgramBuilder& b); +SmallVector trivialControlledRz(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZ gate. -std::pair, SmallVector> inverseRz(QCProgramBuilder& b); +SmallVector inverseRz(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZ gate. -std::pair, SmallVector> -inverseMultipleControlledRz(QCProgramBuilder& b); +SmallVector inverseMultipleControlledRz(QCProgramBuilder& b); // --- POp ------------------------------------------------------------------ // /// Creates a circuit with just a P gate. -std::pair, SmallVector> p(QCProgramBuilder& b); +SmallVector p(QCProgramBuilder& b); /// Creates a circuit with a single controlled P gate. -std::pair, SmallVector> -singleControlledP(QCProgramBuilder& b); +SmallVector singleControlledP(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled P gate. -std::pair, SmallVector> -multipleControlledP(QCProgramBuilder& b); +SmallVector multipleControlledP(QCProgramBuilder& b); /// Creates a circuit with a nested controlled P gate. -std::pair, SmallVector> -nestedControlledP(QCProgramBuilder& b); +SmallVector nestedControlledP(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled P gate. -std::pair, SmallVector> -trivialControlledP(QCProgramBuilder& b); +SmallVector trivialControlledP(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a P gate. -std::pair, SmallVector> inverseP(QCProgramBuilder& b); +SmallVector inverseP(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled P gate. -std::pair, SmallVector> -inverseMultipleControlledP(QCProgramBuilder& b); +SmallVector inverseMultipleControlledP(QCProgramBuilder& b); // --- ROp ------------------------------------------------------------------ // /// Creates a circuit with just an R gate. -std::pair, SmallVector> r(QCProgramBuilder& b); +SmallVector r(QCProgramBuilder& b); /// Creates a circuit with a single controlled R gate. -std::pair, SmallVector> -singleControlledR(QCProgramBuilder& b); +SmallVector singleControlledR(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled R gate. -std::pair, SmallVector> -multipleControlledR(QCProgramBuilder& b); +SmallVector multipleControlledR(QCProgramBuilder& b); /// Creates a circuit with a nested controlled R gate. -std::pair, SmallVector> -nestedControlledR(QCProgramBuilder& b); +SmallVector nestedControlledR(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled R gate. -std::pair, SmallVector> -trivialControlledR(QCProgramBuilder& b); +SmallVector trivialControlledR(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an R gate. -std::pair, SmallVector> inverseR(QCProgramBuilder& b); +SmallVector inverseR(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled R gate. -std::pair, SmallVector> -inverseMultipleControlledR(QCProgramBuilder& b); +SmallVector inverseMultipleControlledR(QCProgramBuilder& b); // --- U2Op ----------------------------------------------------------------- // /// Creates a circuit with just a U2 gate. -std::pair, SmallVector> u2(QCProgramBuilder& b); +SmallVector u2(QCProgramBuilder& b); /// Creates a circuit with a single controlled U2 gate. -std::pair, SmallVector> -singleControlledU2(QCProgramBuilder& b); +SmallVector singleControlledU2(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled U2 gate. -std::pair, SmallVector> -multipleControlledU2(QCProgramBuilder& b); +SmallVector multipleControlledU2(QCProgramBuilder& b); /// Creates a circuit with a nested controlled U2 gate. -std::pair, SmallVector> -nestedControlledU2(QCProgramBuilder& b); +SmallVector nestedControlledU2(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled U2 gate. -std::pair, SmallVector> -trivialControlledU2(QCProgramBuilder& b); +SmallVector trivialControlledU2(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a U2 gate. -std::pair, SmallVector> inverseU2(QCProgramBuilder& b); +SmallVector inverseU2(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled U2 gate. -std::pair, SmallVector> -inverseMultipleControlledU2(QCProgramBuilder& b); +SmallVector inverseMultipleControlledU2(QCProgramBuilder& b); // --- UOp ------------------------------------------------------------------ // /// Creates a circuit with just a U gate. -std::pair, SmallVector> u(QCProgramBuilder& b); +SmallVector u(QCProgramBuilder& b); /// Creates a circuit with a single controlled U gate. -std::pair, SmallVector> -singleControlledU(QCProgramBuilder& b); +SmallVector singleControlledU(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled U gate. -std::pair, SmallVector> -multipleControlledU(QCProgramBuilder& b); +SmallVector multipleControlledU(QCProgramBuilder& b); /// Creates a circuit with a nested controlled U gate. -std::pair, SmallVector> -nestedControlledU(QCProgramBuilder& b); +SmallVector nestedControlledU(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled U gate. -std::pair, SmallVector> -trivialControlledU(QCProgramBuilder& b); +SmallVector trivialControlledU(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a U gate. -std::pair, SmallVector> inverseU(QCProgramBuilder& b); +SmallVector inverseU(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled U gate. -std::pair, SmallVector> -inverseMultipleControlledU(QCProgramBuilder& b); +SmallVector inverseMultipleControlledU(QCProgramBuilder& b); // --- SWAPOp --------------------------------------------------------------- // /// Creates a circuit with just a SWAP gate. -std::pair, SmallVector> swap(QCProgramBuilder& b); +SmallVector swap(QCProgramBuilder& b); /// Creates a circuit with a single controlled SWAP gate. -std::pair, SmallVector> -singleControlledSwap(QCProgramBuilder& b); +SmallVector singleControlledSwap(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled SWAP gate. -std::pair, SmallVector> -multipleControlledSwap(QCProgramBuilder& b); +SmallVector multipleControlledSwap(QCProgramBuilder& b); /// Creates a circuit with a nested controlled SWAP gate. -std::pair, SmallVector> -nestedControlledSwap(QCProgramBuilder& b); +SmallVector nestedControlledSwap(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled SWAP gate. -std::pair, SmallVector> -trivialControlledSwap(QCProgramBuilder& b); +SmallVector trivialControlledSwap(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a SWAP gate. -std::pair, SmallVector> -inverseSwap(QCProgramBuilder& b); +SmallVector inverseSwap(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SWAP /// gate. -std::pair, SmallVector> -inverseMultipleControlledSwap(QCProgramBuilder& b); +SmallVector inverseMultipleControlledSwap(QCProgramBuilder& b); // --- iSWAPOp -------------------------------------------------------------- // /// Creates a circuit with just an iSWAP gate. -std::pair, SmallVector> iswap(QCProgramBuilder& b); +SmallVector iswap(QCProgramBuilder& b); /// Creates a circuit with a single controlled iSWAP gate. -std::pair, SmallVector> -singleControlledIswap(QCProgramBuilder& b); +SmallVector singleControlledIswap(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled iSWAP gate. -std::pair, SmallVector> -multipleControlledIswap(QCProgramBuilder& b); +SmallVector multipleControlledIswap(QCProgramBuilder& b); /// Creates a circuit with a nested controlled iSWAP gate. -std::pair, SmallVector> -nestedControlledIswap(QCProgramBuilder& b); +SmallVector nestedControlledIswap(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled iSWAP gate. -std::pair, SmallVector> -trivialControlledIswap(QCProgramBuilder& b); +SmallVector trivialControlledIswap(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an iSWAP gate. -std::pair, SmallVector> -inverseIswap(QCProgramBuilder& b); +SmallVector inverseIswap(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled iSWAP /// gate. -std::pair, SmallVector> -inverseMultipleControlledIswap(QCProgramBuilder& b); +SmallVector inverseMultipleControlledIswap(QCProgramBuilder& b); // --- DCXOp ---------------------------------------------------------------- // /// Creates a circuit with just a DCX gate. -std::pair, SmallVector> dcx(QCProgramBuilder& b); +SmallVector dcx(QCProgramBuilder& b); /// Creates a circuit with a single controlled DCX gate. -std::pair, SmallVector> -singleControlledDcx(QCProgramBuilder& b); +SmallVector singleControlledDcx(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled DCX gate. -std::pair, SmallVector> -multipleControlledDcx(QCProgramBuilder& b); +SmallVector multipleControlledDcx(QCProgramBuilder& b); /// Creates a circuit with a nested controlled DCX gate. -std::pair, SmallVector> -nestedControlledDcx(QCProgramBuilder& b); +SmallVector nestedControlledDcx(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled DCX gate. -std::pair, SmallVector> -trivialControlledDcx(QCProgramBuilder& b); +SmallVector trivialControlledDcx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a DCX gate. -std::pair, SmallVector> -inverseDcx(QCProgramBuilder& b); +SmallVector inverseDcx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled DCX gate. -std::pair, SmallVector> -inverseMultipleControlledDcx(QCProgramBuilder& b); +SmallVector inverseMultipleControlledDcx(QCProgramBuilder& b); // --- ECROp ---------------------------------------------------------------- // /// Creates a circuit with just an ECR gate. -std::pair, SmallVector> ecr(QCProgramBuilder& b); +SmallVector ecr(QCProgramBuilder& b); /// Creates a circuit with a single controlled ECR gate. -std::pair, SmallVector> -singleControlledEcr(QCProgramBuilder& b); +SmallVector singleControlledEcr(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled ECR gate. -std::pair, SmallVector> -multipleControlledEcr(QCProgramBuilder& b); +SmallVector multipleControlledEcr(QCProgramBuilder& b); /// Creates a circuit with a nested controlled ECR gate. -std::pair, SmallVector> -nestedControlledEcr(QCProgramBuilder& b); +SmallVector nestedControlledEcr(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled ECR gate. -std::pair, SmallVector> -trivialControlledEcr(QCProgramBuilder& b); +SmallVector trivialControlledEcr(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an ECR gate. -std::pair, SmallVector> -inverseEcr(QCProgramBuilder& b); +SmallVector inverseEcr(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled ECR gate. -std::pair, SmallVector> -inverseMultipleControlledEcr(QCProgramBuilder& b); +SmallVector inverseMultipleControlledEcr(QCProgramBuilder& b); // --- RXXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RXX gate. -std::pair, SmallVector> rxx(QCProgramBuilder& b); +SmallVector rxx(QCProgramBuilder& b); /// Creates a circuit with a single controlled RXX gate. -std::pair, SmallVector> -singleControlledRxx(QCProgramBuilder& b); +SmallVector singleControlledRxx(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RXX gate. -std::pair, SmallVector> -multipleControlledRxx(QCProgramBuilder& b); +SmallVector multipleControlledRxx(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RXX gate. -std::pair, SmallVector> -nestedControlledRxx(QCProgramBuilder& b); +SmallVector nestedControlledRxx(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RXX gate. -std::pair, SmallVector> -trivialControlledRxx(QCProgramBuilder& b); +SmallVector trivialControlledRxx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RXX gate. -std::pair, SmallVector> -inverseRxx(QCProgramBuilder& b); +SmallVector inverseRxx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RXX gate. -std::pair, SmallVector> -inverseMultipleControlledRxx(QCProgramBuilder& b); +SmallVector inverseMultipleControlledRxx(QCProgramBuilder& b); /// Creates a circuit with a triple-controlled RXX gate. -std::pair, SmallVector> -tripleControlledRxx(QCProgramBuilder& b); +SmallVector tripleControlledRxx(QCProgramBuilder& b); /// Creates a circuit with a four-controlled RXX gate. -std::pair, SmallVector> -fourControlledRxx(QCProgramBuilder& b); +SmallVector fourControlledRxx(QCProgramBuilder& b); // --- RYYOp ---------------------------------------------------------------- // /// Creates a circuit with just an RYY gate. -std::pair, SmallVector> ryy(QCProgramBuilder& b); +SmallVector ryy(QCProgramBuilder& b); /// Creates a circuit with a single controlled RYY gate. -std::pair, SmallVector> -singleControlledRyy(QCProgramBuilder& b); +SmallVector singleControlledRyy(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RYY gate. -std::pair, SmallVector> -multipleControlledRyy(QCProgramBuilder& b); +SmallVector multipleControlledRyy(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RYY gate. -std::pair, SmallVector> -nestedControlledRyy(QCProgramBuilder& b); +SmallVector nestedControlledRyy(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RYY gate. -std::pair, SmallVector> -trivialControlledRyy(QCProgramBuilder& b); +SmallVector trivialControlledRyy(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RYY gate. -std::pair, SmallVector> -inverseRyy(QCProgramBuilder& b); +SmallVector inverseRyy(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RYY gate. -std::pair, SmallVector> -inverseMultipleControlledRyy(QCProgramBuilder& b); +SmallVector inverseMultipleControlledRyy(QCProgramBuilder& b); // --- RZXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZX gate. -std::pair, SmallVector> rzx(QCProgramBuilder& b); +SmallVector rzx(QCProgramBuilder& b); /// Creates a circuit with a single controlled RZX gate. -std::pair, SmallVector> -singleControlledRzx(QCProgramBuilder& b); +SmallVector singleControlledRzx(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RZX gate. -std::pair, SmallVector> -multipleControlledRzx(QCProgramBuilder& b); +SmallVector multipleControlledRzx(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RZX gate. -std::pair, SmallVector> -nestedControlledRzx(QCProgramBuilder& b); +SmallVector nestedControlledRzx(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RZX gate. -std::pair, SmallVector> -trivialControlledRzx(QCProgramBuilder& b); +SmallVector trivialControlledRzx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZX gate. -std::pair, SmallVector> -inverseRzx(QCProgramBuilder& b); +SmallVector inverseRzx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZX gate. -std::pair, SmallVector> -inverseMultipleControlledRzx(QCProgramBuilder& b); +SmallVector inverseMultipleControlledRzx(QCProgramBuilder& b); // --- RZZOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZZ gate. -std::pair, SmallVector> rzz(QCProgramBuilder& b); +SmallVector rzz(QCProgramBuilder& b); /// Creates a circuit with a single controlled RZZ gate. -std::pair, SmallVector> -singleControlledRzz(QCProgramBuilder& b); +SmallVector singleControlledRzz(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled RZZ gate. -std::pair, SmallVector> -multipleControlledRzz(QCProgramBuilder& b); +SmallVector multipleControlledRzz(QCProgramBuilder& b); /// Creates a circuit with a nested controlled RZZ gate. -std::pair, SmallVector> -nestedControlledRzz(QCProgramBuilder& b); +SmallVector nestedControlledRzz(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RZZ gate. -std::pair, SmallVector> -trivialControlledRzz(QCProgramBuilder& b); +SmallVector trivialControlledRzz(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZZ gate. -std::pair, SmallVector> -inverseRzz(QCProgramBuilder& b); +SmallVector inverseRzz(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZZ gate. -std::pair, SmallVector> -inverseMultipleControlledRzz(QCProgramBuilder& b); +SmallVector inverseMultipleControlledRzz(QCProgramBuilder& b); // --- XXPlusYYOp ----------------------------------------------------------- // /// Creates a circuit with just an XXPlusYY gate. -std::pair, SmallVector> xxPlusYY(QCProgramBuilder& b); +SmallVector xxPlusYY(QCProgramBuilder& b); /// Creates a circuit with a single controlled XXPlusYY gate. -std::pair, SmallVector> -singleControlledXxPlusYY(QCProgramBuilder& b); +SmallVector singleControlledXxPlusYY(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled XXPlusYY gate. -std::pair, SmallVector> -multipleControlledXxPlusYY(QCProgramBuilder& b); +SmallVector multipleControlledXxPlusYY(QCProgramBuilder& b); /// Creates a circuit with a nested controlled XXPlusYY gate. -std::pair, SmallVector> -nestedControlledXxPlusYY(QCProgramBuilder& b); +SmallVector nestedControlledXxPlusYY(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled XXPlusYY gate. -std::pair, SmallVector> -trivialControlledXxPlusYY(QCProgramBuilder& b); +SmallVector trivialControlledXxPlusYY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an XXPlusYY gate. -std::pair, SmallVector> -inverseXxPlusYY(QCProgramBuilder& b); +SmallVector inverseXxPlusYY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled XXPlusYY /// gate. -std::pair, SmallVector> -inverseMultipleControlledXxPlusYY(QCProgramBuilder& b); +SmallVector inverseMultipleControlledXxPlusYY(QCProgramBuilder& b); // --- XXMinusYYOp ---------------------------------------------------------- // /// Creates a circuit with just an XXMinusYY gate. -std::pair, SmallVector> xxMinusYY(QCProgramBuilder& b); +SmallVector xxMinusYY(QCProgramBuilder& b); /// Creates a circuit with a single controlled XXMinusYY gate. -std::pair, SmallVector> -singleControlledXxMinusYY(QCProgramBuilder& b); +SmallVector singleControlledXxMinusYY(QCProgramBuilder& b); /// Creates a circuit with a multi-controlled XXMinusYY gate. -std::pair, SmallVector> -multipleControlledXxMinusYY(QCProgramBuilder& b); +SmallVector multipleControlledXxMinusYY(QCProgramBuilder& b); /// Creates a circuit with a nested controlled XXMinusYY gate. -std::pair, SmallVector> -nestedControlledXxMinusYY(QCProgramBuilder& b); +SmallVector nestedControlledXxMinusYY(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled XXMinusYY gate. -std::pair, SmallVector> -trivialControlledXxMinusYY(QCProgramBuilder& b); +SmallVector trivialControlledXxMinusYY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an XXMinusYY gate. -std::pair, SmallVector> -inverseXxMinusYY(QCProgramBuilder& b); +SmallVector inverseXxMinusYY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled XXMinusYY /// gate. -std::pair, SmallVector> -inverseMultipleControlledXxMinusYY(QCProgramBuilder& b); +SmallVector inverseMultipleControlledXxMinusYY(QCProgramBuilder& b); // --- BarrierOp ------------------------------------------------------------ // /// Creates a circuit with a barrier. -std::pair, SmallVector> barrier(QCProgramBuilder& b); +SmallVector barrier(QCProgramBuilder& b); /// Creates a circuit with a barrier on two qubits. -std::pair, SmallVector> -barrierTwoQubits(QCProgramBuilder& b); +SmallVector barrierTwoQubits(QCProgramBuilder& b); /// Creates a circuit with a barrier on multiple qubits. -std::pair, SmallVector> -barrierMultipleQubits(QCProgramBuilder& b); +SmallVector barrierMultipleQubits(QCProgramBuilder& b); /// Creates a circuit with a single controlled barrier. -std::pair, SmallVector> -singleControlledBarrier(QCProgramBuilder& b); +SmallVector singleControlledBarrier(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a barrier. -std::pair, SmallVector> -inverseBarrier(QCProgramBuilder& b); +SmallVector inverseBarrier(QCProgramBuilder& b); // --- CtrlOp --------------------------------------------------------------- // /// Creates a circuit with a trivial ctrl modifier. -std::pair, SmallVector> -trivialCtrl(QCProgramBuilder& b); +SmallVector trivialCtrl(QCProgramBuilder& b); /// Creates a circuit with an empty ctrl modifier. -std::pair, SmallVector> emptyCtrl(QCProgramBuilder& b); +SmallVector emptyCtrl(QCProgramBuilder& b); /// Creates a circuit with nested ctrl modifiers. -std::pair, SmallVector> -nestedCtrl(QCProgramBuilder& b); +SmallVector nestedCtrl(QCProgramBuilder& b); /// Creates a circuit with triple nested ctrl modifiers. -std::pair, SmallVector> -tripleNestedCtrl(QCProgramBuilder& b); +SmallVector tripleNestedCtrl(QCProgramBuilder& b); /// Creates a circuit with double nested ctrl modifiers with two qubits each. -std::pair, SmallVector> -doubleNestedCtrlTwoQubits(QCProgramBuilder& b); +SmallVector doubleNestedCtrlTwoQubits(QCProgramBuilder& b); /// Creates a circuit with control modifiers interleaved by an inverse modifier. -std::pair, SmallVector> -ctrlInvSandwich(QCProgramBuilder& b); +SmallVector ctrlInvSandwich(QCProgramBuilder& b); /// Creates a circuit with a control modifier applied to two gates. -std::pair, SmallVector> ctrlTwo(QCProgramBuilder& b); +SmallVector ctrlTwo(QCProgramBuilder& b); /// Creates a circuit with a control modifier applied to a controlled and a /// non-controlled gate. -std::pair, SmallVector> -ctrlTwoMixed(QCProgramBuilder& b); +SmallVector ctrlTwoMixed(QCProgramBuilder& b); /// Creates a circuit with nested control modifiers applied to two gates. -std::pair, SmallVector> -nestedCtrlTwo(QCProgramBuilder& b); +SmallVector nestedCtrlTwo(QCProgramBuilder& b); /// Creates a circuit with a control modifier applied to a inverse modifier /// applied to two gates. -std::pair, SmallVector> -ctrlInvTwo(QCProgramBuilder& b); +SmallVector ctrlInvTwo(QCProgramBuilder& b); // --- InvOp ---------------------------------------------------------------- // /// Creates a circuit with an empty inverse modifier. -std::pair, SmallVector> emptyInv(QCProgramBuilder& b); +SmallVector emptyInv(QCProgramBuilder& b); /// Creates a circuit with nested inverse modifiers. -std::pair, SmallVector> nestedInv(QCProgramBuilder& b); +SmallVector nestedInv(QCProgramBuilder& b); /// Creates a circuit with triple nested inverse modifiers. -std::pair, SmallVector> -tripleNestedInv(QCProgramBuilder& b); +SmallVector tripleNestedInv(QCProgramBuilder& b); /// Creates a circuit with inverse modifiers interleaved by a control modifier. -std::pair, SmallVector> -invCtrlSandwich(QCProgramBuilder& b); +SmallVector invCtrlSandwich(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to two gates. -std::pair, SmallVector> invTwo(QCProgramBuilder& b); +SmallVector invTwo(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a control modifier /// applied to two gates. -std::pair, SmallVector> -invCtrlTwo(QCProgramBuilder& b); +SmallVector invCtrlTwo(QCProgramBuilder& b); // --- IfOp ----------------------------------------------------------------- // /// Creates a circuit with a simple if operation with one qubit. -std::pair, SmallVector> simpleIf(QCProgramBuilder& b); +SmallVector simpleIf(QCProgramBuilder& b); /// Creates a circuit with an if operation with an else branch. -std::pair, SmallVector> ifElse(QCProgramBuilder& b); +SmallVector ifElse(QCProgramBuilder& b); /// Creates a circuit with an if operation with two qubits. -std::pair, SmallVector> -ifTwoQubits(QCProgramBuilder& b); +SmallVector ifTwoQubits(QCProgramBuilder& b); /// Creates a circuit with an if operation with a nested for operation with /// a register. -std::pair, SmallVector> -nestedIfOpForLoop(QCProgramBuilder& b); +SmallVector nestedIfOpForLoop(QCProgramBuilder& b); // --- WhileOp -------------------------------------------------------------- // /// Creates a circuit with a while operation using a while loop. -std::pair, SmallVector> -simpleWhileReset(QCProgramBuilder& b); +SmallVector simpleWhileReset(QCProgramBuilder& b); /// Creates a circuit with a while operation using a do-while loop. -std::pair, SmallVector> -simpleDoWhileReset(QCProgramBuilder& b); +SmallVector simpleDoWhileReset(QCProgramBuilder& b); // --- ForOp ---------------------------------------------------------------- // /// Creates a circuit with a simple for operation with a register. -std::pair, SmallVector> -simpleForLoop(QCProgramBuilder& b); +SmallVector simpleForLoop(QCProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested if operation. -std::pair, SmallVector> -nestedForLoopIfOp(QCProgramBuilder& b); +SmallVector nestedForLoopIfOp(QCProgramBuilder& b); /// Creates a circuit with a for operation with a register and a nested while /// operation. -std::pair, SmallVector> -nestedForLoopWhileOp(QCProgramBuilder& b); +SmallVector nestedForLoopWhileOp(QCProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is separately allocated from the /// register. -std::pair, SmallVector> -nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b); +SmallVector nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is extracted from the register. -std::pair, SmallVector> -nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b); +SmallVector nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b); } // namespace mlir::qc diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index f9784bf4b3..d6e9d61cc6 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -14,134 +14,105 @@ #include #include -#include // NOLINT(misc-include-cleaner) -#include #include #include #include #include #include -#include #include +namespace mlir::qco { + /** - * @brief Measures the given `qtensor` and return the measurement outcomes and - * their types. + * @brief Measures the given `qtensor` and returns the measurement outcomes. * @param b The `ProgramBuilder` used to perform the measurements. * @param qTensor The `qtensor` to be measured. - * @return A pair containing the result values and their types. + * @param size The number of qubits in the `qtensor`. + * @return The result values. */ -static std::pair, mlir::SmallVector> -measureAndReturnQTensor(mlir::qco::QCOProgramBuilder& b, mlir::Value qTensor, - int64_t size) { - mlir::SmallVector bits; - mlir::SmallVector bitTypes; - auto i1Type = b.getI1Type(); +static SmallVector measureAndReturnQTensor(QCOProgramBuilder& b, + Value qTensor, + const int64_t size) { + SmallVector bits; for (auto i = 0; i < size; ++i) { auto [qTensorOut, qubit] = b.qtensorExtract(qTensor, i); auto [q2, bit] = b.measure(qubit); bits.push_back(bit); - bitTypes.push_back(i1Type); qTensor = b.qtensorInsert(q2, qTensorOut, i); } - return {bits, bitTypes}; + return bits; } /** - * @brief Measures the given qubits and return the measurement outcomes and - * their types. + * @brief Measures the given qubits and returns the measurement outcomes. * @param b The `ProgramBuilder` used to perform the measurements. * @param qubits The qubits to be measured. - * @return A pair containing the result values and their types. + * @return The result values. */ -static std::pair, mlir::SmallVector> -measureAndReturn(mlir::qco::QCOProgramBuilder& b, - const mlir::SmallVector& qubits) { - mlir::SmallVector bits; - mlir::SmallVector bitTypes; - auto i1Type = b.getI1Type(); - for (const auto& q : qubits) { - auto [q2, bit] = b.measure(q); - bits.push_back(bit); - bitTypes.push_back(i1Type); - } - return {bits, bitTypes}; +static SmallVector measureAndReturn(QCOProgramBuilder& b, + ValueRange qubits) { + return llvm::to_vector( + llvm::map_range(qubits, [&](Value q) { return b.measure(q).second; })); } -namespace mlir::qco { - -std::pair, SmallVector> -emptyQCO(QCOProgramBuilder& b) { - return {{b.intConstant(0)}, {b.getI64Type()}}; -} +SmallVector emptyQCO(QCOProgramBuilder& b) { return {b.intConstant(0)}; } -std::pair, SmallVector> -allocQubit(QCOProgramBuilder& b) { +SmallVector allocQubit(QCOProgramBuilder& b) { auto q = b.allocQubit(); return measureAndReturn(b, {q}); } -std::pair, SmallVector> -alloc2Qubits(QCOProgramBuilder& b) { +SmallVector alloc2Qubits(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.allocQubit(); return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -allocQubitNoMeasure(QCOProgramBuilder& b) { +SmallVector allocQubitNoMeasure(QCOProgramBuilder& b) { (void)b.allocQubit(); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return {b.intConstant(0)}; } -std::pair, SmallVector> -alloc1QubitRegister(QCOProgramBuilder& b) { +SmallVector alloc1QubitRegister(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(1); - return measureAndReturn(b, {reg[0]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -alloc2QubitRegister(QCOProgramBuilder& b) { +SmallVector alloc2QubitRegister(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(2); - return measureAndReturn(b, {reg[0], reg[1]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -alloc3QubitRegister(QCOProgramBuilder& b) { +SmallVector alloc3QubitRegister(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -allocMultipleQubitRegisters(QCOProgramBuilder& b) { +SmallVector allocMultipleQubitRegisters(QCOProgramBuilder& b) { auto r1 = b.allocQubitRegister(2); auto r2 = b.allocQubitRegister(3); return measureAndReturn(b, {r1[0], r1[1], r2[0], r2[1], r2[2]}); } -std::pair, SmallVector> -allocLargeRegister(QCOProgramBuilder& b) { +SmallVector allocLargeRegister(QCOProgramBuilder& b) { auto r = b.allocQubitRegister(100); return measureAndReturn(b, {r[0]}); } -std::pair, SmallVector> -staticQubitsNoMeasure(QCOProgramBuilder& b) { +SmallVector staticQubitsNoMeasure(QCOProgramBuilder& b) { (void)b.staticQubit(0); (void)b.staticQubit(1); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return {b.intConstant(0)}; } -std::pair, SmallVector> -staticQubits(QCOProgramBuilder& b) { +SmallVector staticQubits(QCOProgramBuilder& b) { auto q1 = b.staticQubit(0); auto q2 = b.staticQubit(1); return measureAndReturn(b, {q1, q2}); } -std::pair, SmallVector> -staticQubitsWithOps(QCOProgramBuilder& b) { +SmallVector staticQubitsWithOps(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); q0 = b.h(q0); @@ -149,8 +120,7 @@ staticQubitsWithOps(QCOProgramBuilder& b) { return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithParametricOps(QCOProgramBuilder& b) { +SmallVector staticQubitsWithParametricOps(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); q0 = b.rx(std::numbers::pi / 4., q0); @@ -158,38 +128,33 @@ staticQubitsWithParametricOps(QCOProgramBuilder& b) { return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithTwoTargetOps(QCOProgramBuilder& b) { +SmallVector staticQubitsWithTwoTargetOps(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); std::tie(q0, q1) = b.rzz(0.123, q0, q1); return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithCtrl(QCOProgramBuilder& b) { +SmallVector staticQubitsWithCtrl(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); std::tie(q0, q1) = b.cx(q0, q1); return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -staticQubitsWithInv(QCOProgramBuilder& b) { +SmallVector staticQubitsWithInv(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); q0 = b.inv(q0, [&](Value qubit) { return b.t(qubit); }); return measureAndReturn(b, {q0}); } -std::pair, SmallVector> -allocSinkPair(QCOProgramBuilder& b) { +SmallVector allocSinkPair(QCOProgramBuilder& b) { auto q = b.allocQubit(); b.sink(q); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return {b.intConstant(0)}; } -std::pair, SmallVector> -deadGatesProgram(QCOProgramBuilder& b) { +SmallVector deadGatesProgram(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.allocQubit(); @@ -201,11 +166,10 @@ deadGatesProgram(QCOProgramBuilder& b) { auto [_, c1] = b.measure(res1); q0 = b.reset(res0); - return {{m0, m1}, {b.getI1Type(), b.getI1Type()}}; + return {m0, m1}; } -std::pair, SmallVector> -deadGatesWithIfOpProgram(QCOProgramBuilder& b) { +SmallVector deadGatesWithIfOpProgram(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.allocQubit(); q0 = b.h(q0); @@ -237,11 +201,10 @@ deadGatesWithIfOpProgram(QCOProgramBuilder& b) { return SmallVector{q1Else}; })[0]; - return {{c0}, {b.getI1Type()}}; + return {c0}; } -std::pair, SmallVector> -deadGatesWithIfOpSimplified(QCOProgramBuilder& b) { +SmallVector deadGatesWithIfOpSimplified(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.allocQubit(); q0 = b.h(q0); @@ -261,52 +224,47 @@ deadGatesWithIfOpSimplified(QCOProgramBuilder& b) { return SmallVector{q1Else}; })[0]; - return {{c0}, {b.getI1Type()}}; + return {c0}; } -std::pair, SmallVector> -mixedStaticThenDynamicQubit(QCOProgramBuilder& b) { +SmallVector mixedStaticThenDynamicQubit(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.allocQubit(); return measureAndReturn(b, {q0, q1}); } -std::pair, SmallVector> -mixedDynamicRegisterThenStaticQubit(QCOProgramBuilder& b) { +SmallVector mixedDynamicRegisterThenStaticQubit(QCOProgramBuilder& b) { b.qtensorAlloc(2); auto q1 = b.staticQubit(0); return measureAndReturn(b, {q1}); } -std::pair, SmallVector> -singleMeasurementToSingleBit(QCOProgramBuilder& b) { +SmallVector singleMeasurementToSingleBit(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); const auto [q1, bit] = b.measure(q[0], c[0]); - return {{bit}, {b.getI1Type()}}; + return {bit}; } -std::pair, SmallVector> -repeatedMeasurementToSameBit(QCOProgramBuilder& b) { +SmallVector repeatedMeasurementToSameBit(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); auto [q1, _c1] = b.measure(q[0], c[0]); auto [q2, _c2] = b.measure(q1, c[0]); auto [q3, c3] = b.measure(q2, c[0]); - return {{c3}, {b.getI1Type()}}; + return {c3}; } -std::pair, SmallVector> -repeatedMeasurementToDifferentBits(QCOProgramBuilder& b) { +SmallVector repeatedMeasurementToDifferentBits(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(3); auto [q1, c1] = b.measure(q[0], c[0]); auto [q2, c2] = b.measure(q1, c[1]); auto [q3, c3] = b.measure(q2, c[2]); - return {{c1, c2, c3}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; + return {c1, c2, c3}; } -std::pair, SmallVector> +SmallVector multipleClassicalRegistersAndMeasurements(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); const auto& c0 = b.allocClassicalBitRegister(1, "c0"); @@ -314,33 +272,29 @@ multipleClassicalRegistersAndMeasurements(QCOProgramBuilder& b) { auto [q0, bit1] = b.measure(q[0], c0[0]); auto [q1, bit2] = b.measure(q[1], c1[0]); auto [q2, bit3] = b.measure(q[2], c1[1]); - return {{bit1, bit2, bit3}, {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; + return {bit1, bit2, bit3}; } -std::pair, SmallVector> -measurementWithoutRegisters(QCOProgramBuilder& b) { +SmallVector measurementWithoutRegisters(QCOProgramBuilder& b) { auto q = b.allocQubit(); auto [q1, c] = b.measure(q); - return {{c}, {b.getI1Type()}}; + return {c}; } -std::pair, SmallVector> -resetQubitWithoutOp(QCOProgramBuilder& b) { +SmallVector resetQubitWithoutOp(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.reset(q); return measureAndReturn(b, {q}); } -std::pair, SmallVector> -resetMultipleQubitsWithoutOp(QCOProgramBuilder& b) { +SmallVector resetMultipleQubitsWithoutOp(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); q[0] = b.reset(q[0]); q[1] = b.reset(q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -repeatedResetWithoutOp(QCOProgramBuilder& b) { +SmallVector repeatedResetWithoutOp(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.reset(q); q = b.reset(q); @@ -348,100 +302,88 @@ repeatedResetWithoutOp(QCOProgramBuilder& b) { return measureAndReturn(b, {q}); } -std::pair, SmallVector> -resetQubitAfterSingleOp(QCOProgramBuilder& b) { +SmallVector resetQubitAfterSingleOp(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); q[0] = b.reset(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -resetMultipleQubitsAfterSingleOp(QCOProgramBuilder& b) { +SmallVector resetMultipleQubitsAfterSingleOp(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); q[0] = b.h(q[0]); q[0] = b.reset(q[0]); q[1] = b.h(q[1]); q[1] = b.reset(q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -repeatedResetAfterSingleOp(QCOProgramBuilder& b) { +SmallVector repeatedResetAfterSingleOp(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); q[0] = b.reset(q[0]); q[0] = b.reset(q[0]); q[0] = b.reset(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -globalPhase(QCOProgramBuilder& b) { +SmallVector globalPhase(QCOProgramBuilder& b) { b.gphase(0.123); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return {b.intConstant(0)}; } -std::pair, SmallVector> -singleControlledGlobalPhase(QCOProgramBuilder& b) { +SmallVector singleControlledGlobalPhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.cgphase(0.123, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledGlobalPhase(QCOProgramBuilder& b) { +SmallVector multipleControlledGlobalPhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto qs = b.mcgphase(0.123, {q[0], q[1], q[2]}); - return measureAndReturn(b, {qs[0], qs[1], qs[2]}); + return measureAndReturn(b, qs); } -std::pair, SmallVector> -inverseGlobalPhase(QCOProgramBuilder& b) { +SmallVector inverseGlobalPhase(QCOProgramBuilder& b) { b.inv(ValueRange{}, [&](ValueRange /*qubits*/) { b.gphase(-0.123); return SmallVector{}; }); - return {{b.intConstant(0)}, {b.getI64Type()}}; + return {b.intConstant(0)}; } -std::pair, SmallVector> -inverseMultipleControlledGlobalPhase(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledGlobalPhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto qs = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { SmallVector controls{qubits[0], qubits[1], qubits[2]}; auto controlsOut = b.mcgphase(-0.123, controls); return SmallVector(controlsOut.begin(), controlsOut.end()); }); - return measureAndReturn(b, {qs[0], qs[1], qs[2]}); + return measureAndReturn(b, qs); } -std::pair, SmallVector> -identity(QCOProgramBuilder& b) { +SmallVector identity(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.id(q); return measureAndReturn(b, {q}); } -std::pair, SmallVector> -singleControlledIdentity(QCOProgramBuilder& b) { +SmallVector singleControlledIdentity(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[1], q[0]) = b.cid(q[1], q[0]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledIdentity(QCOProgramBuilder& b) { +SmallVector multipleControlledIdentity(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcid({q[2], q[1]}, q[0]); q[2] = res.first[0]; q[1] = res.first[1]; q[0] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledIdentity(QCOProgramBuilder& b) { +SmallVector nestedControlledIdentity(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -451,26 +393,23 @@ nestedControlledIdentity(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledIdentity(QCOProgramBuilder& b) { +SmallVector trivialControlledIdentity(QCOProgramBuilder& b) { auto q = b.allocQubit(); auto res = b.mcid({}, q); q = res.second; return measureAndReturn(b, {q}); } -std::pair, SmallVector> -inverseIdentity(QCOProgramBuilder& b) { +SmallVector inverseIdentity(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.id(qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledIdentity(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledIdentity(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -481,34 +420,31 @@ inverseMultipleControlledIdentity(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> x(QCOProgramBuilder& b) { +SmallVector x(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.x(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledX(QCOProgramBuilder& b) { +SmallVector singleControlledX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.cx(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledX(QCOProgramBuilder& b) { +SmallVector multipleControlledX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcx({q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledX(QCOProgramBuilder& b) { +SmallVector nestedControlledX(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -518,19 +454,17 @@ nestedControlledX(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledX(QCOProgramBuilder& b) { +SmallVector trivialControlledX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcx({}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -repeatedControlledX(QCOProgramBuilder& b) { +SmallVector repeatedControlledX(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto control = b.h(q0); std::vector targets; @@ -545,15 +479,13 @@ repeatedControlledX(QCOProgramBuilder& b) { SmallVector(targets.begin(), targets.end())); } -std::pair, SmallVector> -inverseX(QCOProgramBuilder& b) { +SmallVector inverseX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.x(qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledX(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -564,18 +496,17 @@ inverseMultipleControlledX(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoX(QCOProgramBuilder& b) { +SmallVector twoX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.x(q[0]); q[0] = b.x(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -controlledTwoX(QCOProgramBuilder& b) { +SmallVector controlledTwoX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.ctrl(q[0], q[1], [&](Value target) { target = b.x(target); @@ -584,8 +515,7 @@ controlledTwoX(QCOProgramBuilder& b) { return measureAndReturn(b, {res.first, res.second}); } -std::pair, SmallVector> -inverseTwoX(QCOProgramBuilder& b) { +SmallVector inverseTwoX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { qubit = b.x(qubit); @@ -595,8 +525,7 @@ inverseTwoX(QCOProgramBuilder& b) { return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseGphaseX(QCOProgramBuilder& b) { +SmallVector inverseGphaseX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { b.gphase(-0.123); @@ -605,8 +534,7 @@ inverseGphaseX(QCOProgramBuilder& b) { return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseGphaseBarrier(QCOProgramBuilder& b) { +SmallVector inverseGphaseBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { b.gphase(0.123); @@ -615,8 +543,7 @@ inverseGphaseBarrier(QCOProgramBuilder& b) { return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseTwoBarriersInInv(QCOProgramBuilder& b) { +SmallVector inverseTwoBarriersInInv(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { qubit = b.barrier({qubit})[0]; @@ -625,31 +552,28 @@ inverseTwoBarriersInInv(QCOProgramBuilder& b) { return measureAndReturn(b, {res}); } -std::pair, SmallVector> y(QCOProgramBuilder& b) { +SmallVector y(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.y(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledY(QCOProgramBuilder& b) { +SmallVector singleControlledY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.cy(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledY(QCOProgramBuilder& b) { +SmallVector multipleControlledY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcy({q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledY(QCOProgramBuilder& b) { +SmallVector nestedControlledY(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -659,26 +583,23 @@ nestedControlledY(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledY(QCOProgramBuilder& b) { +SmallVector trivialControlledY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcy({}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseY(QCOProgramBuilder& b) { +SmallVector inverseY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.y(qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledY(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -689,41 +610,38 @@ inverseMultipleControlledY(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoY(QCOProgramBuilder& b) { +SmallVector twoY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.y(q[0]); q[0] = b.y(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> z(QCOProgramBuilder& b) { +SmallVector z(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.z(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledZ(QCOProgramBuilder& b) { +SmallVector singleControlledZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.cz(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledZ(QCOProgramBuilder& b) { +SmallVector multipleControlledZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcz({q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledZ(QCOProgramBuilder& b) { +SmallVector nestedControlledZ(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -733,26 +651,23 @@ nestedControlledZ(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledZ(QCOProgramBuilder& b) { +SmallVector trivialControlledZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcz({}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseZ(QCOProgramBuilder& b) { +SmallVector inverseZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.z(qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledZ(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -763,41 +678,38 @@ inverseMultipleControlledZ(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoZ(QCOProgramBuilder& b) { +SmallVector twoZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.z(q[0]); q[0] = b.z(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> h(QCOProgramBuilder& b) { +SmallVector h(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledH(QCOProgramBuilder& b) { +SmallVector singleControlledH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.ch(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledH(QCOProgramBuilder& b) { +SmallVector multipleControlledH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mch({q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledH(QCOProgramBuilder& b) { +SmallVector nestedControlledH(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -807,26 +719,23 @@ nestedControlledH(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledH(QCOProgramBuilder& b) { +SmallVector trivialControlledH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mch({}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseH(QCOProgramBuilder& b) { +SmallVector inverseH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.h(qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledH(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -837,50 +746,46 @@ inverseMultipleControlledH(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoH(QCOProgramBuilder& b) { +SmallVector twoH(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.h(q); q = b.h(q); return measureAndReturn(b, {q}); } -std::pair, SmallVector> -hWithoutRegister(QCOProgramBuilder& b) { +SmallVector hWithoutRegister(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.h(q); return measureAndReturn(b, {q}); } -std::pair, SmallVector> s(QCOProgramBuilder& b) { +SmallVector s(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.s(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledS(QCOProgramBuilder& b) { +SmallVector singleControlledS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.cs(q[0], q[1]); q[0] = res.first; q[1] = res.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledS(QCOProgramBuilder& b) { +SmallVector multipleControlledS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcs({q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledS(QCOProgramBuilder& b) { +SmallVector nestedControlledS(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -890,26 +795,23 @@ nestedControlledS(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledS(QCOProgramBuilder& b) { +SmallVector trivialControlledS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcs({}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseS(QCOProgramBuilder& b) { +SmallVector inverseS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.s(qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledS(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -920,51 +822,47 @@ inverseMultipleControlledS(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -sThenSdg(QCOProgramBuilder& b) { +SmallVector sThenSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.s(q[0]); q[0] = b.sdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoS(QCOProgramBuilder& b) { +SmallVector twoS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.s(q[0]); q[0] = b.s(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> sdg(QCOProgramBuilder& b) { +SmallVector sdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledSdg(QCOProgramBuilder& b) { +SmallVector singleControlledSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.csdg(q[0], q[1]); q[0] = res.first; q[1] = res.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledSdg(QCOProgramBuilder& b) { +SmallVector multipleControlledSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcsdg({q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledSdg(QCOProgramBuilder& b) { +SmallVector nestedControlledSdg(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -974,26 +872,23 @@ nestedControlledSdg(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledSdg(QCOProgramBuilder& b) { +SmallVector trivialControlledSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcsdg({}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseSdg(QCOProgramBuilder& b) { +SmallVector inverseSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.sdg(qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledSdg(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -1004,51 +899,47 @@ inverseMultipleControlledSdg(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -sdgThenS(QCOProgramBuilder& b) { +SmallVector sdgThenS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sdg(q[0]); q[0] = b.s(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoSdg(QCOProgramBuilder& b) { +SmallVector twoSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sdg(q[0]); q[0] = b.sdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> t_(QCOProgramBuilder& b) { +SmallVector t_(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.t(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledT(QCOProgramBuilder& b) { +SmallVector singleControlledT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.ct(q[0], q[1]); q[0] = res.first; q[1] = res.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledT(QCOProgramBuilder& b) { +SmallVector multipleControlledT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mct({q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledT(QCOProgramBuilder& b) { +SmallVector nestedControlledT(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -1058,26 +949,23 @@ nestedControlledT(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledT(QCOProgramBuilder& b) { +SmallVector trivialControlledT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mct({}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseT(QCOProgramBuilder& b) { +SmallVector inverseT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.t(qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledT(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -1088,51 +976,47 @@ inverseMultipleControlledT(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -tThenTdg(QCOProgramBuilder& b) { +SmallVector tThenTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.t(q[0]); q[0] = b.tdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoT(QCOProgramBuilder& b) { +SmallVector twoT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.t(q[0]); q[0] = b.t(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> tdg(QCOProgramBuilder& b) { +SmallVector tdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.tdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledTdg(QCOProgramBuilder& b) { +SmallVector singleControlledTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.ctdg(q[0], q[1]); q[0] = res.first; q[1] = res.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledTdg(QCOProgramBuilder& b) { +SmallVector multipleControlledTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mctdg({q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledTdg(QCOProgramBuilder& b) { +SmallVector nestedControlledTdg(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -1142,26 +1026,23 @@ nestedControlledTdg(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledTdg(QCOProgramBuilder& b) { +SmallVector trivialControlledTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mctdg({}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseTdg(QCOProgramBuilder& b) { +SmallVector inverseTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.tdg(qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledTdg(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -1172,51 +1053,47 @@ inverseMultipleControlledTdg(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -tdgThenT(QCOProgramBuilder& b) { +SmallVector tdgThenT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.tdg(q[0]); q[0] = b.t(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoTdg(QCOProgramBuilder& b) { +SmallVector twoTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.tdg(q[0]); q[0] = b.tdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> sx(QCOProgramBuilder& b) { +SmallVector sx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sx(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledSx(QCOProgramBuilder& b) { +SmallVector singleControlledSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.csx(q[0], q[1]); q[0] = res.first; q[1] = res.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledSx(QCOProgramBuilder& b) { +SmallVector multipleControlledSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcsx({q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledSx(QCOProgramBuilder& b) { +SmallVector nestedControlledSx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -1226,26 +1103,23 @@ nestedControlledSx(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledSx(QCOProgramBuilder& b) { +SmallVector trivialControlledSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcsx({}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseSx(QCOProgramBuilder& b) { +SmallVector inverseSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.sx(qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledSx(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -1256,51 +1130,47 @@ inverseMultipleControlledSx(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -sxThenSxdg(QCOProgramBuilder& b) { +SmallVector sxThenSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sx(q[0]); q[0] = b.sxdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoSx(QCOProgramBuilder& b) { +SmallVector twoSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sx(q[0]); q[0] = b.sx(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> sxdg(QCOProgramBuilder& b) { +SmallVector sxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sxdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledSxdg(QCOProgramBuilder& b) { +SmallVector singleControlledSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.csxdg(q[0], q[1]); q[0] = res.first; q[1] = res.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledSxdg(QCOProgramBuilder& b) { +SmallVector multipleControlledSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcsxdg({q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledSxdg(QCOProgramBuilder& b) { +SmallVector nestedControlledSxdg(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -1310,26 +1180,23 @@ nestedControlledSxdg(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledSxdg(QCOProgramBuilder& b) { +SmallVector trivialControlledSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcsxdg({}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseSxdg(QCOProgramBuilder& b) { +SmallVector inverseSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.sxdg(qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledSxdg(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -1340,51 +1207,47 @@ inverseMultipleControlledSxdg(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -sxdgThenSx(QCOProgramBuilder& b) { +SmallVector sxdgThenSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sxdg(q[0]); q[0] = b.sx(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoSxdg(QCOProgramBuilder& b) { +SmallVector twoSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sxdg(q[0]); q[0] = b.sxdg(q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> rx(QCOProgramBuilder& b) { +SmallVector rx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rx(0.123, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRx(QCOProgramBuilder& b) { +SmallVector singleControlledRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.crx(0.123, q[0], q[1]); q[0] = res.first; q[1] = res.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRx(QCOProgramBuilder& b) { +SmallVector multipleControlledRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcrx(0.123, {q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRx(QCOProgramBuilder& b) { +SmallVector nestedControlledRx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = @@ -1395,26 +1258,23 @@ nestedControlledRx(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRx(QCOProgramBuilder& b) { +SmallVector trivialControlledRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcrx(0.123, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRx(QCOProgramBuilder& b) { +SmallVector inverseRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.rx(-0.123, qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledRx(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -1425,49 +1285,44 @@ inverseMultipleControlledRx(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRxOppositePhase(QCOProgramBuilder& b) { +SmallVector twoRxOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rx(0.123, q[0]); q[0] = b.rx(-0.123, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -rxPiOver2(QCOProgramBuilder& b) { +SmallVector rxPiOver2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rx(std::numbers::pi / 2, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> ry(QCOProgramBuilder& b) { +SmallVector ry(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.ry(0.456, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRy(QCOProgramBuilder& b) { +SmallVector singleControlledRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.cry(0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRy(QCOProgramBuilder& b) { +SmallVector multipleControlledRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcry(0.456, {q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRy(QCOProgramBuilder& b) { +SmallVector nestedControlledRy(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = @@ -1478,26 +1333,23 @@ nestedControlledRy(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRy(QCOProgramBuilder& b) { +SmallVector trivialControlledRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcry(0.456, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRy(QCOProgramBuilder& b) { +SmallVector inverseRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.ry(-0.456, qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledRy(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -1508,49 +1360,44 @@ inverseMultipleControlledRy(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRyOppositePhase(QCOProgramBuilder& b) { +SmallVector twoRyOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.ry(0.456, q[0]); q[0] = b.ry(-0.456, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -ryPiOver2(QCOProgramBuilder& b) { +SmallVector ryPiOver2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.ry(std::numbers::pi / 2, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> rz(QCOProgramBuilder& b) { +SmallVector rz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rz(0.789, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRz(QCOProgramBuilder& b) { +SmallVector singleControlledRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.crz(0.789, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRz(QCOProgramBuilder& b) { +SmallVector multipleControlledRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcrz(0.789, {q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRz(QCOProgramBuilder& b) { +SmallVector nestedControlledRz(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = @@ -1561,26 +1408,23 @@ nestedControlledRz(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRz(QCOProgramBuilder& b) { +SmallVector trivialControlledRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcrz(0.789, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRz(QCOProgramBuilder& b) { +SmallVector inverseRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.rz(-0.789, qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledRz(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -1591,42 +1435,38 @@ inverseMultipleControlledRz(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRzOppositePhase(QCOProgramBuilder& b) { +SmallVector twoRzOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rz(0.789, q[0]); q[0] = b.rz(-0.789, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> p(QCOProgramBuilder& b) { +SmallVector p(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.p(0.123, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledP(QCOProgramBuilder& b) { +SmallVector singleControlledP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.cp(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledP(QCOProgramBuilder& b) { +SmallVector multipleControlledP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcp(0.123, {q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledP(QCOProgramBuilder& b) { +SmallVector nestedControlledP(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = @@ -1637,26 +1477,23 @@ nestedControlledP(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledP(QCOProgramBuilder& b) { +SmallVector trivialControlledP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcp(0.123, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseP(QCOProgramBuilder& b) { +SmallVector inverseP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.p(-0.123, qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledP(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -1667,42 +1504,38 @@ inverseMultipleControlledP(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoPOppositePhase(QCOProgramBuilder& b) { +SmallVector twoPOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.p(0.123, q); q = b.p(-0.123, q); return measureAndReturn(b, {q}); } -std::pair, SmallVector> r(QCOProgramBuilder& b) { +SmallVector r(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.r(0.123, 0.456, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledR(QCOProgramBuilder& b) { +SmallVector singleControlledR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.cr(0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledR(QCOProgramBuilder& b) { +SmallVector multipleControlledR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcr(0.123, 0.456, {q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledR(QCOProgramBuilder& b) { +SmallVector nestedControlledR(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = @@ -1713,27 +1546,24 @@ nestedControlledR(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledR(QCOProgramBuilder& b) { +SmallVector trivialControlledR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcr(0.123, 0.456, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseR(QCOProgramBuilder& b) { +SmallVector inverseR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.r(-0.123, 0.456, qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledR(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -1744,55 +1574,50 @@ inverseMultipleControlledR(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -canonicalizeRToRx(QCOProgramBuilder& b) { +SmallVector canonicalizeRToRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.r(0.123, 0., q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -canonicalizeRToRy(QCOProgramBuilder& b) { +SmallVector canonicalizeRToRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.r(0.456, std::numbers::pi / 2, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoR(QCOProgramBuilder& b) { +SmallVector twoR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.r(0.045, 0.456, q[0]); q[0] = b.r(0.078, 0.456, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> u2(QCOProgramBuilder& b) { +SmallVector u2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u2(0.234, 0.567, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledU2(QCOProgramBuilder& b) { +SmallVector singleControlledU2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.cu2(0.234, 0.567, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledU2(QCOProgramBuilder& b) { +SmallVector multipleControlledU2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcu2(0.234, 0.567, {q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledU2(QCOProgramBuilder& b) { +SmallVector nestedControlledU2(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = @@ -1803,19 +1628,17 @@ nestedControlledU2(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledU2(QCOProgramBuilder& b) { +SmallVector trivialControlledU2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcu2(0.234, 0.567, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseU2(QCOProgramBuilder& b) { +SmallVector inverseU2(QCOProgramBuilder& b) { constexpr double pi = std::numbers::pi; auto q = b.allocQubitRegister(1); auto res = b.inv( @@ -1823,8 +1646,7 @@ inverseU2(QCOProgramBuilder& b) { return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledU2(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledU2(QCOProgramBuilder& b) { constexpr double pi = std::numbers::pi; auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { @@ -1836,55 +1658,49 @@ inverseMultipleControlledU2(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -canonicalizeU2ToH(QCOProgramBuilder& b) { +SmallVector canonicalizeU2ToH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u2(0., std::numbers::pi, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -canonicalizeU2ToRx(QCOProgramBuilder& b) { +SmallVector canonicalizeU2ToRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u2(-std::numbers::pi / 2, std::numbers::pi / 2, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -canonicalizeU2ToRy(QCOProgramBuilder& b) { +SmallVector canonicalizeU2ToRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u2(0., 0., q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> u(QCOProgramBuilder& b) { +SmallVector u(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u(0.1, 0.2, 0.3, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledU(QCOProgramBuilder& b) { +SmallVector singleControlledU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.cu(0.1, 0.2, 0.3, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledU(QCOProgramBuilder& b) { +SmallVector multipleControlledU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.mcu(0.1, 0.2, 0.3, {q[0], q[1]}, q[2]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledU(QCOProgramBuilder& b) { +SmallVector nestedControlledU(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto res = b.ctrl({reg[0]}, {reg[1], reg[2]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = @@ -1895,27 +1711,24 @@ nestedControlledU(QCOProgramBuilder& b) { reg[0] = res.first[0]; reg[1] = res.second[0]; reg[2] = res.second[1]; - return measureAndReturn(b, {reg[0], reg[1], reg[2]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledU(QCOProgramBuilder& b) { +SmallVector trivialControlledU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcu(0.1, 0.2, 0.3, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseU(QCOProgramBuilder& b) { +SmallVector inverseU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.u(-0.1, -0.3, -0.2, qubit); }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseMultipleControlledU(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetOut] = @@ -1926,66 +1739,59 @@ inverseMultipleControlledU(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -canonicalizeUToP(QCOProgramBuilder& b) { +SmallVector canonicalizeUToP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u(0., 0., 0.123, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -canonicalizeUToRx(QCOProgramBuilder& b) { +SmallVector canonicalizeUToRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u(0.123, -std::numbers::pi / 2, std::numbers::pi / 2, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -canonicalizeUToRy(QCOProgramBuilder& b) { +SmallVector canonicalizeUToRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u(0.456, 0., 0., q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -canonicalizeUToU2(QCOProgramBuilder& b) { +SmallVector canonicalizeUToU2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u(std::numbers::pi / 2, 0.234, 0.567, q[0]); - return measureAndReturn(b, {q[0]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> swap(QCOProgramBuilder& b) { +SmallVector swap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.swap(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledSwap(QCOProgramBuilder& b) { +SmallVector singleControlledSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.cswap(q[0], q[1], q[2]); q[0] = res.first; q[1] = res.second.first; q[2] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledSwap(QCOProgramBuilder& b) { +SmallVector multipleControlledSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.mcswap({q[0], q[1]}, q[2], q[3]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second.first; q[3] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledSwap(QCOProgramBuilder& b) { +SmallVector nestedControlledSwap(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto res = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { @@ -2002,20 +1808,18 @@ nestedControlledSwap(QCOProgramBuilder& b) { reg[1] = res.second[0]; reg[2] = res.second[1]; reg[3] = res.second[2]; - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledSwap(QCOProgramBuilder& b) { +SmallVector trivialControlledSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.mcswap({}, q[0], q[1]); q[0] = res.second.first; q[1] = res.second.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseSwap(QCOProgramBuilder& b) { +SmallVector inverseSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.swap(qubits[0], qubits[1]); @@ -2023,11 +1827,10 @@ inverseSwap(QCOProgramBuilder& b) { }); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledSwap(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = @@ -2039,53 +1842,49 @@ inverseMultipleControlledSwap(QCOProgramBuilder& b) { q[1] = res[1]; q[2] = res[2]; q[3] = res[3]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoSwap(QCOProgramBuilder& b) { +SmallVector twoSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.swap(q[0], q[1]); std::tie(q[0], q[1]) = b.swap(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoSwapSwappedTargets(QCOProgramBuilder& b) { +SmallVector twoSwapSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.swap(q[0], q[1]); std::tie(q[1], q[0]) = b.swap(q[1], q[0]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> iswap(QCOProgramBuilder& b) { +SmallVector iswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.iswap(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledIswap(QCOProgramBuilder& b) { +SmallVector singleControlledIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.ciswap(q[0], q[1], q[2]); q[0] = res.first; q[1] = res.second.first; q[2] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledIswap(QCOProgramBuilder& b) { +SmallVector multipleControlledIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.mciswap({q[0], q[1]}, q[2], q[3]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second.first; q[3] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledIswap(QCOProgramBuilder& b) { +SmallVector nestedControlledIswap(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto res = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { @@ -2102,20 +1901,18 @@ nestedControlledIswap(QCOProgramBuilder& b) { reg[1] = res.second[0]; reg[2] = res.second[1]; reg[3] = res.second[2]; - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledIswap(QCOProgramBuilder& b) { +SmallVector trivialControlledIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.mciswap({}, q[0], q[1]); q[0] = res.second.first; q[1] = res.second.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseIswap(QCOProgramBuilder& b) { +SmallVector inverseIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.iswap(qubits[0], qubits[1]); @@ -2123,11 +1920,10 @@ inverseIswap(QCOProgramBuilder& b) { }); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledIswap(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = @@ -2139,38 +1935,35 @@ inverseMultipleControlledIswap(QCOProgramBuilder& b) { q[1] = res[1]; q[2] = res[2]; q[3] = res[3]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> dcx(QCOProgramBuilder& b) { +SmallVector dcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.dcx(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledDcx(QCOProgramBuilder& b) { +SmallVector singleControlledDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.cdcx(q[0], q[1], q[2]); q[0] = res.first; q[1] = res.second.first; q[2] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledDcx(QCOProgramBuilder& b) { +SmallVector multipleControlledDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.mcdcx({q[0], q[1]}, q[2], q[3]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second.first; q[3] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledDcx(QCOProgramBuilder& b) { +SmallVector nestedControlledDcx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto res = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { @@ -2187,20 +1980,18 @@ nestedControlledDcx(QCOProgramBuilder& b) { reg[1] = res.second[0]; reg[2] = res.second[1]; reg[3] = res.second[2]; - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledDcx(QCOProgramBuilder& b) { +SmallVector trivialControlledDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.mcdcx({}, q[0], q[1]); q[0] = res.second.first; q[1] = res.second.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseDcx(QCOProgramBuilder& b) { +SmallVector inverseDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[1], q[0]}, [&](ValueRange qubits) { auto res = b.dcx(qubits[0], qubits[1]); @@ -2208,11 +1999,10 @@ inverseDcx(QCOProgramBuilder& b) { }); q[1] = res[0]; q[0] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledDcx(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.inv({q[0], q[1], q[3], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = @@ -2224,53 +2014,49 @@ inverseMultipleControlledDcx(QCOProgramBuilder& b) { q[1] = res[1]; q[3] = res[2]; q[2] = res[3]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoDcx(QCOProgramBuilder& b) { +SmallVector twoDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.dcx(q[0], q[1]); std::tie(q[0], q[1]) = b.dcx(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoDcxSwappedTargets(QCOProgramBuilder& b) { +SmallVector twoDcxSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.dcx(q[0], q[1]); std::tie(q[1], q[0]) = b.dcx(q[1], q[0]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> ecr(QCOProgramBuilder& b) { +SmallVector ecr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.ecr(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledEcr(QCOProgramBuilder& b) { +SmallVector singleControlledEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.cecr(q[0], q[1], q[2]); q[0] = res.first; q[1] = res.second.first; q[2] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledEcr(QCOProgramBuilder& b) { +SmallVector multipleControlledEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.mcecr({q[0], q[1]}, q[2], q[3]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second.first; q[3] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledEcr(QCOProgramBuilder& b) { +SmallVector nestedControlledEcr(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto res = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { @@ -2287,20 +2073,18 @@ nestedControlledEcr(QCOProgramBuilder& b) { reg[1] = res.second[0]; reg[2] = res.second[1]; reg[3] = res.second[2]; - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledEcr(QCOProgramBuilder& b) { +SmallVector trivialControlledEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.mcecr({}, q[0], q[1]); q[0] = res.second.first; q[1] = res.second.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseEcr(QCOProgramBuilder& b) { +SmallVector inverseEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.ecr(qubits[0], qubits[1]); @@ -2308,11 +2092,10 @@ inverseEcr(QCOProgramBuilder& b) { }); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledEcr(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = @@ -2324,45 +2107,42 @@ inverseMultipleControlledEcr(QCOProgramBuilder& b) { q[1] = res[1]; q[2] = res[2]; q[3] = res[3]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoEcr(QCOProgramBuilder& b) { +SmallVector twoEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.ecr(q[0], q[1]); std::tie(q[0], q[1]) = b.ecr(q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> rxx(QCOProgramBuilder& b) { +SmallVector rxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rxx(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRxx(QCOProgramBuilder& b) { +SmallVector singleControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.crxx(0.123, q[0], q[1], q[2]); q[0] = res.first; q[1] = res.second.first; q[2] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRxx(QCOProgramBuilder& b) { +SmallVector multipleControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second.first; q[3] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRxx(QCOProgramBuilder& b) { +SmallVector nestedControlledRxx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto res = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { @@ -2379,20 +2159,18 @@ nestedControlledRxx(QCOProgramBuilder& b) { reg[1] = res.second[0]; reg[2] = res.second[1]; reg[3] = res.second[2]; - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRxx(QCOProgramBuilder& b) { +SmallVector trivialControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.mcrxx(0.123, {}, q[0], q[1]); q[0] = res.second.first; q[1] = res.second.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRxx(QCOProgramBuilder& b) { +SmallVector inverseRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.rxx(-0.123, qubits[0], qubits[1]); @@ -2400,11 +2178,10 @@ inverseRxx(QCOProgramBuilder& b) { }); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledRxx(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = @@ -2416,11 +2193,10 @@ inverseMultipleControlledRxx(QCOProgramBuilder& b) { q[1] = res[1]; q[2] = res[2]; q[3] = res[3]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -tripleControlledRxx(QCOProgramBuilder& b) { +SmallVector tripleControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(5); auto res = b.mcrxx(0.123, {q[0], q[1], q[2]}, q[3], q[4]); q[0] = res.first[0]; @@ -2428,11 +2204,10 @@ tripleControlledRxx(QCOProgramBuilder& b) { q[2] = res.first[2]; q[3] = res.second.first; q[4] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -fourControlledRxx(QCOProgramBuilder& b) { +SmallVector fourControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(6); auto res = b.mcrxx(0.123, {q[0], q[1], q[2], q[3]}, q[4], q[5]); q[0] = res.first[0]; @@ -2441,71 +2216,65 @@ fourControlledRxx(QCOProgramBuilder& b) { q[3] = res.first[3]; q[4] = res.second.first; q[5] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4], q[5]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoRxx(QCOProgramBuilder& b) { +SmallVector twoRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); // 0.045 + 0.078 = 0.123 std::tie(q[0], q[1]) = b.rxx(0.045, q[0], q[1]); std::tie(q[0], q[1]) = b.rxx(0.078, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRxxSwappedTargets(QCOProgramBuilder& b) { +SmallVector twoRxxSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); // 0.045 + 0.078 = 0.123 std::tie(q[0], q[1]) = b.rxx(0.045, q[0], q[1]); std::tie(q[1], q[0]) = b.rxx(0.078, q[1], q[0]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRxxOppositePhase(QCOProgramBuilder& b) { +SmallVector twoRxxOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rxx(0.123, q[0], q[1]); std::tie(q[0], q[1]) = b.rxx(-0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRxxOppositePhaseSwappedTargets(QCOProgramBuilder& b) { +SmallVector twoRxxOppositePhaseSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rxx(0.123, q[0], q[1]); std::tie(q[1], q[0]) = b.rxx(-0.123, q[1], q[0]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> ryy(QCOProgramBuilder& b) { +SmallVector ryy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.ryy(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRyy(QCOProgramBuilder& b) { +SmallVector singleControlledRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.cryy(0.123, q[0], q[1], q[2]); q[0] = res.first; q[1] = res.second.first; q[2] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRyy(QCOProgramBuilder& b) { +SmallVector multipleControlledRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.mcryy(0.123, {q[0], q[1]}, q[2], q[3]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second.first; q[3] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRyy(QCOProgramBuilder& b) { +SmallVector nestedControlledRyy(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto res = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { @@ -2522,20 +2291,18 @@ nestedControlledRyy(QCOProgramBuilder& b) { reg[1] = res.second[0]; reg[2] = res.second[1]; reg[3] = res.second[2]; - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRyy(QCOProgramBuilder& b) { +SmallVector trivialControlledRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.mcryy(0.123, {}, q[0], q[1]); q[0] = res.second.first; q[1] = res.second.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRyy(QCOProgramBuilder& b) { +SmallVector inverseRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.ryy(-0.123, qubits[0], qubits[1]); @@ -2543,11 +2310,10 @@ inverseRyy(QCOProgramBuilder& b) { }); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledRyy(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = @@ -2559,71 +2325,65 @@ inverseMultipleControlledRyy(QCOProgramBuilder& b) { q[1] = res[1]; q[2] = res[2]; q[3] = res[3]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoRyy(QCOProgramBuilder& b) { +SmallVector twoRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); // 0.045 + 0.078 = 0.123 std::tie(q[0], q[1]) = b.ryy(0.045, q[0], q[1]); std::tie(q[0], q[1]) = b.ryy(0.078, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRyyOppositePhaseSwappedTargets(QCOProgramBuilder& b) { +SmallVector twoRyyOppositePhaseSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.ryy(0.123, q[0], q[1]); std::tie(q[1], q[0]) = b.ryy(-0.123, q[1], q[0]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRyyOppositePhase(QCOProgramBuilder& b) { +SmallVector twoRyyOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.ryy(0.123, q[0], q[1]); std::tie(q[0], q[1]) = b.ryy(-0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRyySwappedTargets(QCOProgramBuilder& b) { +SmallVector twoRyySwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); // 0.045 + 0.078 = 0.123 std::tie(q[0], q[1]) = b.ryy(0.045, q[0], q[1]); std::tie(q[1], q[0]) = b.ryy(0.078, q[1], q[0]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> rzx(QCOProgramBuilder& b) { +SmallVector rzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rzx(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRzx(QCOProgramBuilder& b) { +SmallVector singleControlledRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.crzx(0.123, q[0], q[1], q[2]); q[0] = res.first; q[1] = res.second.first; q[2] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRzx(QCOProgramBuilder& b) { +SmallVector multipleControlledRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.mcrzx(0.123, {q[0], q[1]}, q[2], q[3]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second.first; q[3] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRzx(QCOProgramBuilder& b) { +SmallVector nestedControlledRzx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto res = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { @@ -2640,20 +2400,18 @@ nestedControlledRzx(QCOProgramBuilder& b) { reg[1] = res.second[0]; reg[2] = res.second[1]; reg[3] = res.second[2]; - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRzx(QCOProgramBuilder& b) { +SmallVector trivialControlledRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.mcrzx(0.123, {}, q[0], q[1]); q[0] = res.second.first; q[1] = res.second.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRzx(QCOProgramBuilder& b) { +SmallVector inverseRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.rzx(-0.123, qubits[0], qubits[1]); @@ -2661,11 +2419,10 @@ inverseRzx(QCOProgramBuilder& b) { }); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledRzx(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = @@ -2677,46 +2434,42 @@ inverseMultipleControlledRzx(QCOProgramBuilder& b) { q[1] = res[1]; q[2] = res[2]; q[3] = res[3]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRzxOppositePhase(QCOProgramBuilder& b) { +SmallVector twoRzxOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rzx(0.123, q[0], q[1]); std::tie(q[0], q[1]) = b.rzx(-0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> rzz(QCOProgramBuilder& b) { +SmallVector rzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rzz(0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledRzz(QCOProgramBuilder& b) { +SmallVector singleControlledRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.crzz(0.123, q[0], q[1], q[2]); q[0] = res.first; q[1] = res.second.first; q[2] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledRzz(QCOProgramBuilder& b) { +SmallVector multipleControlledRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.mcrzz(0.123, {q[0], q[1]}, q[2], q[3]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second.first; q[3] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledRzz(QCOProgramBuilder& b) { +SmallVector nestedControlledRzz(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto res = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { @@ -2733,20 +2486,18 @@ nestedControlledRzz(QCOProgramBuilder& b) { reg[1] = res.second[0]; reg[2] = res.second[1]; reg[3] = res.second[2]; - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledRzz(QCOProgramBuilder& b) { +SmallVector trivialControlledRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.mcrzz(0.123, {}, q[0], q[1]); q[0] = res.second.first; q[1] = res.second.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseRzz(QCOProgramBuilder& b) { +SmallVector inverseRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.rzz(-0.123, qubits[0], qubits[1]); @@ -2754,11 +2505,10 @@ inverseRzz(QCOProgramBuilder& b) { }); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledRzz(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = @@ -2770,72 +2520,65 @@ inverseMultipleControlledRzz(QCOProgramBuilder& b) { q[1] = res[1]; q[2] = res[2]; q[3] = res[3]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> twoRzz(QCOProgramBuilder& b) { +SmallVector twoRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); // 0.045 + 0.078 = 0.123 std::tie(q[0], q[1]) = b.rzz(0.045, q[0], q[1]); std::tie(q[0], q[1]) = b.rzz(0.078, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRzzSwappedTargets(QCOProgramBuilder& b) { +SmallVector twoRzzSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); // 0.045 + 0.078 = 0.123 std::tie(q[0], q[1]) = b.rzz(0.045, q[0], q[1]); std::tie(q[1], q[0]) = b.rzz(0.078, q[1], q[0]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRzzOppositePhase(QCOProgramBuilder& b) { +SmallVector twoRzzOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rzz(0.123, q[0], q[1]); std::tie(q[0], q[1]) = b.rzz(-0.123, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoRzzOppositePhaseSwappedTargets(QCOProgramBuilder& b) { +SmallVector twoRzzOppositePhaseSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rzz(0.123, q[0], q[1]); std::tie(q[1], q[0]) = b.rzz(-0.123, q[1], q[0]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -xxPlusYY(QCOProgramBuilder& b) { +SmallVector xxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.xx_plus_yy(0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledXxPlusYY(QCOProgramBuilder& b) { +SmallVector singleControlledXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.cxx_plus_yy(0.123, 0.456, q[0], q[1], q[2]); q[0] = res.first; q[1] = res.second.first; q[2] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledXxPlusYY(QCOProgramBuilder& b) { +SmallVector multipleControlledXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.mcxx_plus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second.first; q[3] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledXxPlusYY(QCOProgramBuilder& b) { +SmallVector nestedControlledXxPlusYY(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto res = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { @@ -2853,20 +2596,18 @@ nestedControlledXxPlusYY(QCOProgramBuilder& b) { reg[1] = res.second[0]; reg[2] = res.second[1]; reg[3] = res.second[2]; - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledXxPlusYY(QCOProgramBuilder& b) { +SmallVector trivialControlledXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.mcxx_plus_yy(0.123, 0.456, {}, q[0], q[1]); q[0] = res.second.first; q[1] = res.second.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseXxPlusYY(QCOProgramBuilder& b) { +SmallVector inverseXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.xx_plus_yy(-0.123, 0.456, qubits[0], qubits[1]); @@ -2874,11 +2615,10 @@ inverseXxPlusYY(QCOProgramBuilder& b) { }); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledXxPlusYY(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.mcxx_plus_yy( @@ -2890,55 +2630,49 @@ inverseMultipleControlledXxPlusYY(QCOProgramBuilder& b) { q[1] = res[1]; q[2] = res[2]; q[3] = res[3]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoXxPlusYYOppositePhase(QCOProgramBuilder& b) { +SmallVector twoXxPlusYYOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.xx_plus_yy(0.123, 0.456, q[0], q[1]); std::tie(q[0], q[1]) = b.xx_plus_yy(-0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoXxPlusYYSwappedTargets(QCOProgramBuilder& b) { +SmallVector twoXxPlusYYSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.xx_plus_yy(0.045, 0.456, q[0], q[1]); std::tie(q[1], q[0]) = b.xx_plus_yy(0.078, 0.456, q[1], q[0]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -xxMinusYY(QCOProgramBuilder& b) { +SmallVector xxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.xx_minus_yy(0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledXxMinusYY(QCOProgramBuilder& b) { +SmallVector singleControlledXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.cxx_minus_yy(0.123, 0.456, q[0], q[1], q[2]); q[0] = res.first; q[1] = res.second.first; q[2] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -multipleControlledXxMinusYY(QCOProgramBuilder& b) { +SmallVector multipleControlledXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.mcxx_minus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); q[0] = res.first[0]; q[1] = res.first[1]; q[2] = res.second.first; q[3] = res.second.second; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -nestedControlledXxMinusYY(QCOProgramBuilder& b) { +SmallVector nestedControlledXxMinusYY(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto res = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { @@ -2956,20 +2690,18 @@ nestedControlledXxMinusYY(QCOProgramBuilder& b) { reg[1] = res.second[0]; reg[2] = res.second[1]; reg[3] = res.second[2]; - return measureAndReturn(b, {reg[0], reg[1], reg[2], reg[3]}); + return measureAndReturn(b, reg.qubits); } -std::pair, SmallVector> -trivialControlledXxMinusYY(QCOProgramBuilder& b) { +SmallVector trivialControlledXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.mcxx_minus_yy(0.123, 0.456, {}, q[0], q[1]); q[0] = res.second.first; q[1] = res.second.second; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseXxMinusYY(QCOProgramBuilder& b) { +SmallVector inverseXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto res = b.xx_minus_yy(-0.123, 0.456, qubits[0], qubits[1]); @@ -2977,11 +2709,10 @@ inverseXxMinusYY(QCOProgramBuilder& b) { }); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -inverseMultipleControlledXxMinusYY(QCOProgramBuilder& b) { +SmallVector inverseMultipleControlledXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.inv({q[0], q[1], q[2], q[3]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = b.mcxx_minus_yy( @@ -2993,67 +2724,60 @@ inverseMultipleControlledXxMinusYY(QCOProgramBuilder& b) { q[1] = res[1]; q[2] = res[2]; q[3] = res[3]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoXxMinusYYOppositePhase(QCOProgramBuilder& b) { +SmallVector twoXxMinusYYOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.xx_minus_yy(0.123, 0.456, q[0], q[1]); std::tie(q[0], q[1]) = b.xx_minus_yy(-0.123, 0.456, q[0], q[1]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -twoXxMinusYYSwappedTargets(QCOProgramBuilder& b) { +SmallVector twoXxMinusYYSwappedTargets(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.xx_minus_yy(0.045, 0.456, q[0], q[1]); std::tie(q[1], q[0]) = b.xx_minus_yy(0.078, 0.456, q[1], q[0]); - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> barrier(QCOProgramBuilder& b) { +SmallVector barrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto q1 = b.barrier(q[0]); return measureAndReturn(b, {q1}); } -std::pair, SmallVector> -barrierTwoQubits(QCOProgramBuilder& b) { +SmallVector barrierTwoQubits(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.barrier({q[0], q[1]}); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -barrierMultipleQubits(QCOProgramBuilder& b) { +SmallVector barrierMultipleQubits(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.barrier({q[0], q[1], q[2]}); q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -singleControlledBarrier(QCOProgramBuilder& b) { +SmallVector singleControlledBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.ctrl(q[1], q[0], [&](Value target) { return b.barrier({target})[0]; }); return measureAndReturn(b, {res.second}); } -std::pair, SmallVector> -inverseBarrier(QCOProgramBuilder& b) { +SmallVector inverseBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.barrier({qubit})[0]; }); return measureAndReturn(b, {res}); } -std::pair, SmallVector> -twoBarrier(QCOProgramBuilder& b) { +SmallVector twoBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto b1 = b.barrier({q[0], q[1]}); q[0] = b1[0]; @@ -3061,29 +2785,26 @@ twoBarrier(QCOProgramBuilder& b) { auto b2 = b.barrier({q[0], q[1]}); q[0] = b2[0]; q[1] = b2[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -trivialCtrl(QCOProgramBuilder& b) { +SmallVector trivialCtrl(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto [_, q01] = b.ctrl({}, {q[0], q[1]}, [&](ValueRange targets) { auto [q0, q1] = b.rxx(0.123, targets[0], targets[1]); return SmallVector{q0, q1}; }); - return measureAndReturn(b, {q01[0], q01[1]}); + return measureAndReturn(b, q01); } -std::pair, SmallVector> -emptyCtrl(QCOProgramBuilder& b) { +SmallVector emptyCtrl(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rxx(0.123, q[0], q[1]); auto [res0, res1] = b.ctrl(q[0], q[1], [&](Value target) { return target; }); return measureAndReturn(b, {res0, res1}); } -std::pair, SmallVector> -nestedCtrl(QCOProgramBuilder& b) { +SmallVector nestedCtrl(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.ctrl({q[0]}, {q[1], q[2], q[3]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -3098,11 +2819,10 @@ nestedCtrl(QCOProgramBuilder& b) { q[1] = res.second[0]; q[2] = res.second[1]; q[3] = res.second[2]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -tripleNestedCtrl(QCOProgramBuilder& b) { +SmallVector tripleNestedCtrl(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(5); auto res = b.ctrl({q[0]}, {q[1], q[2], q[3], q[4]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl( @@ -3126,11 +2846,10 @@ tripleNestedCtrl(QCOProgramBuilder& b) { q[2] = res.second[1]; q[3] = res.second[2]; q[4] = res.second[3]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -doubleNestedCtrlTwoQubits(QCOProgramBuilder& b) { +SmallVector doubleNestedCtrlTwoQubits(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(6); auto res = b.ctrl({q[0], q[1]}, {q[2], q[3], q[4], q[5]}, [&](ValueRange targets) { @@ -3150,11 +2869,10 @@ doubleNestedCtrlTwoQubits(QCOProgramBuilder& b) { q[3] = res.second[1]; q[4] = res.second[2]; q[5] = res.second[3]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3], q[4], q[5]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -ctrlInvSandwich(QCOProgramBuilder& b) { +SmallVector ctrlInvSandwich(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.ctrl({q[0]}, {q[1], q[2], q[3]}, [&](ValueRange targets) { auto inner = b.inv( @@ -3175,10 +2893,10 @@ ctrlInvSandwich(QCOProgramBuilder& b) { q[1] = res.second[0]; q[2] = res.second[1]; q[3] = res.second[2]; - return measureAndReturn(b, {q[0], q[1], q[2], q[3]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> ctrlTwo(QCOProgramBuilder& b) { +SmallVector ctrlTwo(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.ctrl({q[0], q[1]}, {q[2], q[3]}, [&](ValueRange targets) { auto i0 = targets[0]; @@ -3191,8 +2909,7 @@ std::pair, SmallVector> ctrlTwo(QCOProgramBuilder& b) { b, {res.first[0], res.first[1], res.second[0], res.second[1]}); } -std::pair, SmallVector> -ctrlTwoMixed(QCOProgramBuilder& b) { +SmallVector ctrlTwoMixed(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.ctrl({q[0], q[1]}, {q[2], q[3]}, [&](ValueRange targets) { auto i0 = targets[0]; @@ -3205,8 +2922,7 @@ ctrlTwoMixed(QCOProgramBuilder& b) { b, {res.first[0], res.first[1], res.second[0], res.second[1]}); } -std::pair, SmallVector> -nestedCtrlTwo(QCOProgramBuilder& b) { +SmallVector nestedCtrlTwo(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); auto res = b.ctrl(q[0], {q[1], q[2], q[3]}, [&](ValueRange targets) { const auto& [controlsOut, targetsOut] = b.ctrl( @@ -3223,8 +2939,7 @@ nestedCtrlTwo(QCOProgramBuilder& b) { b, {res.first[0], res.second[0], res.second[1], res.second[2]}); } -std::pair, SmallVector> -ctrlInvTwo(QCOProgramBuilder& b) { +SmallVector ctrlInvTwo(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.ctrl(q[0], {q[1], q[2]}, [&](ValueRange targets) { auto inner = b.inv(targets, [&](ValueRange qubits) { @@ -3239,16 +2954,14 @@ ctrlInvTwo(QCOProgramBuilder& b) { return measureAndReturn(b, {res.first[0], res.second[0], res.second[1]}); } -std::pair, SmallVector> -emptyInv(QCOProgramBuilder& b) { +SmallVector emptyInv(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); std::tie(q[0], q[1]) = b.rxx(0.123, q[0], q[1]); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { return qubits; }); - return measureAndReturn(b, {res[0], res[1]}); + return measureAndReturn(b, res); } -std::pair, SmallVector> -nestedInv(QCOProgramBuilder& b) { +SmallVector nestedInv(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto inner = b.inv({qubits[0], qubits[1]}, [&](ValueRange innerQubits) { @@ -3259,11 +2972,10 @@ nestedInv(QCOProgramBuilder& b) { }); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -tripleNestedInv(QCOProgramBuilder& b) { +SmallVector tripleNestedInv(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto inner1 = b.inv({qubits[0], qubits[1]}, [&](ValueRange innerQubits) { @@ -3279,11 +2991,10 @@ tripleNestedInv(QCOProgramBuilder& b) { }); q[0] = res[0]; q[1] = res[1]; - return measureAndReturn(b, {q[0], q[1]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> -invCtrlSandwich(QCOProgramBuilder& b) { +SmallVector invCtrlSandwich(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = @@ -3300,10 +3011,10 @@ invCtrlSandwich(QCOProgramBuilder& b) { q[0] = res[0]; q[1] = res[1]; q[2] = res[2]; - return measureAndReturn(b, {q[0], q[1], q[2]}); + return measureAndReturn(b, q.qubits); } -std::pair, SmallVector> invTwo(QCOProgramBuilder& b) { +SmallVector invTwo(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { auto i0 = qubits[0]; @@ -3312,11 +3023,10 @@ std::pair, SmallVector> invTwo(QCOProgramBuilder& b) { std::tie(i0, i1) = b.rxx(0.123, i0, i1); return SmallVector{i0, i1}; }); - return measureAndReturn(b, {res[0], res[1]}); + return measureAndReturn(b, res); } -std::pair, SmallVector> -invCtrlTwo(QCOProgramBuilder& b) { +SmallVector invCtrlTwo(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange qubits) { const auto& [controlsOut, targetsOut] = @@ -3329,11 +3039,10 @@ invCtrlTwo(QCOProgramBuilder& b) { }); return llvm::to_vector(llvm::concat(controlsOut, targetsOut)); }); - return measureAndReturn(b, {res[0], res[1], res[2]}); + return measureAndReturn(b, res); } -std::pair, SmallVector> -simpleIf(QCOProgramBuilder& b) { +SmallVector simpleIf(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto q0 = b.h(q[0]); auto [measuredQubit, measureResult] = b.measure(q0); @@ -3343,11 +3052,10 @@ simpleIf(QCOProgramBuilder& b) { }); q[0] = res[0]; auto [q1, bit] = b.measure(q[0]); - return {{measureResult, bit}, {b.getI1Type(), b.getI1Type()}}; + return {measureResult, bit}; } -std::pair, SmallVector> -ifWithAngle(QCOProgramBuilder& b) { +SmallVector ifWithAngle(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto theta = b.floatConstant(0.123); auto q0 = b.h(q[0]); @@ -3359,8 +3067,7 @@ ifWithAngle(QCOProgramBuilder& b) { return measureAndReturn(b, {q0}); } -std::pair, SmallVector> -ifTwoQubits(QCOProgramBuilder& b) { +SmallVector ifTwoQubits(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto q0 = b.h(q[0]); auto [measuredQubit, measureResult] = b.measure(q0); @@ -3374,11 +3081,10 @@ ifTwoQubits(QCOProgramBuilder& b) { q[1] = res[1]; auto [q0_, c0] = b.measure(q[0]); auto [q1, c1] = b.measure(q[1]); - return {{measureResult, c0, c1}, - {b.getI1Type(), b.getI1Type(), b.getI1Type()}}; + return {measureResult, c0, c1}; } -std::pair, SmallVector> ifElse(QCOProgramBuilder& b) { +SmallVector ifElse(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto q0 = b.h(q[0]); auto [measuredQubit, measureResult] = b.measure(q0); @@ -3394,11 +3100,10 @@ std::pair, SmallVector> ifElse(QCOProgramBuilder& b) { }); q[0] = res[0]; auto [q0_, c0] = b.measure(q[0]); - return {{measureResult, c0}, {b.getI1Type(), b.getI1Type()}}; + return {measureResult, c0}; } -std::pair, SmallVector> -ifOneQubitOneTensor(QCOProgramBuilder& b) { +SmallVector ifOneQubitOneTensor(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto t0 = b.allocQubitRegister(1); auto q1 = b.h(q0); @@ -3414,8 +3119,7 @@ ifOneQubitOneTensor(QCOProgramBuilder& b) { return measureAndReturn(b, {ifRes[0]}); } -std::pair, SmallVector> -constantTrueIf(QCOProgramBuilder& b) { +SmallVector constantTrueIf(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto ifRes = b.qcoIf( true, q.qubits, @@ -3430,8 +3134,7 @@ constantTrueIf(QCOProgramBuilder& b) { return measureAndReturn(b, {ifRes[0]}); } -std::pair, SmallVector> -constantFalseIf(QCOProgramBuilder& b) { +SmallVector constantFalseIf(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto ifRes = b.qcoIf( false, q.qubits, @@ -3446,8 +3149,7 @@ constantFalseIf(QCOProgramBuilder& b) { return measureAndReturn(b, {ifRes[0]}); } -std::pair, SmallVector> -nestedTrueIf(QCOProgramBuilder& b) { +SmallVector nestedTrueIf(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto q0 = b.h(q[0]); auto [measuredQubit, measureResult] = b.measure(q0); @@ -3460,11 +3162,10 @@ nestedTrueIf(QCOProgramBuilder& b) { return llvm::to_vector(innerResult); }); auto [q1, c] = b.measure(ifRes[0]); - return {{measureResult, c}, {b.getI1Type(), b.getI1Type()}}; + return {measureResult, c}; } -std::pair, SmallVector> -nestedFalseIf(QCOProgramBuilder& b) { +SmallVector nestedFalseIf(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto q0 = b.h(q[0]); auto [measuredQubit, measureResult] = b.measure(q0); @@ -3485,24 +3186,21 @@ nestedFalseIf(QCOProgramBuilder& b) { return llvm::to_vector(innerResult); }); auto [q1, c] = b.measure(ifRes[0]); - return {{measureResult, c}, {b.getI1Type(), b.getI1Type()}}; + return {measureResult, c}; } -std::pair, SmallVector> -qtensorAlloc(QCOProgramBuilder& b) { +SmallVector qtensorAlloc(QCOProgramBuilder& b) { (void)b.qtensorAlloc(3); return measureAndReturn(b, {}); } -std::pair, SmallVector> -qtensorDealloc(QCOProgramBuilder& b) { +SmallVector qtensorDealloc(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); b.qtensorDealloc(qtensor); return measureAndReturn(b, {}); } -std::pair, SmallVector> -qtensorFromElements(QCOProgramBuilder& b) { +SmallVector qtensorFromElements(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.allocQubit(); auto q2 = b.allocQubit(); @@ -3510,15 +3208,13 @@ qtensorFromElements(QCOProgramBuilder& b) { return measureAndReturn(b, {}); } -std::pair, SmallVector> -qtensorExtract(QCOProgramBuilder& b) { +SmallVector qtensorExtract(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [t, q] = b.qtensorExtract(qtensor, 0); return measureAndReturn(b, {q}); } -std::pair, SmallVector> -qtensorInsert(QCOProgramBuilder& b) { +SmallVector qtensorInsert(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); auto q1 = b.h(q0); @@ -3526,24 +3222,21 @@ qtensorInsert(QCOProgramBuilder& b) { return measureAndReturn(b, {}); } -std::pair, SmallVector> -qtensorExtractInsertIndexMismatch(QCOProgramBuilder& b) { +SmallVector qtensorExtractInsertIndexMismatch(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); (void)b.qtensorInsert(q0, extractOutTensor, 1); return measureAndReturn(b, {}); } -std::pair, SmallVector> -qtensorExtractInsertSameIndex(QCOProgramBuilder& b) { +SmallVector qtensorExtractInsertSameIndex(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); (void)b.qtensorInsert(q0, extractOutTensor, 0); return measureAndReturn(b, {}); } -std::pair, SmallVector> -qtensorInsertExtractIndexMismatch(QCOProgramBuilder& b) { +SmallVector qtensorInsertExtractIndexMismatch(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); auto q1 = b.h(q0); @@ -3553,8 +3246,7 @@ qtensorInsertExtractIndexMismatch(QCOProgramBuilder& b) { return measureAndReturn(b, {}); } -std::pair, SmallVector> -qtensorInsertExtractSameIndex(QCOProgramBuilder& b) { +SmallVector qtensorInsertExtractSameIndex(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [extractOutTensor, q0] = b.qtensorExtract(qtensor, 0); auto q1 = b.h(q0); @@ -3564,8 +3256,7 @@ qtensorInsertExtractSameIndex(QCOProgramBuilder& b) { return measureAndReturn(b, {}); } -std::pair, SmallVector> -qtensorChain(QCOProgramBuilder& b) { +SmallVector qtensorChain(QCOProgramBuilder& b) { Value q0; Value q1; Value q2; @@ -3585,8 +3276,7 @@ qtensorChain(QCOProgramBuilder& b) { return measureAndReturn(b, {}); } -std::pair, SmallVector> -qtensorAlternativeChain(QCOProgramBuilder& b) { +SmallVector qtensorAlternativeChain(QCOProgramBuilder& b) { Value q0; Value q1; Value q2; @@ -3606,8 +3296,7 @@ qtensorAlternativeChain(QCOProgramBuilder& b) { return measureAndReturn(b, {}); } -std::pair, SmallVector> -simpleWhileReset(QCOProgramBuilder& b) { +SmallVector simpleWhileReset(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.h(q0); auto scfWhile = b.scfWhile( @@ -3624,8 +3313,7 @@ simpleWhileReset(QCOProgramBuilder& b) { return measureAndReturn(b, {scfWhile[0]}); } -std::pair, SmallVector> -simpleDoWhileReset(QCOProgramBuilder& b) { +SmallVector simpleDoWhileReset(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto scfWhile = b.scfWhile( ValueRange{q0}, @@ -3639,8 +3327,7 @@ simpleDoWhileReset(QCOProgramBuilder& b) { return measureAndReturn(b, {scfWhile[0]}); } -std::pair, SmallVector> -simpleForLoop(QCOProgramBuilder& b) { +SmallVector simpleForLoop(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto scfFor = b.scfFor(0, 2, 1, {reg.value}, [&](Value iv, ValueRange iterArgs) { @@ -3652,8 +3339,7 @@ simpleForLoop(QCOProgramBuilder& b) { return measureAndReturnQTensor(b, scfFor[0], 2); }; -std::pair, SmallVector> -forLoopWithAngle(QCOProgramBuilder& b) { +SmallVector forLoopWithAngle(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto theta = b.floatConstant(0.123); auto scfFor = @@ -3667,8 +3353,7 @@ forLoopWithAngle(QCOProgramBuilder& b) { return measureAndReturn(b, {q}); } -std::pair, SmallVector> -nestedForLoopIfOp(QCOProgramBuilder& b) { +SmallVector nestedForLoopIfOp(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto q0 = b.allocQubit(); auto scfFor = @@ -3686,8 +3371,7 @@ nestedForLoopIfOp(QCOProgramBuilder& b) { return measureAndReturn(b, {scfFor[1]}); } -std::pair, SmallVector> -nestedForLoopWhileOp(QCOProgramBuilder& b) { +SmallVector nestedForLoopWhileOp(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto loopResult = b.scfFor(0, 2, 1, {reg.value}, [&](Value iv, ValueRange iterArgs) { @@ -3716,8 +3400,7 @@ nestedForLoopWhileOp(QCOProgramBuilder& b) { return measureAndReturnQTensor(b, scfFor[0], 2); } -std::pair, SmallVector> -nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b) { +SmallVector nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto control0 = b.allocQubit(); auto control1 = b.h(control0); @@ -3733,8 +3416,7 @@ nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b) { return measureAndReturn(b, {scfFor[1]}); } -std::pair, SmallVector> -nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b) { +SmallVector nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto control = b.h(reg[0]); auto scfFor = b.scfFor( @@ -3749,8 +3431,7 @@ nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b) { return measureAndReturn(b, {scfFor[1]}); } -std::pair, SmallVector> -nestedIfOpForLoop(QCOProgramBuilder& b) { +SmallVector nestedIfOpForLoop(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); auto q1 = b.h(q0); @@ -3774,8 +3455,7 @@ nestedIfOpForLoop(QCOProgramBuilder& b) { return measureAndReturn(b, {ifRes[1]}); } -std::pair, SmallVector> -nestedIfOpForLoopWithAngle(QCOProgramBuilder& b) { +SmallVector nestedIfOpForLoopWithAngle(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); auto theta1 = b.floatConstant(0.123); @@ -3801,8 +3481,7 @@ nestedIfOpForLoopWithAngle(QCOProgramBuilder& b) { return measureAndReturn(b, {res[1]}); } -std::pair, SmallVector> -controlledXH(QCOProgramBuilder& b) { +SmallVector controlledXH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto [ctrl, targ] = b.ctrl(q[0], q[1], [&](Value target) { target = b.x(target); @@ -3811,8 +3490,7 @@ controlledXH(QCOProgramBuilder& b) { return measureAndReturn(b, {ctrl, targ}); } -std::pair, SmallVector> -controlledInverseHT(QCOProgramBuilder& b) { +SmallVector controlledInverseHT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto [ctrl, targ] = b.ctrl(q[0], q[1], [&](ValueRange targets) { auto wire = b.inv({targets[0]}, [&](ValueRange innerTargets) { @@ -3825,19 +3503,17 @@ controlledInverseHT(QCOProgramBuilder& b) { return measureAndReturn(b, {ctrl[0], targ[0]}); } -std::pair, SmallVector> -inverseTwoRxRy(QCOProgramBuilder& b) { +SmallVector inverseTwoRxRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange targets) { auto w0 = b.rx(0.2, targets[0]); auto w1 = b.ry(0.3, targets[1]); return SmallVector{w0, w1}; }); - return measureAndReturn(b, {res[0], res[1]}); + return measureAndReturn(b, res); } -std::pair, SmallVector> -inverseCxThenRz(QCOProgramBuilder& b) { +SmallVector inverseCxThenRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange targets) { auto w0 = targets[0]; @@ -3846,11 +3522,10 @@ inverseCxThenRz(QCOProgramBuilder& b) { w1 = b.rz(0.4, w1); return SmallVector{w0, w1}; }); - return measureAndReturn(b, {res[0], res[1]}); + return measureAndReturn(b, res); } -std::pair, SmallVector> -inverseDcxThenRz(QCOProgramBuilder& b) { +SmallVector inverseDcxThenRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange targets) { auto w0 = targets[0]; @@ -3859,11 +3534,10 @@ inverseDcxThenRz(QCOProgramBuilder& b) { w1 = b.rz(0.4, w1); return SmallVector{w0, w1}; }); - return measureAndReturn(b, {res[0], res[1]}); + return measureAndReturn(b, res); } -std::pair, SmallVector> -inverseGphaseBarrierX(QCOProgramBuilder& b) { +SmallVector inverseGphaseBarrierX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value target) { b.gphase(0.25); @@ -3874,8 +3548,7 @@ inverseGphaseBarrierX(QCOProgramBuilder& b) { return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseNestedInvHAndT(QCOProgramBuilder& b) { +SmallVector inverseNestedInvHAndT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value target) { auto wire = b.inv(target, [&](Value inner) { return b.h(inner); }); @@ -3884,19 +3557,17 @@ inverseNestedInvHAndT(QCOProgramBuilder& b) { return measureAndReturn(b, {res}); } -std::pair, SmallVector> -inverseNestedInvHAndX(QCOProgramBuilder& b) { +SmallVector inverseNestedInvHAndX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange targets) { auto w0 = b.inv(targets[0], [&](Value inner) { return b.h(inner); }); auto w1 = b.x(targets[1]); return SmallVector{w0, w1}; }); - return measureAndReturn(b, {res[0], res[1]}); + return measureAndReturn(b, res); } -std::pair, SmallVector> -inverseThreeWireRxRyRz(QCOProgramBuilder& b) { +SmallVector inverseThreeWireRxRyRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange targets) { auto w0 = b.rx(0.2, targets[0]); @@ -3904,11 +3575,10 @@ inverseThreeWireRxRyRz(QCOProgramBuilder& b) { auto w2 = b.rz(0.4, targets[2]); return SmallVector{w0, w1, w2}; }); - return measureAndReturn(b, {res[0], res[1], res[2]}); + return measureAndReturn(b, res); } -std::pair, SmallVector> -inverseThreeWireNestedTwoInv(QCOProgramBuilder& b) { +SmallVector inverseThreeWireNestedTwoInv(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange targets) { auto inner = b.inv({targets[0], targets[1]}, [&](ValueRange innerTargets) { @@ -3919,11 +3589,10 @@ inverseThreeWireNestedTwoInv(QCOProgramBuilder& b) { auto w2 = b.rz(0.4, targets[2]); return SmallVector{inner[0], inner[1], w2}; }); - return measureAndReturn(b, {res[0], res[1], res[2]}); + return measureAndReturn(b, res); } -std::pair, SmallVector> -inverseWithThreeQubitOpInBody(QCOProgramBuilder& b) { +SmallVector inverseWithThreeQubitOpInBody(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); auto res = b.inv({q[0], q[1], q[2]}, [&](ValueRange targets) { auto [controls, innerTarget] = @@ -3931,7 +3600,7 @@ inverseWithThreeQubitOpInBody(QCOProgramBuilder& b) { [&](Value inner) { return b.x(inner); }); return SmallVector{controls[0], controls[1], innerTarget}; }); - return measureAndReturn(b, {res[0], res[1], res[2]}); + return measureAndReturn(b, res); } } // namespace mlir::qco diff --git a/mlir/unittests/programs/qco_programs.h b/mlir/unittests/programs/qco_programs.h index 26d25de42b..badf4f2794 100644 --- a/mlir/unittests/programs/qco_programs.h +++ b/mlir/unittests/programs/qco_programs.h @@ -10,1497 +10,1197 @@ #pragma once -#include #include #include -#include - namespace mlir::qco { class QCOProgramBuilder; /// Creates an empty QCO program. -std::pair, SmallVector> -emptyQCO(QCOProgramBuilder& builder); +SmallVector emptyQCO(QCOProgramBuilder& builder); // --- Qubit Management ----------------------------------------------------- // /// Allocates a single qubit. -std::pair, SmallVector> -allocQubit(QCOProgramBuilder& b); +SmallVector allocQubit(QCOProgramBuilder& b); /// Allocates two individual qubits. -std::pair, SmallVector> -alloc2Qubits(QCOProgramBuilder& b); +SmallVector alloc2Qubits(QCOProgramBuilder& b); /// Allocates a single qubit that is not measured. -std::pair, SmallVector> -allocQubitNoMeasure(QCOProgramBuilder& b); +SmallVector allocQubitNoMeasure(QCOProgramBuilder& b); /// Allocates a qubit register of size `1`. -std::pair, SmallVector> -alloc1QubitRegister(QCOProgramBuilder& b); +SmallVector alloc1QubitRegister(QCOProgramBuilder& b); /// Allocates a qubit register of size `2`. -std::pair, SmallVector> -alloc2QubitRegister(QCOProgramBuilder& b); +SmallVector alloc2QubitRegister(QCOProgramBuilder& b); /// Allocates a qubit register of size `3`. -std::pair, SmallVector> -alloc3QubitRegister(QCOProgramBuilder& b); +SmallVector alloc3QubitRegister(QCOProgramBuilder& b); /// Allocates two qubit registers of size `2` and `3`. -std::pair, SmallVector> -allocMultipleQubitRegisters(QCOProgramBuilder& b); +SmallVector allocMultipleQubitRegisters(QCOProgramBuilder& b); /// Allocates a large qubit register. -std::pair, SmallVector> -allocLargeRegister(QCOProgramBuilder& b); +SmallVector allocLargeRegister(QCOProgramBuilder& b); /// Allocates two inline qubits. -std::pair, SmallVector> -staticQubits(QCOProgramBuilder& b); +SmallVector staticQubits(QCOProgramBuilder& b); /// Allocates two inline qubits without measuring them. -std::pair, SmallVector> -staticQubitsNoMeasure(QCOProgramBuilder& b); +SmallVector staticQubitsNoMeasure(QCOProgramBuilder& b); /// Allocates two static qubits and applies operations. -std::pair, SmallVector> -staticQubitsWithOps(QCOProgramBuilder& b); +SmallVector staticQubitsWithOps(QCOProgramBuilder& b); /// Allocates two static qubits and applies parametric gates. -std::pair, SmallVector> -staticQubitsWithParametricOps(QCOProgramBuilder& b); +SmallVector staticQubitsWithParametricOps(QCOProgramBuilder& b); /// Allocates two static qubits and applies a two-target gate. -std::pair, SmallVector> -staticQubitsWithTwoTargetOps(QCOProgramBuilder& b); +SmallVector staticQubitsWithTwoTargetOps(QCOProgramBuilder& b); /// Allocates two static qubits and applies a controlled gate. -std::pair, SmallVector> -staticQubitsWithCtrl(QCOProgramBuilder& b); +SmallVector staticQubitsWithCtrl(QCOProgramBuilder& b); /// Allocates a static qubit and applies an inverse modifier. -std::pair, SmallVector> -staticQubitsWithInv(QCOProgramBuilder& b); +SmallVector staticQubitsWithInv(QCOProgramBuilder& b); /// Allocates and explicitly sinks a single qubit. -std::pair, SmallVector> -allocSinkPair(QCOProgramBuilder& b); +SmallVector allocSinkPair(QCOProgramBuilder& b); /// Allocates two qubits and performs a set of dead gates on them. -std::pair, SmallVector> -deadGatesProgram(QCOProgramBuilder& b); +SmallVector deadGatesProgram(QCOProgramBuilder& b); /// Allocates two qubits and performs a set of dead gates on them, including /// `if` operations. -std::pair, SmallVector> -deadGatesWithIfOpProgram(QCOProgramBuilder& b); +SmallVector deadGatesWithIfOpProgram(QCOProgramBuilder& b); /// Allocates two qubits and performs only non-dead `if` operations. -std::pair, SmallVector> -deadGatesWithIfOpSimplified(QCOProgramBuilder& b); +SmallVector deadGatesWithIfOpSimplified(QCOProgramBuilder& b); // --- Invalid / mixed addressing (unit tests) -------------------------------- /// @pre `builder.initialize()`. Fatal mixed addressing: static then dynamic /// alloc. -std::pair, SmallVector> -mixedStaticThenDynamicQubit(QCOProgramBuilder& b); +SmallVector mixedStaticThenDynamicQubit(QCOProgramBuilder& b); /// @pre `builder.initialize()`. Fatal mixed addressing: `qtensor` alloc then /// static. -std::pair, SmallVector> -mixedDynamicRegisterThenStaticQubit(QCOProgramBuilder& b); +SmallVector mixedDynamicRegisterThenStaticQubit(QCOProgramBuilder& b); // --- MeasureOp ------------------------------------------------------------ // /// Measures a single qubit into a single classical bit. -std::pair, SmallVector> -singleMeasurementToSingleBit(QCOProgramBuilder& b); +SmallVector singleMeasurementToSingleBit(QCOProgramBuilder& b); /// Repeatedly measures a single qubit into the same classical bit. -std::pair, SmallVector> -repeatedMeasurementToSameBit(QCOProgramBuilder& b); +SmallVector repeatedMeasurementToSameBit(QCOProgramBuilder& b); /// Repeatedly measures a single qubit into different classical bits. -std::pair, SmallVector> -repeatedMeasurementToDifferentBits(QCOProgramBuilder& b); +SmallVector repeatedMeasurementToDifferentBits(QCOProgramBuilder& b); /// Measures multiple qubits into multiple classical bits. -std::pair, SmallVector> +SmallVector multipleClassicalRegistersAndMeasurements(QCOProgramBuilder& b); /// Measures a single qubit into a single classical bit, without explicitly /// allocating a quantum or classical register. -std::pair, SmallVector> -measurementWithoutRegisters(QCOProgramBuilder& b); +SmallVector measurementWithoutRegisters(QCOProgramBuilder& b); // --- ResetOp -------------------------------------------------------------- // /// Resets a single qubit without any operations being applied. -std::pair, SmallVector> -resetQubitWithoutOp(QCOProgramBuilder& b); +SmallVector resetQubitWithoutOp(QCOProgramBuilder& b); /// Resets multiple qubits without any operations being applied. -std::pair, SmallVector> -resetMultipleQubitsWithoutOp(QCOProgramBuilder& b); +SmallVector resetMultipleQubitsWithoutOp(QCOProgramBuilder& b); /// Repeatedly resets a single qubit without any operations being applied. -std::pair, SmallVector> -repeatedResetWithoutOp(QCOProgramBuilder& b); +SmallVector repeatedResetWithoutOp(QCOProgramBuilder& b); /// Resets a single qubit after a single operation. -std::pair, SmallVector> -resetQubitAfterSingleOp(QCOProgramBuilder& b); +SmallVector resetQubitAfterSingleOp(QCOProgramBuilder& b); /// Resets multiple qubits after a single operation. -std::pair, SmallVector> -resetMultipleQubitsAfterSingleOp(QCOProgramBuilder& b); +SmallVector resetMultipleQubitsAfterSingleOp(QCOProgramBuilder& b); /// Repeatedly resets a single qubit after a single operation. -std::pair, SmallVector> -repeatedResetAfterSingleOp(QCOProgramBuilder& b); +SmallVector repeatedResetAfterSingleOp(QCOProgramBuilder& b); // --- GPhaseOp ------------------------------------------------------------- // /// Creates a circuit with just a global phase. -std::pair, SmallVector> -globalPhase(QCOProgramBuilder& b); +SmallVector globalPhase(QCOProgramBuilder& b); /// Creates a controlled global phase gate with a single control qubit. -std::pair, SmallVector> -singleControlledGlobalPhase(QCOProgramBuilder& b); +SmallVector singleControlledGlobalPhase(QCOProgramBuilder& b); /// Creates a multi-controlled global phase gate with multiple control qubits. -std::pair, SmallVector> -multipleControlledGlobalPhase(QCOProgramBuilder& b); +SmallVector multipleControlledGlobalPhase(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a global phase gate. -std::pair, SmallVector> -inverseGlobalPhase(QCOProgramBuilder& b); +SmallVector inverseGlobalPhase(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled global /// phase gate. -std::pair, SmallVector> -inverseMultipleControlledGlobalPhase(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledGlobalPhase(QCOProgramBuilder& b); // --- IdOp ----------------------------------------------------------------- // /// Creates a circuit with just an identity gate. -std::pair, SmallVector> identity(QCOProgramBuilder& b); +SmallVector identity(QCOProgramBuilder& b); /// Creates a controlled identity gate with a single control qubit. -std::pair, SmallVector> -singleControlledIdentity(QCOProgramBuilder& b); +SmallVector singleControlledIdentity(QCOProgramBuilder& b); /// Creates a multi-controlled identity gate with multiple control qubits. -std::pair, SmallVector> -multipleControlledIdentity(QCOProgramBuilder& b); +SmallVector multipleControlledIdentity(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled identity gate. -std::pair, SmallVector> -nestedControlledIdentity(QCOProgramBuilder& b); +SmallVector nestedControlledIdentity(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled identity gate. -std::pair, SmallVector> -trivialControlledIdentity(QCOProgramBuilder& b); +SmallVector trivialControlledIdentity(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an identity gate. -std::pair, SmallVector> -inverseIdentity(QCOProgramBuilder& b); +SmallVector inverseIdentity(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled identity /// gate. -std::pair, SmallVector> -inverseMultipleControlledIdentity(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledIdentity(QCOProgramBuilder& b); // --- XOp ------------------------------------------------------------------ // /// Creates a circuit with just an X gate. -std::pair, SmallVector> x(QCOProgramBuilder& b); +SmallVector x(QCOProgramBuilder& b); /// Creates a circuit with a single controlled X gate. -std::pair, SmallVector> -singleControlledX(QCOProgramBuilder& b); +SmallVector singleControlledX(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled X gate. -std::pair, SmallVector> -multipleControlledX(QCOProgramBuilder& b); +SmallVector multipleControlledX(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled X gate. -std::pair, SmallVector> -nestedControlledX(QCOProgramBuilder& b); +SmallVector nestedControlledX(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled X gate. -std::pair, SmallVector> -trivialControlledX(QCOProgramBuilder& b); +SmallVector trivialControlledX(QCOProgramBuilder& b); /// Creates a circuit with repeated controlled X gates. -std::pair, SmallVector> -repeatedControlledX(QCOProgramBuilder& b); +SmallVector repeatedControlledX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an X gate. -std::pair, SmallVector> inverseX(QCOProgramBuilder& b); +SmallVector inverseX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled X gate. -std::pair, SmallVector> -inverseMultipleControlledX(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledX(QCOProgramBuilder& b); /// Creates a circuit with two subsequent X gates. -std::pair, SmallVector> twoX(QCOProgramBuilder& b); +SmallVector twoX(QCOProgramBuilder& b); /// Creates a circuit with a control modifier applied to two subsequent X gates. -std::pair, SmallVector> -controlledTwoX(QCOProgramBuilder& b); +SmallVector controlledTwoX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to two subsequent X /// gates. -std::pair, SmallVector> -inverseTwoX(QCOProgramBuilder& b); +SmallVector inverseTwoX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a global phase and an /// X gate. -std::pair, SmallVector> -inverseGphaseX(QCOProgramBuilder& b); +SmallVector inverseGphaseX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a global phase and a /// barrier. -std::pair, SmallVector> -inverseGphaseBarrier(QCOProgramBuilder& b); +SmallVector inverseGphaseBarrier(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to two consecutive /// barriers. -std::pair, SmallVector> -inverseTwoBarriersInInv(QCOProgramBuilder& b); +SmallVector inverseTwoBarriersInInv(QCOProgramBuilder& b); // --- YOp ------------------------------------------------------------------ // /// Creates a circuit with just a Y gate. -std::pair, SmallVector> y(QCOProgramBuilder& b); +SmallVector y(QCOProgramBuilder& b); /// Creates a circuit with a single controlled Y gate. -std::pair, SmallVector> -singleControlledY(QCOProgramBuilder& b); +SmallVector singleControlledY(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled Y gate. -std::pair, SmallVector> -multipleControlledY(QCOProgramBuilder& b); +SmallVector multipleControlledY(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled Y gate. -std::pair, SmallVector> -nestedControlledY(QCOProgramBuilder& b); +SmallVector nestedControlledY(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled Y gate. -std::pair, SmallVector> -trivialControlledY(QCOProgramBuilder& b); +SmallVector trivialControlledY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Y gate. -std::pair, SmallVector> inverseY(QCOProgramBuilder& b); +SmallVector inverseY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Y gate. -std::pair, SmallVector> -inverseMultipleControlledY(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledY(QCOProgramBuilder& b); /// Creates a circuit with two Y gates in a row. -std::pair, SmallVector> twoY(QCOProgramBuilder& b); +SmallVector twoY(QCOProgramBuilder& b); // --- ZOp ------------------------------------------------------------------ // /// Creates a circuit with just a Z gate. -std::pair, SmallVector> z(QCOProgramBuilder& b); +SmallVector z(QCOProgramBuilder& b); /// Creates a circuit with a single controlled Z gate. -std::pair, SmallVector> -singleControlledZ(QCOProgramBuilder& b); +SmallVector singleControlledZ(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled Z gate. -std::pair, SmallVector> -multipleControlledZ(QCOProgramBuilder& b); +SmallVector multipleControlledZ(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled Z gate. -std::pair, SmallVector> -nestedControlledZ(QCOProgramBuilder& b); +SmallVector nestedControlledZ(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled Z gate. -std::pair, SmallVector> -trivialControlledZ(QCOProgramBuilder& b); +SmallVector trivialControlledZ(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Z gate. -std::pair, SmallVector> inverseZ(QCOProgramBuilder& b); +SmallVector inverseZ(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Z gate. -std::pair, SmallVector> -inverseMultipleControlledZ(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledZ(QCOProgramBuilder& b); /// Creates a circuit with two Z gates in a row. -std::pair, SmallVector> twoZ(QCOProgramBuilder& b); +SmallVector twoZ(QCOProgramBuilder& b); // --- HOp ------------------------------------------------------------------ // /// Creates a circuit with just an H gate. -std::pair, SmallVector> h(QCOProgramBuilder& b); +SmallVector h(QCOProgramBuilder& b); /// Creates a circuit with a single controlled H gate. -std::pair, SmallVector> -singleControlledH(QCOProgramBuilder& b); +SmallVector singleControlledH(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled H gate. -std::pair, SmallVector> -multipleControlledH(QCOProgramBuilder& b); +SmallVector multipleControlledH(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled H gate. -std::pair, SmallVector> -nestedControlledH(QCOProgramBuilder& b); +SmallVector nestedControlledH(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled H gate. -std::pair, SmallVector> -trivialControlledH(QCOProgramBuilder& b); +SmallVector trivialControlledH(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an H gate. -std::pair, SmallVector> inverseH(QCOProgramBuilder& b); +SmallVector inverseH(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled H gate. -std::pair, SmallVector> -inverseMultipleControlledH(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledH(QCOProgramBuilder& b); /// Creates a circuit with two H gates in a row. -std::pair, SmallVector> twoH(QCOProgramBuilder& b); +SmallVector twoH(QCOProgramBuilder& b); /// Creates a circuit with just an H gate and no qubit register. -std::pair, SmallVector> -hWithoutRegister(QCOProgramBuilder& b); +SmallVector hWithoutRegister(QCOProgramBuilder& b); // --- SOp ------------------------------------------------------------------ // /// Creates a circuit with just an S gate. -std::pair, SmallVector> s(QCOProgramBuilder& b); +SmallVector s(QCOProgramBuilder& b); /// Creates a circuit with a single controlled S gate. -std::pair, SmallVector> -singleControlledS(QCOProgramBuilder& b); +SmallVector singleControlledS(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled S gate. -std::pair, SmallVector> -multipleControlledS(QCOProgramBuilder& b); +SmallVector multipleControlledS(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled S gate. -std::pair, SmallVector> -nestedControlledS(QCOProgramBuilder& b); +SmallVector nestedControlledS(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled S gate. -std::pair, SmallVector> -trivialControlledS(QCOProgramBuilder& b); +SmallVector trivialControlledS(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an S gate. -std::pair, SmallVector> inverseS(QCOProgramBuilder& b); +SmallVector inverseS(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled S gate. -std::pair, SmallVector> -inverseMultipleControlledS(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledS(QCOProgramBuilder& b); /// Creates a circuit with an S gate followed by an Sdg gate. -std::pair, SmallVector> sThenSdg(QCOProgramBuilder& b); +SmallVector sThenSdg(QCOProgramBuilder& b); /// Creates a circuit with two S gates in a row. -std::pair, SmallVector> twoS(QCOProgramBuilder& b); +SmallVector twoS(QCOProgramBuilder& b); // --- SdgOp ---------------------------------------------------------------- // /// Creates a circuit with just an Sdg gate. -std::pair, SmallVector> sdg(QCOProgramBuilder& b); +SmallVector sdg(QCOProgramBuilder& b); /// Creates a circuit with a single controlled Sdg gate. -std::pair, SmallVector> -singleControlledSdg(QCOProgramBuilder& b); +SmallVector singleControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled Sdg gate. -std::pair, SmallVector> -multipleControlledSdg(QCOProgramBuilder& b); +SmallVector multipleControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled Sdg gate. -std::pair, SmallVector> -nestedControlledSdg(QCOProgramBuilder& b); +SmallVector nestedControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled Sdg gate. -std::pair, SmallVector> -trivialControlledSdg(QCOProgramBuilder& b); +SmallVector trivialControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an Sdg gate. -std::pair, SmallVector> -inverseSdg(QCOProgramBuilder& b); +SmallVector inverseSdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Sdg gate. -std::pair, SmallVector> -inverseMultipleControlledSdg(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with an Sdg gate followed an S gate. -std::pair, SmallVector> sdgThenS(QCOProgramBuilder& b); +SmallVector sdgThenS(QCOProgramBuilder& b); /// Creates a circuit with two Sdg gates in a row. -std::pair, SmallVector> twoSdg(QCOProgramBuilder& b); +SmallVector twoSdg(QCOProgramBuilder& b); // --- TOp ------------------------------------------------------------------ // /// Creates a circuit with just a T gate. -std::pair, SmallVector> -t_(QCOProgramBuilder& b); // NOLINT(*-identifier-naming) +SmallVector t_(QCOProgramBuilder& b); // NOLINT(*-identifier-naming) /// Creates a circuit with a single controlled T gate. -std::pair, SmallVector> -singleControlledT(QCOProgramBuilder& b); +SmallVector singleControlledT(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled T gate. -std::pair, SmallVector> -multipleControlledT(QCOProgramBuilder& b); +SmallVector multipleControlledT(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled T gate. -std::pair, SmallVector> -nestedControlledT(QCOProgramBuilder& b); +SmallVector nestedControlledT(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled T gate. -std::pair, SmallVector> -trivialControlledT(QCOProgramBuilder& b); +SmallVector trivialControlledT(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a T gate. -std::pair, SmallVector> inverseT(QCOProgramBuilder& b); +SmallVector inverseT(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled T gate. -std::pair, SmallVector> -inverseMultipleControlledT(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledT(QCOProgramBuilder& b); /// Creates a circuit with a T gate followed by a Tdg gate. -std::pair, SmallVector> tThenTdg(QCOProgramBuilder& b); +SmallVector tThenTdg(QCOProgramBuilder& b); /// Creates a circuit with two T gates in a row. -std::pair, SmallVector> twoT(QCOProgramBuilder& b); +SmallVector twoT(QCOProgramBuilder& b); // --- TdgOp ---------------------------------------------------------------- // /// Creates a circuit with just a Tdg gate. -std::pair, SmallVector> tdg(QCOProgramBuilder& b); +SmallVector tdg(QCOProgramBuilder& b); /// Creates a circuit with a single controlled Tdg gate. -std::pair, SmallVector> -singleControlledTdg(QCOProgramBuilder& b); +SmallVector singleControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled Tdg gate. -std::pair, SmallVector> -multipleControlledTdg(QCOProgramBuilder& b); +SmallVector multipleControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled Tdg gate. -std::pair, SmallVector> -nestedControlledTdg(QCOProgramBuilder& b); +SmallVector nestedControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled Tdg gate. -std::pair, SmallVector> -trivialControlledTdg(QCOProgramBuilder& b); +SmallVector trivialControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Tdg gate. -std::pair, SmallVector> -inverseTdg(QCOProgramBuilder& b); +SmallVector inverseTdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Tdg gate. -std::pair, SmallVector> -inverseMultipleControlledTdg(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with a Tdg gate followed by a T gate. -std::pair, SmallVector> tdgThenT(QCOProgramBuilder& b); +SmallVector tdgThenT(QCOProgramBuilder& b); /// Creates a circuit with two Tdg gates in a row. -std::pair, SmallVector> twoTdg(QCOProgramBuilder& b); +SmallVector twoTdg(QCOProgramBuilder& b); // --- SXOp ----------------------------------------------------------------- // /// Creates a circuit with just an SX gate. -std::pair, SmallVector> sx(QCOProgramBuilder& b); +SmallVector sx(QCOProgramBuilder& b); /// Creates a circuit with a single controlled SX gate. -std::pair, SmallVector> -singleControlledSx(QCOProgramBuilder& b); +SmallVector singleControlledSx(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled SX gate. -std::pair, SmallVector> -multipleControlledSx(QCOProgramBuilder& b); +SmallVector multipleControlledSx(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled SX gate. -std::pair, SmallVector> -nestedControlledSx(QCOProgramBuilder& b); +SmallVector nestedControlledSx(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled SX gate. -std::pair, SmallVector> -trivialControlledSx(QCOProgramBuilder& b); +SmallVector trivialControlledSx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an SX gate. -std::pair, SmallVector> -inverseSx(QCOProgramBuilder& b); +SmallVector inverseSx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SX gate. -std::pair, SmallVector> -inverseMultipleControlledSx(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledSx(QCOProgramBuilder& b); /// Creates a circuit with an SX gate followed by an SXdg gate. -std::pair, SmallVector> -sxThenSxdg(QCOProgramBuilder& b); +SmallVector sxThenSxdg(QCOProgramBuilder& b); /// Creates a circuit with two SX gates in a row. -std::pair, SmallVector> twoSx(QCOProgramBuilder& b); +SmallVector twoSx(QCOProgramBuilder& b); // --- SXdgOp --------------------------------------------------------------- // /// Creates a circuit with just an SXdg gate. -std::pair, SmallVector> sxdg(QCOProgramBuilder& b); +SmallVector sxdg(QCOProgramBuilder& b); /// Creates a circuit with a single controlled SXdg gate. -std::pair, SmallVector> -singleControlledSxdg(QCOProgramBuilder& b); +SmallVector singleControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled SXdg gate. -std::pair, SmallVector> -multipleControlledSxdg(QCOProgramBuilder& b); +SmallVector multipleControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled SXdg gate. -std::pair, SmallVector> -nestedControlledSxdg(QCOProgramBuilder& b); +SmallVector nestedControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled SXdg gate. -std::pair, SmallVector> -trivialControlledSxdg(QCOProgramBuilder& b); +SmallVector trivialControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an SXdg gate. -std::pair, SmallVector> -inverseSxdg(QCOProgramBuilder& b); +SmallVector inverseSxdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SXdg /// gate. -std::pair, SmallVector> -inverseMultipleControlledSxdg(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with an SXdg gate followed by an SX gate. -std::pair, SmallVector> -sxdgThenSx(QCOProgramBuilder& b); +SmallVector sxdgThenSx(QCOProgramBuilder& b); /// Creates a circuit with two SXdg gates in a row. -std::pair, SmallVector> twoSxdg(QCOProgramBuilder& b); +SmallVector twoSxdg(QCOProgramBuilder& b); // --- RXOp ----------------------------------------------------------------- // /// Creates a circuit with just an RX gate. -std::pair, SmallVector> rx(QCOProgramBuilder& b); +SmallVector rx(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RX gate. -std::pair, SmallVector> -singleControlledRx(QCOProgramBuilder& b); +SmallVector singleControlledRx(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RX gate. -std::pair, SmallVector> -multipleControlledRx(QCOProgramBuilder& b); +SmallVector multipleControlledRx(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RX gate. -std::pair, SmallVector> -nestedControlledRx(QCOProgramBuilder& b); +SmallVector nestedControlledRx(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RX gate. -std::pair, SmallVector> -trivialControlledRx(QCOProgramBuilder& b); +SmallVector trivialControlledRx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RX gate. -std::pair, SmallVector> -inverseRx(QCOProgramBuilder& b); +SmallVector inverseRx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RX gate. -std::pair, SmallVector> -inverseMultipleControlledRx(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledRx(QCOProgramBuilder& b); /// Creates a circuit with two RX gates in a row with opposite phases. -std::pair, SmallVector> -twoRxOppositePhase(QCOProgramBuilder& b); +SmallVector twoRxOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with an RX gate with an angle of pi/2. -std::pair, SmallVector> -rxPiOver2(QCOProgramBuilder& b); +SmallVector rxPiOver2(QCOProgramBuilder& b); // --- RYOp ----------------------------------------------------------------- // /// Creates a circuit with just an RY gate. -std::pair, SmallVector> ry(QCOProgramBuilder& b); +SmallVector ry(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RY gate. -std::pair, SmallVector> -singleControlledRy(QCOProgramBuilder& b); +SmallVector singleControlledRy(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RY gate. -std::pair, SmallVector> -multipleControlledRy(QCOProgramBuilder& b); +SmallVector multipleControlledRy(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RY gate. -std::pair, SmallVector> -nestedControlledRy(QCOProgramBuilder& b); +SmallVector nestedControlledRy(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RY gate. -std::pair, SmallVector> -trivialControlledRy(QCOProgramBuilder& b); +SmallVector trivialControlledRy(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RY gate. -std::pair, SmallVector> -inverseRy(QCOProgramBuilder& b); +SmallVector inverseRy(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RY gate. -std::pair, SmallVector> -inverseMultipleControlledRy(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledRy(QCOProgramBuilder& b); /// Creates a circuit with two RY gates in a row with opposite phases. -std::pair, SmallVector> -twoRyOppositePhase(QCOProgramBuilder& b); +SmallVector twoRyOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with an RY gate with an angle of pi/2. -std::pair, SmallVector> -ryPiOver2(QCOProgramBuilder& b); +SmallVector ryPiOver2(QCOProgramBuilder& b); // --- RZOp ----------------------------------------------------------------- // /// Creates a circuit with just an RZ gate. -std::pair, SmallVector> rz(QCOProgramBuilder& b); +SmallVector rz(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RZ gate. -std::pair, SmallVector> -singleControlledRz(QCOProgramBuilder& b); +SmallVector singleControlledRz(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RZ gate. -std::pair, SmallVector> -multipleControlledRz(QCOProgramBuilder& b); +SmallVector multipleControlledRz(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RZ gate. -std::pair, SmallVector> -nestedControlledRz(QCOProgramBuilder& b); +SmallVector nestedControlledRz(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RZ gate. -std::pair, SmallVector> -trivialControlledRz(QCOProgramBuilder& b); +SmallVector trivialControlledRz(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZ gate. -std::pair, SmallVector> -inverseRz(QCOProgramBuilder& b); +SmallVector inverseRz(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZ gate. -std::pair, SmallVector> -inverseMultipleControlledRz(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledRz(QCOProgramBuilder& b); /// Creates a circuit with two RZ gates in a row with opposite phases. -std::pair, SmallVector> -twoRzOppositePhase(QCOProgramBuilder& b); +SmallVector twoRzOppositePhase(QCOProgramBuilder& b); // --- POp ------------------------------------------------------------------ // /// Creates a circuit with just a P gate. -std::pair, SmallVector> p(QCOProgramBuilder& b); +SmallVector p(QCOProgramBuilder& b); /// Creates a circuit with a single controlled P gate. -std::pair, SmallVector> -singleControlledP(QCOProgramBuilder& b); +SmallVector singleControlledP(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled P gate. -std::pair, SmallVector> -multipleControlledP(QCOProgramBuilder& b); +SmallVector multipleControlledP(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled P gate. -std::pair, SmallVector> -nestedControlledP(QCOProgramBuilder& b); +SmallVector nestedControlledP(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled P gate. -std::pair, SmallVector> -trivialControlledP(QCOProgramBuilder& b); +SmallVector trivialControlledP(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a P gate. -std::pair, SmallVector> inverseP(QCOProgramBuilder& b); +SmallVector inverseP(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled P gate. -std::pair, SmallVector> -inverseMultipleControlledP(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledP(QCOProgramBuilder& b); /// Creates a circuit with two P gates in a row with opposite phases. -std::pair, SmallVector> -twoPOppositePhase(QCOProgramBuilder& b); +SmallVector twoPOppositePhase(QCOProgramBuilder& b); // --- ROp ------------------------------------------------------------------ // /// Creates a circuit with just an R gate. -std::pair, SmallVector> r(QCOProgramBuilder& b); +SmallVector r(QCOProgramBuilder& b); /// Creates a circuit with a single controlled R gate. -std::pair, SmallVector> -singleControlledR(QCOProgramBuilder& b); +SmallVector singleControlledR(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled R gate. -std::pair, SmallVector> -multipleControlledR(QCOProgramBuilder& b); +SmallVector multipleControlledR(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled R gate. -std::pair, SmallVector> -nestedControlledR(QCOProgramBuilder& b); +SmallVector nestedControlledR(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled R gate. -std::pair, SmallVector> -trivialControlledR(QCOProgramBuilder& b); +SmallVector trivialControlledR(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an R gate. -std::pair, SmallVector> inverseR(QCOProgramBuilder& b); +SmallVector inverseR(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled R gate. -std::pair, SmallVector> -inverseMultipleControlledR(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledR(QCOProgramBuilder& b); /// Creates a circuit with an R gate that can be canonicalized to an RX gate. -std::pair, SmallVector> -canonicalizeRToRx(QCOProgramBuilder& b); +SmallVector canonicalizeRToRx(QCOProgramBuilder& b); /// Creates a circuit with an R gate that can be canonicalized to an RY gate. -std::pair, SmallVector> -canonicalizeRToRy(QCOProgramBuilder& b); +SmallVector canonicalizeRToRy(QCOProgramBuilder& b); /// Creates a circuit with two R gates in a row with the same `phi`. -std::pair, SmallVector> twoR(QCOProgramBuilder& b); +SmallVector twoR(QCOProgramBuilder& b); // --- U2Op ----------------------------------------------------------------- // /// Creates a circuit with just a U2 gate. -std::pair, SmallVector> u2(QCOProgramBuilder& b); +SmallVector u2(QCOProgramBuilder& b); /// Creates a circuit with a single controlled U2 gate. -std::pair, SmallVector> -singleControlledU2(QCOProgramBuilder& b); +SmallVector singleControlledU2(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled U2 gate. -std::pair, SmallVector> -multipleControlledU2(QCOProgramBuilder& b); +SmallVector multipleControlledU2(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled U2 gate. -std::pair, SmallVector> -nestedControlledU2(QCOProgramBuilder& b); +SmallVector nestedControlledU2(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled U2 gate. -std::pair, SmallVector> -trivialControlledU2(QCOProgramBuilder& b); +SmallVector trivialControlledU2(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a U2 gate. -std::pair, SmallVector> -inverseU2(QCOProgramBuilder& b); +SmallVector inverseU2(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled U2 gate. -std::pair, SmallVector> -inverseMultipleControlledU2(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledU2(QCOProgramBuilder& b); /// Creates a circuit with a U2 gate that can be canonicalized to an H gate. -std::pair, SmallVector> -canonicalizeU2ToH(QCOProgramBuilder& b); +SmallVector canonicalizeU2ToH(QCOProgramBuilder& b); /// Creates a circuit with a U2 gate that can be canonicalized to an RX gate. -std::pair, SmallVector> -canonicalizeU2ToRx(QCOProgramBuilder& b); +SmallVector canonicalizeU2ToRx(QCOProgramBuilder& b); /// Creates a circuit with a U2 gate that can be canonicalized to an RY gate. -std::pair, SmallVector> -canonicalizeU2ToRy(QCOProgramBuilder& b); +SmallVector canonicalizeU2ToRy(QCOProgramBuilder& b); // --- UOp ------------------------------------------------------------------ // /// Creates a circuit with just a U gate. -std::pair, SmallVector> u(QCOProgramBuilder& b); +SmallVector u(QCOProgramBuilder& b); /// Creates a circuit with a single controlled U gate. -std::pair, SmallVector> -singleControlledU(QCOProgramBuilder& b); +SmallVector singleControlledU(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled U gate. -std::pair, SmallVector> -multipleControlledU(QCOProgramBuilder& b); +SmallVector multipleControlledU(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled U gate. -std::pair, SmallVector> -nestedControlledU(QCOProgramBuilder& b); +SmallVector nestedControlledU(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled U gate. -std::pair, SmallVector> -trivialControlledU(QCOProgramBuilder& b); +SmallVector trivialControlledU(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a U gate. -std::pair, SmallVector> inverseU(QCOProgramBuilder& b); +SmallVector inverseU(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled U gate. -std::pair, SmallVector> -inverseMultipleControlledU(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledU(QCOProgramBuilder& b); /// Creates a circuit with a U gate that can be canonicalized to a P gate. -std::pair, SmallVector> -canonicalizeUToP(QCOProgramBuilder& b); +SmallVector canonicalizeUToP(QCOProgramBuilder& b); /// Creates a circuit with a U gate that can be canonicalized to an RX gate. -std::pair, SmallVector> -canonicalizeUToRx(QCOProgramBuilder& b); +SmallVector canonicalizeUToRx(QCOProgramBuilder& b); /// Creates a circuit with a U gate that can be canonicalized to an RY gate. -std::pair, SmallVector> -canonicalizeUToRy(QCOProgramBuilder& b); +SmallVector canonicalizeUToRy(QCOProgramBuilder& b); /// Creates a circuit with a U gate that can be canonicalized to a U2 gate. -std::pair, SmallVector> -canonicalizeUToU2(QCOProgramBuilder& b); +SmallVector canonicalizeUToU2(QCOProgramBuilder& b); // --- SWAPOp --------------------------------------------------------------- // /// Creates a circuit with just a SWAP gate. -std::pair, SmallVector> swap(QCOProgramBuilder& b); +SmallVector swap(QCOProgramBuilder& b); /// Creates a circuit with a single controlled SWAP gate. -std::pair, SmallVector> -singleControlledSwap(QCOProgramBuilder& b); +SmallVector singleControlledSwap(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled SWAP gate. -std::pair, SmallVector> -multipleControlledSwap(QCOProgramBuilder& b); +SmallVector multipleControlledSwap(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled SWAP gate. -std::pair, SmallVector> -nestedControlledSwap(QCOProgramBuilder& b); +SmallVector nestedControlledSwap(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled SWAP gate. -std::pair, SmallVector> -trivialControlledSwap(QCOProgramBuilder& b); +SmallVector trivialControlledSwap(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a SWAP gate. -std::pair, SmallVector> -inverseSwap(QCOProgramBuilder& b); +SmallVector inverseSwap(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SWAP /// gate. -std::pair, SmallVector> -inverseMultipleControlledSwap(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledSwap(QCOProgramBuilder& b); /// Creates a circuit with two SWAP gates in a row. -std::pair, SmallVector> twoSwap(QCOProgramBuilder& b); +SmallVector twoSwap(QCOProgramBuilder& b); /// Creates a circuit with two SWAP gates in a row with swapped targets. -std::pair, SmallVector> -twoSwapSwappedTargets(QCOProgramBuilder& b); +SmallVector twoSwapSwappedTargets(QCOProgramBuilder& b); // --- iSWAPOp -------------------------------------------------------------- // /// Creates a circuit with just an iSWAP gate. -std::pair, SmallVector> iswap(QCOProgramBuilder& b); +SmallVector iswap(QCOProgramBuilder& b); /// Creates a circuit with a single controlled iSWAP gate. -std::pair, SmallVector> -singleControlledIswap(QCOProgramBuilder& b); +SmallVector singleControlledIswap(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled iSWAP gate. -std::pair, SmallVector> -multipleControlledIswap(QCOProgramBuilder& b); +SmallVector multipleControlledIswap(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled iSWAP gate. -std::pair, SmallVector> -nestedControlledIswap(QCOProgramBuilder& b); +SmallVector nestedControlledIswap(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled iSWAP gate. -std::pair, SmallVector> -trivialControlledIswap(QCOProgramBuilder& b); +SmallVector trivialControlledIswap(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an iSWAP gate. -std::pair, SmallVector> -inverseIswap(QCOProgramBuilder& b); +SmallVector inverseIswap(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled iSWAP /// gate. -std::pair, SmallVector> -inverseMultipleControlledIswap(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledIswap(QCOProgramBuilder& b); // --- DCXOp ---------------------------------------------------------------- // /// Creates a circuit with just a DCX gate. -std::pair, SmallVector> dcx(QCOProgramBuilder& b); +SmallVector dcx(QCOProgramBuilder& b); /// Creates a circuit with a single controlled DCX gate. -std::pair, SmallVector> -singleControlledDcx(QCOProgramBuilder& b); +SmallVector singleControlledDcx(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled DCX gate. -std::pair, SmallVector> -multipleControlledDcx(QCOProgramBuilder& b); +SmallVector multipleControlledDcx(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled DCX gate. -std::pair, SmallVector> -nestedControlledDcx(QCOProgramBuilder& b); +SmallVector nestedControlledDcx(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled DCX gate. -std::pair, SmallVector> -trivialControlledDcx(QCOProgramBuilder& b); +SmallVector trivialControlledDcx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a DCX gate. -std::pair, SmallVector> -inverseDcx(QCOProgramBuilder& b); +SmallVector inverseDcx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled DCX gate. -std::pair, SmallVector> -inverseMultipleControlledDcx(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledDcx(QCOProgramBuilder& b); /// Creates a circuit with two DCX gates in a row with identical targets. -std::pair, SmallVector> twoDcx(QCOProgramBuilder& b); +SmallVector twoDcx(QCOProgramBuilder& b); /// Creates a circuit with two DCX gates in a row with swapped targets. -std::pair, SmallVector> -twoDcxSwappedTargets(QCOProgramBuilder& b); +SmallVector twoDcxSwappedTargets(QCOProgramBuilder& b); // --- ECROp ---------------------------------------------------------------- // /// Creates a circuit with just an ECR gate. -std::pair, SmallVector> ecr(QCOProgramBuilder& b); +SmallVector ecr(QCOProgramBuilder& b); /// Creates a circuit with a single controlled ECR gate. -std::pair, SmallVector> -singleControlledEcr(QCOProgramBuilder& b); +SmallVector singleControlledEcr(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled ECR gate. -std::pair, SmallVector> -multipleControlledEcr(QCOProgramBuilder& b); +SmallVector multipleControlledEcr(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled ECR gate. -std::pair, SmallVector> -nestedControlledEcr(QCOProgramBuilder& b); +SmallVector nestedControlledEcr(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled ECR gate. -std::pair, SmallVector> -trivialControlledEcr(QCOProgramBuilder& b); +SmallVector trivialControlledEcr(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an ECR gate. -std::pair, SmallVector> -inverseEcr(QCOProgramBuilder& b); +SmallVector inverseEcr(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled ECR gate. -std::pair, SmallVector> -inverseMultipleControlledEcr(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledEcr(QCOProgramBuilder& b); /// Creates a circuit with two ECR gates in a row. -std::pair, SmallVector> twoEcr(QCOProgramBuilder& b); +SmallVector twoEcr(QCOProgramBuilder& b); // --- RXXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RXX gate. -std::pair, SmallVector> rxx(QCOProgramBuilder& b); +SmallVector rxx(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RXX gate. -std::pair, SmallVector> -singleControlledRxx(QCOProgramBuilder& b); +SmallVector singleControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RXX gate. -std::pair, SmallVector> -multipleControlledRxx(QCOProgramBuilder& b); +SmallVector multipleControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RXX gate. -std::pair, SmallVector> -nestedControlledRxx(QCOProgramBuilder& b); +SmallVector nestedControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RXX gate. -std::pair, SmallVector> -trivialControlledRxx(QCOProgramBuilder& b); +SmallVector trivialControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RXX gate. -std::pair, SmallVector> -inverseRxx(QCOProgramBuilder& b); +SmallVector inverseRxx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RXX gate. -std::pair, SmallVector> -inverseMultipleControlledRxx(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with a triple-controlled RXX gate. -std::pair, SmallVector> -tripleControlledRxx(QCOProgramBuilder& b); +SmallVector tripleControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with a four-controlled RXX gate. -std::pair, SmallVector> -fourControlledRxx(QCOProgramBuilder& b); +SmallVector fourControlledRxx(QCOProgramBuilder& b); /// Creates a circuit with two RXX gates in a row. -std::pair, SmallVector> twoRxx(QCOProgramBuilder& b); +SmallVector twoRxx(QCOProgramBuilder& b); /// Creates a circuit with two RXX gates in a row with swapped targets. -std::pair, SmallVector> -twoRxxSwappedTargets(QCOProgramBuilder& b); +SmallVector twoRxxSwappedTargets(QCOProgramBuilder& b); /// Creates a circuit with two RXX gates in a row with opposite phases. -std::pair, SmallVector> -twoRxxOppositePhase(QCOProgramBuilder& b); +SmallVector twoRxxOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with two RXX gates in a row with opposite phases and /// swapped targets. -std::pair, SmallVector> -twoRxxOppositePhaseSwappedTargets(QCOProgramBuilder& b); +SmallVector twoRxxOppositePhaseSwappedTargets(QCOProgramBuilder& b); // --- RYYOp ---------------------------------------------------------------- // /// Creates a circuit with just an RYY gate. -std::pair, SmallVector> ryy(QCOProgramBuilder& b); +SmallVector ryy(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RYY gate. -std::pair, SmallVector> -singleControlledRyy(QCOProgramBuilder& b); +SmallVector singleControlledRyy(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RYY gate. -std::pair, SmallVector> -multipleControlledRyy(QCOProgramBuilder& b); +SmallVector multipleControlledRyy(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RYY gate. -std::pair, SmallVector> -nestedControlledRyy(QCOProgramBuilder& b); +SmallVector nestedControlledRyy(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RYY gate. -std::pair, SmallVector> -trivialControlledRyy(QCOProgramBuilder& b); +SmallVector trivialControlledRyy(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RYY gate. -std::pair, SmallVector> -inverseRyy(QCOProgramBuilder& b); +SmallVector inverseRyy(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RYY gate. -std::pair, SmallVector> -inverseMultipleControlledRyy(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledRyy(QCOProgramBuilder& b); /// Creates a circuit with two RYY gates in a row. -std::pair, SmallVector> twoRyy(QCOProgramBuilder& b); +SmallVector twoRyy(QCOProgramBuilder& b); /// Creates a circuit with two RYY gates in a row with swapped targets. -std::pair, SmallVector> -twoRyySwappedTargets(QCOProgramBuilder& b); +SmallVector twoRyySwappedTargets(QCOProgramBuilder& b); /// Creates a circuit with two RYY gates in a row with opposite phases. -std::pair, SmallVector> -twoRyyOppositePhase(QCOProgramBuilder& b); +SmallVector twoRyyOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with two RYY gates in a row with opposite phases and /// swapped targets. -std::pair, SmallVector> -twoRyyOppositePhaseSwappedTargets(QCOProgramBuilder& b); +SmallVector twoRyyOppositePhaseSwappedTargets(QCOProgramBuilder& b); // --- RZXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZX gate. -std::pair, SmallVector> rzx(QCOProgramBuilder& b); +SmallVector rzx(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RZX gate. -std::pair, SmallVector> -singleControlledRzx(QCOProgramBuilder& b); +SmallVector singleControlledRzx(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RZX gate. -std::pair, SmallVector> -multipleControlledRzx(QCOProgramBuilder& b); +SmallVector multipleControlledRzx(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RZX gate. -std::pair, SmallVector> -nestedControlledRzx(QCOProgramBuilder& b); +SmallVector nestedControlledRzx(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RZX gate. -std::pair, SmallVector> -trivialControlledRzx(QCOProgramBuilder& b); +SmallVector trivialControlledRzx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZX gate. -std::pair, SmallVector> -inverseRzx(QCOProgramBuilder& b); +SmallVector inverseRzx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZX gate. -std::pair, SmallVector> -inverseMultipleControlledRzx(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledRzx(QCOProgramBuilder& b); /// Creates a circuit with two RZX gates in a row with opposite phases. -std::pair, SmallVector> -twoRzxOppositePhase(QCOProgramBuilder& b); +SmallVector twoRzxOppositePhase(QCOProgramBuilder& b); // --- RZZOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZZ gate. -std::pair, SmallVector> rzz(QCOProgramBuilder& b); +SmallVector rzz(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RZZ gate. -std::pair, SmallVector> -singleControlledRzz(QCOProgramBuilder& b); +SmallVector singleControlledRzz(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled RZZ gate. -std::pair, SmallVector> -multipleControlledRzz(QCOProgramBuilder& b); +SmallVector multipleControlledRzz(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled RZZ gate. -std::pair, SmallVector> -nestedControlledRzz(QCOProgramBuilder& b); +SmallVector nestedControlledRzz(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RZZ gate. -std::pair, SmallVector> -trivialControlledRzz(QCOProgramBuilder& b); +SmallVector trivialControlledRzz(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZZ gate. -std::pair, SmallVector> -inverseRzz(QCOProgramBuilder& b); +SmallVector inverseRzz(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZZ gate. -std::pair, SmallVector> -inverseMultipleControlledRzz(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledRzz(QCOProgramBuilder& b); /// Creates a circuit with two RZZ gates in a row. -std::pair, SmallVector> twoRzz(QCOProgramBuilder& b); +SmallVector twoRzz(QCOProgramBuilder& b); /// Creates a circuit with two RZZ gates in a row with swapped targets. -std::pair, SmallVector> -twoRzzSwappedTargets(QCOProgramBuilder& b); +SmallVector twoRzzSwappedTargets(QCOProgramBuilder& b); /// Creates a circuit with two RZZ gates in a row with opposite phases. -std::pair, SmallVector> -twoRzzOppositePhase(QCOProgramBuilder& b); +SmallVector twoRzzOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with two RZZ gates in a row with opposite phases and /// swapped targets. -std::pair, SmallVector> -twoRzzOppositePhaseSwappedTargets(QCOProgramBuilder& b); +SmallVector twoRzzOppositePhaseSwappedTargets(QCOProgramBuilder& b); // --- XXPlusYYOp ----------------------------------------------------------- // /// Creates a circuit with just an XXPlusYY gate. -std::pair, SmallVector> xxPlusYY(QCOProgramBuilder& b); +SmallVector xxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with a single controlled XXPlusYY gate. -std::pair, SmallVector> -singleControlledXxPlusYY(QCOProgramBuilder& b); +SmallVector singleControlledXxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled XXPlusYY gate. -std::pair, SmallVector> -multipleControlledXxPlusYY(QCOProgramBuilder& b); +SmallVector multipleControlledXxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled XXPlusYY gate. -std::pair, SmallVector> -nestedControlledXxPlusYY(QCOProgramBuilder& b); +SmallVector nestedControlledXxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled XXPlusYY gate. -std::pair, SmallVector> -trivialControlledXxPlusYY(QCOProgramBuilder& b); +SmallVector trivialControlledXxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an XXPlusYY gate. -std::pair, SmallVector> -inverseXxPlusYY(QCOProgramBuilder& b); +SmallVector inverseXxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled XXPlusYY /// gate. -std::pair, SmallVector> -inverseMultipleControlledXxPlusYY(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledXxPlusYY(QCOProgramBuilder& b); /// Creates a circuit with two XXPlusYY gates in a row with opposite phases. -std::pair, SmallVector> -twoXxPlusYYOppositePhase(QCOProgramBuilder& b); +SmallVector twoXxPlusYYOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with two XXPlusYY gates in a row with swapped targets. -std::pair, SmallVector> -twoXxPlusYYSwappedTargets(QCOProgramBuilder& b); +SmallVector twoXxPlusYYSwappedTargets(QCOProgramBuilder& b); // --- XXMinusYYOp ---------------------------------------------------------- // /// Creates a circuit with just an XXMinusYY gate. -std::pair, SmallVector> -xxMinusYY(QCOProgramBuilder& b); +SmallVector xxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with a single controlled XXMinusYY gate. -std::pair, SmallVector> -singleControlledXxMinusYY(QCOProgramBuilder& b); +SmallVector singleControlledXxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with a multi-controlled XXMinusYY gate. -std::pair, SmallVector> -multipleControlledXxMinusYY(QCOProgramBuilder& b); +SmallVector multipleControlledXxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with a nested controlled XXMinusYY gate. -std::pair, SmallVector> -nestedControlledXxMinusYY(QCOProgramBuilder& b); +SmallVector nestedControlledXxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled XXMinusYY gate. -std::pair, SmallVector> -trivialControlledXxMinusYY(QCOProgramBuilder& b); +SmallVector trivialControlledXxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an XXMinusYY gate. -std::pair, SmallVector> -inverseXxMinusYY(QCOProgramBuilder& b); +SmallVector inverseXxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled XXMinusYY /// gate. -std::pair, SmallVector> -inverseMultipleControlledXxMinusYY(QCOProgramBuilder& b); +SmallVector inverseMultipleControlledXxMinusYY(QCOProgramBuilder& b); /// Creates a circuit with two XXMinusYY gates in a row with opposite phases. -std::pair, SmallVector> -twoXxMinusYYOppositePhase(QCOProgramBuilder& b); +SmallVector twoXxMinusYYOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with two XXMinusYY gates in a row with swapped targets. -std::pair, SmallVector> -twoXxMinusYYSwappedTargets(QCOProgramBuilder& b); +SmallVector twoXxMinusYYSwappedTargets(QCOProgramBuilder& b); // --- BarrierOp ------------------------------------------------------------ // /// Creates a circuit with a barrier. -std::pair, SmallVector> barrier(QCOProgramBuilder& b); +SmallVector barrier(QCOProgramBuilder& b); /// Creates a circuit with a barrier on two qubits. -std::pair, SmallVector> -barrierTwoQubits(QCOProgramBuilder& b); +SmallVector barrierTwoQubits(QCOProgramBuilder& b); /// Creates a circuit with a barrier on multiple qubits. -std::pair, SmallVector> -barrierMultipleQubits(QCOProgramBuilder& b); +SmallVector barrierMultipleQubits(QCOProgramBuilder& b); /// Creates a circuit with a single controlled barrier. -std::pair, SmallVector> -singleControlledBarrier(QCOProgramBuilder& b); +SmallVector singleControlledBarrier(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a barrier. -std::pair, SmallVector> -inverseBarrier(QCOProgramBuilder& b); +SmallVector inverseBarrier(QCOProgramBuilder& b); /// Creates a circuit with two barriers in a row with overlapping qubits. -std::pair, SmallVector> -twoBarrier(QCOProgramBuilder& b); +SmallVector twoBarrier(QCOProgramBuilder& b); // --- CtrlOp --------------------------------------------------------------- // /// Creates a circuit with a trivial ctrl modifier. -std::pair, SmallVector> -trivialCtrl(QCOProgramBuilder& b); +SmallVector trivialCtrl(QCOProgramBuilder& b); /// Creates a circuit with an empty ctrl modifier. -std::pair, SmallVector> -emptyCtrl(QCOProgramBuilder& b); +SmallVector emptyCtrl(QCOProgramBuilder& b); /// Creates a circuit with nested ctrl modifiers. -std::pair, SmallVector> -nestedCtrl(QCOProgramBuilder& b); +SmallVector nestedCtrl(QCOProgramBuilder& b); /// Creates a circuit with triple nested ctrl modifiers. -std::pair, SmallVector> -tripleNestedCtrl(QCOProgramBuilder& b); +SmallVector tripleNestedCtrl(QCOProgramBuilder& b); /// Creates a circuit with double nested ctrl modifiers with two qubits each. -std::pair, SmallVector> -doubleNestedCtrlTwoQubits(QCOProgramBuilder& b); +SmallVector doubleNestedCtrlTwoQubits(QCOProgramBuilder& b); /// Creates a circuit with control modifiers interleaved by an inverse modifier. -std::pair, SmallVector> -ctrlInvSandwich(QCOProgramBuilder& b); +SmallVector ctrlInvSandwich(QCOProgramBuilder& b); /// Creates a circuit with a control modifier applied to two gates. -std::pair, SmallVector> ctrlTwo(QCOProgramBuilder& b); +SmallVector ctrlTwo(QCOProgramBuilder& b); /// Creates a circuit with a control modifier applied to a controlled and a /// non-controlled gate. -std::pair, SmallVector> -ctrlTwoMixed(QCOProgramBuilder& b); +SmallVector ctrlTwoMixed(QCOProgramBuilder& b); /// Creates a circuit with nested control modifiers applied to two gates. -std::pair, SmallVector> -nestedCtrlTwo(QCOProgramBuilder& b); +SmallVector nestedCtrlTwo(QCOProgramBuilder& b); /// Creates a circuit with a control modifier applied to an inverse modifier /// applied to two gates. -std::pair, SmallVector> -ctrlInvTwo(QCOProgramBuilder& b); +SmallVector ctrlInvTwo(QCOProgramBuilder& b); // --- InvOp ---------------------------------------------------------------- // /// Creates a circuit with an empty inverse modifier. -std::pair, SmallVector> emptyInv(QCOProgramBuilder& b); +SmallVector emptyInv(QCOProgramBuilder& b); /// Creates a circuit with nested inverse modifiers. -std::pair, SmallVector> -nestedInv(QCOProgramBuilder& b); +SmallVector nestedInv(QCOProgramBuilder& b); /// Creates a circuit with triple nested inverse modifiers. -std::pair, SmallVector> -tripleNestedInv(QCOProgramBuilder& b); +SmallVector tripleNestedInv(QCOProgramBuilder& b); /// Creates a circuit with inverse modifiers interleaved by a control modifier. -std::pair, SmallVector> -invCtrlSandwich(QCOProgramBuilder& b); +SmallVector invCtrlSandwich(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to two gates. -std::pair, SmallVector> invTwo(QCOProgramBuilder& b); +SmallVector invTwo(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a control modifier /// applied to two gates. -std::pair, SmallVector> -invCtrlTwo(QCOProgramBuilder& b); +SmallVector invCtrlTwo(QCOProgramBuilder& b); // --- IfOp ---------------------------------------------------------------- // /// Creates a circuit with a simple if operation with one qubit. -std::pair, SmallVector> simpleIf(QCOProgramBuilder& b); +SmallVector simpleIf(QCOProgramBuilder& b); /// Creates a circuit with an if operation with a parameterized gate. -std::pair, SmallVector> -ifWithAngle(QCOProgramBuilder& b); +SmallVector ifWithAngle(QCOProgramBuilder& b); /// Creates a circuit with an if operation with two qubits. -std::pair, SmallVector> -ifTwoQubits(QCOProgramBuilder& b); +SmallVector ifTwoQubits(QCOProgramBuilder& b); /// Creates a circuit with an if operation with an else branch. -std::pair, SmallVector> ifElse(QCOProgramBuilder& b); +SmallVector ifElse(QCOProgramBuilder& b); /// Creates a circuit with an if operation with one qubit and one register. -std::pair, SmallVector> -ifOneQubitOneTensor(QCOProgramBuilder& b); +SmallVector ifOneQubitOneTensor(QCOProgramBuilder& b); /// Creates a circuit with an if operation that uses a constant true as /// condition. -std::pair, SmallVector> -constantTrueIf(QCOProgramBuilder& b); +SmallVector constantTrueIf(QCOProgramBuilder& b); /// Creates a circuit with an if operation that uses a constant false as /// condition. -std::pair, SmallVector> -constantFalseIf(QCOProgramBuilder& b); +SmallVector constantFalseIf(QCOProgramBuilder& b); /// Creates a circuit with a nested if operation in the then branch that uses /// the same condition. -std::pair, SmallVector> -nestedTrueIf(QCOProgramBuilder& b); +SmallVector nestedTrueIf(QCOProgramBuilder& b); /// Creates a circuit with a nested if operation in the else branch that uses /// the same condition. -std::pair, SmallVector> -nestedFalseIf(QCOProgramBuilder& b); +SmallVector nestedFalseIf(QCOProgramBuilder& b); /// Creates a circuit with an if operation with a nested for operation with /// a register. -std::pair, SmallVector> -nestedIfOpForLoop(QCOProgramBuilder& b); +SmallVector nestedIfOpForLoop(QCOProgramBuilder& b); /// Creates a circuit with an if operation with a nested for operation and /// parameterized gates. -std::pair, SmallVector> -nestedIfOpForLoopWithAngle(QCOProgramBuilder& b); +SmallVector nestedIfOpForLoopWithAngle(QCOProgramBuilder& b); // --- WhileOp -------------------------------------------------------------- // /// Creates a circuit with a while operation using a while loop. -std::pair, SmallVector> -simpleWhileReset(QCOProgramBuilder& b); +SmallVector simpleWhileReset(QCOProgramBuilder& b); /// Creates a circuit with a while operation using a do-while loop. -std::pair, SmallVector> -simpleDoWhileReset(QCOProgramBuilder& b); +SmallVector simpleDoWhileReset(QCOProgramBuilder& b); // --- ForOp ---------------------------------------------------------------- // /// Creates a circuit with a simple for operation with a register. -std::pair, SmallVector> -simpleForLoop(QCOProgramBuilder& b); +SmallVector simpleForLoop(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a parameterized gate. -std::pair, SmallVector> -forLoopWithAngle(QCOProgramBuilder& b); +SmallVector forLoopWithAngle(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested if operation. -std::pair, SmallVector> -nestedForLoopIfOp(QCOProgramBuilder& b); +SmallVector nestedForLoopIfOp(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a register and a nested while /// operation. -std::pair, SmallVector> -nestedForLoopWhileOp(QCOProgramBuilder& b); +SmallVector nestedForLoopWhileOp(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is separately allocated from the /// register. -std::pair, SmallVector> -nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b); +SmallVector nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is extracted from the register. -std::pair, SmallVector> -nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b); +SmallVector nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b); // --- QTensor Operations -------------------------------------------------- // /// Allocates a tensor of size `3`. -std::pair, SmallVector> -qtensorAlloc(QCOProgramBuilder& b); +SmallVector qtensorAlloc(QCOProgramBuilder& b); /// Allocates and explicitly deallocates a tensor. -std::pair, SmallVector> -qtensorDealloc(QCOProgramBuilder& b); +SmallVector qtensorDealloc(QCOProgramBuilder& b); /// Constructs a tensor with from_elements. -std::pair, SmallVector> -qtensorFromElements(QCOProgramBuilder& b); +SmallVector qtensorFromElements(QCOProgramBuilder& b); /// Extracts a qubit from a tensor. -std::pair, SmallVector> -qtensorExtract(QCOProgramBuilder& b); +SmallVector qtensorExtract(QCOProgramBuilder& b); /// Inserts a qubit into a tensor. -std::pair, SmallVector> -qtensorInsert(QCOProgramBuilder& b); +SmallVector qtensorInsert(QCOProgramBuilder& b); /// Extracts a qubit from a tensor and inserts it immediately at a different /// index. -std::pair, SmallVector> -qtensorExtractInsertIndexMismatch(QCOProgramBuilder& b); +SmallVector qtensorExtractInsertIndexMismatch(QCOProgramBuilder& b); /// Extracts a qubit from a tensor and inserts it immediately at the same index. -std::pair, SmallVector> -qtensorExtractInsertSameIndex(QCOProgramBuilder& b); +SmallVector qtensorExtractInsertSameIndex(QCOProgramBuilder& b); /// Inserts a qubit into a tensor and extracts it immediately at a different /// index. -std::pair, SmallVector> -qtensorInsertExtractIndexMismatch(QCOProgramBuilder& b); +SmallVector qtensorInsertExtractIndexMismatch(QCOProgramBuilder& b); /// Inserts a qubit into a tensor and extracts it immediately at the same index. -std::pair, SmallVector> -qtensorInsertExtractSameIndex(QCOProgramBuilder& b); +SmallVector qtensorInsertExtractSameIndex(QCOProgramBuilder& b); /// Extracts three qubits with ascending index (0, 1, 2), performs a /// computation, and finally inserts the qubits in ascending order (0, 1, 2). -std::pair, SmallVector> -qtensorChain(QCOProgramBuilder& b); +SmallVector qtensorChain(QCOProgramBuilder& b); /// Performs the same computation as the `qtensorChain` function, but uses /// qubits immediately after the extract and inserts the qubits in descending /// order (2, 1, 0). -std::pair, SmallVector> -qtensorAlternativeChain(QCOProgramBuilder& b); +SmallVector qtensorAlternativeChain(QCOProgramBuilder& b); -std::pair, SmallVector> -controlledXH(QCOProgramBuilder& b); +SmallVector controlledXH(QCOProgramBuilder& b); -std::pair, SmallVector> -controlledInverseHT(QCOProgramBuilder& b); +SmallVector controlledInverseHT(QCOProgramBuilder& b); -std::pair, SmallVector> -inverseTwoRxRy(QCOProgramBuilder& b); +SmallVector inverseTwoRxRy(QCOProgramBuilder& b); -std::pair, SmallVector> -inverseCxThenRz(QCOProgramBuilder& b); +SmallVector inverseCxThenRz(QCOProgramBuilder& b); -std::pair, SmallVector> -inverseDcxThenRz(QCOProgramBuilder& b); +SmallVector inverseDcxThenRz(QCOProgramBuilder& b); -std::pair, SmallVector> -inverseGphaseBarrierX(QCOProgramBuilder& b); +SmallVector inverseGphaseBarrierX(QCOProgramBuilder& b); -std::pair, SmallVector> -inverseNestedInvHAndT(QCOProgramBuilder& b); +SmallVector inverseNestedInvHAndT(QCOProgramBuilder& b); -std::pair, SmallVector> -inverseNestedInvHAndX(QCOProgramBuilder& b); +SmallVector inverseNestedInvHAndX(QCOProgramBuilder& b); -std::pair, SmallVector> -inverseThreeWireRxRyRz(QCOProgramBuilder& b); +SmallVector inverseThreeWireRxRyRz(QCOProgramBuilder& b); -std::pair, SmallVector> -inverseThreeWireNestedTwoInv(QCOProgramBuilder& b); +SmallVector inverseThreeWireNestedTwoInv(QCOProgramBuilder& b); -std::pair, SmallVector> -inverseWithThreeQubitOpInBody(QCOProgramBuilder& b); +SmallVector inverseWithThreeQubitOpInBody(QCOProgramBuilder& b); } // namespace mlir::qco diff --git a/mlir/unittests/programs/qir_programs.cpp b/mlir/unittests/programs/qir_programs.cpp index 551c0fad94..334fba8079 100644 --- a/mlir/unittests/programs/qir_programs.cpp +++ b/mlir/unittests/programs/qir_programs.cpp @@ -12,14 +12,13 @@ #include "mlir/Dialect/QIR/Builder/QIRProgramBuilder.h" -#include -#include #include #include #include #include -#include + +namespace mlir::qir { /** * @brief Measures the given qubits, records the outcomes and returns @@ -30,18 +29,15 @@ * @param inRegister Whether to store the results in a classical result array or * not. * @param startIndex The starting index for measurement outcomes. - * @return A pair containing the result value and its type. + * @return The result value. */ -static std::pair -measureAndRecord(mlir::qir::QIRProgramBuilder& b, - mlir::SmallVector qubits, bool inRegister, - int64_t startIndex = 0) { +static Value measureAndRecord(QIRProgramBuilder& b, ValueRange qubits, + bool inRegister, int64_t startIndex = 0) { if (qubits.empty()) { - auto zeroConst = b.intConstant(0); - return {zeroConst, b.getI64Type()}; + return b.intConstant(0); } - mlir::qir::QIRProgramBuilder::ClassicalRegister resultArray; + QIRProgramBuilder::ClassicalRegister resultArray; if (inRegister) { resultArray = b.allocClassicalBitRegister( static_cast(qubits.size()), "meas"); @@ -52,50 +48,42 @@ measureAndRecord(mlir::qir::QIRProgramBuilder& b, : b.measure(qubits[i], startIndex + i); } - auto zeroConst = b.intConstant(0); - return {zeroConst, b.getI64Type()}; + return b.intConstant(0); } -namespace mlir::qir { -template -std::pair emptyQIR(QIRProgramBuilder& b) { +template Value emptyQIR(QIRProgramBuilder& b) { return measureAndRecord(b, {}, IntoRegister); } -template -std::pair allocQubit(QIRProgramBuilder& b) { +template Value allocQubit(QIRProgramBuilder& b) { auto q = b.allocQubit(); return measureAndRecord(b, {q}, IntoRegister); } -template -std::pair alloc1QubitRegister(QIRProgramBuilder& b) { +template Value alloc1QubitRegister(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair allocQubitRegister(QIRProgramBuilder& b) { +template Value allocQubitRegister(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair alloc3QubitRegister(QIRProgramBuilder& b) { +template Value alloc3QubitRegister(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair allocMultipleQubitRegisters(QIRProgramBuilder& b) { +Value allocMultipleQubitRegisters(QIRProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); auto q1 = b.allocQubitRegister(3); return measureAndRecord(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}, IntoRegister); } template -std::pair -allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b) { +Value allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); auto q1 = b.allocQubitRegister(3); b.h(q0[0]); @@ -106,19 +94,18 @@ allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b) { return measureAndRecord(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}, IntoRegister); } -template -std::pair allocLargeRegister(QIRProgramBuilder& b) { +template Value allocLargeRegister(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(100); return measureAndRecord(b, {q[0], q[99]}, IntoRegister); } -std::pair staticQubits(QIRProgramBuilder& b) { +Value staticQubits(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); return measureAndRecord(b, {q0, q1}, false); } -std::pair staticQubitsWithOps(QIRProgramBuilder& b) { +Value staticQubitsWithOps(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.h(q0); @@ -126,7 +113,7 @@ std::pair staticQubitsWithOps(QIRProgramBuilder& b) { return measureAndRecord(b, {q0, q1}, false); } -std::pair staticQubitsWithParametricOps(QIRProgramBuilder& b) { +Value staticQubitsWithParametricOps(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.rx(std::numbers::pi / 4., q0); @@ -134,27 +121,27 @@ std::pair staticQubitsWithParametricOps(QIRProgramBuilder& b) { return measureAndRecord(b, {q0, q1}, false); } -std::pair staticQubitsWithTwoTargetOps(QIRProgramBuilder& b) { +Value staticQubitsWithTwoTargetOps(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.rzz(0.123, q0, q1); return measureAndRecord(b, {q0, q1}, false); } -std::pair staticQubitsWithCtrl(QIRProgramBuilder& b) { +Value staticQubitsWithCtrl(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.cx(q0, q1); return measureAndRecord(b, {q0, q1}, false); } -std::pair staticQubitsWithInv(QIRProgramBuilder& b) { +Value staticQubitsWithInv(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); b.tdg(q0); return measureAndRecord(b, {q0}, false); } -std::pair staticQubitsWithDuplicates(QIRProgramBuilder& b) { +Value staticQubitsWithDuplicates(QIRProgramBuilder& b) { auto q0a = b.staticQubit(0); auto q1a = b.staticQubit(1); auto q0b = b.staticQubit(0); @@ -167,7 +154,7 @@ std::pair staticQubitsWithDuplicates(QIRProgramBuilder& b) { return measureAndRecord(b, {q0b, q1b}, false); } -std::pair staticQubitsCanonical(QIRProgramBuilder& b) { +Value staticQubitsCanonical(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.staticQubit(1); b.rx(std::numbers::pi / 4., q0); @@ -178,738 +165,676 @@ std::pair staticQubitsCanonical(QIRProgramBuilder& b) { return measureAndRecord(b, {q0, q1}, false); } -std::pair mixedStaticThenDynamicQubit(QIRProgramBuilder& b) { +Value mixedStaticThenDynamicQubit(QIRProgramBuilder& b) { auto q0 = b.staticQubit(0); auto q1 = b.allocQubit(); return measureAndRecord(b, {q0, q1}, false); } -std::pair -mixedDynamicRegisterThenStaticQubit(QIRProgramBuilder& b) { +Value mixedDynamicRegisterThenStaticQubit(QIRProgramBuilder& b) { auto q0 = b.allocQubitRegister(2); auto q1 = b.staticQubit(0); return measureAndRecord(b, {q0[0], q0[1], q1}, false); } template -std::pair singleMeasurementToSingleBit(QIRProgramBuilder& b) { +Value singleMeasurementToSingleBit(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto c = b.allocClassicalBitRegister(1); b.measure(q[0], c[0]); - return {b.intConstant(0), b.getI64Type()}; + return b.intConstant(0); } template -std::pair repeatedMeasurementToSameBit(QIRProgramBuilder& b) { +Value repeatedMeasurementToSameBit(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto c = b.allocClassicalBitRegister(1); b.measure(q[0], c[0]); b.measure(q[0], c[0]); b.measure(q[0], c[0]); - return {b.intConstant(0), b.getI64Type()}; + return b.intConstant(0); } template -std::pair -repeatedMeasurementToDifferentBits(QIRProgramBuilder& b) { +Value repeatedMeasurementToDifferentBits(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto c = b.allocClassicalBitRegister(3); b.measure(q[0], c[0]); b.measure(q[0], c[1]); b.measure(q[0], c[2]); - return {b.intConstant(0), b.getI64Type()}; + return b.intConstant(0); } template -std::pair -multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b) { +Value multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); const auto& c0 = b.allocClassicalBitRegister(1, "c0"); const auto& c1 = b.allocClassicalBitRegister(2, "c1"); b.measure(q[0], c0[0]); b.measure(q[1], c1[0]); b.measure(q[2], c1[1]); - return {b.intConstant(0), b.getI64Type()}; + return b.intConstant(0); } template -std::pair measurementWithoutRegisters(QIRProgramBuilder& b) { +Value measurementWithoutRegisters(QIRProgramBuilder& b) { auto q = b.allocQubit(); auto bit = b.measure(q, 0); - return {b.intConstant(0), b.getI64Type()}; + return b.intConstant(0); } -template -std::pair resetQubitWithoutOp(QIRProgramBuilder& b) { +template Value resetQubitWithoutOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair resetMultipleQubitsWithoutOp(QIRProgramBuilder& b) { +Value resetMultipleQubitsWithoutOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.reset(q[0]); b.reset(q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair repeatedResetWithoutOp(QIRProgramBuilder& b) { +Value repeatedResetWithoutOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair resetQubitAfterSingleOp(QIRProgramBuilder& b) { +Value resetQubitAfterSingleOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b) { +Value resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.h(q[0]); b.reset(q[0]); b.h(q[1]); b.reset(q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair repeatedResetAfterSingleOp(QIRProgramBuilder& b) { +Value repeatedResetAfterSingleOp(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair globalPhase(QIRProgramBuilder& b) { +template Value globalPhase(QIRProgramBuilder& b) { b.gphase(0.123); return measureAndRecord(b, {}, IntoRegister); } -template -std::pair identity(QIRProgramBuilder& b) { +template Value identity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.id(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair singleControlledIdentity(QIRProgramBuilder& b) { +Value singleControlledIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cid(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair twoQubitsOneIdentity(QIRProgramBuilder& b) { +template Value twoQubitsOneIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.id(q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair threeQubitsOneIdentity(QIRProgramBuilder& b) { +Value threeQubitsOneIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.id(q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair multipleControlledIdentity(QIRProgramBuilder& b) { +Value multipleControlledIdentity(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcid({q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair x(QIRProgramBuilder& b) { +template Value x(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.x(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledX(QIRProgramBuilder& b) { +template Value singleControlledX(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cx(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledX(QIRProgramBuilder& b) { +template Value multipleControlledX(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcx({q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair y(QIRProgramBuilder& b) { +template Value y(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.y(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledY(QIRProgramBuilder& b) { +template Value singleControlledY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cy(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledY(QIRProgramBuilder& b) { +template Value multipleControlledY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcy({q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair z(QIRProgramBuilder& b) { +template Value z(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.z(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledZ(QIRProgramBuilder& b) { +template Value singleControlledZ(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cz(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledZ(QIRProgramBuilder& b) { +template Value multipleControlledZ(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcz({q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair h(QIRProgramBuilder& b) { +template Value h(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledH(QIRProgramBuilder& b) { +template Value singleControlledH(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ch(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledH(QIRProgramBuilder& b) { +template Value multipleControlledH(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mch({q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair hWithoutRegister(QIRProgramBuilder& b) { +template Value hWithoutRegister(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); return measureAndRecord(b, {q}, false); } -template std::pair s(QIRProgramBuilder& b) { +template Value s(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.s(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledS(QIRProgramBuilder& b) { +template Value singleControlledS(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cs(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledS(QIRProgramBuilder& b) { +template Value multipleControlledS(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcs({q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair sdg(QIRProgramBuilder& b) { +template Value sdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sdg(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledSdg(QIRProgramBuilder& b) { +template Value singleControlledSdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csdg(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledSdg(QIRProgramBuilder& b) { +template Value multipleControlledSdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsdg({q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair t_(QIRProgramBuilder& b) { // NOLINT(*-identifier-naming) +Value t_(QIRProgramBuilder& b) { // NOLINT(*-identifier-naming) auto q = b.allocQubitRegister(1); b.t(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledT(QIRProgramBuilder& b) { +template Value singleControlledT(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ct(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledT(QIRProgramBuilder& b) { +template Value multipleControlledT(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mct({q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair tdg(QIRProgramBuilder& b) { +template Value tdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.tdg(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledTdg(QIRProgramBuilder& b) { +template Value singleControlledTdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ctdg(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledTdg(QIRProgramBuilder& b) { +template Value multipleControlledTdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mctdg({q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair sx(QIRProgramBuilder& b) { +template Value sx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sx(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledSx(QIRProgramBuilder& b) { +template Value singleControlledSx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csx(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledSx(QIRProgramBuilder& b) { +template Value multipleControlledSx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsx({q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair sxdg(QIRProgramBuilder& b) { +template Value sxdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sxdg(q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledSxdg(QIRProgramBuilder& b) { +template Value singleControlledSxdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.csxdg(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair multipleControlledSxdg(QIRProgramBuilder& b) { +Value multipleControlledSxdg(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcsxdg({q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair rx(QIRProgramBuilder& b) { +template Value rx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rx(0.123, q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledRx(QIRProgramBuilder& b) { +template Value singleControlledRx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.crx(0.123, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledRx(QIRProgramBuilder& b) { +template Value multipleControlledRx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcrx(0.123, {q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair ry(QIRProgramBuilder& b) { +template Value ry(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.ry(0.456, q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledRy(QIRProgramBuilder& b) { +template Value singleControlledRy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cry(0.456, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledRy(QIRProgramBuilder& b) { +template Value multipleControlledRy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcry(0.456, {q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair rz(QIRProgramBuilder& b) { +template Value rz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rz(0.789, q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledRz(QIRProgramBuilder& b) { +template Value singleControlledRz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.crz(0.789, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledRz(QIRProgramBuilder& b) { +template Value multipleControlledRz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcrz(0.789, {q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair p(QIRProgramBuilder& b) { +template Value p(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.p(0.123, q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledP(QIRProgramBuilder& b) { +template Value singleControlledP(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cp(0.123, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledP(QIRProgramBuilder& b) { +template Value multipleControlledP(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcp(0.123, {q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair r(QIRProgramBuilder& b) { +template Value r(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.r(0.123, 0.456, q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledR(QIRProgramBuilder& b) { +template Value singleControlledR(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cr(0.123, 0.456, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledR(QIRProgramBuilder& b) { +template Value multipleControlledR(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcr(0.123, 0.456, {q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair u2(QIRProgramBuilder& b) { +template Value u2(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u2(0.234, 0.567, q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledU2(QIRProgramBuilder& b) { +template Value singleControlledU2(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cu2(0.234, 0.567, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledU2(QIRProgramBuilder& b) { +template Value multipleControlledU2(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcu2(0.234, 0.567, {q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair u(QIRProgramBuilder& b) { +template Value u(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u(0.1, 0.2, 0.3, q[0]); - return measureAndRecord(b, {q[0]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledU(QIRProgramBuilder& b) { +template Value singleControlledU(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.cu(0.1, 0.2, 0.3, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledU(QIRProgramBuilder& b) { +template Value multipleControlledU(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.mcu(0.1, 0.2, 0.3, {q[0], q[1]}, q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair swap(QIRProgramBuilder& b) { +template Value swap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.swap(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledSwap(QIRProgramBuilder& b) { +template Value singleControlledSwap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cswap(q[0], q[1], q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair multipleControlledSwap(QIRProgramBuilder& b) { +Value multipleControlledSwap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcswap({q[0], q[1]}, q[2], q[3]); - return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair iswap(QIRProgramBuilder& b) { +template Value iswap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.iswap(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledIswap(QIRProgramBuilder& b) { +template Value singleControlledIswap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.ciswap(q[0], q[1], q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair multipleControlledIswap(QIRProgramBuilder& b) { +Value multipleControlledIswap(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mciswap({q[0], q[1]}, q[2], q[3]); - return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair dcx(QIRProgramBuilder& b) { +template Value dcx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.dcx(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledDcx(QIRProgramBuilder& b) { +template Value singleControlledDcx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cdcx(q[0], q[1], q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledDcx(QIRProgramBuilder& b) { +template Value multipleControlledDcx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcdcx({q[0], q[1]}, q[2], q[3]); - return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair ecr(QIRProgramBuilder& b) { +template Value ecr(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ecr(q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledEcr(QIRProgramBuilder& b) { +template Value singleControlledEcr(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cecr(q[0], q[1], q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledEcr(QIRProgramBuilder& b) { +template Value multipleControlledEcr(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcecr({q[0], q[1]}, q[2], q[3]); - return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair rxx(QIRProgramBuilder& b) { +template Value rxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rxx(0.123, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledRxx(QIRProgramBuilder& b) { +template Value singleControlledRxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crxx(0.123, q[0], q[1], q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledRxx(QIRProgramBuilder& b) { +template Value multipleControlledRxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair tripleControlledRxx(QIRProgramBuilder& b) { +template Value tripleControlledRxx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(5); b.mcrxx(0.123, {q[0], q[1], q[2]}, q[3], q[4]); - return measureAndRecord(b, {q[0], q[1], q[2], q[3], q[4]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair ryy(QIRProgramBuilder& b) { +template Value ryy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.ryy(0.123, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledRyy(QIRProgramBuilder& b) { +template Value singleControlledRyy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cryy(0.123, q[0], q[1], q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledRyy(QIRProgramBuilder& b) { +template Value multipleControlledRyy(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcryy(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair rzx(QIRProgramBuilder& b) { +template Value rzx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rzx(0.123, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledRzx(QIRProgramBuilder& b) { +template Value singleControlledRzx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crzx(0.123, q[0], q[1], q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledRzx(QIRProgramBuilder& b) { +template Value multipleControlledRzx(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrzx(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template std::pair rzz(QIRProgramBuilder& b) { +template Value rzz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.rzz(0.123, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair singleControlledRzz(QIRProgramBuilder& b) { +template Value singleControlledRzz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.crzz(0.123, q[0], q[1], q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair multipleControlledRzz(QIRProgramBuilder& b) { +template Value multipleControlledRzz(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcrzz(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair xxPlusYY(QIRProgramBuilder& b) { +template Value xxPlusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.xx_plus_yy(0.123, 0.456, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair singleControlledXxPlusYY(QIRProgramBuilder& b) { +Value singleControlledXxPlusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cxx_plus_yy(0.123, 0.456, q[0], q[1], q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair multipleControlledXxPlusYY(QIRProgramBuilder& b) { +Value multipleControlledXxPlusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcxx_plus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); - return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair xxMinusYY(QIRProgramBuilder& b) { +template Value xxMinusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.xx_minus_yy(0.123, 0.456, q[0], q[1]); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair singleControlledXxMinusYY(QIRProgramBuilder& b) { +Value singleControlledXxMinusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(3); b.cxx_minus_yy(0.123, 0.456, q[0], q[1], q[2]); - return measureAndRecord(b, {q[0], q[1], q[2]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } template -std::pair multipleControlledXxMinusYY(QIRProgramBuilder& b) { +Value multipleControlledXxMinusYY(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcxx_minus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); - return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } -template -std::pair simpleIf(QIRProgramBuilder& b) { +template Value simpleIf(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); auto cond = b.measure(q[0], 0); b.scfIf(cond, [&] { b.x(q[0]); }); - return measureAndRecord(b, {q[0]}, IntoRegister, 1); + return measureAndRecord(b, q.qubits, IntoRegister, 1); } -template -std::pair ifElse(QIRProgramBuilder& b) { +template Value ifElse(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); auto cond = b.measure(q[0], 0); b.scfIf(cond, [&] { b.x(q[0]); }, [&] { b.z(q[0]); }); - return measureAndRecord(b, {q[0]}, IntoRegister, 1); + return measureAndRecord(b, q.qubits, IntoRegister, 1); } -template -std::pair ifTwoQubits(QIRProgramBuilder& b) { +template Value ifTwoQubits(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(2); b.h(q[0]); auto cond = b.measure(q[0], 0); @@ -917,11 +842,10 @@ std::pair ifTwoQubits(QIRProgramBuilder& b) { b.x(q[0]); b.x(q[1]); }); - return measureAndRecord(b, {q[0], q[1]}, IntoRegister, 1); + return measureAndRecord(b, q.qubits, IntoRegister, 1); } -template -std::pair nestedIfOpForLoop(QIRProgramBuilder& b) { +template Value nestedIfOpForLoop(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); b.h(q0); @@ -937,8 +861,7 @@ std::pair nestedIfOpForLoop(QIRProgramBuilder& b) { return measureAndRecord(b, {q0}, IntoRegister, 1); } -template -std::pair simpleWhileReset(QIRProgramBuilder& b) { +template Value simpleWhileReset(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); b.scfWhile( @@ -950,8 +873,7 @@ std::pair simpleWhileReset(QIRProgramBuilder& b) { return measureAndRecord(b, {q}, IntoRegister, 1); } -template -std::pair simpleDoWhileReset(QIRProgramBuilder& b) { +template Value simpleDoWhileReset(QIRProgramBuilder& b) { auto q = b.allocQubit(); b.scfWhile([&] { b.h(q); @@ -961,18 +883,16 @@ std::pair simpleDoWhileReset(QIRProgramBuilder& b) { return measureAndRecord(b, {q}, IntoRegister, 1); } -template -std::pair simpleForLoop(QIRProgramBuilder& b) { +template Value simpleForLoop(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(2); b.scfFor(0, 2, 1, [&](Value iv) { auto q = b.load(reg.value, iv); b.h(q); }); - return measureAndRecord(b, {reg[0], reg[1]}, IntoRegister); + return measureAndRecord(b, reg.qubits, IntoRegister); }; -template -std::pair nestedForLoopIfOp(QIRProgramBuilder& b) { +template Value nestedForLoopIfOp(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto qCond = b.allocQubit(); b.scfFor(0, 2, 1, [&](Value iv) { @@ -986,8 +906,7 @@ std::pair nestedForLoopIfOp(QIRProgramBuilder& b) { return measureAndRecord(b, {qCond}, IntoRegister, 1); } -template -std::pair nestedForLoopWhileOp(QIRProgramBuilder& b) { +template Value nestedForLoopWhileOp(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(2); b.scfFor(0, 2, 1, [&](Value iv) { auto q = b.load(reg.value, iv); @@ -1002,12 +921,11 @@ std::pair nestedForLoopWhileOp(QIRProgramBuilder& b) { }, [&] { b.h(q); }); }); - return measureAndRecord(b, {reg[0], reg[1]}, IntoRegister, 1); + return measureAndRecord(b, reg.qubits, IntoRegister, 1); } template -std::pair -nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b) { +Value nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto control = b.allocQubit(); b.h(control); @@ -1020,8 +938,7 @@ nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b) { } template -std::pair -nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b) { +Value nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.h(reg[0]); b.scfFor(1, 4, 1, [&](Value iv) { @@ -1032,360 +949,259 @@ nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b) { return measureAndRecord(b, {reg[0]}, IntoRegister); } -template -std::pair ctrlTwo(QIRProgramBuilder& b) { +template Value ctrlTwo(QIRProgramBuilder& b) { auto q = b.allocQubitRegister(4); b.mcx({q[0], q[1]}, q[2]); b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); - return measureAndRecord(b, {q[0], q[1], q[2], q[3]}, IntoRegister); + return measureAndRecord(b, q.qubits, IntoRegister); } // Instantiate the templates for IntoRegister = false -template std::pair emptyQIR(QIRProgramBuilder& builder); -template std::pair allocQubit(QIRProgramBuilder& b); -template std::pair -alloc1QubitRegister(QIRProgramBuilder& b); -template std::pair allocQubitRegister(QIRProgramBuilder& b); -template std::pair -alloc3QubitRegister(QIRProgramBuilder& b); -template std::pair -allocMultipleQubitRegisters(QIRProgramBuilder& b); -template std::pair -allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b); -template std::pair allocLargeRegister(QIRProgramBuilder& b); -template std::pair -singleMeasurementToSingleBit(QIRProgramBuilder& b); -template std::pair -repeatedMeasurementToSameBit(QIRProgramBuilder& b); -template std::pair -repeatedMeasurementToDifferentBits(QIRProgramBuilder& b); -template std::pair +template Value emptyQIR(QIRProgramBuilder& builder); +template Value allocQubit(QIRProgramBuilder& b); +template Value alloc1QubitRegister(QIRProgramBuilder& b); +template Value allocQubitRegister(QIRProgramBuilder& b); +template Value alloc3QubitRegister(QIRProgramBuilder& b); +template Value allocMultipleQubitRegisters(QIRProgramBuilder& b); +template Value allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b); +template Value allocLargeRegister(QIRProgramBuilder& b); +template Value singleMeasurementToSingleBit(QIRProgramBuilder& b); +template Value repeatedMeasurementToSameBit(QIRProgramBuilder& b); +template Value repeatedMeasurementToDifferentBits(QIRProgramBuilder& b); +template Value multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b); -template std::pair -measurementWithoutRegisters(QIRProgramBuilder& b); -template std::pair -resetQubitWithoutOp(QIRProgramBuilder& b); -template std::pair -resetMultipleQubitsWithoutOp(QIRProgramBuilder& b); -template std::pair -repeatedResetWithoutOp(QIRProgramBuilder& b); -template std::pair -resetQubitAfterSingleOp(QIRProgramBuilder& b); -template std::pair -resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b); -template std::pair -repeatedResetAfterSingleOp(QIRProgramBuilder& b); -template std::pair globalPhase(QIRProgramBuilder& b); -template std::pair identity(QIRProgramBuilder& b); -template std::pair -singleControlledIdentity(QIRProgramBuilder& b); -template std::pair -twoQubitsOneIdentity(QIRProgramBuilder& b); -template std::pair -threeQubitsOneIdentity(QIRProgramBuilder& b); -template std::pair -multipleControlledIdentity(QIRProgramBuilder& b); -template std::pair x(QIRProgramBuilder& b); -template std::pair singleControlledX(QIRProgramBuilder& b); -template std::pair -multipleControlledX(QIRProgramBuilder& b); -template std::pair y(QIRProgramBuilder& b); -template std::pair singleControlledY(QIRProgramBuilder& b); -template std::pair -multipleControlledY(QIRProgramBuilder& b); -template std::pair z(QIRProgramBuilder& b); -template std::pair singleControlledZ(QIRProgramBuilder& b); -template std::pair -multipleControlledZ(QIRProgramBuilder& b); -template std::pair h(QIRProgramBuilder& b); -template std::pair singleControlledH(QIRProgramBuilder& b); -template std::pair -multipleControlledH(QIRProgramBuilder& b); -template std::pair hWithoutRegister(QIRProgramBuilder& b); -template std::pair s(QIRProgramBuilder& b); -template std::pair singleControlledS(QIRProgramBuilder& b); -template std::pair -multipleControlledS(QIRProgramBuilder& b); -template std::pair sdg(QIRProgramBuilder& b); -template std::pair -singleControlledSdg(QIRProgramBuilder& b); -template std::pair -multipleControlledSdg(QIRProgramBuilder& b); -template std::pair t_(QIRProgramBuilder& b); -template std::pair singleControlledT(QIRProgramBuilder& b); -template std::pair -multipleControlledT(QIRProgramBuilder& b); -template std::pair tdg(QIRProgramBuilder& b); -template std::pair -singleControlledTdg(QIRProgramBuilder& b); -template std::pair -multipleControlledTdg(QIRProgramBuilder& b); -template std::pair sx(QIRProgramBuilder& b); -template std::pair singleControlledSx(QIRProgramBuilder& b); -template std::pair -multipleControlledSx(QIRProgramBuilder& b); -template std::pair sxdg(QIRProgramBuilder& b); -template std::pair -singleControlledSxdg(QIRProgramBuilder& b); -template std::pair -multipleControlledSxdg(QIRProgramBuilder& b); -template std::pair rx(QIRProgramBuilder& b); -template std::pair singleControlledRx(QIRProgramBuilder& b); -template std::pair -multipleControlledRx(QIRProgramBuilder& b); -template std::pair ry(QIRProgramBuilder& b); -template std::pair singleControlledRy(QIRProgramBuilder& b); -template std::pair -multipleControlledRy(QIRProgramBuilder& b); -template std::pair rz(QIRProgramBuilder& b); -template std::pair singleControlledRz(QIRProgramBuilder& b); -template std::pair -multipleControlledRz(QIRProgramBuilder& b); -template std::pair p(QIRProgramBuilder& b); -template std::pair singleControlledP(QIRProgramBuilder& b); -template std::pair -multipleControlledP(QIRProgramBuilder& b); -template std::pair r(QIRProgramBuilder& b); -template std::pair singleControlledR(QIRProgramBuilder& b); -template std::pair -multipleControlledR(QIRProgramBuilder& b); -template std::pair u2(QIRProgramBuilder& b); -template std::pair singleControlledU2(QIRProgramBuilder& b); -template std::pair -multipleControlledU2(QIRProgramBuilder& b); -template std::pair u(QIRProgramBuilder& b); -template std::pair singleControlledU(QIRProgramBuilder& b); -template std::pair -multipleControlledU(QIRProgramBuilder& b); -template std::pair swap(QIRProgramBuilder& b); -template std::pair -singleControlledSwap(QIRProgramBuilder& b); -template std::pair -multipleControlledSwap(QIRProgramBuilder& b); -template std::pair iswap(QIRProgramBuilder& b); -template std::pair -singleControlledIswap(QIRProgramBuilder& b); -template std::pair -multipleControlledIswap(QIRProgramBuilder& b); -template std::pair dcx(QIRProgramBuilder& b); -template std::pair -singleControlledDcx(QIRProgramBuilder& b); -template std::pair -multipleControlledDcx(QIRProgramBuilder& b); -template std::pair ecr(QIRProgramBuilder& b); -template std::pair -singleControlledEcr(QIRProgramBuilder& b); -template std::pair -multipleControlledEcr(QIRProgramBuilder& b); -template std::pair rxx(QIRProgramBuilder& b); -template std::pair -singleControlledRxx(QIRProgramBuilder& b); -template std::pair -multipleControlledRxx(QIRProgramBuilder& b); -template std::pair -tripleControlledRxx(QIRProgramBuilder& b); -template std::pair ryy(QIRProgramBuilder& b); -template std::pair -singleControlledRyy(QIRProgramBuilder& b); -template std::pair -multipleControlledRyy(QIRProgramBuilder& b); -template std::pair rzx(QIRProgramBuilder& b); -template std::pair -singleControlledRzx(QIRProgramBuilder& b); -template std::pair -multipleControlledRzx(QIRProgramBuilder& b); -template std::pair rzz(QIRProgramBuilder& b); -template std::pair -singleControlledRzz(QIRProgramBuilder& b); -template std::pair -multipleControlledRzz(QIRProgramBuilder& b); -template std::pair xxPlusYY(QIRProgramBuilder& b); -template std::pair -singleControlledXxPlusYY(QIRProgramBuilder& b); -template std::pair -multipleControlledXxPlusYY(QIRProgramBuilder& b); -template std::pair xxMinusYY(QIRProgramBuilder& b); -template std::pair -singleControlledXxMinusYY(QIRProgramBuilder& b); -template std::pair -multipleControlledXxMinusYY(QIRProgramBuilder& b); -template std::pair simpleIf(QIRProgramBuilder& b); -template std::pair ifElse(QIRProgramBuilder& b); -template std::pair ifTwoQubits(QIRProgramBuilder& b); -template std::pair nestedIfOpForLoop(QIRProgramBuilder& b); -template std::pair simpleWhileReset(QIRProgramBuilder& b); -template std::pair simpleDoWhileReset(QIRProgramBuilder& b); -template std::pair simpleForLoop(QIRProgramBuilder& b); -template std::pair nestedForLoopIfOp(QIRProgramBuilder& b); -template std::pair -nestedForLoopWhileOp(QIRProgramBuilder& b); -template std::pair +template Value measurementWithoutRegisters(QIRProgramBuilder& b); +template Value resetQubitWithoutOp(QIRProgramBuilder& b); +template Value resetMultipleQubitsWithoutOp(QIRProgramBuilder& b); +template Value repeatedResetWithoutOp(QIRProgramBuilder& b); +template Value resetQubitAfterSingleOp(QIRProgramBuilder& b); +template Value resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b); +template Value repeatedResetAfterSingleOp(QIRProgramBuilder& b); +template Value globalPhase(QIRProgramBuilder& b); +template Value identity(QIRProgramBuilder& b); +template Value singleControlledIdentity(QIRProgramBuilder& b); +template Value twoQubitsOneIdentity(QIRProgramBuilder& b); +template Value threeQubitsOneIdentity(QIRProgramBuilder& b); +template Value multipleControlledIdentity(QIRProgramBuilder& b); +template Value x(QIRProgramBuilder& b); +template Value singleControlledX(QIRProgramBuilder& b); +template Value multipleControlledX(QIRProgramBuilder& b); +template Value y(QIRProgramBuilder& b); +template Value singleControlledY(QIRProgramBuilder& b); +template Value multipleControlledY(QIRProgramBuilder& b); +template Value z(QIRProgramBuilder& b); +template Value singleControlledZ(QIRProgramBuilder& b); +template Value multipleControlledZ(QIRProgramBuilder& b); +template Value h(QIRProgramBuilder& b); +template Value singleControlledH(QIRProgramBuilder& b); +template Value multipleControlledH(QIRProgramBuilder& b); +template Value hWithoutRegister(QIRProgramBuilder& b); +template Value s(QIRProgramBuilder& b); +template Value singleControlledS(QIRProgramBuilder& b); +template Value multipleControlledS(QIRProgramBuilder& b); +template Value sdg(QIRProgramBuilder& b); +template Value singleControlledSdg(QIRProgramBuilder& b); +template Value multipleControlledSdg(QIRProgramBuilder& b); +template Value t_(QIRProgramBuilder& b); +template Value singleControlledT(QIRProgramBuilder& b); +template Value multipleControlledT(QIRProgramBuilder& b); +template Value tdg(QIRProgramBuilder& b); +template Value singleControlledTdg(QIRProgramBuilder& b); +template Value multipleControlledTdg(QIRProgramBuilder& b); +template Value sx(QIRProgramBuilder& b); +template Value singleControlledSx(QIRProgramBuilder& b); +template Value multipleControlledSx(QIRProgramBuilder& b); +template Value sxdg(QIRProgramBuilder& b); +template Value singleControlledSxdg(QIRProgramBuilder& b); +template Value multipleControlledSxdg(QIRProgramBuilder& b); +template Value rx(QIRProgramBuilder& b); +template Value singleControlledRx(QIRProgramBuilder& b); +template Value multipleControlledRx(QIRProgramBuilder& b); +template Value ry(QIRProgramBuilder& b); +template Value singleControlledRy(QIRProgramBuilder& b); +template Value multipleControlledRy(QIRProgramBuilder& b); +template Value rz(QIRProgramBuilder& b); +template Value singleControlledRz(QIRProgramBuilder& b); +template Value multipleControlledRz(QIRProgramBuilder& b); +template Value p(QIRProgramBuilder& b); +template Value singleControlledP(QIRProgramBuilder& b); +template Value multipleControlledP(QIRProgramBuilder& b); +template Value r(QIRProgramBuilder& b); +template Value singleControlledR(QIRProgramBuilder& b); +template Value multipleControlledR(QIRProgramBuilder& b); +template Value u2(QIRProgramBuilder& b); +template Value singleControlledU2(QIRProgramBuilder& b); +template Value multipleControlledU2(QIRProgramBuilder& b); +template Value u(QIRProgramBuilder& b); +template Value singleControlledU(QIRProgramBuilder& b); +template Value multipleControlledU(QIRProgramBuilder& b); +template Value swap(QIRProgramBuilder& b); +template Value singleControlledSwap(QIRProgramBuilder& b); +template Value multipleControlledSwap(QIRProgramBuilder& b); +template Value iswap(QIRProgramBuilder& b); +template Value singleControlledIswap(QIRProgramBuilder& b); +template Value multipleControlledIswap(QIRProgramBuilder& b); +template Value dcx(QIRProgramBuilder& b); +template Value singleControlledDcx(QIRProgramBuilder& b); +template Value multipleControlledDcx(QIRProgramBuilder& b); +template Value ecr(QIRProgramBuilder& b); +template Value singleControlledEcr(QIRProgramBuilder& b); +template Value multipleControlledEcr(QIRProgramBuilder& b); +template Value rxx(QIRProgramBuilder& b); +template Value singleControlledRxx(QIRProgramBuilder& b); +template Value multipleControlledRxx(QIRProgramBuilder& b); +template Value tripleControlledRxx(QIRProgramBuilder& b); +template Value ryy(QIRProgramBuilder& b); +template Value singleControlledRyy(QIRProgramBuilder& b); +template Value multipleControlledRyy(QIRProgramBuilder& b); +template Value rzx(QIRProgramBuilder& b); +template Value singleControlledRzx(QIRProgramBuilder& b); +template Value multipleControlledRzx(QIRProgramBuilder& b); +template Value rzz(QIRProgramBuilder& b); +template Value singleControlledRzz(QIRProgramBuilder& b); +template Value multipleControlledRzz(QIRProgramBuilder& b); +template Value xxPlusYY(QIRProgramBuilder& b); +template Value singleControlledXxPlusYY(QIRProgramBuilder& b); +template Value multipleControlledXxPlusYY(QIRProgramBuilder& b); +template Value xxMinusYY(QIRProgramBuilder& b); +template Value singleControlledXxMinusYY(QIRProgramBuilder& b); +template Value multipleControlledXxMinusYY(QIRProgramBuilder& b); +template Value simpleIf(QIRProgramBuilder& b); +template Value ifElse(QIRProgramBuilder& b); +template Value ifTwoQubits(QIRProgramBuilder& b); +template Value nestedIfOpForLoop(QIRProgramBuilder& b); +template Value simpleWhileReset(QIRProgramBuilder& b); +template Value simpleDoWhileReset(QIRProgramBuilder& b); +template Value simpleForLoop(QIRProgramBuilder& b); +template Value nestedForLoopIfOp(QIRProgramBuilder& b); +template Value nestedForLoopWhileOp(QIRProgramBuilder& b); +template Value nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b); -template std::pair +template Value nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b); -template std::pair ctrlTwo(QIRProgramBuilder& b); +template Value ctrlTwo(QIRProgramBuilder& b); // Instantiate the templates for IntoRegister = true -template std::pair emptyQIR(QIRProgramBuilder& builder); -template std::pair allocQubit(QIRProgramBuilder& b); -template std::pair alloc1QubitRegister(QIRProgramBuilder& b); -template std::pair allocQubitRegister(QIRProgramBuilder& b); -template std::pair alloc3QubitRegister(QIRProgramBuilder& b); -template std::pair -allocMultipleQubitRegisters(QIRProgramBuilder& b); -template std::pair -allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b); -template std::pair allocLargeRegister(QIRProgramBuilder& b); -template std::pair -singleMeasurementToSingleBit(QIRProgramBuilder& b); -template std::pair -repeatedMeasurementToSameBit(QIRProgramBuilder& b); -template std::pair -repeatedMeasurementToDifferentBits(QIRProgramBuilder& b); -template std::pair +template Value emptyQIR(QIRProgramBuilder& builder); +template Value allocQubit(QIRProgramBuilder& b); +template Value alloc1QubitRegister(QIRProgramBuilder& b); +template Value allocQubitRegister(QIRProgramBuilder& b); +template Value alloc3QubitRegister(QIRProgramBuilder& b); +template Value allocMultipleQubitRegisters(QIRProgramBuilder& b); +template Value allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b); +template Value allocLargeRegister(QIRProgramBuilder& b); +template Value singleMeasurementToSingleBit(QIRProgramBuilder& b); +template Value repeatedMeasurementToSameBit(QIRProgramBuilder& b); +template Value repeatedMeasurementToDifferentBits(QIRProgramBuilder& b); +template Value multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b); -template std::pair -measurementWithoutRegisters(QIRProgramBuilder& b); -template std::pair resetQubitWithoutOp(QIRProgramBuilder& b); -template std::pair -resetMultipleQubitsWithoutOp(QIRProgramBuilder& b); -template std::pair -repeatedResetWithoutOp(QIRProgramBuilder& b); -template std::pair -resetQubitAfterSingleOp(QIRProgramBuilder& b); -template std::pair -resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b); -template std::pair -repeatedResetAfterSingleOp(QIRProgramBuilder& b); -template std::pair globalPhase(QIRProgramBuilder& b); -template std::pair identity(QIRProgramBuilder& b); -template std::pair -singleControlledIdentity(QIRProgramBuilder& b); -template std::pair -twoQubitsOneIdentity(QIRProgramBuilder& b); -template std::pair -threeQubitsOneIdentity(QIRProgramBuilder& b); -template std::pair -multipleControlledIdentity(QIRProgramBuilder& b); -template std::pair x(QIRProgramBuilder& b); -template std::pair singleControlledX(QIRProgramBuilder& b); -template std::pair multipleControlledX(QIRProgramBuilder& b); -template std::pair y(QIRProgramBuilder& b); -template std::pair singleControlledY(QIRProgramBuilder& b); -template std::pair multipleControlledY(QIRProgramBuilder& b); -template std::pair z(QIRProgramBuilder& b); -template std::pair singleControlledZ(QIRProgramBuilder& b); -template std::pair multipleControlledZ(QIRProgramBuilder& b); -template std::pair h(QIRProgramBuilder& b); -template std::pair singleControlledH(QIRProgramBuilder& b); -template std::pair multipleControlledH(QIRProgramBuilder& b); -template std::pair hWithoutRegister(QIRProgramBuilder& b); -template std::pair s(QIRProgramBuilder& b); -template std::pair singleControlledS(QIRProgramBuilder& b); -template std::pair multipleControlledS(QIRProgramBuilder& b); -template std::pair sdg(QIRProgramBuilder& b); -template std::pair singleControlledSdg(QIRProgramBuilder& b); -template std::pair -multipleControlledSdg(QIRProgramBuilder& b); -template std::pair t_(QIRProgramBuilder& b); -template std::pair singleControlledT(QIRProgramBuilder& b); -template std::pair multipleControlledT(QIRProgramBuilder& b); -template std::pair tdg(QIRProgramBuilder& b); -template std::pair singleControlledTdg(QIRProgramBuilder& b); -template std::pair -multipleControlledTdg(QIRProgramBuilder& b); -template std::pair sx(QIRProgramBuilder& b); -template std::pair singleControlledSx(QIRProgramBuilder& b); -template std::pair -multipleControlledSx(QIRProgramBuilder& b); -template std::pair sxdg(QIRProgramBuilder& b); -template std::pair -singleControlledSxdg(QIRProgramBuilder& b); -template std::pair -multipleControlledSxdg(QIRProgramBuilder& b); -template std::pair rx(QIRProgramBuilder& b); -template std::pair singleControlledRx(QIRProgramBuilder& b); -template std::pair -multipleControlledRx(QIRProgramBuilder& b); -template std::pair ry(QIRProgramBuilder& b); -template std::pair singleControlledRy(QIRProgramBuilder& b); -template std::pair -multipleControlledRy(QIRProgramBuilder& b); -template std::pair rz(QIRProgramBuilder& b); -template std::pair singleControlledRz(QIRProgramBuilder& b); -template std::pair -multipleControlledRz(QIRProgramBuilder& b); -template std::pair p(QIRProgramBuilder& b); -template std::pair singleControlledP(QIRProgramBuilder& b); -template std::pair multipleControlledP(QIRProgramBuilder& b); -template std::pair r(QIRProgramBuilder& b); -template std::pair singleControlledR(QIRProgramBuilder& b); -template std::pair multipleControlledR(QIRProgramBuilder& b); -template std::pair u2(QIRProgramBuilder& b); -template std::pair singleControlledU2(QIRProgramBuilder& b); -template std::pair -multipleControlledU2(QIRProgramBuilder& b); -template std::pair u(QIRProgramBuilder& b); -template std::pair singleControlledU(QIRProgramBuilder& b); -template std::pair multipleControlledU(QIRProgramBuilder& b); -template std::pair swap(QIRProgramBuilder& b); -template std::pair -singleControlledSwap(QIRProgramBuilder& b); -template std::pair -multipleControlledSwap(QIRProgramBuilder& b); -template std::pair iswap(QIRProgramBuilder& b); -template std::pair -singleControlledIswap(QIRProgramBuilder& b); -template std::pair -multipleControlledIswap(QIRProgramBuilder& b); -template std::pair dcx(QIRProgramBuilder& b); -template std::pair singleControlledDcx(QIRProgramBuilder& b); -template std::pair -multipleControlledDcx(QIRProgramBuilder& b); -template std::pair ecr(QIRProgramBuilder& b); -template std::pair singleControlledEcr(QIRProgramBuilder& b); -template std::pair -multipleControlledEcr(QIRProgramBuilder& b); -template std::pair rxx(QIRProgramBuilder& b); -template std::pair singleControlledRxx(QIRProgramBuilder& b); -template std::pair -multipleControlledRxx(QIRProgramBuilder& b); -template std::pair tripleControlledRxx(QIRProgramBuilder& b); -template std::pair ryy(QIRProgramBuilder& b); -template std::pair singleControlledRyy(QIRProgramBuilder& b); -template std::pair -multipleControlledRyy(QIRProgramBuilder& b); -template std::pair rzx(QIRProgramBuilder& b); -template std::pair singleControlledRzx(QIRProgramBuilder& b); -template std::pair -multipleControlledRzx(QIRProgramBuilder& b); -template std::pair rzz(QIRProgramBuilder& b); -template std::pair singleControlledRzz(QIRProgramBuilder& b); -template std::pair -multipleControlledRzz(QIRProgramBuilder& b); -template std::pair xxPlusYY(QIRProgramBuilder& b); -template std::pair -singleControlledXxPlusYY(QIRProgramBuilder& b); -template std::pair -multipleControlledXxPlusYY(QIRProgramBuilder& b); -template std::pair xxMinusYY(QIRProgramBuilder& b); -template std::pair -singleControlledXxMinusYY(QIRProgramBuilder& b); -template std::pair -multipleControlledXxMinusYY(QIRProgramBuilder& b); -template std::pair simpleIf(QIRProgramBuilder& b); -template std::pair ifElse(QIRProgramBuilder& b); -template std::pair ifTwoQubits(QIRProgramBuilder& b); -template std::pair nestedIfOpForLoop(QIRProgramBuilder& b); -template std::pair simpleWhileReset(QIRProgramBuilder& b); -template std::pair simpleDoWhileReset(QIRProgramBuilder& b); -template std::pair simpleForLoop(QIRProgramBuilder& b); -template std::pair nestedForLoopIfOp(QIRProgramBuilder& b); -template std::pair -nestedForLoopWhileOp(QIRProgramBuilder& b); -template std::pair -nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b); -template std::pair +template Value measurementWithoutRegisters(QIRProgramBuilder& b); +template Value resetQubitWithoutOp(QIRProgramBuilder& b); +template Value resetMultipleQubitsWithoutOp(QIRProgramBuilder& b); +template Value repeatedResetWithoutOp(QIRProgramBuilder& b); +template Value resetQubitAfterSingleOp(QIRProgramBuilder& b); +template Value resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b); +template Value repeatedResetAfterSingleOp(QIRProgramBuilder& b); +template Value globalPhase(QIRProgramBuilder& b); +template Value identity(QIRProgramBuilder& b); +template Value singleControlledIdentity(QIRProgramBuilder& b); +template Value twoQubitsOneIdentity(QIRProgramBuilder& b); +template Value threeQubitsOneIdentity(QIRProgramBuilder& b); +template Value multipleControlledIdentity(QIRProgramBuilder& b); +template Value x(QIRProgramBuilder& b); +template Value singleControlledX(QIRProgramBuilder& b); +template Value multipleControlledX(QIRProgramBuilder& b); +template Value y(QIRProgramBuilder& b); +template Value singleControlledY(QIRProgramBuilder& b); +template Value multipleControlledY(QIRProgramBuilder& b); +template Value z(QIRProgramBuilder& b); +template Value singleControlledZ(QIRProgramBuilder& b); +template Value multipleControlledZ(QIRProgramBuilder& b); +template Value h(QIRProgramBuilder& b); +template Value singleControlledH(QIRProgramBuilder& b); +template Value multipleControlledH(QIRProgramBuilder& b); +template Value hWithoutRegister(QIRProgramBuilder& b); +template Value s(QIRProgramBuilder& b); +template Value singleControlledS(QIRProgramBuilder& b); +template Value multipleControlledS(QIRProgramBuilder& b); +template Value sdg(QIRProgramBuilder& b); +template Value singleControlledSdg(QIRProgramBuilder& b); +template Value multipleControlledSdg(QIRProgramBuilder& b); +template Value t_(QIRProgramBuilder& b); +template Value singleControlledT(QIRProgramBuilder& b); +template Value multipleControlledT(QIRProgramBuilder& b); +template Value tdg(QIRProgramBuilder& b); +template Value singleControlledTdg(QIRProgramBuilder& b); +template Value multipleControlledTdg(QIRProgramBuilder& b); +template Value sx(QIRProgramBuilder& b); +template Value singleControlledSx(QIRProgramBuilder& b); +template Value multipleControlledSx(QIRProgramBuilder& b); +template Value sxdg(QIRProgramBuilder& b); +template Value singleControlledSxdg(QIRProgramBuilder& b); +template Value multipleControlledSxdg(QIRProgramBuilder& b); +template Value rx(QIRProgramBuilder& b); +template Value singleControlledRx(QIRProgramBuilder& b); +template Value multipleControlledRx(QIRProgramBuilder& b); +template Value ry(QIRProgramBuilder& b); +template Value singleControlledRy(QIRProgramBuilder& b); +template Value multipleControlledRy(QIRProgramBuilder& b); +template Value rz(QIRProgramBuilder& b); +template Value singleControlledRz(QIRProgramBuilder& b); +template Value multipleControlledRz(QIRProgramBuilder& b); +template Value p(QIRProgramBuilder& b); +template Value singleControlledP(QIRProgramBuilder& b); +template Value multipleControlledP(QIRProgramBuilder& b); +template Value r(QIRProgramBuilder& b); +template Value singleControlledR(QIRProgramBuilder& b); +template Value multipleControlledR(QIRProgramBuilder& b); +template Value u2(QIRProgramBuilder& b); +template Value singleControlledU2(QIRProgramBuilder& b); +template Value multipleControlledU2(QIRProgramBuilder& b); +template Value u(QIRProgramBuilder& b); +template Value singleControlledU(QIRProgramBuilder& b); +template Value multipleControlledU(QIRProgramBuilder& b); +template Value swap(QIRProgramBuilder& b); +template Value singleControlledSwap(QIRProgramBuilder& b); +template Value multipleControlledSwap(QIRProgramBuilder& b); +template Value iswap(QIRProgramBuilder& b); +template Value singleControlledIswap(QIRProgramBuilder& b); +template Value multipleControlledIswap(QIRProgramBuilder& b); +template Value dcx(QIRProgramBuilder& b); +template Value singleControlledDcx(QIRProgramBuilder& b); +template Value multipleControlledDcx(QIRProgramBuilder& b); +template Value ecr(QIRProgramBuilder& b); +template Value singleControlledEcr(QIRProgramBuilder& b); +template Value multipleControlledEcr(QIRProgramBuilder& b); +template Value rxx(QIRProgramBuilder& b); +template Value singleControlledRxx(QIRProgramBuilder& b); +template Value multipleControlledRxx(QIRProgramBuilder& b); +template Value tripleControlledRxx(QIRProgramBuilder& b); +template Value ryy(QIRProgramBuilder& b); +template Value singleControlledRyy(QIRProgramBuilder& b); +template Value multipleControlledRyy(QIRProgramBuilder& b); +template Value rzx(QIRProgramBuilder& b); +template Value singleControlledRzx(QIRProgramBuilder& b); +template Value multipleControlledRzx(QIRProgramBuilder& b); +template Value rzz(QIRProgramBuilder& b); +template Value singleControlledRzz(QIRProgramBuilder& b); +template Value multipleControlledRzz(QIRProgramBuilder& b); +template Value xxPlusYY(QIRProgramBuilder& b); +template Value singleControlledXxPlusYY(QIRProgramBuilder& b); +template Value multipleControlledXxPlusYY(QIRProgramBuilder& b); +template Value xxMinusYY(QIRProgramBuilder& b); +template Value singleControlledXxMinusYY(QIRProgramBuilder& b); +template Value multipleControlledXxMinusYY(QIRProgramBuilder& b); +template Value simpleIf(QIRProgramBuilder& b); +template Value ifElse(QIRProgramBuilder& b); +template Value ifTwoQubits(QIRProgramBuilder& b); +template Value nestedIfOpForLoop(QIRProgramBuilder& b); +template Value simpleWhileReset(QIRProgramBuilder& b); +template Value simpleDoWhileReset(QIRProgramBuilder& b); +template Value simpleForLoop(QIRProgramBuilder& b); +template Value nestedForLoopIfOp(QIRProgramBuilder& b); +template Value nestedForLoopWhileOp(QIRProgramBuilder& b); +template Value nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b); +template Value nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b); -template std::pair ctrlTwo(QIRProgramBuilder& b); +template Value ctrlTwo(QIRProgramBuilder& b); } // namespace mlir::qir diff --git a/mlir/unittests/programs/qir_programs.h b/mlir/unittests/programs/qir_programs.h index c5b2d9df00..b58a3ff396 100644 --- a/mlir/unittests/programs/qir_programs.h +++ b/mlir/unittests/programs/qir_programs.h @@ -10,609 +10,567 @@ #pragma once -#include #include -#include - namespace mlir::qir { class QIRProgramBuilder; /// Creates an empty QIR program. -template -std::pair emptyQIR(QIRProgramBuilder& builder); +template Value emptyQIR(QIRProgramBuilder& builder); // --- Qubit Management ----------------------------------------------------- // /// Allocates a single qubit. -template -std::pair allocQubit(QIRProgramBuilder& b); +template Value allocQubit(QIRProgramBuilder& b); /// Allocates a qubit register of size `1`. template -std::pair alloc1QubitRegister(QIRProgramBuilder& b); +Value alloc1QubitRegister(QIRProgramBuilder& b); /// Allocates a qubit register of size `2`. template -std::pair allocQubitRegister(QIRProgramBuilder& b); +Value allocQubitRegister(QIRProgramBuilder& b); /// Allocates a qubit register of size `3`. template -std::pair alloc3QubitRegister(QIRProgramBuilder& b); +Value alloc3QubitRegister(QIRProgramBuilder& b); /// Allocates two qubit registers of size `2` and `3`. template -std::pair allocMultipleQubitRegisters(QIRProgramBuilder& b); +Value allocMultipleQubitRegisters(QIRProgramBuilder& b); /// Allocates two qubit registers of size `2` and `3` and applies operations. template -std::pair allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b); +Value allocMultipleQubitRegistersWithOps(QIRProgramBuilder& b); /// Allocates a large qubit register. template -std::pair allocLargeRegister(QIRProgramBuilder& b); +Value allocLargeRegister(QIRProgramBuilder& b); /// Allocates two inline qubits. -std::pair staticQubits(QIRProgramBuilder& b); +Value staticQubits(QIRProgramBuilder& b); /// Allocates two static qubits and applies operations. -std::pair staticQubitsWithOps(QIRProgramBuilder& b); +Value staticQubitsWithOps(QIRProgramBuilder& b); /// Allocates two static qubits and applies parametric gates. -std::pair staticQubitsWithParametricOps(QIRProgramBuilder& b); +Value staticQubitsWithParametricOps(QIRProgramBuilder& b); /// Allocates two static qubits and applies a two-target gate. -std::pair staticQubitsWithTwoTargetOps(QIRProgramBuilder& b); +Value staticQubitsWithTwoTargetOps(QIRProgramBuilder& b); /// Allocates two static qubits and applies a controlled gate. -std::pair staticQubitsWithCtrl(QIRProgramBuilder& b); +Value staticQubitsWithCtrl(QIRProgramBuilder& b); /// Allocates a static qubit and applies the inverse of a T gate (Tdg). -std::pair staticQubitsWithInv(QIRProgramBuilder& b); +Value staticQubitsWithInv(QIRProgramBuilder& b); /// Allocates duplicate static qubits and applies operations on both. -std::pair staticQubitsWithDuplicates(QIRProgramBuilder& b); +Value staticQubitsWithDuplicates(QIRProgramBuilder& b); /// Same as `staticQubitsWithDuplicates`, but with canonical static qubit /// retrievals. -std::pair staticQubitsCanonical(QIRProgramBuilder& b); +Value staticQubitsCanonical(QIRProgramBuilder& b); // --- Invalid / mixed addressing (unit tests) -------------------------------- /// @pre `builder.initialize()`. Fatal mixed addressing: static then dynamic /// alloc. -std::pair mixedStaticThenDynamicQubit(QIRProgramBuilder& b); +Value mixedStaticThenDynamicQubit(QIRProgramBuilder& b); /// @pre `builder.initialize()`. Fatal mixed addressing: dynamic register then /// static. -std::pair -mixedDynamicRegisterThenStaticQubit(QIRProgramBuilder& b); +Value mixedDynamicRegisterThenStaticQubit(QIRProgramBuilder& b); // --- MeasureOp ------------------------------------------------------------ // /// Measures a single qubit into a single classical bit. template -std::pair singleMeasurementToSingleBit(QIRProgramBuilder& b); +Value singleMeasurementToSingleBit(QIRProgramBuilder& b); /// Repeatedly measures a single qubit into the same classical bit. template -std::pair repeatedMeasurementToSameBit(QIRProgramBuilder& b); +Value repeatedMeasurementToSameBit(QIRProgramBuilder& b); /// Repeatedly measures a single qubit into different classical bits. template -std::pair repeatedMeasurementToDifferentBits(QIRProgramBuilder& b); +Value repeatedMeasurementToDifferentBits(QIRProgramBuilder& b); /// Measures multiple qubits into multiple classical bits. template -std::pair -multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b); +Value multipleClassicalRegistersAndMeasurements(QIRProgramBuilder& b); /// Measures a single qubit into a single classical bit, without explicitly /// allocating a quantum or classical register. template -std::pair measurementWithoutRegisters(QIRProgramBuilder& b); +Value measurementWithoutRegisters(QIRProgramBuilder& b); // --- ResetOp -------------------------------------------------------------- // /// Resets a single qubit without any operations being applied. template -std::pair resetQubitWithoutOp(QIRProgramBuilder& b); +Value resetQubitWithoutOp(QIRProgramBuilder& b); /// Resets multiple qubits without any operations being applied. template -std::pair resetMultipleQubitsWithoutOp(QIRProgramBuilder& b); +Value resetMultipleQubitsWithoutOp(QIRProgramBuilder& b); /// Repeatedly resets a single qubit without any operations being applied. template -std::pair repeatedResetWithoutOp(QIRProgramBuilder& b); +Value repeatedResetWithoutOp(QIRProgramBuilder& b); /// Resets a single qubit after a single operation. template -std::pair resetQubitAfterSingleOp(QIRProgramBuilder& b); +Value resetQubitAfterSingleOp(QIRProgramBuilder& b); /// Resets multiple qubits after a single operation. template -std::pair resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b); +Value resetMultipleQubitsAfterSingleOp(QIRProgramBuilder& b); /// Repeatedly resets a single qubit after a single operation. template -std::pair repeatedResetAfterSingleOp(QIRProgramBuilder& b); +Value repeatedResetAfterSingleOp(QIRProgramBuilder& b); // --- GPhaseOp ------------------------------------------------------------- // /// Creates a circuit with just a global phase. -template -std::pair globalPhase(QIRProgramBuilder& b); +template Value globalPhase(QIRProgramBuilder& b); // --- IdOp ----------------------------------------------------------------- // /// Creates a circuit with just an identity gate. -template -std::pair identity(QIRProgramBuilder& b); +template Value identity(QIRProgramBuilder& b); /// Creates a controlled identity gate with a single control qubit. template -std::pair singleControlledIdentity(QIRProgramBuilder& b); +Value singleControlledIdentity(QIRProgramBuilder& b); /// Creates an identity gate on a single qubit in a two-qubit register. template -std::pair twoQubitsOneIdentity(QIRProgramBuilder& b); +Value twoQubitsOneIdentity(QIRProgramBuilder& b); /// Creates an identity gate on a single qubit in a three-qubit register. template -std::pair threeQubitsOneIdentity(QIRProgramBuilder& b); +Value threeQubitsOneIdentity(QIRProgramBuilder& b); /// Creates a multi-controlled identity gate with multiple control qubits. template -std::pair multipleControlledIdentity(QIRProgramBuilder& b); +Value multipleControlledIdentity(QIRProgramBuilder& b); // --- XOp ------------------------------------------------------------------ // /// Creates a circuit with just an X gate. -template -std::pair x(QIRProgramBuilder& b); +template Value x(QIRProgramBuilder& b); /// Creates a circuit with a single controlled X gate. template -std::pair singleControlledX(QIRProgramBuilder& b); +Value singleControlledX(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled X gate. template -std::pair multipleControlledX(QIRProgramBuilder& b); +Value multipleControlledX(QIRProgramBuilder& b); // --- YOp ------------------------------------------------------------------ // /// Creates a circuit with just a Y gate. -template -std::pair y(QIRProgramBuilder& b); +template Value y(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Y gate. template -std::pair singleControlledY(QIRProgramBuilder& b); +Value singleControlledY(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Y gate. template -std::pair multipleControlledY(QIRProgramBuilder& b); +Value multipleControlledY(QIRProgramBuilder& b); // --- ZOp ------------------------------------------------------------------ // /// Creates a circuit with just a Z gate. -template -std::pair z(QIRProgramBuilder& b); +template Value z(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Z gate. template -std::pair singleControlledZ(QIRProgramBuilder& b); +Value singleControlledZ(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Z gate. template -std::pair multipleControlledZ(QIRProgramBuilder& b); +Value multipleControlledZ(QIRProgramBuilder& b); // --- HOp ------------------------------------------------------------------ // /// Creates a circuit with just an H gate. -template -std::pair h(QIRProgramBuilder& b); +template Value h(QIRProgramBuilder& b); /// Creates a circuit with a single controlled H gate. template -std::pair singleControlledH(QIRProgramBuilder& b); +Value singleControlledH(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled H gate. template -std::pair multipleControlledH(QIRProgramBuilder& b); +Value multipleControlledH(QIRProgramBuilder& b); /// Creates a circuit with just an H gate and no qubit register. template -std::pair hWithoutRegister(QIRProgramBuilder& b); +Value hWithoutRegister(QIRProgramBuilder& b); // --- SOp ------------------------------------------------------------------ // /// Creates a circuit with just an S gate. -template -std::pair s(QIRProgramBuilder& b); +template Value s(QIRProgramBuilder& b); /// Creates a circuit with a single controlled S gate. template -std::pair singleControlledS(QIRProgramBuilder& b); +Value singleControlledS(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled S gate. template -std::pair multipleControlledS(QIRProgramBuilder& b); +Value multipleControlledS(QIRProgramBuilder& b); // --- SdgOp ---------------------------------------------------------------- // /// Creates a circuit with just an Sdg gate. -template -std::pair sdg(QIRProgramBuilder& b); +template Value sdg(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Sdg gate. template -std::pair singleControlledSdg(QIRProgramBuilder& b); +Value singleControlledSdg(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Sdg gate. template -std::pair multipleControlledSdg(QIRProgramBuilder& b); +Value multipleControlledSdg(QIRProgramBuilder& b); // --- TOp ------------------------------------------------------------------ // /// Creates a circuit with just a T gate. template -std::pair t_(QIRProgramBuilder& b); // NOLINT(*-identifier-naming) +Value t_(QIRProgramBuilder& b); // NOLINT(*-identifier-naming) /// Creates a circuit with a single controlled T gate. template -std::pair singleControlledT(QIRProgramBuilder& b); +Value singleControlledT(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled T gate. template -std::pair multipleControlledT(QIRProgramBuilder& b); +Value multipleControlledT(QIRProgramBuilder& b); // --- TdgOp ---------------------------------------------------------------- // /// Creates a circuit with just a Tdg gate. -template -std::pair tdg(QIRProgramBuilder& b); +template Value tdg(QIRProgramBuilder& b); /// Creates a circuit with a single controlled Tdg gate. template -std::pair singleControlledTdg(QIRProgramBuilder& b); +Value singleControlledTdg(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled Tdg gate. template -std::pair multipleControlledTdg(QIRProgramBuilder& b); +Value multipleControlledTdg(QIRProgramBuilder& b); // --- SXOp ----------------------------------------------------------------- // /// Creates a circuit with just an SX gate. -template -std::pair sx(QIRProgramBuilder& b); +template Value sx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled SX gate. template -std::pair singleControlledSx(QIRProgramBuilder& b); +Value singleControlledSx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled SX gate. template -std::pair multipleControlledSx(QIRProgramBuilder& b); +Value multipleControlledSx(QIRProgramBuilder& b); // --- SXdgOp --------------------------------------------------------------- // /// Creates a circuit with just an SXdg gate. -template -std::pair sxdg(QIRProgramBuilder& b); +template Value sxdg(QIRProgramBuilder& b); /// Creates a circuit with a single controlled SXdg gate. template -std::pair singleControlledSxdg(QIRProgramBuilder& b); +Value singleControlledSxdg(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled SXdg gate. template -std::pair multipleControlledSxdg(QIRProgramBuilder& b); +Value multipleControlledSxdg(QIRProgramBuilder& b); // --- RXOp ----------------------------------------------------------------- // /// Creates a circuit with just an RX gate. -template -std::pair rx(QIRProgramBuilder& b); +template Value rx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RX gate. template -std::pair singleControlledRx(QIRProgramBuilder& b); +Value singleControlledRx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RX gate. template -std::pair multipleControlledRx(QIRProgramBuilder& b); +Value multipleControlledRx(QIRProgramBuilder& b); // --- RYOp ----------------------------------------------------------------- // /// Creates a circuit with just an RY gate. -template -std::pair ry(QIRProgramBuilder& b); +template Value ry(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RY gate. template -std::pair singleControlledRy(QIRProgramBuilder& b); +Value singleControlledRy(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RY gate. template -std::pair multipleControlledRy(QIRProgramBuilder& b); +Value multipleControlledRy(QIRProgramBuilder& b); // --- RZOp ----------------------------------------------------------------- // /// Creates a circuit with just an RZ gate. -template -std::pair rz(QIRProgramBuilder& b); +template Value rz(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RZ gate. template -std::pair singleControlledRz(QIRProgramBuilder& b); +Value singleControlledRz(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RZ gate. template -std::pair multipleControlledRz(QIRProgramBuilder& b); +Value multipleControlledRz(QIRProgramBuilder& b); // --- POp ------------------------------------------------------------------ // /// Creates a circuit with just a P gate. -template -std::pair p(QIRProgramBuilder& b); +template Value p(QIRProgramBuilder& b); /// Creates a circuit with a single controlled P gate. template -std::pair singleControlledP(QIRProgramBuilder& b); +Value singleControlledP(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled P gate. template -std::pair multipleControlledP(QIRProgramBuilder& b); +Value multipleControlledP(QIRProgramBuilder& b); // --- ROp ------------------------------------------------------------------ // /// Creates a circuit with just an R gate. -template -std::pair r(QIRProgramBuilder& b); +template Value r(QIRProgramBuilder& b); /// Creates a circuit with a single controlled R gate. template -std::pair singleControlledR(QIRProgramBuilder& b); +Value singleControlledR(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled R gate. template -std::pair multipleControlledR(QIRProgramBuilder& b); +Value multipleControlledR(QIRProgramBuilder& b); // --- U2Op ----------------------------------------------------------------- // /// Creates a circuit with just a U2 gate. -template -std::pair u2(QIRProgramBuilder& b); +template Value u2(QIRProgramBuilder& b); /// Creates a circuit with a single controlled U2 gate. template -std::pair singleControlledU2(QIRProgramBuilder& b); +Value singleControlledU2(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled U2 gate. template -std::pair multipleControlledU2(QIRProgramBuilder& b); +Value multipleControlledU2(QIRProgramBuilder& b); // --- UOp ------------------------------------------------------------------ // /// Creates a circuit with just a U gate. -template -std::pair u(QIRProgramBuilder& b); +template Value u(QIRProgramBuilder& b); /// Creates a circuit with a single controlled U gate. template -std::pair singleControlledU(QIRProgramBuilder& b); +Value singleControlledU(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled U gate. template -std::pair multipleControlledU(QIRProgramBuilder& b); +Value multipleControlledU(QIRProgramBuilder& b); // --- SWAPOp --------------------------------------------------------------- // /// Creates a circuit with just a SWAP gate. -template -std::pair swap(QIRProgramBuilder& b); +template Value swap(QIRProgramBuilder& b); /// Creates a circuit with a single controlled SWAP gate. template -std::pair singleControlledSwap(QIRProgramBuilder& b); +Value singleControlledSwap(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled SWAP gate. template -std::pair multipleControlledSwap(QIRProgramBuilder& b); +Value multipleControlledSwap(QIRProgramBuilder& b); // --- iSWAPOp -------------------------------------------------------------- // /// Creates a circuit with just an iSWAP gate. -template -std::pair iswap(QIRProgramBuilder& b); +template Value iswap(QIRProgramBuilder& b); /// Creates a circuit with a single controlled iSWAP gate. template -std::pair singleControlledIswap(QIRProgramBuilder& b); +Value singleControlledIswap(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled iSWAP gate. template -std::pair multipleControlledIswap(QIRProgramBuilder& b); +Value multipleControlledIswap(QIRProgramBuilder& b); // --- DCXOp ---------------------------------------------------------------- // /// Creates a circuit with just a DCX gate. -template -std::pair dcx(QIRProgramBuilder& b); +template Value dcx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled DCX gate. template -std::pair singleControlledDcx(QIRProgramBuilder& b); +Value singleControlledDcx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled DCX gate. template -std::pair multipleControlledDcx(QIRProgramBuilder& b); +Value multipleControlledDcx(QIRProgramBuilder& b); // --- ECROp ---------------------------------------------------------------- // /// Creates a circuit with just an ECR gate. -template -std::pair ecr(QIRProgramBuilder& b); +template Value ecr(QIRProgramBuilder& b); /// Creates a circuit with a single controlled ECR gate. template -std::pair singleControlledEcr(QIRProgramBuilder& b); +Value singleControlledEcr(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled ECR gate. template -std::pair multipleControlledEcr(QIRProgramBuilder& b); +Value multipleControlledEcr(QIRProgramBuilder& b); // --- RXXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RXX gate. -template -std::pair rxx(QIRProgramBuilder& b); +template Value rxx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RXX gate. template -std::pair singleControlledRxx(QIRProgramBuilder& b); +Value singleControlledRxx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RXX gate. template -std::pair multipleControlledRxx(QIRProgramBuilder& b); +Value multipleControlledRxx(QIRProgramBuilder& b); /// Creates a circuit with a triple-controlled RXX gate. template -std::pair tripleControlledRxx(QIRProgramBuilder& b); +Value tripleControlledRxx(QIRProgramBuilder& b); // --- RYYOp ---------------------------------------------------------------- // /// Creates a circuit with just an RYY gate. -template -std::pair ryy(QIRProgramBuilder& b); +template Value ryy(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RYY gate. template -std::pair singleControlledRyy(QIRProgramBuilder& b); +Value singleControlledRyy(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RYY gate. template -std::pair multipleControlledRyy(QIRProgramBuilder& b); +Value multipleControlledRyy(QIRProgramBuilder& b); // --- RZXOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZX gate. -template -std::pair rzx(QIRProgramBuilder& b); +template Value rzx(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RZX gate. template -std::pair singleControlledRzx(QIRProgramBuilder& b); +Value singleControlledRzx(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RZX gate. template -std::pair multipleControlledRzx(QIRProgramBuilder& b); +Value multipleControlledRzx(QIRProgramBuilder& b); // --- RZZOp ---------------------------------------------------------------- // /// Creates a circuit with just an RZZ gate. -template -std::pair rzz(QIRProgramBuilder& b); +template Value rzz(QIRProgramBuilder& b); /// Creates a circuit with a single controlled RZZ gate. template -std::pair singleControlledRzz(QIRProgramBuilder& b); +Value singleControlledRzz(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled RZZ gate. template -std::pair multipleControlledRzz(QIRProgramBuilder& b); +Value multipleControlledRzz(QIRProgramBuilder& b); // --- XXPlusYYOp ----------------------------------------------------------- // /// Creates a circuit with just an XXPlusYY gate. -template -std::pair xxPlusYY(QIRProgramBuilder& b); +template Value xxPlusYY(QIRProgramBuilder& b); /// Creates a circuit with a single controlled XXPlusYY gate. template -std::pair singleControlledXxPlusYY(QIRProgramBuilder& b); +Value singleControlledXxPlusYY(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled XXPlusYY gate. template -std::pair multipleControlledXxPlusYY(QIRProgramBuilder& b); +Value multipleControlledXxPlusYY(QIRProgramBuilder& b); // --- XXMinusYYOp ---------------------------------------------------------- // /// Creates a circuit with just an XXMinusYY gate. -template -std::pair xxMinusYY(QIRProgramBuilder& b); +template Value xxMinusYY(QIRProgramBuilder& b); /// Creates a circuit with a single controlled XXMinusYY gate. template -std::pair singleControlledXxMinusYY(QIRProgramBuilder& b); +Value singleControlledXxMinusYY(QIRProgramBuilder& b); /// Creates a circuit with a multi-controlled XXMinusYY gate. template -std::pair multipleControlledXxMinusYY(QIRProgramBuilder& b); +Value multipleControlledXxMinusYY(QIRProgramBuilder& b); // --- IfOp ----------------------------------------------------------------- // /// Creates a circuit with a simple if operation with one qubit. -template -std::pair simpleIf(QIRProgramBuilder& b); +template Value simpleIf(QIRProgramBuilder& b); /// Creates a circuit with an if operation with an else branch. -template -std::pair ifElse(QIRProgramBuilder& b); +template Value ifElse(QIRProgramBuilder& b); /// Creates a circuit with an if operation with two qubits. -template -std::pair ifTwoQubits(QIRProgramBuilder& b); +template Value ifTwoQubits(QIRProgramBuilder& b); /// Creates a circuit with an if operation with a nested for operation with /// a register. template -std::pair nestedIfOpForLoop(QIRProgramBuilder& b); +Value nestedIfOpForLoop(QIRProgramBuilder& b); // --- WhileOp -------------------------------------------------------------- // /// Creates a circuit with a while operation using a while loop. template -std::pair simpleWhileReset(QIRProgramBuilder& b); +Value simpleWhileReset(QIRProgramBuilder& b); /// Creates a circuit with a while operation using a do-while loop. template -std::pair simpleDoWhileReset(QIRProgramBuilder& b); +Value simpleDoWhileReset(QIRProgramBuilder& b); // --- ForOp ---------------------------------------------------------------- // /// Creates a circuit with a simple for operation with a register. -template -std::pair simpleForLoop(QIRProgramBuilder& b); +template Value simpleForLoop(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested if operation. template -std::pair nestedForLoopIfOp(QIRProgramBuilder& b); +Value nestedForLoopIfOp(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a nested while /// operation. template -std::pair nestedForLoopWhileOp(QIRProgramBuilder& b); +Value nestedForLoopWhileOp(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is separately allocated from the /// register. template -std::pair -nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b); +Value nestedForLoopCtrlOpWithSeparateQubit(QIRProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is extracted from the register. template -std::pair -nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b); +Value nestedForLoopCtrlOpWithExtractedQubit(QIRProgramBuilder& b); // --- CtrlOp --------------------------------------------------------------- // /// Creates a circuit with a control modifier applied to two gates. -template -std::pair ctrlTwo(QIRProgramBuilder& b); +template Value ctrlTwo(QIRProgramBuilder& b); } // namespace mlir::qir From 01399268434d80f2c8c9ea5a0af614206c75d702 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Fri, 10 Jul 2026 02:01:52 +0200 Subject: [PATCH 73/80] :children_crossing: Enable shortcut for single-return programs Signed-off-by: burgholzer --- .../Dialect/QC/Builder/QCProgramBuilder.h | 12 + .../Dialect/QCO/Builder/QCOProgramBuilder.h | 12 + .../Dialect/QC/Builder/QCProgramBuilder.cpp | 10 + .../Dialect/QCO/Builder/QCOProgramBuilder.cpp | 10 + .../Compiler/test_compiler_pipeline.cpp | 24 +- .../JeffRoundTrip/test_jeff_round_trip.cpp | 10 +- .../Conversion/QCOToQC/test_qco_to_qc.cpp | 10 +- .../Conversion/QCToQCO/test_qc_to_qco.cpp | 9 +- .../test_qc_to_qir_adaptive.cpp | 10 +- .../QCToQIRBase/test_qc_to_qir_base.cpp | 11 +- mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp | 8 +- .../QC/Translation/test_qasm3_translation.cpp | 9 +- .../test_quantum_computation_translation.cpp | 7 +- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 14 +- .../Dialect/QCO/IR/test_qco_ir_matrix.cpp | 4 +- mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp | 12 +- .../Dialect/QTensor/IR/test_qtensor_ir.cpp | 25 +- mlir/unittests/TestCaseUtils.h | 57 +- mlir/unittests/programs/qc_programs.cpp | 326 +++--- mlir/unittests/programs/qc_programs.h | 164 +-- mlir/unittests/programs/qco_programs.cpp | 987 +++++++++--------- mlir/unittests/programs/qco_programs.h | 260 ++--- 22 files changed, 1041 insertions(+), 950 deletions(-) diff --git a/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h b/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h index cbcee93fd4..dee7248db0 100644 --- a/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h @@ -1195,6 +1195,18 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder { build(MLIRContext* context, const function_ref(QCProgramBuilder&)>& buildFunc); + /** + * @brief Convenience method for building quantum programs with one return + * value. + * @param context The MLIR context to use for building the program + * @param buildFunc A function that takes a reference to a QCProgramBuilder + * and returns the single result value of the desired quantum program. + * @return The module containing the quantum program built by buildFunc. + */ + static OwningOpRef + build(MLIRContext* context, + const function_ref& buildFunc); + private: enum class AllocationMode : uint8_t { Unset, Static, Dynamic }; diff --git a/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h b/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h index a9ba23b0da..d88e12dfa7 100644 --- a/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h +++ b/mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h @@ -1503,6 +1503,18 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder { build(MLIRContext* context, const function_ref(QCOProgramBuilder&)>& buildFunc); + /** + * @brief Convenience method for building quantum programs with one return + * value. + * @param context The MLIR context to use for building the program + * @param buildFunc A function that takes a reference to a QCOProgramBuilder + * and returns the single result value of the desired quantum program. + * @return The module containing the quantum program built by buildFunc. + */ + static OwningOpRef + build(MLIRContext* context, + const function_ref& buildFunc); + private: enum class AllocationMode : uint8_t { Unset, Static, Dynamic }; diff --git a/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp b/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp index 0b6b93b1cd..183e1fb7c4 100644 --- a/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp +++ b/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp @@ -722,4 +722,14 @@ OwningOpRef QCProgramBuilder::build( return builder.finalize(result); } +OwningOpRef QCProgramBuilder::build( + MLIRContext* context, + const function_ref& buildFunc) { + QCProgramBuilder builder(context); + builder.initialize(); + auto result = buildFunc(builder); + builder.retype(result.getType()); + return builder.finalize(result); +} + } // namespace mlir::qc diff --git a/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp b/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp index f3feb41a37..f766602a24 100644 --- a/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp +++ b/mlir/lib/Dialect/QCO/Builder/QCOProgramBuilder.cpp @@ -1233,4 +1233,14 @@ OwningOpRef QCOProgramBuilder::build( return builder.finalize(result); } +OwningOpRef QCOProgramBuilder::build( + MLIRContext* context, + const function_ref& buildFunc) { + QCOProgramBuilder builder(context); + builder.initialize(); + auto result = buildFunc(builder); + builder.retype(result.getType()); + return builder.finalize(result); +} + } // namespace mlir::qco diff --git a/mlir/unittests/Compiler/test_compiler_pipeline.cpp b/mlir/unittests/Compiler/test_compiler_pipeline.cpp index 8d59129b14..01aff2798f 100644 --- a/mlir/unittests/Compiler/test_compiler_pipeline.cpp +++ b/mlir/unittests/Compiler/test_compiler_pipeline.cpp @@ -52,8 +52,8 @@ using namespace mlir::qc; using namespace mlir::qco; using namespace mlir::qir; -using QCProgramBuilderFn = MultiResultBuilder; -using QIRProgramBuilderFn = SingleResultBuilder; +using QCProgramBuilderFn = NamedMLIRBuilder; +using QIRProgramBuilderFn = NamedMLIRBuilder; using QuantumComputationBuilderFn = NamedBuilder<::qc::QuantumComputation>; namespace { @@ -105,15 +105,15 @@ class CompilerPipelineTest [[nodiscard]] OwningOpRef buildQCReference(const QCProgramBuilderFn builder) const { - auto module = QCProgramBuilder::build(context.get(), builder.fn); + auto module = mqt::test::buildMLIRProgram(context.get(), builder); EXPECT_TRUE(runQCCleanupPipeline(module.get()).succeeded()); return module; } [[nodiscard]] OwningOpRef buildQIRReference(const QIRProgramBuilderFn builder) const { - auto module = QIRProgramBuilder::build( - context.get(), builder.fn, QIRProgramBuilder::Profile::Adaptive); + auto module = mqt::test::buildMLIRProgram( + context.get(), builder, QIRProgramBuilder::Profile::Adaptive); EXPECT_TRUE(runQIRCleanupPipeline(module.get(), true).succeeded()); return module; } @@ -168,7 +168,7 @@ TEST_P(CompilerPipelineTest, EndToEndPipeline) { } else { ASSERT_TRUE(testCase.qcProgramBuilder); module = - QCProgramBuilder::build(context.get(), testCase.qcProgramBuilder.fn); + mqt::test::buildMLIRProgram(context.get(), testCase.qcProgramBuilder); ASSERT_TRUE(module); printer.record(module.get(), "QC Input" + name); } @@ -213,12 +213,12 @@ TEST_P(CompilerPipelineTest, EndToEndPipeline) { * Correctness of the pass is tested in a dedicated test. */ TEST_F(CompilerPipelineTest, RotationGateMergingPass) { - auto module = QCProgramBuilder::build( - context.get(), [&](QCProgramBuilder& b) -> SmallVector { + auto module = + QCProgramBuilder::build(context.get(), [&](QCProgramBuilder& b) { auto q = b.allocQubit(); b.rz(1.0, q); b.rx(1.0, q); - return {b.measure(q)}; + return b.measure(q); }); ASSERT_TRUE(module); @@ -237,12 +237,12 @@ TEST_F(CompilerPipelineTest, RotationGateMergingPass) { * Correctness of the pass is tested in a dedicated test. */ TEST_F(CompilerPipelineTest, HadamardLiftingPass) { - auto module = QCProgramBuilder::build( - context.get(), [&](QCProgramBuilder& b) -> SmallVector { + auto module = + QCProgramBuilder::build(context.get(), [&](QCProgramBuilder& b) { auto q = b.allocQubit(); b.x(q); b.h(q); - return {b.measure(q)}; + return b.measure(q); }); ASSERT_TRUE(module); diff --git a/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp b/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp index bf69e61817..e0eba98200 100644 --- a/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp +++ b/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp @@ -45,8 +45,8 @@ namespace { struct JeffRoundTripTestCase { std::string name; - mqt::test::MultiResultBuilder programBuilder; - mqt::test::MultiResultBuilder referenceBuilder; + mqt::test::NamedMLIRBuilder programBuilder; + mqt::test::NamedMLIRBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const JeffRoundTripTestCase& info); @@ -94,8 +94,7 @@ TEST_P(JeffRoundTripTest, ProgramEquivalence) { const auto name = " (" + nameStr + ")"; mqt::test::DeferredPrinter printer; - auto program = - qco::QCOProgramBuilder::build(context.get(), programBuilder.fn); + auto program = mqt::test::buildMLIRProgram(context.get(), programBuilder); ASSERT_TRUE(program); printer.record(program.get(), "Original QCO IR" + name); EXPECT_TRUE(verify(*program).succeeded()); @@ -129,8 +128,7 @@ TEST_P(JeffRoundTripTest, ProgramEquivalence) { printer.record(program.get(), "Canonicalized Converted QCO IR" + name); EXPECT_TRUE(verify(*program).succeeded()); - auto reference = - qco::QCOProgramBuilder::build(context.get(), referenceBuilder.fn); + auto reference = mqt::test::buildMLIRProgram(context.get(), referenceBuilder); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QCO IR" + name); EXPECT_TRUE(verify(*reference).succeeded()); diff --git a/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp b/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp index f52fcfb18a..7bd7389f7e 100644 --- a/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp +++ b/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp @@ -44,8 +44,8 @@ namespace { struct QCOToQCTestCase { std::string name; - mqt::test::MultiResultBuilder programBuilder; - mqt::test::MultiResultBuilder referenceBuilder; + mqt::test::NamedMLIRBuilder programBuilder; + mqt::test::NamedMLIRBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCOToQCTestCase& info); @@ -88,8 +88,7 @@ TEST_P(QCOToQCTest, ProgramEquivalence) { const auto name = " (" + nameStr + ")"; mqt::test::DeferredPrinter printer; - auto program = - qco::QCOProgramBuilder::build(context.get(), programBuilder.fn); + auto program = mqt::test::buildMLIRProgram(context.get(), programBuilder); ASSERT_TRUE(program); printer.record(program.get(), "Original QCO IR" + name); EXPECT_TRUE(verify(*program).succeeded()); @@ -106,8 +105,7 @@ TEST_P(QCOToQCTest, ProgramEquivalence) { printer.record(program.get(), "Canonicalized Converted QC IR" + name); EXPECT_TRUE(verify(*program).succeeded()); - auto reference = - qc::QCProgramBuilder::build(context.get(), referenceBuilder.fn); + auto reference = mqt::test::buildMLIRProgram(context.get(), referenceBuilder); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QC IR" + name); EXPECT_TRUE(verify(*reference).succeeded()); diff --git a/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp b/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp index d62cb08c4e..ed77f90963 100644 --- a/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp +++ b/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp @@ -44,8 +44,8 @@ namespace { struct QCToQCOTestCase { std::string name; - mqt::test::MultiResultBuilder programBuilder; - mqt::test::MultiResultBuilder referenceBuilder; + mqt::test::NamedMLIRBuilder programBuilder; + mqt::test::NamedMLIRBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCToQCOTestCase& info); @@ -88,7 +88,7 @@ TEST_P(QCToQCOTest, ProgramEquivalence) { const auto name = " (" + GetParam().name + ")"; mqt::test::DeferredPrinter printer; - auto program = qc::QCProgramBuilder::build(context.get(), programBuilder.fn); + auto program = mqt::test::buildMLIRProgram(context.get(), programBuilder); ASSERT_TRUE(program); printer.record(program.get(), "Original QC IR" + name); EXPECT_TRUE(verify(*program).succeeded()); @@ -105,8 +105,7 @@ TEST_P(QCToQCOTest, ProgramEquivalence) { printer.record(program.get(), "Canonicalized Converted QCO IR" + name); EXPECT_TRUE(verify(*program).succeeded()); - auto reference = - qco::QCOProgramBuilder::build(context.get(), referenceBuilder.fn); + auto reference = mqt::test::buildMLIRProgram(context.get(), referenceBuilder); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QCO IR" + name); EXPECT_TRUE(verify(*reference).succeeded()); diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp index 44deddb42c..df69c21e95 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp @@ -45,8 +45,8 @@ namespace { struct QCToQIRAdaptiveTestCase { std::string name; - mqt::test::MultiResultBuilder programBuilder; - mqt::test::SingleResultBuilder referenceBuilder; + mqt::test::NamedMLIRBuilder programBuilder; + mqt::test::NamedMLIRBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCToQIRAdaptiveTestCase& info); @@ -90,7 +90,7 @@ TEST_P(QCToQIRAdaptiveTest, ProgramEquivalence) { const auto name = " (" + GetParam().name + ")"; mqt::test::DeferredPrinter printer; - auto program = qc::QCProgramBuilder::build(context.get(), programBuilder.fn); + auto program = mqt::test::buildMLIRProgram(context.get(), programBuilder); ASSERT_TRUE(program); printer.record(program.get(), "Original QC IR" + name); EXPECT_TRUE(verify(*program).succeeded()); @@ -108,8 +108,8 @@ TEST_P(QCToQIRAdaptiveTest, ProgramEquivalence) { EXPECT_TRUE(verify(*program).succeeded()); auto reference = - qir::QIRProgramBuilder::build(context.get(), referenceBuilder.fn, - qir::QIRProgramBuilder::Profile::Adaptive); + mqt::test::buildMLIRProgram(context.get(), referenceBuilder, + qir::QIRProgramBuilder::Profile::Adaptive); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QIR IR" + name); EXPECT_TRUE(verify(*reference).succeeded()); diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp index ee51f68037..0a3872eb13 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp @@ -45,8 +45,8 @@ namespace { struct QCToQIRBaseTestCase { std::string name; - mqt::test::MultiResultBuilder programBuilder; - mqt::test::SingleResultBuilder referenceBuilder; + mqt::test::NamedMLIRBuilder programBuilder; + mqt::test::NamedMLIRBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCToQIRBaseTestCase& info); @@ -88,7 +88,7 @@ TEST_P(QCToQIRBaseTest, ProgramEquivalence) { const auto name = " (" + GetParam().name + ")"; mqt::test::DeferredPrinter printer; - auto program = qc::QCProgramBuilder::build(context.get(), programBuilder.fn); + auto program = mqt::test::buildMLIRProgram(context.get(), programBuilder); ASSERT_TRUE(program); printer.record(program.get(), "Original QC IR" + name); EXPECT_TRUE(verify(*program).succeeded()); @@ -105,9 +105,8 @@ TEST_P(QCToQIRBaseTest, ProgramEquivalence) { printer.record(program.get(), "Canonicalized Converted QIR IR" + name); EXPECT_TRUE(verify(*program).succeeded()); - auto reference = - qir::QIRProgramBuilder::build(context.get(), referenceBuilder.fn, - qir::QIRProgramBuilder::Profile::Base); + auto reference = mqt::test::buildMLIRProgram( + context.get(), referenceBuilder, qir::QIRProgramBuilder::Profile::Base); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QIR IR" + name); EXPECT_TRUE(verify(*reference).succeeded()); diff --git a/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp b/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp index 77569a69d8..d6c8d44d4f 100644 --- a/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp +++ b/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp @@ -38,8 +38,8 @@ namespace { struct QCTestCase { std::string name; - mqt::test::MultiResultBuilder programBuilder; - mqt::test::MultiResultBuilder referenceBuilder; + mqt::test::NamedMLIRBuilder programBuilder; + mqt::test::NamedMLIRBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCTestCase& info); }; @@ -76,7 +76,7 @@ TEST_P(QCTest, ProgramEquivalence) { const auto name = " (" + GetParam().name + ")"; mqt::test::DeferredPrinter printer; - auto program = QCProgramBuilder::build(context.get(), programBuilder.fn); + auto program = mqt::test::buildMLIRProgram(context.get(), programBuilder); ASSERT_TRUE(program); printer.record(program.get(), "Original QC IR" + name); EXPECT_TRUE(verify(*program).succeeded()); @@ -85,7 +85,7 @@ TEST_P(QCTest, ProgramEquivalence) { printer.record(program.get(), "Canonicalized QC IR" + name); EXPECT_TRUE(verify(*program).succeeded()); - auto reference = QCProgramBuilder::build(context.get(), referenceBuilder.fn); + auto reference = mqt::test::buildMLIRProgram(context.get(), referenceBuilder); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QC IR" + name); EXPECT_TRUE(verify(*reference).succeeded()); diff --git a/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp b/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp index 2ecb199495..0296111684 100644 --- a/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp +++ b/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp @@ -40,7 +40,7 @@ namespace { struct QASM3TranslationTestCase { std::string name; std::string source; - mqt::test::MultiResultBuilder referenceBuilder; + mqt::test::NamedMLIRBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QASM3TranslationTestCase& test); @@ -129,7 +129,7 @@ static SmallVector twoMixedControlledX(qc::QCProgramBuilder& b) { return {c0, c1, c2, c3, c4, c5}; } -static SmallVector ifNot(qc::QCProgramBuilder& b) { +static Value ifNot(qc::QCProgramBuilder& b) { auto trueValue = b.boolConstant(true); auto q = b.allocQubitRegister(1); b.h(q[0]); @@ -137,7 +137,7 @@ static SmallVector ifNot(qc::QCProgramBuilder& b) { auto cond = arith::XOrIOp::create(b, c, trueValue).getResult(); b.scfIf(cond, [&] { b.x(q[0]); }); auto out = b.measure(q[0]); - return {out}; + return out; } TEST_P(QASM3TranslationTest, ProgramEquivalence) { @@ -155,8 +155,7 @@ TEST_P(QASM3TranslationTest, ProgramEquivalence) { printer.record(translated.get(), "Canonicalized Translated QC IR" + name); EXPECT_TRUE(verify(*translated).succeeded()); - auto reference = - qc::QCProgramBuilder::build(context.get(), referenceBuilder.fn); + auto reference = mqt::test::buildMLIRProgram(context.get(), referenceBuilder); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QC IR" + name); EXPECT_TRUE(verify(*reference).succeeded()); diff --git a/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp b/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp index 128878283b..d3db4d7c54 100644 --- a/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp +++ b/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp @@ -39,9 +39,7 @@ namespace { struct QuantumComputationTranslationTestCase { std::string name; mqt::test::NamedBuilder<::qc::QuantumComputation> programBuilder; - mqt::test::NamedBuilder> - referenceBuilder; + mqt::test::NamedMLIRBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, @@ -92,8 +90,7 @@ TEST_P(QuantumComputationTranslationTest, ProgramEquivalence) { printer.record(translated.get(), "Canonicalized Translated QC IR" + name); EXPECT_TRUE(mlir::verify(*translated).succeeded()); - auto reference = - mlir::qc::QCProgramBuilder::build(context.get(), referenceBuilder.fn); + auto reference = mqt::test::buildMLIRProgram(context.get(), referenceBuilder); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QC IR" + name); EXPECT_TRUE(mlir::verify(*reference).succeeded()); diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 4f6a7cfeea..5d5bc939e2 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -41,8 +41,8 @@ namespace { struct QCOTestCase { std::string name; - mqt::test::MultiResultBuilder programBuilder; - mqt::test::MultiResultBuilder referenceBuilder; + mqt::test::NamedMLIRBuilder programBuilder; + mqt::test::NamedMLIRBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QCOTestCase& info); }; @@ -76,7 +76,7 @@ TEST_P(QCOTest, ProgramEquivalence) { const auto name = " (" + GetParam().name + ")"; mqt::test::DeferredPrinter printer; - auto program = QCOProgramBuilder::build(context.get(), programBuilder.fn); + auto program = mqt::test::buildMLIRProgram(context.get(), programBuilder); ASSERT_TRUE(program); printer.record(program.get(), "Original QCO IR" + name); EXPECT_TRUE(verify(*program).succeeded()); @@ -85,7 +85,7 @@ TEST_P(QCOTest, ProgramEquivalence) { printer.record(program.get(), "Canonicalized QCO IR" + name); EXPECT_TRUE(verify(*program).succeeded()); - auto reference = QCOProgramBuilder::build(context.get(), referenceBuilder.fn); + auto reference = mqt::test::buildMLIRProgram(context.get(), referenceBuilder); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QCO IR" + name); EXPECT_TRUE(verify(*reference).succeeded()); @@ -145,7 +145,7 @@ TEST_F(QCOTest, DirectIfBuilder) { EXPECT_TRUE(verify(*directBuilder).succeeded()); auto refBuilder = - QCOProgramBuilder::build(context.get(), MQT_NAMED_BUILDER(simpleIf).fn); + mqt::test::buildMLIRProgram(context.get(), MQT_NAMED_BUILDER(simpleIf)); ASSERT_TRUE(refBuilder); EXPECT_TRUE(verify(*refBuilder).succeeded()); EXPECT_TRUE(runQCOCleanupPipeline(refBuilder.get()).succeeded()); @@ -189,8 +189,8 @@ TEST_F(QCOTest, IfOpParser) { EXPECT_TRUE(runQCOCleanupPipeline(parsedSourceModule.get()).succeeded()); EXPECT_TRUE(verify(*parsedSourceModule).succeeded()); - auto refBuilder = QCOProgramBuilder::build( - context.get(), MQT_NAMED_BUILDER(ifOneQubitOneTensor).fn); + auto refBuilder = mqt::test::buildMLIRProgram( + context.get(), MQT_NAMED_BUILDER(ifOneQubitOneTensor)); ASSERT_TRUE(refBuilder); EXPECT_TRUE(verify(*refBuilder).succeeded()); EXPECT_TRUE(runQCOCleanupPipeline(refBuilder.get()).succeeded()); diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp index 92716e3919..49233d5e4e 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir_matrix.cpp @@ -105,8 +105,8 @@ namespace { struct QCOMatrixTestCase { std::string name; - mqt::test::MultiResultBuilder programBuilder; - mqt::test::MultiResultBuilder referenceBuilder; + mqt::test::NamedMLIRBuilder programBuilder; + mqt::test::NamedMLIRBuilder referenceBuilder; }; class QCOMatrixTest : public testing::TestWithParam { diff --git a/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp b/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp index a5f86f607e..e2a0c79dd4 100644 --- a/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp +++ b/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp @@ -35,8 +35,8 @@ namespace { struct QIRTestCase { std::string name; - mqt::test::SingleResultBuilder programBuilder; - mqt::test::SingleResultBuilder referenceBuilder; + mqt::test::NamedMLIRBuilder programBuilder; + mqt::test::NamedMLIRBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QIRTestCase& info); }; @@ -69,8 +69,8 @@ TEST_P(QIRTest, ProgramEquivalence) { const auto name = " (" + GetParam().name + ")"; mqt::test::DeferredPrinter printer; - auto program = QIRProgramBuilder::build(context.get(), programBuilder.fn, - QIRProgramBuilder::Profile::Adaptive); + auto program = mqt::test::buildMLIRProgram( + context.get(), programBuilder, QIRProgramBuilder::Profile::Adaptive); ASSERT_TRUE(program); printer.record(program.get(), "Original QIR IR" + name); EXPECT_TRUE(verify(*program).succeeded()); @@ -79,8 +79,8 @@ TEST_P(QIRTest, ProgramEquivalence) { printer.record(program.get(), "Canonicalized QIR IR" + name); EXPECT_TRUE(verify(*program).succeeded()); - auto reference = QIRProgramBuilder::build( - context.get(), referenceBuilder.fn, QIRProgramBuilder::Profile::Adaptive); + auto reference = mqt::test::buildMLIRProgram( + context.get(), referenceBuilder, QIRProgramBuilder::Profile::Adaptive); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QIR IR" + name); EXPECT_TRUE(verify(*reference).succeeded()); diff --git a/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp b/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp index 7282617469..a94ad944c0 100644 --- a/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp +++ b/mlir/unittests/Dialect/QTensor/IR/test_qtensor_ir.cpp @@ -66,9 +66,11 @@ class QTensorTest : public ::testing::Test { } /// Build a module using the QCOProgramBuilder and run the cleanup pipeline. - [[nodiscard]] OwningOpRef buildAndCanonicalize( - SmallVector (*buildFn)(QCOProgramBuilder&)) const { - auto module = QCOProgramBuilder::build(context.get(), buildFn); + template + [[nodiscard]] OwningOpRef + buildAndCanonicalize(BuildFn&& buildFn) const { + auto module = + QCOProgramBuilder::build(context.get(), std::forward(buildFn)); if (!module) { return {}; } @@ -193,11 +195,10 @@ TEST_F(QTensorTest, AllocOpStaticTypeWithDynamicSizeOperandFailsVerification) { /// An alloc immediately followed by dealloc should be eliminated entirely. TEST_F(QTensorTest, DeallocOpAllocDeallocPairIsRemoved) { - auto canonicalized = - buildAndCanonicalize([](QCOProgramBuilder& b) -> SmallVector { - b.qtensorAlloc(3); - return {b.intConstant(0)}; - }); + auto canonicalized = buildAndCanonicalize([](QCOProgramBuilder& b) { + b.qtensorAlloc(3); + return b.intConstant(0); + }); ASSERT_TRUE(canonicalized); EXPECT_TRUE(verify(*canonicalized).succeeded()); // Both AllocOp and DeallocOp should have been erased. @@ -423,8 +424,8 @@ TEST_F(QTensorTest, ResetAfterExtractThroughSameIndexInsertIsNotEliminated) { struct QTensorIntegrationTestCase { std::string name; - mqt::test::MultiResultBuilder programBuilder; - mqt::test::MultiResultBuilder referenceBuilder; + mqt::test::NamedMLIRBuilder programBuilder; + mqt::test::NamedMLIRBuilder referenceBuilder; friend std::ostream& operator<<(std::ostream& os, const QTensorIntegrationTestCase& info); @@ -456,7 +457,7 @@ TEST_P(QTensorIntegrationTest, ProgramEquivalence) { const auto name = " (" + GetParam().name + ")"; mqt::test::DeferredPrinter printer; - auto program = QCOProgramBuilder::build(context.get(), programBuilder.fn); + auto program = mqt::test::buildMLIRProgram(context.get(), programBuilder); ASSERT_TRUE(program); printer.record(program.get(), "Original QTensor IR" + name); EXPECT_TRUE(verify(*program).succeeded()); @@ -465,7 +466,7 @@ TEST_P(QTensorIntegrationTest, ProgramEquivalence) { printer.record(program.get(), "Canonicalized QTensor IR" + name); EXPECT_TRUE(verify(*program).succeeded()); - auto reference = QCOProgramBuilder::build(context.get(), referenceBuilder.fn); + auto reference = mqt::test::buildMLIRProgram(context.get(), referenceBuilder); ASSERT_TRUE(reference); printer.record(reference.get(), "Reference QTensor IR" + name); EXPECT_TRUE(verify(*reference).succeeded()); diff --git a/mlir/unittests/TestCaseUtils.h b/mlir/unittests/TestCaseUtils.h index dea345fa97..8492019899 100644 --- a/mlir/unittests/TestCaseUtils.h +++ b/mlir/unittests/TestCaseUtils.h @@ -18,12 +18,15 @@ #include #include #include +#include #include #include #include #include +#include #include +#include #include namespace mqt::test { @@ -49,12 +52,60 @@ namedBuilder(const char* name, RetT (*fn)(BuilderT&)) noexcept { return NamedBuilder{name, fn}; } +template struct NamedMLIRBuilder { + using SingleFn = mlir::Value (*)(BuilderT&); + using MultiFn = mlir::SmallVector (*)(BuilderT&); + + const char* name = nullptr; + std::variant fn; + + constexpr NamedMLIRBuilder(const char* nameIn, SingleFn fnIn) noexcept + : name(nameIn), fn(fnIn) {} + + constexpr NamedMLIRBuilder(const char* nameIn, MultiFn fnIn) noexcept + : name(nameIn), fn(fnIn) {} + + // NOLINTNEXTLINE(*-explicit-constructor) + constexpr NamedMLIRBuilder(std::nullptr_t) noexcept : fn(std::monostate{}) {} + + [[nodiscard]] constexpr explicit operator bool() const noexcept { + return !std::holds_alternative(fn); + } +}; + template -using MultiResultBuilder = - NamedBuilder>; +[[nodiscard]] constexpr NamedMLIRBuilder +namedBuilder(const char* name, mlir::Value (*fn)(BuilderT&)) noexcept { + return NamedMLIRBuilder{name, fn}; +} template -using SingleResultBuilder = NamedBuilder; +[[nodiscard]] constexpr NamedMLIRBuilder +namedBuilder(const char* name, + mlir::SmallVector (*fn)(BuilderT&)) noexcept { + return NamedMLIRBuilder{name, fn}; +} + +template +[[nodiscard]] mlir::OwningOpRef +buildMLIRProgram(mlir::MLIRContext* context, + const NamedMLIRBuilder& builder, Args&&... args) { + return std::visit( + [&](T fn) -> mlir::OwningOpRef { + using FnT = std::decay_t; + if constexpr (std::is_same_v) { + return {}; + } else if constexpr (requires { + BuilderT::build(context, fn, + std::forward(args)...); + }) { + return BuilderT::build(context, fn, std::forward(args)...); + } else { + return {}; + } + }, + builder.fn); +} [[nodiscard]] constexpr const char* displayName(const char* name) noexcept { return name != nullptr ? name : ""; diff --git a/mlir/unittests/programs/qc_programs.cpp b/mlir/unittests/programs/qc_programs.cpp index 14cf2bde9b..c54cc9c2d9 100644 --- a/mlir/unittests/programs/qc_programs.cpp +++ b/mlir/unittests/programs/qc_programs.cpp @@ -33,16 +33,16 @@ static SmallVector measureAndReturn(QCProgramBuilder& b, llvm::map_range(qubits, [&](Value q) { return b.measure(q); })); } -SmallVector emptyQC(QCProgramBuilder& b) { return {b.intConstant(0)}; } +Value emptyQC(QCProgramBuilder& b) { return b.intConstant(0); } -SmallVector allocQubit(QCProgramBuilder& b) { +Value allocQubit(QCProgramBuilder& b) { auto q = b.allocQubit(); - return measureAndReturn(b, {q}); + return b.measure(q); } -SmallVector allocQubitNoMeasure(QCProgramBuilder& b) { +Value allocQubitNoMeasure(QCProgramBuilder& b) { b.allocQubit(); - return {b.intConstant(0)}; + return b.intConstant(0); } SmallVector allocMultipleQubitRegistersWithOps(QCProgramBuilder& b) { @@ -56,9 +56,9 @@ SmallVector allocMultipleQubitRegistersWithOps(QCProgramBuilder& b) { return measureAndReturn(b, {q0[0], q0[1], q1[0], q1[1], q1[2]}); } -SmallVector alloc1QubitRegister(QCProgramBuilder& b) { +Value alloc1QubitRegister(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector allocQubitRegister(QCProgramBuilder& b) { @@ -88,10 +88,10 @@ SmallVector staticQubits(QCProgramBuilder& b) { return measureAndReturn(b, {q0, q1}); } -SmallVector staticQubitsNoMeasure(QCProgramBuilder& b) { +Value staticQubitsNoMeasure(QCProgramBuilder& b) { b.staticQubit(0); b.staticQubit(1); - return {b.intConstant(0)}; + return b.intConstant(0); } SmallVector staticQubitsWithOps(QCProgramBuilder& b) { @@ -124,10 +124,10 @@ SmallVector staticQubitsWithCtrl(QCProgramBuilder& b) { return measureAndReturn(b, {q0, q1}); } -SmallVector staticQubitsWithInv(QCProgramBuilder& b) { +Value staticQubitsWithInv(QCProgramBuilder& b) { auto q0 = b.staticQubit(0); b.inv(q0, [&](Value qubit) { b.t(qubit); }); - return measureAndReturn(b, {q0}); + return b.measure(q0); } SmallVector staticQubitsWithDuplicates(QCProgramBuilder& b) { @@ -156,10 +156,10 @@ SmallVector staticQubitsCanonical(QCProgramBuilder& b) { return measureAndReturn(b, {q0, q1}); } -SmallVector allocDeallocPair(QCProgramBuilder& b) { +Value allocDeallocPair(QCProgramBuilder& b) { auto q = b.allocQubit(); b.dealloc(q); - return {b.intConstant(0)}; + return b.intConstant(0); } SmallVector mixedStaticThenDynamicQubit(QCProgramBuilder& b) { @@ -174,20 +174,20 @@ SmallVector mixedDynamicRegisterThenStaticQubit(QCProgramBuilder& b) { return measureAndReturn(b, {q0[0], q0[1], q1}); } -SmallVector singleMeasurementToSingleBit(QCProgramBuilder& b) { +Value singleMeasurementToSingleBit(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); const auto outcome = b.measure(q[0], c[0]); - return {outcome}; + return outcome; } -SmallVector repeatedMeasurementToSameBit(QCProgramBuilder& b) { +Value repeatedMeasurementToSameBit(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); b.measure(q[0], c[0]); b.measure(q[0], c[0]); auto c3 = b.measure(q[0], c[0]); - return {c3}; + return c3; } SmallVector repeatedMeasurementToDifferentBits(QCProgramBuilder& b) { @@ -210,16 +210,16 @@ multipleClassicalRegistersAndMeasurements(QCProgramBuilder& b) { return {b1, b2, b3}; } -SmallVector measurementWithoutRegisters(QCProgramBuilder& b) { +Value measurementWithoutRegisters(QCProgramBuilder& b) { auto q = b.allocQubit(); auto c = b.measure(q); - return {c}; + return c; } -SmallVector resetQubitWithoutOp(QCProgramBuilder& b) { +Value resetQubitWithoutOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector resetMultipleQubitsWithoutOp(QCProgramBuilder& b) { @@ -229,19 +229,19 @@ SmallVector resetMultipleQubitsWithoutOp(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector repeatedResetWithoutOp(QCProgramBuilder& b) { +Value repeatedResetWithoutOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector resetQubitAfterSingleOp(QCProgramBuilder& b) { +Value resetQubitAfterSingleOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector resetMultipleQubitsAfterSingleOp(QCProgramBuilder& b) { @@ -253,30 +253,30 @@ SmallVector resetMultipleQubitsAfterSingleOp(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector repeatedResetAfterSingleOp(QCProgramBuilder& b) { +Value repeatedResetAfterSingleOp(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); b.reset(q[0]); b.reset(q[0]); b.reset(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector globalPhase(QCProgramBuilder& b) { +Value globalPhase(QCProgramBuilder& b) { b.gphase(0.123); - return {b.intConstant(0)}; + return b.intConstant(0); } -SmallVector globalPhaseAndMeasure(QCProgramBuilder& b) { +Value globalPhaseAndMeasure(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.gphase(0.123); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector singleControlledGlobalPhase(QCProgramBuilder& b) { +Value singleControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.cgphase(0.123, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector multipleControlledGlobalPhase(QCProgramBuilder& b) { @@ -291,15 +291,15 @@ SmallVector nestedControlledGlobalPhase(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector trivialControlledGlobalPhase(QCProgramBuilder& b) { +Value trivialControlledGlobalPhase(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcgphase(0.123, {}); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseGlobalPhase(QCProgramBuilder& b) { +Value inverseGlobalPhase(QCProgramBuilder& b) { b.inv(ValueRange{}, [&](ValueRange /*qubits*/) { b.gphase(-0.123); }); - return {b.intConstant(0)}; + return b.intConstant(0); } SmallVector inverseMultipleControlledGlobalPhase(QCProgramBuilder& b) { @@ -309,10 +309,10 @@ SmallVector inverseMultipleControlledGlobalPhase(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector identity(QCProgramBuilder& b) { +Value identity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.id(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledIdentity(QCProgramBuilder& b) { @@ -352,16 +352,16 @@ SmallVector nestedControlledIdentity(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector trivialControlledIdentity(QCProgramBuilder& b) { +Value trivialControlledIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcid({}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseIdentity(QCProgramBuilder& b) { +Value inverseIdentity(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.id(qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledIdentity(QCProgramBuilder& b) { @@ -371,10 +371,10 @@ SmallVector inverseMultipleControlledIdentity(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector x(QCProgramBuilder& b) { +Value x(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.x(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledX(QCProgramBuilder& b) { @@ -396,10 +396,10 @@ SmallVector nestedControlledX(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledX(QCProgramBuilder& b) { +Value trivialControlledX(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcx({}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector repeatedControlledX(QCProgramBuilder& b) { @@ -415,10 +415,10 @@ SmallVector repeatedControlledX(QCProgramBuilder& b) { return measureAndReturn(b, qubits); } -SmallVector inverseX(QCProgramBuilder& b) { +Value inverseX(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.x(qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledX(QCProgramBuilder& b) { @@ -428,10 +428,10 @@ SmallVector inverseMultipleControlledX(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector y(QCProgramBuilder& b) { +Value y(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.y(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledY(QCProgramBuilder& b) { @@ -453,16 +453,16 @@ SmallVector nestedControlledY(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledY(QCProgramBuilder& b) { +Value trivialControlledY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcy({}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseY(QCProgramBuilder& b) { +Value inverseY(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.y(qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledY(QCProgramBuilder& b) { @@ -472,10 +472,10 @@ SmallVector inverseMultipleControlledY(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector z(QCProgramBuilder& b) { +Value z(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.z(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledZ(QCProgramBuilder& b) { @@ -497,16 +497,16 @@ SmallVector nestedControlledZ(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledZ(QCProgramBuilder& b) { +Value trivialControlledZ(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcz({}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseZ(QCProgramBuilder& b) { +Value inverseZ(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.z(qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledZ(QCProgramBuilder& b) { @@ -516,10 +516,10 @@ SmallVector inverseMultipleControlledZ(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector h(QCProgramBuilder& b) { +Value h(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.h(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledH(QCProgramBuilder& b) { @@ -541,16 +541,16 @@ SmallVector nestedControlledH(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledH(QCProgramBuilder& b) { +Value trivialControlledH(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mch({}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseH(QCProgramBuilder& b) { +Value inverseH(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.h(qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledH(QCProgramBuilder& b) { @@ -560,16 +560,16 @@ SmallVector inverseMultipleControlledH(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector hWithoutRegister(QCProgramBuilder& b) { +Value hWithoutRegister(QCProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); - return measureAndReturn(b, {q}); + return b.measure(q); } -SmallVector s(QCProgramBuilder& b) { +Value s(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.s(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledS(QCProgramBuilder& b) { @@ -591,16 +591,16 @@ SmallVector nestedControlledS(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledS(QCProgramBuilder& b) { +Value trivialControlledS(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcs({}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseS(QCProgramBuilder& b) { +Value inverseS(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.s(qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledS(QCProgramBuilder& b) { @@ -610,10 +610,10 @@ SmallVector inverseMultipleControlledS(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector sdg(QCProgramBuilder& b) { +Value sdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sdg(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledSdg(QCProgramBuilder& b) { @@ -635,16 +635,16 @@ SmallVector nestedControlledSdg(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledSdg(QCProgramBuilder& b) { +Value trivialControlledSdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcsdg({}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseSdg(QCProgramBuilder& b) { +Value inverseSdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.sdg(qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledSdg(QCProgramBuilder& b) { @@ -654,10 +654,10 @@ SmallVector inverseMultipleControlledSdg(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector t_(QCProgramBuilder& b) { +Value t_(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.t(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledT(QCProgramBuilder& b) { @@ -679,16 +679,16 @@ SmallVector nestedControlledT(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledT(QCProgramBuilder& b) { +Value trivialControlledT(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mct({}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseT(QCProgramBuilder& b) { +Value inverseT(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.t(qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledT(QCProgramBuilder& b) { @@ -698,10 +698,10 @@ SmallVector inverseMultipleControlledT(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector tdg(QCProgramBuilder& b) { +Value tdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.tdg(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledTdg(QCProgramBuilder& b) { @@ -723,16 +723,16 @@ SmallVector nestedControlledTdg(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledTdg(QCProgramBuilder& b) { +Value trivialControlledTdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mctdg({}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseTdg(QCProgramBuilder& b) { +Value inverseTdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.tdg(qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledTdg(QCProgramBuilder& b) { @@ -742,10 +742,10 @@ SmallVector inverseMultipleControlledTdg(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector sx(QCProgramBuilder& b) { +Value sx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sx(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledSx(QCProgramBuilder& b) { @@ -767,16 +767,16 @@ SmallVector nestedControlledSx(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledSx(QCProgramBuilder& b) { +Value trivialControlledSx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcsx({}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseSx(QCProgramBuilder& b) { +Value inverseSx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.sx(qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledSx(QCProgramBuilder& b) { @@ -786,10 +786,10 @@ SmallVector inverseMultipleControlledSx(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector sxdg(QCProgramBuilder& b) { +Value sxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.sxdg(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledSxdg(QCProgramBuilder& b) { @@ -811,16 +811,16 @@ SmallVector nestedControlledSxdg(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledSxdg(QCProgramBuilder& b) { +Value trivialControlledSxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcsxdg({}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseSxdg(QCProgramBuilder& b) { +Value inverseSxdg(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.sxdg(qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledSxdg(QCProgramBuilder& b) { @@ -831,10 +831,10 @@ SmallVector inverseMultipleControlledSxdg(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector rx(QCProgramBuilder& b) { +Value rx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rx(0.123, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledRx(QCProgramBuilder& b) { @@ -856,16 +856,16 @@ SmallVector nestedControlledRx(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledRx(QCProgramBuilder& b) { +Value trivialControlledRx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcrx(0.123, {}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseRx(QCProgramBuilder& b) { +Value inverseRx(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.rx(-0.123, qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledRx(QCProgramBuilder& b) { @@ -876,10 +876,10 @@ SmallVector inverseMultipleControlledRx(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector ry(QCProgramBuilder& b) { +Value ry(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.ry(0.456, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledRy(QCProgramBuilder& b) { @@ -901,16 +901,16 @@ SmallVector nestedControlledRy(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledRy(QCProgramBuilder& b) { +Value trivialControlledRy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcry(0.456, {}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseRy(QCProgramBuilder& b) { +Value inverseRy(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.ry(-0.456, qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledRy(QCProgramBuilder& b) { @@ -921,10 +921,10 @@ SmallVector inverseMultipleControlledRy(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector rz(QCProgramBuilder& b) { +Value rz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.rz(0.789, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledRz(QCProgramBuilder& b) { @@ -946,16 +946,16 @@ SmallVector nestedControlledRz(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledRz(QCProgramBuilder& b) { +Value trivialControlledRz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcrz(0.789, {}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseRz(QCProgramBuilder& b) { +Value inverseRz(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.rz(-0.789, qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledRz(QCProgramBuilder& b) { @@ -966,10 +966,10 @@ SmallVector inverseMultipleControlledRz(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector p(QCProgramBuilder& b) { +Value p(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.p(0.123, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledP(QCProgramBuilder& b) { @@ -991,16 +991,16 @@ SmallVector nestedControlledP(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledP(QCProgramBuilder& b) { +Value trivialControlledP(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcp(0.123, {}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseP(QCProgramBuilder& b) { +Value inverseP(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.p(-0.123, qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledP(QCProgramBuilder& b) { @@ -1011,10 +1011,10 @@ SmallVector inverseMultipleControlledP(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector r(QCProgramBuilder& b) { +Value r(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.r(0.123, 0.456, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledR(QCProgramBuilder& b) { @@ -1037,16 +1037,16 @@ SmallVector nestedControlledR(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledR(QCProgramBuilder& b) { +Value trivialControlledR(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcr(0.123, 0.456, {}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseR(QCProgramBuilder& b) { +Value inverseR(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.r(-0.123, 0.456, qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledR(QCProgramBuilder& b) { @@ -1057,10 +1057,10 @@ SmallVector inverseMultipleControlledR(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector u2(QCProgramBuilder& b) { +Value u2(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u2(0.234, 0.567, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledU2(QCProgramBuilder& b) { @@ -1083,17 +1083,17 @@ SmallVector nestedControlledU2(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledU2(QCProgramBuilder& b) { +Value trivialControlledU2(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcu2(0.234, 0.567, {}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseU2(QCProgramBuilder& b) { +Value inverseU2(QCProgramBuilder& b) { constexpr double pi = std::numbers::pi; auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.u2(-0.567 + pi, -0.234 - pi, qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledU2(QCProgramBuilder& b) { @@ -1105,10 +1105,10 @@ SmallVector inverseMultipleControlledU2(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector u(QCProgramBuilder& b) { +Value u(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.u(0.1, 0.2, 0.3, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector singleControlledU(QCProgramBuilder& b) { @@ -1131,16 +1131,16 @@ SmallVector nestedControlledU(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledU(QCProgramBuilder& b) { +Value trivialControlledU(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.mcu(0.1, 0.2, 0.3, {}, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } -SmallVector inverseU(QCProgramBuilder& b) { +Value inverseU(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.u(-0.1, -0.3, -0.2, qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector inverseMultipleControlledU(QCProgramBuilder& b) { @@ -1633,10 +1633,10 @@ SmallVector inverseMultipleControlledXxMinusYY(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector barrier(QCProgramBuilder& b) { +Value barrier(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.barrier(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector barrierTwoQubits(QCProgramBuilder& b) { @@ -1657,10 +1657,10 @@ SmallVector singleControlledBarrier(QCProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector inverseBarrier(QCProgramBuilder& b) { +Value inverseBarrier(QCProgramBuilder& b) { auto q = b.allocQubitRegister(1); b.inv(q[0], [&](Value qubit) { b.barrier(qubit); }); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]); } SmallVector trivialCtrl(QCProgramBuilder& b) { @@ -1856,7 +1856,7 @@ SmallVector ifTwoQubits(QCProgramBuilder& b) { return {cond, c0, c1}; } -SmallVector nestedIfOpForLoop(QCProgramBuilder& b) { +Value nestedIfOpForLoop(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); b.h(q0); @@ -1869,10 +1869,10 @@ SmallVector nestedIfOpForLoop(QCProgramBuilder& b) { b.h(q1); }); }); - return measureAndReturn(b, {q0}); + return b.measure(q0); } -SmallVector simpleWhileReset(QCProgramBuilder& b) { +Value simpleWhileReset(QCProgramBuilder& b) { auto q = b.allocQubit(); b.h(q); b.scfWhile( @@ -1881,10 +1881,10 @@ SmallVector simpleWhileReset(QCProgramBuilder& b) { b.scfCondition(measureResult); }, [&] { b.h(q); }); - return measureAndReturn(b, {q}); + return b.measure(q); } -SmallVector simpleDoWhileReset(QCProgramBuilder& b) { +Value simpleDoWhileReset(QCProgramBuilder& b) { auto q = b.allocQubit(); b.scfWhile( [&] { @@ -1893,7 +1893,7 @@ SmallVector simpleDoWhileReset(QCProgramBuilder& b) { b.scfCondition(measureResult); }, [&] {}); - return measureAndReturn(b, {q}); + return b.measure(q); } SmallVector simpleForLoop(QCProgramBuilder& b) { @@ -1905,7 +1905,7 @@ SmallVector simpleForLoop(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); }; -SmallVector nestedForLoopIfOp(QCProgramBuilder& b) { +Value nestedForLoopIfOp(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto qCond = b.allocQubit(); b.scfFor(0, 2, 1, [&](Value iv) { @@ -1916,7 +1916,7 @@ SmallVector nestedForLoopIfOp(QCProgramBuilder& b) { b.h(q); }); }); - return measureAndReturn(b, {qCond}); + return b.measure(qCond); } SmallVector nestedForLoopWhileOp(QCProgramBuilder& b) { @@ -1937,7 +1937,7 @@ SmallVector nestedForLoopWhileOp(QCProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b) { +Value nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto control = b.allocQubit(); b.h(control); @@ -1946,10 +1946,10 @@ SmallVector nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b) { b.h(q0); b.cx(control, q0); }); - return measureAndReturn(b, {control}); + return b.measure(control); } -SmallVector nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b) { +Value nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b) { auto reg = b.allocQubitRegister(4); b.h(reg[0]); b.scfFor(1, 4, 1, [&](Value iv) { @@ -1957,7 +1957,7 @@ SmallVector nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b) { b.h(q0); b.cx(reg[0], q0); }); - return measureAndReturn(b, {reg[0]}); + return b.measure(reg[0]); } } // namespace mlir::qc diff --git a/mlir/unittests/programs/qc_programs.h b/mlir/unittests/programs/qc_programs.h index fc041ca1a8..4849d861c7 100644 --- a/mlir/unittests/programs/qc_programs.h +++ b/mlir/unittests/programs/qc_programs.h @@ -17,18 +17,18 @@ namespace mlir::qc { class QCProgramBuilder; /// Creates an empty QC Program. -SmallVector emptyQC(QCProgramBuilder& b); +Value emptyQC(QCProgramBuilder& b); // --- Qubit Management ----------------------------------------------------- // /// Allocates a single qubit. -SmallVector allocQubit(QCProgramBuilder& b); +Value allocQubit(QCProgramBuilder& b); /// Allocates a single qubit without measuring it. -SmallVector allocQubitNoMeasure(QCProgramBuilder& b); +Value allocQubitNoMeasure(QCProgramBuilder& b); /// Allocates a qubit register of size `1`. -SmallVector alloc1QubitRegister(QCProgramBuilder& b); +Value alloc1QubitRegister(QCProgramBuilder& b); /// Allocates a qubit register of size `2`. SmallVector allocQubitRegister(QCProgramBuilder& b); @@ -49,7 +49,7 @@ SmallVector allocLargeRegister(QCProgramBuilder& b); SmallVector staticQubits(QCProgramBuilder& b); /// Allocates two inline qubits without measuring them. -SmallVector staticQubitsNoMeasure(QCProgramBuilder& b); +Value staticQubitsNoMeasure(QCProgramBuilder& b); /// Allocates two static qubits and applies operations. SmallVector staticQubitsWithOps(QCProgramBuilder& b); @@ -64,7 +64,7 @@ SmallVector staticQubitsWithTwoTargetOps(QCProgramBuilder& b); SmallVector staticQubitsWithCtrl(QCProgramBuilder& b); /// Allocates a static qubit and applies an inverse modifier. -SmallVector staticQubitsWithInv(QCProgramBuilder& b); +Value staticQubitsWithInv(QCProgramBuilder& b); /// Allocates duplicate static qubits and applies operations on both. SmallVector staticQubitsWithDuplicates(QCProgramBuilder& b); @@ -74,7 +74,7 @@ SmallVector staticQubitsWithDuplicates(QCProgramBuilder& b); SmallVector staticQubitsCanonical(QCProgramBuilder& b); /// Allocates and explicitly deallocates a single qubit. -SmallVector allocDeallocPair(QCProgramBuilder& b); +Value allocDeallocPair(QCProgramBuilder& b); // --- Invalid / mixed addressing (unit tests) -------------------------------- @@ -89,10 +89,10 @@ SmallVector mixedDynamicRegisterThenStaticQubit(QCProgramBuilder& b); // --- MeasureOp ------------------------------------------------------------ // /// Measures a single qubit into a single classical bit. -SmallVector singleMeasurementToSingleBit(QCProgramBuilder& b); +Value singleMeasurementToSingleBit(QCProgramBuilder& b); /// Repeatedly measures a single qubit into the same classical bit. -SmallVector repeatedMeasurementToSameBit(QCProgramBuilder& b); +Value repeatedMeasurementToSameBit(QCProgramBuilder& b); /// Repeatedly measures a single qubit into different classical bits. SmallVector repeatedMeasurementToDifferentBits(QCProgramBuilder& b); @@ -103,38 +103,38 @@ multipleClassicalRegistersAndMeasurements(QCProgramBuilder& b); /// Measures a single qubit into a single classical bit, without explicitly /// allocating a quantum or classical register. -SmallVector measurementWithoutRegisters(QCProgramBuilder& b); +Value measurementWithoutRegisters(QCProgramBuilder& b); // --- ResetOp -------------------------------------------------------------- // /// Resets a single qubit without any operations being applied. -SmallVector resetQubitWithoutOp(QCProgramBuilder& b); +Value resetQubitWithoutOp(QCProgramBuilder& b); /// Resets multiple qubits without any operations being applied. SmallVector resetMultipleQubitsWithoutOp(QCProgramBuilder& b); /// Repeatedly resets a single qubit without any operations being applied. -SmallVector repeatedResetWithoutOp(QCProgramBuilder& b); +Value repeatedResetWithoutOp(QCProgramBuilder& b); /// Resets a single qubit after a single operation. -SmallVector resetQubitAfterSingleOp(QCProgramBuilder& b); +Value resetQubitAfterSingleOp(QCProgramBuilder& b); /// Resets multiple qubits after a single operation. SmallVector resetMultipleQubitsAfterSingleOp(QCProgramBuilder& b); /// Repeatedly resets a single qubit after a single operation. -SmallVector repeatedResetAfterSingleOp(QCProgramBuilder& b); +Value repeatedResetAfterSingleOp(QCProgramBuilder& b); // --- GPhaseOp ------------------------------------------------------------- // /// Creates a circuit with just a global phase. -SmallVector globalPhase(QCProgramBuilder& b); +Value globalPhase(QCProgramBuilder& b); /// Creates a circuit with just a global phase and a single measured qubit. -SmallVector globalPhaseAndMeasure(QCProgramBuilder& b); +Value globalPhaseAndMeasure(QCProgramBuilder& b); /// Creates a controlled global phase gate with a single control qubit. -SmallVector singleControlledGlobalPhase(QCProgramBuilder& b); +Value singleControlledGlobalPhase(QCProgramBuilder& b); /// Creates a multi-controlled global phase gate with multiple control qubits. SmallVector multipleControlledGlobalPhase(QCProgramBuilder& b); @@ -143,10 +143,10 @@ SmallVector multipleControlledGlobalPhase(QCProgramBuilder& b); SmallVector nestedControlledGlobalPhase(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled global phase gate. -SmallVector trivialControlledGlobalPhase(QCProgramBuilder& b); +Value trivialControlledGlobalPhase(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a global phase gate. -SmallVector inverseGlobalPhase(QCProgramBuilder& b); +Value inverseGlobalPhase(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled global /// phase gate. @@ -155,7 +155,7 @@ SmallVector inverseMultipleControlledGlobalPhase(QCProgramBuilder& b); // --- IdOp ----------------------------------------------------------------- // /// Creates a circuit with just an identity gate. -SmallVector identity(QCProgramBuilder& b); +Value identity(QCProgramBuilder& b); /// Creates a controlled identity gate with a single control qubit. SmallVector singleControlledIdentity(QCProgramBuilder& b); @@ -176,10 +176,10 @@ SmallVector twoQubitsOneBarrier(QCProgramBuilder& b); SmallVector nestedControlledIdentity(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled identity gate. -SmallVector trivialControlledIdentity(QCProgramBuilder& b); +Value trivialControlledIdentity(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an identity gate. -SmallVector inverseIdentity(QCProgramBuilder& b); +Value inverseIdentity(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled identity /// gate. @@ -188,7 +188,7 @@ SmallVector inverseMultipleControlledIdentity(QCProgramBuilder& b); // --- XOp ------------------------------------------------------------------ // /// Creates a circuit with just an X gate. -SmallVector x(QCProgramBuilder& b); +Value x(QCProgramBuilder& b); /// Creates a circuit with a single controlled X gate. SmallVector singleControlledX(QCProgramBuilder& b); @@ -200,13 +200,13 @@ SmallVector multipleControlledX(QCProgramBuilder& b); SmallVector nestedControlledX(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled X gate. -SmallVector trivialControlledX(QCProgramBuilder& b); +Value trivialControlledX(QCProgramBuilder& b); /// Creates a circuit with repeated controlled X gates. SmallVector repeatedControlledX(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an X gate. -SmallVector inverseX(QCProgramBuilder& b); +Value inverseX(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled X gate. SmallVector inverseMultipleControlledX(QCProgramBuilder& b); @@ -214,7 +214,7 @@ SmallVector inverseMultipleControlledX(QCProgramBuilder& b); // --- YOp ------------------------------------------------------------------ // /// Creates a circuit with just a Y gate. -SmallVector y(QCProgramBuilder& b); +Value y(QCProgramBuilder& b); /// Creates a circuit with a single controlled Y gate. SmallVector singleControlledY(QCProgramBuilder& b); @@ -226,10 +226,10 @@ SmallVector multipleControlledY(QCProgramBuilder& b); SmallVector nestedControlledY(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled Y gate. -SmallVector trivialControlledY(QCProgramBuilder& b); +Value trivialControlledY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Y gate. -SmallVector inverseY(QCProgramBuilder& b); +Value inverseY(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Y gate. SmallVector inverseMultipleControlledY(QCProgramBuilder& b); @@ -237,7 +237,7 @@ SmallVector inverseMultipleControlledY(QCProgramBuilder& b); // --- ZOp ------------------------------------------------------------------ // /// Creates a circuit with just a Z gate. -SmallVector z(QCProgramBuilder& b); +Value z(QCProgramBuilder& b); /// Creates a circuit with a single controlled Z gate. SmallVector singleControlledZ(QCProgramBuilder& b); @@ -249,10 +249,10 @@ SmallVector multipleControlledZ(QCProgramBuilder& b); SmallVector nestedControlledZ(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled Z gate. -SmallVector trivialControlledZ(QCProgramBuilder& b); +Value trivialControlledZ(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Z gate. -SmallVector inverseZ(QCProgramBuilder& b); +Value inverseZ(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Z gate. SmallVector inverseMultipleControlledZ(QCProgramBuilder& b); @@ -260,7 +260,7 @@ SmallVector inverseMultipleControlledZ(QCProgramBuilder& b); // --- HOp ------------------------------------------------------------------ // /// Creates a circuit with just an H gate. -SmallVector h(QCProgramBuilder& b); +Value h(QCProgramBuilder& b); /// Creates a circuit with a single controlled H gate. SmallVector singleControlledH(QCProgramBuilder& b); @@ -272,21 +272,21 @@ SmallVector multipleControlledH(QCProgramBuilder& b); SmallVector nestedControlledH(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled H gate. -SmallVector trivialControlledH(QCProgramBuilder& b); +Value trivialControlledH(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an H gate. -SmallVector inverseH(QCProgramBuilder& b); +Value inverseH(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled H gate. SmallVector inverseMultipleControlledH(QCProgramBuilder& b); /// Creates a circuit with just an H gate and no qubit register. -SmallVector hWithoutRegister(QCProgramBuilder& b); +Value hWithoutRegister(QCProgramBuilder& b); // --- SOp ------------------------------------------------------------------ // /// Creates a circuit with just an S gate. -SmallVector s(QCProgramBuilder& b); +Value s(QCProgramBuilder& b); /// Creates a circuit with a single controlled S gate. SmallVector singleControlledS(QCProgramBuilder& b); @@ -298,10 +298,10 @@ SmallVector multipleControlledS(QCProgramBuilder& b); SmallVector nestedControlledS(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled S gate. -SmallVector trivialControlledS(QCProgramBuilder& b); +Value trivialControlledS(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an S gate. -SmallVector inverseS(QCProgramBuilder& b); +Value inverseS(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled S gate. SmallVector inverseMultipleControlledS(QCProgramBuilder& b); @@ -309,7 +309,7 @@ SmallVector inverseMultipleControlledS(QCProgramBuilder& b); // --- SdgOp ---------------------------------------------------------------- // /// Creates a circuit with just an Sdg gate. -SmallVector sdg(QCProgramBuilder& b); +Value sdg(QCProgramBuilder& b); /// Creates a circuit with a single controlled Sdg gate. SmallVector singleControlledSdg(QCProgramBuilder& b); @@ -321,10 +321,10 @@ SmallVector multipleControlledSdg(QCProgramBuilder& b); SmallVector nestedControlledSdg(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled Sdg gate. -SmallVector trivialControlledSdg(QCProgramBuilder& b); +Value trivialControlledSdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an Sdg gate. -SmallVector inverseSdg(QCProgramBuilder& b); +Value inverseSdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Sdg gate. SmallVector inverseMultipleControlledSdg(QCProgramBuilder& b); @@ -332,7 +332,7 @@ SmallVector inverseMultipleControlledSdg(QCProgramBuilder& b); // --- TOp ------------------------------------------------------------------ // /// Creates a circuit with just a T gate. -SmallVector t_(QCProgramBuilder& b); // NOLINT(*-identifier-naming) +Value t_(QCProgramBuilder& b); // NOLINT(*-identifier-naming) /// Creates a circuit with a single controlled T gate. SmallVector singleControlledT(QCProgramBuilder& b); @@ -344,10 +344,10 @@ SmallVector multipleControlledT(QCProgramBuilder& b); SmallVector nestedControlledT(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled T gate. -SmallVector trivialControlledT(QCProgramBuilder& b); +Value trivialControlledT(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a T gate. -SmallVector inverseT(QCProgramBuilder& b); +Value inverseT(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled T gate. SmallVector inverseMultipleControlledT(QCProgramBuilder& b); @@ -355,7 +355,7 @@ SmallVector inverseMultipleControlledT(QCProgramBuilder& b); // --- TdgOp ---------------------------------------------------------------- // /// Creates a circuit with just a Tdg gate. -SmallVector tdg(QCProgramBuilder& b); +Value tdg(QCProgramBuilder& b); /// Creates a circuit with a single controlled Tdg gate. SmallVector singleControlledTdg(QCProgramBuilder& b); @@ -367,10 +367,10 @@ SmallVector multipleControlledTdg(QCProgramBuilder& b); SmallVector nestedControlledTdg(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled Tdg gate. -SmallVector trivialControlledTdg(QCProgramBuilder& b); +Value trivialControlledTdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Tdg gate. -SmallVector inverseTdg(QCProgramBuilder& b); +Value inverseTdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Tdg gate. SmallVector inverseMultipleControlledTdg(QCProgramBuilder& b); @@ -378,7 +378,7 @@ SmallVector inverseMultipleControlledTdg(QCProgramBuilder& b); // --- SXOp ----------------------------------------------------------------- // /// Creates a circuit with just an SX gate. -SmallVector sx(QCProgramBuilder& b); +Value sx(QCProgramBuilder& b); /// Creates a circuit with a single controlled SX gate. SmallVector singleControlledSx(QCProgramBuilder& b); @@ -390,10 +390,10 @@ SmallVector multipleControlledSx(QCProgramBuilder& b); SmallVector nestedControlledSx(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled SX gate. -SmallVector trivialControlledSx(QCProgramBuilder& b); +Value trivialControlledSx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an SX gate. -SmallVector inverseSx(QCProgramBuilder& b); +Value inverseSx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SX gate. SmallVector inverseMultipleControlledSx(QCProgramBuilder& b); @@ -401,7 +401,7 @@ SmallVector inverseMultipleControlledSx(QCProgramBuilder& b); // --- SXdgOp --------------------------------------------------------------- // /// Creates a circuit with just an SXdg gate. -SmallVector sxdg(QCProgramBuilder& b); +Value sxdg(QCProgramBuilder& b); /// Creates a circuit with a single controlled SXdg gate. SmallVector singleControlledSxdg(QCProgramBuilder& b); @@ -413,10 +413,10 @@ SmallVector multipleControlledSxdg(QCProgramBuilder& b); SmallVector nestedControlledSxdg(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled SXdg gate. -SmallVector trivialControlledSxdg(QCProgramBuilder& b); +Value trivialControlledSxdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an SXdg gate. -SmallVector inverseSxdg(QCProgramBuilder& b); +Value inverseSxdg(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SXdg /// gate. @@ -425,7 +425,7 @@ SmallVector inverseMultipleControlledSxdg(QCProgramBuilder& b); // --- RXOp ----------------------------------------------------------------- // /// Creates a circuit with just an RX gate. -SmallVector rx(QCProgramBuilder& b); +Value rx(QCProgramBuilder& b); /// Creates a circuit with a single controlled RX gate. SmallVector singleControlledRx(QCProgramBuilder& b); @@ -437,10 +437,10 @@ SmallVector multipleControlledRx(QCProgramBuilder& b); SmallVector nestedControlledRx(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RX gate. -SmallVector trivialControlledRx(QCProgramBuilder& b); +Value trivialControlledRx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RX gate. -SmallVector inverseRx(QCProgramBuilder& b); +Value inverseRx(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RX gate. SmallVector inverseMultipleControlledRx(QCProgramBuilder& b); @@ -448,7 +448,7 @@ SmallVector inverseMultipleControlledRx(QCProgramBuilder& b); // --- RYOp ----------------------------------------------------------------- // /// Creates a circuit with just an RY gate. -SmallVector ry(QCProgramBuilder& b); +Value ry(QCProgramBuilder& b); /// Creates a circuit with a single controlled RY gate. SmallVector singleControlledRy(QCProgramBuilder& b); @@ -460,10 +460,10 @@ SmallVector multipleControlledRy(QCProgramBuilder& b); SmallVector nestedControlledRy(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RY gate. -SmallVector trivialControlledRy(QCProgramBuilder& b); +Value trivialControlledRy(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RY gate. -SmallVector inverseRy(QCProgramBuilder& b); +Value inverseRy(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RY gate. SmallVector inverseMultipleControlledRy(QCProgramBuilder& b); @@ -471,7 +471,7 @@ SmallVector inverseMultipleControlledRy(QCProgramBuilder& b); // --- RZOp ----------------------------------------------------------------- // /// Creates a circuit with just an RZ gate. -SmallVector rz(QCProgramBuilder& b); +Value rz(QCProgramBuilder& b); /// Creates a circuit with a single controlled RZ gate. SmallVector singleControlledRz(QCProgramBuilder& b); @@ -483,10 +483,10 @@ SmallVector multipleControlledRz(QCProgramBuilder& b); SmallVector nestedControlledRz(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled RZ gate. -SmallVector trivialControlledRz(QCProgramBuilder& b); +Value trivialControlledRz(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZ gate. -SmallVector inverseRz(QCProgramBuilder& b); +Value inverseRz(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZ gate. SmallVector inverseMultipleControlledRz(QCProgramBuilder& b); @@ -494,7 +494,7 @@ SmallVector inverseMultipleControlledRz(QCProgramBuilder& b); // --- POp ------------------------------------------------------------------ // /// Creates a circuit with just a P gate. -SmallVector p(QCProgramBuilder& b); +Value p(QCProgramBuilder& b); /// Creates a circuit with a single controlled P gate. SmallVector singleControlledP(QCProgramBuilder& b); @@ -506,10 +506,10 @@ SmallVector multipleControlledP(QCProgramBuilder& b); SmallVector nestedControlledP(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled P gate. -SmallVector trivialControlledP(QCProgramBuilder& b); +Value trivialControlledP(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a P gate. -SmallVector inverseP(QCProgramBuilder& b); +Value inverseP(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled P gate. SmallVector inverseMultipleControlledP(QCProgramBuilder& b); @@ -517,7 +517,7 @@ SmallVector inverseMultipleControlledP(QCProgramBuilder& b); // --- ROp ------------------------------------------------------------------ // /// Creates a circuit with just an R gate. -SmallVector r(QCProgramBuilder& b); +Value r(QCProgramBuilder& b); /// Creates a circuit with a single controlled R gate. SmallVector singleControlledR(QCProgramBuilder& b); @@ -529,10 +529,10 @@ SmallVector multipleControlledR(QCProgramBuilder& b); SmallVector nestedControlledR(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled R gate. -SmallVector trivialControlledR(QCProgramBuilder& b); +Value trivialControlledR(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an R gate. -SmallVector inverseR(QCProgramBuilder& b); +Value inverseR(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled R gate. SmallVector inverseMultipleControlledR(QCProgramBuilder& b); @@ -540,7 +540,7 @@ SmallVector inverseMultipleControlledR(QCProgramBuilder& b); // --- U2Op ----------------------------------------------------------------- // /// Creates a circuit with just a U2 gate. -SmallVector u2(QCProgramBuilder& b); +Value u2(QCProgramBuilder& b); /// Creates a circuit with a single controlled U2 gate. SmallVector singleControlledU2(QCProgramBuilder& b); @@ -552,10 +552,10 @@ SmallVector multipleControlledU2(QCProgramBuilder& b); SmallVector nestedControlledU2(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled U2 gate. -SmallVector trivialControlledU2(QCProgramBuilder& b); +Value trivialControlledU2(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a U2 gate. -SmallVector inverseU2(QCProgramBuilder& b); +Value inverseU2(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled U2 gate. SmallVector inverseMultipleControlledU2(QCProgramBuilder& b); @@ -563,7 +563,7 @@ SmallVector inverseMultipleControlledU2(QCProgramBuilder& b); // --- UOp ------------------------------------------------------------------ // /// Creates a circuit with just a U gate. -SmallVector u(QCProgramBuilder& b); +Value u(QCProgramBuilder& b); /// Creates a circuit with a single controlled U gate. SmallVector singleControlledU(QCProgramBuilder& b); @@ -575,10 +575,10 @@ SmallVector multipleControlledU(QCProgramBuilder& b); SmallVector nestedControlledU(QCProgramBuilder& b); /// Creates a circuit with a trivial controlled U gate. -SmallVector trivialControlledU(QCProgramBuilder& b); +Value trivialControlledU(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a U gate. -SmallVector inverseU(QCProgramBuilder& b); +Value inverseU(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled U gate. SmallVector inverseMultipleControlledU(QCProgramBuilder& b); @@ -826,7 +826,7 @@ SmallVector inverseMultipleControlledXxMinusYY(QCProgramBuilder& b); // --- BarrierOp ------------------------------------------------------------ // /// Creates a circuit with a barrier. -SmallVector barrier(QCProgramBuilder& b); +Value barrier(QCProgramBuilder& b); /// Creates a circuit with a barrier on two qubits. SmallVector barrierTwoQubits(QCProgramBuilder& b); @@ -838,7 +838,7 @@ SmallVector barrierMultipleQubits(QCProgramBuilder& b); SmallVector singleControlledBarrier(QCProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a barrier. -SmallVector inverseBarrier(QCProgramBuilder& b); +Value inverseBarrier(QCProgramBuilder& b); // --- CtrlOp --------------------------------------------------------------- // @@ -908,15 +908,15 @@ SmallVector ifTwoQubits(QCProgramBuilder& b); /// Creates a circuit with an if operation with a nested for operation with /// a register. -SmallVector nestedIfOpForLoop(QCProgramBuilder& b); +Value nestedIfOpForLoop(QCProgramBuilder& b); // --- WhileOp -------------------------------------------------------------- // /// Creates a circuit with a while operation using a while loop. -SmallVector simpleWhileReset(QCProgramBuilder& b); +Value simpleWhileReset(QCProgramBuilder& b); /// Creates a circuit with a while operation using a do-while loop. -SmallVector simpleDoWhileReset(QCProgramBuilder& b); +Value simpleDoWhileReset(QCProgramBuilder& b); // --- ForOp ---------------------------------------------------------------- // @@ -925,7 +925,7 @@ SmallVector simpleForLoop(QCProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested if operation. -SmallVector nestedForLoopIfOp(QCProgramBuilder& b); +Value nestedForLoopIfOp(QCProgramBuilder& b); /// Creates a circuit with a for operation with a register and a nested while /// operation. @@ -934,10 +934,10 @@ SmallVector nestedForLoopWhileOp(QCProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is separately allocated from the /// register. -SmallVector nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b); +Value nestedForLoopCtrlOpWithSeparateQubit(QCProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is extracted from the register. -SmallVector nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b); +Value nestedForLoopCtrlOpWithExtractedQubit(QCProgramBuilder& b); } // namespace mlir::qc diff --git a/mlir/unittests/programs/qco_programs.cpp b/mlir/unittests/programs/qco_programs.cpp index d6e9d61cc6..4cafe6572d 100644 --- a/mlir/unittests/programs/qco_programs.cpp +++ b/mlir/unittests/programs/qco_programs.cpp @@ -56,11 +56,11 @@ static SmallVector measureAndReturn(QCOProgramBuilder& b, llvm::map_range(qubits, [&](Value q) { return b.measure(q).second; })); } -SmallVector emptyQCO(QCOProgramBuilder& b) { return {b.intConstant(0)}; } +Value emptyQCO(QCOProgramBuilder& b) { return b.intConstant(0); } -SmallVector allocQubit(QCOProgramBuilder& b) { +Value allocQubit(QCOProgramBuilder& b) { auto q = b.allocQubit(); - return measureAndReturn(b, {q}); + return b.measure(q).second; } SmallVector alloc2Qubits(QCOProgramBuilder& b) { @@ -69,14 +69,14 @@ SmallVector alloc2Qubits(QCOProgramBuilder& b) { return measureAndReturn(b, {q0, q1}); } -SmallVector allocQubitNoMeasure(QCOProgramBuilder& b) { +Value allocQubitNoMeasure(QCOProgramBuilder& b) { (void)b.allocQubit(); - return {b.intConstant(0)}; + return b.intConstant(0); } -SmallVector alloc1QubitRegister(QCOProgramBuilder& b) { +Value alloc1QubitRegister(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(1); - return measureAndReturn(b, reg.qubits); + return b.measure(reg[0]).second; } SmallVector alloc2QubitRegister(QCOProgramBuilder& b) { @@ -95,15 +95,15 @@ SmallVector allocMultipleQubitRegisters(QCOProgramBuilder& b) { return measureAndReturn(b, {r1[0], r1[1], r2[0], r2[1], r2[2]}); } -SmallVector allocLargeRegister(QCOProgramBuilder& b) { +Value allocLargeRegister(QCOProgramBuilder& b) { auto r = b.allocQubitRegister(100); - return measureAndReturn(b, {r[0]}); + return b.measure(r[0]).second; } -SmallVector staticQubitsNoMeasure(QCOProgramBuilder& b) { +Value staticQubitsNoMeasure(QCOProgramBuilder& b) { (void)b.staticQubit(0); (void)b.staticQubit(1); - return {b.intConstant(0)}; + return b.intConstant(0); } SmallVector staticQubits(QCOProgramBuilder& b) { @@ -142,16 +142,16 @@ SmallVector staticQubitsWithCtrl(QCOProgramBuilder& b) { return measureAndReturn(b, {q0, q1}); } -SmallVector staticQubitsWithInv(QCOProgramBuilder& b) { +Value staticQubitsWithInv(QCOProgramBuilder& b) { auto q0 = b.staticQubit(0); q0 = b.inv(q0, [&](Value qubit) { return b.t(qubit); }); - return measureAndReturn(b, {q0}); + return b.measure(q0).second; } -SmallVector allocSinkPair(QCOProgramBuilder& b) { +Value allocSinkPair(QCOProgramBuilder& b) { auto q = b.allocQubit(); b.sink(q); - return {b.intConstant(0)}; + return b.intConstant(0); } SmallVector deadGatesProgram(QCOProgramBuilder& b) { @@ -169,7 +169,7 @@ SmallVector deadGatesProgram(QCOProgramBuilder& b) { return {m0, m1}; } -SmallVector deadGatesWithIfOpProgram(QCOProgramBuilder& b) { +Value deadGatesWithIfOpProgram(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.allocQubit(); q0 = b.h(q0); @@ -182,11 +182,11 @@ SmallVector deadGatesWithIfOpProgram(QCOProgramBuilder& b) { [&](ValueRange qubits) -> SmallVector { auto q1Then = b.x(qubits[0]); b.gphase(0.5); // This adds memory effects to the `IfOp`. - return SmallVector{q1Then}; + return {q1Then}; }, [&](ValueRange qubits) -> SmallVector { auto q1Else = b.h(qubits[0]); - return SmallVector{q1Else}; + return {q1Else}; })[0]; // This is an `if` without memory effects - it can be removed. @@ -194,17 +194,17 @@ SmallVector deadGatesWithIfOpProgram(QCOProgramBuilder& b) { c0, {q1}, [&](ValueRange qubits) -> SmallVector { auto q1Then = b.x(qubits[0]); - return SmallVector{q1Then}; + return {q1Then}; }, [&](ValueRange qubits) -> SmallVector { auto q1Else = b.h(qubits[0]); - return SmallVector{q1Else}; + return {q1Else}; })[0]; - return {c0}; + return c0; } -SmallVector deadGatesWithIfOpSimplified(QCOProgramBuilder& b) { +Value deadGatesWithIfOpSimplified(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.allocQubit(); q0 = b.h(q0); @@ -217,14 +217,14 @@ SmallVector deadGatesWithIfOpSimplified(QCOProgramBuilder& b) { [&](ValueRange qubits) -> SmallVector { auto q1Then = b.x(qubits[0]); b.gphase(0.5); // Due to memory effect, the `IfOp` stays. - return SmallVector{q1Then}; + return {q1Then}; }, [&](ValueRange qubits) -> SmallVector { auto q1Else = b.h(qubits[0]); - return SmallVector{q1Else}; + return {q1Else}; })[0]; - return {c0}; + return c0; } SmallVector mixedStaticThenDynamicQubit(QCOProgramBuilder& b) { @@ -233,26 +233,26 @@ SmallVector mixedStaticThenDynamicQubit(QCOProgramBuilder& b) { return measureAndReturn(b, {q0, q1}); } -SmallVector mixedDynamicRegisterThenStaticQubit(QCOProgramBuilder& b) { +Value mixedDynamicRegisterThenStaticQubit(QCOProgramBuilder& b) { b.qtensorAlloc(2); auto q1 = b.staticQubit(0); - return measureAndReturn(b, {q1}); + return b.measure(q1).second; } -SmallVector singleMeasurementToSingleBit(QCOProgramBuilder& b) { +Value singleMeasurementToSingleBit(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); const auto [q1, bit] = b.measure(q[0], c[0]); - return {bit}; + return bit; } -SmallVector repeatedMeasurementToSameBit(QCOProgramBuilder& b) { +Value repeatedMeasurementToSameBit(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); const auto& c = b.allocClassicalBitRegister(1); auto [q1, _c1] = b.measure(q[0], c[0]); auto [q2, _c2] = b.measure(q1, c[0]); auto [q3, c3] = b.measure(q2, c[0]); - return {c3}; + return c3; } SmallVector repeatedMeasurementToDifferentBits(QCOProgramBuilder& b) { @@ -275,16 +275,16 @@ multipleClassicalRegistersAndMeasurements(QCOProgramBuilder& b) { return {bit1, bit2, bit3}; } -SmallVector measurementWithoutRegisters(QCOProgramBuilder& b) { +Value measurementWithoutRegisters(QCOProgramBuilder& b) { auto q = b.allocQubit(); auto [q1, c] = b.measure(q); - return {c}; + return c; } -SmallVector resetQubitWithoutOp(QCOProgramBuilder& b) { +Value resetQubitWithoutOp(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.reset(q); - return measureAndReturn(b, {q}); + return b.measure(q).second; } SmallVector resetMultipleQubitsWithoutOp(QCOProgramBuilder& b) { @@ -294,19 +294,19 @@ SmallVector resetMultipleQubitsWithoutOp(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector repeatedResetWithoutOp(QCOProgramBuilder& b) { +Value repeatedResetWithoutOp(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.reset(q); q = b.reset(q); q = b.reset(q); - return measureAndReturn(b, {q}); + return b.measure(q).second; } -SmallVector resetQubitAfterSingleOp(QCOProgramBuilder& b) { +Value resetQubitAfterSingleOp(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); q[0] = b.reset(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector resetMultipleQubitsAfterSingleOp(QCOProgramBuilder& b) { @@ -318,24 +318,24 @@ SmallVector resetMultipleQubitsAfterSingleOp(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector repeatedResetAfterSingleOp(QCOProgramBuilder& b) { +Value repeatedResetAfterSingleOp(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); q[0] = b.reset(q[0]); q[0] = b.reset(q[0]); q[0] = b.reset(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector globalPhase(QCOProgramBuilder& b) { +Value globalPhase(QCOProgramBuilder& b) { b.gphase(0.123); - return {b.intConstant(0)}; + return b.intConstant(0); } -SmallVector singleControlledGlobalPhase(QCOProgramBuilder& b) { +Value singleControlledGlobalPhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.cgphase(0.123, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector multipleControlledGlobalPhase(QCOProgramBuilder& b) { @@ -344,12 +344,12 @@ SmallVector multipleControlledGlobalPhase(QCOProgramBuilder& b) { return measureAndReturn(b, qs); } -SmallVector inverseGlobalPhase(QCOProgramBuilder& b) { +Value inverseGlobalPhase(QCOProgramBuilder& b) { b.inv(ValueRange{}, [&](ValueRange /*qubits*/) { b.gphase(-0.123); return SmallVector{}; }); - return {b.intConstant(0)}; + return b.intConstant(0); } SmallVector inverseMultipleControlledGlobalPhase(QCOProgramBuilder& b) { @@ -362,10 +362,10 @@ SmallVector inverseMultipleControlledGlobalPhase(QCOProgramBuilder& b) { return measureAndReturn(b, qs); } -SmallVector identity(QCOProgramBuilder& b) { +Value identity(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.id(q); - return measureAndReturn(b, {q}); + return b.measure(q).second; } SmallVector singleControlledIdentity(QCOProgramBuilder& b) { @@ -396,17 +396,17 @@ SmallVector nestedControlledIdentity(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledIdentity(QCOProgramBuilder& b) { +Value trivialControlledIdentity(QCOProgramBuilder& b) { auto q = b.allocQubit(); auto res = b.mcid({}, q); q = res.second; - return measureAndReturn(b, {q}); + return b.measure(q).second; } -SmallVector inverseIdentity(QCOProgramBuilder& b) { +Value inverseIdentity(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.id(qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledIdentity(QCOProgramBuilder& b) { @@ -423,10 +423,10 @@ SmallVector inverseMultipleControlledIdentity(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector x(QCOProgramBuilder& b) { +Value x(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.x(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledX(QCOProgramBuilder& b) { @@ -457,11 +457,11 @@ SmallVector nestedControlledX(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledX(QCOProgramBuilder& b) { +Value trivialControlledX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcx({}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector repeatedControlledX(QCOProgramBuilder& b) { @@ -479,10 +479,10 @@ SmallVector repeatedControlledX(QCOProgramBuilder& b) { SmallVector(targets.begin(), targets.end())); } -SmallVector inverseX(QCOProgramBuilder& b) { +Value inverseX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.x(qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledX(QCOProgramBuilder& b) { @@ -499,11 +499,11 @@ SmallVector inverseMultipleControlledX(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector twoX(QCOProgramBuilder& b) { +Value twoX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.x(q[0]); q[0] = b.x(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector controlledTwoX(QCOProgramBuilder& b) { @@ -515,47 +515,47 @@ SmallVector controlledTwoX(QCOProgramBuilder& b) { return measureAndReturn(b, {res.first, res.second}); } -SmallVector inverseTwoX(QCOProgramBuilder& b) { +Value inverseTwoX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { qubit = b.x(qubit); qubit = b.x(qubit); return qubit; }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } -SmallVector inverseGphaseX(QCOProgramBuilder& b) { +Value inverseGphaseX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { b.gphase(-0.123); return b.x(qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } -SmallVector inverseGphaseBarrier(QCOProgramBuilder& b) { +Value inverseGphaseBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { b.gphase(0.123); return b.barrier({qubit})[0]; }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } -SmallVector inverseTwoBarriersInInv(QCOProgramBuilder& b) { +Value inverseTwoBarriersInInv(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { qubit = b.barrier({qubit})[0]; return b.barrier({qubit})[0]; }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } -SmallVector y(QCOProgramBuilder& b) { +Value y(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.y(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledY(QCOProgramBuilder& b) { @@ -586,17 +586,17 @@ SmallVector nestedControlledY(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledY(QCOProgramBuilder& b) { +Value trivialControlledY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcy({}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseY(QCOProgramBuilder& b) { +Value inverseY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.y(qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledY(QCOProgramBuilder& b) { @@ -613,17 +613,17 @@ SmallVector inverseMultipleControlledY(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector twoY(QCOProgramBuilder& b) { +Value twoY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.y(q[0]); q[0] = b.y(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector z(QCOProgramBuilder& b) { +Value z(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.z(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledZ(QCOProgramBuilder& b) { @@ -654,17 +654,17 @@ SmallVector nestedControlledZ(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledZ(QCOProgramBuilder& b) { +Value trivialControlledZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcz({}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseZ(QCOProgramBuilder& b) { +Value inverseZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.z(qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledZ(QCOProgramBuilder& b) { @@ -681,17 +681,17 @@ SmallVector inverseMultipleControlledZ(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector twoZ(QCOProgramBuilder& b) { +Value twoZ(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.z(q[0]); q[0] = b.z(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector h(QCOProgramBuilder& b) { +Value h(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.h(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledH(QCOProgramBuilder& b) { @@ -722,17 +722,17 @@ SmallVector nestedControlledH(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledH(QCOProgramBuilder& b) { +Value trivialControlledH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mch({}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseH(QCOProgramBuilder& b) { +Value inverseH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.h(qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledH(QCOProgramBuilder& b) { @@ -749,23 +749,23 @@ SmallVector inverseMultipleControlledH(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector twoH(QCOProgramBuilder& b) { +Value twoH(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.h(q); q = b.h(q); - return measureAndReturn(b, {q}); + return b.measure(q).second; } -SmallVector hWithoutRegister(QCOProgramBuilder& b) { +Value hWithoutRegister(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.h(q); - return measureAndReturn(b, {q}); + return b.measure(q).second; } -SmallVector s(QCOProgramBuilder& b) { +Value s(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.s(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledS(QCOProgramBuilder& b) { @@ -798,17 +798,17 @@ SmallVector nestedControlledS(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledS(QCOProgramBuilder& b) { +Value trivialControlledS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcs({}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseS(QCOProgramBuilder& b) { +Value inverseS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.s(qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledS(QCOProgramBuilder& b) { @@ -825,24 +825,24 @@ SmallVector inverseMultipleControlledS(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector sThenSdg(QCOProgramBuilder& b) { +Value sThenSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.s(q[0]); q[0] = b.sdg(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector twoS(QCOProgramBuilder& b) { +Value twoS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.s(q[0]); q[0] = b.s(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector sdg(QCOProgramBuilder& b) { +Value sdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sdg(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledSdg(QCOProgramBuilder& b) { @@ -875,17 +875,17 @@ SmallVector nestedControlledSdg(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledSdg(QCOProgramBuilder& b) { +Value trivialControlledSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcsdg({}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseSdg(QCOProgramBuilder& b) { +Value inverseSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.sdg(qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledSdg(QCOProgramBuilder& b) { @@ -902,24 +902,24 @@ SmallVector inverseMultipleControlledSdg(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector sdgThenS(QCOProgramBuilder& b) { +Value sdgThenS(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sdg(q[0]); q[0] = b.s(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector twoSdg(QCOProgramBuilder& b) { +Value twoSdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sdg(q[0]); q[0] = b.sdg(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector t_(QCOProgramBuilder& b) { +Value t_(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.t(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledT(QCOProgramBuilder& b) { @@ -952,17 +952,17 @@ SmallVector nestedControlledT(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledT(QCOProgramBuilder& b) { +Value trivialControlledT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mct({}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseT(QCOProgramBuilder& b) { +Value inverseT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.t(qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledT(QCOProgramBuilder& b) { @@ -979,24 +979,24 @@ SmallVector inverseMultipleControlledT(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector tThenTdg(QCOProgramBuilder& b) { +Value tThenTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.t(q[0]); q[0] = b.tdg(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector twoT(QCOProgramBuilder& b) { +Value twoT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.t(q[0]); q[0] = b.t(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector tdg(QCOProgramBuilder& b) { +Value tdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.tdg(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledTdg(QCOProgramBuilder& b) { @@ -1029,17 +1029,17 @@ SmallVector nestedControlledTdg(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledTdg(QCOProgramBuilder& b) { +Value trivialControlledTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mctdg({}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseTdg(QCOProgramBuilder& b) { +Value inverseTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.tdg(qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledTdg(QCOProgramBuilder& b) { @@ -1056,24 +1056,24 @@ SmallVector inverseMultipleControlledTdg(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector tdgThenT(QCOProgramBuilder& b) { +Value tdgThenT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.tdg(q[0]); q[0] = b.t(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector twoTdg(QCOProgramBuilder& b) { +Value twoTdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.tdg(q[0]); q[0] = b.tdg(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector sx(QCOProgramBuilder& b) { +Value sx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sx(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledSx(QCOProgramBuilder& b) { @@ -1106,17 +1106,17 @@ SmallVector nestedControlledSx(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledSx(QCOProgramBuilder& b) { +Value trivialControlledSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcsx({}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseSx(QCOProgramBuilder& b) { +Value inverseSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.sx(qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledSx(QCOProgramBuilder& b) { @@ -1133,24 +1133,24 @@ SmallVector inverseMultipleControlledSx(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector sxThenSxdg(QCOProgramBuilder& b) { +Value sxThenSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sx(q[0]); q[0] = b.sxdg(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector twoSx(QCOProgramBuilder& b) { +Value twoSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sx(q[0]); q[0] = b.sx(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector sxdg(QCOProgramBuilder& b) { +Value sxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sxdg(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledSxdg(QCOProgramBuilder& b) { @@ -1183,17 +1183,17 @@ SmallVector nestedControlledSxdg(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledSxdg(QCOProgramBuilder& b) { +Value trivialControlledSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcsxdg({}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseSxdg(QCOProgramBuilder& b) { +Value inverseSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.sxdg(qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledSxdg(QCOProgramBuilder& b) { @@ -1210,24 +1210,24 @@ SmallVector inverseMultipleControlledSxdg(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector sxdgThenSx(QCOProgramBuilder& b) { +Value sxdgThenSx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sxdg(q[0]); q[0] = b.sx(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector twoSxdg(QCOProgramBuilder& b) { +Value twoSxdg(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.sxdg(q[0]); q[0] = b.sxdg(q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector rx(QCOProgramBuilder& b) { +Value rx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rx(0.123, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledRx(QCOProgramBuilder& b) { @@ -1261,17 +1261,17 @@ SmallVector nestedControlledRx(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledRx(QCOProgramBuilder& b) { +Value trivialControlledRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcrx(0.123, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseRx(QCOProgramBuilder& b) { +Value inverseRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.rx(-0.123, qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledRx(QCOProgramBuilder& b) { @@ -1288,23 +1288,23 @@ SmallVector inverseMultipleControlledRx(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector twoRxOppositePhase(QCOProgramBuilder& b) { +Value twoRxOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rx(0.123, q[0]); q[0] = b.rx(-0.123, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector rxPiOver2(QCOProgramBuilder& b) { +Value rxPiOver2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rx(std::numbers::pi / 2, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector ry(QCOProgramBuilder& b) { +Value ry(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.ry(0.456, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledRy(QCOProgramBuilder& b) { @@ -1336,17 +1336,17 @@ SmallVector nestedControlledRy(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledRy(QCOProgramBuilder& b) { +Value trivialControlledRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcry(0.456, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseRy(QCOProgramBuilder& b) { +Value inverseRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.ry(-0.456, qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledRy(QCOProgramBuilder& b) { @@ -1363,23 +1363,23 @@ SmallVector inverseMultipleControlledRy(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector twoRyOppositePhase(QCOProgramBuilder& b) { +Value twoRyOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.ry(0.456, q[0]); q[0] = b.ry(-0.456, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector ryPiOver2(QCOProgramBuilder& b) { +Value ryPiOver2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.ry(std::numbers::pi / 2, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector rz(QCOProgramBuilder& b) { +Value rz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rz(0.789, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledRz(QCOProgramBuilder& b) { @@ -1411,17 +1411,17 @@ SmallVector nestedControlledRz(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledRz(QCOProgramBuilder& b) { +Value trivialControlledRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcrz(0.789, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseRz(QCOProgramBuilder& b) { +Value inverseRz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.rz(-0.789, qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledRz(QCOProgramBuilder& b) { @@ -1438,17 +1438,17 @@ SmallVector inverseMultipleControlledRz(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector twoRzOppositePhase(QCOProgramBuilder& b) { +Value twoRzOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.rz(0.789, q[0]); q[0] = b.rz(-0.789, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector p(QCOProgramBuilder& b) { +Value p(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.p(0.123, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledP(QCOProgramBuilder& b) { @@ -1480,17 +1480,17 @@ SmallVector nestedControlledP(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledP(QCOProgramBuilder& b) { +Value trivialControlledP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcp(0.123, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseP(QCOProgramBuilder& b) { +Value inverseP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.p(-0.123, qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledP(QCOProgramBuilder& b) { @@ -1507,17 +1507,17 @@ SmallVector inverseMultipleControlledP(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector twoPOppositePhase(QCOProgramBuilder& b) { +Value twoPOppositePhase(QCOProgramBuilder& b) { auto q = b.allocQubit(); q = b.p(0.123, q); q = b.p(-0.123, q); - return measureAndReturn(b, {q}); + return b.measure(q).second; } -SmallVector r(QCOProgramBuilder& b) { +Value r(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.r(0.123, 0.456, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledR(QCOProgramBuilder& b) { @@ -1549,18 +1549,18 @@ SmallVector nestedControlledR(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledR(QCOProgramBuilder& b) { +Value trivialControlledR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcr(0.123, 0.456, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseR(QCOProgramBuilder& b) { +Value inverseR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.r(-0.123, 0.456, qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledR(QCOProgramBuilder& b) { @@ -1577,29 +1577,29 @@ SmallVector inverseMultipleControlledR(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector canonicalizeRToRx(QCOProgramBuilder& b) { +Value canonicalizeRToRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.r(0.123, 0., q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector canonicalizeRToRy(QCOProgramBuilder& b) { +Value canonicalizeRToRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.r(0.456, std::numbers::pi / 2, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector twoR(QCOProgramBuilder& b) { +Value twoR(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.r(0.045, 0.456, q[0]); q[0] = b.r(0.078, 0.456, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector u2(QCOProgramBuilder& b) { +Value u2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u2(0.234, 0.567, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledU2(QCOProgramBuilder& b) { @@ -1631,19 +1631,19 @@ SmallVector nestedControlledU2(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledU2(QCOProgramBuilder& b) { +Value trivialControlledU2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcu2(0.234, 0.567, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseU2(QCOProgramBuilder& b) { +Value inverseU2(QCOProgramBuilder& b) { constexpr double pi = std::numbers::pi; auto q = b.allocQubitRegister(1); auto res = b.inv( q[0], [&](Value qubit) { return b.u2(-0.567 + pi, -0.234 - pi, qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledU2(QCOProgramBuilder& b) { @@ -1661,28 +1661,28 @@ SmallVector inverseMultipleControlledU2(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector canonicalizeU2ToH(QCOProgramBuilder& b) { +Value canonicalizeU2ToH(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u2(0., std::numbers::pi, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector canonicalizeU2ToRx(QCOProgramBuilder& b) { +Value canonicalizeU2ToRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u2(-std::numbers::pi / 2, std::numbers::pi / 2, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector canonicalizeU2ToRy(QCOProgramBuilder& b) { +Value canonicalizeU2ToRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u2(0., 0., q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector u(QCOProgramBuilder& b) { +Value u(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u(0.1, 0.2, 0.3, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector singleControlledU(QCOProgramBuilder& b) { @@ -1714,18 +1714,18 @@ SmallVector nestedControlledU(QCOProgramBuilder& b) { return measureAndReturn(b, reg.qubits); } -SmallVector trivialControlledU(QCOProgramBuilder& b) { +Value trivialControlledU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.mcu(0.1, 0.2, 0.3, {}, q[0]); q[0] = res.second; - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector inverseU(QCOProgramBuilder& b) { +Value inverseU(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.u(-0.1, -0.3, -0.2, qubit); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseMultipleControlledU(QCOProgramBuilder& b) { @@ -1742,28 +1742,28 @@ SmallVector inverseMultipleControlledU(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector canonicalizeUToP(QCOProgramBuilder& b) { +Value canonicalizeUToP(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u(0., 0., 0.123, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector canonicalizeUToRx(QCOProgramBuilder& b) { +Value canonicalizeUToRx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u(0.123, -std::numbers::pi / 2, std::numbers::pi / 2, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector canonicalizeUToRy(QCOProgramBuilder& b) { +Value canonicalizeUToRy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u(0.456, 0., 0., q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } -SmallVector canonicalizeUToU2(QCOProgramBuilder& b) { +Value canonicalizeUToU2(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); q[0] = b.u(std::numbers::pi / 2, 0.234, 0.567, q[0]); - return measureAndReturn(b, q.qubits); + return b.measure(q[0]).second; } SmallVector swap(QCOProgramBuilder& b) { @@ -1783,47 +1783,47 @@ SmallVector singleControlledSwap(QCOProgramBuilder& b) { SmallVector multipleControlledSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - auto res = b.mcswap({q[0], q[1]}, q[2], q[3]); - q[0] = res.first[0]; - q[1] = res.first[1]; - q[2] = res.second.first; - q[3] = res.second.second; + auto [c, t] = b.mcswap({q[0], q[1]}, q[2], q[3]); + q[0] = c[0]; + q[1] = c[1]; + q[2] = t.first; + q[3] = t.second; return measureAndReturn(b, q.qubits); } SmallVector nestedControlledSwap(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - auto res = + auto [c, t] = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.swap(innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.swap(innerTargets[0], innerTargets[1]); + return SmallVector{fst, snd}; }); return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); - reg[0] = res.first[0]; - reg[1] = res.second[0]; - reg[2] = res.second[1]; - reg[3] = res.second[2]; + reg[0] = c[0]; + reg[1] = t[0]; + reg[2] = t[1]; + reg[3] = t[2]; return measureAndReturn(b, reg.qubits); } SmallVector trivialControlledSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto res = b.mcswap({}, q[0], q[1]); - q[0] = res.second.first; - q[1] = res.second.second; + auto [c, t] = b.mcswap({}, q[0], q[1]); + q[0] = t.first; + q[1] = t.second; return measureAndReturn(b, q.qubits); } SmallVector inverseSwap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { - auto res = b.swap(qubits[0], qubits[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.swap(qubits[0], qubits[1]); + return SmallVector{fst, snd}; }); q[0] = res[0]; q[1] = res[1]; @@ -1867,56 +1867,57 @@ SmallVector iswap(QCOProgramBuilder& b) { SmallVector singleControlledIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - auto res = b.ciswap(q[0], q[1], q[2]); - q[0] = res.first; - q[1] = res.second.first; - q[2] = res.second.second; + auto [c, t] = b.ciswap(q[0], q[1], q[2]); + q[0] = c; + q[1] = t.first; + q[2] = t.second; return measureAndReturn(b, q.qubits); } SmallVector multipleControlledIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - auto res = b.mciswap({q[0], q[1]}, q[2], q[3]); - q[0] = res.first[0]; - q[1] = res.first[1]; - q[2] = res.second.first; - q[3] = res.second.second; + auto [c, t] = b.mciswap({q[0], q[1]}, q[2], q[3]); + q[0] = c[0]; + q[1] = c[1]; + q[2] = t.first; + q[3] = t.second; return measureAndReturn(b, q.qubits); } SmallVector nestedControlledIswap(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - auto res = + auto [c, t] = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.iswap(innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = + b.iswap(innerTargets[0], innerTargets[1]); + return SmallVector{fst, snd}; }); return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); - reg[0] = res.first[0]; - reg[1] = res.second[0]; - reg[2] = res.second[1]; - reg[3] = res.second[2]; + reg[0] = c[0]; + reg[1] = t[0]; + reg[2] = t[1]; + reg[3] = t[2]; return measureAndReturn(b, reg.qubits); } SmallVector trivialControlledIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto res = b.mciswap({}, q[0], q[1]); - q[0] = res.second.first; - q[1] = res.second.second; + auto [c, t] = b.mciswap({}, q[0], q[1]); + q[0] = t.first; + q[1] = t.second; return measureAndReturn(b, q.qubits); } SmallVector inverseIswap(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { - auto res = b.iswap(qubits[0], qubits[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.iswap(qubits[0], qubits[1]); + return SmallVector{fst, snd}; }); q[0] = res[0]; q[1] = res[1]; @@ -1946,56 +1947,56 @@ SmallVector dcx(QCOProgramBuilder& b) { SmallVector singleControlledDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - auto res = b.cdcx(q[0], q[1], q[2]); - q[0] = res.first; - q[1] = res.second.first; - q[2] = res.second.second; + auto [c, t] = b.cdcx(q[0], q[1], q[2]); + q[0] = c; + q[1] = t.first; + q[2] = t.second; return measureAndReturn(b, q.qubits); } SmallVector multipleControlledDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - auto res = b.mcdcx({q[0], q[1]}, q[2], q[3]); - q[0] = res.first[0]; - q[1] = res.first[1]; - q[2] = res.second.first; - q[3] = res.second.second; + auto [c, t] = b.mcdcx({q[0], q[1]}, q[2], q[3]); + q[0] = c[0]; + q[1] = c[1]; + q[2] = t.first; + q[3] = t.second; return measureAndReturn(b, q.qubits); } SmallVector nestedControlledDcx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - auto res = + auto [c, t] = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.dcx(innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.dcx(innerTargets[0], innerTargets[1]); + return SmallVector{fst, snd}; }); return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); - reg[0] = res.first[0]; - reg[1] = res.second[0]; - reg[2] = res.second[1]; - reg[3] = res.second[2]; + reg[0] = c[0]; + reg[1] = t[0]; + reg[2] = t[1]; + reg[3] = t[2]; return measureAndReturn(b, reg.qubits); } SmallVector trivialControlledDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto res = b.mcdcx({}, q[0], q[1]); - q[0] = res.second.first; - q[1] = res.second.second; + auto [c, t] = b.mcdcx({}, q[0], q[1]); + q[0] = t.first; + q[1] = t.second; return measureAndReturn(b, q.qubits); } SmallVector inverseDcx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[1], q[0]}, [&](ValueRange qubits) { - auto res = b.dcx(qubits[0], qubits[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.dcx(qubits[0], qubits[1]); + return SmallVector{fst, snd}; }); q[1] = res[0]; q[0] = res[1]; @@ -2039,56 +2040,56 @@ SmallVector ecr(QCOProgramBuilder& b) { SmallVector singleControlledEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - auto res = b.cecr(q[0], q[1], q[2]); - q[0] = res.first; - q[1] = res.second.first; - q[2] = res.second.second; + auto [c, t] = b.cecr(q[0], q[1], q[2]); + q[0] = c; + q[1] = t.first; + q[2] = t.second; return measureAndReturn(b, q.qubits); } SmallVector multipleControlledEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - auto res = b.mcecr({q[0], q[1]}, q[2], q[3]); - q[0] = res.first[0]; - q[1] = res.first[1]; - q[2] = res.second.first; - q[3] = res.second.second; + auto [fst, snd] = b.mcecr({q[0], q[1]}, q[2], q[3]); + q[0] = fst[0]; + q[1] = fst[1]; + q[2] = snd.first; + q[3] = snd.second; return measureAndReturn(b, q.qubits); } SmallVector nestedControlledEcr(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - auto res = + auto [c, t] = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.ecr(innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.ecr(innerTargets[0], innerTargets[1]); + return SmallVector{fst, snd}; }); return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); - reg[0] = res.first[0]; - reg[1] = res.second[0]; - reg[2] = res.second[1]; - reg[3] = res.second[2]; + reg[0] = c[0]; + reg[1] = t[0]; + reg[2] = t[1]; + reg[3] = t[2]; return measureAndReturn(b, reg.qubits); } SmallVector trivialControlledEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto res = b.mcecr({}, q[0], q[1]); - q[0] = res.second.first; - q[1] = res.second.second; + auto [c, t] = b.mcecr({}, q[0], q[1]); + q[0] = t.first; + q[1] = t.second; return measureAndReturn(b, q.qubits); } SmallVector inverseEcr(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { - auto res = b.ecr(qubits[0], qubits[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.ecr(qubits[0], qubits[1]); + return SmallVector{fst, snd}; }); q[0] = res[0]; q[1] = res[1]; @@ -2125,56 +2126,57 @@ SmallVector rxx(QCOProgramBuilder& b) { SmallVector singleControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - auto res = b.crxx(0.123, q[0], q[1], q[2]); - q[0] = res.first; - q[1] = res.second.first; - q[2] = res.second.second; + auto [c, t] = b.crxx(0.123, q[0], q[1], q[2]); + q[0] = c; + q[1] = t.first; + q[2] = t.second; return measureAndReturn(b, q.qubits); } SmallVector multipleControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - auto res = b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); - q[0] = res.first[0]; - q[1] = res.first[1]; - q[2] = res.second.first; - q[3] = res.second.second; + auto [c, t] = b.mcrxx(0.123, {q[0], q[1]}, q[2], q[3]); + q[0] = c[0]; + q[1] = c[1]; + q[2] = t.first; + q[3] = t.second; return measureAndReturn(b, q.qubits); } SmallVector nestedControlledRxx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - auto res = + auto [c, t] = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.rxx(0.123, innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = + b.rxx(0.123, innerTargets[0], innerTargets[1]); + return SmallVector{fst, snd}; }); return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); - reg[0] = res.first[0]; - reg[1] = res.second[0]; - reg[2] = res.second[1]; - reg[3] = res.second[2]; + reg[0] = c[0]; + reg[1] = t[0]; + reg[2] = t[1]; + reg[3] = t[2]; return measureAndReturn(b, reg.qubits); } SmallVector trivialControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto res = b.mcrxx(0.123, {}, q[0], q[1]); - q[0] = res.second.first; - q[1] = res.second.second; + auto [c, t] = b.mcrxx(0.123, {}, q[0], q[1]); + q[0] = t.first; + q[1] = t.second; return measureAndReturn(b, q.qubits); } SmallVector inverseRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { - auto res = b.rxx(-0.123, qubits[0], qubits[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.rxx(-0.123, qubits[0], qubits[1]); + return SmallVector{fst, snd}; }); q[0] = res[0]; q[1] = res[1]; @@ -2198,24 +2200,24 @@ SmallVector inverseMultipleControlledRxx(QCOProgramBuilder& b) { SmallVector tripleControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(5); - auto res = b.mcrxx(0.123, {q[0], q[1], q[2]}, q[3], q[4]); - q[0] = res.first[0]; - q[1] = res.first[1]; - q[2] = res.first[2]; - q[3] = res.second.first; - q[4] = res.second.second; + auto [c, t] = b.mcrxx(0.123, {q[0], q[1], q[2]}, q[3], q[4]); + q[0] = c[0]; + q[1] = c[1]; + q[2] = c[2]; + q[3] = t.first; + q[4] = t.second; return measureAndReturn(b, q.qubits); } SmallVector fourControlledRxx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(6); - auto res = b.mcrxx(0.123, {q[0], q[1], q[2], q[3]}, q[4], q[5]); - q[0] = res.first[0]; - q[1] = res.first[1]; - q[2] = res.first[2]; - q[3] = res.first[3]; - q[4] = res.second.first; - q[5] = res.second.second; + auto [c, t] = b.mcrxx(0.123, {q[0], q[1], q[2], q[3]}, q[4], q[5]); + q[0] = c[0]; + q[1] = c[1]; + q[2] = c[2]; + q[3] = c[3]; + q[4] = t.first; + q[5] = t.second; return measureAndReturn(b, q.qubits); } @@ -2257,56 +2259,57 @@ SmallVector ryy(QCOProgramBuilder& b) { SmallVector singleControlledRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - auto res = b.cryy(0.123, q[0], q[1], q[2]); - q[0] = res.first; - q[1] = res.second.first; - q[2] = res.second.second; + auto [c, t] = b.cryy(0.123, q[0], q[1], q[2]); + q[0] = c; + q[1] = t.first; + q[2] = t.second; return measureAndReturn(b, q.qubits); } SmallVector multipleControlledRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - auto res = b.mcryy(0.123, {q[0], q[1]}, q[2], q[3]); - q[0] = res.first[0]; - q[1] = res.first[1]; - q[2] = res.second.first; - q[3] = res.second.second; + auto [c, t] = b.mcryy(0.123, {q[0], q[1]}, q[2], q[3]); + q[0] = c[0]; + q[1] = c[1]; + q[2] = t.first; + q[3] = t.second; return measureAndReturn(b, q.qubits); } SmallVector nestedControlledRyy(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - auto res = + auto [c, t] = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.ryy(0.123, innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = + b.ryy(0.123, innerTargets[0], innerTargets[1]); + return SmallVector{fst, snd}; }); return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); - reg[0] = res.first[0]; - reg[1] = res.second[0]; - reg[2] = res.second[1]; - reg[3] = res.second[2]; + reg[0] = c[0]; + reg[1] = t[0]; + reg[2] = t[1]; + reg[3] = t[2]; return measureAndReturn(b, reg.qubits); } SmallVector trivialControlledRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto res = b.mcryy(0.123, {}, q[0], q[1]); - q[0] = res.second.first; - q[1] = res.second.second; + auto [c, t] = b.mcryy(0.123, {}, q[0], q[1]); + q[0] = t.first; + q[1] = t.second; return measureAndReturn(b, q.qubits); } SmallVector inverseRyy(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { - auto res = b.ryy(-0.123, qubits[0], qubits[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.ryy(-0.123, qubits[0], qubits[1]); + return SmallVector{fst, snd}; }); q[0] = res[0]; q[1] = res[1]; @@ -2366,56 +2369,57 @@ SmallVector rzx(QCOProgramBuilder& b) { SmallVector singleControlledRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - auto res = b.crzx(0.123, q[0], q[1], q[2]); - q[0] = res.first; - q[1] = res.second.first; - q[2] = res.second.second; + auto [c, t] = b.crzx(0.123, q[0], q[1], q[2]); + q[0] = c; + q[1] = t.first; + q[2] = t.second; return measureAndReturn(b, q.qubits); } SmallVector multipleControlledRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - auto res = b.mcrzx(0.123, {q[0], q[1]}, q[2], q[3]); - q[0] = res.first[0]; - q[1] = res.first[1]; - q[2] = res.second.first; - q[3] = res.second.second; + auto [c, t] = b.mcrzx(0.123, {q[0], q[1]}, q[2], q[3]); + q[0] = c[0]; + q[1] = c[1]; + q[2] = t.first; + q[3] = t.second; return measureAndReturn(b, q.qubits); } SmallVector nestedControlledRzx(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - auto res = + auto [c, t] = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.rzx(0.123, innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = + b.rzx(0.123, innerTargets[0], innerTargets[1]); + return SmallVector{fst, snd}; }); return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); - reg[0] = res.first[0]; - reg[1] = res.second[0]; - reg[2] = res.second[1]; - reg[3] = res.second[2]; + reg[0] = c[0]; + reg[1] = t[0]; + reg[2] = t[1]; + reg[3] = t[2]; return measureAndReturn(b, reg.qubits); } SmallVector trivialControlledRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto res = b.mcrzx(0.123, {}, q[0], q[1]); - q[0] = res.second.first; - q[1] = res.second.second; + auto [c, t] = b.mcrzx(0.123, {}, q[0], q[1]); + q[0] = t.first; + q[1] = t.second; return measureAndReturn(b, q.qubits); } SmallVector inverseRzx(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { - auto res = b.rzx(-0.123, qubits[0], qubits[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.rzx(-0.123, qubits[0], qubits[1]); + return SmallVector{fst, snd}; }); q[0] = res[0]; q[1] = res[1]; @@ -2452,56 +2456,57 @@ SmallVector rzz(QCOProgramBuilder& b) { SmallVector singleControlledRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - auto res = b.crzz(0.123, q[0], q[1], q[2]); - q[0] = res.first; - q[1] = res.second.first; - q[2] = res.second.second; + auto [c, t] = b.crzz(0.123, q[0], q[1], q[2]); + q[0] = c; + q[1] = t.first; + q[2] = t.second; return measureAndReturn(b, q.qubits); } SmallVector multipleControlledRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - auto res = b.mcrzz(0.123, {q[0], q[1]}, q[2], q[3]); - q[0] = res.first[0]; - q[1] = res.first[1]; - q[2] = res.second.first; - q[3] = res.second.second; + auto [c, t] = b.mcrzz(0.123, {q[0], q[1]}, q[2], q[3]); + q[0] = c[0]; + q[1] = c[1]; + q[2] = t.first; + q[3] = t.second; return measureAndReturn(b, q.qubits); } SmallVector nestedControlledRzz(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - auto res = + auto [c, t] = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.rzz(0.123, innerTargets[0], innerTargets[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = + b.rzz(0.123, innerTargets[0], innerTargets[1]); + return SmallVector{fst, snd}; }); return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); - reg[0] = res.first[0]; - reg[1] = res.second[0]; - reg[2] = res.second[1]; - reg[3] = res.second[2]; + reg[0] = c[0]; + reg[1] = t[0]; + reg[2] = t[1]; + reg[3] = t[2]; return measureAndReturn(b, reg.qubits); } SmallVector trivialControlledRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto res = b.mcrzz(0.123, {}, q[0], q[1]); - q[0] = res.second.first; - q[1] = res.second.second; + auto [c, t] = b.mcrzz(0.123, {}, q[0], q[1]); + q[0] = t.first; + q[1] = t.second; return measureAndReturn(b, q.qubits); } SmallVector inverseRzz(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { - auto res = b.rzz(-0.123, qubits[0], qubits[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.rzz(-0.123, qubits[0], qubits[1]); + return SmallVector{fst, snd}; }); q[0] = res[0]; q[1] = res[1]; @@ -2561,57 +2566,57 @@ SmallVector xxPlusYY(QCOProgramBuilder& b) { SmallVector singleControlledXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - auto res = b.cxx_plus_yy(0.123, 0.456, q[0], q[1], q[2]); - q[0] = res.first; - q[1] = res.second.first; - q[2] = res.second.second; + auto [c, t] = b.cxx_plus_yy(0.123, 0.456, q[0], q[1], q[2]); + q[0] = c; + q[1] = t.first; + q[2] = t.second; return measureAndReturn(b, q.qubits); } SmallVector multipleControlledXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - auto res = b.mcxx_plus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); - q[0] = res.first[0]; - q[1] = res.first[1]; - q[2] = res.second.first; - q[3] = res.second.second; + auto [c, t] = b.mcxx_plus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); + q[0] = c[0]; + q[1] = c[1]; + q[2] = t.first; + q[3] = t.second; return measureAndReturn(b, q.qubits); } SmallVector nestedControlledXxPlusYY(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - auto res = + auto [c, t] = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.xx_plus_yy(0.123, 0.456, innerTargets[0], - innerTargets[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.xx_plus_yy( + 0.123, 0.456, innerTargets[0], innerTargets[1]); + return SmallVector{fst, snd}; }); return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); - reg[0] = res.first[0]; - reg[1] = res.second[0]; - reg[2] = res.second[1]; - reg[3] = res.second[2]; + reg[0] = c[0]; + reg[1] = t[0]; + reg[2] = t[1]; + reg[3] = t[2]; return measureAndReturn(b, reg.qubits); } SmallVector trivialControlledXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto res = b.mcxx_plus_yy(0.123, 0.456, {}, q[0], q[1]); - q[0] = res.second.first; - q[1] = res.second.second; + auto [c, t] = b.mcxx_plus_yy(0.123, 0.456, {}, q[0], q[1]); + q[0] = t.first; + q[1] = t.second; return measureAndReturn(b, q.qubits); } SmallVector inverseXxPlusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { - auto res = b.xx_plus_yy(-0.123, 0.456, qubits[0], qubits[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.xx_plus_yy(-0.123, 0.456, qubits[0], qubits[1]); + return SmallVector{fst, snd}; }); q[0] = res[0]; q[1] = res[1]; @@ -2655,57 +2660,57 @@ SmallVector xxMinusYY(QCOProgramBuilder& b) { SmallVector singleControlledXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(3); - auto res = b.cxx_minus_yy(0.123, 0.456, q[0], q[1], q[2]); - q[0] = res.first; - q[1] = res.second.first; - q[2] = res.second.second; + auto [c, t] = b.cxx_minus_yy(0.123, 0.456, q[0], q[1], q[2]); + q[0] = c; + q[1] = t.first; + q[2] = t.second; return measureAndReturn(b, q.qubits); } SmallVector multipleControlledXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(4); - auto res = b.mcxx_minus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); - q[0] = res.first[0]; - q[1] = res.first[1]; - q[2] = res.second.first; - q[3] = res.second.second; + auto [c, t] = b.mcxx_minus_yy(0.123, 0.456, {q[0], q[1]}, q[2], q[3]); + q[0] = c[0]; + q[1] = c[1]; + q[2] = t.first; + q[3] = t.second; return measureAndReturn(b, q.qubits); } SmallVector nestedControlledXxMinusYY(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); - auto res = + auto [c, t] = b.ctrl({reg[0]}, {reg[1], reg[2], reg[3]}, [&](ValueRange targets) { const auto& [innerControlsOut, innerTargetsOut] = b.ctrl({targets[0]}, {targets[1], targets[2]}, [&](ValueRange innerTargets) { - auto res = b.xx_minus_yy(0.123, 0.456, innerTargets[0], - innerTargets[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.xx_minus_yy( + 0.123, 0.456, innerTargets[0], innerTargets[1]); + return SmallVector{fst, snd}; }); return llvm::to_vector( llvm::concat(innerControlsOut, innerTargetsOut)); }); - reg[0] = res.first[0]; - reg[1] = res.second[0]; - reg[2] = res.second[1]; - reg[3] = res.second[2]; + reg[0] = c[0]; + reg[1] = t[0]; + reg[2] = t[1]; + reg[3] = t[2]; return measureAndReturn(b, reg.qubits); } SmallVector trivialControlledXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); - auto res = b.mcxx_minus_yy(0.123, 0.456, {}, q[0], q[1]); - q[0] = res.second.first; - q[1] = res.second.second; + auto [c, t] = b.mcxx_minus_yy(0.123, 0.456, {}, q[0], q[1]); + q[0] = t.first; + q[1] = t.second; return measureAndReturn(b, q.qubits); } SmallVector inverseXxMinusYY(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.inv({q[0], q[1]}, [&](ValueRange qubits) { - auto res = b.xx_minus_yy(-0.123, 0.456, qubits[0], qubits[1]); - return SmallVector{res.first, res.second}; + auto [fst, snd] = b.xx_minus_yy(-0.123, 0.456, qubits[0], qubits[1]); + return SmallVector{fst, snd}; }); q[0] = res[0]; q[1] = res[1]; @@ -2741,10 +2746,10 @@ SmallVector twoXxMinusYYSwappedTargets(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector barrier(QCOProgramBuilder& b) { +Value barrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); - auto q1 = b.barrier(q[0]); - return measureAndReturn(b, {q1}); + q[0] = b.barrier(q[0])[0]; + return b.measure(q[0]).second; } SmallVector barrierTwoQubits(QCOProgramBuilder& b) { @@ -2764,17 +2769,17 @@ SmallVector barrierMultipleQubits(QCOProgramBuilder& b) { return measureAndReturn(b, q.qubits); } -SmallVector singleControlledBarrier(QCOProgramBuilder& b) { +Value singleControlledBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(2); auto res = b.ctrl(q[1], q[0], [&](Value target) { return b.barrier({target})[0]; }); - return measureAndReturn(b, {res.second}); + return b.measure(res.second).second; } -SmallVector inverseBarrier(QCOProgramBuilder& b) { +Value inverseBarrier(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value qubit) { return b.barrier({qubit})[0]; }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector twoBarrier(QCOProgramBuilder& b) { @@ -3055,7 +3060,7 @@ SmallVector simpleIf(QCOProgramBuilder& b) { return {measureResult, bit}; } -SmallVector ifWithAngle(QCOProgramBuilder& b) { +Value ifWithAngle(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto theta = b.floatConstant(0.123); auto q0 = b.h(q[0]); @@ -3064,7 +3069,7 @@ SmallVector ifWithAngle(QCOProgramBuilder& b) { auto innerQubit = b.rx(theta, args[0]); return SmallVector{innerQubit}; })[0]; - return measureAndReturn(b, {q0}); + return b.measure(q0).second; } SmallVector ifTwoQubits(QCOProgramBuilder& b) { @@ -3103,7 +3108,7 @@ SmallVector ifElse(QCOProgramBuilder& b) { return {measureResult, c0}; } -SmallVector ifOneQubitOneTensor(QCOProgramBuilder& b) { +Value ifOneQubitOneTensor(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto t0 = b.allocQubitRegister(1); auto q1 = b.h(q0); @@ -3116,10 +3121,10 @@ SmallVector ifOneQubitOneTensor(QCOProgramBuilder& b) { auto t2 = b.qtensorInsert(innerQubit2, t1, 0); return SmallVector{innerQubit0, t2}; }); - return measureAndReturn(b, {ifRes[0]}); + return b.measure(ifRes[0]).second; } -SmallVector constantTrueIf(QCOProgramBuilder& b) { +Value constantTrueIf(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto ifRes = b.qcoIf( true, q.qubits, @@ -3131,10 +3136,10 @@ SmallVector constantTrueIf(QCOProgramBuilder& b) { auto innerQubit = b.z(args[0]); return SmallVector{innerQubit}; }); - return measureAndReturn(b, {ifRes[0]}); + return b.measure(ifRes[0]).second; } -SmallVector constantFalseIf(QCOProgramBuilder& b) { +Value constantFalseIf(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto ifRes = b.qcoIf( false, q.qubits, @@ -3146,7 +3151,7 @@ SmallVector constantFalseIf(QCOProgramBuilder& b) { auto innerQubit = b.z(args[0]); return SmallVector{innerQubit}; }); - return measureAndReturn(b, {ifRes[0]}); + return b.measure(ifRes[0]).second; } SmallVector nestedTrueIf(QCOProgramBuilder& b) { @@ -3208,10 +3213,10 @@ SmallVector qtensorFromElements(QCOProgramBuilder& b) { return measureAndReturn(b, {}); } -SmallVector qtensorExtract(QCOProgramBuilder& b) { +Value qtensorExtract(QCOProgramBuilder& b) { auto qtensor = b.qtensorAlloc(3); auto [t, q] = b.qtensorExtract(qtensor, 0); - return measureAndReturn(b, {q}); + return b.measure(q).second; } SmallVector qtensorInsert(QCOProgramBuilder& b) { @@ -3296,7 +3301,7 @@ SmallVector qtensorAlternativeChain(QCOProgramBuilder& b) { return measureAndReturn(b, {}); } -SmallVector simpleWhileReset(QCOProgramBuilder& b) { +Value simpleWhileReset(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto q1 = b.h(q0); auto scfWhile = b.scfWhile( @@ -3310,10 +3315,10 @@ SmallVector simpleWhileReset(QCOProgramBuilder& b) { auto q3 = b.h(iterArgs[0]); return SmallVector{q3}; }); - return measureAndReturn(b, {scfWhile[0]}); + return b.measure(scfWhile[0]).second; } -SmallVector simpleDoWhileReset(QCOProgramBuilder& b) { +Value simpleDoWhileReset(QCOProgramBuilder& b) { auto q0 = b.allocQubit(); auto scfWhile = b.scfWhile( ValueRange{q0}, @@ -3324,7 +3329,7 @@ SmallVector simpleDoWhileReset(QCOProgramBuilder& b) { return SmallVector{q2}; }, [&](ValueRange iterArgs) { return llvm::to_vector(iterArgs); }); - return measureAndReturn(b, {scfWhile[0]}); + return b.measure(scfWhile[0]).second; } SmallVector simpleForLoop(QCOProgramBuilder& b) { @@ -3339,7 +3344,7 @@ SmallVector simpleForLoop(QCOProgramBuilder& b) { return measureAndReturnQTensor(b, scfFor[0], 2); }; -SmallVector forLoopWithAngle(QCOProgramBuilder& b) { +Value forLoopWithAngle(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto theta = b.floatConstant(0.123); auto scfFor = @@ -3350,10 +3355,10 @@ SmallVector forLoopWithAngle(QCOProgramBuilder& b) { return SmallVector{insert}; }); auto [newReg, q] = b.qtensorExtract(scfFor[0], 0); - return measureAndReturn(b, {q}); + return b.measure(q).second; } -SmallVector nestedForLoopIfOp(QCOProgramBuilder& b) { +Value nestedForLoopIfOp(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(2); auto q0 = b.allocQubit(); auto scfFor = @@ -3368,7 +3373,7 @@ SmallVector nestedForLoopIfOp(QCOProgramBuilder& b) { }); return SmallVector{ifOp[0], q2}; }); - return measureAndReturn(b, {scfFor[1]}); + return b.measure(scfFor[1]).second; } SmallVector nestedForLoopWhileOp(QCOProgramBuilder& b) { @@ -3385,13 +3390,13 @@ SmallVector nestedForLoopWhileOp(QCOProgramBuilder& b) { auto [t0, q0] = b.qtensorExtract(iterArgs[0], iv); auto whileResult = b.scfWhile( q0, - [&](ValueRange iterArgs) { - auto [q1, measureResult] = b.measure(iterArgs[0]); + [&](ValueRange innerIterArgs) { + auto [q1, measureResult] = b.measure(innerIterArgs[0]); b.scfCondition(measureResult, q1); return SmallVector{q1}; }, - [&](ValueRange iterArgs) { - auto q2 = b.h(iterArgs[0]); + [&](ValueRange innerIterArgs) { + auto q2 = b.h(innerIterArgs[0]); return SmallVector{q2}; }); auto insert = b.qtensorInsert(whileResult[0], t0, iv); @@ -3400,7 +3405,7 @@ SmallVector nestedForLoopWhileOp(QCOProgramBuilder& b) { return measureAndReturnQTensor(b, scfFor[0], 2); } -SmallVector nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b) { +Value nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto control0 = b.allocQubit(); auto control1 = b.h(control0); @@ -3413,10 +3418,10 @@ SmallVector nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b) { auto insert = b.qtensorInsert(targetOut, t0, iv); return SmallVector{insert, controlOut}; }); - return measureAndReturn(b, {scfFor[1]}); + return b.measure(scfFor[1]).second; } -SmallVector nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b) { +Value nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(4); auto control = b.h(reg[0]); auto scfFor = b.scfFor( @@ -3428,10 +3433,10 @@ SmallVector nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b) { auto insert = b.qtensorInsert(targetOut, t0, iv); return SmallVector{insert, controlOut}; }); - return measureAndReturn(b, {scfFor[1]}); + return b.measure(scfFor[1]).second; } -SmallVector nestedIfOpForLoop(QCOProgramBuilder& b) { +Value nestedIfOpForLoop(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); auto q1 = b.h(q0); @@ -3452,10 +3457,10 @@ SmallVector nestedIfOpForLoop(QCOProgramBuilder& b) { }); return SmallVector{scfFor[0], args[1]}; }); - return measureAndReturn(b, {ifRes[1]}); + return b.measure(ifRes[1]).second; } -SmallVector nestedIfOpForLoopWithAngle(QCOProgramBuilder& b) { +Value nestedIfOpForLoopWithAngle(QCOProgramBuilder& b) { auto reg = b.allocQubitRegister(3); auto q0 = b.allocQubit(); auto theta1 = b.floatConstant(0.123); @@ -3478,7 +3483,7 @@ SmallVector nestedIfOpForLoopWithAngle(QCOProgramBuilder& b) { }); return SmallVector{scfFor[0], args[1]}; }); - return measureAndReturn(b, {res[1]}); + return b.measure(res[1]).second; } SmallVector controlledXH(QCOProgramBuilder& b) { @@ -3537,7 +3542,7 @@ SmallVector inverseDcxThenRz(QCOProgramBuilder& b) { return measureAndReturn(b, res); } -SmallVector inverseGphaseBarrierX(QCOProgramBuilder& b) { +Value inverseGphaseBarrierX(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value target) { b.gphase(0.25); @@ -3545,16 +3550,16 @@ SmallVector inverseGphaseBarrierX(QCOProgramBuilder& b) { wire = b.x(wire); return wire; }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } -SmallVector inverseNestedInvHAndT(QCOProgramBuilder& b) { +Value inverseNestedInvHAndT(QCOProgramBuilder& b) { auto q = b.allocQubitRegister(1); auto res = b.inv(q[0], [&](Value target) { auto wire = b.inv(target, [&](Value inner) { return b.h(inner); }); return b.t(wire); }); - return measureAndReturn(b, {res}); + return b.measure(res).second; } SmallVector inverseNestedInvHAndX(QCOProgramBuilder& b) { diff --git a/mlir/unittests/programs/qco_programs.h b/mlir/unittests/programs/qco_programs.h index badf4f2794..f764e7ab09 100644 --- a/mlir/unittests/programs/qco_programs.h +++ b/mlir/unittests/programs/qco_programs.h @@ -17,21 +17,21 @@ namespace mlir::qco { class QCOProgramBuilder; /// Creates an empty QCO program. -SmallVector emptyQCO(QCOProgramBuilder& builder); +Value emptyQCO(QCOProgramBuilder& builder); // --- Qubit Management ----------------------------------------------------- // /// Allocates a single qubit. -SmallVector allocQubit(QCOProgramBuilder& b); +Value allocQubit(QCOProgramBuilder& b); /// Allocates two individual qubits. SmallVector alloc2Qubits(QCOProgramBuilder& b); /// Allocates a single qubit that is not measured. -SmallVector allocQubitNoMeasure(QCOProgramBuilder& b); +Value allocQubitNoMeasure(QCOProgramBuilder& b); /// Allocates a qubit register of size `1`. -SmallVector alloc1QubitRegister(QCOProgramBuilder& b); +Value alloc1QubitRegister(QCOProgramBuilder& b); /// Allocates a qubit register of size `2`. SmallVector alloc2QubitRegister(QCOProgramBuilder& b); @@ -43,13 +43,13 @@ SmallVector alloc3QubitRegister(QCOProgramBuilder& b); SmallVector allocMultipleQubitRegisters(QCOProgramBuilder& b); /// Allocates a large qubit register. -SmallVector allocLargeRegister(QCOProgramBuilder& b); +Value allocLargeRegister(QCOProgramBuilder& b); /// Allocates two inline qubits. SmallVector staticQubits(QCOProgramBuilder& b); /// Allocates two inline qubits without measuring them. -SmallVector staticQubitsNoMeasure(QCOProgramBuilder& b); +Value staticQubitsNoMeasure(QCOProgramBuilder& b); /// Allocates two static qubits and applies operations. SmallVector staticQubitsWithOps(QCOProgramBuilder& b); @@ -64,20 +64,20 @@ SmallVector staticQubitsWithTwoTargetOps(QCOProgramBuilder& b); SmallVector staticQubitsWithCtrl(QCOProgramBuilder& b); /// Allocates a static qubit and applies an inverse modifier. -SmallVector staticQubitsWithInv(QCOProgramBuilder& b); +Value staticQubitsWithInv(QCOProgramBuilder& b); /// Allocates and explicitly sinks a single qubit. -SmallVector allocSinkPair(QCOProgramBuilder& b); +Value allocSinkPair(QCOProgramBuilder& b); /// Allocates two qubits and performs a set of dead gates on them. SmallVector deadGatesProgram(QCOProgramBuilder& b); /// Allocates two qubits and performs a set of dead gates on them, including /// `if` operations. -SmallVector deadGatesWithIfOpProgram(QCOProgramBuilder& b); +Value deadGatesWithIfOpProgram(QCOProgramBuilder& b); /// Allocates two qubits and performs only non-dead `if` operations. -SmallVector deadGatesWithIfOpSimplified(QCOProgramBuilder& b); +Value deadGatesWithIfOpSimplified(QCOProgramBuilder& b); // --- Invalid / mixed addressing (unit tests) -------------------------------- @@ -87,15 +87,15 @@ SmallVector mixedStaticThenDynamicQubit(QCOProgramBuilder& b); /// @pre `builder.initialize()`. Fatal mixed addressing: `qtensor` alloc then /// static. -SmallVector mixedDynamicRegisterThenStaticQubit(QCOProgramBuilder& b); +Value mixedDynamicRegisterThenStaticQubit(QCOProgramBuilder& b); // --- MeasureOp ------------------------------------------------------------ // /// Measures a single qubit into a single classical bit. -SmallVector singleMeasurementToSingleBit(QCOProgramBuilder& b); +Value singleMeasurementToSingleBit(QCOProgramBuilder& b); /// Repeatedly measures a single qubit into the same classical bit. -SmallVector repeatedMeasurementToSameBit(QCOProgramBuilder& b); +Value repeatedMeasurementToSameBit(QCOProgramBuilder& b); /// Repeatedly measures a single qubit into different classical bits. SmallVector repeatedMeasurementToDifferentBits(QCOProgramBuilder& b); @@ -106,41 +106,41 @@ multipleClassicalRegistersAndMeasurements(QCOProgramBuilder& b); /// Measures a single qubit into a single classical bit, without explicitly /// allocating a quantum or classical register. -SmallVector measurementWithoutRegisters(QCOProgramBuilder& b); +Value measurementWithoutRegisters(QCOProgramBuilder& b); // --- ResetOp -------------------------------------------------------------- // /// Resets a single qubit without any operations being applied. -SmallVector resetQubitWithoutOp(QCOProgramBuilder& b); +Value resetQubitWithoutOp(QCOProgramBuilder& b); /// Resets multiple qubits without any operations being applied. SmallVector resetMultipleQubitsWithoutOp(QCOProgramBuilder& b); /// Repeatedly resets a single qubit without any operations being applied. -SmallVector repeatedResetWithoutOp(QCOProgramBuilder& b); +Value repeatedResetWithoutOp(QCOProgramBuilder& b); /// Resets a single qubit after a single operation. -SmallVector resetQubitAfterSingleOp(QCOProgramBuilder& b); +Value resetQubitAfterSingleOp(QCOProgramBuilder& b); /// Resets multiple qubits after a single operation. SmallVector resetMultipleQubitsAfterSingleOp(QCOProgramBuilder& b); /// Repeatedly resets a single qubit after a single operation. -SmallVector repeatedResetAfterSingleOp(QCOProgramBuilder& b); +Value repeatedResetAfterSingleOp(QCOProgramBuilder& b); // --- GPhaseOp ------------------------------------------------------------- // /// Creates a circuit with just a global phase. -SmallVector globalPhase(QCOProgramBuilder& b); +Value globalPhase(QCOProgramBuilder& b); /// Creates a controlled global phase gate with a single control qubit. -SmallVector singleControlledGlobalPhase(QCOProgramBuilder& b); +Value singleControlledGlobalPhase(QCOProgramBuilder& b); /// Creates a multi-controlled global phase gate with multiple control qubits. SmallVector multipleControlledGlobalPhase(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a global phase gate. -SmallVector inverseGlobalPhase(QCOProgramBuilder& b); +Value inverseGlobalPhase(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled global /// phase gate. @@ -149,7 +149,7 @@ SmallVector inverseMultipleControlledGlobalPhase(QCOProgramBuilder& b); // --- IdOp ----------------------------------------------------------------- // /// Creates a circuit with just an identity gate. -SmallVector identity(QCOProgramBuilder& b); +Value identity(QCOProgramBuilder& b); /// Creates a controlled identity gate with a single control qubit. SmallVector singleControlledIdentity(QCOProgramBuilder& b); @@ -161,10 +161,10 @@ SmallVector multipleControlledIdentity(QCOProgramBuilder& b); SmallVector nestedControlledIdentity(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled identity gate. -SmallVector trivialControlledIdentity(QCOProgramBuilder& b); +Value trivialControlledIdentity(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an identity gate. -SmallVector inverseIdentity(QCOProgramBuilder& b); +Value inverseIdentity(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled identity /// gate. @@ -173,7 +173,7 @@ SmallVector inverseMultipleControlledIdentity(QCOProgramBuilder& b); // --- XOp ------------------------------------------------------------------ // /// Creates a circuit with just an X gate. -SmallVector x(QCOProgramBuilder& b); +Value x(QCOProgramBuilder& b); /// Creates a circuit with a single controlled X gate. SmallVector singleControlledX(QCOProgramBuilder& b); @@ -185,43 +185,43 @@ SmallVector multipleControlledX(QCOProgramBuilder& b); SmallVector nestedControlledX(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled X gate. -SmallVector trivialControlledX(QCOProgramBuilder& b); +Value trivialControlledX(QCOProgramBuilder& b); /// Creates a circuit with repeated controlled X gates. SmallVector repeatedControlledX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an X gate. -SmallVector inverseX(QCOProgramBuilder& b); +Value inverseX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled X gate. SmallVector inverseMultipleControlledX(QCOProgramBuilder& b); /// Creates a circuit with two subsequent X gates. -SmallVector twoX(QCOProgramBuilder& b); +Value twoX(QCOProgramBuilder& b); /// Creates a circuit with a control modifier applied to two subsequent X gates. SmallVector controlledTwoX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to two subsequent X /// gates. -SmallVector inverseTwoX(QCOProgramBuilder& b); +Value inverseTwoX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a global phase and an /// X gate. -SmallVector inverseGphaseX(QCOProgramBuilder& b); +Value inverseGphaseX(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a global phase and a /// barrier. -SmallVector inverseGphaseBarrier(QCOProgramBuilder& b); +Value inverseGphaseBarrier(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to two consecutive /// barriers. -SmallVector inverseTwoBarriersInInv(QCOProgramBuilder& b); +Value inverseTwoBarriersInInv(QCOProgramBuilder& b); // --- YOp ------------------------------------------------------------------ // /// Creates a circuit with just a Y gate. -SmallVector y(QCOProgramBuilder& b); +Value y(QCOProgramBuilder& b); /// Creates a circuit with a single controlled Y gate. SmallVector singleControlledY(QCOProgramBuilder& b); @@ -233,21 +233,21 @@ SmallVector multipleControlledY(QCOProgramBuilder& b); SmallVector nestedControlledY(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled Y gate. -SmallVector trivialControlledY(QCOProgramBuilder& b); +Value trivialControlledY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Y gate. -SmallVector inverseY(QCOProgramBuilder& b); +Value inverseY(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Y gate. SmallVector inverseMultipleControlledY(QCOProgramBuilder& b); /// Creates a circuit with two Y gates in a row. -SmallVector twoY(QCOProgramBuilder& b); +Value twoY(QCOProgramBuilder& b); // --- ZOp ------------------------------------------------------------------ // /// Creates a circuit with just a Z gate. -SmallVector z(QCOProgramBuilder& b); +Value z(QCOProgramBuilder& b); /// Creates a circuit with a single controlled Z gate. SmallVector singleControlledZ(QCOProgramBuilder& b); @@ -259,21 +259,21 @@ SmallVector multipleControlledZ(QCOProgramBuilder& b); SmallVector nestedControlledZ(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled Z gate. -SmallVector trivialControlledZ(QCOProgramBuilder& b); +Value trivialControlledZ(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Z gate. -SmallVector inverseZ(QCOProgramBuilder& b); +Value inverseZ(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Z gate. SmallVector inverseMultipleControlledZ(QCOProgramBuilder& b); /// Creates a circuit with two Z gates in a row. -SmallVector twoZ(QCOProgramBuilder& b); +Value twoZ(QCOProgramBuilder& b); // --- HOp ------------------------------------------------------------------ // /// Creates a circuit with just an H gate. -SmallVector h(QCOProgramBuilder& b); +Value h(QCOProgramBuilder& b); /// Creates a circuit with a single controlled H gate. SmallVector singleControlledH(QCOProgramBuilder& b); @@ -285,24 +285,24 @@ SmallVector multipleControlledH(QCOProgramBuilder& b); SmallVector nestedControlledH(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled H gate. -SmallVector trivialControlledH(QCOProgramBuilder& b); +Value trivialControlledH(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an H gate. -SmallVector inverseH(QCOProgramBuilder& b); +Value inverseH(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled H gate. SmallVector inverseMultipleControlledH(QCOProgramBuilder& b); /// Creates a circuit with two H gates in a row. -SmallVector twoH(QCOProgramBuilder& b); +Value twoH(QCOProgramBuilder& b); /// Creates a circuit with just an H gate and no qubit register. -SmallVector hWithoutRegister(QCOProgramBuilder& b); +Value hWithoutRegister(QCOProgramBuilder& b); // --- SOp ------------------------------------------------------------------ // /// Creates a circuit with just an S gate. -SmallVector s(QCOProgramBuilder& b); +Value s(QCOProgramBuilder& b); /// Creates a circuit with a single controlled S gate. SmallVector singleControlledS(QCOProgramBuilder& b); @@ -314,24 +314,24 @@ SmallVector multipleControlledS(QCOProgramBuilder& b); SmallVector nestedControlledS(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled S gate. -SmallVector trivialControlledS(QCOProgramBuilder& b); +Value trivialControlledS(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an S gate. -SmallVector inverseS(QCOProgramBuilder& b); +Value inverseS(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled S gate. SmallVector inverseMultipleControlledS(QCOProgramBuilder& b); /// Creates a circuit with an S gate followed by an Sdg gate. -SmallVector sThenSdg(QCOProgramBuilder& b); +Value sThenSdg(QCOProgramBuilder& b); /// Creates a circuit with two S gates in a row. -SmallVector twoS(QCOProgramBuilder& b); +Value twoS(QCOProgramBuilder& b); // --- SdgOp ---------------------------------------------------------------- // /// Creates a circuit with just an Sdg gate. -SmallVector sdg(QCOProgramBuilder& b); +Value sdg(QCOProgramBuilder& b); /// Creates a circuit with a single controlled Sdg gate. SmallVector singleControlledSdg(QCOProgramBuilder& b); @@ -343,24 +343,24 @@ SmallVector multipleControlledSdg(QCOProgramBuilder& b); SmallVector nestedControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled Sdg gate. -SmallVector trivialControlledSdg(QCOProgramBuilder& b); +Value trivialControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an Sdg gate. -SmallVector inverseSdg(QCOProgramBuilder& b); +Value inverseSdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Sdg gate. SmallVector inverseMultipleControlledSdg(QCOProgramBuilder& b); /// Creates a circuit with an Sdg gate followed an S gate. -SmallVector sdgThenS(QCOProgramBuilder& b); +Value sdgThenS(QCOProgramBuilder& b); /// Creates a circuit with two Sdg gates in a row. -SmallVector twoSdg(QCOProgramBuilder& b); +Value twoSdg(QCOProgramBuilder& b); // --- TOp ------------------------------------------------------------------ // /// Creates a circuit with just a T gate. -SmallVector t_(QCOProgramBuilder& b); // NOLINT(*-identifier-naming) +Value t_(QCOProgramBuilder& b); // NOLINT(*-identifier-naming) /// Creates a circuit with a single controlled T gate. SmallVector singleControlledT(QCOProgramBuilder& b); @@ -372,24 +372,24 @@ SmallVector multipleControlledT(QCOProgramBuilder& b); SmallVector nestedControlledT(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled T gate. -SmallVector trivialControlledT(QCOProgramBuilder& b); +Value trivialControlledT(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a T gate. -SmallVector inverseT(QCOProgramBuilder& b); +Value inverseT(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled T gate. SmallVector inverseMultipleControlledT(QCOProgramBuilder& b); /// Creates a circuit with a T gate followed by a Tdg gate. -SmallVector tThenTdg(QCOProgramBuilder& b); +Value tThenTdg(QCOProgramBuilder& b); /// Creates a circuit with two T gates in a row. -SmallVector twoT(QCOProgramBuilder& b); +Value twoT(QCOProgramBuilder& b); // --- TdgOp ---------------------------------------------------------------- // /// Creates a circuit with just a Tdg gate. -SmallVector tdg(QCOProgramBuilder& b); +Value tdg(QCOProgramBuilder& b); /// Creates a circuit with a single controlled Tdg gate. SmallVector singleControlledTdg(QCOProgramBuilder& b); @@ -401,24 +401,24 @@ SmallVector multipleControlledTdg(QCOProgramBuilder& b); SmallVector nestedControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled Tdg gate. -SmallVector trivialControlledTdg(QCOProgramBuilder& b); +Value trivialControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a Tdg gate. -SmallVector inverseTdg(QCOProgramBuilder& b); +Value inverseTdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled Tdg gate. SmallVector inverseMultipleControlledTdg(QCOProgramBuilder& b); /// Creates a circuit with a Tdg gate followed by a T gate. -SmallVector tdgThenT(QCOProgramBuilder& b); +Value tdgThenT(QCOProgramBuilder& b); /// Creates a circuit with two Tdg gates in a row. -SmallVector twoTdg(QCOProgramBuilder& b); +Value twoTdg(QCOProgramBuilder& b); // --- SXOp ----------------------------------------------------------------- // /// Creates a circuit with just an SX gate. -SmallVector sx(QCOProgramBuilder& b); +Value sx(QCOProgramBuilder& b); /// Creates a circuit with a single controlled SX gate. SmallVector singleControlledSx(QCOProgramBuilder& b); @@ -430,24 +430,24 @@ SmallVector multipleControlledSx(QCOProgramBuilder& b); SmallVector nestedControlledSx(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled SX gate. -SmallVector trivialControlledSx(QCOProgramBuilder& b); +Value trivialControlledSx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an SX gate. -SmallVector inverseSx(QCOProgramBuilder& b); +Value inverseSx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SX gate. SmallVector inverseMultipleControlledSx(QCOProgramBuilder& b); /// Creates a circuit with an SX gate followed by an SXdg gate. -SmallVector sxThenSxdg(QCOProgramBuilder& b); +Value sxThenSxdg(QCOProgramBuilder& b); /// Creates a circuit with two SX gates in a row. -SmallVector twoSx(QCOProgramBuilder& b); +Value twoSx(QCOProgramBuilder& b); // --- SXdgOp --------------------------------------------------------------- // /// Creates a circuit with just an SXdg gate. -SmallVector sxdg(QCOProgramBuilder& b); +Value sxdg(QCOProgramBuilder& b); /// Creates a circuit with a single controlled SXdg gate. SmallVector singleControlledSxdg(QCOProgramBuilder& b); @@ -459,25 +459,25 @@ SmallVector multipleControlledSxdg(QCOProgramBuilder& b); SmallVector nestedControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled SXdg gate. -SmallVector trivialControlledSxdg(QCOProgramBuilder& b); +Value trivialControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an SXdg gate. -SmallVector inverseSxdg(QCOProgramBuilder& b); +Value inverseSxdg(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled SXdg /// gate. SmallVector inverseMultipleControlledSxdg(QCOProgramBuilder& b); /// Creates a circuit with an SXdg gate followed by an SX gate. -SmallVector sxdgThenSx(QCOProgramBuilder& b); +Value sxdgThenSx(QCOProgramBuilder& b); /// Creates a circuit with two SXdg gates in a row. -SmallVector twoSxdg(QCOProgramBuilder& b); +Value twoSxdg(QCOProgramBuilder& b); // --- RXOp ----------------------------------------------------------------- // /// Creates a circuit with just an RX gate. -SmallVector rx(QCOProgramBuilder& b); +Value rx(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RX gate. SmallVector singleControlledRx(QCOProgramBuilder& b); @@ -489,24 +489,24 @@ SmallVector multipleControlledRx(QCOProgramBuilder& b); SmallVector nestedControlledRx(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RX gate. -SmallVector trivialControlledRx(QCOProgramBuilder& b); +Value trivialControlledRx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RX gate. -SmallVector inverseRx(QCOProgramBuilder& b); +Value inverseRx(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RX gate. SmallVector inverseMultipleControlledRx(QCOProgramBuilder& b); /// Creates a circuit with two RX gates in a row with opposite phases. -SmallVector twoRxOppositePhase(QCOProgramBuilder& b); +Value twoRxOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with an RX gate with an angle of pi/2. -SmallVector rxPiOver2(QCOProgramBuilder& b); +Value rxPiOver2(QCOProgramBuilder& b); // --- RYOp ----------------------------------------------------------------- // /// Creates a circuit with just an RY gate. -SmallVector ry(QCOProgramBuilder& b); +Value ry(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RY gate. SmallVector singleControlledRy(QCOProgramBuilder& b); @@ -518,24 +518,24 @@ SmallVector multipleControlledRy(QCOProgramBuilder& b); SmallVector nestedControlledRy(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RY gate. -SmallVector trivialControlledRy(QCOProgramBuilder& b); +Value trivialControlledRy(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RY gate. -SmallVector inverseRy(QCOProgramBuilder& b); +Value inverseRy(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RY gate. SmallVector inverseMultipleControlledRy(QCOProgramBuilder& b); /// Creates a circuit with two RY gates in a row with opposite phases. -SmallVector twoRyOppositePhase(QCOProgramBuilder& b); +Value twoRyOppositePhase(QCOProgramBuilder& b); /// Creates a circuit with an RY gate with an angle of pi/2. -SmallVector ryPiOver2(QCOProgramBuilder& b); +Value ryPiOver2(QCOProgramBuilder& b); // --- RZOp ----------------------------------------------------------------- // /// Creates a circuit with just an RZ gate. -SmallVector rz(QCOProgramBuilder& b); +Value rz(QCOProgramBuilder& b); /// Creates a circuit with a single controlled RZ gate. SmallVector singleControlledRz(QCOProgramBuilder& b); @@ -547,21 +547,21 @@ SmallVector multipleControlledRz(QCOProgramBuilder& b); SmallVector nestedControlledRz(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled RZ gate. -SmallVector trivialControlledRz(QCOProgramBuilder& b); +Value trivialControlledRz(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an RZ gate. -SmallVector inverseRz(QCOProgramBuilder& b); +Value inverseRz(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled RZ gate. SmallVector inverseMultipleControlledRz(QCOProgramBuilder& b); /// Creates a circuit with two RZ gates in a row with opposite phases. -SmallVector twoRzOppositePhase(QCOProgramBuilder& b); +Value twoRzOppositePhase(QCOProgramBuilder& b); // --- POp ------------------------------------------------------------------ // /// Creates a circuit with just a P gate. -SmallVector p(QCOProgramBuilder& b); +Value p(QCOProgramBuilder& b); /// Creates a circuit with a single controlled P gate. SmallVector singleControlledP(QCOProgramBuilder& b); @@ -573,21 +573,21 @@ SmallVector multipleControlledP(QCOProgramBuilder& b); SmallVector nestedControlledP(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled P gate. -SmallVector trivialControlledP(QCOProgramBuilder& b); +Value trivialControlledP(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a P gate. -SmallVector inverseP(QCOProgramBuilder& b); +Value inverseP(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled P gate. SmallVector inverseMultipleControlledP(QCOProgramBuilder& b); /// Creates a circuit with two P gates in a row with opposite phases. -SmallVector twoPOppositePhase(QCOProgramBuilder& b); +Value twoPOppositePhase(QCOProgramBuilder& b); // --- ROp ------------------------------------------------------------------ // /// Creates a circuit with just an R gate. -SmallVector r(QCOProgramBuilder& b); +Value r(QCOProgramBuilder& b); /// Creates a circuit with a single controlled R gate. SmallVector singleControlledR(QCOProgramBuilder& b); @@ -599,27 +599,27 @@ SmallVector multipleControlledR(QCOProgramBuilder& b); SmallVector nestedControlledR(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled R gate. -SmallVector trivialControlledR(QCOProgramBuilder& b); +Value trivialControlledR(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to an R gate. -SmallVector inverseR(QCOProgramBuilder& b); +Value inverseR(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled R gate. SmallVector inverseMultipleControlledR(QCOProgramBuilder& b); /// Creates a circuit with an R gate that can be canonicalized to an RX gate. -SmallVector canonicalizeRToRx(QCOProgramBuilder& b); +Value canonicalizeRToRx(QCOProgramBuilder& b); /// Creates a circuit with an R gate that can be canonicalized to an RY gate. -SmallVector canonicalizeRToRy(QCOProgramBuilder& b); +Value canonicalizeRToRy(QCOProgramBuilder& b); /// Creates a circuit with two R gates in a row with the same `phi`. -SmallVector twoR(QCOProgramBuilder& b); +Value twoR(QCOProgramBuilder& b); // --- U2Op ----------------------------------------------------------------- // /// Creates a circuit with just a U2 gate. -SmallVector u2(QCOProgramBuilder& b); +Value u2(QCOProgramBuilder& b); /// Creates a circuit with a single controlled U2 gate. SmallVector singleControlledU2(QCOProgramBuilder& b); @@ -631,27 +631,27 @@ SmallVector multipleControlledU2(QCOProgramBuilder& b); SmallVector nestedControlledU2(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled U2 gate. -SmallVector trivialControlledU2(QCOProgramBuilder& b); +Value trivialControlledU2(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a U2 gate. -SmallVector inverseU2(QCOProgramBuilder& b); +Value inverseU2(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled U2 gate. SmallVector inverseMultipleControlledU2(QCOProgramBuilder& b); /// Creates a circuit with a U2 gate that can be canonicalized to an H gate. -SmallVector canonicalizeU2ToH(QCOProgramBuilder& b); +Value canonicalizeU2ToH(QCOProgramBuilder& b); /// Creates a circuit with a U2 gate that can be canonicalized to an RX gate. -SmallVector canonicalizeU2ToRx(QCOProgramBuilder& b); +Value canonicalizeU2ToRx(QCOProgramBuilder& b); /// Creates a circuit with a U2 gate that can be canonicalized to an RY gate. -SmallVector canonicalizeU2ToRy(QCOProgramBuilder& b); +Value canonicalizeU2ToRy(QCOProgramBuilder& b); // --- UOp ------------------------------------------------------------------ // /// Creates a circuit with just a U gate. -SmallVector u(QCOProgramBuilder& b); +Value u(QCOProgramBuilder& b); /// Creates a circuit with a single controlled U gate. SmallVector singleControlledU(QCOProgramBuilder& b); @@ -663,25 +663,25 @@ SmallVector multipleControlledU(QCOProgramBuilder& b); SmallVector nestedControlledU(QCOProgramBuilder& b); /// Creates a circuit with a trivial controlled U gate. -SmallVector trivialControlledU(QCOProgramBuilder& b); +Value trivialControlledU(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a U gate. -SmallVector inverseU(QCOProgramBuilder& b); +Value inverseU(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a controlled U gate. SmallVector inverseMultipleControlledU(QCOProgramBuilder& b); /// Creates a circuit with a U gate that can be canonicalized to a P gate. -SmallVector canonicalizeUToP(QCOProgramBuilder& b); +Value canonicalizeUToP(QCOProgramBuilder& b); /// Creates a circuit with a U gate that can be canonicalized to an RX gate. -SmallVector canonicalizeUToRx(QCOProgramBuilder& b); +Value canonicalizeUToRx(QCOProgramBuilder& b); /// Creates a circuit with a U gate that can be canonicalized to an RY gate. -SmallVector canonicalizeUToRy(QCOProgramBuilder& b); +Value canonicalizeUToRy(QCOProgramBuilder& b); /// Creates a circuit with a U gate that can be canonicalized to a U2 gate. -SmallVector canonicalizeUToU2(QCOProgramBuilder& b); +Value canonicalizeUToU2(QCOProgramBuilder& b); // --- SWAPOp --------------------------------------------------------------- // @@ -995,7 +995,7 @@ SmallVector twoXxMinusYYSwappedTargets(QCOProgramBuilder& b); // --- BarrierOp ------------------------------------------------------------ // /// Creates a circuit with a barrier. -SmallVector barrier(QCOProgramBuilder& b); +Value barrier(QCOProgramBuilder& b); /// Creates a circuit with a barrier on two qubits. SmallVector barrierTwoQubits(QCOProgramBuilder& b); @@ -1004,10 +1004,10 @@ SmallVector barrierTwoQubits(QCOProgramBuilder& b); SmallVector barrierMultipleQubits(QCOProgramBuilder& b); /// Creates a circuit with a single controlled barrier. -SmallVector singleControlledBarrier(QCOProgramBuilder& b); +Value singleControlledBarrier(QCOProgramBuilder& b); /// Creates a circuit with an inverse modifier applied to a barrier. -SmallVector inverseBarrier(QCOProgramBuilder& b); +Value inverseBarrier(QCOProgramBuilder& b); /// Creates a circuit with two barriers in a row with overlapping qubits. SmallVector twoBarrier(QCOProgramBuilder& b); @@ -1073,7 +1073,7 @@ SmallVector invCtrlTwo(QCOProgramBuilder& b); SmallVector simpleIf(QCOProgramBuilder& b); /// Creates a circuit with an if operation with a parameterized gate. -SmallVector ifWithAngle(QCOProgramBuilder& b); +Value ifWithAngle(QCOProgramBuilder& b); /// Creates a circuit with an if operation with two qubits. SmallVector ifTwoQubits(QCOProgramBuilder& b); @@ -1082,15 +1082,15 @@ SmallVector ifTwoQubits(QCOProgramBuilder& b); SmallVector ifElse(QCOProgramBuilder& b); /// Creates a circuit with an if operation with one qubit and one register. -SmallVector ifOneQubitOneTensor(QCOProgramBuilder& b); +Value ifOneQubitOneTensor(QCOProgramBuilder& b); /// Creates a circuit with an if operation that uses a constant true as /// condition. -SmallVector constantTrueIf(QCOProgramBuilder& b); +Value constantTrueIf(QCOProgramBuilder& b); /// Creates a circuit with an if operation that uses a constant false as /// condition. -SmallVector constantFalseIf(QCOProgramBuilder& b); +Value constantFalseIf(QCOProgramBuilder& b); /// Creates a circuit with a nested if operation in the then branch that uses /// the same condition. @@ -1102,19 +1102,19 @@ SmallVector nestedFalseIf(QCOProgramBuilder& b); /// Creates a circuit with an if operation with a nested for operation with /// a register. -SmallVector nestedIfOpForLoop(QCOProgramBuilder& b); +Value nestedIfOpForLoop(QCOProgramBuilder& b); /// Creates a circuit with an if operation with a nested for operation and /// parameterized gates. -SmallVector nestedIfOpForLoopWithAngle(QCOProgramBuilder& b); +Value nestedIfOpForLoopWithAngle(QCOProgramBuilder& b); // --- WhileOp -------------------------------------------------------------- // /// Creates a circuit with a while operation using a while loop. -SmallVector simpleWhileReset(QCOProgramBuilder& b); +Value simpleWhileReset(QCOProgramBuilder& b); /// Creates a circuit with a while operation using a do-while loop. -SmallVector simpleDoWhileReset(QCOProgramBuilder& b); +Value simpleDoWhileReset(QCOProgramBuilder& b); // --- ForOp ---------------------------------------------------------------- // @@ -1122,11 +1122,11 @@ SmallVector simpleDoWhileReset(QCOProgramBuilder& b); SmallVector simpleForLoop(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a parameterized gate. -SmallVector forLoopWithAngle(QCOProgramBuilder& b); +Value forLoopWithAngle(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested if operation. -SmallVector nestedForLoopIfOp(QCOProgramBuilder& b); +Value nestedForLoopIfOp(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a register and a nested while /// operation. @@ -1135,11 +1135,11 @@ SmallVector nestedForLoopWhileOp(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is separately allocated from the /// register. -SmallVector nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b); +Value nestedForLoopCtrlOpWithSeparateQubit(QCOProgramBuilder& b); /// Creates a circuit with a for operation with a register and a qubit and a /// nested ctrl operation where the qubit is extracted from the register. -SmallVector nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b); +Value nestedForLoopCtrlOpWithExtractedQubit(QCOProgramBuilder& b); // --- QTensor Operations -------------------------------------------------- // @@ -1153,7 +1153,7 @@ SmallVector qtensorDealloc(QCOProgramBuilder& b); SmallVector qtensorFromElements(QCOProgramBuilder& b); /// Extracts a qubit from a tensor. -SmallVector qtensorExtract(QCOProgramBuilder& b); +Value qtensorExtract(QCOProgramBuilder& b); /// Inserts a qubit into a tensor. SmallVector qtensorInsert(QCOProgramBuilder& b); @@ -1191,9 +1191,9 @@ SmallVector inverseCxThenRz(QCOProgramBuilder& b); SmallVector inverseDcxThenRz(QCOProgramBuilder& b); -SmallVector inverseGphaseBarrierX(QCOProgramBuilder& b); +Value inverseGphaseBarrierX(QCOProgramBuilder& b); -SmallVector inverseNestedInvHAndT(QCOProgramBuilder& b); +Value inverseNestedInvHAndT(QCOProgramBuilder& b); SmallVector inverseNestedInvHAndX(QCOProgramBuilder& b); From ec6777dbd75e2633b501fc1664bd94b1721bf909 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Fri, 10 Jul 2026 02:16:01 +0200 Subject: [PATCH 74/80] :art: Misc. improvements to QuantumComputation translation Signed-off-by: burgholzer --- .../QC/Translation/TranslateQuantumComputationToQC.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp b/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp index a649832590..4b798de54b 100644 --- a/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp +++ b/mlir/lib/Dialect/QC/Translation/TranslateQuantumComputationToQC.cpp @@ -730,7 +730,7 @@ static LogicalResult addIfElseOp(QCProgramBuilder& builder, * @brief Translates an operation from QuantumComputation to QC dialect * * @param builder The QCProgramBuilder used to create operations - * @param quantumComputation The quantum computation to translate + * @param operation The operation to translate * @param state The translation state * @return Success if all supported operations were translated */ @@ -850,10 +850,8 @@ OwningOpRef translateQuantumComputationToQC( MLIRContext* context, const ::qc::QuantumComputation& quantumComputation) { // Create and initialize the builder (creates module and main function) QCProgramBuilder builder(context); - SmallVector resultTypes(quantumComputation.getNcbits()); - for (auto i = 0; i < quantumComputation.getNcbits(); ++i) { - resultTypes[i] = builder.getI1Type(); - } + SmallVector resultTypes(quantumComputation.getNcbits(), + builder.getI1Type()); if (quantumComputation.getNcbits() == 0) { // Without classical bits, we instead return an exit code 0. resultTypes.push_back(builder.getI64Type()); From 6ab9653098e818b542a7929eda465f55e85fd20e Mon Sep 17 00:00:00 2001 From: burgholzer Date: Fri, 10 Jul 2026 02:25:35 +0200 Subject: [PATCH 75/80] :art: Automatically infer return type in OQ3 translation Signed-off-by: burgholzer --- mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp b/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp index c1e05f821a..c00290455e 100644 --- a/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp +++ b/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp @@ -227,8 +227,6 @@ class MLIRQasmImporter final : public qasm3::InstVisitor { // Collect measurement results for all output bit registers SmallVector returnValues; - SmallVector returnTypes; - auto i1Type = builder.getI1Type(); for (const auto& regName : outputRegisters) { auto it = bitValues.find(regName); if (it == bitValues.end()) { @@ -250,11 +248,10 @@ class MLIRQasmImporter final : public qasm3::InstVisitor { return nullptr; } returnValues.push_back(bit); - returnTypes.push_back(i1Type); } } - builder.retype(returnTypes); + builder.retype(ValueRange(returnValues).getTypes()); return builder.finalize(returnValues); } From 0cd289a040d02ad37e9abc68f5f2c0dc1943ddd9 Mon Sep 17 00:00:00 2001 From: burgholzer Date: Fri, 10 Jul 2026 02:26:03 +0200 Subject: [PATCH 76/80] :rotating_light: Fix linter warnings Signed-off-by: burgholzer --- mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp | 1 - .../lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp | 4 ++-- .../Dialect/QCO/Transforms/Mapping/Mapping.cpp | 2 +- .../unittests/Compiler/test_compiler_pipeline.cpp | 1 - .../JeffRoundTrip/test_jeff_round_trip.cpp | 2 -- .../Conversion/QCOToQC/test_qco_to_qc.cpp | 2 -- .../Conversion/QCToQCO/test_qc_to_qco.cpp | 2 -- .../QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp | 2 -- .../QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp | 2 -- mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp | 2 -- .../QC/Translation/test_qasm3_translation.cpp | 1 - .../test_quantum_computation_translation.cpp | 2 -- mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp | 1 - .../Decomposition/test_euler_decomposition.cpp | 4 +++- .../QCO/Transforms/Mapping/test_mapping.cpp | 1 + mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp | 2 -- mlir/unittests/TestCaseUtils.h | 15 ++++++--------- mlir/unittests/programs/qir_programs.cpp | 1 - 18 files changed, 13 insertions(+), 34 deletions(-) diff --git a/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp b/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp index 183e1fb7c4..3a06d4b593 100644 --- a/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp +++ b/mlir/lib/Dialect/QC/Builder/QCProgramBuilder.cpp @@ -12,7 +12,6 @@ #include "mlir/Dialect/QC/IR/QCDialect.h" #include "mlir/Dialect/QC/IR/QCOps.h" -#include "mlir/Dialect/QCO/IR/QCODialect.h" #include "mlir/Dialect/Utils/Utils.h" #include diff --git a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp index d7e4241635..c07fa324aa 100644 --- a/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp +++ b/mlir/lib/Dialect/QCO/IR/QubitManagement/SinkOp.cpp @@ -67,7 +67,7 @@ struct RemoveAllocSinkPair final : OpRewritePattern { /** * @brief Remove dead gates. */ -struct DeadGateElimination final : public OpRewritePattern { +struct DeadGateElimination final : OpRewritePattern { explicit DeadGateElimination(MLIRContext* context) : OpRewritePattern(context) {} @@ -76,7 +76,7 @@ struct DeadGateElimination final : public OpRewritePattern { PatternRewriter& rewriter) const override { Value currentValue = op.getQubit(); auto* currentOp = currentValue.getDefiningOp(); - bool success = false; + auto success = false; while (currentOp != nullptr) { if (!checkDeadGate(currentOp)) { break; diff --git a/mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp b/mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp index 7ccd1caac0..0b12d7efbb 100644 --- a/mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp +++ b/mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp @@ -10,7 +10,6 @@ #include "mlir/Dialect/QCO/Transforms/Mapping/Mapping.h" -#include "mlir/Dialect/QCO/IR/QCODialect.h" #include "mlir/Dialect/QCO/IR/QCOInterfaces.h" #include "mlir/Dialect/QCO/IR/QCOOps.h" #include "mlir/Dialect/QCO/Utils/Drivers.h" @@ -19,6 +18,7 @@ #include "mlir/Dialect/QCO/Utils/WireIterator.h" #include "mlir/Dialect/QTensor/IR/QTensorOps.h" #include "mlir/Dialect/QTensor/Utils/TensorIterator.h" +#include "mlir/Dialect/Utils/Utils.h" #include #include diff --git a/mlir/unittests/Compiler/test_compiler_pipeline.cpp b/mlir/unittests/Compiler/test_compiler_pipeline.cpp index 01aff2798f..b67f8c7f96 100644 --- a/mlir/unittests/Compiler/test_compiler_pipeline.cpp +++ b/mlir/unittests/Compiler/test_compiler_pipeline.cpp @@ -43,7 +43,6 @@ #include #include #include -#include namespace mqt::test::compiler { diff --git a/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp b/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp index e0eba98200..cd4856ebac 100644 --- a/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp +++ b/mlir/unittests/Conversion/JeffRoundTrip/test_jeff_round_trip.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -37,7 +36,6 @@ #include #include #include -#include using namespace mlir; diff --git a/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp b/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp index 7bd7389f7e..3cab63449f 100644 --- a/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp +++ b/mlir/unittests/Conversion/QCOToQC/test_qco_to_qc.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -36,7 +35,6 @@ #include #include #include -#include using namespace mlir; diff --git a/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp b/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp index ed77f90963..0b78783834 100644 --- a/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp +++ b/mlir/unittests/Conversion/QCToQCO/test_qc_to_qco.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -36,7 +35,6 @@ #include #include #include -#include using namespace mlir; diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp index df69c21e95..e386a4e579 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRAdaptive/test_qc_to_qir_adaptive.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -37,7 +36,6 @@ #include #include #include -#include using namespace mlir; diff --git a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp index 0a3872eb13..4319c3b4d3 100644 --- a/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp +++ b/mlir/unittests/Conversion/QCToQIR/QCToQIRBase/test_qc_to_qir_base.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -37,7 +36,6 @@ #include #include #include -#include using namespace mlir; diff --git a/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp b/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp index d6c8d44d4f..08d56935ed 100644 --- a/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp +++ b/mlir/unittests/Dialect/QC/IR/test_qc_ir.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -29,7 +28,6 @@ #include #include #include -#include using namespace mlir; using namespace mlir::qc; diff --git a/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp b/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp index 0296111684..c99059aa77 100644 --- a/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp +++ b/mlir/unittests/Dialect/QC/Translation/test_qasm3_translation.cpp @@ -31,7 +31,6 @@ #include #include #include -#include using namespace mlir; diff --git a/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp b/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp index d3db4d7c54..b94e3f082c 100644 --- a/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp +++ b/mlir/unittests/Dialect/QC/Translation/test_quantum_computation_translation.cpp @@ -25,14 +25,12 @@ #include #include #include -#include #include #include #include #include #include -#include namespace { diff --git a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp index 5d5bc939e2..5d829b6284 100644 --- a/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp +++ b/mlir/unittests/Dialect/QCO/IR/test_qco_ir.cpp @@ -32,7 +32,6 @@ #include #include #include -#include using namespace mlir; using namespace mlir::qco; diff --git a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp index bb41d8c78b..f1413aed70 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_euler_decomposition.cpp @@ -18,6 +18,8 @@ #include "mlir/Dialect/Utils/Utils.h" #include +#include +#include #include #include #include @@ -109,7 +111,7 @@ class EulerSynthesisExactTest */ static SmallVector measureAndReturn(QCOProgramBuilder& b, ValueRange qubits) { - return llvm::to_vector( + return to_vector( llvm::map_range(qubits, [&](Value q) { return b.measure(q).second; })); } diff --git a/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp b/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp index 05c2bf2f74..e43019e27b 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp @@ -14,6 +14,7 @@ #include "mlir/Dialect/QCO/IR/QCOOps.h" #include "mlir/Dialect/QCO/Transforms/Mapping/Mapping.h" #include "mlir/Dialect/QCO/Transforms/Passes.h" +#include "mlir/Dialect/Utils/Utils.h" #include #include diff --git a/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp b/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp index e2a0c79dd4..da6b6e25d0 100644 --- a/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp +++ b/mlir/unittests/Dialect/QIR/IR/test_qir_ir.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include @@ -26,7 +25,6 @@ #include #include #include -#include using namespace mlir; using namespace qir; diff --git a/mlir/unittests/TestCaseUtils.h b/mlir/unittests/TestCaseUtils.h index 8492019899..2646b3207a 100644 --- a/mlir/unittests/TestCaseUtils.h +++ b/mlir/unittests/TestCaseUtils.h @@ -14,17 +14,17 @@ #include #include -#include #include #include #include +#include #include #include +#include #include #include #include -#include #include #include #include @@ -92,13 +92,10 @@ buildMLIRProgram(mlir::MLIRContext* context, const NamedMLIRBuilder& builder, Args&&... args) { return std::visit( [&](T fn) -> mlir::OwningOpRef { - using FnT = std::decay_t; - if constexpr (std::is_same_v) { - return {}; - } else if constexpr (requires { - BuilderT::build(context, fn, - std::forward(args)...); - }) { + if constexpr (requires { + BuilderT::build(context, fn, + std::forward(args)...); + }) { return BuilderT::build(context, fn, std::forward(args)...); } else { return {}; diff --git a/mlir/unittests/programs/qir_programs.cpp b/mlir/unittests/programs/qir_programs.cpp index 334fba8079..1eb9efae9e 100644 --- a/mlir/unittests/programs/qir_programs.cpp +++ b/mlir/unittests/programs/qir_programs.cpp @@ -13,7 +13,6 @@ #include "mlir/Dialect/QIR/Builder/QIRProgramBuilder.h" #include -#include #include #include From 93b32c48364c91db72dfa6b7e3d47785ad56b8c7 Mon Sep 17 00:00:00 2001 From: Matthias Reumann Date: Fri, 10 Jul 2026 12:57:45 +0200 Subject: [PATCH 77/80] Use new builder API in mapping tests --- .../QCO/Transforms/Mapping/test_mapping.cpp | 351 ++++++++---------- 1 file changed, 164 insertions(+), 187 deletions(-) diff --git a/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp b/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp index a051c06b9e..ef4da7e933 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp @@ -232,13 +232,16 @@ TEST_P(MappingPassTest, NoQubitAllocations) { const auto& device = GetParam(); QCOProgramBuilder builder(context.get()); - builder.initialize(); + builder.initialize({builder.getI1Type()}); - Value q0 = builder.allocQubit(); + Value q0; + Value c0; + q0 = builder.allocQubit(); q0 = builder.h(q0); + std::tie(q0, c0) = builder.measure(q0); builder.sink(q0); - auto m = builder.finalize(); + auto m = builder.finalize(c0); auto res = runPass(m.get(), device.couplingSet, MappingPassOptions{}); ASSERT_TRUE(res.failed()); @@ -248,22 +251,24 @@ TEST_P(MappingPassTest, NoExtractAfterInsert) { const auto& device = GetParam(); QCOProgramBuilder builder(context.get()); - builder.initialize(); + builder.initialize({builder.getI1Type()}); Value tensor0 = builder.qtensorAlloc(1); Value q0; + Value c0; std::tie(tensor0, q0) = builder.qtensorExtract(tensor0, 0); q0 = builder.h(q0); tensor0 = builder.qtensorInsert(q0, tensor0, 0); std::tie(tensor0, q0) = builder.qtensorExtract(tensor0, 0); q0 = builder.x(q0); + std::tie(q0, c0) = builder.measure(q0); tensor0 = builder.qtensorInsert(q0, tensor0, 0); builder.qtensorDealloc(tensor0); - auto m = builder.finalize(); + auto m = builder.finalize(c0); auto res = runPass(m.get(), device.couplingSet, MappingPassOptions{}); ASSERT_TRUE(res.failed()); @@ -271,27 +276,29 @@ TEST_P(MappingPassTest, NoExtractAfterInsert) { TEST_P(MappingPassTest, TooManyQubitsForArch) { const auto& device = GetParam(); - const auto n = static_cast(device.nqubits) + 1; + const auto size = static_cast(device.nqubits) + 1; + + SmallVector bits(size); + SmallVector qubits(size); QCOProgramBuilder builder(context.get()); - builder.initialize(); - - Value tensor = builder.qtensorAlloc(n); - SmallVector qubits(n); - for (int64_t i = 0; i < n; ++i) { - Value qi; - std::tie(tensor, qi) = builder.qtensorExtract(tensor, i); - qi = builder.h(qi); - qubits[i] = qi; + builder.initialize(SmallVector(size, builder.getI1Type())); + + Value tensor = builder.qtensorAlloc(size); + + for (int64_t i = 0; i < size; ++i) { + std::tie(tensor, qubits[i]) = builder.qtensorExtract(tensor, i); + qubits[i] = builder.h(qubits[i]); + std::tie(qubits[i], bits[i]) = builder.measure(qubits[i]); } - for (int64_t i = 0; i < n; ++i) { + for (int64_t i = 0; i < size; ++i) { tensor = builder.qtensorInsert(qubits[i], tensor, i); } builder.qtensorDealloc(tensor); - auto m = builder.finalize(); + auto m = builder.finalize(bits); auto res = runPass(m.get(), device.couplingSet, MappingPassOptions{}); ASSERT_TRUE(res.failed()); @@ -299,31 +306,34 @@ TEST_P(MappingPassTest, TooManyQubitsForArch) { TEST_P(MappingPassTest, GHZ) { const auto& device = GetParam(); + const int64_t size = 3; + + SmallVector qubits(size); + SmallVector bits(size); QCOProgramBuilder builder(context.get()); - builder.initialize(); + builder.initialize(SmallVector(3, builder.getI1Type())); Value tensor = builder.qtensorAlloc(3); + std::tie(tensor, qubits[0]) = builder.qtensorExtract(tensor, 0); + std::tie(tensor, qubits[1]) = builder.qtensorExtract(tensor, 1); + std::tie(tensor, qubits[2]) = builder.qtensorExtract(tensor, 2); - Value q0; - std::tie(tensor, q0) = builder.qtensorExtract(tensor, 0); - - Value q1; - std::tie(tensor, q1) = builder.qtensorExtract(tensor, 1); + qubits[0] = builder.h(qubits[0]); + std::tie(qubits[0], qubits[1]) = builder.cx(qubits[0], qubits[1]); + std::tie(qubits[0], qubits[2]) = builder.cx(qubits[0], qubits[2]); - Value q2; - std::tie(tensor, q2) = builder.qtensorExtract(tensor, 2); + std::tie(qubits[0], bits[0]) = builder.measure(qubits[0]); + std::tie(qubits[1], bits[1]) = builder.measure(qubits[1]); + std::tie(qubits[2], bits[2]) = builder.measure(qubits[2]); - q0 = builder.h(q0); - std::tie(q0, q1) = builder.cx(q0, q1); - std::tie(q0, q2) = builder.cx(q0, q2); + tensor = builder.qtensorInsert(qubits[0], tensor, 0); + tensor = builder.qtensorInsert(qubits[1], tensor, 1); + tensor = builder.qtensorInsert(qubits[2], tensor, 2); - tensor = builder.qtensorInsert(q0, tensor, 0); - tensor = builder.qtensorInsert(q1, tensor, 1); - tensor = builder.qtensorInsert(q2, tensor, 2); builder.qtensorDealloc(tensor); - auto m = builder.finalize(); + auto m = builder.finalize(bits); auto res = runPass(m.get(), device.couplingSet, MappingPassOptions{}); auto entry = getEntryPoint(m.get()); @@ -333,7 +343,9 @@ TEST_P(MappingPassTest, GHZ) { TEST_P(MappingPassTest, GHZUnrolled) { const auto& device = GetParam(); - const auto n = static_cast(device.nqubits); + const auto size = static_cast(device.nqubits); + + SmallVector bits(size); PassManager pm(context.get()); pm.addNestedPass(createQuantumLoopUnroll()); @@ -342,15 +354,15 @@ TEST_P(MappingPassTest, GHZUnrolled) { pm.addPass(createMappingPass(device.couplingSet, MappingPassOptions{})); QCOProgramBuilder builder(context.get()); - builder.initialize(); + builder.initialize(SmallVector(size, builder.getI1Type())); - Value tensor = builder.qtensorAlloc(n); + Value tensor = builder.qtensorAlloc(size); Value q0; std::tie(tensor, q0) = builder.qtensorExtract(tensor, 0); q0 = builder.h(q0); tensor = builder.qtensorInsert(q0, tensor, 0); tensor = builder.scfFor( - 1, n, 1, {tensor}, [&builder](Value iv, ValueRange iterArgs) { + 1, size, 1, {tensor}, [&builder](Value iv, ValueRange iterArgs) { Value loopTensor = iterArgs[0]; Value ctrl; Value targ; @@ -365,9 +377,17 @@ TEST_P(MappingPassTest, GHZUnrolled) { return SmallVector{loopTensor}; })[0]; + + for (int64_t i = 0; i < size; ++i) { + Value q; + std::tie(tensor, q) = builder.qtensorExtract(tensor, i); + std::tie(q, bits[i]) = builder.measure(q); + tensor = builder.qtensorInsert(q, tensor, i); + } + builder.qtensorDealloc(tensor); - auto m = builder.finalize(); + auto m = builder.finalize(bits); auto res = pm.run(m.get()); auto entry = getEntryPoint(m.get()); @@ -377,35 +397,34 @@ TEST_P(MappingPassTest, GHZUnrolled) { TEST_P(MappingPassTest, GroverLike) { const auto& device = GetParam(); + const int64_t size = 5; + + SmallVector qubits(size); + SmallVector bits(size); PassManager pm(context.get()); pm.addPass(createMappingPass(device.couplingSet, MappingPassOptions{})); QCOProgramBuilder builder(context.get()); - builder.initialize(); + builder.initialize(SmallVector(5, builder.getI1Type())); Value tensor = builder.qtensorAlloc(4); Value flagTensor = builder.qtensorAlloc(1); - Value q0; - Value q1; - Value q2; - Value q3; - Value flag; - std::tie(tensor, q0) = builder.qtensorExtract(tensor, 0); - std::tie(tensor, q1) = builder.qtensorExtract(tensor, 1); - std::tie(tensor, q2) = builder.qtensorExtract(tensor, 2); - std::tie(tensor, q3) = builder.qtensorExtract(tensor, 3); - std::tie(flagTensor, flag) = builder.qtensorExtract(flagTensor, 0); + std::tie(tensor, qubits[0]) = builder.qtensorExtract(tensor, 0); + std::tie(tensor, qubits[1]) = builder.qtensorExtract(tensor, 1); + std::tie(tensor, qubits[2]) = builder.qtensorExtract(tensor, 2); + std::tie(tensor, qubits[3]) = builder.qtensorExtract(tensor, 3); + std::tie(flagTensor, qubits[4]) = builder.qtensorExtract(flagTensor, 0); - q0 = builder.h(q0); - q1 = builder.h(q1); - q2 = builder.h(q2); - q3 = builder.h(q3); - flag = builder.x(flag); + qubits[0] = builder.h(qubits[0]); + qubits[1] = builder.h(qubits[1]); + qubits[2] = builder.h(qubits[2]); + qubits[3] = builder.h(qubits[3]); + qubits[4] = builder.x(qubits[4]); - const auto forResults = builder.scfFor( - 1, 3, 1, {q0, q1, q2, q3, flag}, [&builder](Value, ValueRange iterArgs) { + qubits = + builder.scfFor(1, 3, 1, qubits, [&builder](Value, ValueRange iterArgs) { Value iterQ0 = iterArgs[0]; Value iterQ1 = iterArgs[1]; Value iterQ2 = iterArgs[2]; @@ -419,42 +438,22 @@ TEST_P(MappingPassTest, GroverLike) { return SmallVector{iterQ0, iterQ1, iterQ2, iterQ3, iterFlag}; }); + qubits = builder.barrier(qubits); - q0 = forResults[0]; - q1 = forResults[1]; - q2 = forResults[2]; - q3 = forResults[3]; - flag = forResults[4]; - - const auto barrierResults = builder.barrier({q0, q1, q2, q3, flag}); - q0 = barrierResults[0]; - q1 = barrierResults[1]; - q2 = barrierResults[2]; - q3 = barrierResults[3]; - flag = barrierResults[4]; - - Value c0; - Value c1; - Value c2; - Value c3; - Value c4; - - std::tie(q0, c0) = builder.measure(q0); - std::tie(q1, c1) = builder.measure(q1); - std::tie(q2, c2) = builder.measure(q2); - std::tie(q3, c3) = builder.measure(q3); - std::tie(flag, c4) = builder.measure(flag); + for (int64_t i = 0; i < size; ++i) { + std::tie(qubits[i], bits[i]) = builder.measure(qubits[i]); + } - tensor = builder.qtensorInsert(q0, tensor, 0); - tensor = builder.qtensorInsert(q1, tensor, 1); - tensor = builder.qtensorInsert(q2, tensor, 2); - tensor = builder.qtensorInsert(q3, tensor, 3); - flagTensor = builder.qtensorInsert(flag, flagTensor, 0); + tensor = builder.qtensorInsert(qubits[0], tensor, 0); + tensor = builder.qtensorInsert(qubits[1], tensor, 1); + tensor = builder.qtensorInsert(qubits[2], tensor, 2); + tensor = builder.qtensorInsert(qubits[3], tensor, 3); + flagTensor = builder.qtensorInsert(qubits[4], flagTensor, 0); builder.qtensorDealloc(tensor); builder.qtensorDealloc(flagTensor); - auto m = builder.finalize(); + auto m = builder.finalize(bits); auto res = pm.run(m.get()); auto entry = getEntryPoint(m.get()); @@ -463,26 +462,26 @@ TEST_P(MappingPassTest, GroverLike) { } TEST_P(MappingPassTest, ParallelLoops) { - constexpr int64_t nqubits = 6; const auto& device = GetParam(); + constexpr int64_t size = 6; + + SmallVector qubits(size); + SmallVector bits(size); PassManager pm(context.get()); pm.addPass(createMappingPass(device.couplingSet, MappingPassOptions{})); QCOProgramBuilder builder(context.get()); - builder.initialize(); - - Value tensor = builder.qtensorAlloc(nqubits); - SmallVector creg(nqubits); - SmallVector qreg(nqubits); + builder.initialize(SmallVector(size, builder.getI1Type())); - for (int64_t i = 0; i < nqubits; ++i) { - std::tie(tensor, qreg[i]) = builder.qtensorExtract(tensor, i); - qreg[i] = builder.h(qreg[i]); + Value tensor = builder.qtensorAlloc(size); + for (int64_t i = 0; i < size; ++i) { + std::tie(tensor, qubits[i]) = builder.qtensorExtract(tensor, i); + qubits[i] = builder.h(qubits[i]); } const auto upForResults = - builder.scfFor(1, 3, 1, {qreg[0], qreg[1], qreg[2]}, + builder.scfFor(1, 3, 1, {qubits[0], qubits[1], qubits[2]}, [&builder](Value, ValueRange iterArgs) { Value iterQ0 = iterArgs[0]; Value iterQ1 = iterArgs[1]; @@ -497,12 +496,12 @@ TEST_P(MappingPassTest, ParallelLoops) { return SmallVector{iterQ0, iterQ1, iterQ2}; }); - qreg[0] = upForResults[0]; - qreg[1] = upForResults[1]; - qreg[2] = upForResults[2]; + qubits[0] = upForResults[0]; + qubits[1] = upForResults[1]; + qubits[2] = upForResults[2]; const auto downForResults = - builder.scfFor(1, 3, 1, {qreg[3], qreg[4], qreg[5]}, + builder.scfFor(1, 3, 1, {qubits[3], qubits[4], qubits[5]}, [&builder](Value, ValueRange iterArgs) { Value iterQ0 = iterArgs[0]; Value iterQ1 = iterArgs[1]; @@ -517,24 +516,24 @@ TEST_P(MappingPassTest, ParallelLoops) { return SmallVector{iterQ0, iterQ1, iterQ2}; }); - qreg[3] = downForResults[0]; - qreg[4] = downForResults[1]; - qreg[5] = downForResults[2]; + qubits[3] = downForResults[0]; + qubits[4] = downForResults[1]; + qubits[5] = downForResults[2]; - qreg = builder.barrier(qreg); + qubits = builder.barrier(qubits); - for (int64_t i = 0; i < nqubits; ++i) { - std::tie(qreg[i], creg[i]) = builder.measure(qreg[i]); - qreg[i] = builder.h(qreg[i]); + for (int64_t i = 0; i < size; ++i) { + std::tie(qubits[i], bits[i]) = builder.measure(qubits[i]); + qubits[i] = builder.h(qubits[i]); } - for (int64_t i = 0; i < nqubits; ++i) { - tensor = builder.qtensorInsert(qreg[i], tensor, i); + for (int64_t i = 0; i < size; ++i) { + tensor = builder.qtensorInsert(qubits[i], tensor, i); } builder.qtensorDealloc(tensor); - auto m = builder.finalize(); + auto m = builder.finalize(bits); auto res = pm.run(m.get()); auto entry = getEntryPoint(m.get()); @@ -544,91 +543,68 @@ TEST_P(MappingPassTest, ParallelLoops) { TEST_P(MappingPassTest, Sabre) { const auto& device = GetParam(); + constexpr int64_t size = 6; + + SmallVector qubits(size); + SmallVector bits(size); QCOProgramBuilder builder(context.get()); - builder.initialize(); + builder.initialize(SmallVector(6, builder.getI1Type())); Value tensorUp = builder.qtensorAlloc(4); Value tensorDown = builder.qtensorAlloc(2); - Value q0; - std::tie(tensorUp, q0) = builder.qtensorExtract(tensorUp, 0); - - Value q1; - std::tie(tensorUp, q1) = builder.qtensorExtract(tensorUp, 1); - - Value q2; - std::tie(tensorUp, q2) = builder.qtensorExtract(tensorUp, 2); + std::tie(tensorUp, qubits[0]) = builder.qtensorExtract(tensorUp, 0); + std::tie(tensorUp, qubits[1]) = builder.qtensorExtract(tensorUp, 1); + std::tie(tensorUp, qubits[2]) = builder.qtensorExtract(tensorUp, 2); + std::tie(tensorUp, qubits[3]) = builder.qtensorExtract(tensorUp, 3); + std::tie(tensorDown, qubits[4]) = builder.qtensorExtract(tensorDown, 0); + std::tie(tensorDown, qubits[5]) = builder.qtensorExtract(tensorDown, 1); - Value q3; - std::tie(tensorUp, q3) = builder.qtensorExtract(tensorUp, 3); - - Value q4; - std::tie(tensorDown, q4) = builder.qtensorExtract(tensorDown, 0); - - Value q5; - std::tie(tensorDown, q5) = builder.qtensorExtract(tensorDown, 1); - - q0 = builder.h(q0); - q1 = builder.h(q1); - q4 = builder.h(q4); + qubits[0] = builder.h(qubits[0]); + qubits[1] = builder.h(qubits[1]); + qubits[4] = builder.h(qubits[4]); - q0 = builder.z(q0); - std::tie(q1, q2) = builder.cx(q1, q2); - std::tie(q4, q5) = builder.cx(q4, q5); + qubits[0] = builder.z(qubits[0]); + std::tie(qubits[1], qubits[2]) = builder.cx(qubits[1], qubits[2]); + std::tie(qubits[4], qubits[5]) = builder.cx(qubits[4], qubits[5]); - std::tie(q0, q1) = builder.cx(q0, q1); + std::tie(qubits[0], qubits[1]) = builder.cx(qubits[0], qubits[1]); - q0 = builder.h(q0); - q1 = builder.y(q1); - std::tie(q0, q1) = builder.cx(q0, q1); + qubits[0] = builder.h(qubits[0]); + qubits[1] = builder.y(qubits[1]); + std::tie(qubits[0], qubits[1]) = builder.cx(qubits[0], qubits[1]); - std::tie(q2, q3) = builder.cx(q2, q3); + std::tie(qubits[2], qubits[3]) = builder.cx(qubits[2], qubits[3]); - q2 = builder.h(q2); - q3 = builder.h(q3); + qubits[2] = builder.h(qubits[2]); + qubits[3] = builder.h(qubits[3]); - std::tie(q1, q2) = builder.cx(q1, q2); - std::tie(q3, q5) = builder.cx(q3, q5); + std::tie(qubits[1], qubits[2]) = builder.cx(qubits[1], qubits[2]); + std::tie(qubits[3], qubits[5]) = builder.cx(qubits[3], qubits[5]); - q3 = builder.z(q3); + qubits[3] = builder.z(qubits[3]); - std::tie(q3, q4) = builder.cx(q3, q4); + std::tie(qubits[3], qubits[4]) = builder.cx(qubits[3], qubits[4]); - std::tie(q3, q0) = builder.cx(q3, q0); + std::tie(qubits[3], qubits[0]) = builder.cx(qubits[3], qubits[0]); - ValueRange out = builder.barrier({q0, q1, q2, q3, q4, q5}); - q0 = out[0]; - q1 = out[1]; - q2 = out[2]; - q3 = out[3]; - q4 = out[4]; - q5 = out[5]; + qubits = builder.barrier(qubits); - Value c0; - Value c1; - Value c2; - Value c3; - Value c4; - Value c5; + for (int64_t i = 0; i < size; ++i) { + std::tie(qubits[i], bits[i]) = builder.measure(qubits[i]); + } - std::tie(q0, c0) = builder.measure(q0); - std::tie(q1, c1) = builder.measure(q1); - std::tie(q2, c2) = builder.measure(q2); - std::tie(q3, c3) = builder.measure(q3); - std::tie(q4, c4) = builder.measure(q4); - std::tie(q5, c5) = builder.measure(q5); - - tensorUp = builder.qtensorInsert(q0, tensorUp, 0); - tensorUp = builder.qtensorInsert(q1, tensorUp, 1); - tensorUp = builder.qtensorInsert(q2, tensorUp, 2); - tensorUp = builder.qtensorInsert(q3, tensorUp, 3); - tensorDown = builder.qtensorInsert(q4, tensorDown, 0); - tensorDown = builder.qtensorInsert(q5, tensorDown, 1); + tensorUp = builder.qtensorInsert(qubits[0], tensorUp, 0); + tensorUp = builder.qtensorInsert(qubits[1], tensorUp, 1); + tensorUp = builder.qtensorInsert(qubits[2], tensorUp, 2); + tensorUp = builder.qtensorInsert(qubits[3], tensorUp, 3); + tensorDown = builder.qtensorInsert(qubits[4], tensorDown, 0); + tensorDown = builder.qtensorInsert(qubits[5], tensorDown, 1); builder.qtensorDealloc(tensorUp); builder.qtensorDealloc(tensorDown); - auto m = builder.finalize(); + auto m = builder.finalize(bits); auto res = runPass(m.get(), device.couplingSet, MappingPassOptions{}); auto entry = getEntryPoint(m.get()); @@ -638,35 +614,36 @@ TEST_P(MappingPassTest, Sabre) { TEST_P(MappingPassTest, RandomOrderGHZ) { const auto& device = GetParam(); + constexpr int64_t size = 9; - QCOProgramBuilder builder(context.get()); - builder.initialize(); + SmallVector qubits(size); + SmallVector bits(size); - Value tensor = builder.qtensorAlloc(9); - SmallVector qubits(9); - SmallVector cregs(9); + QCOProgramBuilder builder(context.get()); + builder.initialize(SmallVector(size, builder.getI1Type())); - for (int64_t i = 0; i < 9; ++i) { + Value tensor = builder.qtensorAlloc(size); + for (int64_t i = 0; i < size; ++i) { std::tie(tensor, qubits[i]) = builder.qtensorExtract(tensor, i); } qubits[0] = builder.h(qubits[0]); - std::tie(qubits[0], cregs[0]) = builder.measure(qubits[0]); + std::tie(qubits[0], bits[0]) = builder.measure(qubits[0]); qubits = builder.qcoIf( - cregs[0], qubits, + bits[0], qubits, [&](ValueRange args) { SmallVector values(args); values[0] = builder.h(values[0]); - for (size_t i = 1; i < 9; ++i) { + for (size_t i = 1; i < size; ++i) { std::tie(values[0], values[i]) = builder.cx(values[0], values[i]); } return values; }, [&](ValueRange args) { SmallVector values(args); - values[8] = builder.h(values[8]); - for (size_t i = 8; i > 0; --i) { + values[size - 1] = builder.h(values[size - 1]); + for (size_t i = size - 1; i > 0; --i) { std::tie(values[8], values[i - 1]) = builder.cx(values[8], values[i - 1]); } @@ -675,17 +652,17 @@ TEST_P(MappingPassTest, RandomOrderGHZ) { qubits = builder.barrier(qubits); - for (int64_t i = 0; i < 9; ++i) { - std::tie(qubits[i], cregs[i]) = builder.measure(qubits[i]); + for (int64_t i = 0; i < size; ++i) { + std::tie(qubits[i], bits[i]) = builder.measure(qubits[i]); } - for (int64_t i = 0; i < 9; ++i) { + for (int64_t i = 0; i < size; ++i) { tensor = builder.qtensorInsert(qubits[i], tensor, i); } builder.qtensorDealloc(tensor); - auto m = builder.finalize(); + auto m = builder.finalize(bits); auto res = runPass(m.get(), device.couplingSet, MappingPassOptions{.ntrials = 1}); auto entry = getEntryPoint(m.get()); From 75767b263aea2f364a64402df65700644c177d15 Mon Sep 17 00:00:00 2001 From: Matthias Reumann Date: Fri, 10 Jul 2026 13:07:59 +0200 Subject: [PATCH 78/80] Add missing include --- mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp b/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp index ef4da7e933..3153febf45 100644 --- a/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp +++ b/mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include From 5a775ac3b60c45bd8b30cacc647a8896665be29a Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Sat, 11 Jul 2026 03:16:14 +0200 Subject: [PATCH 79/80] feat(mlir): :sparkles: report all qubits in Qasm3 if no output statement is used --- .../QC/Translation/TranslateQASM3ToQC.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp b/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp index c00290455e..eab7843753 100644 --- a/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp +++ b/mlir/lib/Dialect/QC/Translation/TranslateQASM3ToQC.cpp @@ -221,6 +221,10 @@ class MLIRQasmImporter final : public qasm3::InstVisitor { } OwningOpRef finalize() { + if (outputRegisters.empty()) { + outputRegisters = allBitRegisters; + } + if (outputRegisters.empty()) { return builder.finalize(); } @@ -271,6 +275,9 @@ class MLIRQasmImporter final : public qasm3::InstVisitor { /// Map from classical-register name to measurement results. llvm::StringMap> bitValues; + /// Names of all bit registers, in declaration order. + SmallVector allBitRegisters; + /// Names of classical registers declared as output, in declaration order. SmallVector outputRegisters; @@ -397,10 +404,12 @@ class MLIRQasmImporter final : public qasm3::InstVisitor { case qasm3::Int: case qasm3::Uint: { classicalRegisters[id] = builder.allocClassicalBitRegister(size, id); - if ((stmt->isOutput || openQASM2CompatMode) && - sizedType->type == qasm3::Bit) { - // We return `output` bits in QASM3, or all named bits in QASM2. - outputRegisters.push_back(id); + if (sizedType->type == qasm3::Bit) { + allBitRegisters.push_back(id); + if (stmt->isOutput || openQASM2CompatMode) { + // We return `output` bits in QASM3, or all named bits in QASM2. + outputRegisters.push_back(id); + } } break; } From 2db079dc5b0d205c41270e8cc3a52adaacae1bd0 Mon Sep 17 00:00:00 2001 From: Damian Rovara Date: Sat, 11 Jul 2026 13:32:15 +0200 Subject: [PATCH 80/80] test(mlir): :white_check_mark: simplify tests with new `output` handling in OpenQASM3 --- mlir/unittests/programs/qasm_programs.cpp | 238 +++++++++++----------- 1 file changed, 119 insertions(+), 119 deletions(-) diff --git a/mlir/unittests/programs/qasm_programs.cpp b/mlir/unittests/programs/qasm_programs.cpp index fcd60b0868..eee6350b78 100644 --- a/mlir/unittests/programs/qasm_programs.cpp +++ b/mlir/unittests/programs/qasm_programs.cpp @@ -18,14 +18,14 @@ namespace mlir::qasm { const std::string allocQubit = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit q; -output bit c; +bit c; c = measure q; )qasm"; const std::string allocQubitRegister = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -33,8 +33,8 @@ const std::string allocMultipleQubitRegisters = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q0; qubit[3] q1; -output bit[2] c0; -output bit[3] c1; +bit[2] c0; +bit[3] c1; c0 = measure q0; c1 = measure q1; )qasm"; @@ -42,7 +42,7 @@ c1 = measure q1; const std::string allocLargeRegister = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[100] q; -output bit[2] c; +bit[2] c; c[0] = measure q[0]; c[1] = measure q[99]; )qasm"; @@ -50,14 +50,14 @@ c[1] = measure q[99]; const std::string singleMeasurementToSingleBit = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; -output bit[1] c; +bit[1] c; measure q[0] -> c[0]; )qasm"; const std::string repeatedMeasurementToSameBit = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; -output bit[1] c; +bit[1] c; measure q[0] -> c[0]; measure q[0] -> c[0]; measure q[0] -> c[0]; @@ -66,7 +66,7 @@ measure q[0] -> c[0]; const std::string repeatedMeasurementToDifferentBits = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; -output bit[3] c; +bit[3] c; measure q[0] -> c[0]; measure q[0] -> c[1]; measure q[0] -> c[2]; @@ -76,8 +76,8 @@ const std::string multipleClassicalRegistersAndMeasurements = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; -output bit[1] c0; -output bit[2] c1; +bit[1] c0; +bit[2] c1; measure q[0] -> c0[0]; measure q[1] -> c1[0]; measure q[2] -> c1[1]; @@ -86,7 +86,7 @@ measure q[2] -> c1[1]; const std::string resetQubitAfterSingleOp = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; -output bit[1] c; +bit[1] c; h q[0]; reset q[0]; c = measure q; @@ -95,7 +95,7 @@ c = measure q; const std::string resetMultipleQubitsAfterSingleOp = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; -output bit[2] c; +bit[2] c; h q[0]; reset q[0]; h q[1]; @@ -106,7 +106,7 @@ c = measure q; const std::string repeatedResetAfterSingleOp = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; -output bit[1] c; +bit[1] c; h q[0]; reset q[0]; reset q[0]; @@ -128,7 +128,7 @@ const std::string identity = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; id q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -136,7 +136,7 @@ const std::string singleControlledIdentity = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ id q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -144,7 +144,7 @@ const std::string multipleControlledIdentity = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ id q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -152,7 +152,7 @@ const std::string x = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; x q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -160,7 +160,7 @@ const std::string twoX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; x q; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -168,7 +168,7 @@ const std::string singleControlledX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ x q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -176,7 +176,7 @@ const std::string singleNegControlledX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; negctrl @ x q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -184,7 +184,7 @@ const std::string multipleControlledX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ x q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -200,7 +200,7 @@ const std::string mixedControlledX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ negctrl @ x q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -210,9 +210,9 @@ qubit[2] q1; qubit[2] q2; qubit[2] q3; ctrl @ negctrl @ x q1, q2, q3; -output bit[2] c1; -output bit[2] c2; -output bit[2] c3; +bit[2] c1; +bit[2] c2; +bit[2] c3; c1 = measure q1; c2 = measure q2; c3 = measure q3; @@ -222,7 +222,7 @@ const std::string inverseX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; inv @ x q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -230,7 +230,7 @@ const std::string inverseMultipleControlledX = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; inv @ ctrl(2) @ x q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -238,7 +238,7 @@ const std::string y = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; y q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -246,7 +246,7 @@ const std::string singleControlledY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ y q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -254,7 +254,7 @@ const std::string multipleControlledY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ y q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -262,7 +262,7 @@ const std::string z = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; z q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -270,7 +270,7 @@ const std::string singleControlledZ = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ z q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -278,7 +278,7 @@ const std::string multipleControlledZ = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ z q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -286,7 +286,7 @@ const std::string h = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; h q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -294,7 +294,7 @@ const std::string singleControlledH = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ h q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -302,7 +302,7 @@ const std::string multipleControlledH = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ h q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -310,7 +310,7 @@ const std::string s = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; s q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -318,7 +318,7 @@ const std::string singleControlledS = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ s q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -326,7 +326,7 @@ const std::string multipleControlledS = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ s q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -334,7 +334,7 @@ const std::string sdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; sdg q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -342,7 +342,7 @@ const std::string singleControlledSdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ sdg q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -350,7 +350,7 @@ const std::string multipleControlledSdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ sdg q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -358,7 +358,7 @@ const std::string t_ = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; t q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -366,7 +366,7 @@ const std::string singleControlledT = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ t q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -374,7 +374,7 @@ const std::string multipleControlledT = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ t q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -382,7 +382,7 @@ const std::string tdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; tdg q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -390,7 +390,7 @@ const std::string singleControlledTdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ tdg q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -398,7 +398,7 @@ const std::string multipleControlledTdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ tdg q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -406,7 +406,7 @@ const std::string sx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; sx q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -414,7 +414,7 @@ const std::string singleControlledSx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ sx q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -422,7 +422,7 @@ const std::string multipleControlledSx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ sx q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -430,7 +430,7 @@ const std::string sxdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; sxdg q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -438,7 +438,7 @@ const std::string singleControlledSxdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ sxdg q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -446,7 +446,7 @@ const std::string multipleControlledSxdg = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ sxdg q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -454,7 +454,7 @@ const std::string rx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; rx(0.123) q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -462,7 +462,7 @@ const std::string singleControlledRx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ rx(0.123) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -470,7 +470,7 @@ const std::string multipleControlledRx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ rx(0.123) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -478,7 +478,7 @@ const std::string ry = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; ry(0.456) q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -486,7 +486,7 @@ const std::string singleControlledRy = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ ry(0.456) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -494,7 +494,7 @@ const std::string multipleControlledRy = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ ry(0.456) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -502,7 +502,7 @@ const std::string rz = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; rz(0.789) q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -510,7 +510,7 @@ const std::string singleControlledRz = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ rz(0.789) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -518,7 +518,7 @@ const std::string multipleControlledRz = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ rz(0.789) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -526,7 +526,7 @@ const std::string p = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; p(0.123) q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -534,7 +534,7 @@ const std::string singleControlledP = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ p(0.123) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -542,7 +542,7 @@ const std::string multipleControlledP = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ p(0.123) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -550,7 +550,7 @@ const std::string r = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; r(0.123, 0.456) q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -558,7 +558,7 @@ const std::string singleControlledR = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ r(0.123, 0.456) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -566,7 +566,7 @@ const std::string multipleControlledR = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ r(0.123, 0.456) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -574,7 +574,7 @@ const std::string u2 = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; u2(0.234, 0.567) q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -582,7 +582,7 @@ const std::string singleControlledU2 = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ u2(0.234, 0.567) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -590,7 +590,7 @@ const std::string multipleControlledU2 = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ u2(0.234, 0.567) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -598,7 +598,7 @@ const std::string u = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; u(0.1, 0.2, 0.3) q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -606,7 +606,7 @@ const std::string singleControlledU = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ctrl @ u(0.1, 0.2, 0.3) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -614,7 +614,7 @@ const std::string multipleControlledU = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl(2) @ u(0.1, 0.2, 0.3) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -622,7 +622,7 @@ const std::string swap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; swap q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -630,7 +630,7 @@ const std::string singleControlledSwap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ swap q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -638,7 +638,7 @@ const std::string multipleControlledSwap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ swap q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -646,7 +646,7 @@ const std::string iswap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; iswap q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -654,7 +654,7 @@ const std::string singleControlledIswap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ iswap q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -662,7 +662,7 @@ const std::string multipleControlledIswap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ iswap q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -670,7 +670,7 @@ const std::string inverseIswap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; inv @ iswap q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -678,7 +678,7 @@ const std::string inverseMultipleControlledIswap = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; inv @ ctrl(2) @ iswap q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -686,7 +686,7 @@ const std::string dcx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; dcx q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -694,7 +694,7 @@ const std::string singleControlledDcx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ dcx q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -702,7 +702,7 @@ const std::string multipleControlledDcx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ dcx q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -710,7 +710,7 @@ const std::string ecr = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ecr q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -718,7 +718,7 @@ const std::string singleControlledEcr = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ ecr q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -726,7 +726,7 @@ const std::string multipleControlledEcr = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ ecr q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -734,7 +734,7 @@ const std::string rxx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; rxx(0.123) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -742,7 +742,7 @@ const std::string singleControlledRxx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ rxx(0.123) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -750,7 +750,7 @@ const std::string multipleControlledRxx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ rxx(0.123) q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -758,7 +758,7 @@ const std::string tripleControlledRxx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[5] q; ctrl(3) @ rxx(0.123) q[0], q[1], q[2], q[3], q[4]; -output bit[5] c; +bit[5] c; c = measure q; )qasm"; @@ -766,7 +766,7 @@ const std::string ryy = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; ryy(0.123) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -774,7 +774,7 @@ const std::string singleControlledRyy = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ ryy(0.123) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -782,7 +782,7 @@ const std::string multipleControlledRyy = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ ryy(0.123) q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -790,7 +790,7 @@ const std::string rzx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; rzx(0.123) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -798,7 +798,7 @@ const std::string singleControlledRzx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ rzx(0.123) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -806,7 +806,7 @@ const std::string multipleControlledRzx = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ rzx(0.123) q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -814,7 +814,7 @@ const std::string rzz = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; rzz(0.123) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -822,7 +822,7 @@ const std::string singleControlledRzz = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ rzz(0.123) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -830,7 +830,7 @@ const std::string multipleControlledRzz = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ rzz(0.123) q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -838,7 +838,7 @@ const std::string xxPlusYY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; xx_plus_yy(0.123, 0.456) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -846,7 +846,7 @@ const std::string singleControlledXxPlusYY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ xx_plus_yy(0.123, 0.456) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -854,7 +854,7 @@ const std::string multipleControlledXxPlusYY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ xx_plus_yy(0.123, 0.456) q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -862,7 +862,7 @@ const std::string xxMinusYY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; xx_minus_yy(0.123, 0.456) q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -870,7 +870,7 @@ const std::string singleControlledXxMinusYY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; ctrl @ xx_minus_yy(0.123, 0.456) q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -878,7 +878,7 @@ const std::string multipleControlledXxMinusYY = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[4] q; ctrl(2) @ xx_minus_yy(0.123, 0.456) q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -886,7 +886,7 @@ const std::string barrier = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; barrier q[0]; -output bit[1] c; +bit[1] c; c = measure q; )qasm"; @@ -894,7 +894,7 @@ const std::string barrierTwoQubits = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; barrier q[0], q[1]; -output bit[2] c; +bit[2] c; c = measure q; )qasm"; @@ -902,7 +902,7 @@ const std::string barrierMultipleQubits = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[3] q; barrier q[0], q[1], q[2]; -output bit[3] c; +bit[3] c; c = measure q; )qasm"; @@ -914,7 +914,7 @@ gate compound q0, q1 { rxx(0.123) q0, q1; } ctrl(2) @ compound q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -926,7 +926,7 @@ gate compound q0, q1 { rxx(0.123) q0, q1; } ctrl(2) @ compound q[0], q[1], q[2], q[3]; -output bit[4] c; +bit[4] c; c = measure q; )qasm"; @@ -934,11 +934,11 @@ const std::string simpleIf = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; h q[0]; -output bit c = measure q[0]; +bit c = measure q[0]; if (c) { x q[0]; } -output bit[1] out; +bit[1] out; out = measure q; )qasm"; @@ -958,12 +958,12 @@ const std::string ifTwoQubits = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; h q[0]; -output bit c = measure q[0]; +bit c = measure q[0]; if (c) { x q[0]; x q[1]; } -output bit[2] out; +bit[2] out; out = measure q; )qasm"; @@ -984,13 +984,13 @@ const std::string ifElse = R"qasm(OPENQASM 3.0; include "stdgates.inc"; qubit[1] q; h q[0]; -output bit c = measure q[0]; +bit c = measure q[0]; if (c) { x q[0]; } else { z q[0]; } -output bit[1] out; +bit[1] out; out = measure q; )qasm";