-
Notifications
You must be signed in to change notification settings - Fork 74
[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
mpharrigan
merged 55 commits into
quantumlib:main
from
mpharrigan:2025-03/classical-sim-1
May 13, 2025
Merged
[open-systems] Phased classical simulation #1590
mpharrigan
merged 55 commits into
quantumlib:main
from
mpharrigan:2025-03/classical-sim-1
May 13, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NoureldinYosri
approved these changes
May 7, 2025
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
added a commit
that referenced
this pull request
Jul 14, 2025
This pull request is the third in a series for supporting open system (classical data & measurement), roadmap item #445. ~~This branch is based on #1590 (for my convenience; it doesn't use any of that functionality)~~ ## `Bloq.tensor_contract(superoperator=True)` This is the new interface. It will return a 0-, 2-, or 4-dimensional tensor for constants, density matrices, and superoperators (resp) to support simulating programs with measurements and non-unitary maps. Read the docs for the indexing convention for the superoperator; but if you're really doing something with the superoperators you may want to operate on the quimb tensor network with friendly indices itself. ## `cbloq_to_superquimb` The workhorse of the new functionality is this function that converts a composite bloq to a tensor network that represents the density matrix and/or superoperator of the program. Some operations like measurement or discarding qubits cannot be represented in a pure-state statevector / unitary picture. `cbloq_to_superquimb` still uses `Bloq.my_tensors` to construct the network. It adds each tensor twice: once in the "forward" direction and again in the "backward" (adjoint) direction. ## `DiscardInd` The `Bloq.my_tensors` method can now return a `DiscardInd` object, which signifies that that tensor index should be discarded by tracing it out. It turns out that this simple extension lets you represent any CPTP map using the "system+environment" modeling approach. ## `MeasZ`, `Discard` This PR includes two non-unitary maps: measuring in the Z basis and discarding a qubit or classical bit. ## Manipulating quimb tensor networks This PR makes some changes to the way we handle outer indices in the quimb tensor network. This should only be of interest to folks who use the "hands on" approach of directly manipulating the tensor networks. The changes make sense and clean up some of the docs. The outer indices are now re-mapped to tuples of qualtran objects that actually make sense rather than keeping them as `Connection`s to `DanglingT` objects. There is a new flag `friendly_indices=True` which will make the outer indices friendly strings. **breaking change** I renamed and made-private the `get_left_and_right_inds` function. The original idea was to use this as a public way of getting a handle on the outer indices, but it was always tricky to use; and needed to be changed to support the new variety of outer indices present in the superoperator networks. No one should need a replacement for this function since the `qtn.TensorNetwork` object outer indices now just intrinsically make sense. ## Non-changes This includes the minimal set of non-unitary CPTP bloqs to support the docs notebooks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request is the second in a series for supporting open system (classical data & measurement), roadmap item #445.
This branch is based on #1584Bloq.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 when11
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 pointsBloq.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
on_classical_vals
forCSwapApprox
? #1527