POVMSampler¶
- class POVMSampler(sampler: BaseSamplerV2)[source]¶
Bases:
object
A
BaseSamplerV2
-compatible interface for sampling POVMs.This class does not implement the Sampler primitive interface as a subclass but rather takes an existing instance of a Sampler primitive as its input. In this way, it is trivial for the end-user to switch between simulated or hardware-executed POVM sampling jobs.
Here is a simple example to get you started:
>>> from povm_toolbox.library import ClassicalShadows >>> from povm_toolbox.sampler import POVMSampler >>> from qiskit.circuit import QuantumCircuit >>> from qiskit.primitives import StatevectorSampler >>> circ = QuantumCircuit(2) >>> _ = circ.h(0) >>> _ = circ.cx(0, 1) >>> povm = ClassicalShadows(2, seed=42) >>> sampler = StatevectorSampler(seed=42) >>> povm_sampler = POVMSampler(sampler) >>> job = povm_sampler.run([circ], povm=povm, shots=16) >>> result = job.result()
Now, if you want to execute your experiments on real hardware, you can simply replace the
StatevectorSampler
above by aSamplerV2
:from qiskit_ibm_runtime import SamplerV2 sampler = SamplerV2(...)
Initialize the POVM Sampler.
- Parameters:
sampler (BaseSamplerV2) – the
BaseSamplerV2
that is used to collect the POVM samples.
Attributes
- sampler¶
The
BaseSamplerV2
that is used to collect the POVM samples.
Methods
- run(pubs: Iterable[povm_toolbox.sampler.POVMSamplerPubLike], *, shots: int | None = None, povm: POVMImplementation | None = None, pass_manager: StagedPassManager | None = None) POVMSamplerJob [source]¶
Run and collect samples from each pub.
- Parameters:
pubs (Iterable[povm_toolbox.sampler.POVMSamplerPubLike]) – An iterable of
POVMSamplerPubLike
objects. For example, a list of circuits or tuples(circuit, parameter_values, shots, povm)
.shots (int | None) – The total number of shots to sample for each pub that does not specify its own shots. If
None
, the default number of shots of thesampler
is used.povm (POVMImplementation | None) – A POVM implementation to sample from for each pub that does not specify it own POVM. If
None
, each pub has to specify its own POVM.pass_manager (StagedPassManager | None) – An optional transpilation pass manager. For each pub, after its circuit has been composed with the measurement circuit, the pass manager will be used to transpile the composed circuit.
- Returns:
The POVM sampler job object.
- Return type: