Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1051 from DiamondLightSource/1049_hotfixes_from_r…
Browse files Browse the repository at this point in the history
…obot_load_testing

Fix issues in robot load found in testing
  • Loading branch information
DominicOram authored Dec 18, 2023
2 parents 3b69e90 + 1fa1436 commit 442ceb6
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/hyperion/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def put(self, plan_name: str, action: Actions):
)
if plan is None:
raise PlanNotFound(
f"Experiment plan '{plan_name}' has no 'run' method."
f"Experiment plan '{plan_name}' not found in context. Context has {self.context.plan_functions.keys()}"
)

parameters = experiment_internal_param_type.from_json(request.data)
Expand Down
4 changes: 4 additions & 0 deletions src/hyperion/experiment_plans/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
pin_tip_centre_then_xray_centre,
)
from hyperion.experiment_plans.rotation_scan_plan import rotation_scan
from hyperion.experiment_plans.wait_for_robot_load_then_centre_plan import (
wait_for_robot_load_then_centre,
)

__all__ = [
"flyscan_xray_centre",
"grid_detect_then_xray_centre",
"rotation_scan",
"pin_tip_centre_then_xray_centre",
"wait_for_robot_load_then_centre",
]
11 changes: 11 additions & 0 deletions src/hyperion/experiment_plans/experiment_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
grid_detect_then_xray_centre_plan,
pin_centre_then_xray_centre_plan,
stepped_grid_scan_plan,
wait_for_robot_load_then_centre_plan,
)
from hyperion.external_interaction.callbacks.abstract_plan_callback_collection import (
NullPlanCallbackCollection,
Expand Down Expand Up @@ -39,6 +40,10 @@
SteppedGridScanInternalParameters,
SteppedGridScanParams,
)
from hyperion.parameters.plan_specific.wait_for_robot_load_then_center_params import (
WaitForRobotLoadThenCentreInternalParameters,
WaitForRobotLoadThenCentreParams,
)


def not_implemented():
Expand Down Expand Up @@ -81,6 +86,12 @@ def do_nothing():
"experiment_param_type": SteppedGridScanParams,
"callback_collection_type": NullPlanCallbackCollection,
},
"wait_for_robot_load_then_centre": {
"setup": wait_for_robot_load_then_centre_plan.create_devices,
"internal_param_type": WaitForRobotLoadThenCentreInternalParameters,
"experiment_param_type": WaitForRobotLoadThenCentreParams,
"callback_collection_type": NullPlanCallbackCollection,
},
}
EXPERIMENT_NAMES = list(PLAN_REGISTRY.keys())
EXPERIMENT_TYPE_LIST = [p["experiment_param_type"] for p in PLAN_REGISTRY.values()]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import json
from typing import TYPE_CHECKING

import bluesky.plan_stubs as bps
from blueapi.core import BlueskyContext, MsgGenerator
Expand All @@ -15,17 +14,15 @@
GridDetectThenXRayCentreComposite,
)
from hyperion.experiment_plans.pin_centre_then_xray_centre_plan import (
pin_tip_centre_then_xray_centre,
pin_centre_then_xray_centre_plan,
)
from hyperion.log import LOGGER
from hyperion.parameters.plan_specific.pin_centre_then_xray_centre_params import (
PinCentreThenXrayCentreInternalParameters,
)

if TYPE_CHECKING:
from hyperion.parameters.plan_specific.wait_for_robot_load_then_center_params import (
WaitForRobotLoadThenCentreInternalParameters,
)
from hyperion.parameters.plan_specific.wait_for_robot_load_then_center_params import (
WaitForRobotLoadThenCentreInternalParameters,
)


def create_devices(context: BlueskyContext) -> GridDetectThenXRayCentreComposite:
Expand Down Expand Up @@ -61,7 +58,7 @@ def wait_for_robot_load_then_centre_plan(

params_json = json.loads(parameters.json())
pin_centre_params = PinCentreThenXrayCentreInternalParameters(**params_json)
yield from pin_tip_centre_then_xray_centre(composite, pin_centre_params)
yield from pin_centre_then_xray_centre_plan(composite, pin_centre_params)


def wait_for_robot_load_then_centre(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def activity_gated_event(self, doc: Event):

event_descriptor = self.descriptors[doc["descriptor"]]
if event_descriptor.get("name") == ISPYB_HARDWARE_READ_PLAN:
ISPYB_LOGGER.info("ISPyB handler received event from read hardware")
self.params.hyperion_params.ispyb_params.undulator_gap = doc["data"][
"undulator_current_gap"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def activity_gated_start(self, doc: dict):
if doc.get("subplan_name") == GRIDSCAN_OUTER_PLAN:
self.uid_to_finalize_on = doc.get("uid")
ISPYB_LOGGER.info(
"ISPyB callback recieved start document with experiment parameters and"
"ISPyB callback recieved start document with experiment parameters and "
f"uid: {self.uid_to_finalize_on}"
)
json_params = doc.get("hyperion_internal_parameters")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Any

import numpy as np
from dodal.devices.detector import TriggerMode
from dodal.devices.eiger import DetectorParams
from dodal.devices.detector import DetectorParams, TriggerMode
from dodal.parameters.experiment_parameter_base import AbstractExperimentParameterBase
from pydantic import validator
from pydantic.dataclasses import dataclass

Expand Down Expand Up @@ -34,7 +34,7 @@ class Config:


@dataclass
class WaitForRobotLoadThenCentreParams:
class WaitForRobotLoadThenCentreParams(AbstractExperimentParameterBase):
"""
Holder class for the parameters of a plan that waits for robot load then does a
centre.
Expand All @@ -45,6 +45,9 @@ class WaitForRobotLoadThenCentreParams:
omega_start: float
snapshot_dir: str

def get_num_images(self):
return 0


class WaitForRobotLoadThenCentreInternalParameters(InternalParameters):
experiment_params: WaitForRobotLoadThenCentreParams
Expand Down
2 changes: 2 additions & 0 deletions src/hyperion/utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ def setup_context(
fake_with_ophyd_sim=fake_with_ophyd_sim,
)

LOGGER.info(f"Plans found in context: {context.plan_functions.keys()}")

return context
1 change: 1 addition & 0 deletions tests/system_tests/hyperion/test_main_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,4 @@ def test_when_context_created_then_contains_expected_number_of_plans():
assert "rotation_scan" in plan_names
assert "flyscan_xray_centre" in plan_names
assert "pin_tip_centre_then_xray_centre" in plan_names
assert "wait_for_robot_load_then_centre" in plan_names
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"zocalo_environment": "artemis",
"beamline": "BL03I",
"insertion_prefix": "SR03S",
"experiment_type": "wait_for_robot_load_then_xray_centre",
"experiment_type": "wait_for_robot_load_then_centre",
"detector_params": {
"current_energy_ev": 100,
"directory": "/tmp/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dodal.devices.smargon import Smargon
from ophyd.sim import instantiate_fake_device

from hyperion.experiment_plans.wait_for_robot_load_then_centre import (
from hyperion.experiment_plans.wait_for_robot_load_then_centre_plan import (
wait_for_robot_load_then_centre,
)
from hyperion.parameters.external_parameters import from_file as raw_params_from_file
Expand All @@ -29,7 +29,7 @@ def wait_for_robot_load_then_centre_params():


@patch(
"hyperion.experiment_plans.wait_for_robot_load_then_centre.pin_tip_centre_then_xray_centre"
"hyperion.experiment_plans.wait_for_robot_load_then_centre_plan.pin_centre_then_xray_centre_plan"
)
def test_when_plan_run_then_centring_plan_run_with_expected_parameters(
mock_centring_plan: MagicMock,
Expand Down Expand Up @@ -83,7 +83,7 @@ def return_not_disabled_after_reads(_):

@pytest.mark.parametrize("total_disabled_reads", [5, 3, 14])
@patch(
"hyperion.experiment_plans.wait_for_robot_load_then_centre.pin_tip_centre_then_xray_centre"
"hyperion.experiment_plans.wait_for_robot_load_then_centre_plan.pin_centre_then_xray_centre_plan"
)
def test_given_smargon_disabled_when_plan_run_then_waits_on_smargon(
mock_centring_plan: MagicMock,
Expand All @@ -107,7 +107,7 @@ def test_given_smargon_disabled_when_plan_run_then_waits_on_smargon(


@patch(
"hyperion.experiment_plans.wait_for_robot_load_then_centre.pin_tip_centre_then_xray_centre"
"hyperion.experiment_plans.wait_for_robot_load_then_centre_plan.pin_centre_then_xray_centre_plan"
)
def test_given_smargon_disabled_for_longer_than_timeout_when_plan_run_then_throws_exception(
mock_centring_plan: MagicMock,
Expand All @@ -118,7 +118,7 @@ def test_given_smargon_disabled_for_longer_than_timeout_when_plan_run_then_throw


@patch(
"hyperion.experiment_plans.wait_for_robot_load_then_centre.pin_tip_centre_then_xray_centre"
"hyperion.experiment_plans.wait_for_robot_load_then_centre_plan.pin_centre_then_xray_centre_plan"
)
def test_when_plan_run_then_detector_arm_started_before_wait_on_robot_load(
mock_centring_plan: MagicMock,
Expand Down

0 comments on commit 442ceb6

Please sign in to comment.