-
Notifications
You must be signed in to change notification settings - Fork 59
Create xDSL universe for the unified compiler #2208
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
mudit2812
wants to merge
43
commits into
main
Choose a base branch
from
xdsl-universe
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
43 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 e7db061
Migrate xDSL universe PR to Catalyst
mudit2812 9863ed6
Fix link in changelog
mudit2812 22a6e6e
Merge branch 'main' into migrate-unified-compiler
mudit2812 b4a321d
Merge branch 'main' into migrate-unified-compiler
mudit2812 4cbe02a
Remove reference to 'remove-chained-self-inverses'
mudit2812 a3d252e
Merge branch 'migrate-unified-compiler' into xdsl-universe
mudit2812 f65965d
Merge branch 'main' into xdsl-universe
mudit2812 058b3f6
Resolve merge artifacts
mudit2812 ec17ecf
Fit jit
mudit2812 f1fd5ae
Raise error if attempting to use python_interface without xdsl installed
mudit2812 2a3de09
Add pylint suppression
mudit2812 b3b8121
Merge branch 'main' into xdsl-universe
mudit2812 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # 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. | ||
| """xDSL universe for containing all dialects and passes.""" | ||
|
|
||
| xdsl_available = True | ||
|
|
||
| try: | ||
| from xdsl.passes import ModulePass | ||
| from xdsl.universe import Universe | ||
| except (ImportError, ModuleNotFoundError): | ||
| xdsl_available = False # pragma: no cover | ||
|
|
||
| # We must check that xDSL is installed because we're adding an entry point to | ||
| # PennyLane that references this file, and we must ensure that PennyLane can | ||
| # be installed in environments where xDSL is not installed. | ||
| XDSL_UNIVERSE = None | ||
|
|
||
| if xdsl_available: | ||
| # pylint: disable=import-outside-toplevel | ||
| from . import dialects, transforms | ||
|
|
||
| shared_dialects = ("stablehlo", "transform") | ||
|
|
||
| # Create a map from dialect names to dialect classes. Dialects that are already | ||
| # provided by xDSL cannot be loaded into the multiverse, so we don't add them to | ||
| # our universe. | ||
| names_to_dialects = { | ||
| d.name: d | ||
| for name in dialects.__all__ | ||
| if (d := getattr(dialects, name)).name not in shared_dialects | ||
| } | ||
|
|
||
| # Create a map from pass names to their respective ModulePass. The transforms module | ||
| # contains PassDispatcher instances as well as ModulePasses. We only want to collect | ||
| # the ModulePasses. We cannot use issubclass with instances, which is why we first | ||
| # check if isinstance(transform, type). | ||
| names_to_passes = { | ||
| t.name: t | ||
| for name in transforms.__all__ | ||
| if isinstance((t := getattr(transforms, name)), type) and issubclass(t, ModulePass) | ||
| } | ||
|
|
||
| # The Universe is used to expose custom dialects and transforms to xDSL. It is | ||
| # specified as an entry point in PennyLane's pyproject.toml file, which makes | ||
| # it available to look up by xDSL for tools such as xdsl-opt, xdsl-gui, etc. | ||
| XDSL_UNIVERSE = Universe(all_dialects=names_to_dialects, all_passes=names_to_passes) |
60 changes: 60 additions & 0 deletions
60
frontend/test/pytest/python_interface/test_xdsl_universe.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,60 @@ | ||
| # 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. | ||
| """Unit tests for the xDSL universe.""" | ||
|
|
||
| import pytest | ||
|
|
||
| pytestmark = pytest.mark.xdsl | ||
| xdsl = pytest.importorskip("xdsl") | ||
|
|
||
| # pylint: disable=wrong-import-position | ||
| from xdsl.passes import ModulePass | ||
| from xdsl.universe import Universe as xUniverse | ||
|
|
||
| from catalyst.python_interface import dialects, transforms | ||
| from catalyst.python_interface.xdsl_universe import XDSL_UNIVERSE, shared_dialects | ||
|
|
||
| all_dialects = tuple(getattr(dialects, name) for name in dialects.__all__) | ||
| all_transforms = tuple( | ||
| transform | ||
| for name in transforms.__all__ | ||
| if isinstance((transform := getattr(transforms, name)), type) | ||
| and issubclass(transform, ModulePass) | ||
| ) | ||
|
|
||
|
|
||
| def test_correct_universe(): | ||
| """Test that all the available dialects and transforms are available in the universe.""" | ||
| for d in all_dialects: | ||
| if d.name not in shared_dialects: | ||
| assert d.name in XDSL_UNIVERSE.all_dialects | ||
| assert XDSL_UNIVERSE.all_dialects[d.name] == d | ||
|
|
||
| for t in all_transforms: | ||
| assert t.name in XDSL_UNIVERSE.all_passes | ||
| assert XDSL_UNIVERSE.all_passes[t.name] == t | ||
|
|
||
|
|
||
| def test_correct_multiverse(): | ||
| """Test that all the available dialects and transforms are available in the multiverse.""" | ||
| multiverse = xUniverse.get_multiverse() | ||
|
|
||
| for d in all_dialects: | ||
| assert d.name in multiverse.all_dialects | ||
| if d.name not in shared_dialects: | ||
| assert multiverse.all_dialects[d.name] == d | ||
|
|
||
| for t in all_transforms: | ||
| assert t.name in multiverse.all_passes | ||
| assert multiverse.all_passes[t.name] == t |
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
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.
Everything failing. Need to remove this.