mx-bluesky 1.5.4__py3-none-any.whl → 1.5.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. mx_bluesky/_version.py +2 -2
  2. mx_bluesky/beamlines/i04/__init__.py +6 -1
  3. mx_bluesky/beamlines/i04/redis_to_murko_forwarder.py +2 -3
  4. mx_bluesky/beamlines/i04/thawing_plan.py +173 -59
  5. mx_bluesky/beamlines/i24/serial/blueapi_config.yaml +1 -1
  6. mx_bluesky/beamlines/i24/serial/dcid.py +4 -25
  7. mx_bluesky/beamlines/i24/serial/extruder/EX-gui-edm/DetStage.edl +4 -7
  8. mx_bluesky/beamlines/i24/serial/extruder/EX-gui-edm/DiamondExtruder-I24-py3v1.edl +5 -5
  9. mx_bluesky/beamlines/i24/serial/extruder/i24ssx_Extruder_Collect_py3v2.py +18 -107
  10. mx_bluesky/beamlines/i24/serial/fixed_target/FT-gui-edm/CustomChip_py3v1.edl +1 -1
  11. mx_bluesky/beamlines/i24/serial/fixed_target/FT-gui-edm/DetStage.edl +1 -4
  12. mx_bluesky/beamlines/i24/serial/fixed_target/FT-gui-edm/DiamondChipI24-py3v1.edl +13 -13
  13. mx_bluesky/beamlines/i24/serial/fixed_target/FT-gui-edm/MappingLite-oxford_py3v1.edl +8 -8
  14. mx_bluesky/beamlines/i24/serial/fixed_target/FT-gui-edm/pumpprobe-py3v1.edl +7 -7
  15. mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Collect_py3v1.py +8 -92
  16. mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_Chip_Manager_py3v1.py +2 -18
  17. mx_bluesky/beamlines/i24/serial/parameters/constants.py +0 -2
  18. mx_bluesky/beamlines/i24/serial/parameters/experiment_parameters.py +1 -6
  19. mx_bluesky/beamlines/i24/serial/parameters/fixed_target/cs/cs_maker.json +3 -3
  20. mx_bluesky/beamlines/i24/serial/run_extruder.sh +15 -0
  21. mx_bluesky/beamlines/i24/serial/run_fixed_target.sh +17 -0
  22. mx_bluesky/beamlines/i24/serial/set_visit_directory.sh +1 -1
  23. mx_bluesky/beamlines/i24/serial/setup_beamline/__init__.py +1 -2
  24. mx_bluesky/beamlines/i24/serial/setup_beamline/pv.py +0 -25
  25. mx_bluesky/beamlines/i24/serial/setup_beamline/pv_abstract.py +1 -30
  26. mx_bluesky/beamlines/i24/serial/setup_beamline/setup_beamline.py +0 -94
  27. mx_bluesky/beamlines/i24/serial/setup_beamline/setup_detector.py +4 -10
  28. mx_bluesky/beamlines/i24/serial/setup_beamline/setup_zebra_plans.py +12 -20
  29. mx_bluesky/beamlines/i24/serial/web_gui_plans/general_plans.py +4 -13
  30. mx_bluesky/beamlines/i24/serial/write_nexus.py +34 -9
  31. mx_bluesky/common/experiment_plans/common_flyscan_xray_centre_plan.py +25 -2
  32. mx_bluesky/common/external_interaction/callbacks/common/ispyb_callback_base.py +1 -1
  33. mx_bluesky/common/external_interaction/callbacks/common/plan_reactive_callback.py +2 -2
  34. mx_bluesky/common/external_interaction/callbacks/xray_centre/ispyb_callback.py +2 -2
  35. mx_bluesky/common/external_interaction/callbacks/xray_centre/nexus_callback.py +2 -2
  36. mx_bluesky/common/parameters/components.py +1 -0
  37. mx_bluesky/hyperion/__main__.py +16 -3
  38. mx_bluesky/hyperion/baton_handler.py +78 -11
  39. mx_bluesky/hyperion/experiment_plans/load_centre_collect_full_plan.py +19 -8
  40. mx_bluesky/hyperion/external_interaction/agamemnon.py +6 -2
  41. mx_bluesky/hyperion/external_interaction/alerting/constants.py +2 -7
  42. mx_bluesky/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py +2 -2
  43. mx_bluesky/hyperion/parameters/constants.py +1 -0
  44. mx_bluesky/hyperion/plan_runner.py +2 -4
  45. mx_bluesky/hyperion/plan_runner_api.py +43 -0
  46. {mx_bluesky-1.5.4.dist-info → mx_bluesky-1.5.6.dist-info}/METADATA +2 -2
  47. {mx_bluesky-1.5.4.dist-info → mx_bluesky-1.5.6.dist-info}/RECORD +51 -50
  48. {mx_bluesky-1.5.4.dist-info → mx_bluesky-1.5.6.dist-info}/WHEEL +0 -0
  49. {mx_bluesky-1.5.4.dist-info → mx_bluesky-1.5.6.dist-info}/entry_points.txt +0 -0
  50. {mx_bluesky-1.5.4.dist-info → mx_bluesky-1.5.6.dist-info}/licenses/LICENSE +0 -0
  51. {mx_bluesky-1.5.4.dist-info → mx_bluesky-1.5.6.dist-info}/top_level.txt +0 -0
@@ -24,7 +24,7 @@ from mx_bluesky.beamlines.i24.serial.log import SSX_LOGGER
24
24
 
25
25
  # Detector specific outs
26
26
  TTL_EIGER = 1
27
- TTL_PILATUS = 2
27
+ TTL_LASER = 2
28
28
  TTL_FAST_SHUTTER = 4
29
29
 
30
30
  SHUTTER_MODE = {
@@ -171,12 +171,11 @@ def setup_zebra_for_extruder_with_pump_probe_plan(
171
171
 
172
172
  For this use case, both the laser and detector set up is taken care of by the Zebra.
173
173
  WARNING. This means that some hardware changes have been made.
174
- Because all four of the zebra ttl outputs are in use in this mode, when the \
175
- detector in use is the Eiger, the Pilatus cable is repurposed to trigger the light \
176
- source, and viceversa.
174
+ All four of the zebra ttl outputs are in use in this mode. When the \
175
+ detector in use is the Eiger, the previous Pilatus cable is repurposed to trigger \
176
+ the light source.
177
177
 
178
- The data collection output is OUT1_TTL for Eiger and OUT2_TTL for Pilatus and \
179
- should be set to AND3.
178
+ The data collection output is OUT1_TTL for Eiger and should be set to AND3.
180
179
 
181
180
  Position compare settings:
182
181
  - The gate input is on SOFT_IN2.
@@ -191,7 +190,7 @@ def setup_zebra_for_extruder_with_pump_probe_plan(
191
190
 
192
191
  Args:
193
192
  zebra (Zebra): The zebra ophyd device.
194
- det_type (str): Detector in use, current choices are Eiger or Pilatus.
193
+ det_type (str): Detector in use.
195
194
  exp_time (float): Collection exposure time, in s.
196
195
  num_images (int): Number of images to be collected.
197
196
  pump_exp (float): Laser dwell, in s.
@@ -210,8 +209,8 @@ def setup_zebra_for_extruder_with_pump_probe_plan(
210
209
  yield from set_logic_gates_for_porto_triggering(zebra)
211
210
 
212
211
  # Set TTL out depending on detector type
213
- DET_TTL = TTL_EIGER if det_type == "eiger" else TTL_PILATUS
214
- LASER_TTL = TTL_PILATUS if det_type == "eiger" else TTL_EIGER
212
+ DET_TTL = TTL_EIGER
213
+ LASER_TTL = TTL_LASER # may change with additional detectors
215
214
  yield from bps.abs_set(
216
215
  zebra.output.out_pvs[DET_TTL], zebra.mapping.sources.AND4, group=group
217
216
  )
@@ -281,8 +280,7 @@ def setup_zebra_for_fastchip_plan(
281
280
 
282
281
  For this use case, the laser set up is taken care of by the geobrick, leaving only \
283
282
  the detector side set up to the Zebra.
284
- The data collection output is OUT1_TTL for Eiger and OUT2_TTL for Pilatus and \
285
- should be set to AND3.
283
+ The data collection output is OUT1_TTL for Eiger and should be set to AND3.
286
284
 
287
285
  Position compare settings:
288
286
  - The gate input is on IN3_TTL.
@@ -291,16 +289,14 @@ def setup_zebra_for_fastchip_plan(
291
289
  - Trigger source set to the exposure time with a 100us buffer in order to \
292
290
  avoid missing any triggers.
293
291
  - The trigger width is calculated depending on which detector is in use: the \
294
- Pilatus only needs the trigger rising edge to collect for a set time, while \
295
- the Eiger (used here in Externally Interrupter Exposure Series mode) \
292
+ Eiger (used here in Externally Interrupter Exposure Series mode) \
296
293
  will only collect while the signal is high and will stop once a falling \
297
294
  edge is detected. For this reason a square wave pulse width will be set to \
298
- half the exposure time in the Pilatus case, and to the exposure time minus \
299
- a small drop (~100um) for the Eiger.
295
+ the exposure time minus a small drop (~100um) for the Eiger.
300
296
 
301
297
  Args:
302
298
  zebra (Zebra): The zebra ophyd device.
303
- det_type (str): Detector in use, current choices are Eiger or Pilatus.
299
+ det_type (str): Detector in use.
304
300
  num_gates (int): Number of apertures to visit in a chip.
305
301
  num_exposures (int): Number of times data is collected in each aperture.
306
302
  exposure_time_s (float): Exposure time for each shot.
@@ -335,10 +331,6 @@ def setup_zebra_for_fastchip_plan(
335
331
  yield from bps.abs_set(
336
332
  zebra.output.out_pvs[TTL_EIGER], zebra.mapping.sources.AND3, group=group
337
333
  )
338
- if det_type == "pilatus":
339
- yield from bps.abs_set(
340
- zebra.output.out_pvs[TTL_PILATUS], zebra.mapping.sources.AND3, group=group
341
- )
342
334
 
343
335
  # Square wave - needs a small drop to make it work for eiger
344
336
  pulse_width = (
@@ -13,7 +13,6 @@ from dodal.devices.i24.beamstop import Beamstop
13
13
  from dodal.devices.i24.dcm import DCM
14
14
  from dodal.devices.i24.dual_backlight import BacklightPositions, DualBacklight
15
15
  from dodal.devices.i24.focus_mirrors import FocusMirrorsMode
16
- from dodal.devices.i24.pilatus_metadata import PilatusMetadata
17
16
  from dodal.devices.i24.pmac import PMAC
18
17
  from dodal.devices.motors import YZStage
19
18
  from dodal.devices.oav.oav_detector import OAVBeamCentreFile
@@ -39,14 +38,13 @@ from mx_bluesky.beamlines.i24.serial.log import (
39
38
  _read_visit_directory_from_file,
40
39
  )
41
40
  from mx_bluesky.beamlines.i24.serial.parameters import (
42
- DetectorName,
43
41
  FixedTargetParameters,
44
42
  get_chip_format,
45
43
  )
46
44
  from mx_bluesky.beamlines.i24.serial.parameters.utils import EmptyMapError
47
45
  from mx_bluesky.beamlines.i24.serial.setup_beamline import pv
48
46
  from mx_bluesky.beamlines.i24.serial.setup_beamline.ca import caput
49
- from mx_bluesky.beamlines.i24.serial.setup_beamline.pv_abstract import Eiger, Pilatus
47
+ from mx_bluesky.beamlines.i24.serial.setup_beamline.pv_abstract import Eiger
50
48
  from mx_bluesky.beamlines.i24.serial.setup_beamline.setup_detector import (
51
49
  _move_detector_stage,
52
50
  get_detector_type,
@@ -103,10 +101,10 @@ def gui_sleep(sec: int) -> MsgGenerator:
103
101
 
104
102
  @bpp.run_decorator()
105
103
  def gui_move_detector(
106
- det: Literal["eiger", "pilatus"],
104
+ det: Literal["eiger"],
107
105
  detector_stage: YZStage = inject("detector_motion"),
108
106
  ) -> MsgGenerator:
109
- det_y_target = Eiger.det_y_target if det == "eiger" else Pilatus.det_y_target
107
+ det_y_target = Eiger.det_y_target
110
108
  yield from _move_detector_stage(detector_stage, det_y_target)
111
109
  # Make the output readable
112
110
  SSX_LOGGER.debug(f"Detector move done, resetting general PV to {det}")
@@ -138,9 +136,7 @@ def gui_run_chip_collection(
138
136
  shutter: HutchShutter = inject("shutter"),
139
137
  dcm: DCM = inject("dcm"),
140
138
  mirrors: FocusMirrorsMode = inject("focus_mirrors"),
141
- beam_center_pilatus: DetectorBeamCenter = inject("pilatus_bc"),
142
139
  beam_center_eiger: DetectorBeamCenter = inject("eiger_bc"),
143
- pilatus_metadata: PilatusMetadata = inject("pilatus_meta"),
144
140
  ) -> MsgGenerator:
145
141
  """Set the parameter model for the data collection.
146
142
 
@@ -210,11 +206,7 @@ def gui_run_chip_collection(
210
206
  if parameters.chip_map:
211
207
  yield from upload_chip_map_to_geobrick(pmac, parameters.chip_map)
212
208
 
213
- beam_center_device = (
214
- beam_center_eiger
215
- if parameters.detector_name is DetectorName.EIGER
216
- else beam_center_pilatus
217
- )
209
+ beam_center_device = beam_center_eiger
218
210
  SSX_LOGGER.info("Beam center device ready")
219
211
 
220
212
  # DCID instance - do not create yet
@@ -234,5 +226,4 @@ def gui_run_chip_collection(
234
226
  beam_center_device,
235
227
  parameters,
236
228
  dcid,
237
- pilatus_metadata,
238
229
  )
@@ -35,8 +35,9 @@ def call_nexgen(
35
35
  start_time (datetime): Collection start time.
36
36
 
37
37
  Raises:
38
- ValueError: For a wrong experiment type passed (either unknwon or not matched \
38
+ ValueError: For a wrong experiment type passed (either unknown or not matched \
39
39
  to parameter model).
40
+ HTTPError: For a problem with reponse from server
40
41
 
41
42
  """
42
43
  current_chip_map = None
@@ -75,10 +76,6 @@ def call_nexgen(
75
76
  f"Call to nexgen server with the following chip definition: \n{chip_prog_dict}"
76
77
  )
77
78
 
78
- access_token = pathlib.Path("/scratch/ssx_nexgen.key").read_text().strip()
79
- url = "https://ssx-nexgen.diamond.ac.uk/ssx_eiger/write"
80
- headers = {"Authorization": f"Bearer {access_token}"}
81
-
82
79
  payload = {
83
80
  "beamline": "i24",
84
81
  "beam_center": beam_center_in_pix,
@@ -98,8 +95,36 @@ def call_nexgen(
98
95
  "bit_depth": bit_depth,
99
96
  "start_time": start_time.isoformat(),
100
97
  }
101
- SSX_LOGGER.info(f"Sending POST request to {url} with payload:")
102
- SSX_LOGGER.info(pprint.pformat(payload))
103
- response = requests.post(url, headers=headers, json=payload)
104
- response.raise_for_status()
98
+ submit_to_server(payload)
99
+
100
+
101
+ def submit_to_server(
102
+ payload: dict | None,
103
+ ):
104
+ """Submit the payload to nexgen-server.
105
+
106
+ Args:
107
+ payload (dict): Dictionary of parameters to send to nex-gen server
108
+
109
+ Raises:
110
+ ValueError: For a wrong experiment type passed (either unknown or not matched \
111
+ to parameter model).
112
+ HTTPError: For a problem with reponse from server
113
+
114
+ """
115
+ access_token = pathlib.Path("/scratch/ssx_nexgen.key").read_text().strip()
116
+ url = "https://ssx-nexgen.diamond.ac.uk/ssx_eiger/write"
117
+ headers = {"Authorization": f"Bearer {access_token}"}
118
+
119
+ try:
120
+ SSX_LOGGER.info(f"Sending POST request to {url} with payload:")
121
+ SSX_LOGGER.info(pprint.pformat(payload))
122
+ response = requests.post(url, headers=headers, json=payload)
123
+ response.raise_for_status()
124
+ except requests.HTTPError as e:
125
+ SSX_LOGGER.error(f"Nexus writer failed. Reason from server {e}")
126
+ raise
127
+ except Exception as e:
128
+ SSX_LOGGER.exception(f"Error generating nexus file: {e}")
129
+ raise
105
130
  SSX_LOGGER.info(f"Response: {response.text} (status code: {response.status_code})")
@@ -9,6 +9,7 @@ import bluesky.preprocessors as bpp
9
9
  import numpy as np
10
10
  from bluesky.protocols import Readable
11
11
  from bluesky.utils import MsgGenerator
12
+ from dodal.common.beamlines.commissioning_mode import read_commissioning_mode
12
13
  from dodal.devices.fast_grid_scan import (
13
14
  FastGridScanCommon,
14
15
  )
@@ -226,11 +227,33 @@ def _fetch_xrc_results_from_zocalo(
226
227
  for xr in filtered_results
227
228
  ]
228
229
  else:
229
- LOGGER.warning("No X-ray centre received")
230
- raise CrystalNotFoundException()
230
+ commissioning_mode = yield from read_commissioning_mode()
231
+ if commissioning_mode:
232
+ LOGGER.info("Commissioning mode enabled, returning dummy result")
233
+ flyscan_results = [_generate_dummy_xrc_result(parameters)]
234
+ else:
235
+ LOGGER.warning("No X-ray centre received")
236
+ raise CrystalNotFoundException()
231
237
  yield from _fire_xray_centre_result_event(flyscan_results)
232
238
 
233
239
 
240
+ def _generate_dummy_xrc_result(params: SpecifiedThreeDGridScan) -> XRayCentreResult:
241
+ com = [params.x_steps / 2, params.y_steps / 2, params.z_steps / 2]
242
+ max_voxel = [round(p) for p in com]
243
+ return _xrc_result_in_boxes_to_result_in_mm(
244
+ XrcResult(
245
+ centre_of_mass=com,
246
+ max_voxel=max_voxel,
247
+ bounding_box=[max_voxel, [p + 1 for p in max_voxel]],
248
+ n_voxels=1,
249
+ max_count=10000,
250
+ total_count=100000,
251
+ sample_id=params.sample_id,
252
+ ),
253
+ params,
254
+ )
255
+
256
+
234
257
  @bpp.set_run_key_decorator(PlanNameConstants.GRIDSCAN_MAIN)
235
258
  @bpp.run_decorator(md={"subplan_name": PlanNameConstants.GRIDSCAN_MAIN})
236
259
  def run_gridscan(
@@ -186,7 +186,7 @@ class BaseISPyBCallback(PlanReactiveCallback):
186
186
  pass
187
187
 
188
188
  def activity_gated_stop(self, doc: RunStop) -> RunStop:
189
- """Subclasses must check that they are recieving a stop document for the correct
189
+ """Subclasses must check that they are receiving a stop document for the correct
190
190
  uid to use this method!"""
191
191
  assert self.ispyb is not None, (
192
192
  "ISPyB handler received stop document, but deposition object doesn't exist!"
@@ -24,8 +24,8 @@ class PlanReactiveCallback(CallbackBase):
24
24
  metadata to trigger this.
25
25
  The run_decorator of the plan should include in its metadata dictionary the key
26
26
  'activate callbacks', with a list of strings of the callback class(es) to
27
- activate or deactivate. On a recieving a start doc which specifies this, this
28
- class will be activated, and on recieving the stop document for the
27
+ activate or deactivate. On a receiving a start doc which specifies this, this
28
+ class will be activated, and on receiving the stop document for the
29
29
  corresponding uid it will deactivate. The ordinary 'start', 'descriptor',
30
30
  'event' and 'stop' methods will be triggered as normal, and will in turn trigger
31
31
  'activity_gated_' methods - to preserve this functionality, subclasses which
@@ -69,8 +69,8 @@ ispyb_activation_decorator = make_decorator(ispyb_activation_wrapper)
69
69
  class GridscanISPyBCallback(BaseISPyBCallback):
70
70
  """Callback class to handle the deposition of experiment parameters into the ISPyB
71
71
  database. Listens for 'event' and 'descriptor' documents. Creates the ISpyB entry on
72
- recieving an 'event' document for the 'ispyb_reading_hardware' event, and updates the
73
- deposition on recieving its final 'stop' document.
72
+ receiving an 'event' document for the 'ispyb_reading_hardware' event, and updates the
73
+ deposition on receiving its final 'stop' document.
74
74
 
75
75
  To use, subscribe the Bluesky RunEngine to an instance of this class.
76
76
  E.g.:
@@ -24,10 +24,10 @@ T = TypeVar("T", bound="SpecifiedThreeDGridScan")
24
24
 
25
25
  class GridscanNexusFileCallback(PlanReactiveCallback):
26
26
  """Callback class to handle the creation of Nexus files based on experiment \
27
- parameters. Initialises on recieving a 'start' document for the \
27
+ parameters. Initialises on receiving a 'start' document for the \
28
28
  'run_gridscan_move_and_tidy' sub plan, which must also contain the run parameters, \
29
29
  as metadata under the 'hyperion_internal_parameters' key. Actually writes the \
30
- nexus files on updates the timestamps on recieving the 'ispyb_reading_hardware' event \
30
+ nexus files on updates the timestamps on receiving the 'ispyb_reading_hardware' event \
31
31
  document, and finalises the files on getting a 'stop' document for the whole run.
32
32
 
33
33
  To use, subscribe the Bluesky RunEngine to an instance of this class.
@@ -231,6 +231,7 @@ class DiffractionExperimentWithSample(DiffractionExperiment, WithSample): ...
231
231
 
232
232
  class MultiXtalSelection(BaseModel):
233
233
  name: str
234
+ ignore_xtal_not_found: bool = False
234
235
 
235
236
 
236
237
  class TopNByMaxCountSelection(MultiXtalSelection):
@@ -1,4 +1,5 @@
1
1
  import json
2
+ import signal
2
3
  import threading
3
4
  from dataclasses import asdict
4
5
  from sys import argv
@@ -32,9 +33,10 @@ from mx_bluesky.hyperion.parameters.cli import (
32
33
  HyperionMode,
33
34
  parse_cli_args,
34
35
  )
35
- from mx_bluesky.hyperion.parameters.constants import CONST
36
+ from mx_bluesky.hyperion.parameters.constants import CONST, HyperionConstants
36
37
  from mx_bluesky.hyperion.parameters.load_centre_collect import LoadCentreCollect
37
38
  from mx_bluesky.hyperion.plan_runner import PlanRunner
39
+ from mx_bluesky.hyperion.plan_runner_api import create_server_for_udc
38
40
  from mx_bluesky.hyperion.runner import (
39
41
  GDARunner,
40
42
  StatusAndMessage,
@@ -170,7 +172,7 @@ def main():
170
172
  """Main application entry point."""
171
173
  args = parse_cli_args()
172
174
  initialise_globals(args)
173
- hyperion_port = 5005
175
+ hyperion_port = HyperionConstants.HYPERION_PORT
174
176
  context = setup_context(dev_mode=args.dev_mode)
175
177
 
176
178
  if args.mode == HyperionMode.GDA:
@@ -188,7 +190,18 @@ def main():
188
190
  )
189
191
  runner.wait_on_queue()
190
192
  else:
191
- run_forever(PlanRunner(context))
193
+ plan_runner = PlanRunner(context, args.dev_mode)
194
+ create_server_for_udc(plan_runner)
195
+ _register_sigterm_handler(plan_runner)
196
+ run_forever(plan_runner)
197
+
198
+
199
+ def _register_sigterm_handler(runner: PlanRunner):
200
+ def shutdown_on_sigterm(sig_num, frame):
201
+ LOGGER.info("Received SIGTERM, shutting down...")
202
+ runner.shutdown()
203
+
204
+ signal.signal(signal.SIGTERM, shutdown_on_sigterm)
192
205
 
193
206
 
194
207
  if __name__ == "__main__":
@@ -6,12 +6,22 @@ from blueapi.core.context import BlueskyContext
6
6
  from bluesky import plan_stubs as bps
7
7
  from bluesky import preprocessors as bpp
8
8
  from bluesky.utils import MsgGenerator, RunEngineInterrupted
9
+ from dodal.common.beamlines.commissioning_mode import set_commissioning_signal
10
+ from dodal.devices.aperturescatterguard import ApertureScatterguard
9
11
  from dodal.devices.baton import Baton
12
+ from dodal.devices.motors import XYZStage
13
+ from dodal.devices.robot import BartRobot
14
+ from dodal.devices.smargon import Smargon
10
15
 
16
+ from mx_bluesky.common.device_setup_plans.robot_load_unload import robot_unload
11
17
  from mx_bluesky.common.experiment_plans.inner_plans.udc_default_state import (
12
18
  UDCDefaultDevices,
13
19
  move_to_udc_default_state,
14
20
  )
21
+ from mx_bluesky.common.external_interaction.alerting import (
22
+ AlertService,
23
+ get_alerting_service,
24
+ )
15
25
  from mx_bluesky.common.parameters.components import MxBlueskyParameters
16
26
  from mx_bluesky.common.utils.context import (
17
27
  device_composite_from_context,
@@ -25,6 +35,7 @@ from mx_bluesky.hyperion.experiment_plans.load_centre_collect_full_plan import (
25
35
  from mx_bluesky.hyperion.external_interaction.agamemnon import (
26
36
  create_parameters_from_agamemnon,
27
37
  )
38
+ from mx_bluesky.hyperion.external_interaction.alerting.constants import Subjects
28
39
  from mx_bluesky.hyperion.parameters.components import Wait
29
40
  from mx_bluesky.hyperion.parameters.load_centre_collect import LoadCentreCollect
30
41
  from mx_bluesky.hyperion.plan_runner import PlanException, PlanRunner
@@ -72,6 +83,7 @@ def run_udc_when_requested(context: BlueskyContext, runner: PlanRunner):
72
83
 
73
84
  def acquire_baton() -> MsgGenerator:
74
85
  yield from _wait_for_hyperion_requested(baton)
86
+ LOGGER.debug("Hyperion is now current baton holder.")
75
87
  yield from bps.abs_set(baton.current_user, HYPERION_USER)
76
88
 
77
89
  def collect() -> MsgGenerator:
@@ -86,29 +98,37 @@ def run_udc_when_requested(context: BlueskyContext, runner: PlanRunner):
86
98
  baton: The baton device
87
99
  runner: The runner
88
100
  """
101
+ _raise_udc_start_alert(get_alerting_service())
89
102
  yield from _move_to_udc_default_state(context)
90
103
 
91
104
  # re-fetch the baton because the device has been reinstantiated
92
105
  baton = _get_baton(context)
106
+ current_visit: str | None = None
93
107
  while (yield from _is_requesting_baton(baton)):
94
- yield from _fetch_and_process_agamemnon_instruction(baton, runner)
108
+ current_visit = yield from _fetch_and_process_agamemnon_instruction(
109
+ baton, runner, current_visit
110
+ )
111
+ if current_visit:
112
+ yield from _perform_robot_unload(runner.context, current_visit)
95
113
 
96
114
  def release_baton() -> MsgGenerator:
97
115
  # If hyperion has given up the baton itself we need to also release requested
98
116
  # user so that hyperion doesn't think we're requested again
99
117
  baton = _get_baton(context)
100
- yield from _safely_release_baton(baton)
101
- yield from bps.abs_set(baton.current_user, NO_USER)
118
+ previous_requested_user = yield from _unrequest_baton(baton)
119
+ LOGGER.debug("Hyperion no longer current baton holder.")
120
+ yield from bps.abs_set(baton.current_user, NO_USER, wait=True)
121
+ _raise_baton_released_alert(get_alerting_service(), previous_requested_user)
102
122
 
103
123
  def collect_then_release() -> MsgGenerator:
104
124
  yield from bpp.contingency_wrapper(collect(), final_plan=release_baton)
105
125
 
106
126
  context.run_engine(acquire_baton())
107
- _initialise_udc(context)
127
+ _initialise_udc(context, runner.is_dev_mode)
108
128
  context.run_engine(collect_then_release())
109
129
 
110
130
 
111
- def _initialise_udc(context: BlueskyContext):
131
+ def _initialise_udc(context: BlueskyContext, dev_mode: bool):
112
132
  """
113
133
  Perform all initialisation that happens at the start of UDC just after the
114
134
  baton is acquired, but before we execute any plans or move hardware.
@@ -118,21 +138,25 @@ def _initialise_udc(context: BlueskyContext):
118
138
  """
119
139
  LOGGER.info("Initialising mx-bluesky for UDC start...")
120
140
  clear_all_device_caches(context)
121
- setup_devices(context, False)
141
+ LOGGER.debug("Reinitialising beamline devices")
142
+ setup_devices(context, dev_mode)
143
+ set_commissioning_signal(_get_baton(context).commissioning)
122
144
 
123
145
 
124
146
  def _wait_for_hyperion_requested(baton: Baton):
147
+ LOGGER.debug("Hyperion waiting for baton...")
125
148
  SLEEP_PER_CHECK = 0.1
126
149
  while True:
127
150
  requested_user = yield from bps.rd(baton.requested_user)
128
151
  if requested_user == HYPERION_USER:
152
+ LOGGER.debug("Baton requested for Hyperion")
129
153
  break
130
154
  yield from bps.sleep(SLEEP_PER_CHECK)
131
155
 
132
156
 
133
157
  def _fetch_and_process_agamemnon_instruction(
134
- baton: Baton, runner: PlanRunner
135
- ) -> MsgGenerator:
158
+ baton: Baton, runner: PlanRunner, current_visit: str | None
159
+ ) -> MsgGenerator[str | None]:
136
160
  parameter_list: Sequence[MxBlueskyParameters] = create_parameters_from_agamemnon()
137
161
  if parameter_list:
138
162
  for parameters in parameter_list:
@@ -141,6 +165,7 @@ def _fetch_and_process_agamemnon_instruction(
141
165
  )
142
166
  match parameters:
143
167
  case LoadCentreCollect():
168
+ current_visit = parameters.visit
144
169
  devices: Any = create_devices(runner.context)
145
170
  yield from runner.execute_plan(
146
171
  partial(load_centre_collect_full, devices, parameters)
@@ -152,8 +177,33 @@ def _fetch_and_process_agamemnon_instruction(
152
177
  f"Unsupported instruction decoded from agamemnon {type(parameters)}"
153
178
  )
154
179
  else:
180
+ _raise_udc_completed_alert(get_alerting_service())
155
181
  # Release the baton for orderly exit from the instruction loop
156
- yield from _safely_release_baton(baton)
182
+ yield from _unrequest_baton(baton)
183
+ return current_visit
184
+
185
+
186
+ def _raise_udc_start_alert(alert_service: AlertService):
187
+ alert_service.raise_alert(
188
+ Subjects.UDC_STARTED, "Unattended Data Collection has started.", {}
189
+ )
190
+
191
+
192
+ def _raise_baton_released_alert(alert_service: AlertService, baton_requester: str):
193
+ alert_service.raise_alert(
194
+ Subjects.UDC_BATON_RELEASED,
195
+ f"Hyperion has released the baton. The baton is currently requested by:"
196
+ f" {baton_requester}",
197
+ {},
198
+ )
199
+
200
+
201
+ def _raise_udc_completed_alert(alert_service: AlertService):
202
+ alert_service.raise_alert(
203
+ Subjects.UDC_COMPLETED,
204
+ "Hyperion UDC has completed all pending Agamemnon requests.",
205
+ {},
206
+ )
157
207
 
158
208
 
159
209
  def _runner_sleep(parameters: Wait) -> MsgGenerator:
@@ -174,9 +224,26 @@ def _get_baton(context: BlueskyContext) -> Baton:
174
224
  return find_device_in_context(context, "baton", Baton)
175
225
 
176
226
 
177
- def _safely_release_baton(baton: Baton) -> MsgGenerator:
227
+ def _unrequest_baton(baton: Baton) -> MsgGenerator[str]:
178
228
  """Relinquish the requested user of the baton if it is not already requested
179
- by another user."""
229
+ by another user.
230
+
231
+ Returns:
232
+ The previously requested user, or NO_USER if no user was already requested.
233
+ """
180
234
  requested_user = yield from bps.rd(baton.requested_user)
181
235
  if requested_user == HYPERION_USER:
236
+ LOGGER.debug("Hyperion no longer requesting baton")
182
237
  yield from bps.abs_set(baton.requested_user, NO_USER)
238
+ return NO_USER
239
+ return requested_user
240
+
241
+
242
+ def _perform_robot_unload(context: BlueskyContext, visit: str) -> MsgGenerator:
243
+ robot = find_device_in_context(context, "robot", BartRobot)
244
+ smargon = find_device_in_context(context, "smargon", Smargon)
245
+ aperture_scatterguard = find_device_in_context(
246
+ context, "aperture_scatterguard", ApertureScatterguard
247
+ )
248
+ lower_gonio = find_device_in_context(context, "lower_gonio", XYZStage)
249
+ yield from robot_unload(robot, smargon, aperture_scatterguard, lower_gonio, visit)
@@ -8,11 +8,13 @@ import pydantic
8
8
  from blueapi.core import BlueskyContext
9
9
  from bluesky.preprocessors import run_decorator, set_run_key_decorator, subs_wrapper
10
10
  from bluesky.utils import MsgGenerator
11
+ from dodal.devices.baton import Baton
11
12
  from dodal.devices.oav.oav_parameters import OAVParameters
12
13
 
13
14
  import mx_bluesky.common.xrc_result as flyscan_result
14
15
  from mx_bluesky.common.parameters.components import WithSnapshot
15
16
  from mx_bluesky.common.utils.context import device_composite_from_context
17
+ from mx_bluesky.common.utils.exceptions import CrystalNotFoundException
16
18
  from mx_bluesky.common.utils.log import LOGGER
17
19
  from mx_bluesky.common.xrc_result import XRayCentreEventHandler
18
20
  from mx_bluesky.hyperion.experiment_plans.robot_load_then_centre_plan import (
@@ -36,6 +38,8 @@ from mx_bluesky.hyperion.parameters.rotation import RotationScanPerSweep
36
38
  class LoadCentreCollectComposite(RobotLoadThenCentreComposite, RotationScanComposite):
37
39
  """Composite that provides access to the required devices."""
38
40
 
41
+ baton: Baton
42
+
39
43
 
40
44
  def create_devices(context: BlueskyContext) -> LoadCentreCollectComposite:
41
45
  """Create the necessary devices for the plan."""
@@ -51,8 +55,9 @@ def load_centre_collect_full(
51
55
  * Load the sample if necessary
52
56
  * Move to the specified goniometer start angles
53
57
  * Perform optical centring, then X-ray centring
54
- * If X-ray centring finds a diffracting centre then move to that centre and
55
- * do a collection with the specified parameters.
58
+ * If X-ray centring finds one or more diffracting centres then for each centre
59
+ that satisfies the chosen selection function,
60
+ move to that centre and do a collection with the specified parameters.
56
61
  """
57
62
 
58
63
  get_hyperion_config_client().refresh_cache()
@@ -81,12 +86,18 @@ def load_centre_collect_full(
81
86
  )
82
87
  def plan_with_callback_subs():
83
88
  flyscan_event_handler = XRayCentreEventHandler()
84
- yield from subs_wrapper(
85
- robot_load_then_xray_centre(
86
- composite, parameters.robot_load_then_centre, oav_config_file
87
- ),
88
- flyscan_event_handler,
89
- )
89
+ try:
90
+ yield from subs_wrapper(
91
+ robot_load_then_xray_centre(
92
+ composite, parameters.robot_load_then_centre, oav_config_file
93
+ ),
94
+ flyscan_event_handler,
95
+ )
96
+ except CrystalNotFoundException:
97
+ if parameters.select_centres.ignore_xtal_not_found:
98
+ LOGGER.info("Ignoring crystal not found due to parameter settings.")
99
+ else:
100
+ raise
90
101
 
91
102
  locations_to_collect_um: list[np.ndarray]
92
103
  samples_to_collect: list[int]
@@ -1,5 +1,6 @@
1
1
  import dataclasses
2
2
  import json
3
+ import os
3
4
  import re
4
5
  import traceback
5
6
  from collections.abc import Sequence
@@ -27,7 +28,6 @@ from mx_bluesky.hyperion.parameters.components import Wait
27
28
  from mx_bluesky.hyperion.parameters.load_centre_collect import LoadCentreCollect
28
29
 
29
30
  T = TypeVar("T", bound=WithVisit)
30
- AGAMEMNON_URL = "http://agamemnon.diamond.ac.uk/"
31
31
  MULTIPIN_PREFIX = "multipin"
32
32
  MULTIPIN_FORMAT_DESC = "Expected multipin format is multipin_{number_of_wells}x{well_size}+{distance_between_tip_and_first_well}"
33
33
  MULTIPIN_REGEX = rf"^{MULTIPIN_PREFIX}_(\d+)x(\d+(?:\.\d+)?)\+(\d+(?:\.\d+)?)$"
@@ -191,7 +191,11 @@ def _get_pin_type_from_agamemnon_collect_parameters(
191
191
 
192
192
 
193
193
  def _get_next_instruction(beamline: str) -> dict:
194
- return _get_parameters_from_url(AGAMEMNON_URL + f"getnextcollect/{beamline}")
194
+ return _get_parameters_from_url(get_agamemnon_url() + f"getnextcollect/{beamline}")
195
+
196
+
197
+ def get_agamemnon_url() -> str:
198
+ return os.environ.get("AGAMEMNON_URL", "http://agamemnon.diamond.ac.uk/")
195
199
 
196
200
 
197
201
  def _get_withvisit_parameters_from_agamemnon(parameters: dict) -> tuple:
@@ -3,10 +3,5 @@ from enum import StrEnum
3
3
 
4
4
  class Subjects(StrEnum):
5
5
  UDC_STARTED = "UDC Started"
6
- UDC_BATON_PASSED = "UDC Baton was passed"
7
- UDC_RESUMED_OPERATION = "UDC Resumed operation"
8
- UDC_SUSPENDED_OPERATION = "UDC Suspended operation"
9
- NEW_CONTAINER = "Hyperion is collecting from a new container"
10
- NEW_VISIT = "Hyperion has changed visit"
11
- SAMPLE_ERROR = "Hyperion has encountered a sample error"
12
- BEAMLINE_ERROR = "Hyperion has encountered a beamline error"
6
+ UDC_BATON_RELEASED = "UDC Baton was released"
7
+ UDC_COMPLETED = "UDC Completed"
@@ -34,8 +34,8 @@ if TYPE_CHECKING:
34
34
  class RotationISPyBCallback(BaseISPyBCallback):
35
35
  """Callback class to handle the deposition of experiment parameters into the ISPyB
36
36
  database. Listens for 'event' and 'descriptor' documents. Creates the ISpyB entry on
37
- recieving an 'event' document for the 'ispyb_reading_hardware' event, and updates the
38
- deposition on recieving its final 'stop' document.
37
+ receiving an 'event' document for the 'ispyb_reading_hardware' event, and updates the
38
+ deposition on receiving its final 'stop' document.
39
39
 
40
40
  To use, subscribe the Bluesky RunEngine to an instance of this class.
41
41
  E.g.: