POVMImplementation

The interface for “ready-to-go” POVM implementations.

class MetadataT

The metadata type variable bound to POVMMetadata.

alias of TypeVar(‘MetadataT’, bound=POVMMetadata)

class POVMImplementation(num_qubits: int, *, measurement_layout: list[int] | None = None, insert_barriers: bool = False)[source]

The abstract base interface for all POVM implementations in this library.

Since this is an abstract class, an end-user will not actually create an instance of it at runtime. Instead, you should look at the various concrete implementations of this interface documented in library.

Initialize the POVMImplementation.

Parameters:
  • num_qubits (int) – number of logical qubits in the system.

  • measurement_layout (list[int] | None) – optional list of indices specifying on which qubits the POVM acts. See measurement_layout for more details.

  • insert_barriers (bool) – whether to insert a barrier between the composed circuits. This is not done by default but can prove useful when visualizing the composed circuit.

classical_register_name: str = 'povm_measurement_creg'

The name given to the classical bit register in which the POVM outcomes are stored.

The DataBin container result object will have an attribute with this name, which will contain the raw measurement data.

num_qubits: int

The number of logical qubits in the system.

measurement_layout: list[int] | None

An optional list of indices specifying on which qubits the POVM acts.

If None, two cases can be distinguished:

  1. if a circuit supplied to the compose_circuits() has been transpiled, its final transpile layout will be used as default value,

  2. otherwise, a simple one-to-one layout list(range(num_qubits)) is used.

insert_barriers: bool

Whether to insert a barrier between the original circuit and the measurement circuit produced by this POVM implementation.

measurement_circuit: QuantumCircuit

The QuantumCircuit actually implementing this POVM’s measurement.

abstract definition() BasePOVM[source]

Return the corresponding quantum-informational POVM representation.

Return type:

BasePOVM

abstract to_sampler_pub(circuit: QuantumCircuit, circuit_binding: BindingsArray, shots: int, *, pass_manager: StagedPassManager | None = None) tuple[SamplerPub, MetadataT][source]

Append the measurement circuit(s) to the supplied circuit.

This method takes a supplied circuit and appends the measurement circuit(s) to it. If the measurement circuit is parametrized, its parameters values should be concatenated with the parameter values associated with the supplied quantum circuit.

Parameters:
  • circuit (QuantumCircuit) – A quantum circuit.

  • circuit_binding (BindingsArray) – A bindings array.

  • shots (int) – A specific number of shots to run with.

  • pass_manager (StagedPassManager | None) – An optional transpilation pass manager. After the supplied circuit has been composed with the measurement circuit, the pass manager will be used to transpile the composed circuit.

Returns:

A tuple of a sampler pub and a dictionary of metadata which includes the POVMImplementation object itself. The metadata should contain all the information necessary to extract the POVM outcomes out of raw bitstrings.

Return type:

tuple[SamplerPub, MetadataT]

compose_circuits(circuit: QuantumCircuit) QuantumCircuit[source]

Compose the circuit to sample from, with the measurement circuit.

If the measurement circuit requires some ancilla qubits, this method will inspect the input circuit. If the input circuit has some idling qubits available, they will be used as ancilla measurement qubits. If not enough idling qubits are available, this method will add the necessary number of qubits to the input circuit before composing it with the measurement circuit.

Parameters:

circuit (QuantumCircuit) – The quantum circuit to be sampled from.

Raises:
  • ValueError – if the number of qubits specified by self.measurement_layout does not match the number of qubits on which this POVM implementation acts.

  • CircuitError – if an error has occurred when adding the classic register, used to save POVM results, to the input circuit.

Returns:

The composition of the supplied quantum circuit with the measurement_circuit of this POVM implementation.

Return type:

QuantumCircuit

abstract reshape_data_bin(data: DataBin) DataBin[source]

Reshapes the provided data.

This method should reshape the provided data to the output dimensions expected by the end-user. That is, the dimensions should match those of the qiskit.primitives.SamplerPubLike object provided by the user when submitting their primitive job.

Parameters:

data (DataBin) – The raw primitive result data still shaped according to the internally submitted POVMSamplerJob.

Returns:

A new data structure of the correct shape.

Return type:

DataBin

get_povm_counts_from_raw(data: DataBin, povm_metadata: MetadataT, *, loc: int | tuple[int, ...] | None = None) ndarray | Counter[source]

Get the POVM counts.

Parameters:
  • data (DataBin) – The raw sampled data.

  • povm_metadata (MetadataT) – The associated metadata.

  • loc (int | tuple[int, ...] | None) – an optional location to slice the bitstrings.

Returns:

The POVM counts.

Return type:

ndarray | Counter

get_povm_outcomes_from_raw(data: DataBin, povm_metadata: MetadataT, *, loc: int | tuple[int, ...] | None = None) ndarray | list[tuple[int, ...]][source]

Get the POVM bitstrings.

Parameters:
  • data (DataBin) – The raw sampled data.

  • povm_metadata (MetadataT) – The associated metadata.

  • loc (int | tuple[int, ...] | None) – an optional location to slice the bitstrings.

Returns:

The POVM bitstrings.

Return type:

ndarray | list[tuple[int, …]]