Skip to content

Commit d0c471c

Browse files
authored
🎨 Fix dependent dialects of conversions (#1572)
## Description As pointed out in PennyLaneAI/jeff-mlir#10 (comment), a conversion only depends on a dialect if it _creates_ its operations. This PR fixes the definition of all conversions accordingly. ## Checklist - [x] The pull request only contains commits that are focused and relevant to this change. - [x] ~~I have added appropriate tests that cover the new/changed functionality.~~ - [x] ~~I have updated the documentation to reflect these changes.~~ - [x] I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals. - [x] ~~I have added migration instructions to the upgrade guide (if needed).~~ - [x] The changes follow the project's style guidelines and introduce no new warnings. - [x] The changes are fully tested and pass the CI checks. - [x] I have reviewed my own code changes. --------- Signed-off-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com>
1 parent 61af1b3 commit d0c471c

6 files changed

Lines changed: 44 additions & 56 deletions

File tree

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]) ([**@denialhaag**])
1616
- ✨ Add a `place-and-route` pass for mapping circuits to architectures with restricted topologies ([#1537], [#1547], [#1568]) ([**@MatthiasReumann**])
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], [#1570])
18+
([#1264], [#1330], [#1402], [#1428], [#1430], [#1436], [#1443], [#1446], [#1464], [#1465], [#1470], [#1471], [#1472], [#1474], [#1475], [#1506], [#1510], [#1513], [#1521], [#1542], [#1548], [#1550], [#1554], [#1570], [#1572])
1919
([**@burgholzer**], [**@denialhaag**], [**@taminob**], [**@DRovara**], [**@li-mingbao**], [**@Ectras**], [**@MatthiasReumann**], [**@simon1hofmann**])
2020

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

334334
<!-- PR links -->
335335

336+
[#1572]: https://github.com/munich-quantum-toolkit/core/pull/1572
336337
[#1571]: https://github.com/munich-quantum-toolkit/core/pull/1571
337338
[#1570]: https://github.com/munich-quantum-toolkit/core/pull/1570
338339
[#1568]: https://github.com/munich-quantum-toolkit/core/pull/1568

mlir/include/mlir/Conversion/JeffToQCO/JeffToQCO.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def JeffToQCO : Pass<"jeff-to-qco"> {
3131
"mlir::arith::ArithDialect",
3232
"mlir::math::MathDialect",
3333
"mlir::tensor::TensorDialect",
34-
"mlir::jeff::JeffDialect",
3534
"mlir::qco::QCODialect",
3635
];
3736
}

mlir/include/mlir/Conversion/QCOToJeff/QCOToJeff.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ def QCOToJeff : Pass<"qco-to-jeff"> {
1919
}];
2020

2121
let dependentDialects = [
22-
"mlir::arith::ArithDialect",
23-
"mlir::math::MathDialect",
24-
"mlir::tensor::TensorDialect",
2522
"mlir::jeff::JeffDialect",
26-
"mlir::qco::QCODialect",
2723
];
2824
}

mlir/include/mlir/Conversion/QCOToQC/QCOToQC.td

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ def QCOToQC : Pass<"qco-to-qc"> {
1212
let summary = "Convert QCO dialect to QC dialect.";
1313

1414
let description = [{
15-
This pass converts all operations from the QCO dialect to their equivalent
16-
operations in the QC dialect. It handles the transformation of qubit
17-
values in QCO to qubit references in QC, ensuring that the semantics
18-
of quantum operations are preserved during the conversion process.
19-
}];
15+
This pass converts all operations from the QCO dialect to their equivalent operations in the QC dialect.
16+
It handles the transformation of qubit values in QCO to qubit references in QC, ensuring that the semantics of quantum operations are preserved during the conversion process.
17+
}];
2018

21-
// Define dependent dialects
2219
let dependentDialects = [
23-
"mlir::qco::QCODialect",
24-
"mlir::qc::QCDialect"
20+
"mlir::qc::QCDialect",
2521
];
2622
}

mlir/include/mlir/Conversion/QCToQCO/QCToQCO.td

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ def QCToQCO : Pass<"qc-to-qco"> {
1212
let summary = "Convert QC dialect to QCO dialect.";
1313

1414
let description = [{
15-
This pass converts all operations from the QC dialect to their equivalent
16-
operations in the QCO dialect. It handles the transformation of qubit
17-
references in QC to qubit values in QCO, ensuring that the semantics
18-
of quantum operations are preserved during the conversion process.
19-
}];
15+
This pass converts all operations from the QC dialect to their equivalent operations in the QCO dialect.
16+
It handles the transformation of qubit references in QC to qubit values in QCO, ensuring that the semantics of quantum operations are preserved during the conversion process.
17+
}];
2018

21-
// Define dependent dialects
2219
let dependentDialects = [
23-
"mlir::qc::QCDialect",
24-
"mlir::qco::QCODialect"
20+
"mlir::qco::QCODialect",
2521
];
2622
}

mlir/include/mlir/Conversion/QCToQIR/QCToQIR.td

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,40 @@ def QCToQIR : Pass<"qc-to-qir"> {
1212
let summary = "Lower the QC dialect to the LLVM dialect compliant with QIR 2.0";
1313

1414
let description = [{
15-
This pass lowers all operations from the QC dialect to their equivalent
16-
operations in the LLVM dialect, ensuring compliance with the QIR 2.0 standard.
17-
It translates quantum operations and types from QC to their corresponding
18-
representations in QIR, facilitating interoperability with quantum computing
19-
frameworks that utilize the QIR standard.
20-
21-
Requirements:
22-
- Input is a valid module in the QC dialect.
23-
- The entry function must be marked with the `entry_point` attribute.
24-
- The input entry function must consist of a single block.
25-
Multi-block input functions are currently not supported.
26-
- The program must have straight-line control flow (i.e., Base Profile QIR).
27-
28-
Behavior:
29-
- Each QC quantum operation is replaced by a call to the corresponding QIR function in the LLVM dialect.
30-
- Required QIR module flags are attached as attributes to the entry function.
31-
- The pass transforms the single-block entry function into four blocks to satisfy QIR Base Profile constraints:
32-
0. Initialization block: Sets up the execution environment and performs required runtime initialization.
33-
1. Reversible operations block: Contains only void-returning calls to reversible quantum operations.
34-
2. Irreversible operations block: Contains only void-returning calls to operations marked irreversible, e.g.:
35-
`__quantum__qis__mz__body`, `__quantum__qis__reset__body`.
36-
3. Epilogue block: Records measurement results and returns from the entry function.
37-
- Blocks are connected via unconditional branches in the order listed above.
38-
- Non-quantum dialects are lowered via MLIR's built-in conversions.
39-
40-
Producing LLVM IR:
41-
- After conversion to the LLVM dialect, produce LLVM IR with:
42-
mlir-translate --mlir-to-llvmir input.mlir > output.ll
43-
}];
44-
45-
46-
// Define dependent dialects
15+
This pass lowers all operations from the QC dialect to their equivalent operations in the LLVM dialect, ensuring compliance with the QIR 2.0 standard.
16+
It translates quantum operations and types from QC to their corresponding representations in QIR, facilitating interoperability with quantum computing frameworks that utilize the QIR standard.
17+
18+
Requirements:
19+
20+
- Input is a valid module in the QC dialect.
21+
- The entry function must be marked with the `entry_point` attribute.
22+
- The input entry function must consist of a single block.
23+
Multi-block input functions are currently not supported.
24+
- The program must have straight-line control flow (i.e., Base Profile QIR).
25+
26+
Behavior:
27+
28+
- Each QC quantum operation is replaced by a call to the corresponding QIR function in the LLVM dialect.
29+
- Required QIR module flags are attached as attributes to the entry function.
30+
- The pass transforms the single-block entry function into four blocks to satisfy QIR Base Profile constraints:
31+
0. Initialization block: Sets up the execution environment and performs required runtime initialization.
32+
1. Reversible operations block: Contains only void-returning calls to reversible quantum operations.
33+
2. Irreversible operations block: Contains only void-returning calls to operations marked irreversible (e.g., `__quantum__qis__mz__body` and `__quantum__qis__reset__body`).
34+
3. Epilogue block: Records measurement results and returns from the entry function.
35+
- Blocks are connected via unconditional branches in the order listed above.
36+
- Non-quantum dialects are lowered via MLIR's built-in conversions.
37+
38+
Producing LLVM IR:
39+
40+
- After conversion to the LLVM dialect, produce LLVM IR with:
41+
42+
```
43+
mlir-translate --mlir-to-llvmir input.mlir > output.ll
44+
```
45+
}];
46+
47+
4748
let dependentDialects = [
48-
"mlir::LLVM::LLVMDialect",
49-
"mlir::QCDialect",
49+
"mlir::LLVM::LLVMDialect",
5050
];
5151
}

0 commit comments

Comments
 (0)