Skip to content

Commit

Permalink
Convert cyrostream to ophyd-async (#713)
Browse files Browse the repository at this point in the history
* Convert cryostream to ophyd_async

* Turn off code cov for pytest in vscode as it affects stops the debugger working

* Improve the message printing for dodal connect

* Fix merge error
  • Loading branch information
DominicOram authored Aug 9, 2024
1 parent 394eaf7 commit 32ff239
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"env": {
// Enable break on exception when debugging tests (see: tests/conftest.py)
"PYTEST_RAISE": "1",
"PYTEST_ADDOPTS": "--no-cov -vv"
},
}
]
}
}
16 changes: 16 additions & 0 deletions src/dodal/beamlines/i03.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from dodal.devices.aperturescatterguard import AperturePositions, ApertureScatterguard
from dodal.devices.attenuator import Attenuator
from dodal.devices.backlight import Backlight
from dodal.devices.cryostream import CryoStream
from dodal.devices.dcm import DCM
from dodal.devices.detector import DetectorParams
from dodal.devices.detector.detector_motion import DetectorMotion
Expand Down Expand Up @@ -511,3 +512,18 @@ def lower_gonio(
wait_for_connection,
fake_with_ophyd_sim,
)


def cryo_stream(
wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False
) -> CryoStream:
"""Get the i03 cryostream device, instantiate it if it hasn't already been.
If this is called when already instantiated in i03, it will return the existing object.
"""
return device_instantiation(
CryoStream,
"cryo_stream",
"",
wait_for_connection,
fake_with_ophyd_sim,
)
9 changes: 6 additions & 3 deletions src/dodal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ def connect(beamline: str, all: bool, sim_backend: bool) -> None:
include_skipped=all,
fake_with_ophyd_sim=sim_backend,
)
sim_statement = "(sim mode)" if sim_backend else ""
sim_statement = " (sim mode)" if sim_backend else ""

print(f"{len(devices)} devices connected {sim_statement}:")
print("\n".join([f"\t{device_name}" for device_name in devices.keys()]))
print(f"{len(devices)} devices connected{sim_statement}:")
connected_devices = "\n".join(
sorted([f"\t{device_name}" for device_name in devices.keys()])
)
print(connected_devices)

# If exceptions have occurred, this will print details of the relevant PVs
if len(exceptions) > 0:
Expand Down
26 changes: 19 additions & 7 deletions src/dodal/devices/cryostream.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
from ophyd import Component as Cpt
from ophyd import Device, EpicsSignal, EpicsSignalRO
from enum import Enum

from ophyd_async.core import StandardReadable
from ophyd_async.epics.signal import epics_signal_r, epics_signal_rw

class Cryo(Device):
course = Cpt(EpicsSignal, "-EA-CJET-01:COARSE:CTRL")
fine = Cpt(EpicsSignal, "-EA-CJET-01:FINE:CTRL")
temp = Cpt(EpicsSignalRO, "-EA-CSTRM-01:TEMP")
backpress = Cpt(EpicsSignalRO, "-EA-CSTRM-01:BACKPRESS")

class InOut(str, Enum):
IN = "In"
OUT = "Out"


class CryoStream(StandardReadable):
def __init__(self, prefix: str, name: str = ""):
self.course = epics_signal_rw(InOut, f"{prefix}-EA-CJET-01:COARSE:CTRL")
self.fine = epics_signal_rw(InOut, f"{prefix}-EA-CJET-01:FINE:CTRL")
self.temperature_k = epics_signal_r(float, f"{prefix}-EA-CSTRM-01:TEMP")
self.back_pressure_bar = epics_signal_r(
float, f"{prefix}-EA-CSTRM-01:BACKPRESS"
)

super().__init__(name)
4 changes: 2 additions & 2 deletions tests/common/beamlines/test_device_instantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def test_device_creation(RE, module_and_devices_for_beamline):
module, devices = module_and_devices_for_beamline
for device_name, device in devices.items():
assert device_name in beamline_utils.ACTIVE_DEVICES, (
f"No device named {device_name} was created, devices "
f"are {beamline_utils.ACTIVE_DEVICES.keys()}"
f"No device named {device_name} was created for {module}, "
f"devices are {beamline_utils.ACTIVE_DEVICES.keys()}"
)
assert follows_bluesky_protocols(device)
assert len(beamline_utils.ACTIVE_DEVICES) == len(devices)
Expand Down
4 changes: 2 additions & 2 deletions tests/fake_beamline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from bluesky.protocols import Readable
from ophyd import EpicsMotor

from dodal.devices.cryostream import Cryo
from dodal.devices.cryostream import CryoStream


def device_a() -> Readable:
Expand All @@ -14,7 +14,7 @@ def device_b() -> EpicsMotor:
return _mock_with_name("motor")


def device_c() -> Cryo:
def device_c() -> CryoStream:
return _mock_with_name("cryo")


Expand Down
4 changes: 2 additions & 2 deletions tests/fake_beamline_all_devices_raise_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from bluesky.protocols import Readable
from ophyd_async.epics.motion import Motor

from dodal.devices.cryostream import Cryo
from dodal.devices.cryostream import CryoStream


def device_a() -> Readable:
Expand All @@ -14,5 +14,5 @@ def device_b() -> Motor:
raise asyncio.TimeoutError


def device_c() -> Cryo:
def device_c() -> CryoStream:
raise ValueError
4 changes: 2 additions & 2 deletions tests/fake_beamline_broken_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from bluesky.protocols import Readable
from ophyd import EpicsMotor

from dodal.devices.cryostream import Cryo
from dodal.devices.cryostream import CryoStream


def device_x() -> Readable:
Expand All @@ -14,7 +14,7 @@ def device_y() -> EpicsMotor:
raise AssertionError("Test failure")


def device_z(device_x: Readable, device_y: EpicsMotor) -> Cryo:
def device_z(device_x: Readable, device_y: EpicsMotor) -> CryoStream:
return _mock_with_name("cryo")


Expand Down
4 changes: 2 additions & 2 deletions tests/fake_beamline_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from bluesky.protocols import Readable
from ophyd import EpicsMotor

from dodal.devices.cryostream import Cryo
from dodal.devices.cryostream import CryoStream


def device_x() -> Readable:
Expand All @@ -14,7 +14,7 @@ def device_y() -> EpicsMotor:
return _mock_with_name("motor")


def device_z(device_x: Readable, device_y: EpicsMotor) -> Cryo:
def device_z(device_x: Readable, device_y: EpicsMotor) -> CryoStream:
return _mock_with_name("cryo")


Expand Down
4 changes: 2 additions & 2 deletions tests/fake_beamline_disordered_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from bluesky.protocols import Readable
from ophyd import EpicsMotor

from dodal.devices.cryostream import Cryo
from dodal.devices.cryostream import CryoStream


def device_z(device_x: Readable, device_y: EpicsMotor) -> Cryo:
def device_z(device_x: Readable, device_y: EpicsMotor) -> CryoStream:
return _mock_with_name("cryo")


Expand Down

0 comments on commit 32ff239

Please sign in to comment.