.. _qcdl_using_simulator: ============================== Using the Gate-Model Simulator ============================== The |cloud|_ 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 :ref:`index_gate` package's quantum circuit description language (QCDL), introduced in the :ref:`gate_workflow` section and described in detail in the :ref:`gate_api_ref` section. .. _qcdl_simulator: About the Simulator =================== The |cloud|_ 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. |dwave_short| 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 |cloud|_ service supports ideal and noisy simulations. The following table compares these two simulations. .. list-table:: :header-rows: 1 * - Characteristic - Ideal - Noisy * - Noise model. - Solver parameter :ref:`parameter_drsim_noise_model` set to ``False``. Useful during initial testing of QCDL programs before introducing noise. - Solver parameter :ref:`parameter_drsim_noise_model` set to ``True``. 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 :math:`O(s*g*2^n)` where :math:`n` is the number of qubits, :math:`s` the number of shots, and :math:`g` the number of gates. - Slower due to added gates used to simulate noise. .. _qcdl_submitting_programs: Submitting Programs =================== The :ref:`QPU simulator ` in the |cloud|_ service is intended to simulate :ref:`gate-model quantum computers ` by executing programs formulated as QCDL. Descriptions of the supported parameters and simulator properties are provided in the :ref:`qcdl_simulator_parameters` and :ref:`qcdl_simulator_properties` sections. .. _qcdl_submitting_programs_example: Example Submission ================== The example below submits the following `Bell state `_ QCDL program. .. include:: ../shared/examples.rst :start-after: start_gm_sim_bell :end-before: end_gm_sim_bell Submit the program above to a simulator for a dual-rail QPU with 21 qubits, ``DRsim_21qubits``, in the |cloud|_ service. >>> from dwave.gate.leap import LeapQCDLSimulator ... >>> simulator = LeapQCDLSimulator() # doctest: +SKIP >>> future = simulator.run( # doctest: +SKIP ... simulator_job_submission, ... qpu='DRsim_21qubits', ... noise_model=True, ... shots=500, ... label="SDK Examples - Bell-Program Job Submission") >>> result = future.result().result # doctest: +SKIP .. _qcdl_submitting_programs_results: Example Results =============== Results are returned as a :class:`~dwave.gate.results.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) # doctest: +SKIP (1, 500, 2) For one particular execution of the program above, the following counts are returned. >>> print(result.get_counts()) # doctest: +SKIP [{'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) # doctest: +SKIP 0.093493 See the :ref:`gate_results` section for information about the returned results and supported methods. The :ref:`qcdl_basic_result_records` section describes how you store and retrieve records of measurements.