.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_cookbook_simulation-mode.py: Inspect or rehearse a plan ("simulation mode") ********************************************** Problem ======= Check a plan for mistakes before running it on real hardware. Approach ======== 1. Display the steps of a plan and read through them to verify that they match our intention. 2. Execute the plan on "simulated hardware," Python objects that stand in for real motors and detectors but do not actually communicate with any hardware. Example Solutions ================= The ``bluesky.examples`` module includes simulated motors and detectors. .. code-block:: default # Make a RunEngine instance. from bluesky import RunEngine RE = RunEngine({}) from ophyd.sim import motor, motor1, motor2, det from bluesky.simulators import print_summary, plot_raster_path from bluesky.plans import count, scan, outer_product_scan Inspect plans ------------- Use ``print_summary`` which translates the plan into a human-readable list of steps. .. code-block:: default print_summary(count([det])) print_summary(scan([det], motor, 1, 3, 3)) print_summary(outer_product_scan([det], motor1, 1, 3, 3, motor2, 1, 2, 2, False)) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none =================================== Open Run =================================== Read ['det'] ================================== Close Run =================================== =================================== Open Run =================================== motor -> 1.0 Read ['det', 'motor'] motor -> 2.0 Read ['det', 'motor'] motor -> 3.0 Read ['det', 'motor'] ================================== Close Run =================================== =================================== Open Run =================================== motor1 -> 1.0 motor2 -> 1.0 Read ['det', 'motor1', 'motor2'] motor2 -> 2.0 Read ['det', 'motor1', 'motor2'] motor1 -> 2.0 motor2 -> 1.0 Read ['det', 'motor1', 'motor2'] motor2 -> 2.0 Read ['det', 'motor1', 'motor2'] motor1 -> 3.0 motor2 -> 1.0 Read ['det', 'motor1', 'motor2'] motor2 -> 2.0 Read ['det', 'motor1', 'motor2'] ================================== Close Run =================================== Use ``plot_raster_path`` to visualize a two-dimensional trajectory. .. code-block:: default plot_raster_path(outer_product_scan([det], motor1, 1, 3, 3, motor2, 1, 2, 2, False), 'motor1', 'motor2') .. image:: /cookbook/images/sphx_glr_simulation-mode_001.png :class: sphx-glr-single-img Note that ``print_summary`` cannot be used on plans the require feedback from the hardware, such as adaptively-spaced step scans. Rehearse plans -------------- Simply execute the plan as usual --- ``RE(plan)`` --- but define that plan using the simulated motors and detectors from ``bluesky.examples`` instead of the variables that represent real hardware. .. code-block:: default RE(count([det])) # executes the plan, 'reading' the simulated detector To avoid saving data from these "rehearsal" runs, make a separate instance of the RunEngine, and do not subscribe metadatastore. .. code-block:: default SIM_RE = RunEngine({}) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.297 seconds) .. _sphx_glr_download_cookbook_simulation-mode.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: simulation-mode.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: simulation-mode.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_