✨ Enable Python Bindings for the MQT Compiler Collection#1772
✨ Enable Python Bindings for the MQT Compiler Collection#1772jmoosburger wants to merge 2 commits into
Conversation
|
hey @MatthiasReumann, no code yet, but i did quite some research through the weekend to answer the questions mentioned in the issue. the current mqt-cc tool reads a mlir- or qasm-file, transforms it to a mlir-module and feeds it to a compilation pipeline. the output is a qir-representation of the input-circuit printed to standard-out. the completion criteria says it must be possible to load a qasm circuit, translate it to qc-dialect and further to a qco-circuit.
Thanks in beforehand, answering this will help me proceeding enormously :) |
|
Hi @jmoosburger, The idea is that a user can define an OpenQASM string in Python and then call a, say, Regarding your questions:
Kind of. There is no need for any sort of builder just yet, but we want an MLIR module that comprises a QC or QCO program in Python. The MLIR Python bindings are made for that.
Exactly, we just want to have rather minimal functions to execute the existing C++ code.
That's a fair point! Given the proposals in #1763 and #1770, we believe it is feasible to implement a I hope this clears things up! In general, it probably makes sense to have a look at #1763 and #1770 and the review comments we have provided there. While these two PRs are still far from what we need, they should offer a good starting point. In particular, a first draft that tests the translation from OpenQASM to QC in our CI would already be great. It should then be relatively easy to add the functionality required to close #1693. Feel free to reach out if any of the points do not make sense! |
|
@denialhaag thanks a lot for you input, that helped a lot! following are just some of my notes, if you are interested in my progress and what my further research resulted in: step 1: compile mlir with
|
|
Hey @jmoosburger 👋🏼 |
|
hey @burgholzer, slowly, to be haunest °^^ i struggled with the cmake build, as there are linking issues in a module mqt-core-mlir-unittest-qir-ir after i checked out the current main-branch and i have no idea why exactly... i'm in contact with @MatthiasReumann on this one. But i won't give up, let's see what i can do tomorrow! :) |
|
there is progress 💪 first of all, i excluded the corrupted module mqt-core-mlir-unittest-qir-ir in the cmake-files as a workaroud to proceed. i additionally managed to build llvm/mlir locally with python bindings on. i've referenced it from a python file test-wise and executed a simple test successfully. i probably need some input from you on this point: at the moment you recommend taking the mlir-package as a prebuild from munich-quantum-software that does not contain the python bindings by now. as far as i figured out it is not possible to somehow generate them from that stage, which means the configuration must be changed at the point where the prebuilds are actually built. shall i figure that out in the munich-quantum-software/setup-mlir-project? in any case i can go on with my steps from above tomorrow as the setup seems to work - at least for now on my local machine 👍 |
Hm. Interestingly, none of the other open PRs encountered that problem so far. @denialhaag Could you look into what it would take to enable that for our portable-mlir-toolchain project and whether it is moderately easy to enable and package the resulting artifact. In particular, whether the resulting builds actively depend on a particular Python version and we would technically have to ship multiple. There are quite a few things to clarify there. @jmoosburger I think it is fine for you to focus on this repository and your local setup for now. |
I just tried to build #1770, but to no avail. 🤠
Sure, I'll have a look tomorrow! 😌 |
|
just fyi: what i've done to make mlir python bindings available in a python file:
the full python package is then in: either export this path to an environment variable this makes the following python import successful in mqt: hope this helps... |
question for clarification:are the existing nanobinds in the bindings-directory actually in use somewhere? background:i want to publish the function now i need to reference this PS: i probably need to rename the nanobind from mlir to something else to avoid conflicts with the actual |
An example: The bindings defined in The binding targets must be added to this list to ensure that the bindings are available in Python: Lines 87 to 101 in e595087 Does this help? 🤔 |
|
i certainly does! where exactly do these build-target-strings come from? |
It's defined here: core/bindings/ir/CMakeLists.txt Line 16 in e595087 Edit: |
|
that's what i expected 👍 the additionally, this is where the namespace is defined, in which the bound functionality is available in python, right? core/bindings/ir/CMakeLists.txt Line 19 in e595087 |
Exactly! |
Description
TBD :)
Fixes #1693
Checklist
If PR contains AI-assisted content:
Assisted-by: [Model Name] via [Tool Name]footer.