Note
This is the documentation for the current state of the development branch of Qiskit Experiments. The documentation or APIs here can change prior to being released.
MockIQExperimentHelper¶
- 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
andiq_cluster_width
define the base IQ cluster centers and standard deviations for each qubit in aMockIQBackend
instance. These are used byiq_clusters()
by default. Subclasses can overrideiq_clusters()
to return a modified version ofiq_cluster_centers
andiq_cluster_width
.iq_cluster_centers
is a list of tuples. For a given qubiti_qbt
and computational statei_state
(either 0 or 1), the centers of the IQ clusters are found by indexingiq_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 qubiti_qbt
isiq_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.- Parameters:
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
.
Attributes
- iq_cluster_centers¶
The base cluster centers in the IQ plane.
- iq_cluster_width¶
The base cluster widths in the IQ plane.
Methods
- 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.
Examples:
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/══════╩═ 0
The function that calculates the probability for this circuit doesn’t need any calculation parameters:
@staticmethod 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} output_dict_list.append(probability_output_dict) 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.
@staticmethod 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 output_dict_list.append(probability_output_dict) return output_dict_list
- Return type:
List[Dict[str, Any]]
- iq_clusters(circuits)[source]¶
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 modifyingiq_cluster_centers
andiq_cluster_width
. The default behavior foriq_clusters()
is to return the centers and widths unmodified for each circuit incircuits
. 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
andiq_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 ofiq_cluster_centers
andiq_cluster_width
inqiskit_experiments.test.MockIQExperimentHelper.__init__()
.- Parameters:
circuits (List[QuantumCircuit]) – The quantum circuits for which the clusters should be modified.
- Returns:
- A list of tuples containing the circuit-specific IQ centers and widths for the
provided circuits.
- Return type:
List