Skip to content

Commit 7c36b60

Browse files
authored
Merge branch 'main' into enh/use-wireiterator-in-merge-1q-rotations
Signed-off-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com>
2 parents 0b5f825 + e68b416 commit 7c36b60

63 files changed

Lines changed: 856 additions & 1000 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This project adheres to [Semantic Versioning], with the exception that minor rel
1515
- ✨ Add conversions between `jeff` and QCO ([#1479], [#1548], [#1565], [#1637]) ([**@denialhaag**])
1616
- ✨ Add a `place-and-route` pass for mapping circuits to architectures with restricted topologies ([#1537], [#1547], [#1568], [#1581], [#1583], [#1588], [#1664]) ([**@MatthiasReumann**], [**@burgholzer**])
1717
- ✨ Add initial infrastructure for new QC and QCO MLIR dialects
18-
([#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])
18+
([#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], [#1673])
1919
([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**], [**@simon1hofmann**])
2020

2121
### Changed
@@ -361,6 +361,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool
361361

362362
<!-- PR links -->
363363

364+
[#1673]: https://github.com/munich-quantum-toolkit/core/pull/1673
364365
[#1664]: https://github.com/munich-quantum-toolkit/core/pull/1664
365366
[#1662]: https://github.com/munich-quantum-toolkit/core/pull/1662
366367
[#1652]: https://github.com/munich-quantum-toolkit/core/pull/1652

mlir/include/mlir/Dialect/QC/Builder/QCProgramBuilder.h

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@
1010

1111
#pragma once
1212

13-
#include <llvm/ADT/DenseSet.h>
14-
#include <llvm/ADT/STLFunctionalExtras.h>
15-
#include <llvm/Support/ErrorHandling.h>
1613
#include <mlir/IR/Builders.h>
17-
#include <mlir/IR/BuiltinOps.h>
18-
#include <mlir/IR/MLIRContext.h>
1914
#include <mlir/IR/OwningOpRef.h>
2015
#include <mlir/IR/Value.h>
21-
#include <mlir/IR/ValueRange.h>
2216
#include <mlir/Support/LLVM.h>
2317

2418
#include <cstdint>
2519
#include <string>
2620
#include <variant>
2721

28-
namespace mlir::qc {
22+
namespace mlir {
23+
24+
// Forward declarations
25+
class MLIRContext;
26+
class ModuleOp;
27+
class Operation;
28+
class ValueRange;
29+
30+
namespace qc {
2931

3032
/**
3133
* @brief Builder API for constructing quantum programs in the QC dialect
@@ -113,12 +115,7 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
113115
* @param index The index of the qubit to access
114116
* @return The specified qubit value
115117
*/
116-
Value operator[](size_t index) const {
117-
if (index >= qubits.size()) {
118-
llvm::report_fatal_error("Qubit index out of bounds");
119-
}
120-
return qubits[index];
121-
}
118+
Value operator[](size_t index) const;
122119

123120
/**
124121
* @brief Conversion to the backing MemRef value
@@ -201,16 +198,7 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
201198
* @param index The index of the bit to access (must be less than size)
202199
* @return A Bit structure representing the specified bit
203200
*/
204-
Bit operator[](const int64_t index) const {
205-
if (index < 0 || index >= size) {
206-
const std::string msg = "Bit index " + std::to_string(index) +
207-
" out of bounds for register '" + name +
208-
"' of size " + std::to_string(size);
209-
llvm::reportFatalUsageError(msg.c_str());
210-
}
211-
return {
212-
.registerName = name, .registerSize = size, .registerIndex = index};
213-
}
201+
Bit operator[](const int64_t index) const;
214202
};
215203

216204
/**
@@ -891,8 +879,7 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
891879
* } : !qc.qubit
892880
* ```
893881
*/
894-
QCProgramBuilder& ctrl(ValueRange controls,
895-
const llvm::function_ref<void()>& body);
882+
QCProgramBuilder& ctrl(ValueRange controls, const function_ref<void()>& body);
896883

897884
/**
898885
* @brief Apply an inverse (i.e., adjoint) operation.
@@ -911,7 +898,7 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
911898
* }
912899
* ```
913900
*/
914-
QCProgramBuilder& inv(const llvm::function_ref<void()>& body);
901+
QCProgramBuilder& inv(const function_ref<void()>& body);
915902

916903
//===--------------------------------------------------------------------===//
917904
// Deallocation
@@ -965,19 +952,19 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
965952
*/
966953
static OwningOpRef<ModuleOp>
967954
build(MLIRContext* context,
968-
const llvm::function_ref<void(QCProgramBuilder&)>& buildFunc);
955+
const function_ref<void(QCProgramBuilder&)>& buildFunc);
969956

970957
private:
971958
enum class AllocationMode : uint8_t { Unset, Static, Dynamic };
972959

973960
MLIRContext* ctx{};
974-
ModuleOp module;
961+
Operation* module;
975962

976963
/// Track allocated qubits for automatic deallocation
977-
llvm::DenseSet<Value> allocatedQubits;
964+
DenseSet<Value> allocatedQubits;
978965

979966
/// Track allocated MemRefs for automatic deallocation
980-
llvm::DenseSet<Value> allocatedMemrefs;
967+
DenseSet<Value> allocatedMemrefs;
981968

982969
/// Check if the builder has been finalized
983970
void checkFinalized() const;
@@ -988,4 +975,5 @@ class QCProgramBuilder final : public ImplicitLocOpBuilder {
988975
/// Ensure static and dynamic qubit allocation modes are not mixed.
989976
void ensureAllocationMode(AllocationMode requestedMode);
990977
};
991-
} // namespace mlir::qc
978+
} // namespace qc
979+
} // namespace mlir

mlir/include/mlir/Dialect/QC/IR/QCDialect.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#pragma once
1212

13-
#include <mlir/IR/Dialect.h>
1413
#include <mlir/IR/OpDefinition.h>
1514

1615
#define DIALECT_NAME_QC "qc"

mlir/include/mlir/Dialect/QC/IR/QCInterfaces.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
#pragma once
1212

13-
#include <llvm/ADT/StringRef.h>
14-
#include <mlir/IR/OpDefinition.h>
15-
#include <mlir/IR/Value.h>
13+
#include <mlir/Support/LLVM.h>
1614

1715
#include <cstddef>
1816

mlir/include/mlir/Dialect/QC/IR/QCOps.td

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ def CtrlOp
960960
}];
961961

962962
let builders = [OpBuilder<(ins "ValueRange":$controls,
963-
"const llvm::function_ref<void()>&":$bodyBuilder)>];
963+
"const function_ref<void()>&":$bodyBuilder)>];
964964

965965
let hasCanonicalizer = 1;
966966
let hasVerifier = 1;
@@ -1002,8 +1002,7 @@ def InvOp : QCOp<"inv",
10021002
static StringRef getBaseSymbol() { return "inv"; }
10031003
}];
10041004

1005-
let builders = [OpBuilder<(ins
1006-
"const llvm::function_ref<void()>&":$bodyBuilder)>];
1005+
let builders = [OpBuilder<(ins "const function_ref<void()>&":$bodyBuilder)>];
10071006

10081007
let hasCanonicalizer = 1;
10091008
let hasVerifier = 1;

mlir/include/mlir/Dialect/QC/Transforms/Passes.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
#pragma once
1212

13-
#include "mlir/Dialect/QC/IR/QCDialect.h"
14-
1513
#include <mlir/Pass/Pass.h>
1614
#include <mlir/Pass/PassRegistry.h>
1715

mlir/include/mlir/Dialect/QCO/Builder/QCOProgramBuilder.h

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,25 @@
1010

1111
#pragma once
1212

13-
#include <llvm/ADT/DenseMap.h>
14-
#include <llvm/ADT/DenseSet.h>
15-
#include <llvm/ADT/STLFunctionalExtras.h>
16-
#include <llvm/Support/ErrorHandling.h>
1713
#include <mlir/IR/Builders.h>
18-
#include <mlir/IR/BuiltinOps.h>
19-
#include <mlir/IR/MLIRContext.h>
2014
#include <mlir/IR/OwningOpRef.h>
2115
#include <mlir/IR/Value.h>
22-
#include <mlir/IR/ValueRange.h>
2316
#include <mlir/Support/LLVM.h>
2417

2518
#include <cstdint>
2619
#include <string>
2720
#include <utility>
2821
#include <variant>
2922

30-
namespace mlir::qco {
23+
namespace mlir {
24+
25+
// Forward declarations
26+
class MLIRContext;
27+
class ModuleOp;
28+
class Operation;
29+
class ValueRange;
30+
31+
namespace qco {
3132

3233
/**
3334
* @brief Builder API for constructing quantum programs in the QCO dialect
@@ -122,12 +123,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
122123
* @param index The index of the qubit to access
123124
* @return The specified qubit value
124125
*/
125-
Value& operator[](size_t index) {
126-
if (index >= qubits.size()) {
127-
llvm::reportFatalUsageError("Qubit index out of bounds");
128-
}
129-
return qubits[index];
130-
}
126+
Value& operator[](size_t index);
131127

132128
/**
133129
* @brief Conversion to the backing QTensor value
@@ -210,16 +206,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
210206
* @param index The index of the bit to access (must be less than size)
211207
* @return A Bit structure representing the specified bit
212208
*/
213-
Bit operator[](const int64_t index) const {
214-
if (index < 0 || index >= size) {
215-
const std::string msg = "Bit index " + std::to_string(index) +
216-
" out of bounds for register '" + name +
217-
"' of size " + std::to_string(size);
218-
llvm::reportFatalUsageError(msg.c_str());
219-
}
220-
return {
221-
.registerName = name, .registerSize = size, .registerIndex = index};
222-
}
209+
Bit operator[](int64_t index) const;
223210
};
224211

225212
/**
@@ -1171,7 +1158,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
11711158
*/
11721159
std::pair<ValueRange, ValueRange>
11731160
ctrl(ValueRange controls, ValueRange targets,
1174-
llvm::function_ref<SmallVector<Value>(ValueRange)> body);
1161+
function_ref<SmallVector<Value>(ValueRange)> body);
11751162

11761163
/**
11771164
* @brief Apply an inverse operation
@@ -1196,7 +1183,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
11961183
* ```
11971184
*/
11981185
ValueRange inv(ValueRange qubits,
1199-
llvm::function_ref<SmallVector<Value>(ValueRange)> body);
1186+
function_ref<SmallVector<Value>(ValueRange)> body);
12001187

12011188
//===--------------------------------------------------------------------===//
12021189
// Deallocation
@@ -1263,8 +1250,8 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
12631250
*/
12641251
ValueRange
12651252
qcoIf(const std::variant<bool, Value>& condition, ValueRange qubits,
1266-
llvm::function_ref<SmallVector<Value>(ValueRange)> thenBody,
1267-
llvm::function_ref<SmallVector<Value>(ValueRange)> elseBody = nullptr);
1253+
function_ref<SmallVector<Value>(ValueRange)> thenBody,
1254+
function_ref<SmallVector<Value>(ValueRange)> elseBody = nullptr);
12681255

12691256
//===--------------------------------------------------------------------===//
12701257
// Finalization
@@ -1294,13 +1281,13 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
12941281
*/
12951282
static OwningOpRef<ModuleOp>
12961283
build(MLIRContext* context,
1297-
const llvm::function_ref<void(QCOProgramBuilder&)>& buildFunc);
1284+
const function_ref<void(QCOProgramBuilder&)>& buildFunc);
12981285

12991286
private:
13001287
enum class AllocationMode : uint8_t { Unset, Static, Dynamic };
13011288

13021289
MLIRContext* ctx{};
1303-
ModuleOp module;
1290+
Operation* module;
13041291

13051292
/// Check if the builder has been finalized
13061293
void checkFinalized() const;
@@ -1340,7 +1327,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
13401327
/// Only values present in this map are valid for use in operations.
13411328
/// When an operation consumes a qubit and produces a new one, the old value
13421329
/// is removed and the new output is added.
1343-
llvm::DenseMap<Value, QubitInfo> validQubits;
1330+
DenseMap<Value, QubitInfo> validQubits;
13441331

13451332
/**
13461333
* @brief Validate that a tensor value is valid and unconsumed. This also
@@ -1370,12 +1357,13 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
13701357
/// Only values present in this map are valid for use in operations.
13711358
/// When an operation consumes a tensor and produces a new one, the old value
13721359
/// is removed and the new output is added.
1373-
llvm::DenseMap<Value, TensorInfo> validTensors;
1360+
DenseMap<Value, TensorInfo> validTensors;
13741361

13751362
/// Track whether static or dynamic qubit allocation is used.
13761363
AllocationMode allocationMode = AllocationMode::Unset;
13771364

13781365
/// Ensure static and dynamic qubit allocation modes are not mixed.
13791366
void ensureAllocationMode(AllocationMode requestedMode);
13801367
};
1381-
} // namespace mlir::qco
1368+
} // namespace qco
1369+
} // namespace mlir

mlir/include/mlir/Dialect/QCO/IR/QCODialect.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
#pragma once
1212

13-
#include <mlir/IR/Dialect.h>
14-
#include <mlir/IR/MLIRContext.h>
1513
#include <mlir/IR/OpDefinition.h>
1614

1715
#define DIALECT_NAME_QCO "qco"

mlir/include/mlir/Dialect/QCO/IR/QCOInterfaces.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
#pragma once
1212

1313
#include <Eigen/Core>
14-
#include <llvm/ADT/StringRef.h>
1514
#include <llvm/Support/ErrorHandling.h>
1615
#include <mlir/IR/OpDefinition.h>
17-
#include <mlir/IR/Value.h>
18-
#include <mlir/IR/ValueRange.h>
16+
#include <mlir/Support/LLVM.h>
1917

2018
#include <complex>
2119
#include <cstddef>

mlir/include/mlir/Dialect/QCO/IR/QCOOps.td

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ def CtrlOp
11321132
build($_builder, $_state, controls.getTypes(), targets.getTypes(), controls, targets);
11331133
}]>,
11341134
OpBuilder<(ins "ValueRange":$controls, "ValueRange":$targets,
1135-
"llvm::function_ref<llvm::SmallVector<Value>(ValueRange)"
1135+
"function_ref<SmallVector<Value>(ValueRange)"
11361136
">":$bodyBuilder)>];
11371137

11381138
let hasCanonicalizer = 1;
@@ -1202,7 +1202,7 @@ def InvOp
12021202
build($_builder, $_state, qubits.getTypes(), qubits);
12031203
}]>,
12041204
OpBuilder<(ins "ValueRange":$qubits,
1205-
"llvm::function_ref<llvm::SmallVector<Value>(ValueRange)"
1205+
"function_ref<SmallVector<Value>(ValueRange)"
12061206
">":$bodyBuilder)>];
12071207

12081208
let hasCanonicalizer = 1;
@@ -1256,15 +1256,14 @@ def IfOp
12561256
`{` type($results) `}`
12571257
}];
12581258

1259-
let builders =
1260-
[OpBuilder<(ins "Value":$condition, "ValueRange":$qubits), [{
1259+
let builders = [OpBuilder<(ins "Value":$condition, "ValueRange":$qubits), [{
12611260
build($_builder, $_state, qubits.getTypes(), condition, qubits);
12621261
}]>,
1263-
OpBuilder<(ins "Value":$condition, "ValueRange":$qubits,
1264-
"llvm::function_ref<llvm::SmallVector<Value>(ValueRange)"
1265-
">":$thenBuilder,
1266-
CArg<"llvm::function_ref<llvm::SmallVector<Value>(ValueRange)>",
1267-
"nullptr">:$elseBuilder)>];
1262+
OpBuilder<(ins "Value":$condition, "ValueRange":$qubits,
1263+
"function_ref<SmallVector<Value>(ValueRange)"
1264+
">":$thenBuilder,
1265+
CArg<"function_ref<SmallVector<Value>(ValueRange)>",
1266+
"nullptr">:$elseBuilder)>];
12681267

12691268
let extraClassDeclaration = [{
12701269
Block *thenBlock() {

0 commit comments

Comments
 (0)