DilationMeasurements

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

Bases: POVMImplementation[POVMMetadata]

A measurement leveraging Naimark’s dilation theorem.

IC dilation measurements are defined on a space spanning (at least) four states: e.g. \(\{ |0\rangle,|1\rangle,|2\rangle,|3\rangle\}\). To achieve such a measurement using qubits, every qubit gets paired with an ancilla qubit. Then, the dilation measurement can be constructed via some two-qubit unitary followed by measurements in the computational basis. The binary outcomes \(\{|00\rangle,|01\rangle,|10\rangle,|11\rangle\}\) can then be mapped to the four states above.

There are 8 degrees of freedom in the two-qubit unitary specifying the dilation measurement (for each qubit). Different parametrizations of the unitaries are possible. Here, we use the same parametrization of the dilation POVM as the one presented in the work of G. García-Pérez, M. A. Rossi, B. Sokolov, F. Tacchino, P. K. Barkoutsos, G. Mazzola, I. Tavernelli, and S. Maniscalco, “Learning to measure: adaptive informationally complete generalized measurements for quantum algorithms”, PRX Quantum 2, Publisher: American Physical Society, 040342 (2021). Refer to this work for a detailed explanation of the parametrization.

Note

An additional ancilla qubit is required for each qubit in the system to be measured. Depending on the qubit connectivity the coupling of the measured qubit with its ancilla can introduce a significant overhead of SWAP gates.

The example below shows how you construct a dilation POVM. It plots a visual representation of the POVM’s definition to exemplify the different effects’ directions.

>>> import numpy as np
>>> from povm_toolbox.library import DilationMeasurements
>>> povm = DilationMeasurements(
...     1,
...     parameters=np.array(
...         [0.75, 0.30408673, 0.375, 0.40678524, 0.32509973, 0.25000035, 0.49999321, 0.83333313]
...     ),
... )
>>> print(povm)
DilationMeasurements(num_qubits=1, parameters=array([[0.75      , 0.30408673, 0.375     , 0.40678524, 0.32509973,
        0.25000035, 0.49999321, 0.83333313]]))
>>> povm.definition().draw_bloch()
<Figure size 500x500 with 1 Axes>

(Source code, png, hires.png, pdf)

../_images/povm_toolbox-library-DilationMeasurements-1.png

Initialize a dilation POVM.

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

  • parameters (np.ndarray) – can be either 1D or 2D. If 1D, it should be of length 8 and contain float values that specify the parametrization of the dilation POVM. If 2D, it will have a new set of parameters for each qubit. The 8 values fix all the degrees of freedom.

  • 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.

Raises:
  • ValueError – if the last dimension of parameters is not of length 8.

  • ValueError – if the shape of parameters is not valid.

Attributes

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.

Inherited Attributes

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.

Methods

definition() ProductPOVM[source]

Return the corresponding quantum-informational POVM representation.

Return type:

ProductPOVM

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

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

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

This method takes a supplied circuit and appends the measurement circuit to it. An ancilla qubit is required for each qubit that we want to measure (specified by measurement_layout). If the input circuit has one or more idling qubit(s), they will be used as measurement ancilla qubits. If more ancilla qubits are needed, those will be added to the input circuit (therefore increasing its size).

Warning

The number of qubits in the input circuit may be increased due to the ancilla qubits required for dilatation measurements.

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, POVMMetadata]

Inherited Methods

compose_circuits(circuit: QuantumCircuit) QuantumCircuit

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

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

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, ...]]

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, …]]