Skip to content

Adding 'debug.compile_mlir` to support compiling a standalone MLIR module through Catalyst pipeline #2832

Open
mehrdad2m wants to merge 11 commits into
mainfrom
add-compile-mlir
Open

Adding 'debug.compile_mlir` to support compiling a standalone MLIR module through Catalyst pipeline #2832
mehrdad2m wants to merge 11 commits into
mainfrom
add-compile-mlir

Conversation

@mehrdad2m
Copy link
Copy Markdown
Contributor

Context:
Currently, there was no way to compile and run a standalone MLIR file directly from Python without a full @qjit-decorated function. This could be useful for debugging and also for prototyping an MLIR functionality for which frontend lowering doesn't exist yet. The existing but rather hacky workaround for such use-cases is to use debug.replace_ir to create a dummy MLIR and replace the whole file with the desired one.

Description of the Change:
This is essentially a QoL improvement where we add debug.compile_mlir, which compiles an MLIR string or file through the full Catalyst pipeline and returns a callable CompiledMLIR object. The entry-point function name and output types are supplied explicitly via func_name and result_types. The result can be called like a regular Python function and passed to get_compilation_stage to inspect intermediate IR.

Benefits:

Possible Drawbacks:

Related GitHub Issues:

@mehrdad2m mehrdad2m marked this pull request as ready for review May 13, 2026 14:12
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.00%. Comparing base (361109c) to head (9068789).
⚠️ Report is 24 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2832   +/-   ##
=======================================
  Coverage   97.00%   97.00%           
=======================================
  Files         167      167           
  Lines       18875    18908   +33     
  Branches     1773     1775    +2     
=======================================
+ Hits        18309    18342   +33     
  Misses        420      420           
  Partials      146      146           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mehrdad2m mehrdad2m requested a review from a team May 13, 2026 18:11
Copy link
Copy Markdown
Contributor

@joeycarter joeycarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this is great @mehrdad2m! 🤩

I think this would be a great debugging feature to have, I'm happy to approve if the rest of the team agrees.

Comment thread frontend/catalyst/debug/compiler_functions.py Outdated
Co-authored-by: Joey Carter <joseph.carter@xanadu.ai>
Comment thread frontend/catalyst/debug/compiler_functions.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants