iqm.qiskit_iqm.qiskit_to_iqm.MeasurementKey#
- class iqm.qiskit_iqm.qiskit_to_iqm.MeasurementKey(creg_name: str, creg_len: int, creg_idx: int, clbit_idx: int)#
Bases:
object
Unique key associated with a measurement instruction.
Qiskit stores the results of quantum measurements in classical registers consisting of bits. The circuit execution results are presented as bitstrings of a certain structure so that the classical register and the index within that register for each bit is implied from its position in the bitstring.
For example, if you have two classical registers in the circuit with lengths 3 and 2, then the measurement results will look like ‘01 101’ if the classical register of length 3 was added to the circuit first, and ‘101 01’ otherwise. If a bit in a classical register is not used in any measurement operation it will still show up in the results with the default value of ‘0’.
To be able to handle measurement results in a Qiskit-friendly way, we need to keep around some information about how the circuit was constructed. This can, for example, be achieved by keeping around the original Qiskit quantum circuit and using it when constructing the results in
IQMJob
. This should be done so that the circuit is saved on the server side and not inIQMJob
, since otherwise users will not be able to retrieve results from a detached Python environment solely based on the job id. Another option is to use measurement key strings to store the required info. Qiskit does not use measurement keys, so we are free to use them internally in the communication with the IQM server, and can encode the necessary information in them.This class encapsulates the necessary info, and provides methods to transform between this representation and the measurement key string representation.
- Parameters:
creg_name (str) – name of the classical register
creg_len (int) – number of bits in the classical register
creg_idx (int) – Index of the classical register in the circuit. Determines the order in which this register was added to the circuit relative to the others.
clbit_idx (int) – index of the classical bit within the classical register
Attributes
creg_name
creg_len
creg_idx
clbit_idx
Methods
__delattr__
(name)Implement delattr(self, name).
__eq__
(other)Return self==value.
__hash__
()Return hash(self).
__repr__
()Return repr(self).
__setattr__
(name, value)Implement setattr(self, name, value).
__str__
()Return str(self).
from_clbit
(clbit, circuit)Create a MeasurementKey for a classical bit in a quantum circuit.
from_string
(string)Create a MeasurementKey from its string representation.
- classmethod from_string(string: str) MeasurementKey #
Create a MeasurementKey from its string representation.
- Parameters:
string (str) –
- Return type:
- classmethod from_clbit(clbit: Clbit, circuit: QuantumCircuit) MeasurementKey #
Create a MeasurementKey for a classical bit in a quantum circuit.
- Parameters:
clbit (Clbit) –
circuit (QuantumCircuit) –
- Return type: