def probability(target: QubitSetInput = None) -> ResultType: """Registers this function into the circuit class. Args: target (int, Qubit, or iterable of int / Qubit, optional): The target qubits that the result type is requested for. Default is `None`, which means all qubits for the circuit. Returns: ResultType: probability as a requested result type Examples: >>> circ = Circuit().probability(target=[0, 1]) """ return ResultType.Probability(target=target)
def get_probabilities( self, circuit: Circuit, qubits: Union[Iterable[int], None] = None, n_shots: int = 0, valid_check: bool = True, **kwargs: KwargTypes, ) -> np.ndarray: """ Compute the (exact or empirical) probability distribution of outcomes. If `n_shots > 0` the probabilities are calculated empirically by measurements. If `n_shots = 0` (if supported) they are calculated exactly by simulation. Supported `kwargs` are as for `BraketBackend.process_circuits`. The order is big-endian with respect to the order of qubits in the argument. For example, if qubits=[0,1] then the order of probabilities is [p(0,0), p(0,1), p(1,0), p(1,1)], while if qubits=[1,0] the order is [p(0,0), p(1,0), p(0,1), p(1,1)], where p(i,j) is the probability of qubit 0 being in state i and qubit 1 being in state j. :param qubits: qubits of interest :returns: list of probabilities of outcomes if initial state is all-zeros """ if not self.supports_probability: raise RuntimeError("Backend does not support probability") if (n_shots < self._probability_min_shots or n_shots > self._probability_max_shots): raise ValueError( f"n_shots must be between {self._probability_min_shots} and " f"{self._probability_max_shots}") if valid_check: self._check_all_circuits([circuit], nomeasure_warn=False) bkcirc = self._to_bkcirc(circuit) restype = ResultType.Probability(target=qubits) bkcirc.add_result_type(restype) task = self._run(bkcirc, n_shots=n_shots, **kwargs) res = task.result() return res.get_value_by_result_type(restype) # type: ignore