POVMPostProcessor¶
- class POVMPostProcessor(povm_sample, dual=None, *, combine_counts=False)¶
Bases:
object
The canonical POVM result post-processor.
This post-processor implementation provides a straight-forward interface for computing the expectation values (and standard deviations) of any Pauli-based observable. It is initialized with a
POVMPubResult
as shown below:>>> from povm_toolbox.library import ClassicalShadows >>> from povm_toolbox.sampler import POVMSampler >>> from povm_toolbox.post_processor import POVMPostProcessor >>> from qiskit.circuit import QuantumCircuit >>> from qiskit.primitives import StatevectorSampler >>> from qiskit.quantum_info import SparsePauliOp >>> from numpy.random import default_rng >>> circ = QuantumCircuit(2) >>> _ = circ.h(0) >>> _ = circ.cx(0, 1) >>> povm = ClassicalShadows(2, seed=42) >>> sampler = StatevectorSampler(seed=default_rng(42)) >>> povm_sampler = POVMSampler(sampler) >>> job = povm_sampler.run([circ], povm=povm, shots=16) >>> result = job.result() >>> post_processor = POVMPostProcessor(result[0]) >>> post_processor.get_expectation_value(SparsePauliOp("ZI")) (-2.7755575615628914e-17, 0.3872983346207416)
Additionally, this post-processor also supports the customization of the Dual frame in which the decomposition weights of the provided observable are obtained. Check out this how-to guide for more details on how to do this.
Initialize the POVM post-processor.
- Parameters:
povm_sample (POVMPubResult) – a result from a POVM sampler run.
dual (BaseDual | None) – the Dual frame that will be used to obtain the decomposition weights of an observable when computing its expectation value. For more details, refer to
get_decomposition_weights()
. When this isNone
, the standard “state-average” Dual frame will be constructed from the POVM stored in thepovm_sample
’sPOVMPubResult.metadata
.combine_counts (bool) – indicates whether to combine the counts associated with different parameter sets that were submitted in a single
POVMSamplerPub
. By default, the counts are not combined. Refer to this how-to guide for more information.
- Raises:
ValueError – If the provided
dual
is not a dual frame to the POVM stored in thepovm_samples
’sPOVMPubResult.metadata
.
Attributes
- counts¶
Return the histogram of the POVM outcomes via
POVMPubResult.get_counts()
.
- dual¶
Return the Dual frame that is used.
Warning
If the dual frame is not already built, accessing this property could be computationally demanding.
- povm¶
Return the POVM definition that was used to sample outcomes.
Methods
- get_decomposition_weights(observable, outcome_set)¶
Get the decomposition weights of
observable
into the elements ofpovm
.Given an observable
which is in the span of a POVM (here,povm
), one can write as the weighted sum of the POVM effects, for real weights and where labels the outcomes.See also
BaseDual.get_omegas()
.- Parameters:
observable (SparsePauliOp) – the observable to be decomposed into the POVM effects.
outcome_set (set[Any]) – set of outcome labels indicating which decomposition weights are queried. An outcome of a
ProductPOVM
is labeled by a tuple of integers for instance. For aMultiQubitPOVM
, an outcome is simply labeled by an integer.
- Returns:
A dictionary mapping outcome labels to decomposition weights.
- Return type:
- get_expectation_value(observable, *, loc=None)¶
Return the expectation value and standard deviation of the given
observable
.- Parameters:
observable (SparsePauliOp) – the observable whose expectation value is queried.
loc (int | tuple[int, ...] | None) – this argument is relevant if multiple sets of parameter values were supplied to the sampler in the same
POVMSamplerPub
. The indexloc
then corresponds to the set of parameter values that was supplied to the sampler through the Pub. IfNone
, the expectation value (and standard deviation) for each set of circuit parameters is returned.
- Returns:
A tuple of (estimated) expectation value(s) and standard deviation(s). If a single value was queried (via
loc
), both of these will be afloat
. Otherwise, they will be instances ofnumpy.ndarray
.- Return type:
- get_state_snapshot(outcome)¶
Return the snapshot of the state associated with
outcome
.- Parameters:
outcome (tuple[int, ...]) – the label specifying the snapshot. The outcome is a tuple of integers (one index per local frame).
- Returns:
The snapshot associated with
outcome
. The snapshot is a product operator, which is returned as a dictionary mapping the subsystems of the Hilbert space (e.g. qubits) to the corresponding local operators forming the product operator.- Raises:
NotImplementedError – if the dual frame associated with the post-processor is not product.
- Return type: