BCDA-APS / bluesky_training

Bluesky training, including instrument package
https://bcda-aps.github.io/bluesky_training/
Other
11 stars 0 forks source link

Use RUN_ENGINE_SCAN_ID_PV if defined #228

Closed prjemian closed 1 year ago

prjemian commented 1 year ago
prjemian commented 1 year ago

By default, the bluesky RunEngine maintains a scan_id (integer) as a human-readable reference to a bluesky run. The value is kept in the RE.md dictionary of run metadata. This dictionary is written to local file storage so the sequence can continue even if the Python process is restarted.

One pattern that breaks this idea (and re-uses old scan_id values) happens when the RE object is created with reloading the metadata from the local file storage. Another pattern that breaks this idea is multiple, simultaneous processes each with their own scan_id.

Use EPICS for scan_id instead of metadata file

The concept of a scan_id comes from SPEC (SCAN_N) and our users expect it. Can't rely on this as a unique reference to a run since it can be reset at any time. As an improvement, we can identify an EPICS PV (such as a longout) to use. To persist the scan-id across reboots of the EPICS IOC, the EPICS PV should be in the IOC's autosave configuration.

This PR adds code to the routine IPython startup to use EPICS if the iconfig.yml defines RUN_ENGINE_SCAN_ID_PV: https://github.com/BCDA-APS/bluesky_training/blob/badd13d6906faf9aa0c8231c291d49d10469def2/bluesky/instrument/iconfig.yml#L20

prjemian commented 1 year ago

Separately, refactor and combine where possible these two code blocks: https://github.com/BCDA-APS/bluesky_training/blob/619f90d42a4365f77b50bb1903cdb489c38dac2f/bluesky/instrument/framework/initialize.py#L120-L149 https://github.com/BCDA-APS/bluesky_training/blob/619f90d42a4365f77b50bb1903cdb489c38dac2f/bluesky/instrument/epics_signal_config.py#L31-L58

prjemian commented 1 year ago

@rodolakis @mdwyman @keenanlang : This PR is ready for review.