catalyst icon indicating copy to clipboard operation
catalyst copied to clipboard

Support importing MLIR file or stream into Catalyst

Open sengthai opened this issue 4 months ago • 3 comments

Summary

Catalyst should provide a way to import an MLIR file or stream directly into its workflow. This would enable users to leverage MLIR interoperability by ingesting pre-existing IRs or those generated by other tools.

Motivation

  • Enable advanced transformations and analysis before ingestion.
  • Improve flexibility for researchers and advanced users.

Expected behavior

  • Users can import an MLIR file or provide an MLIR stream (e.g., via stdin, etc.) into Catalyst.
  • Need to validate if the MLIR instructions are supported in the backend.
import catalyst.load

program_mlir_str = "MLIR CONTENT"
program_mlir_path = "path to mlir"

qjit_cir_1 = catalyst.load(program_mlir_str)
qjit_cir_2 = catalyst.load(filepath=program_mlir_path)

# Execute the program
qjit_cir_1()
qjit_cir_2() 

sengthai avatar Jul 08 '25 18:07 sengthai

@sengthai not exactly what you requested but take a look at this PR https://github.com/PennyLaneAI/catalyst/pull/1334 :)

erick-xanadu avatar Jul 08 '25 18:07 erick-xanadu

@sengthai not exactly what you requested but take a look at this PR #1334 :)

Nice! Thanks @erick-xanadu! The core functions are there! I think that approach is helpful for debugging and for users who try to execute their MLIR as well. We should take further action on your PR.

sengthai avatar Jul 08 '25 18:07 sengthai

Besides Erick's approach, it's hard to implement what you suggest above @sengthai because we need the type signature of the program in order to correctly provide arguments and interpret results. At some point I think we were inspecting the IR and attempt to deduce the type signature automatically, but it wasn't without issues (at least with the llvmir I remember it did not work).

dime10 avatar Jul 29 '25 18:07 dime10