Reference: Async Read¶
AsyncReadResult Class¶
psiqworkbench.AsyncReadResult ¶
AsyncReadResult(qc, start_flag=None, bitflags=None, read_mask=None, qint=None, target_xor=0, resolved_value=None, warning_str=None, held_ops=None, fallback_read=None)
AsyncReadResult is the type returned by qc.read_async() and qc.ppm_async().
It provides a "flag" which has not been evaluated.
WITHOUT read_async(), you'd normally do things like this:
Synchronous (stalled) reading:
result = myqubit.read()
if result:
do_something()
if myqubit.read():
do_something()
r1 = myq1.read()
r2 = myq2.read()
r3 = myq3.read()
if r1 and r2 and not r3:
do_something()
To use measurements without stalling, we can treat measured qubits as classical conditions:
This works, but it's not very flexible and has a few catches. The biggest problem is that if the "condition" qubit is re-used for something else you can no longer use it as a condition.
WITH read_async() you have more options:
-
Call
.resolve(), which is the simplest and slowest way to get the result. This causes the program to stall until the QPU has performed the corresponding measurement and can return the result. -
Leave the flag unresolved, and use it in a
withblock instead of anif. This avoids stalling the pipe; any QPU ops inside thewithblock will be marked with the flag so they only execute if the flag resolves as true. -
Attach the flag to QPU instructions. While it's not as nice syntactically, the flag can be attached to QPU instructions, so they'll only execute if that measurement resolves as true.
In all of these cases, the dependent QPU ops are allowed to be issued (or not issued) in a deferred manner, without causing stalls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
qc
|
QPU
|
The QPU instance associated with this result. |
required |
start_flag
|
int
|
The starting flag index for this result. |
None
|
bitflags
|
list
|
A list of bitflags associated with this result. |
None
|
read_mask
|
int
|
A mask identifying which qubits are read. |
None
|
qint
|
Qubits
|
The quantum integer involved in this result. |
None
|
target_xor
|
int
|
XOR values for the result's target. |
0
|
resolved_value
|
int
|
The resolved value of this result, if known. |
None
|
warning_str
|
str
|
A warning message associated with this result. |
None
|
held_ops
|
list
|
A list of held operations for deferred execution. |
None
|
resolve ¶
Stall until this result has been resolved, and cache the result. If force is True, re-resolve instead of using the cached result.