Skip to content

[open-systems] Phased classical simulation #1590

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 55 commits into from
May 13, 2025

Conversation

mpharrigan
Copy link
Collaborator

@mpharrigan mpharrigan commented Mar 10, 2025

This pull request is the second in a series for supporting open system (classical data & measurement), roadmap item #445.

This branch is based on #1584

Bloq.basis_state_phase

This new method can be overridden for phased-classical gates. In this PR, I show how CZ can support this new method. This leaves the basis states alone but applies a phase when 11 is encountered.

PhasedClassicalSimState(ClassicalSimState)

I refactored the classical simulator into a (mutable) class with initialization .from_cbloq(...), binst-by-binst stepping .step(), and finalization .finalize(). These can be combined with .simulate(), which is the new backend for the familiar entry points Bloq.call_classically(...) and friends.

Doing ordinary classical simulation will raise an error if it encounters a bloq with a non-trivial phase. The phased classical simulator will raise an error if it encounters a bloq without classical action; otherwise it will propagate phase. If a bloq does not specifically annotate a phase (but does indeed have classical action), the trivial +1 phase is assumed.

Non-changes (yet)

This PR does not directly support any "open systems" things. The ultimate goal is to support fuzz-testing measurement-based uncomputation. Since MBUC involves tracking phases, this PR is a necessary but not sufficient pre-requisite.

Related

@mpharrigan mpharrigan changed the title [open systems] Phased classical simulation [open-systems] Phased classical simulation Mar 11, 2025
@mpharrigan mpharrigan marked this pull request as ready for review April 9, 2025 22:39
@mpharrigan mpharrigan requested a review from tanujkhattar April 9, 2025 22:39
@mpharrigan mpharrigan merged commit 7b5c8d5 into quantumlib:main May 13, 2025
8 checks passed
wjhuggins pushed a commit to wjhuggins/Qualtran that referenced this pull request May 31, 2025
This pull request is the second in a series for supporting open system
(classical data & measurement), roadmap item
quantumlib#445.

~~This branch is based on quantumlib#1584~~

## `Bloq.basis_state_phase`

This new method can be overridden for phased-classical gates. In this
PR, I show how `CZ` can support this new method. This leaves the basis
states alone but applies a phase when `11` is encountered.

## `PhasedClassicalSimState(ClassicalSimState)`

I refactored the classical simulator into a (mutable) class with
initialization `.from_cbloq(...)`, binst-by-binst stepping `.step()`,
and finalization `.finalize()`. These can be combined with
`.simulate()`, which is the new backend for the familiar entry points
`Bloq.call_classically(...)` and friends.

Doing ordinary classical simulation will raise an error if it encounters
a bloq with a non-trivial phase. The phased classical simulator will
raise an error if it encounters a bloq without classical action;
otherwise it will propagate phase. If a bloq does not specifically
annotate a phase (but does indeed have classical action), the trivial +1
phase is assumed.

## Non-changes (yet)

This PR does not directly support any "open systems" things. The
ultimate goal is to support fuzz-testing measurement-based
uncomputation. Since MBUC involves tracking phases, this PR is a
necessary but not sufficient pre-requisite.

## Related

 - This PR unblocks quantumlib#1527 
 - quantumlib#1499 easier to test
- https://arxiv.org/abs/2105.13410 has a ton of cool circuit
constructions that can be tested with this
@mpharrigan mpharrigan deleted the 2025-03/classical-sim-1 branch June 11, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants