CI for mx_bec / e2e tests with pxi_bec (push) Failing after 1m4s
CI for mx_bec / e2e tests with pxii_bec (push) Failing after 1m17s
CI for mx_bec / e2e tests with pxiii_bec (push) Failing after 1m17s
CI for mx_bec / unit tests with pxiii_bec (push) Failing after 1m47s
CI for mx_bec / unit tests with pxii_bec (push) Failing after 1m55s
CI for mx_bec / unit tests with pxi_bec (push) Failing after 1m55s
# MX task architecture: AareBec service, tasks, queues and widgets Brings the AareBec task architecture into `mx_bec` ## Components - **AareBec service** (`service.py`, `main.py`): custom BEC client that owns the task queue, the actor manager and the external API clients. - **Task framework** (`tasks/core.py`): `@task` decorator and `TaskManager` with `Server` and `Client` roles. The server runs tasks one at a time and pauses the queue on failure; clients request tasks over Redis. `MxTaskQueue` works off the execution list. - **MX tasks** (`tasks/mx_tasks.py`): sample mount, optical centering, raster and multi-raster scans, X-ray centering, rotation data collection, beamline state change and cleanup. - **Automation actors** (`actors/`, `actor_manager.py`): actors that react to sequence milestones and queue the next task, each switchable through a Redis config value. - **External clients**: `AareDaq` REST client (Kerberos token, baton handling), `JFJoch` raster client, `OpticalPrediction` (AareLC). The `AareDaq` client is to be replaced with native BEC implementations. - **Devices** (`devices/`): Aerotech, Smargon (smargopolo), HTTP device base, simulated stages and sample changer, plus a demo config. - **Widgets** (`bec_widgets/widgets/aare_bec/`): actor config, task queue, task panel, sample queue and sample spreadsheet display - for development and admin use. - **Endpoints and messages** for task requests, the execution list, queue-change notifications and sequence state. ## Notes - BEC-driven optical centering was removed; it will be reimplemented from scratch. - The sample spreadsheet is copied between Redis instances by a hack in the service, to be replaced by the sample database connection module. - CI installs from the MX Gitea package index (`jfjoch_client` is pre-release only). --------- Co-authored-by: x10sa <x10sa@psi.ch> Reviewed-on: #2 Co-authored-by: David Perl <david.perl@psi.ch>
75 lines
2.8 KiB
Python
75 lines
2.8 KiB
Python
"""The simulated beamline for development (BEAMLINE=SIMULATED), on real BEC servers."""
|
|
|
|
import pytest
|
|
import yaml
|
|
|
|
from mx_bec.configs import MX_SIMULATED_DEVICES
|
|
from mx_bec.device_planner import BeamlineState, TemperatureMode, init_beamline_environment
|
|
|
|
MOVE_TIMEOUT_S = 30
|
|
|
|
|
|
def _value(device) -> float:
|
|
return next(iter(device.read(cached=False).values()))["value"]
|
|
|
|
|
|
def test_all_simulated_devices_are_loaded(bec):
|
|
config = yaml.safe_load(MX_SIMULATED_DEVICES.read_text())
|
|
assert set(config) <= set(bec.device_manager.devices.keys())
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"name, target",
|
|
[("bl_pos", 1), ("bl_pos", 0), ("det_cov", 2), ("cryo_pos", 0), ("bl_bright", 1.3)],
|
|
)
|
|
def test_simulated_signals_can_be_moved_with_a_scan(bec, name, target):
|
|
device = bec.device_manager.devices[name]
|
|
bec.scans.mv(device, target, relative=False).wait(timeout=MOVE_TIMEOUT_S)
|
|
assert _value(device) == pytest.approx(target)
|
|
|
|
|
|
def test_simulated_signals_can_be_written_directly(bec):
|
|
"""What the device planner does for a device with `move_method: signal`."""
|
|
shutter = bec.device_manager.devices.bcu_shutter
|
|
for target in (1, 0):
|
|
shutter.put(target)
|
|
assert _value(shutter) == target
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"path, target, tolerance",
|
|
[
|
|
("bs_z", 45.1, 0.1),
|
|
("aerotech.x", -2.0, 0.01),
|
|
("aerotech.u", 90.0, 0.01),
|
|
("smargon.z", 1.8, 0.01),
|
|
("smargon.chi", 10.0, 0.01),
|
|
],
|
|
)
|
|
def test_simulated_positioners_reach_their_target(bec, path, target, tolerance):
|
|
"""The stages have to get as close to a named position as the device planner checks it."""
|
|
device = bec.device_manager.devices
|
|
for part in path.split("."):
|
|
device = getattr(device, part)
|
|
bec.scans.mv(device, target, relative=False).wait(timeout=MOVE_TIMEOUT_S)
|
|
assert _value(device) == pytest.approx(target, abs=tolerance)
|
|
|
|
|
|
def test_device_planner_moves_between_beamline_states(bec, simulated_beamline):
|
|
env, devices, planner = init_beamline_environment(bec.device_manager.devices, bec.scans)
|
|
assert env.simulated
|
|
assert set(planner.available_states()) == set(BeamlineState)
|
|
|
|
for state, modifier in [
|
|
(BeamlineState.ROBOT_SAMPLE_EXCHANGE, TemperatureMode.CRYO),
|
|
(BeamlineState.DATA_COLLECTION, TemperatureMode.CRYO),
|
|
(BeamlineState.BEAM_VISUALISATION, None),
|
|
(BeamlineState.MANUAL_SAMPLE_EXCHANGE, TemperatureMode.ROOM_TEMP),
|
|
(BeamlineState.SAMPLE_ALIGNMENT, TemperatureMode.CRYO),
|
|
]:
|
|
planner.move_to(state, modifier)
|
|
assert planner.is_state(state), (state, planner.get_positions())
|
|
target = planner._merged_state(state, modifier)
|
|
assert all(devices[name].is_at(position) for name, position in target.items())
|
|
assert _value(bec.device_manager.devices.bcu_shutter) == 0 # closed before anything moves
|