qilisdk.readout.readout_spec
Classes
Type-safe specification of which readout methods to apply during execution. |
Module Contents
- class Readout[font]
Bases:
Generic[qilisdk.readout.readout_result.S,qilisdk.readout.readout_result.E,qilisdk.readout.readout_result.T]Type-safe specification of which readout methods to apply during execution.
Readoutis the primary interface for declaring what information to extract from the quantum backend after execution. Build a specification by chainingwith_*builder methods, then pass it toexecute().Each
with_*method returns a newReadoutwhose type parameters encode which readout slots are populated, allowing the type checker to verify result access at compile time. The original instance is not mutated.- Type parameters:
- S:
SamplingReadoutResultwhenwith_sampling()was called,None otherwise.
- E:
ExpectationReadoutResultwhenwith_expectation()was called, Noneotherwise.- T:
StateTomographyReadoutResultwhenwith_state_tomography()was called,
Noneotherwise.
- S:
Exemples
Sampling — measure in the computational basis and collect bitstring counts:
spec = Readout().with_sampling(nshots=1000) result = backend.execute(functional, readout=spec) counts = result.samples # dict[str, int] probs = result.probabilities # dict[str, float]Expectation values — compute
<psi|O|psi>for one or more observables:from qilisdk.analog import Z spec = Readout().with_expectation(observables=[Z(0)], nshots=0) result = backend.execute(functional, readout=spec) ev = result.expectation_values # list[float], one entry per observableState tomography — retrieve the full quantum state vector after execution:
spec = Readout().with_state_tomography() result = backend.execute(functional, readout=spec) state = result.state # QTensorMultiple readout types can be combined in a single specification:
from qilisdk.analog import Z spec = Readout().with_sampling(nshots=500).with_expectation(observables=[Z(0)]) result = backend.execute(functional, readout=spec) counts = result.samples # dict[str, int] ev = result.expectation_values # list[float]- with_sampling(nshots: int = 1000, expand_samples: bool = True) Readout[qilisdk.readout.readout_result.SamplingReadoutResult, qilisdk.readout.readout_result.E, qilisdk.readout.readout_result.T][font]
Add a sampling readout to the specification.
If expand_samples is True, partial samples will be displayed with underscores for better readability. For example, «00_0» instead of «000» for a 4-qubit system where the third qubit’s state is not measured. Setting this to false can cause ambiguity, especially if you have a variety of mid-circuit measurements.
- with_expectation(observables: list[qilisdk.analog.Hamiltonian | qilisdk.core.QTensor], nshots: int = 0) Readout[qilisdk.readout.readout_result.S, qilisdk.readout.readout_result.ExpectationReadoutResult, qilisdk.readout.readout_result.T][font]
Add an expectation-value readout to the specification.
- Paràmetres:
observables (
list[Hamiltonian | QTensor]) – Observables whose expectation values will be evaluated.nshots (
int) – Number of measurement shots. Use0for exact (state-vector-based) evaluation.
- Retorna:
A new
Readoutwith the expectation slot populated.- Llença:
ValueError – If an expectation readout was already set.
- with_state_tomography(method: Literal['exact'] = 'exact') Readout[qilisdk.readout.readout_result.S, qilisdk.readout.readout_result.E, qilisdk.readout.readout_result.StateTomographyReadoutResult][font]
Add a state-tomography readout to the specification.
- Paràmetres:
method (
Literal) – Tomography method identifier. Currently only “exact” is supported.- Retorna:
A new
Readoutwith the state-tomography slot populated.- Llença:
ValueError – If a state-tomography readout was already set.
- property sampling: qilisdk.readout.readout.SamplingReadout | None[font]
The sampling readout, or
Noneif not set.
- property expectation: qilisdk.readout.readout.ExpectationReadout | None[font]
The expectation-value readout, or
Noneif not set.
- property state_tomography: qilisdk.readout.readout.StateTomographyReadout | None[font]
The state-tomography readout, or
Noneif not set.
- to_list() list[qilisdk.readout.readout.ReadoutMethod][font]
Return the readout methods as a flat list.
Useful for backward compatibility with APIs that accept
list[ReadoutMethod].