-
Notifications
You must be signed in to change notification settings - Fork 58
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
47
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 all commits
Commits
Show all changes
47 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 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
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 .inspection import QMLCollector | ||
| from .parser import QuantumParser | ||
| from .pass_api import compiler_transform | ||
|
|
||
| __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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah - just a place holder for now 😄