-
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
Changes from 4 commits
2d29a4a
e9435d6
eb30900
7885984
367fd76
48c65e9
6303306
cc9fa9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| from kirin.decl import info, statement | ||
| from kirin.dialects import ilist | ||
|
|
||
| from bloqade.squin import qubit | ||
| from bloqade.types import QubitType | ||
|
|
||
| from ._dialect import dialect | ||
|
|
||
|
|
@@ -12,20 +12,20 @@ | |
| @statement(dialect=dialect) | ||
| class CZ(ir.Statement): | ||
| traits = frozenset({lowering.FromPythonCall()}) | ||
| ctrls: ir.SSAValue = info.argument(ilist.IListType[qubit.QubitType, N]) | ||
| qargs: ir.SSAValue = info.argument(ilist.IListType[qubit.QubitType, N]) | ||
| ctrls: ir.SSAValue = info.argument(ilist.IListType[QubitType, N]) | ||
| qargs: ir.SSAValue = info.argument(ilist.IListType[QubitType, N]) | ||
|
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. I know this isn't part of the PR (so feel free to just resolve this) but I'm curious, why is it a
Collaborator
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. 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). |
||
|
|
||
|
|
||
| @statement(dialect=dialect) | ||
| class R(ir.Statement): | ||
| traits = frozenset({lowering.FromPythonCall()}) | ||
| inputs: ir.SSAValue = info.argument(ilist.IListType[qubit.QubitType, types.Any]) | ||
| inputs: ir.SSAValue = info.argument(ilist.IListType[QubitType, types.Any]) | ||
| axis_angle: ir.SSAValue = info.argument(types.Float) | ||
| rotation_angle: ir.SSAValue = info.argument(types.Float) | ||
|
|
||
|
|
||
| @statement(dialect=dialect) | ||
| class Rz(ir.Statement): | ||
| traits = frozenset({lowering.FromPythonCall()}) | ||
| inputs: ir.SSAValue = info.argument(ilist.IListType[qubit.QubitType, types.Any]) | ||
| inputs: ir.SSAValue = info.argument(ilist.IListType[QubitType, types.Any]) | ||
| rotation_angle: ir.SSAValue = info.argument(types.Float) | ||
| 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, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from kirin import ir | ||
|
|
||
| dialect = ir.Dialect("qubit") |
| 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: ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| 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")] = True, | ||
| aggressive: Annotated[ | ||
| bool, Doc("run aggressive folding passes if `fold=True`") | ||
| ] = False, | ||
| no_raise: Annotated[bool, Doc("do not raise exception during analysis")] = True, | ||
david-pl marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) -> None: | ||
| default_pass = Default( | ||
| self, | ||
| verify=verify, | ||
| fold=fold, | ||
| aggressive=aggressive, | ||
| typeinfer=typeinfer, | ||
| no_raise=no_raise, | ||
| ) | ||
| default_pass.fixpoint(mt) | ||
|
|
||
| return run_pass | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import address_impl as address_impl |
| 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 |
Uh oh!
There was an error while loading. Please reload this page.