-
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
70
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 59 commits
Commits
Show all changes
70 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 8add091
fix: remove pytest.mark.unit as it isnt recognized
andrijapau 32c9ca9
Merge branch 'main' into feature/graph-visualization
andrijapau da1b55c
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
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
122 changes: 122 additions & 0 deletions
122
frontend/catalyst/python_interface/dialects/transform.py
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,122 @@ | ||
| # 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 an updated version of the transform dialect. | ||
| As of the time of writing, xDSL uses the MLIR released with LLVM's | ||
| version 20.1.7. However, https://github.com/PennyLaneAI/catalyst/pull/1916 | ||
| will be updating MLIR where the transform dialect has the | ||
| `apply_registered_pass` operation re-defined. | ||
|
|
||
| See the following changelog on the above PR | ||
|
|
||
| Things related to transform.apply_registered_pass op: | ||
|
|
||
| It now takes in a dynamic_options | ||
|
|
||
| [MLIR][Transform] Allow ApplyRegisteredPassOp to take options as | ||
| a param llvm/llvm-project#142683. We don't need to use this as all our pass options are static. | ||
| https://github.com/llvm/llvm-project/pull/142683 | ||
|
|
||
| The options it takes in are now dictionaries instead of strings | ||
| [MLIR][Transform] apply_registered_pass op's options as a dict llvm/llvm-project#143159 | ||
| https://github.com/llvm/llvm-project/pull/143159 | ||
|
|
||
| This file will re-define the apply_registered_pass operation in xDSL | ||
| and the transform dialect. | ||
|
|
||
| Once xDSL moves to a newer version of MLIR, these changes should | ||
| be contributed upstream. | ||
| """ | ||
|
|
||
| from xdsl.dialects.builtin import Dialect | ||
| from xdsl.dialects.transform import ApplyRegisteredPassOp as xApplyRegisteredPassOp | ||
| from xdsl.dialects.transform import ( | ||
| DictionaryAttr, | ||
| StringAttr, | ||
| ) | ||
| from xdsl.dialects.transform import Transform as xTransform | ||
| from xdsl.dialects.transform import ( | ||
| TransformHandleType, | ||
| irdl_op_definition, | ||
| operand_def, | ||
| prop_def, | ||
| result_def, | ||
| ) | ||
| from xdsl.ir import Attribute, SSAValue | ||
| from xdsl.irdl import IRDLOperation, ParsePropInAttrDict | ||
|
|
||
|
|
||
| # pylint: disable=line-too-long | ||
| @irdl_op_definition | ||
| class ApplyRegisteredPassOp(IRDLOperation): | ||
| """ | ||
| See external [documentation](https://mlir.llvm.org/docs/Dialects/Transform/#transformapply_registered_pass-transformapplyregisteredpassop). | ||
| """ | ||
|
|
||
| name = "transform.apply_registered_pass" | ||
|
|
||
| options = prop_def(DictionaryAttr, default_value=DictionaryAttr({})) | ||
| pass_name = prop_def(StringAttr) | ||
| target = operand_def(TransformHandleType) | ||
| result = result_def(TransformHandleType) | ||
| # While this assembly format doesn't match | ||
| # the one in upstream MLIR, | ||
| # this is because xDSL currently lacks CustomDirectives | ||
| # https://mlir.llvm.org/docs/DefiningDialects/Operations/#custom-directives | ||
| # https://github.com/xdslproject/xdsl/pull/4829 | ||
| # However, storing the property in the attribute should still work | ||
| # specially when parsing and printing in generic format. | ||
| # Which is how Catalyst and XDSL currently communicate at the moment. | ||
| # TODO: Add test. | ||
| assembly_format = "$pass_name `to` $target attr-dict `:` functional-type(operands, results)" | ||
| irdl_options = [ParsePropInAttrDict()] | ||
|
|
||
| def __init__( | ||
| self, | ||
| pass_name: str | StringAttr, | ||
| target: SSAValue, | ||
| options: dict[str | StringAttr, Attribute | str | bool | int] | None = None, | ||
| ): | ||
| if isinstance(pass_name, str): | ||
| pass_name = StringAttr(pass_name) | ||
|
|
||
| if isinstance(options, dict): | ||
| options = DictionaryAttr(options) | ||
|
|
||
| super().__init__( | ||
| properties={ | ||
| "pass_name": pass_name, | ||
| "options": options, | ||
| }, | ||
| operands=[target], | ||
| result_types=[target.type], | ||
| ) | ||
|
|
||
|
|
||
| # Copied over from xDSL's sources | ||
| # the main difference will be the use | ||
| # of a different ApplyRegisteredPassOp | ||
| operations = list(xTransform.operations) | ||
| del operations[operations.index(xApplyRegisteredPassOp)] | ||
| operations.append(ApplyRegisteredPassOp) | ||
|
|
||
| Transform = Dialect( | ||
| "transform", | ||
| [ | ||
| *operations, | ||
| ], | ||
| [ | ||
| *xTransform.attributes, | ||
| ], | ||
| ) |
Oops, something went wrong.
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 😄