add mlir python bindings poc for qasm-to-qco pipeline#1763
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
f7d3c2e to
765518b
Compare
0da01aa to
51b81ef
Compare
f3dbc9d to
b7a05b4
Compare
57add9b to
d8f9dfe
Compare
e21234d to
5acd3f9
Compare
ab8cdff to
ed720c9
Compare
denialhaag
left a comment
There was a problem hiding this comment.
Thanks for this first draft for adding Python bindings to mqt-cc, @ibishal! 🙂
This PR will require some more input from you before it is merge-ready. You can find some more details in the comments below.
In addition to the comments below, please ensure the implementation is tested in Python. The tests should live here: https://github.com/munich-quantum-toolkit/core/tree/main/test/python. This will ensure that the tests are also run in our CI. For this to work, BUILD_MQT_CORE_MLIR will have to be enabled here:
Lines 132 to 136 in 946116d
There was a problem hiding this comment.
It would be nice to structure this more like https://github.com/llvm/llvm-project/tree/main/mlir/include/mlir/CAPI.
There was a problem hiding this comment.
It would be nice to structure this more like https://github.com/llvm/llvm-project/tree/main/mlir/lib/CAPI.
There was a problem hiding this comment.
The bindings should live in https://github.com/munich-quantum-toolkit/core/tree/main/bindings.
There was a problem hiding this comment.
This does not need to be committed. We are already testing the C++ implementation in https://github.com/munich-quantum-toolkit/core/tree/main/mlir/unittests.
There was a problem hiding this comment.
It would be nice to extend this. All dialects, passes, and conversions should be accessible. It would also be nice to provide a compile_program() function that accepts an OpenQASM program and pushes it through the entire pipeline (see the steps in CompilerPipeline.cpp).
| cmake_dependent_option( | ||
| BUILD_MQT_CORE_MLIR_PYTHON | ||
| "Build Python bindings for the MQT MLIR compiler collection (requires MLIR_ENABLE_BINDINGS_PYTHON=ON)" | ||
| OFF | ||
| "BUILD_MQT_CORE_MLIR" | ||
| OFF) |
There was a problem hiding this comment.
BUILD_MQT_CORE_MLIR_PYTHON should be enabled automatically if BUILD_MQT_CORE_MLIR and BUILD_MQT_CORE_BINDINGS are both enabled.
There was a problem hiding this comment.
I would even argue there may be no need for a separate option. Whenever MLIR is enabled and the bindings are as well, this should be built.
Description
Adds Python bindings for the MQT compiler collection, exposing the full (py:qasm) to (mlir:qc) to (mlir:qco) pipeline from Python.
tested with a 2-qubit Bell circuit as input and the output is the full QCO dialect IR with value semantics.
module { func.func @main() -> i64 attributes {passthrough = ["entry_point"]} { %c0_i64 = arith.constant 0 : i64 %c1 = arith.constant 1 : index %c0 = arith.constant 0 : index %c2 = arith.constant 2 : index %0 = qtensor.alloc(%c2) : tensor<2x!qco.qubit> %out_tensor, %result = qtensor.extract %0[%c0] : tensor<2x!qco.qubit> %out_tensor_0, %result_1 = qtensor.extract %out_tensor[%c1] : tensor<2x!qco.qubit> %1 = qco.h %result : !qco.qubit -> !qco.qubit %controls_out, %targets_out = qco.ctrl(%1) targets (%arg0 = %result_1) { %4 = qco.x %arg0 : !qco.qubit -> !qco.qubit qco.yield %4 : !qco.qubit } : ({!qco.qubit}, {!qco.qubit}) -> ({!qco.qubit}, {!qco.qubit}) %2 = qtensor.insert %controls_out into %out_tensor_0[%c0] : tensor<2x!qco.qubit> %3 = qtensor.insert %targets_out into %2[%c1] : tensor<2x!qco.qubit> qtensor.dealloc %3 : tensor<2x!qco.qubit> return %c0_i64 : i64 } }Fixes #1693
Checklist
If PR contains AI-assisted content:
Assisted-by: [Model Name] via [Tool Name]footer.