Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
265cd4d
copy files over
andrijapau Nov 19, 2025
e9ceaa7
add pydot to requirements.txt
andrijapau Nov 19, 2025
ae50ca1
add files
andrijapau Nov 19, 2025
a0e37b0
rename
andrijapau Nov 19, 2025
76b5565
add base class
andrijapau Nov 19, 2025
659f480
quick changes
andrijapau Nov 19, 2025
8699557
add control flow support
andrijapau Nov 19, 2025
db6edc9
clean-up
andrijapau Nov 19, 2025
2be63e4
Apply suggestion from @andrijapau
andrijapau Nov 20, 2025
12fa2af
Apply suggestion from @andrijapau
andrijapau Nov 20, 2025
2c93330
Apply suggestion from @andrijapau
andrijapau Nov 20, 2025
e68c3f4
Apply suggestion from @andrijapau
andrijapau Nov 20, 2025
4aad864
Apply suggestion from @andrijapau
andrijapau Nov 20, 2025
3be39dc
update cluster label logic
andrijapau Nov 20, 2025
a383ba8
fix dag builders test
andrijapau Nov 20, 2025
8ddaa5d
fix pydot dag builders test
andrijapau Nov 20, 2025
1166f40
update doc
andrijapau Nov 20, 2025
b0fbf7e
Merge branch 'feature/graph-visualization' into feature/dag-builders
andrijapau Nov 20, 2025
df9bf45
basic cl
andrijapau Nov 20, 2025
bd75450
Merge branch 'feature/dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 20, 2025
8ca5b1f
basic cl
andrijapau Nov 20, 2025
b579a3f
Trigger CI
andrijapau Nov 20, 2025
a94d843
Trigger CI
andrijapau Nov 20, 2025
331e349
Apply suggestion from @andrijapau
andrijapau Nov 20, 2025
a87d117
just do customop
andrijapau Nov 20, 2025
9713aa3
fix wording
andrijapau Nov 20, 2025
68e8453
Merge branch 'feature/graph-visualization' into feature/dag-builders
andrijapau Nov 20, 2025
8faae36
Merge branch 'feature/dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 20, 2025
7bbc224
rename
andrijapau Nov 20, 2025
d6db965
add back
andrijapau Nov 20, 2025
11b08f0
Update frontend/catalyst/python_interface/visualization/pydot_dag_bui…
andrijapau Nov 20, 2025
a76b5bd
Update frontend/catalyst/python_interface/visualization/pydot_dag_bui…
andrijapau Nov 20, 2025
66a87ab
Merge branch 'feature/dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 20, 2025
90e4ebd
fix
andrijapau Nov 20, 2025
3d9e4bb
fix
andrijapau Nov 20, 2025
e303ef1
Merge branch 'feature/graph-visualization' into feature/mlir-to-dag-pass
andrijapau Nov 20, 2025
2504c13
clean-up
andrijapau Nov 21, 2025
4e78777
remove unnecessary stuff
andrijapau Nov 21, 2025
e17c111
add test skeleton
andrijapau Nov 21, 2025
19ca1b5
add basic tests
andrijapau Nov 21, 2025
7f88834
basic test idea
andrijapau Nov 21, 2025
3d48c92
make visit private
andrijapau Nov 21, 2025
49b3834
make visit private
andrijapau Nov 21, 2025
80ca59d
fix tests
andrijapau Nov 21, 2025
430ceb8
fix tests
andrijapau Nov 22, 2025
0aff4e5
clean-up
andrijapau Nov 24, 2025
e22cbd2
fix: upgrade DAG builders to have get_ methods
andrijapau Nov 24, 2025
acf3da7
cl
andrijapau Nov 24, 2025
bc978ad
update pydot to adhere to new base class methods
andrijapau Nov 24, 2025
dc4cb1c
add test skeletons
andrijapau Nov 24, 2025
7e825d6
add tests
andrijapau Nov 24, 2025
41fc4d1
Apply suggestion from @andrijapau
andrijapau Nov 24, 2025
1868346
add tests
andrijapau Nov 24, 2025
fd8d721
fix tests
andrijapau Nov 24, 2025
284ba07
update tests
andrijapau Nov 24, 2025
95ace87
fix documentation
andrijapau Nov 24, 2025
ec9caae
fix documentation
andrijapau Nov 24, 2025
99bd602
fix tests
andrijapau Nov 24, 2025
7622b50
whoops
andrijapau Nov 24, 2025
86e8389
whoops
andrijapau Nov 24, 2025
a5dc1ac
rename a bunch of stuff
andrijapau Nov 24, 2025
fe7ef47
fix documentation
andrijapau Nov 24, 2025
b2a13cf
rename a bunch of stuff
andrijapau Nov 24, 2025
abfd932
add dev comment
andrijapau Nov 24, 2025
a481a04
rename
andrijapau Nov 24, 2025
9a18e5c
update test
andrijapau Nov 24, 2025
afa60ee
merge fix/upgrade-dag-builders to feature/mlir-to-dag-pass
andrijapau Nov 24, 2025
0f6ab76
add immutability tests
andrijapau Nov 24, 2025
5584c90
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 24, 2025
6d15d7b
clean-up
andrijapau Nov 25, 2025
888d025
clean-up
andrijapau Nov 25, 2025
d4b34f9
whoops
andrijapau Nov 25, 2025
2f27f08
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 25, 2025
33aa334
fix test
andrijapau Nov 25, 2025
d50cfdc
whoops
andrijapau Nov 25, 2025
a364869
cleanup
andrijapau Nov 25, 2025
cddb234
clean-up
andrijapau Nov 25, 2025
1b5210c
fix formatting issue
andrijapau Nov 25, 2025
14b28bb
isort
andrijapau Nov 25, 2025
a1e9211
update tests
andrijapau Nov 25, 2025
aad7449
Apply suggestion from @andrijapau
andrijapau Nov 25, 2025
8225658
isort
andrijapau Nov 25, 2025
b51016e
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 25, 2025
07a0597
Update frontend/catalyst/python_interface/visualization/construct_cir…
andrijapau Nov 25, 2025
40b1eb4
move things around
andrijapau Nov 25, 2025
77dd502
minor cleanup
andrijapau Nov 25, 2025
b4ccd61
refactor the get_ to properties
andrijapau Nov 25, 2025
d354dba
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 25, 2025
d14c15b
update fake dag builder
andrijapau Nov 25, 2025
0e0ddfd
attempt to get rid of _subgraphs
andrijapau Nov 26, 2025
c41adb9
clean-up test
andrijapau Nov 26, 2025
e803543
rename __base__ to None
andrijapau Nov 26, 2025
42cede2
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 26, 2025
085ec57
clean-up
andrijapau Nov 26, 2025
c08a84c
whoops
andrijapau Nov 26, 2025
edc2076
add cluster_ prefix
andrijapau Nov 26, 2025
4c71876
add debug string
andrijapau Nov 26, 2025
f1e5849
bring back cache
andrijapau Nov 26, 2025
0ff2ce9
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 26, 2025
3c9ca3a
add good dev comment
andrijapau Nov 26, 2025
b83e2a4
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 26, 2025
bc54dbf
Apply suggestion from @andrijapau
andrijapau Nov 26, 2025
ee57f40
Apply suggestion from @andrijapau
andrijapau Nov 26, 2025
c341858
whoops
andrijapau Nov 26, 2025
2ded5dc
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 26, 2025
0460cac
refactor singledispatch
andrijapau Nov 26, 2025
0cbe9af
Update frontend/catalyst/python_interface/visualization/dag_builder.py
andrijapau Nov 26, 2025
4dbdb13
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 26, 2025
e752329
add more details to docstring
andrijapau Nov 26, 2025
86b5662
Update frontend/catalyst/python_interface/visualization/dag_builder.py
andrijapau Nov 26, 2025
9c26efd
Update frontend/catalyst/python_interface/visualization/pydot_dag_bui…
andrijapau Nov 26, 2025
81a9aa6
Update frontend/catalyst/python_interface/visualization/pydot_dag_bui…
andrijapau Nov 26, 2025
ab06276
Update frontend/test/pytest/python_interface/visualization/test_pydot…
andrijapau Nov 26, 2025
3e4102b
Update frontend/catalyst/python_interface/visualization/pydot_dag_bui…
andrijapau Nov 26, 2025
194f14a
Update frontend/catalyst/python_interface/visualization/dag_builder.py
andrijapau Nov 26, 2025
685842c
fix fakebackend
andrijapau Nov 26, 2025
986fb3f
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 26, 2025
8c64d81
isort
andrijapau Nov 26, 2025
606f5f5
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 26, 2025
f666a9f
add exceptions check
andrijapau Nov 26, 2025
e28b2b7
add better documentation
andrijapau Nov 26, 2025
952fd7f
fix typo
andrijapau Nov 26, 2025
99f9fc6
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 26, 2025
8f2dc98
Apply suggestion from @andrijapau
andrijapau Nov 26, 2025
eac25d5
Merge branch 'fix/upgrade-dag-builders' into feature/mlir-to-dag-pass
andrijapau Nov 26, 2025
83225b3
Merge branch 'feature/graph-visualization' into feature/mlir-to-dag-pass
andrijapau Nov 26, 2025
ffc9726
fix naming
andrijapau Nov 26, 2025
e675299
feat: add frontend draw_graph API
andrijapau Nov 27, 2025
f803505
clean up
andrijapau Nov 28, 2025
ec6d9f6
merge base into pr
andrijapau Dec 3, 2025
498fb18
cl
andrijapau Dec 3, 2025
f849bc4
format
andrijapau Dec 3, 2025
50aceef
improve frontend
andrijapau Dec 3, 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
1 change: 1 addition & 0 deletions doc/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[(#2229)](https://github.com/PennyLaneAI/catalyst/pull/2229)
[(#2214)](https://github.com/PennyLaneAI/catalyst/pull/2214)
[(#2246)](https://github.com/PennyLaneAI/catalyst/pull/2246)
[(#2243)](https://github.com/PennyLaneAI/catalyst/pull/2243)

* Added ``catalyst.switch``, a qjit compatible, index-switch style control flow decorator.
[(#2171)](https://github.com/PennyLaneAI/catalyst/pull/2171)
Expand Down
55 changes: 55 additions & 0 deletions frontend/catalyst/python_interface/inspection/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@

from __future__ import annotations

import io
import warnings
from functools import wraps
from typing import TYPE_CHECKING

import matplotlib.image as mpimg
import matplotlib.pyplot as plt
from pennylane.tape import QuantumScript

from catalyst.python_interface.compiler import Compiler

from .collector import QMLCollector
from .construct_circuit_dag import ConstructCircuitDAG
from .pydot_dag_builder import PyDotDAGBuilder
from .xdsl_conversion import get_mlir_module

if TYPE_CHECKING:
Expand Down Expand Up @@ -90,3 +95,53 @@ def wrapper(*args, **kwargs):
return cache.get(level, cache[max(cache.keys())])[0]

return wrapper


def draw_graph(qnode: QNode, *, level: None | int = None) -> Callable:
"""
???
"""
cache: dict[int, tuple[str, str]] = _cache_store.setdefault(qnode, {})

def _draw_callback(previous_pass, module, next_pass, pass_level=0):
"""Callback function for circuit drawing."""

pass_instance = previous_pass if previous_pass else next_pass
# Process module to build DAG
utility = ConstructCircuitDAG(PyDotDAGBuilder())
utility.construct(module)
# Store DAG in cache
image_bytes = utility.dag_builder.graph.create_png(prog="dot")
pass_name = pass_instance.name if hasattr(pass_instance, "name") else pass_instance
cache[pass_level] = (
image_bytes,
pass_name if pass_level else "No transforms",
)

@wraps(qnode)
def wrapper(*args, **kwargs):
mlir_module = _get_mlir_module(qnode, args, kwargs)
Compiler.run(mlir_module, callback=_draw_callback)

if not cache:
return None

# Retrieve Data (Fall back to highest level if 'level' is not found)
max_level = max(cache.keys())
image_bytes, pass_name = cache.get(level, cache[max_level])

# Render image bytes to matplotlib
sio = io.BytesIO()
sio.write(image_bytes)
sio.seek(0)

img = mpimg.imread(sio)

fig, ax = plt.subplots()
ax.imshow(img)
ax.set_axis_off()
ax.set_title(f"Level {level if level is not None else max_level}: {pass_name}", fontsize=10)

return fig, ax

return wrapper
Loading