Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions cmake/SetupMLIR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ include_directories(${MQT_MLIR_BUILD_INCLUDE_DIR})
link_directories(${LLVM_BUILD_LIBRARY_DIR})
add_definitions(${LLVM_DEFINITIONS})

string(REPLACE "." ";" MLIR_VERSION_COMPONENTS ${MLIR_VERSION})
list(GET MLIR_VERSION_COMPONENTS 0 MLIR_VERSION_MAJOR)
add_compile_definitions(MLIR_VERSION_MAJOR=${MLIR_VERSION_MAJOR})

# set the binary directory for the build tree such that, e.g., docs can be generated in the build
# tree
set(MLIR_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
10 changes: 3 additions & 7 deletions docs/mlir/Conversions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

## Internal Conversions

```{include} Conversions/MLIRMQTOptToMQTRef.md
```{include} Conversions/MLIRQCToQCO.md

```

```{include} Conversions/MLIRMQTRefToMQTOpt.md
```{include} Conversions/MLIRQCOToQC.md

```

## QIR Conversions

```{include} Conversions/MLIRMQTRefToQIR.md

```

```{include} Conversions/MLIRQIRToMQTRef.md
```{include} Conversions/MLIRQCToQIR.md

```
29 changes: 0 additions & 29 deletions docs/mlir/MQTOpt.md

This file was deleted.

23 changes: 0 additions & 23 deletions docs/mlir/MQTRef.md

This file was deleted.

11 changes: 11 additions & 0 deletions docs/mlir/QC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
tocdepth: 3
---

```{include} Dialects/MLIRQCDialect.md

```

```{include} Dialects/MLIRQCInterfaces.md
:heading-offset: 1
```
11 changes: 11 additions & 0 deletions docs/mlir/QCO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
tocdepth: 3
---

```{include} Dialects/MLIRQCODialect.md

```

```{include} Dialects/MLIRQCOInterfaces.md
:heading-offset: 1
```
109 changes: 6 additions & 103 deletions docs/mlir/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ This part of the MQT explores the capabilities of the Multi-Level Intermediate R

We define multiple dialects, each with its dedicated purpose:

- The {doc}`MQTRef dialect <MQTRef>` uses reference semantics and is designed as a compatibility dialect that simplifies translations from and to existing languages such as Qiskit, OpenQASM, or QIR.
- The {doc}`QC dialect <QC>` uses reference semantics and is designed as a compatibility dialect that simplifies translations from and to existing languages such as Qiskit, OpenQASM, or QIR.

- The {doc}`MQTOpt dialect <MQTOpt>` uses value semantics and is mainly designed for running optimizations.
- The {doc}`QCO dialect <QCO>` uses value semantics and is mainly designed for running optimizations.

Both dialects define various transformation passes.
Both dialects define various canonicalization and transformations that enable the compilation of quantum programs to native quantum hardware.

For intercompatibility, we provide {doc}`conversions <Conversions>` between dialects.
So far, this comprises a conversion from MQTOpt to MQTRef and one from MQTRef to MQTOpt.
So far, this comprises conversions between QC and QCO as well as from QC to QIR.

```{toctree}
:maxdepth: 2

MQTRef
MQTOpt
QC
QCO
Conversions
```

Expand All @@ -27,100 +27,3 @@ The content is not yet complete and subject to change.
Contributions are welcome.
See the {doc}`contribution guide <../contributing>` for more information.
:::

## Register Handling

In MQT's MLIR dialects, quantum and classical registers are represented by MLIR-native `memref` operations rather than custom types.
This design choice offers several advantages:

- **MLIR Integration**: Seamless compatibility with existing MLIR infrastructure, enabling reuse of memory handling patterns and optimization passes
- **Implementation Efficiency**: No need to define and maintain custom register operations, significantly reducing implementation complexity
- **Enhanced Interoperability**: Easier integration with other MLIR dialects and passes, allowing for more flexible compilation pipelines
- **Sustainable Evolution**: Standard memory operations can handle transformations while allowing new features without changing the fundamental register model

### Quantum Register Representation

A quantum register is represented by a `memref` of type `!mqtref.Qubit` or `!mqtopt.Qubit`, depending on the dialect:

```mlir
// A quantum register with 2 qubits
%qreg = memref.alloc() : memref<2x!mqtref.Qubit>
```

Individual qubits are accessed through standard memory operations:

```mlir
// Load qubits from the register
%q0 = memref.load %qreg[%i0] : memref<2x!mqtref.Qubit>
%q1 = memref.load %qreg[%i1] : memref<2x!mqtref.Qubit>
```

Here's a complete example of quantum register allocation, qubit access, and deallocation:

```mlir
module {
func.func @main() attributes {passthrough = ["entry_point"]} {
%i1 = arith.constant 1 : index
%i0 = arith.constant 0 : index
%qreg = memref.alloc() : memref<2x!mqtref.Qubit>
%q0 = memref.load %qreg[%i0] : memref<2x!mqtref.Qubit>
%q1 = memref.load %qreg[%i1] : memref<2x!mqtref.Qubit>
memref.dealloc %qreg : memref<2x!mqtref.Qubit>
return
}
}
```

### Classical Register Representation

Classical registers follow the same pattern as quantum registers but use the `i1` type for boolean measurement results:

```mlir
// A classical register with 1 bit
%creg = memref.alloc() : memref<1xi1>
```

Measurement operations produce `i1` values that can be stored in classical registers:

```mlir
// Measure a qubit and store the result
%c = mqtref.measure %q
memref.store %c, %creg[%i0] : memref<1xi1>
```

### Example: Full Quantum Program with Measurement

Consider the following quantum computation represented in OpenQASM 3.0 code:

```qasm3
OPENQASM 3.0;
include "stdgates.inc";
qubit[1] q;
bit[1] c;
x q[0];
c[0] = measure q[0];
```

In the MQTRef dialect, this corresponds to:

```mlir
module {
func.func @main() attributes {passthrough = ["entry_point"]} {
%i0 = arith.constant 0 : index
%qreg = memref.alloc() : memref<1x!mqtref.Qubit>
%q = memref.load %qreg[%i0] : memref<1x!mqtref.Qubit>
%creg = memref.alloca() : memref<1xi1>
mqtref.x() %q
%c = mqtref.measure %q
memref.store %c, %creg[%i0] : memref<1xi1>
memref.dealloc %qreg : memref<1x!mqtref.Qubit>
return
}
}
```

## Development

Building the MLIR library requires LLVM version 21.1 or later.
Our CI pipeline on GitHub continuously builds and tests the MLIR library on Linux, macOS, and Windows.
To access the latest build logs, visit the [GitHub Actions page](https://github.com/munich-quantum-toolkit/core/actions/workflows/ci.yml).
1 change: 0 additions & 1 deletion mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ add_subdirectory(tools)

# add test code
if(BUILD_MQT_CORE_TESTS)
add_subdirectory(test)
add_subdirectory(unittests)
endif()
4 changes: 0 additions & 4 deletions mlir/include/mlir/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
#
# Licensed under the MIT License

add_subdirectory(MQTRefToMQTOpt)
add_subdirectory(MQTOptToMQTRef)
add_subdirectory(MQTRefToQIR)
add_subdirectory(QIRToMQTRef)
add_subdirectory(QCOToQC)
add_subdirectory(QCToQCO)
add_subdirectory(QCToQIR)
13 changes: 0 additions & 13 deletions mlir/include/mlir/Conversion/MQTOptToMQTRef/CMakeLists.txt

This file was deleted.

23 changes: 0 additions & 23 deletions mlir/include/mlir/Conversion/MQTOptToMQTRef/MQTOptToMQTRef.h

This file was deleted.

29 changes: 0 additions & 29 deletions mlir/include/mlir/Conversion/MQTOptToMQTRef/MQTOptToMQTRef.td

This file was deleted.

13 changes: 0 additions & 13 deletions mlir/include/mlir/Conversion/MQTRefToMQTOpt/CMakeLists.txt

This file was deleted.

23 changes: 0 additions & 23 deletions mlir/include/mlir/Conversion/MQTRefToMQTOpt/MQTRefToMQTOpt.h

This file was deleted.

29 changes: 0 additions & 29 deletions mlir/include/mlir/Conversion/MQTRefToMQTOpt/MQTRefToMQTOpt.td

This file was deleted.

Loading
Loading