Skip to content

Commit 50e6215

Browse files
authored
Merge branch 'main' into qco-if
Signed-off-by: Lukas Burgholzer <burgholzer@me.com>
2 parents edc452e + 756d3c1 commit 50e6215

File tree

18 files changed

+476
-95
lines changed

18 files changed

+476
-95
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ repos:
3030

3131
## Check the pyproject.toml file
3232
- repo: https://github.com/henryiii/validate-pyproject-schema-store
33-
rev: 2026.02.15
33+
rev: 2026.02.21
3434
hooks:
3535
- id: validate-pyproject
3636
priority: 0
@@ -132,7 +132,7 @@ repos:
132132

133133
## Python linting using ruff
134134
- repo: https://github.com/astral-sh/ruff-pre-commit
135-
rev: v0.15.1
135+
rev: v0.15.2
136136
hooks:
137137
- id: ruff-format
138138
priority: 1

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ This project adheres to [Semantic Versioning], with the exception that minor rel
1212
### Added
1313

1414
- ✨ Add initial infrastructure for new QC and QCO MLIR dialects
15-
([#1264], [#1330], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1474], [#1475], [#1506], [#1513])
16-
([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**])
15+
([#1264], [#1330], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1474], [#1475], [#1506], [#1510], [#1513], [#1521])
16+
([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**])
1717

1818
### Changed
1919

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

328328
<!-- PR links -->
329329

330+
[#1521]: https://github.com/munich-quantum-toolkit/core/pull/1521
330331
[#1513]: https://github.com/munich-quantum-toolkit/core/pull/1513
332+
[#1510]: https://github.com/munich-quantum-toolkit/core/pull/1510
331333
[#1506]: https://github.com/munich-quantum-toolkit/core/pull/1506
332334
[#1481]: https://github.com/munich-quantum-toolkit/core/pull/1481
333335
[#1475]: https://github.com/munich-quantum-toolkit/core/pull/1475

mlir/include/mlir/Conversion/QCOToQC/QCOToQC.h

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

1111
#pragma once
1212

13-
#include <mlir/Pass/Pass.h> // from @llvm-project
13+
#include <mlir/Pass/Pass.h>
1414

1515
namespace mlir {
1616
#define GEN_PASS_DECL_QCOTOQC

mlir/include/mlir/Conversion/QCToQCO/QCToQCO.h

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

1111
#pragma once
1212

13-
#include <mlir/Pass/Pass.h> // from @llvm-project
13+
#include <mlir/Pass/Pass.h>
1414

1515
namespace mlir {
1616
#define GEN_PASS_DECL_QCTOQCO

mlir/include/mlir/Conversion/QCToQIR/QCToQIR.h

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

1111
#pragma once
1212

13-
#include <mlir/Pass/Pass.h> // from @llvm-project
13+
#include <mlir/Pass/Pass.h>
1414

1515
namespace mlir {
1616
#define GEN_PASS_DECL_QCTOQIR

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ def CtrlOp : QCOp<"ctrl",
943943
```mlir
944944
qc.ctrl(%q0) {
945945
qc.x %q1 : !qc.qubit
946-
}
946+
} : !qc.qubit
947947
```
948948
}];
949949

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
3+
* Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
4+
* All rights reserved.
5+
*
6+
* SPDX-License-Identifier: MIT
7+
*
8+
* Licensed under the MIT License
9+
*/
10+
11+
#pragma once
12+
13+
#include <iterator>
14+
#include <mlir/IR/Operation.h>
15+
16+
namespace mlir::qco {
17+
18+
/**
19+
* @brief A bidirectional_iterator traversing the def-use chain of a qubit wire.
20+
*
21+
* The iterator follows the flow of a qubit through a sequence of quantum
22+
* operations while respecting the semantics of the respective operation.
23+
**/
24+
class [[nodiscard]] WireIterator {
25+
public:
26+
using iterator_category = std::bidirectional_iterator_tag;
27+
using difference_type = std::ptrdiff_t;
28+
using value_type = mlir::Operation*;
29+
30+
WireIterator() : op_(nullptr), qubit_(nullptr), isSentinel_(false) {}
31+
explicit WireIterator(mlir::Value qubit)
32+
: op_(qubit.getDefiningOp()), qubit_(qubit), isSentinel_(false) {}
33+
34+
/// @returns the operation the iterator points to.
35+
[[nodiscard]] mlir::Operation* operation() const { return op_; }
36+
37+
/// @returns the operation the iterator points to.
38+
[[nodiscard]] mlir::Operation* operator*() const { return operation(); }
39+
40+
/// @returns the qubit the iterator points to.
41+
[[nodiscard]] mlir::Value qubit() const;
42+
43+
WireIterator& operator++() {
44+
forward();
45+
return *this;
46+
}
47+
48+
WireIterator operator++(int) {
49+
auto tmp = *this;
50+
operator++();
51+
return tmp;
52+
}
53+
54+
WireIterator& operator--() {
55+
backward();
56+
return *this;
57+
}
58+
59+
WireIterator operator--(int) {
60+
auto tmp = *this;
61+
operator--();
62+
return tmp;
63+
}
64+
65+
bool operator==(const WireIterator& other) const {
66+
return other.qubit_ == qubit_ && other.op_ == op_ &&
67+
other.isSentinel_ == isSentinel_;
68+
}
69+
70+
bool operator==([[maybe_unused]] std::default_sentinel_t s) const {
71+
return isSentinel_;
72+
}
73+
74+
private:
75+
/// @brief Move to the next operation on the qubit wire.
76+
void forward();
77+
78+
/// @brief Move to the previous operation on the qubit wire.
79+
void backward();
80+
81+
mlir::Operation* op_;
82+
mlir::Value qubit_;
83+
bool isSentinel_;
84+
};
85+
} // namespace mlir::qco

mlir/lib/Conversion/QCOToQC/QCOToQC.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static LogicalResult
6868
convertOneTargetZeroParameter(QCOOpType& op, QCOOpAdaptorType& adaptor,
6969
ConversionPatternRewriter& rewriter) {
7070
// OpAdaptor provides the already type-converted input qubit
71-
const auto& qcQubit = adaptor.getQubitIn();
71+
auto qcQubit = adaptor.getQubitIn();
7272

7373
// Create the QC operation (in-place, no result)
7474
rewriter.create<QCOpType>(op.getLoc(), qcQubit);
@@ -95,7 +95,7 @@ static LogicalResult
9595
convertOneTargetOneParameter(QCOOpType& op, QCOOpAdaptorType& adaptor,
9696
ConversionPatternRewriter& rewriter) {
9797
// OpAdaptor provides the already type-converted input qubit
98-
const auto& qcQubit = adaptor.getQubitIn();
98+
auto qcQubit = adaptor.getQubitIn();
9999

100100
// Create the QC operation (in-place, no result)
101101
rewriter.create<QCOpType>(op.getLoc(), qcQubit, op.getParameter(0));
@@ -122,7 +122,7 @@ static LogicalResult
122122
convertOneTargetTwoParameter(QCOOpType& op, QCOOpAdaptorType& adaptor,
123123
ConversionPatternRewriter& rewriter) {
124124
// OpAdaptor provides the already type-converted input qubit
125-
const auto& qcQubit = adaptor.getQubitIn();
125+
auto qcQubit = adaptor.getQubitIn();
126126

127127
// Create the QC operation (in-place, no result)
128128
rewriter.create<QCOpType>(op.getLoc(), qcQubit, op.getParameter(0),
@@ -150,7 +150,7 @@ static LogicalResult
150150
convertOneTargetThreeParameter(QCOOpType& op, QCOOpAdaptorType& adaptor,
151151
ConversionPatternRewriter& rewriter) {
152152
// OpAdaptor provides the already type-converted input qubit
153-
const auto& qcQubit = adaptor.getQubitIn();
153+
auto qcQubit = adaptor.getQubitIn();
154154

155155
// Create the QC operation (in-place, no result)
156156
rewriter.create<QCOpType>(op.getLoc(), qcQubit, op.getParameter(0),
@@ -178,8 +178,8 @@ static LogicalResult
178178
convertTwoTargetZeroParameter(QCOOpType& op, QCOOpAdaptorType& adaptor,
179179
ConversionPatternRewriter& rewriter) {
180180
// OpAdaptor provides the already type-converted input qubits
181-
const auto& qcQubit0 = adaptor.getQubit0In();
182-
const auto& qcQubit1 = adaptor.getQubit1In();
181+
auto qcQubit0 = adaptor.getQubit0In();
182+
auto qcQubit1 = adaptor.getQubit1In();
183183

184184
// Create the QC operation (in-place, no result)
185185
rewriter.create<QCOpType>(op.getLoc(), qcQubit0, qcQubit1);
@@ -206,8 +206,8 @@ static LogicalResult
206206
convertTwoTargetOneParameter(QCOOpType& op, QCOOpAdaptorType& adaptor,
207207
ConversionPatternRewriter& rewriter) {
208208
// OpAdaptor provides the already type-converted input qubits
209-
const auto& qcQubit0 = adaptor.getQubit0In();
210-
const auto& qcQubit1 = adaptor.getQubit1In();
209+
auto qcQubit0 = adaptor.getQubit0In();
210+
auto qcQubit1 = adaptor.getQubit1In();
211211

212212
// Create the QC operation (in-place, no result)
213213
rewriter.create<QCOpType>(op.getLoc(), qcQubit0, qcQubit1,
@@ -235,8 +235,8 @@ static LogicalResult
235235
convertTwoTargetTwoParameter(QCOOpType& op, QCOOpAdaptorType& adaptor,
236236
ConversionPatternRewriter& rewriter) {
237237
// OpAdaptor provides the already type-converted input qubits
238-
const auto& qcQubit0 = adaptor.getQubit0In();
239-
const auto& qcQubit1 = adaptor.getQubit1In();
238+
auto qcQubit0 = adaptor.getQubit0In();
239+
auto qcQubit1 = adaptor.getQubit1In();
240240

241241
// Create the QC operation (in-place, no result)
242242
rewriter.create<QCOpType>(op.getLoc(), qcQubit0, qcQubit1, op.getParameter(0),
@@ -392,7 +392,7 @@ struct ConvertQCOMeasureOp final : OpConversionPattern<qco::MeasureOp> {
392392
matchAndRewrite(qco::MeasureOp op, OpAdaptor adaptor,
393393
ConversionPatternRewriter& rewriter) const override {
394394
// OpAdaptor provides the already type-converted input qubit
395-
const auto& qcQubit = adaptor.getQubitIn();
395+
auto qcQubit = adaptor.getQubitIn();
396396

397397
// Create qc.measure (in-place operation, returns only bit)
398398
// Preserve register metadata for output recording
@@ -437,7 +437,7 @@ struct ConvertQCOResetOp final : OpConversionPattern<qco::ResetOp> {
437437
matchAndRewrite(qco::ResetOp op, OpAdaptor adaptor,
438438
ConversionPatternRewriter& rewriter) const override {
439439
// OpAdaptor provides the already type-converted input qubit
440-
const auto& qcQubit = adaptor.getQubitIn();
440+
auto qcQubit = adaptor.getQubitIn();
441441

442442
// Create qc.reset (in-place operation, no result)
443443
rewriter.create<qc::ResetOp>(op.getLoc(), qcQubit);
@@ -737,7 +737,7 @@ struct ConvertQCOBarrierOp final : OpConversionPattern<qco::BarrierOp> {
737737
matchAndRewrite(qco::BarrierOp op, OpAdaptor adaptor,
738738
ConversionPatternRewriter& rewriter) const override {
739739
// OpAdaptor provides the already type-converted qubits
740-
const auto& qcQubits = adaptor.getQubitsIn();
740+
auto qcQubits = adaptor.getQubitsIn();
741741

742742
// Create qc.barrier operation
743743
rewriter.create<qc::BarrierOp>(op.getLoc(), qcQubits);
@@ -763,7 +763,7 @@ struct ConvertQCOBarrierOp final : OpConversionPattern<qco::BarrierOp> {
763763
* ```mlir
764764
* qc.ctrl(%q0) {
765765
* qc.x %q1 : !qc.qubit
766-
* }
766+
* } : !qc.qubit
767767
* ```
768768
*/
769769
struct ConvertQCOCtrlOp final : OpConversionPattern<qco::CtrlOp> {
@@ -773,7 +773,7 @@ struct ConvertQCOCtrlOp final : OpConversionPattern<qco::CtrlOp> {
773773
matchAndRewrite(qco::CtrlOp op, OpAdaptor adaptor,
774774
ConversionPatternRewriter& rewriter) const override {
775775
// Get QC controls
776-
const auto& qcControls = adaptor.getControlsIn();
776+
auto qcControls = adaptor.getControlsIn();
777777

778778
// Create qc.ctrl operation
779779
auto qcOp = qc::CtrlOp::create(rewriter, op.getLoc(), qcControls);

0 commit comments

Comments
 (0)