Using the Gate-Model Simulator#
The Leap quantum cloud service provides access to a simulator that enables you to test gate-model circuits intended to be executed on a dual-rail quantum processing unit (QPU). You describe your circuits using the dwave-gate package’s quantum circuit description language (QCDL), introduced in the Introduction to QCDL section and described in detail in the API Reference section.
About the Simulator#
The Leap service provides a Monte Carlo simulator of QCDL programs.
This simulator closely models the classical and quantum operation of the QPU with varying approximations. It instantiates a “state” representing both classical and quantum components of the hardware and then executes your QCDL instructions one at a time to update that state.
As a shot-by-shot Monte Carlo simulator, it is significantly slower than an exact statevector simulator and scales linearly with the number of shots (however, its operation is embarrassingly parallel). For example, it does not multiply the circuit’s operations into a single matrix that can then extract probabilities for each outcome. Computations are executed operation by operation with Monte Carlo to support realtime control flow, enable a computation to progress along multiple trajectories based on mid-circuit measurements, and to simulate noise events. D‑Wave is working to improve performance by various means.
Tip
Accuracy bears a simulation cost and error handling increases circuit complexity. It is advisable to start circuit development against the ideal simulator and then introduce error modeling.
The simulator in the Leap service supports ideal and noisy simulations. The following table compares these two simulations.
Characteristic |
Ideal |
Noisy |
|---|---|---|
Noise model. |
Solver parameter noise_model set to
Useful during initial testing of QCDL programs before introducing noise. |
Solver parameter noise_model set to
This simulation is useful for exploring the impact of erasures on QCDL programs. It operates by randomly applying Pauli errors, leakages, and seepages after quantum gates and idles. |
Runtime. |
Scales as \(O(s*g*2^n)\) where \(n\) is the number of qubits, \(s\) the number of shots, and \(g\) the number of gates. |
Slower due to added gates used to simulate noise. |
Submitting Programs#
The QPU simulator in the Leap service is intended to simulate gate-model quantum computers by executing programs formulated as QCDL.
Descriptions of the supported parameters and simulator properties are provided in the Gate-Model Simulator Parameters and Gate-Model Simulator Properties sections.
Example Submission#
The example below submits the following Bell state QCDL program.
from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import cx, h, measure
@qcdl(2)
def bell_program(q0, q1):
h(q0)
cx(q0, q1)
measure(q0)
measure(q1)
simulator_job_submission = bell_program()
Submit the program above to a simulator for a dual-rail QPU with 21 qubits,
DRsim_21qubits, in the Leap service.
>>> from dwave.gate.leap import LeapQCDLSimulator
...
>>> simulator = LeapQCDLSimulator()
>>> future = simulator.run(
... simulator_job_submission,
... qpu='DRsim_21qubits',
... noise_model=True,
... shots=500,
... label="SDK Examples - Bell-Program Job Submission")
>>> result = future.result().result
Example Results#
Results are returned as a Result class, that also
includes information such as execution time and provides methods for analyzing
the measurements.
The returned result is a 3D array of (measurements per shot, shots, qubits).
For the previous example, one measurement is taken per shot, for 500 shots, on
two qubits.
>>> print(result.get_memory().shape)
(1, 500, 2)
For one particular execution of the program above, the following counts are returned.
>>> print(result.get_counts())
[{'11': 203, '*1': 14, '00': 230, '0*': 22, '*0': 19, '1*': 10, '**': 2}]
The execution time on the simulator (excluding any queuing time, for example) for that job submission is about a tenth of a second.
>>> print(result.run_time)
0.093493
See the Results section for information about the returned results and supported methods. The Result Records section describes how you store and retrieve records of measurements.