-
Notifications
You must be signed in to change notification settings - Fork 59
feat: add graph visualization for compiled programs #2216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrijapau
wants to merge
67
commits into
main
Choose a base branch
from
feature/graph-visualization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 37 commits
Commits
Show all changes
67 commits
Select commit
Hold shift + click to select a range
df8b97b
Migrate unified compiler to Catalyst
mudit2812 9536707
Fixing migration artifacts; linting
mudit2812 1453aae
Fix CI errors; Ignore unified compiler in coverage reports
mudit2812 efc0f88
Test out how graphviz is installed
mudit2812 10cd749
Lint some more
mudit2812 27de22d
Merge branch 'main' into migrate-unified-compiler
mudit2812 f7aa2b6
[skip ci] Skip CI
mudit2812 012f58b
[skip ci] Skip CI
mudit2812 f0a0c90
Merge branch 'migrate-unified-compiler' of https://github.com/PennyLa…
mudit2812 c98755e
Try installing graphviz with apt
mudit2812 bb5bd00
Fix codefactor complaints
mudit2812 1448472
Merge branch 'main' into migrate-unified-compiler
mudit2812 5e745f5
Try appeasing codefactor again
mudit2812 0409933
Try appeasing codefactor once again
mudit2812 e786a12
Pylint suppression
mudit2812 4ae10ff
Reduce complexity of stablehlo.reduce and stablehlo.dynamic_broadcast…
mudit2812 dc41a7b
Fix some failures
mudit2812 58b13e4
Try change to graphviz installation
mudit2812 4e5f904
Merge branch 'main' into migrate-unified-compiler
mudit2812 637d2cf
Try installing graphviz with pip
mudit2812 091c5e1
Merge branch 'main' into migrate-unified-compiler
mudit2812 64e0fd4
Try installing graphviz with both apt and pip
mudit2812 dc15d3a
Add utils file to remove conftest imports
mudit2812 e7e33d6
Merge branch 'main' into migrate-unified-compiler
mudit2812 f919e8d
Remove unused imports
mudit2812 005ba9f
Add graphviz dependencies to lightning.kokkos testing workflow
mudit2812 6117189
Update cookbook
mudit2812 6961324
Migrate all changelog entries from PennyLane
mudit2812 0fdbb46
Merge branch 'main' into migrate-unified-compiler
mudit2812 a868bc3
Add EOF new line to .codecov.yml
mudit2812 8f00b2f
change changelog entry slightly
mudit2812 22a6e6e
Merge branch 'main' into migrate-unified-compiler
mudit2812 a63412d
basic cl
andrijapau 82b023a
Trigger CI
andrijapau efdea51
Merge branch 'migrate-unified-compiler' into feature/graph-visualization
andrijapau 248b7bd
feat: add `DAGBuilder` abstract base class and `PyDotDAGBuilder` conc…
andrijapau b4a321d
Merge branch 'main' into migrate-unified-compiler
mudit2812 09be3af
feat: add `nodes`, `clusters` and `edges` properties to DAGBuilders (…
andrijapau 4cbe02a
Remove reference to 'remove-chained-self-inverses'
mudit2812 c5f08c3
Remove leftover references to pennylane.compiler.python_compiler
mudit2812 251832a
feat: add `ConstructCircuitDAG` director pattern (#2214)
andrijapau f8cd095
fix: rename `id` to `uid` (#2246)
andrijapau 43acb6f
fix: rename id to uid in FakeDAGBuilder
andrijapau f87de2a
format: black and isort
andrijapau fe76357
Streamline circuit inspection utilities (#2237)
jzaia18 fc2ce0e
Merge branch 'migrate-unified-compiler' into feature/graph-visualization
andrijapau 5f2028d
feat: add cluster visualization for `FuncOp` and `DeviceInitOp` opera…
andrijapau c5b9337
fix: use standard cluster label rather than "label" nodes (#2285)
andrijapau 8f6563e
feat: add cluster visualization for `WhileOp`, `IfOp`, `ForOp` (#2234)
andrijapau 3179d95
feat: visualize static operators and measurements as nodes (#2218)
andrijapau 017a93a
Merge branch 'main' into feature/graph-visualization
andrijapau 53923a6
Apply suggestion from @andrijapau
andrijapau 126f585
Revert "Apply suggestion from @andrijapau"
andrijapau 4bef8af
clean up merge
andrijapau 1555917
Apply suggestion from @andrijapau
andrijapau 993722f
Apply suggestion from @andrijapau
andrijapau 527e9b0
Apply suggestion from @andrijapau
andrijapau 248594c
Apply suggestion from @andrijapau
andrijapau 8c32850
Apply suggestion from @andrijapau
andrijapau feb3ef3
Apply suggestion from @andrijapau
andrijapau b3d9a0b
remove transform.py
andrijapau f88ccc3
restore frontend/catalyst/compiler.py
andrijapau 26fddb8
restore frontend/catalyst/jit.py
andrijapau 324bbda
restore frontend/test/pytest/python_interface/conftest.py
andrijapau 8bf4c17
restore test_python_compiler.py
andrijapau e8ef2c3
change tests
andrijapau 37fe1d9
Merge branch 'main' into feature/graph-visualization
andrijapau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,6 @@ coverage: | |
| status: | ||
| project: false | ||
| patch: true | ||
|
|
||
| ignore: | ||
| - "frontend/catalyst/python_interface" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,57 @@ | |
|
|
||
| <h3>New features since last release</h3> | ||
|
|
||
| * Compiled programs can be visualized. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This entry should probably be significantly more descriptive since it's a pretty big new feature
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah - just a place holder for now 😄 |
||
| [(#2213)](https://github.com/PennyLaneAI/catalyst/pull/2213) | ||
| [(#2229)](https://github.com/PennyLaneAI/catalyst/pull/2229) | ||
|
|
||
| * Added ``catalyst.switch``, a qjit compatible, index-switch style control flow decorator. | ||
| [(#2171)](https://github.com/PennyLaneAI/catalyst/pull/2171) | ||
|
|
||
| <h3>Improvements 🛠</h3> | ||
|
|
||
| * Add an experimental `outline_state_evolution_pass` xDSL pass to `catalyst.python_interface.transforms`, | ||
| which moves all quantum gate operations to a private callable. | ||
| [(#8367)](https://github.com/PennyLaneAI/pennylane/pull/8367) | ||
|
|
||
| * A new experimental `split_non_commuting_pass` compiler pass has been added to | ||
| `catalyst.python_interface.transforms`. This pass splits quantum functions that | ||
| measure observables on the same wires into multiple function executions, where | ||
| each execution measures observables on different wires (using the "wires" grouping | ||
| strategy). The original function is replaced with calls to these generated functions, | ||
| and the results are combined appropriately. | ||
| [(#8531)](https://github.com/PennyLaneAI/pennylane/pull/8531) | ||
|
|
||
| * Add the `PCPhaseOp` operation to the xDSL Quantum dialect. | ||
| [(#8621)](https://github.com/PennyLaneAI/pennylane/pull/8621) | ||
|
|
||
| * Users can now apply xDSL passes without the need to pass the `pass_plugins` argument to | ||
| the `qjit` decorator. | ||
| [(#8572)](https://github.com/PennyLaneAI/pennylane/pull/8572) | ||
| [(#8573)](https://github.com/PennyLaneAI/pennylane/pull/8573) | ||
| [(#2169)](https://github.com/PennyLaneAI/catalyst/pull/2169) | ||
| [(#2183)](https://github.com/PennyLaneAI/catalyst/pull/2183) | ||
|
|
||
| * The :meth:`catalyst.python_interface.transforms.convert_to_mbqc_formalism_pass` now | ||
| supports :class:`~xdsl.dialects.scf.IndexSwitchOp` in IR and ignores regions that have no body. | ||
| [(#8632)](https://github.com/PennyLaneAI/pennylane/pull/8632) | ||
|
|
||
| * The `convert_to_mbqc_formalism` compilation pass now outlines the operations to represent a gate | ||
| in the MBQC formalism into subroutines in order to reduce the IR size for large programs. | ||
| [(#8619)](https://github.com/PennyLaneAI/pennylane/pull/8619) | ||
|
|
||
| * The :meth:`catalyst.python_interface.Compiler.run` method now accepts a string as input, | ||
| which is parsed and transformed with xDSL. | ||
| [(#8587)](https://github.com/PennyLaneAI/pennylane/pull/8587) | ||
|
|
||
| * An `is_xdsl_pass` function has been added to the `catalyst.python_interface.pass_api` module. | ||
| This function checks if a pass name corresponds to an xDSL implemented pass. | ||
| [(#8572)](https://github.com/PennyLaneAI/pennylane/pull/8572) | ||
|
|
||
| * A new `catalyst.python_interface.utils` submodule has been added, containing general-purpose utilities for | ||
| working with xDSL. This includes a function that extracts the concrete value of scalar, constant SSA values. | ||
| [(#8514)](https://github.com/PennyLaneAI/pennylane/pull/8514) | ||
|
|
||
| * Resource tracking now supports dynamic qubit allocation | ||
| [(#2203)](https://github.com/PennyLaneAI/catalyst/pull/2203) | ||
|
|
||
|
|
@@ -38,11 +84,6 @@ | |
| * `qml.grad` and `qml.jacobian` can now be used with `qjit` when program capture is enabled. | ||
| [(#2078)](https://github.com/PennyLaneAI/catalyst/pull/2078) | ||
|
|
||
| * xDSL passes are now automatically detected when using the `qjit` decorator. | ||
| This removes the need to pass the `pass_plugins` argument to the `qjit` decorator. | ||
| [(#2169)](https://github.com/PennyLaneAI/catalyst/pull/2169) | ||
| [(#2183)](https://github.com/PennyLaneAI/catalyst/pull/2183) | ||
|
|
||
| * The ``mlir_opt`` property now correctly handles xDSL passes by automatically | ||
| detecting when the Python compiler is being used and routing through it appropriately. | ||
| [(#2190)](https://github.com/PennyLaneAI/catalyst/pull/2190) | ||
|
|
@@ -75,6 +116,20 @@ | |
|
|
||
| <h3>Bug fixes 🐛</h3> | ||
|
|
||
| * The experimental xDSL :func:`~catalyst.python_interface.transforms.measurements_from_samples_pass` | ||
| pass has been updated to support `shots` defined by an `arith.constant` operation. | ||
| [(#8460)](https://github.com/PennyLaneAI/pennylane/pull/8460) | ||
|
|
||
| * The experimental xDSL :func:`~catalyst.python_interface.transforms.diagonalize_measurements` | ||
| pass has been updated to fix a bug that included the wrong SSA value for final qubit insertion | ||
| and deallocation at the end of the circuit. A clear error is now also raised when there are | ||
| observables with overlapping wires. | ||
| [(#8383)](https://github.com/PennyLaneAI/pennylane/pull/8383) | ||
|
|
||
| * Fixes a bug in the constructor of the xDSL Quantum dialect's `QubitUnitaryOp` that | ||
| prevented an instance from being constructed. | ||
| [(#8456)](https://github.com/PennyLaneAI/pennylane/pull/8456) | ||
|
|
||
andrijapau marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Fixes an issue where a heap-to-stack allocation conversion pass was causing SIGSEGV issues | ||
| during program execution at runtime. | ||
| [(#2172)](https://github.com/PennyLaneAI/catalyst/pull/2172) | ||
|
|
@@ -130,6 +185,10 @@ | |
|
|
||
| <h3>Internal changes ⚙️</h3> | ||
|
|
||
| * Migrated the `pennylane.compiler.python_compiler` submodule from PennyLane to Catalyst. | ||
| It is now accessible as `catalyst.python_interface`. | ||
| [(#2199)](https://github.com/PennyLaneAI/catalyst/pull/2199) | ||
|
|
||
| * Replaces the deprecated `shape_dtype_to_ir_type` function with the `RankedTensorType.get` method. | ||
| [(#2159)](https://github.com/PennyLaneAI/catalyst/pull/2159) | ||
|
|
||
|
|
@@ -181,6 +240,11 @@ | |
|
|
||
| <h3>Documentation 📝</h3> | ||
|
|
||
| * Added a "Unified Compiler Cookbook" RST file, along with tutorials, to `catalyst.python_interface.doc`, | ||
| which provides a quickstart guide for getting started with xDSL and its integration with PennyLane and | ||
| Catalyst. | ||
| [(#8571)](https://github.com/PennyLaneAI/pennylane/pull/8571) | ||
|
|
||
andrijapau marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * A typo in the code example for :func:`~.passes.ppr_to_ppm` has been corrected. | ||
| [(#2136)](https://github.com/PennyLaneAI/catalyst/pull/2136) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # 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. | ||
| """Python Compiler API for integration of Catalyst with xDSL.""" | ||
|
|
||
| from .compiler import Compiler | ||
| from .parser import QuantumParser | ||
| from .pass_api import compiler_transform | ||
| from .visualization import QMLCollector | ||
|
|
||
| __all__ = [ | ||
| "Compiler", | ||
| "compiler_transform", | ||
| "QuantumParser", | ||
| "QMLCollector", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # 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 PennyLane-xDSL integration API.""" | ||
|
|
||
|
|
||
| import io | ||
|
|
||
| from jax._src.interpreters import mlir | ||
| from jaxlib.mlir.dialects import stablehlo | ||
| from jaxlib.mlir.ir import Context as jaxContext | ||
| from jaxlib.mlir.ir import Module as jaxModule | ||
| from pennylane.typing import Callable | ||
| from xdsl.context import Context as xContext | ||
| from xdsl.dialects.builtin import ModuleOp | ||
| from xdsl.passes import ModulePass, PassPipeline | ||
| from xdsl.printer import Printer | ||
|
|
||
| from catalyst.python_interface.parser import QuantumParser | ||
| from catalyst.python_interface.pass_api import ApplyTransformSequence | ||
|
|
||
|
|
||
| # pylint: disable=too-few-public-methods | ||
| class Compiler: | ||
| """Compiler namespace""" | ||
|
|
||
| @staticmethod | ||
| def run( | ||
| module: jaxModule | str, | ||
| callback: Callable[[ModulePass, ModuleOp, ModulePass], None] | None = None, | ||
| ) -> jaxModule | str: | ||
| """Runs the apply-transform-sequence pass. | ||
|
|
||
| The apply-transform-sequence pass is a "meta-pass". In other words, | ||
| it is a pass that runs other passes. | ||
|
|
||
| Args: | ||
| module: Either a Jax MLIR module or MLIR IR as a string | ||
| callback: Optional callback function called between passes | ||
|
|
||
| Returns: | ||
| jaxModule | str: jaxModule if the input was a jaxModule, else a string. | ||
| """ | ||
| # Convert to generic text format | ||
| is_jax_module = isinstance(module, jaxModule) | ||
| if is_jax_module: | ||
| gentxtmod = module.operation.get_asm( | ||
| binary=False, print_generic_op_form=True, assume_verified=True | ||
| ) | ||
| else: | ||
| gentxtmod = module | ||
|
|
||
| # Parse and transform with xDSL | ||
| ctx = xContext(allow_unregistered=True) | ||
| parser = QuantumParser(ctx, gentxtmod) | ||
| # xmod is modified in place | ||
| xmod = parser.parse_module() | ||
| pipeline = PassPipeline((ApplyTransformSequence(callback=callback),)) | ||
| pipeline.apply(ctx, xmod) | ||
|
|
||
| # Convert back to string | ||
| buffer = io.StringIO() | ||
| Printer(stream=buffer, print_generic_format=True).print_op(xmod) | ||
|
|
||
| # Convert back to jaxModule if input was jaxModule | ||
| if is_jax_module: | ||
| with jaxContext() as jctx: | ||
| jctx.allow_unregistered_dialects = True | ||
| jctx.append_dialect_registry(mlir.upstream_dialects) | ||
| stablehlo.register_dialect(jctx) # pylint: disable=no-member | ||
| newmod: jaxModule = jaxModule.parse(buffer.getvalue()) | ||
| return newmod | ||
| return buffer.getvalue() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.