Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
df8b97b
Migrate unified compiler to Catalyst
mudit2812 Nov 17, 2025
9536707
Fixing migration artifacts; linting
mudit2812 Nov 17, 2025
1453aae
Fix CI errors; Ignore unified compiler in coverage reports
mudit2812 Nov 17, 2025
efc0f88
Test out how graphviz is installed
mudit2812 Nov 17, 2025
10cd749
Lint some more
mudit2812 Nov 17, 2025
27de22d
Merge branch 'main' into migrate-unified-compiler
mudit2812 Nov 17, 2025
f7aa2b6
[skip ci] Skip CI
mudit2812 Nov 17, 2025
012f58b
[skip ci] Skip CI
mudit2812 Nov 17, 2025
f0a0c90
Merge branch 'migrate-unified-compiler' of https://github.com/PennyLa…
mudit2812 Nov 17, 2025
c98755e
Try installing graphviz with apt
mudit2812 Nov 17, 2025
bb5bd00
Fix codefactor complaints
mudit2812 Nov 17, 2025
1448472
Merge branch 'main' into migrate-unified-compiler
mudit2812 Nov 17, 2025
5e745f5
Try appeasing codefactor again
mudit2812 Nov 17, 2025
0409933
Try appeasing codefactor once again
mudit2812 Nov 17, 2025
e786a12
Pylint suppression
mudit2812 Nov 17, 2025
4ae10ff
Reduce complexity of stablehlo.reduce and stablehlo.dynamic_broadcast…
mudit2812 Nov 17, 2025
dc41a7b
Fix some failures
mudit2812 Nov 18, 2025
58b13e4
Try change to graphviz installation
mudit2812 Nov 18, 2025
4e5f904
Merge branch 'main' into migrate-unified-compiler
mudit2812 Nov 18, 2025
637d2cf
Try installing graphviz with pip
mudit2812 Nov 18, 2025
091c5e1
Merge branch 'main' into migrate-unified-compiler
mudit2812 Nov 18, 2025
64e0fd4
Try installing graphviz with both apt and pip
mudit2812 Nov 18, 2025
dc15d3a
Add utils file to remove conftest imports
mudit2812 Nov 18, 2025
e7e33d6
Merge branch 'main' into migrate-unified-compiler
mudit2812 Nov 18, 2025
f919e8d
Remove unused imports
mudit2812 Nov 18, 2025
005ba9f
Add graphviz dependencies to lightning.kokkos testing workflow
mudit2812 Nov 18, 2025
6117189
Update cookbook
mudit2812 Nov 18, 2025
6961324
Migrate all changelog entries from PennyLane
mudit2812 Nov 18, 2025
0fdbb46
Merge branch 'main' into migrate-unified-compiler
mudit2812 Nov 18, 2025
a868bc3
Add EOF new line to .codecov.yml
mudit2812 Nov 18, 2025
8f00b2f
change changelog entry slightly
mudit2812 Nov 18, 2025
22a6e6e
Merge branch 'main' into migrate-unified-compiler
mudit2812 Nov 20, 2025
b4a321d
Merge branch 'main' into migrate-unified-compiler
mudit2812 Nov 26, 2025
e3ef736
Copy over xdsl_conversion changes
jzaia18 Nov 26, 2025
b7995ff
Rename visualization -> inspection
jzaia18 Nov 26, 2025
67705a9
finalize migration of branch
jzaia18 Nov 26, 2025
e735ca2
Update CHANGELOG
jzaia18 Nov 26, 2025
a979216
Copy over changes from PennyLane
jzaia18 Nov 26, 2025
4cbe02a
Remove reference to 'remove-chained-self-inverses'
mudit2812 Nov 26, 2025
e8e84e6
Woops, forgot to add the main files
jzaia18 Nov 26, 2025
c5f08c3
Remove leftover references to pennylane.compiler.python_compiler
mudit2812 Nov 27, 2025
fe76357
Streamline circuit inspection utilities (#2237)
jzaia18 Dec 1, 2025
be3ff3a
Merge branch 'migrate-unified-compiler' into feature/xdsl-specs
jzaia18 Dec 1, 2025
3395581
Merge branch 'main' into migrate-unified-compiler
mudit2812 Dec 1, 2025
c21850f
Merge branch 'migrate-unified-compiler' into feature/xdsl-specs
jzaia18 Dec 1, 2025
ad7c306
Better display for 'all' in compbasis
jzaia18 Dec 1, 2025
a69c9ba
Remove more references to python_compiler
mudit2812 Dec 1, 2025
9d208f9
Address more code review comments
mudit2812 Dec 1, 2025
7946287
Merge branch 'migrate-unified-compiler' into feature/xdsl-specs
jzaia18 Dec 1, 2025
e223b3f
Undo accidental change
jzaia18 Dec 1, 2025
8ce6f96
Fix jit
mudit2812 Dec 1, 2025
664d24a
Fix jit again
mudit2812 Dec 1, 2025
e07a332
Merge branch 'main' into migrate-unified-compiler
mudit2812 Dec 1, 2025
f9035c0
Fix line-too-long
mudit2812 Dec 1, 2025
ca1aa3a
Merge branch 'migrate-unified-compiler' of https://github.com/PennyLa…
mudit2812 Dec 1, 2025
d146453
Merge branch 'migrate-unified-compiler' into feature/xdsl-specs
jzaia18 Dec 2, 2025
87be66c
Update specs unit tests
jzaia18 Dec 2, 2025
f43cb3d
Remove vestigial workaround
jzaia18 Dec 2, 2025
0e4cd8d
Apply suggestions from code review
jzaia18 Dec 2, 2025
ef7c6c9
Update frontend/test/pytest/python_interface/inspection/test_mlir_spe…
jzaia18 Dec 2, 2025
eb11eb0
Update function names and docs
jzaia18 Dec 2, 2025
869dcc0
Merge branch 'feature/xdsl-specs' of github.com:PennyLaneAI/catalyst …
jzaia18 Dec 2, 2025
611a0ea
Oops
jzaia18 Dec 2, 2025
6711a0f
Minor tweaks to simplify
jzaia18 Dec 2, 2025
0288e6c
Update unit tests
jzaia18 Dec 2, 2025
02bbdfc
Simplify unit tests
jzaia18 Dec 2, 2025
28ab6e6
Separate out collect_region into 2 functions, 1 for regions and 1 for…
jzaia18 Dec 2, 2025
32261bf
Update changelog
jzaia18 Dec 3, 2025
7f4eb06
Remove the local transform dialect (#2261)
mehrdad2m Dec 3, 2025
3947e05
Remove unneeded XDSL plugin load
jzaia18 Dec 3, 2025
a4e86cd
Merge branch 'migrate-unified-compiler' into feature/xdsl-specs
jzaia18 Dec 3, 2025
24eb758
Merge branch 'main' into migrate-unified-compiler
dime10 Dec 3, 2025
2413520
Merge branch 'migrate-unified-compiler' into feature/xdsl-specs
jzaia18 Dec 4, 2025
5bf82d8
Apply PR review comments
jzaia18 Dec 4, 2025
b6fb585
[skip ci] add importorskip for graphviz to mlir_graph tests
mudit2812 Dec 5, 2025
0b1f237
Merge branch 'migrate-unified-compiler' of https://github.com/PennyLa…
mudit2812 Dec 5, 2025
8ef2b58
Merge branch 'main' into migrate-unified-compiler
mudit2812 Dec 5, 2025
848795d
[skip ci] Skip CI
mudit2812 Dec 5, 2025
58e06f0
Merge branch 'migrate-unified-compiler' of https://github.com/PennyLa…
mudit2812 Dec 5, 2025
14eb727
Update .codecov.yml
mudit2812 Dec 5, 2025
7477272
Add better testing for Hamiltonians
jzaia18 Dec 5, 2025
dce6a8d
Merge branch 'migrate-unified-compiler' into feature/xdsl-specs
jzaia18 Dec 5, 2025
14b8380
Small formatting fix
jzaia18 Dec 5, 2025
8980de6
Merge branch 'feature/xdsl-specs' of github.com:PennyLaneAI/catalyst …
jzaia18 Dec 5, 2025
4badc05
Add graph decomp test
jzaia18 Dec 5, 2025
d9647ca
Merge branch 'main' into feature/xdsl-specs
jzaia18 Dec 5, 2025
b5802db
Fix botched merge
jzaia18 Dec 5, 2025
187d283
Fix changelog
jzaia18 Dec 5, 2025
0a4eba3
Placate codefactor
jzaia18 Dec 5, 2025
792e807
More codefactor nitpicks
jzaia18 Dec 5, 2025
2e96f6d
YET MORE NITPICKS!
jzaia18 Dec 5, 2025
cf4b2ca
Change for xdsl is imported
jzaia18 Dec 5, 2025
b26c967
Reorder imports
jzaia18 Dec 6, 2025
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
5 changes: 5 additions & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@

<h3>Internal changes ⚙️</h3>

* A new `catalyst.python_interface.inspection.mlir_specs` method has been added to facilitate
PennyLane's new pass-by-pass specs feature. This function returns information gathered by parsing
the xDSL generated by a given QJIT object, such as gate counts, measurements, or qubit allocations.
[(#2238)](https://github.com/PennyLaneAI/catalyst/pull/2238)

* Resource tracking now writes out at device destruction time instead of qubit deallocation
time. The written resources will be the total amount of resources collected throughout the
lifetime of the execution. For executions that split work between multiple functions,
Expand Down
3 changes: 2 additions & 1 deletion frontend/catalyst/python_interface/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""Unified Compiler API for integration of Catalyst with xDSL."""

from .compiler import Compiler
from .inspection import QMLCollector
from .inspection import QMLCollector, mlir_specs
from .parser import QuantumParser
from .pass_api import compiler_transform

Expand All @@ -23,4 +23,5 @@
"compiler_transform",
"QuantumParser",
"QMLCollector",
"mlir_specs",
]
11 changes: 10 additions & 1 deletion frontend/catalyst/python_interface/inspection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,14 @@
from .collector import QMLCollector
from .draw import draw
from .mlir_graph import generate_mlir_graph
from .specs import mlir_specs
from .specs_collector import ResourcesResult, specs_collect

__all__ = ["QMLCollector", "draw", "generate_mlir_graph"]
__all__ = [
"QMLCollector",
"draw",
"generate_mlir_graph",
"specs_collect",
"ResourcesResult",
"mlir_specs",
]
103 changes: 103 additions & 0 deletions frontend/catalyst/python_interface/inspection/specs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Copyright 2025 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""This file contains the implementation of the `specs` function for the Unified Compiler."""

from __future__ import annotations

import warnings
from typing import TYPE_CHECKING, Literal

from ..compiler import Compiler
from .specs_collector import ResourcesResult, specs_collect
from .xdsl_conversion import get_mlir_module

if TYPE_CHECKING:
from catalyst.jit import QJIT


class StopCompilation(Exception):
"""Custom exception to stop compilation early when the desired specs level is reached."""


def mlir_specs(
qnode: QJIT, level: int | tuple[int] | list[int] | Literal["all"], *args, **kwargs
) -> ResourcesResult | dict[str, ResourcesResult]:
"""Compute the specs used for a circuit at the level of an MLIR pass.

Args:
qnode (QNode): The (QJIT'd) qnode to get the specs for
level (int | tuple[int] | list[int] | "all"): The MLIR pass level to get the specs for
*args: Positional arguments to pass to the QNode
**kwargs: Keyword arguments to pass to the QNode

Returns:
ResourcesResult | dict[str, ResourcesResult]: The resources for the circuit at the
specified level
"""
cache: dict[int, tuple[ResourcesResult, str]] = {}

if args or kwargs:
warnings.warn(
"The `specs` function does not yet support dynamic arguments, "
"so the results may not reflect information provided by the arguments.",
UserWarning,
)

max_level = level
if max_level == "all":
max_level = None
elif isinstance(level, (tuple, list)):
max_level = max(level)
elif not isinstance(level, int):
raise ValueError("The `level` argument must be an int, a tuple/list of ints, or 'all'.")

def _specs_callback(previous_pass, module, next_pass, pass_level=0):
"""Callback function for gathering circuit specs."""

pass_instance = previous_pass if previous_pass else next_pass
result = specs_collect(module)

pass_name = pass_instance.name if hasattr(pass_instance, "name") else pass_instance
cache[pass_level] = (
result,
pass_name if pass_level else "Before MLIR Passes",
)

if max_level is not None and pass_level >= max_level:
raise StopCompilation("Stopping compilation after reaching max specs level.")

mlir_module = get_mlir_module(qnode, args, kwargs)
try:
Compiler.run(mlir_module, callback=_specs_callback)
except StopCompilation:
# We use StopCompilation to interrupt the compilation once we reach
# the desired level
pass

if level == "all":
return {f"{cache[lvl][1]} (MLIR-{lvl})": cache[lvl][0] for lvl in sorted(cache.keys())}

if isinstance(level, (tuple, list)):
if any(lvl not in cache for lvl in level):
missing = [str(lvl) for lvl in level if lvl not in cache]
raise ValueError(
f"Requested specs levels {', '.join(missing)} not found in MLIR pass list."
)
return {f"{cache[lvl][1]} (MLIR-{lvl})": cache[lvl][0] for lvl in level if lvl in cache}

# Just one level was specified
if level not in cache:
raise ValueError(f"Requested specs level {level} not found in MLIR pass list.")
return cache[level][0]
Loading