QuantumComputer.run_and_measure¶
-
QuantumComputer.
run_and_measure
(program, trials)[source]¶ Run the provided state preparation program and measure all qubits.
The returned data is a dictionary keyed by qubit index because qubits for a given QuantumComputer may be non-contiguous and non-zero-indexed. To turn this dictionary into a 2d numpy array of bitstrings, consider:
bitstrings = qc.run_and_measure(...) bitstring_array = np.vstack([bitstrings[q] for q in qc.qubits()]).T bitstring_array.shape # (trials, len(qc.qubits()))
Note
If the target
QuantumComputer
is a noiselessQVM
then only the qubits explicitly used in the program will be measured. Otherwise all qubits will be measured. In some circumstances this can exhaust the memory available to the simulator, and this may be manifested by the QVM failing to respond or timeout.Note
In contrast to
QVMConnection.run_and_measure
, this method simulates noise correctly for noisy QVMs. However, this method is slower fortrials > 1
. For faster noise-free simulation, considerWavefunctionSimulator.run_and_measure
.