qrisp.QuantumCircuit.run#
- QuantumCircuit.run(shots: int | None = None, backend: Any = None) dict[str, Any][source]#
Executes a QuantumCircuit on a backend and returns the measurement results.
- Parameters:
- shotsint or None, optional
Number of shots to sample. When set to
None(default), the behaviour depends on the backend. For simulators, the exact probability distribution is returned. For real quantum devices, the number of shots is determined by the backend’s default settings.- backendobject, optional
The backend on which to evaluate the QuantumCircuit. When not provided, Qrisp’s built-in statevector simulator is used.
- Returns:
- dict[str, Any]
A dictionary mapping measurement outcome strings to integer counts (when shots is given) or to exact float probabilities (when shots is
Noneand the backend is a simulator).
Examples
In this example, we prepare a 3-qubit GHZ state and retrieve the exact probability distribution by omitting shots:
>>> from qrisp import QuantumCircuit >>> qc = QuantumCircuit(3) >>> qc.h(0) >>> qc.cx(0, [1, 2]) >>> qc.measure([0, 1, 2]) >>> qc.run() {'000': 0.5, '111': 0.5}
We can also pass an explicit shot count to obtain sampled integer counts instead. In this example we prepare a 2-qubit state where we expect to get the outcome
11in all shots:>>> qc_det = QuantumCircuit(2) >>> qc_det.x([0, 1]) >>> qc_det.measure([0, 1]) >>> qc_det.run(shots=100) {'11': 100}