-
Notifications
You must be signed in to change notification settings - Fork 1
Restructure and move qubit dialect #557
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2d29a4a
Restructure qubit dialect
david-pl e9435d6
Remove leftover code
david-pl eb30900
Add Phil's type inference impl back in
david-pl 7885984
Also make QubitId and MeasurementId adhere to broadcasting semantics
david-pl 367fd76
Merge branch 'main' into david/549-qubit-restructure
johnzl-777 48c65e9
Apply suggestions from code review
david-pl 6303306
Add defaults to annotated doc strings
david-pl cc9fa9c
Merge branch 'main' into david/549-qubit-restructure
david-pl 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
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
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,12 @@ | ||
| from bloqade.types import Qubit as Qubit, QubitType as QubitType | ||
|
|
||
| from . import stmts as stmts, analysis as analysis | ||
| from .stdlib import new as new, qalloc as qalloc, broadcast as broadcast | ||
| from ._dialect import dialect as dialect | ||
| from ._prelude import kernel as kernel | ||
| from .stdlib.simple import ( | ||
| reset as reset, | ||
| measure as measure, | ||
| get_qubit_id as get_qubit_id, | ||
| get_measurement_id as get_measurement_id, | ||
| ) |
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,3 @@ | ||
| from kirin import ir | ||
|
|
||
| dialect = ir.Dialect("qubit") |
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,49 @@ | ||
| from typing import Any, TypeVar | ||
|
|
||
| from kirin.dialects import ilist | ||
| from kirin.lowering import wraps | ||
|
|
||
| from bloqade.types import Qubit, MeasurementResult | ||
|
|
||
| from .stmts import New, Reset, Measure, QubitId, MeasurementId | ||
|
|
||
|
|
||
| @wraps(New) | ||
| def new() -> Qubit: | ||
| """Create a new qubit. | ||
|
|
||
| Returns: | ||
| Qubit: A new qubit. | ||
| """ | ||
| ... | ||
|
|
||
|
|
||
| N = TypeVar("N", bound=int) | ||
|
|
||
|
|
||
| @wraps(Measure) | ||
| def measure(qubits: ilist.IList[Qubit, N]) -> ilist.IList[MeasurementResult, N]: | ||
| """Measure a list of qubits. | ||
|
|
||
| Args: | ||
| qubits (IList[Qubit, N]): The list of qubits to measure. | ||
|
|
||
| Returns: | ||
| IList[MeasurementResult, N]: The list containing the results of the measurements. | ||
| A MeasurementResult can represent both 0 and 1, but also atoms that are lost. | ||
| """ | ||
| ... | ||
|
|
||
|
|
||
| @wraps(QubitId) | ||
| def get_qubit_id(qubits: ilist.IList[Qubit, N]) -> ilist.IList[int, N]: ... | ||
|
|
||
|
|
||
| @wraps(MeasurementId) | ||
| def get_measurement_id( | ||
| measurements: ilist.IList[MeasurementResult, N], | ||
| ) -> ilist.IList[int, N]: ... | ||
|
|
||
|
|
||
| @wraps(Reset) | ||
| def reset(qubits: ilist.IList[Qubit, Any]) -> None: ... |
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,45 @@ | ||
| from typing import Annotated | ||
|
|
||
| from kirin import ir | ||
| from kirin.passes import Default | ||
| from kirin.prelude import structural_no_opt | ||
| from typing_extensions import Doc | ||
|
|
||
| from . import _dialect as qubit | ||
|
|
||
|
|
||
| @ir.dialect_group(structural_no_opt.union([qubit])) | ||
| def kernel(self): | ||
| """Compile to a qubit kernel""" | ||
|
|
||
| def run_pass( | ||
| mt, | ||
| *, | ||
| verify: Annotated[ | ||
| bool, Doc("run `verify` before running passes, default is `True`") | ||
| ] = True, | ||
| typeinfer: Annotated[ | ||
| bool, | ||
| Doc( | ||
| "run type inference and apply the inferred type to IR, default `False`" | ||
| ), | ||
| ] = False, | ||
| fold: Annotated[bool, Doc("run folding passes, default is `True`")] = True, | ||
| aggressive: Annotated[ | ||
| bool, Doc("run aggressive folding passes if `fold=True`") | ||
| ] = False, | ||
| no_raise: Annotated[ | ||
| bool, Doc("do not raise exception during analysis, default is `True`") | ||
| ] = True, | ||
| ) -> None: | ||
| default_pass = Default( | ||
| self, | ||
| verify=verify, | ||
| fold=fold, | ||
| aggressive=aggressive, | ||
| typeinfer=typeinfer, | ||
| no_raise=no_raise, | ||
| ) | ||
| default_pass.fixpoint(mt) | ||
|
|
||
| return run_pass |
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 @@ | ||
| from . import address_impl as address_impl |
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,2 @@ | ||
| from . import simple as simple, broadcast as broadcast | ||
| from ._new import new as new, qalloc as qalloc |
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.
I know this isn't part of the PR (so feel free to just resolve this) but I'm curious, why is it a
qarghere when we usually do something likecontrolsvs.targets?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.
Oh, that was introduced by @weinbe58 somewhere. I think I even left a similar comment on the PR? Should we change it? (Not in this PR, of course).