-
Notifications
You must be signed in to change notification settings - Fork 1
Native gate + stdlib dialect group. #502
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
Native gate + stdlib dialect group. #502
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
☂️ Python Coverage
Overall Coverage
New Files
Modified Files
|
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.
Pull Request Overview
Introduces a new native dialect group and associated standard library of gate kernels (single-qubit and broadcast variants) plus a PyQrack backend implementation and tests. Key additions include dialect statements (CZ, R, Rz), interpreter implementations, stdlib wrappers for common gates, and initial tests for GHZ and selected 1-qubit gates.
- Adds native gate dialect (CZ, R, Rz) and kernel decorator.
- Provides stdlib single-qubit and broadcast gate implementations.
- Implements PyQrack native interpreter methods and initial (but partially ineffective) tests.
Reviewed Changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| test/native/test_stdlib.py | Adds GHZ and 1-qubit gate tests (assertion logic currently faulty, some expected states incorrect, limited coverage). |
| src/bloqade/pyqrack/native.py | Implements PyQrack interpreter methods for CZ, R, Rz (minor naming/built-in shadowing issue). |
| src/bloqade/pyqrack/init.py | Exports NativeMethods. |
| src/bloqade/native/stdlib/simple.py | Single-qubit gate kernels (duplication with broadcast; minor naming inconsistency; exposes many untested gates). |
| src/bloqade/native/stdlib/broadcast.py | Broadcast (vectorized) versions of gates (duplicated patterns from simple.py). |
| src/bloqade/native/stdlib/init.py | Re-exports stdlib symbols. |
| src/bloqade/native/dialects/gates/stmts.py | Declares CZ, R, Rz statements. |
| src/bloqade/native/dialects/gates/_interface.py | Provides lowering wrappers (CZ parameter order inconsistent with statement and usage). |
| src/bloqade/native/dialects/gates/_dialect.py | Defines dialect object. |
| src/bloqade/native/dialects/gates/init.py | Re-exports dialect constructs. |
| src/bloqade/native/_prelude.py | Defines kernel dialect group and pass pipeline wrapper. |
| src/bloqade/native/init.py | Exports kernel decorator and gates interface. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
@weinbe58 I really like the general structure here. One small thing I'd vote for is that we re-export the stdlib on the top-level of from bloqade import native
from bloqade.squin import qubit # NOTE: move that to top-level bloqade in other PR
@native.kernel
def main():
q = qubit.new(4)
native.x(q[0]) # calls stdlib.simple
native.broadcast.x(q) # calls stdlib.broadcastI'd also do the same in squin, so users can then just write |
This PR implements the native dialect group. In this dialect group we compose with `qubit` and `gates` where `gates` only has Neutral atom specific gate operations. Semanticaly these operators permit explicit parallelism at the statement level, e.g. all qubit arguments are `IListType[QubitType, Any]` and all rotation angles are a single value. Along with the dialect groups there is a standard library of some common gates implemented with this dialect group. There are versions of the gate library `bloqade.native.stdlib` has functions with single qubits as arguments and then there is another library `bloqade.native.stdlib.broadcast` where those arguments are broadcasted like the statements. NOTE: there is no analysis methods required here because all statements have no return value.
This implements the clifford dialect under squin, as discussed in #494. Consistent with #502, all statements take a list of qubits as arguments. We don't expose the wrappers, instead, there is a `simple` stdlib and a `broadcast` stdlib, which contains kernel functions that provide the user-facing API. Some open things: * I'm re-exporting the standard library functions on the top-level of squin. This is for usability, so the user can just write e.g. `squin.x(q[0])`, which calls the `stdlib.simple.x` method. Similarly, you can call `squin.broadcast.x(q)`. The only downside of this, IMO, is that things might be a bit confusing when we backport this. But we can also remove the export and add it back later when we are doing the breaking refactor. * There are a few statements, which I'm not sure we need, so I skipped them for now. Once we settle on which statements should be added, I'll add the rest as stdlib functions. The statements are: * `Shift` * `U3` * `Rot` - this one is actually part of the native dialect, but I'm not sure we need it in clifford, since I already added `Rx` and `Ry`. @weinbe58 what do you think? **Edit**: The way I export stuff here is somewhat related to QuEraComputing/bloqade#287. As @Roger-luo suggests there, we could also move the stdlib here to `gate`, but that is breaking since e.g. `gate.x` is already taken as of now.
This PR implements the native dialect group. In this dialect group we compose with
qubitandgateswheregatesonly has Neutral atom specific gate operations. Semanticaly these operators permit explicit parallelism at the statement level, e.g. all qubit arguments areIListType[QubitType, Any]and all rotation angles are a single value.Along with the dialect groups there is a standard library of some common gates implemented with this dialect group. There are versions of the gate library
bloqade.native.stdlibhas functions with single qubits as arguments and then there is another librarybloqade.native.stdlib.broadcastwhere those arguments are broadcasted like the statements.NOTE: there is no analysis methods required here because all statements have no return value.