Skip to content

Commit 83de359

Browse files
authored
Ability to launch blueapi and run Hyperion plans (#1389)
* Add load_centre_collect, robot_unload and udc_default_state blueapi plans * Add some documentation for hyperion-blueapi * Updates to work with DeviceManager, BartRobot changes
1 parent 05d29b6 commit 83de359

File tree

12 files changed

+317
-12
lines changed

12 files changed

+317
-12
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Hyperion on BlueAPI
2+
===================
3+
4+
This document describes the migration of Hyperion from a monolithic service that contains its own application server
5+
and is only partially dependent on BlueAPI,
6+
to a standard BlueAPI application deployment.
7+
8+
Architecture
9+
------------
10+
11+
Hyperion on BlueAPI consists of two components:
12+
13+
* hyperion-blueapi: This is intended to ultimately be a standard blueapi installation, consisting of a beamline
14+
module and a dodal plan module. In the interim, deployment may vary from the standard method until such time as
15+
monolithic operation can be desupported. ``hyperion-blueapi`` exposes a minimal set of bluesky plans for UDC data
16+
collection.
17+
18+
* hyperion-supervisor: This will be a separate service that is responsible for fetching instructions from
19+
Agamemnon, decoding them and sending corresponding requests to ``hyperion-blueapi`` for execution. The supervisor
20+
also monitors the state of ``hyperion-blueapi``, manages the Hyperion baton and provides endpoints for status
21+
monitoring.
22+
23+
Deployment
24+
----------
25+
26+
``hyperion-blueapi`` is automatically available in a standard Hyperion deployment.
27+
28+
Launching
29+
---------
30+
31+
``hyperion-blueapi`` can be launched in using the ``run_hyperion.sh`` script, using the ``--blueapi`` option:
32+
33+
::
34+
35+
./run_hyperion.sh --beamline=i03 --dev --blueapi

docs/developer/hyperion/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Documentation specific for the Hyperion module within MX-Bluesky
1717
reference/param-hierarchy
1818
reference/coordinate-systems
1919
system-tests
20+
hyperion-blueapi
2021

2122
+++
2223

run_hyperion.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ START=1
77
IN_DEV=false
88
MODE=gda
99

10+
CONFIG_DIR=`dirname $0`/src/mx_bluesky/hyperion
11+
BLUEAPI_CONFIG=$CONFIG_DIR/blueapi_config.yaml
12+
1013
for option in "$@"; do
1114
case $option in
1215
-b=*|--beamline=*)
@@ -22,10 +25,14 @@ for option in "$@"; do
2225
;;
2326
--dev)
2427
IN_DEV=true
28+
BLUEAPI_CONFIG=$CONFIG_DIR/blueapi_dev_config.yaml
2529
;;
2630
--udc)
2731
MODE=udc
2832
;;
33+
--blueapi)
34+
MODE=blueapi
35+
;;
2936
--help|--info|--h)
3037
source .venv/bin/activate
3138
echo "`basename $0` [options]"
@@ -38,10 +45,9 @@ Options:
3845
--stop Used to stop a currently running instance of Hyperion. Will override any other operations
3946
options.
4047
--no-start Used to specify that the script should be run without starting the server.
41-
--skip-startup-connection
42-
Do not connect to devices at startup
4348
--dev Enable dev mode to run from a local workspace on a development machine.
4449
--udc Start hyperion in UDC mode instead of taking commands from GDA
50+
--blueapi Start hyperion in blueapi mode instead of taking commands from GDA
4551
--help This help
4652
4753
By default this script will start an Hyperion server unless the --no-start flag is specified.
@@ -59,6 +65,7 @@ kill_active_apps () {
5965
echo "Killing active instances of hyperion and hyperion-callbacks..."
6066
pkill -e -f "python.*hyperion"
6167
pkill -e -f "SCREEN.*hyperion"
68+
blueapi controller stop 2>/dev/null
6269
echo "done."
6370
}
6471

@@ -120,8 +127,6 @@ if [[ $START == 1 ]]; then
120127

121128
source .venv/bin/activate
122129

123-
#Add future arguments here
124-
125130
declare -A h_and_cb_args=( ["IN_DEV"]="$IN_DEV" )
126131
declare -A h_and_cb_arg_strings=( ["IN_DEV"]="--dev" )
127132

@@ -136,16 +141,23 @@ if [[ $START == 1 ]]; then
136141
done
137142

138143
unset PYEPICS_LIBCA
139-
echo "Starting hyperion with hyperion $h_commands, start_log is $start_log_path"
140-
hyperion `echo $h_commands;`>$start_log_path 2>&1 &
144+
if [ $MODE = "blueapi" ]; then
145+
echo "Starting hyperion in blueapi mode, start log is $start_log_path"
146+
blueapi --config $BLUEAPI_CONFIG serve > $start_log_path 2>&1 &
147+
HEALTHCHECK_ENDPOINT="healthz"
148+
else
149+
echo "Starting hyperion with hyperion $h_commands, start_log is $start_log_path"
150+
hyperion `echo $h_commands;`>$start_log_path 2>&1 &
151+
HEALTHCHECK_ENDPOINT="status"
152+
fi
141153
echo "Starting hyperion-callbacks with hyperion-callbacks $cb_commands, start_log is $callback_start_log_path"
142154
hyperion-callbacks `echo $cb_commands;`>$callback_start_log_path 2>&1 &
143155
echo "$(date) Waiting for Hyperion to start"
144156

145157
for i in {1..30}
146158
do
147159
echo "$(date)"
148-
curl --head -X GET http://localhost:5005/status >/dev/null
160+
curl --head -X GET http://localhost:5005/$HEALTHCHECK_ENDPOINT >/dev/null
149161
ret_value=$?
150162
if [ $ret_value -ne 0 ]; then
151163
sleep 1

src/mx_bluesky/common/device_setup_plans/robot_load_unload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from bluesky.utils import MsgGenerator
66
from dodal.devices.aperturescatterguard import ApertureScatterguard, ApertureValue
77
from dodal.devices.motors import XYZStage
8-
from dodal.devices.robot import BartRobot
8+
from dodal.devices.robot import SAMPLE_LOCATION_EMPTY, BartRobot
99
from dodal.devices.smargon import CombinedMove, Smargon, StubPosition
1010
from dodal.plan_stubs.motor_utils import MoveTooLargeError, home_and_reset_wrapper
1111

@@ -117,7 +117,7 @@ def do_robot_unload_and_send_to_ispyb():
117117
yield from bps.save()
118118

119119
def _unload():
120-
yield from bps.abs_set(robot, None, wait=True)
120+
yield from bps.abs_set(robot, SAMPLE_LOCATION_EMPTY, wait=True)
121121
yield from wait_for_smargon_not_disabled(smargon)
122122

123123
gonio_finished = yield from do_plan_while_lower_gonio_at_home(
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
env:
2+
sources:
3+
- kind: deviceManager
4+
module: dodal.beamlines.i03
5+
- kind: planFunctions
6+
module: mx_bluesky.hyperion.blueapi_plans
7+
events:
8+
broadcast_status_events: false
9+
api:
10+
url: http://localhost:5005
11+
cors:
12+
allow_credentials: True
13+
origins:
14+
- "*"
15+
logging:
16+
graylog:
17+
url: "tcp://graylog-log-target.diamond.ac.uk:12232"
18+
enabled: true
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
env:
2+
sources:
3+
- kind: deviceManager
4+
module: dodal.beamlines.i03
5+
mock: true
6+
- kind: planFunctions
7+
module: mx_bluesky.hyperion.blueapi_plans
8+
events:
9+
broadcast_status_events: false
10+
api:
11+
url: http://localhost:5005
12+
cors:
13+
allow_credentials: True
14+
origins:
15+
- "*"
16+
logging:
17+
level: DEBUG
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""
2+
This module contains the bluesky plan entry points for use with hyperion-blueapi.
3+
The json schema and documentation therein generated by the blueapi /plans endpoint
4+
from this file constitutes the hyperion-blueapi interface to the hyperion supervisor
5+
process.
6+
"""
7+
8+
from bluesky.utils import MsgGenerator
9+
from dodal.common import inject
10+
from dodal.devices.aperturescatterguard import ApertureScatterguard
11+
from dodal.devices.motors import XYZStage
12+
from dodal.devices.robot import BartRobot
13+
from dodal.devices.smargon import Smargon
14+
15+
from mx_bluesky.common.device_setup_plans.robot_load_unload import (
16+
robot_unload as _robot_unload,
17+
)
18+
from mx_bluesky.hyperion.experiment_plans.load_centre_collect_full_plan import (
19+
LoadCentreCollectComposite,
20+
)
21+
from mx_bluesky.hyperion.experiment_plans.load_centre_collect_full_plan import (
22+
load_centre_collect_full as _load_centre_collect_full,
23+
)
24+
from mx_bluesky.hyperion.experiment_plans.udc_default_state import (
25+
UDCDefaultDevices,
26+
)
27+
from mx_bluesky.hyperion.experiment_plans.udc_default_state import (
28+
move_to_udc_default_state as _move_to_udc_default_state,
29+
)
30+
from mx_bluesky.hyperion.parameters.load_centre_collect import LoadCentreCollect
31+
32+
__all__ = [
33+
"LoadCentreCollectComposite",
34+
"LoadCentreCollect",
35+
"UDCDefaultDevices",
36+
"load_centre_collect",
37+
"move_to_udc_default_state",
38+
"robot_unload",
39+
]
40+
41+
42+
def load_centre_collect(
43+
parameters: LoadCentreCollect, composite: LoadCentreCollectComposite = inject()
44+
) -> MsgGenerator:
45+
"""
46+
Attempt a complete data collection experiment, consisting of the following:
47+
* Load the sample if necessary
48+
* Move to the specified goniometer start angles
49+
* Perform optical centring, then X-ray centring
50+
* If X-ray centring finds one or more diffracting centres then for each centre
51+
that satisfies the chosen selection function,
52+
move to that centre and do a collection with the specified parameters.
53+
"""
54+
yield from _load_centre_collect_full(composite, parameters)
55+
56+
57+
def robot_unload(
58+
visit: str,
59+
robot: BartRobot = inject("robot"),
60+
smargon: Smargon = inject("smargon"),
61+
aperture_scatterguard: ApertureScatterguard = inject("aperture_scatterguard"),
62+
lower_gonio: XYZStage = inject("lower_gonio"),
63+
) -> MsgGenerator:
64+
"""
65+
Unload the currently mounted pin into the location that it was loaded from.
66+
This is to be invoked as the final step upon successful completion of the UDC queue.
67+
"""
68+
yield from _robot_unload(robot, smargon, aperture_scatterguard, lower_gonio, visit)
69+
70+
71+
def move_to_udc_default_state(
72+
composite: UDCDefaultDevices = inject(),
73+
) -> MsgGenerator:
74+
"""
75+
Move beamline hardware to known positions prior to UDC start.
76+
"""
77+
yield from _move_to_udc_default_state(composite)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "move_to_udc_default_state",
3+
"params": {},
4+
"instrument_session": "cm12345-1"
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "robot_unload",
3+
"params": {
4+
"visit": "cm12345-1"
5+
},
6+
"instrument_session": "cm12345-1"
7+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "load_centre_collect",
3+
"params": {
4+
"parameters": {
5+
"parameter_model_version": "5.0.0",
6+
"beamline": "BL03S",
7+
"det_dist_to_beam_converter_path": "tests/test_data/test_lookup_table.txt",
8+
"insertion_prefix": "SR03S",
9+
"visit": "cm31105-4",
10+
"detector_distance_mm": 255,
11+
"sample_id": 12345,
12+
"sample_puck": 40,
13+
"sample_pin": 3,
14+
"robot_load_then_centre": {
15+
"storage_directory": "{tmp_data}/123458/xraycentring",
16+
"file_name": "robot_load_centring_file",
17+
"comment": "Robot load and centre",
18+
"exposure_time_s": 0.004,
19+
"use_roi_mode": false,
20+
"demand_energy_ev": 11100,
21+
"run_number": 0,
22+
"panda_runup_distance_mm": 0.17,
23+
"box_size_um": 20
24+
},
25+
"multi_rotation_scan": {
26+
"comment": "Rotation",
27+
"storage_directory": "{tmp_data}/123458/",
28+
"file_name": "file_name",
29+
"exposure_time_s": 0.004,
30+
"selected_aperture": "SMALL_APERTURE",
31+
"transmission_frac": 1.0,
32+
"demand_energy_ev": 11100,
33+
"rotation_increment_deg": 0.1,
34+
"shutter_opening_time_s": 0.6,
35+
"snapshot_omegas_deg": [
36+
0,
37+
90,
38+
180,
39+
270
40+
],
41+
"run_number": 1,
42+
"rotation_scans": [
43+
{
44+
"rotation_axis": "omega",
45+
"rotation_direction": "Negative",
46+
"scan_width_deg": 180.0,
47+
"omega_start_deg": 0,
48+
"phi_start_deg": 0.47,
49+
"chi_start_deg": 23.85
50+
}
51+
]
52+
}
53+
}
54+
},
55+
"instrument_session": "cm12345-1"
56+
}

0 commit comments

Comments
 (0)