cunqa.tools.probabilities
- probabilities(result, per_qubit=False, partial=None, sep_registers=False, estimate=False)
Extracts probabilities from result information. If we have statevector or density matrix exact probabilities are obtained, otherwise frequencies are calculated from counts.
Note
If several states (statevector or density matrix) are saved, a dict with keys the state labels and values the probability arrays is returned.
- Parameters:
result (<class cunqa.result.Result>) – result object to extract probabilities from
per_qubit (bool) – selects probabilities per bitstring (False) or per qubit (True). If True, an 2D (num_qubits x 2)-array with the probability of “0” and “1” for each qubit as rows, where the qubit index decreases with row index, is returned. Default: False.
partial (list[int]) – list of indices of significant qubits. If given, probabilities are marginalized w/ respect to those qubits. Good for excluding ancillae.
sep_registers (bool) – if True, a separate probs array is returned for each cl_register on the estimation from counts mode. If additionally the partial option is desired, it should be of type list[list[int]] or behave analogously. Default: False
estimate (bool) – if True, probabilities are estimated from counts regardless of the presence of statevector or density matrix to pull them from. Default: False
- Returns:
probabilities per bitstring or per qubit. Order is as follows:
Per bitstring: probability on each position is associated to the corresponding bitstring in ascending binary order, ie for 2 qubits [“00”, “01”, “10”, “11”].
Per qubit: probability of “0” and “1” for each qubit where qubit 0 is the last row and the qubit index increases as row index decreases.
Partial preserves these orders in both cases.
- Return type:
probs (dict, np.ndarray)