fix: spelling
CI / lint (push) Successful in 29s
CI / test (3.12) (push) Failing after 32s
CI / test (3.14) (push) Canceled after 34s
CI / test-with-coverage (push) Failing after 35s
CI / coverage-analysis (push) Skipped
CI / test (3.13) (push) Canceled after 36s

This commit is contained in:
perl_d committed 2026-10-30 12:27:21 +01:00
1 parent 96ebf7be78
commit b9ba72a535
7 files changed
+56 -57

No files matched your search

+1 -2
View File
@@ -29,7 +29,7 @@ class MXAutomationActor(SubscriptionActor, ABC):
"""
config_key: ClassVar[str]
"""Unique key used to build this actor's config endpoints, e.g. "optical_centring"."""
"""Unique key used to build this actor's config endpoints, e.g. "optical_centering"."""
def __init__(self, client: AareBec, name: str, exec_id: str):
# TODO aare protocols for aare actors which take only the aare client
@@ -63,7 +63,6 @@ class MXAutomationActor(SubscriptionActor, ABC):
def action(self, client: AareBec, sample_id: int) -> None:
"""What to do when `.condition()` evaluates `True`."""
@abstractmethod
def _action(self, client: AareBec) -> None:
assert self.last_message is not None
sample_id = self.last_message.sample_id
+12 -12
View File
@@ -16,10 +16,10 @@ from aare_bec_proto.service import AareBec
logger = bec_logger.logger
class OnSampleMountedRunOpticalCentring(MXAutomationActor):
"""When a sample is mounted, run optical centring. Only runs if mounting reported success."""
class OnSampleMountedRunOpticalCentering(MXAutomationActor):
"""When a sample is mounted, run optical centering. Only runs if mounting reported success."""
config_key = "optical_centring_on_mount"
config_key = "optical_centering_on_mount"
def default_monitor_endpoints(self) -> set[EndpointInfo[type[MXMeasurementSequenceMessage]]]:
return {StateEndpoints.sample_mounted()}
@@ -28,25 +28,25 @@ class OnSampleMountedRunOpticalCentring(MXAutomationActor):
return self.last_message is not None and self.last_message.success
def action(self, client: AareBec, sample_id: int) -> None:
logger.info(f"{self.name}: running optical centring for sample {sample_id}")
client.tasks.run_optical_centring(sample_id)
logger.info(f"{self.name}: running optical centering for sample {sample_id}")
client.tasks.run_optical_centering(sample_id)
class OnOpticalCentringDoneRunXrayCentring(MXAutomationActor):
"""When optical centring finished, run X-ray centring. Runs regardless of success."""
class OnOpticalCenteringDoneRunXrayCentering(MXAutomationActor):
"""When optical centering finished, run X-ray centering. Runs regardless of success."""
config_key = "xray_centring_after_optical"
config_key = "xray_centering_after_optical"
def default_monitor_endpoints(self) -> set[EndpointInfo[type[MXMeasurementSequenceMessage]]]:
return {StateEndpoints.optical_centring_done()}
return {StateEndpoints.optical_centering_done()}
def condition(self, client: AareBec) -> bool:
return self.last_message is not None
def action(self, client: AareBec, sample_id: int) -> None:
logger.info(f"{self.name}: running X-ray centring for sample {sample_id}")
# TODO: replace with the real centring procedure; publish the milestone from there.
logger.info(f"{self.name}: running X-ray centering for sample {sample_id}")
# TODO: replace with the real centering procedure; publish the milestone from there.
client.connector.set_and_publish(
StateEndpoints.xray_centring_done(),
StateEndpoints.xray_centering_done(),
MXMeasurementSequenceMessage(sample_id=sample_id, success=True),
)
+5 -5
View File
@@ -16,17 +16,17 @@ class StateEndpoints:
)
@staticmethod
def optical_centring_done():
def optical_centering_done():
return EndpointInfo(
endpoint=f"{EndpointType.INFO.value}/mx/sequence/optical_centring_done",
endpoint=f"{EndpointType.INFO.value}/mx/sequence/optical_centering_done",
message_type=MXMeasurementSequenceMessage,
message_op=MessageOp.SET_PUBLISH,
)
@staticmethod
def xray_centring_done():
def xray_centering_done():
return EndpointInfo(
endpoint=f"{EndpointType.INFO.value}/mx/sequence/xray_centring_done",
endpoint=f"{EndpointType.INFO.value}/mx/sequence/xray_centering_done",
message_type=MXMeasurementSequenceMessage,
message_op=MessageOp.SET_PUBLISH,
)
@@ -57,7 +57,7 @@ class ActorEndpoints:
class DataAnalysisEndpoints:
@staticmethod
def optical_prediction():
"""Stream for image analysis predictions (for optical centring, grid scan parameters...)"""
"""Stream for image analysis predictions (for optical centering, grid scan parameters...)"""
return EndpointInfo(
endpoint=f"{EndpointType.USER.value}/mx/analysis/optical_prediction",
message_type=OpticalPredictionMessage,
+9 -9
View File
@@ -13,7 +13,7 @@ from aare_bec_proto.constants import AareBecWorkflowState
from aare_bec_proto.devices.smargopolo_smargon import Smargon
from aare_bec_proto.endpoints import StateEndpoints
from aare_bec_proto.messages import MXMeasurementSequenceMessage
from aare_bec_proto.states.optical_centring import OpticalPrediction
from aare_bec_proto.states.optical_centering import OpticalPrediction
if TYPE_CHECKING:
from bec_lib.redis_connector import RedisConnector
@@ -62,21 +62,21 @@ class MxTasks:
def __init__(self, client: AareBec):
self._client = client
def run_optical_centring(self, sample_id: int):
"""Update optical centring prediction, then tell Smargon to move there. Repeat for each of
several angles as specified in the config. Publishes `optical_centring_done` milestone."""
def run_optical_centering(self, sample_id: int):
"""Update optical centering prediction, then tell Smargon to move there. Repeat for each of
several angles as specified in the config. Publishes `optical_centering_done` milestone."""
smargon: Smargon = self._client.devices.smargon
for angle in self._client.config.optical_centring.angles:
for angle in self._client.config.optical_centering.angles:
smargon.omega.set(angle).wait()
if (target := self._client.optical_prediction.get_target_point_offset_mm()) is None:
logger.warning("No target point obtained from AareLc")
self._publish_optical_centring_done(sample_id, success=False)
self._publish_optical_centering_done(sample_id, success=False)
return
smargon.nudge_in_lab_frame(*target).wait()
self._publish_optical_centring_done(sample_id, success=True)
self._publish_optical_centering_done(sample_id, success=True)
def _publish_optical_centring_done(self, sample_id: int, *, success: bool):
def _publish_optical_centering_done(self, sample_id: int, *, success: bool):
self._client.connector.set_and_publish(
StateEndpoints.optical_centring_done(),
StateEndpoints.optical_centering_done(),
MXMeasurementSequenceMessage(sample_id=sample_id, success=success),
)
+4 -4
View File
@@ -7,8 +7,8 @@ from aare_bec_proto.actor_manager import AareActorManager
from aare_bec_proto.actors import all_actor_classes
from aare_bec_proto.actors.core import MXAutomationActor
from aare_bec_proto.actors.mx_automation import (
OnOpticalCentringDoneRunXrayCentring,
OnSampleMountedRunOpticalCentring,
OnOpticalCenteringDoneRunXrayCentering,
OnSampleMountedRunOpticalCentering,
)
from aare_bec_proto.messages import MXMeasurementSequenceMessage
@@ -65,8 +65,8 @@ def manager():
def test_all_actor_classes_finds_concrete_subclasses():
classes = all_actor_classes()
assert OnSampleMountedRunOpticalCentring in classes
assert OnOpticalCentringDoneRunXrayCentring in classes
assert OnSampleMountedRunOpticalCentering in classes
assert OnOpticalCenteringDoneRunXrayCentering in classes
assert MXAutomationActor not in classes
assert len({c.config_key for c in classes}) == len(classes), "config keys must be unique"
+16 -16
View File
@@ -7,8 +7,8 @@ from bec_lib.redis_connector import MessageObject
from ophyd.status import Status
from aare_bec_proto.actors.mx_automation import (
OnOpticalCentringDoneRunXrayCentring,
OnSampleMountedRunOpticalCentring,
OnOpticalCenteringDoneRunXrayCentering,
OnSampleMountedRunOpticalCentering,
)
from aare_bec_proto.endpoints import StateEndpoints
from aare_bec_proto.messages import MXMeasurementSequenceMessage
@@ -30,49 +30,49 @@ def _msg_obj(
def test_config_endpoint_is_a_managed_bool_stream():
ep = OnSampleMountedRunOpticalCentring.config_endpoint()
ep = OnSampleMountedRunOpticalCentering.config_endpoint()
assert ep.message_op == MessageOp.STREAM
assert ep.message_type is BoolConfigDefaultFalse
assert OnSampleMountedRunOpticalCentring.config_key in ep.endpoint
assert OnSampleMountedRunOpticalCentering.config_key in ep.endpoint
def test_actor_subscribes_to_its_milestone(client):
OnSampleMountedRunOpticalCentring(client, name="a", exec_id="a")
OnSampleMountedRunOpticalCentering(client, name="a", exec_id="a")
registered = {call.args[0].endpoint for call in client.connector.register.call_args_list}
assert StateEndpoints.sample_mounted().endpoint in registered
def test_successful_milestone_triggers_next_step(client):
actor = OnSampleMountedRunOpticalCentring(client, name="a", exec_id="a")
actor = OnSampleMountedRunOpticalCentering(client, name="a", exec_id="a")
actor.evaluate(_msg_obj(StateEndpoints.sample_mounted(), sample_id=42, success=True))
client.tasks.run_optical_centring.assert_called_once_with(42)
client.tasks.run_optical_centering.assert_called_once_with(42)
assert actor.last_message is None
def test_failed_milestone_does_not_trigger(client):
actor = OnSampleMountedRunOpticalCentring(client, name="a", exec_id="a")
actor = OnSampleMountedRunOpticalCentering(client, name="a", exec_id="a")
actor.evaluate(_msg_obj(StateEndpoints.sample_mounted(), sample_id=42, success=False))
client.tasks.run_optical_centring.assert_not_called()
client.tasks.run_optical_centering.assert_not_called()
client.connector.set_and_publish.assert_not_called()
def test_unexpected_message_is_ignored(client):
actor = OnSampleMountedRunOpticalCentring(client, name="a", exec_id="a")
actor = OnSampleMountedRunOpticalCentering(client, name="a", exec_id="a")
actor.evaluate(MessageObject(topic="x", value=BoolConfigDefaultFalse()))
client.tasks.run_optical_centring.assert_not_called()
client.tasks.run_optical_centering.assert_not_called()
client.connector.set_and_publish.assert_not_called()
def test_actors_chain(client):
"""sample mounted -> optical centring -> xray centring: each actor consumes what the previous
"""sample mounted -> optical centering -> xray centering: each actor consumes what the previous
step publishes. Uses the real MxTasks with a mocked prediction and smargon."""
client.tasks = MxTasks(client)
client.optical_prediction.get_target_point_offset_mm.return_value = (0.1, 0.2, 0.0)
move = Status()
client.devices.smargon.nudge_in_lab_frame.return_value = move
first = OnSampleMountedRunOpticalCentring(client, name="a", exec_id="a")
second = OnOpticalCentringDoneRunXrayCentring(client, name="b", exec_id="b")
first = OnSampleMountedRunOpticalCentering(client, name="a", exec_id="a")
second = OnOpticalCenteringDoneRunXrayCentering(client, name="b", exec_id="b")
first.evaluate(_msg_obj(StateEndpoints.sample_mounted(), sample_id=7, success=True))
client.devices.smargon.nudge_in_lab_frame.assert_called_once_with(0.1, 0.2, 0.0)
@@ -80,10 +80,10 @@ def test_actors_chain(client):
move.set_finished()
endpoint, msg = client.connector.set_and_publish.call_args.args
assert endpoint.endpoint == StateEndpoints.optical_centring_done().endpoint
assert endpoint.endpoint == StateEndpoints.optical_centering_done().endpoint
assert msg == MXMeasurementSequenceMessage(sample_id=7, success=True)
second.evaluate(MessageObject(topic=endpoint.endpoint, value=msg))
endpoint, msg = client.connector.set_and_publish.call_args.args
assert endpoint.endpoint == StateEndpoints.xray_centring_done().endpoint
assert endpoint.endpoint == StateEndpoints.xray_centering_done().endpoint
assert msg.sample_id == 7
+9 -9
View File
@@ -59,40 +59,40 @@ def _published(client) -> tuple[str, MXMeasurementSequenceMessage]:
return endpoint.endpoint, msg
def test_optical_centring_without_target_publishes_failure(mock_client):
def test_optical_centering_without_target_publishes_failure(mock_client):
mock_client.optical_prediction.get_target_point_offset_mm.return_value = None
MxTasks(mock_client).run_optical_centring(sample_id=3)
MxTasks(mock_client).run_optical_centering(sample_id=3)
mock_client.devices.smargon.nudge_in_lab_frame.assert_not_called()
assert _published(mock_client) == (
StateEndpoints.optical_centring_done().endpoint,
StateEndpoints.optical_centering_done().endpoint,
MXMeasurementSequenceMessage(sample_id=3, success=False),
)
def test_optical_centring_publishes_when_move_completes(mock_client):
def test_optical_centering_publishes_when_move_completes(mock_client):
mock_client.optical_prediction.get_target_point_offset_mm.return_value = (0.1, -0.2, 0.0)
move = Status()
mock_client.devices.smargon.nudge_in_lab_frame.return_value = move
MxTasks(mock_client).run_optical_centring(sample_id=3)
MxTasks(mock_client).run_optical_centering(sample_id=3)
mock_client.devices.smargon.nudge_in_lab_frame.assert_called_once_with(0.1, -0.2, 0.0)
mock_client.connector.set_and_publish.assert_not_called()
move.set_finished()
assert _published(mock_client) == (
StateEndpoints.optical_centring_done().endpoint,
StateEndpoints.optical_centering_done().endpoint,
MXMeasurementSequenceMessage(sample_id=3, success=True),
)
def test_optical_centring_publishes_failure_when_move_fails(mock_client):
def test_optical_centering_publishes_failure_when_move_fails(mock_client):
mock_client.optical_prediction.get_target_point_offset_mm.return_value = (0.1, -0.2, 0.0)
move = Status()
mock_client.devices.smargon.nudge_in_lab_frame.return_value = move
MxTasks(mock_client).run_optical_centring(sample_id=3)
MxTasks(mock_client).run_optical_centering(sample_id=3)
move.set_exception(TimeoutError("smargon did not reach target"))
assert _published(mock_client) == (
StateEndpoints.optical_centring_done().endpoint,
StateEndpoints.optical_centering_done().endpoint,
MXMeasurementSequenceMessage(sample_id=3, success=False),
)