PennyLaneAI / catalyst

A JIT compiler for hybrid quantum programs in PennyLane
https://docs.pennylane.ai/projects/catalyst
Apache License 2.0
101 stars 26 forks source link

Add minimal OpenQASM dialect support in MLIR #897

Open joeycarter opened 4 days ago

joeycarter commented 4 days ago

Context: Adding a native representation of the OpenQASM standard in MLIR.

Description of the Change:

Benefits: Having native OpenQASM support in MLIR will, for example, help facilitate the translation of an OpenQASM text file into and out of MLIR, enable transformations on OpenQASM programs, and more generally improve inter-operability between tools.

Possible Drawbacks: Only limited support for now.

Related GitHub Issues: Resolves #873

joeycarter commented 4 days ago

This is my initial attempt at resolving issue #873. At the moment, the OpenQASM dialect I have implemented is not "aware" of what any of the operations do (qubit allocation, RY gate and CNOT gate); I have assumed this was not required for the issue at hand. The MLIR -> OpenQASM translation pass simply walks through the IR operations and prints to the console the equivalent OpenQASM statements (as suggested in the original issue description). However, because of the way the MLIR tools are implemented, this also prints the original IR after it, since the operations were not modified in any way. I'm curious if there's a solution to this.

dime10 commented 3 days ago

Hi @joeycarter, thank you for the submission! I will have a look at it shortly :)

dime10 commented 3 days ago

Nice work!! I don't really have any comments so this is great as is 🎉

However, because of the way the MLIR tools are implemented, this also prints the original IR after it, since the operations were not modified in any way. I'm curious if there's a solution to this.

Good point, this is just how the opt tool works I think. If you really wanted to you could probably output the openqasm to a different stream, and then redirect the regular opt output to /dev/null. But I think its fine.

joeycarter commented 3 days ago

Thanks @dime10! In that case I'll leave it as is.