class MockIQExperimentHelper(iq_cluster_centers=None, iq_cluster_width=None)[source]#

Abstract class for the MockIQ helper classes.

Different tests will use experiment specific helper classes which define the pattern of the IQ data that is then analyzed.

Create a MockIQBackend helper object to define how the backend functions.

iq_cluster_centers and iq_cluster_width define the base IQ cluster centers and standard deviations for each qubit in a MockIQBackend instance. These are used by iq_clusters() by default. Subclasses can override iq_clusters() to return a modified version of iq_cluster_centers and iq_cluster_width. iq_cluster_centers is a list of tuples. For a given qubit i_qbt and computational state i_state (either 0 or 1), the centers of the IQ clusters are found by indexing iq_cluster_centers as follows:

iq_center = helper.iq_cluster_centers[i_qbt][i_state]
center_inphase = iq_center[0]
center_quadrature = iq_center[1]

iq_cluster_width is indexed similarly except that there is only one width per qubit: i.e., the standard deviation of the IQ cluster for qubit i_qbt is

iq_width = helper.iq_cluster_width[i_qbt]

Subclasses must call super().__init__(iq_cluster_centers,iq_cluster_width) so that these properties are stored appropriately.

  • iq_cluster_centers (List[Tuple[Tuple[float, float], Tuple[float, float]]] | None) – A list of tuples containing the clusters’ centers in the IQ plane. There are different centers for different logical values of the qubit. Defaults to a single qubit with clusters in quadrants 1 and 3.

  • iq_cluster_width (List[float] | None) – A list of standard deviation values for the sampling of each qubit. Defaults to widths of 1.0 for each qubit in iq_cluster_centers.



The base cluster centers in the IQ plane.


The base cluster widths in the IQ plane.


abstract compute_probabilities(circuits)[source]#

A function provided by the user which is used to determine the probability of each output of the circuit. The function returns a list of dictionaries, each containing output binary strings and their probabilities.


1 qubit circuit - excited state

In this experiment, we want to bring a qubit to its excited state and measure it. The circuit:

q:   ┤ X ├┤M├
c: 1/══════╩═

The function that calculates the probability for this circuit doesn’t need any calculation parameters:

def compute_probabilities(self, circuits: List[QuantumCircuit])
    -> List[Dict[str, float]]:

    output_dict_list = []
    for circuit in circuits:
        probability_output_dict = {"1": 1.0, "0": 0.0}
    return output_dict_list

3 qubit circuit

In this experiment, we prepare a Bell state with the first and second qubit. In addition, we will bring the third qubit to its excited state. The circuit:

        ┌───┐     ┌─┐
q_0:    ┤ H ├──■──┤M├───
q_1:    ─────┤ X ├─╫─┤M├
        ┌───┐└┬─┬┘ ║ └╥┘
q_2:    ┤ X ├─┤M├──╫──╫─
        └───┘ └╥┘  ║  ║
c:    3/═══════╩═══╩══╩═
            2   0  1

When an output string isn’t in the probability dictionary, the backend will assume its probability is 0.

def compute_probabilities(self, circuits: List[QuantumCircuit])
    -> List[Dict[str, float]]:

    output_dict_list = []
    for circuit in circuits:
        probability_output_dict = {}
        probability_output_dict["001"] = 0.5
        probability_output_dict["111"] = 0.5
    return output_dict_list
Return type:

List[Dict[str, Any]]


Returns circuit-specific IQ cluster centers and widths in the IQ plane.

Subclasses can override this function to modify the centers and widths of IQ clusters based on the circuits being simulated by a MockIQBackend. The base centers and widths are stored internally within the helper object, and can be set in __init__() or by modifying iq_cluster_centers and iq_cluster_width. The default behavior for iq_clusters() is to return the centers and widths unmodified for each circuit in circuits. Subclasses may return different centers and widths based on the circuits provided.

The returned list contains a tuple per circuit. Each tuple contains the IQ centers and widths in the same format as iq_cluster_centers and iq_cluster_width, passed as arguments to __init__(). The format of the centers and widths lists, in the argument list and in the returned tuples, must match the format of iq_cluster_centers and iq_cluster_width in qiskit_experiments.test.MockIQExperimentHelper.__init__().


circuits (List[QuantumCircuit]) – The quantum circuits for which the clusters should be modified.


A list of tuples containing the circuit-specific IQ centers and widths for the

provided circuits.

Return type:



Sub-classes can override this method to introduce a phase in the IQ plane.

This is needed, to test the resonator spectroscopy where the point in the IQ plane has a frequency-dependent phase rotation.

Return type: