Skip to content

Add a device state plan stub - #2267

Merged
oliwenmandiamond merged 6 commits into
mainfrom
state_plan_stub
Nov 12, 2026
Merged

oliwenmandiamond merged 6 commits into
mainfrom
state_plan_stub

Conversation

@oliwenmandiamond

@oliwenmandiamond oliwenmandiamond commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

When working with devices, it is often useful to inspect their current state, including the positions and readings of all readable child devices throughout the device hierarchy.

This plan provides a convenient way to obtain a snapshot of a device's state without manually reading each child individually. Unlike the standard Bluesky read plan, which only reads signals exposed through a device's read() implementation, this plan recursively traverses the device tree and reads all readable children. This includes signals that may not be included in data collection, but are still useful for debugging or understanding the current state of a device.

This is also fully compatible with blueapi. Have tested below:

>>> from blueapi.client import BlueapiClient
>>> bc = BlueapiClient.from_config_file("/scratch/bluesky_development/blueapi/tests/system_tests/config.yaml")
>>> bc.login()
Logged in
>>> bc.instrument_session = "cm12345-2"
>>> pl = bc.plans
>>> dev = bc.devices
>>> pl.state(dev.stage)
{'stage-x': 0.0, 'stage-x-motor_egu': '', 'stage-x-motor_resolution': 0.0, 'stage-x-steps_per_revolution': 0, 'stage-x-units_per_revolution': 0.0, 'stage-x-encoder_resolution': 0.0, 'stage-x-velocity': 1000.0, 'stage-x-offset': 0.0, 'stage-x-user_setpoint': 0.0, 'stage-x-max_velocity': 1000.0, 'stage-x-acceleration_time': 0.0, 'stage-x-precision': 0, 'stage-x-deadband': 0.0, 'stage-x-motor_done_move': 1, 'stage-x-low_limit_travel': 0.0, 'stage-x-high_limit_travel': 0.0, 'stage-x-dial_low_limit_travel': 0.0, 'stage-x-dial_high_limit_travel': 0.0, 'stage-x-offset_freeze_switch': 'Variable', 'stage-x-high_limit_switch': 0, 'stage-x-low_limit_switch': 0, 'stage-x-output_link': '', 'stage-x-set_use_switch': 'Use', 'stage-x-motor_stop': None, 'stage-theta': 0.0, 'stage-theta-motor_egu': '', 'stage-theta-motor_resolution': 0.0, 'stage-theta-steps_per_revolution': 0, 'stage-theta-units_per_revolution': 0.0, 'stage-theta-encoder_resolution': 0.0, 'stage-theta-velocity': 1000.0, 'stage-theta-offset': 0.0, 'stage-theta-user_setpoint': 0.0, 'stage-theta-max_velocity': 1000.0, 'stage-theta-acceleration_time': 0.0, 'stage-theta-precision': 0, 'stage-theta-deadband': 0.0, 'stage-theta-motor_done_move': 1, 'stage-theta-low_limit_travel': 0.0, 'stage-theta-high_limit_travel': 0.0, 'stage-theta-dial_low_limit_travel': 0.0, 'stage-theta-dial_high_limit_travel': 0.0, 'stage-theta-offset_freeze_switch': 'Variable', 'stage-theta-high_limit_switch': 0, 'stage-theta-low_limit_switch': 0, 'stage-theta-output_link': '', 'stage-theta-set_use_switch': 'Use', 'stage-theta-motor_stop': None}
>>> pl.state(dev.stage.x, dev.det)
{'stage-x-motor_egu': '', 'stage-x-motor_resolution': 0.0, 'stage-x-steps_per_revolution': 0, 'stage-x-units_per_revolution': 0.0, 'stage-x-encoder_resolution': 0.0, 'stage-x-velocity': 1000.0, 'stage-x-offset': 0.0, 'stage-x': 0.0, 'stage-x-user_setpoint': 0.0, 'stage-x-max_velocity': 1000.0, 'stage-x-acceleration_time': 0.0, 'stage-x-precision': 0, 'stage-x-deadband': 0.0, 'stage-x-motor_done_move': 1, 'stage-x-low_limit_travel': 0.0, 'stage-x-high_limit_travel': 0.0, 'stage-x-dial_low_limit_travel': 0.0, 'stage-x-dial_high_limit_travel': 0.0, 'stage-x-offset_freeze_switch': 'Variable', 'stage-x-high_limit_switch': 0, 'stage-x-low_limit_switch': 0, 'stage-x-output_link': '', 'stage-x-set_use_switch': 'Use', 'stage-x-motor_stop': None, 'det-driver': None, 'det-driver-port_name': '', 'det-driver-unique_id': 0, 'det-driver-nd_attributes_file': '', 'det-driver-array_size_x': 0, 'det-driver-array_size_y': 0, 'det-driver-array_size_z': 0, 'det-driver-array_size0': 0, 'det-driver-array_size1': 0, 'det-driver-array_size2': 0, 'det-driver-color_mode': 'Mono', 'det-driver-data_type': 'Int8', 'det-driver-array_counter': 0, 'det-driver-ad_core_version': '', 'det-driver-driver_version': '', 'det-driver-acquire_time': 0.0, 'det-driver-acquire_period': 0.0, 'det-driver-num_images': 0, 'det-driver-image_mode': 'Single', 'det-driver-detector_state': 'Idle', 'det-driver-acquire': False, 'det-driver-wait_for_plugins': False, 'det-driver-manufacturer': '', 'det-driver-model': '', 'det-driver-serial_number': '', 'det-driver-sdk_version': '', 'det-driver-firmware_version': '', 'det-hdf': None, 'det-hdf-port_name': '', 'det-hdf-unique_id': 0, 'det-hdf-nd_attributes_file': '', 'det-hdf-array_size_x': 0, 'det-hdf-array_size_y': 0, 'det-hdf-array_size_z': 0, 'det-hdf-array_size0': 0, 'det-hdf-array_size1': 0, 'det-hdf-array_size2': 0, 'det-hdf-color_mode': 'Mono', 'det-hdf-data_type': 'Int8', 'det-hdf-array_counter': 0, 'det-hdf-ad_core_version': '', 'det-hdf-driver_version': '', 'det-hdf-file_path': '', 'det-hdf-file_name': '', 'det-hdf-file_path_exists': False, 'det-hdf-file_template': '', 'det-hdf-full_file_name': '', 'det-hdf-file_number': 0, 'det-hdf-auto_increment': False, 'det-hdf-file_write_mode': 'Single', 'det-hdf-num_capture': 0, 'det-hdf-num_captured': 0, 'det-hdf-capture': False, 'det-hdf-create_directory': 0, 'det-hdf-nd_array_port': '', 'det-hdf-enable_callbacks': 'Enable', 'det-hdf-nd_array_address': 0, 'det-hdf-queue_size': 0, 'det-hdf-position_mode': False, 'det-hdf-compression': 'None', 'det-hdf-num_extra_dims': 0, 'det-hdf-swmr_mode': False, 'det-hdf-flush_now': False, 'det-hdf-xml_file_name': '', 'det-hdf-num_frames_chunks': 0, 'det-hdf-chunk_size_auto': False, 'det-hdf-lazy_open': False}

Instructions to reviewer on how to test:

  1. Check implementation makes sense and meets needs
  2. Check tests pass

Checks for reviewer

  • Would the PR title make sense to a scientist on a set of release notes
  • If a new device has been added does it follow the standards
  • If changing the API for a pre-existing device, ensure that any beamlines using this device have updated their Bluesky plans accordingly
  • Have the connection tests for the relevant beamline(s) been run via dodal connect ${BEAMLINE}

@oliwenmandiamond
oliwenmandiamond requested a review from a team as a code owner November 12, 2026 11:13
@oliwenmandiamond
oliwenmandiamond requested review from DG-At-Diamond, DominicOram, EmsArnold, Relm-Arrowny, noemifrisina and rtuck99 and removed request for a team November 12, 2026 11:13
@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.30%. Comparing base (250f492) to head (258c511).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2267   +/-   ##
=======================================
  Coverage   99.30%   99.30%           
=======================================
  Files         378      379    +1     
  Lines       14876    14893   +17     
=======================================
+ Hits        14773    14790   +17     
  Misses        103      103           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DominicOram DominicOram left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it could be useful, thanks

@oliwenmandiamond
oliwenmandiamond merged commit 8c8d661 into main Nov 12, 2026
10 of 11 checks passed
@oliwenmandiamond
oliwenmandiamond deleted the state_plan_stub branch November 12, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants