Skip to content

Conversation

@johnzl-777
Copy link
Contributor

This brings in SetDetector and SetObservable into bloqade-circuit. Historically this was the physical dialect in another project but I've gone ahead and renamed it annotate.

@johnzl-777 johnzl-777 linked an issue Nov 6, 2025 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Nov 6, 2025

Codecov Report

❌ Patch coverage is 97.74436% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/bloqade/stim/rewrite/set_detector_to_stim.py 92.68% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
10021 8822 88% 0% 🟢

New Files

File Coverage Status
src/bloqade/annotate/_init_.py 100% 🟢
src/bloqade/annotate/_dialect.py 100% 🟢
src/bloqade/annotate/_interface.py 100% 🟢
src/bloqade/annotate/stmts.py 100% 🟢
src/bloqade/annotate/types.py 100% 🟢
src/bloqade/stim/rewrite/get_record_util.py 100% 🟢
src/bloqade/stim/rewrite/set_detector_to_stim.py 93% 🟢
src/bloqade/stim/rewrite/set_observable_to_stim.py 100% 🟢
TOTAL 99% 🟢

Modified Files

File Coverage Status
src/bloqade/analysis/measure_id/impls.py 96% 🟢
src/bloqade/squin/_init_.py 100% 🟢
src/bloqade/squin/groups.py 100% 🟢
src/bloqade/stim/passes/squin_to_stim.py 100% 🟢
src/bloqade/stim/rewrite/_init_.py 100% 🟢
TOTAL 99% 🟢

updated for commit: b46eda9 by action🐍

@johnzl-777 johnzl-777 marked this pull request as ready for review November 6, 2025 20:09
Copy link
Collaborator

@david-pl david-pl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, just one comment regarding the type.

On a high-level though: since you are making this part of the squin dialect group, what should the behavior here be when running any other interpreter / emit, such as PyQrack or cirq codegen? Is this just expected to error?

Or, even more generally: do we expect all statements in a dialect group to be supported by all interpreters we have for that dialect group?

@statement(dialect=dialect)
class SetDetector(ConsumesMeasurementResults):
coordinates: ir.SSAValue = info.argument(
type=kirin_types.Tuple[kirin_types.Int | kirin_types.Float]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be an IList? Is the length here known?

Judging from the tests, this could be IListType[types.Float, types.Literal(2)].

Do we need to support Int here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this type is wrong.

  1. tuple[int] means it only have one element....
  2. I think the intention here is the concern of sometimes ppl do: (0, 3.2, 5) but I think we should actually not allow it moving forward (error when validate in the future)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think kirin's Tuple type actually aliases to a vararg tuple.
  2. I agree, so then this type should be changed to ilist.

Copy link
Contributor

@kaihsin kaihsin Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, so the right way to hint it (if you really want to use tuple) is:
types.Tuple[types.Float, ...] which is equivalent to types.Tuple[types.Vararg(types.Float)]

Also, for 2. we can discuss if we want that UX. I don't have strong opinion on that.

Copy link
Contributor Author

@johnzl-777 johnzl-777 Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaihsin why do we want to prohibit variable length tuple for the coordinates? My understanding is they just exist to make visualization easier, it doesn't affect any functionality.

Judging from the tests, this could be IListType[types.Float, types.Literal(2)].

@david-pl I think the only reason I cooked up tests with two integer coordinates is because I don't think I've ever seen a 3D coordinate used. That being said, I imagine there must be more complicated codes where this would be desirable

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaihsin's point with the tuple length was that ´Tuple[Int]´ indicates a tuple with only a single element. So the correct typing for variable length here would be ´Tuple[Int, ...]´.

I see, then disregard the comment on the length.

@johnzl-777
Copy link
Contributor Author

On a high-level though: since you are making this part of the squin dialect group, what should the behavior here be when running any other interpreter / emit, such as PyQrack or cirq codegen? Is this just expected to error?

I'll admit the current structure was inspired by @rafaelha 's proposal, I'm completely open to creating a separate kernel/group similar to what annotate used to come from, which was literally physical union squin.

I agree it's not great to have set up the expectation squin works with all these backends and potentially break it by introducing a new dialect. That being said, I assume that if a user is using annotate they aren't really gunning to simulate it on the existing pyqrack/cirq backends?

@david-pl
Copy link
Collaborator

david-pl commented Nov 7, 2025

That being said, I assume that if a user is using annotate they aren't really gunning to simulate it on the existing pyqrack/cirq backends?

Yeah, that's why I'm also not sure here. So I don't have any strong opinion here. I suppose the error you get (something like Method not found for statement ...) should be informative enough to figure out what's wrong.

@johnzl-777 johnzl-777 merged commit 94505d5 into main Nov 7, 2025
11 checks passed
@johnzl-777 johnzl-777 deleted the john/port-annotate-dialect branch November 7, 2025 15:00
@cduck
Copy link
Contributor

cduck commented Nov 7, 2025

On a high-level though: since you are making this part of the squin dialect group, what should the behavior here be when running any other interpreter / emit, such as PyQrack or cirq codegen? Is this just expected to error?

Luckly, set_detector and observable have no effect on the quantum circuit (they just annotate expected error-free outputs and requested logical results of the circuit). So PyQrack and cirq can safely ignore these instructions.

If you really want to, you can compute the requested set_detector and observable XORs of the measurement results and provide these as additional simulator output but the user could just as easily use stim to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC: Migrating physical dialect to bloqade-circuit

5 participants