Skip to content

Conversation

@weinbe58
Copy link
Member

@weinbe58 weinbe58 commented Sep 19, 2025

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.

@weinbe58 weinbe58 linked an issue Sep 19, 2025 that may be closed by this pull request
3 tasks
@codecov
Copy link

codecov bot commented Sep 19, 2025

Codecov Report

❌ Patch coverage is 78.26087% with 50 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/bloqade/native/stdlib/broadcast.py 62.02% 30 Missing ⚠️
src/bloqade/native/stdlib/simple.py 68.75% 20 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Contributor

github-actions bot commented Sep 19, 2025

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
10607 9313 88% 0% 🟢

New Files

File Coverage Status
src/bloqade/native/_init_.py 100% 🟢
src/bloqade/native/_prelude.py 100% 🟢
src/bloqade/native/dialects/_init_.py 100% 🟢
src/bloqade/native/dialects/gates/_init_.py 100% 🟢
src/bloqade/native/dialects/gates/_dialect.py 100% 🟢
src/bloqade/native/dialects/gates/_interface.py 100% 🟢
src/bloqade/native/dialects/gates/stmts.py 100% 🟢
src/bloqade/native/stdlib/_init_.py 100% 🟢
src/bloqade/native/stdlib/broadcast.py 62% 🟢
src/bloqade/native/stdlib/simple.py 69% 🟢
src/bloqade/pyqrack/native.py 100% 🟢
TOTAL 94% 🟢

Modified Files

File Coverage Status
src/bloqade/pyqrack/_init_.py 100% 🟢
TOTAL 100% 🟢

updated for commit: 0402998 by action🐍

@weinbe58 weinbe58 marked this pull request as draft September 19, 2025 17:53
@weinbe58 weinbe58 requested a review from Copilot September 19, 2025 19:20
Copy link
Contributor

Copilot AI left a 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 weinbe58 added rfc Request for Comments backport 0.7 labels Sep 20, 2025
@david-pl
Copy link
Collaborator

@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 native. Since we want to sort of "hide" the wrappers anyway, I think that's fine. And from a user perspective you'd be able to write

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.broadcast

I'd also do the same in squin, so users can then just write squin.x(q[0]) etc.

@weinbe58 weinbe58 requested a review from david-pl September 23, 2025 13:37
@weinbe58 weinbe58 marked this pull request as ready for review September 23, 2025 13:37
@weinbe58 weinbe58 merged commit 3d23367 into main Sep 25, 2025
10 of 11 checks passed
@weinbe58 weinbe58 deleted the phil/493-native-dialect-and-its-stdlib-that-contains-only-our-native-gates branch September 25, 2025 14:40
weinbe58 added a commit that referenced this pull request Sep 25, 2025
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.
david-pl added a commit that referenced this pull request Sep 29, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 0.7 rfc Request for Comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

native dialect and its stdlib that contains only our native gates

3 participants