Skip to content

Commit b45715f

Browse files
authored
Remove unused subplans and improve docs (#1548)
* Remove unused subplans and improve docs * Remove more unused plan names
1 parent 064fa8a commit b45715f

File tree

10 files changed

+34
-19
lines changed

10 files changed

+34
-19
lines changed

docs/developer/general/explanations/callback_and_run_logic.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ Currently, the requirement of needing to have written to ispyb is explicit as th
1313

1414
In general, the ordering flow of when callbacks are triggered is controlled by emitting documents with the expected plan name and data.
1515

16+
Xray Centring
17+
-------------
18+
The xray centring code generally has three parts; detect the grid to flyscan over, do the fast grid scan, collect the data from zocalo and move to the centre it defines. It does this with the following runs:
19+
20+
1. ``CONST.PLAN.GRID_DETECT_AND_DO_GRIDSCAN`` is the outer run. When this starts it will deposit the initial ispyb information (but more is added as the collection continues)
21+
2. ``CONST.PLAN.GRIDSCAN_OUTER`` is started after we have done the grid detection but before we do the work for setting up the gridscan. It is used to set transmission (and optionally feedback as per the selected preprocessors) and to initialise nexus writing (the final nexus file is only written when all the relevant data is read from the beamline)
22+
3. ``CONST.PLAN.DO_FGS`` is the internal run that is opened just before the actual gridscan motion happens. The start of this will create the data to send to zocalo, zocalo is then triggered once all the (zocalo triggered by the hardware read)
23+
4. ``CONST.PLAN.FLYSCAN_RESULTS`` is used to emit the results of the flyscan, that are then picked up by a ``XRayCentreEventHandler`` so that we can use them later in the plan.
24+
25+
1626
Rotation Scans
1727
---------------------
1828

@@ -23,3 +33,5 @@ It does this by starting 1+2*N different runs:
2333
1. ``CONST.PLAN.ROTATION_MULTI``: This is emitted once for the whole multiple rotation. It is used by the nexus callback to get the full number of images and meta_data_run_number so that it knows which hdf file to use. When this is finished zocalo end is triggered.
2434
2. ``CONST.PLAN.ROTATION_OUTER``: Emitted N times, inside a ``CONST.PLAN.ROTATION_MULTI`` run. This is used to create the initial ispyb deposition and create the nexus writer (but not actually write the file)
2535
3. ``CONST.PLAN.ROTATION_MAIN``: Emitted N times, inside ``CONST.PLAN.ROTATION_OUTER`` run. Used to finish writing to ispyb (i.e. write success/failure) and to send collection information to zocalo.
36+
37+
There is also a ``CONST.PLAN.ROTATION_MULTI_OUTER``, which is used when the rotation scan is run independently (i.e. outside of a bigger ``load_centre_collect``). This is needed as we need to activate the ``BeamDrawingCallback`` for this case.

src/mx_bluesky/beamlines/aithre_lasershaping/experiment_plans/robot_load_plan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def robot_load_and_snapshots_plan(
166166
],
167167
},
168168
),
169-
PlanNameConstants.ROBOT_LOAD_AND_SNAPSHOTS,
169+
PlanNameConstants.ROBOT_LOAD,
170170
)
171171

172172

src/mx_bluesky/common/experiment_plans/common_flyscan_xray_centre_plan.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ def _generate_dummy_xrc_result(params: SpecifiedThreeDGridScan) -> XRayCentreRes
256256
)
257257

258258

259-
@bpp.set_run_key_decorator(PlanNameConstants.GRIDSCAN_MAIN)
260-
@bpp.run_decorator(md={"subplan_name": PlanNameConstants.GRIDSCAN_MAIN})
261259
def run_gridscan(
262260
fgs_composite: FlyScanEssentialDevices,
263261
parameters: SpecifiedThreeDGridScan,

src/mx_bluesky/common/external_interaction/callbacks/xray_centre/ispyb_callback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def ispyb_activation_wrapper(plan_generator: MsgGenerator, parameters):
7171
"mx_bluesky_parameters": parameters.model_dump_json(),
7272
},
7373
),
74-
PlanNameConstants.ISPYB_ACTIVATION,
74+
PlanNameConstants.GRID_DETECT_AND_DO_GRIDSCAN,
7575
)
7676

7777

src/mx_bluesky/common/parameters/constants.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,28 @@ class OavConstants:
5656

5757
@dataclass(frozen=True)
5858
class PlanNameConstants:
59+
"""
60+
See https://diamondlightsource.github.io/mx-bluesky/main/developer/general/explanations/callback_and_run_logic.html
61+
for how these are used.
62+
"""
63+
64+
# UDC plan
5965
LOAD_CENTRE_COLLECT = "load_centre_collect"
6066
# Robot subplans
6167
ROBOT_LOAD = "robot_load"
6268
ROBOT_UNLOAD = "robot_unload"
63-
# Gridscan
69+
# Gridscan and xrc subplans
6470
GRID_DETECT_AND_DO_GRIDSCAN = "grid_detect_and_do_gridscan"
65-
GRID_DETECT_INNER = "grid_detect"
6671
GRIDSCAN_OUTER = "run_gridscan_move_and_tidy"
67-
GRIDSCAN_AND_MOVE = "run_gridscan_and_move"
68-
GRIDSCAN_MAIN = "run_gridscan"
6972
DO_FGS = "do_fgs"
70-
# IspyB callback activation
71-
ISPYB_ACTIVATION = "ispyb_activation"
72-
ROBOT_LOAD_AND_SNAPSHOTS = "robot_load_and_snapshots"
73+
FLYSCAN_RESULTS = "xray_centre_results"
7374
# Rotation scan
7475
ROTATION_MULTI = "multi_rotation_wrapper"
7576
ROTATION_MULTI_OUTER = "multi_rotation_outer"
7677
ROTATION_OUTER = "rotation_scan_with_cleanup"
7778
ROTATION_MAIN = "rotation_scan_main"
78-
FLYSCAN_RESULTS = "xray_centre_results"
79+
7980
SET_ENERGY = "set_energy"
80-
UNNAMED_RUN = "unnamed_run"
8181

8282

8383
@dataclass(frozen=True)

src/mx_bluesky/hyperion/experiment_plans/robot_load_and_change_energy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,5 @@ def robot_load_and_change_energy_plan(
174174
],
175175
},
176176
),
177-
CONST.PLAN.ROBOT_LOAD_AND_SNAPSHOTS,
177+
CONST.PLAN.ROBOT_LOAD,
178178
)

src/mx_bluesky/hyperion/experiment_plans/rotation_scan_plan.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ def rotation_scan(
260260
parameters: RotationScan,
261261
oav_params: OAVParameters | None = None,
262262
) -> MsgGenerator:
263+
"""This is intended to be the external API for doing the rotation scan on its own
264+
rather than part of a larger UDC-like collection. In the UDC case the
265+
BeamDrawingCallback will already be activated."""
266+
263267
@bpp.set_run_key_decorator(CONST.PLAN.ROTATION_MULTI_OUTER)
264268
@bpp.run_decorator(
265269
md={

tests/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,6 @@ def test_grid_detect_and_gridscan_start_document(self) -> RunStart:
13611361
"versions": {"ophyd": "1.6.4.post76+g0895f9f", "bluesky": "1.8.3"},
13621362
"scan_id": 1,
13631363
"plan_type": "generator",
1364-
"plan_name": "test",
13651364
"subplan_name": PlanNameConstants.GRID_DETECT_AND_DO_GRIDSCAN,
13661365
"mx_bluesky_parameters": _dummy_params(self._tmp_path).model_dump_json(),
13671366
}
@@ -1447,7 +1446,6 @@ def test_do_fgs_start_document(self) -> RunStart:
14471446
"versions": {"ophyd": "1.6.4.post76+g0895f9f", "bluesky": "1.8.3"},
14481447
"scan_id": 1,
14491448
"plan_type": "generator",
1450-
"plan_name": PlanNameConstants.GRIDSCAN_AND_MOVE,
14511449
"subplan_name": PlanNameConstants.DO_FGS,
14521450
"omega_to_scan_spec": {
14531451
GridscanPlane.OMEGA_XY: specs[0],

tests/unit_tests/common/experiment_plans/test_common_flyscan_xray_centre_plan.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from unittest.mock import MagicMock, call, patch
44

55
import bluesky.plan_stubs as bps
6+
import bluesky.preprocessors as bpp
67
import numpy as np
78
import pytest
89
from bluesky.run_engine import RunEngine, RunEngineResult
@@ -440,7 +441,9 @@ def test_when_grid_scan_fails_with_exception_then_detector_disarmed_and_correct_
440441

441442
with pytest.raises(CompleteError):
442443
run_engine(
443-
run_gridscan(fake_fgs_composite, test_fgs_params, beamline_specific)
444+
bpp.run_wrapper(
445+
run_gridscan(fake_fgs_composite, test_fgs_params, beamline_specific)
446+
)
444447
)
445448

446449
fake_fgs_composite.eiger.disable_roi_mode.assert_called()

tests/unit_tests/common/preprocessors/test_preprocessors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def first_unnamed_run():
267267
def second_unnamed_run():
268268
yield from bps.null()
269269

270-
@bpp.set_run_key_decorator(PlanNameConstants.GRID_DETECT_INNER)
270+
@bpp.set_run_key_decorator("test")
271271
@bpp.run_decorator()
272272
@pause_xbpm_feedback_during_collection_at_desired_transmission_decorator(
273273
devices=xbpm_and_transmission_wrapper_composite,
@@ -276,7 +276,7 @@ def second_unnamed_run():
276276
def first_named_run():
277277
yield from second_named_run()
278278

279-
@bpp.set_run_key_decorator(PlanNameConstants.GRID_DETECT_INNER)
279+
@bpp.set_run_key_decorator("test")
280280
@bpp.run_decorator()
281281
def second_named_run():
282282
yield from bps.null()

0 commit comments

Comments
 (0)