Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@
* A broken link was removed in the [Compiler Core](https://docs.pennylane.ai/projects/catalyst/en/stable/modules/mlir.html) documentation page. The link referred to where precompiled decomposition rules were implemented, which has since been refactored.
[(#2913)](https://github.com/PennyLaneAI/catalyst/pull/2913)

* The documentation for `QJIT.mlir` and `QJIT.mlir_opt` was updated with type hints and docstrings that better reflect the compilation-dependent nature of the properties.
Comment thread
kipawaa marked this conversation as resolved.

<h3>Contributors ✍️</h3>

This release contains contributions from (in alphabetical order):
Expand Down
18 changes: 14 additions & 4 deletions frontend/catalyst/jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,13 @@ def _get_effective_capture_mode(self):
return capture_option

@property
def mlir(self):
"""Obtain the MLIR representation after canonicalization"""
def mlir(self) -> str | None:
"""The canonicalized MLIR representation of the QJIT object after lowering, if available.

Returns:
str: The textual MLIR module for the QJIT object.
None: If compilation has not yet occurred.
"""
# Canonicalize the MLIR since there can be a lot of redundancy coming from JAX.
if not self.mlir_module:
return None
Expand All @@ -626,8 +631,13 @@ def mlir(self):
return canonicalize(stdin=stdin, options=self.compile_options)

@property
def mlir_opt(self):
"""Obtain the MLIR representation after optimization"""
def mlir_opt(self) -> str | None:
"""The MLIR representation of the QJIT object after optimization, if available.

Returns:
str: The textual MLIR module after applying user passes and the default pipeline.
None: If compilation has not yet occurred.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This statement is a bit tricky. Technically, accessing this property triggers the "compilation" (at least compilation in the MLIR / core Catalyst compiler sense), but what needed to have happened before is that the capture and generate_ir stages of the QJIT object needed to have been run, whether via AOT compilation, JIT compilation, or some other way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point! It's kind of difficult to convey all of that concisely, what about something like None: If MLIR cannot be generated for the circuit. and we can explain further in the core of the docstring?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah that makes sense! Maybe a slight modification, since the MLIR having been generated is the criteria, and our programs are more general than circuits:
None: If the MLIR has not yet been generated for this program

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How does f145021 sound?

@dime10 dime10 Jun 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If optimized MLIR has not yet been generated for the program.

The condition for both properties is the same actually, because they take the jax-generated mlir (.mlir_module) as input to produce their output.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I guess I was trying to get at the required success of running the requested pipeline to generate .mlir_opt, whereas .mlir_module is sufficient for .mlir.

@dime10 dime10 Jun 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If there is a failure in the pipeline an error should be raised. The None result is produced precisely when the input IR isn't available.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, added in a98893b

"""
if not self.mlir_module:
return None
using_python_compiler = self.compiler.is_using_python_compiler(self.mlir_module)
Expand Down
Loading