From b1c0e1a90c705ecce9c1105647e3eb006297ee2d Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Tue, 16 Jul 2024 11:38:59 +0000 Subject: [PATCH 01/23] instance of the ternary expression implementation, deleting p38 is next --- src/dodal/beamlines/i22.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index 4b42694a98..cce73a54f8 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -28,6 +28,8 @@ set_log_beamline(BL) set_utils_beamline(BL) +IS_LAB = BL == "p38" + # Currently we must hard-code the visit, determining the visit at runtime requires # infrastructure that is still WIP. # Communication with GDA is also WIP so for now we determine an arbitrary scan number @@ -109,7 +111,7 @@ def i0( return device_instantiation( TetrammDetector, "i0", - "-EA-XBPM-02:", + f"-EA-XBPM-0{1 if IS_LAB else 2}:", wait_for_connection, fake_with_ophyd_sim, type="Cividec Diamond XBPM", @@ -374,7 +376,7 @@ def linkam( return device_instantiation( Linkam3, "linkam", - "-EA-TEMPC-05", + "-EA-TEMPC-05" if IS_LAB else "-EA-TEMPC-05", wait_for_connection, fake_with_ophyd_sim, ) From 90d2e9c68ccacc029c71aa30eb756198aa94f749 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Wed, 17 Jul 2024 12:33:08 +0000 Subject: [PATCH 02/23] moved the whole p38 into i22 --- src/dodal/beamlines/i22.py | 50 +++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index cce73a54f8..0576181e7d 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -11,7 +11,11 @@ ) from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline from dodal.common.beamlines.device_helpers import numbered_slits -from dodal.common.visit import RemoteDirectoryServiceClient, StaticVisitPathProvider +from dodal.common.visit import ( + LocalDirectoryServiceClient, + RemoteDirectoryServiceClient, + StaticVisitPathProvider, +) from dodal.devices.focusing_mirror import FocusingMirror from dodal.devices.i22.dcm import CrystalMetadata, DoubleCrystalMonochromator from dodal.devices.i22.fswitch import FSwitch @@ -37,6 +41,12 @@ # be unique and the data is at risk - this configuration is for testing only. set_path_provider( StaticVisitPathProvider( + BL, + Path("/dls/p38/data/2024/cm37282-2/bluesky"), + client=LocalDirectoryServiceClient(), + ) + if IS_LAB + else StaticVisitPathProvider( BL, Path("/dls/i22/data/2024/cm37271-2/bluesky"), client=RemoteDirectoryServiceClient("http://i22-control:8088/api"), @@ -44,16 +54,17 @@ ) +# d11 at p38, but disconnected def saxs( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> PilatusDetector: return device_instantiation( - NXSasPilatus, - "saxs", - "-EA-PILAT-01:", + AravisDetector if IS_LAB else NXSasPilatus, + "d11" if IS_LAB else "saxs", + "-DI-DCAM-03:" if IS_LAB else "-EA-PILAT-01:", wait_for_connection, fake_with_ophyd_sim, - drv_suffix="CAM:", + drv_suffix="DET:" if IS_LAB else "CAM:", hdf_suffix="HDF5:", metadata_holder=NXSasMetadataHolder( x_pixel_size=(1.72e-1, "mm"), @@ -68,6 +79,7 @@ def saxs( ) +# todo this is not available at p38 def synchrotron( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> Synchrotron: @@ -80,16 +92,17 @@ def synchrotron( ) +# d12 at p38 def waxs( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> PilatusDetector: return device_instantiation( - NXSasPilatus, - "waxs", - "-EA-PILAT-03:", + AravisDetector if IS_LAB else NXSasPilatus, + "d12" if IS_LAB else "waxs", + "-DI-DCAM-04:" if IS_LAB else "-EA-PILAT-03:", wait_for_connection, fake_with_ophyd_sim, - drv_suffix="CAM:", + drv_suffix="DET:" if IS_LAB else "CAM:", hdf_suffix="HDF5:", metadata_holder=NXSasMetadataHolder( x_pixel_size=(1.72e-1, "mm"), @@ -205,6 +218,13 @@ def undulator( ) +# +# The following devices are fake by default since P38 has no optics, +# but having mock devices here means they will be reflected in downstream data +# processing, where they may be required. +# + + def slits_1( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, @@ -287,6 +307,7 @@ def fswitch( ) +# Must find which PandA IOC(s) are compatible # Must document what PandAs are physically connected to # See: https://github.com/bluesky/ophyd-async/issues/284 def panda1( @@ -338,6 +359,9 @@ def panda4( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, ) -> HDFPanda: + # todo skip if at p38 + if IS_LAB: + raise SystemError("no panda4 at the p38 lab") return device_instantiation( HDFPanda, "panda4", @@ -348,13 +372,14 @@ def panda4( ) +# d3 at p38 def oav( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> AravisDetector: return device_instantiation( - NXSasOAV, - "oav", - "-DI-OAV-01:", + AravisDetector if IS_LAB else NXSasOAV, + "d3" if IS_LAB else "oav", + f"-DI-{'DCAM' if IS_LAB else 'OAV'}-01:", wait_for_connection, fake_with_ophyd_sim, drv_suffix="DET:", @@ -377,6 +402,7 @@ def linkam( Linkam3, "linkam", "-EA-TEMPC-05" if IS_LAB else "-EA-TEMPC-05", + # note alternatively -EA-LINKM-02: wait_for_connection, fake_with_ophyd_sim, ) From 5659529e9fd26cf0b6ef8f26cb1103c9f85feaa0 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Mon, 29 Jul 2024 16:34:22 +0100 Subject: [PATCH 03/23] apply the skp device decorator --- src/dodal/beamlines/i22.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index 0576181e7d..9914443657 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -79,7 +79,7 @@ def saxs( ) -# todo this is not available at p38 +@skip_device(IS_LAB) def synchrotron( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> Synchrotron: @@ -354,14 +354,11 @@ def panda3( ) -@skip_device() +@skip_device(IS_LAB) def panda4( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, ) -> HDFPanda: - # todo skip if at p38 - if IS_LAB: - raise SystemError("no panda4 at the p38 lab") return device_instantiation( HDFPanda, "panda4", From f0ee8564cfdd8fb363f121f34152825124d44a44 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Wed, 31 Jul 2024 13:20:13 +0100 Subject: [PATCH 04/23] respond to feedback --- src/dodal/beamlines/i22.py | 32 +++++++++++++++++++++++++++----- src/dodal/cli.py | 7 +++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index 9914443657..217f26937d 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -57,14 +57,36 @@ # d11 at p38, but disconnected def saxs( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False -) -> PilatusDetector: +) -> AravisDetector | NXSasPilatus: + + if IS_LAB: + return device_instantiation( + AravisDetector , + "d11", + "-DI-DCAM-03:", + wait_for_connection, + fake_with_ophyd_sim, + drv_suffix="DET:" , + hdf_suffix="HDF5:", + metadata_holder=NXSasMetadataHolder( + x_pixel_size=(1.72e-1, "mm"), + y_pixel_size=(1.72e-1, "mm"), + description="Dectris Pilatus3 2M", + type="Photon Counting Hybrid Pixel", + sensor_material="silicon", + sensor_thickness=(0.45, "mm"), + distance=(4711.833684146172, "mm"), + ), + directory_provider=get_directory_provider(), + ) + return device_instantiation( - AravisDetector if IS_LAB else NXSasPilatus, - "d11" if IS_LAB else "saxs", - "-DI-DCAM-03:" if IS_LAB else "-EA-PILAT-01:", + NXSasPilatus, + "saxs", + "-EA-PILAT-01:", wait_for_connection, fake_with_ophyd_sim, - drv_suffix="DET:" if IS_LAB else "CAM:", + drv_suffix="CAM:", hdf_suffix="HDF5:", metadata_holder=NXSasMetadataHolder( x_pixel_size=(1.72e-1, "mm"), diff --git a/src/dodal/cli.py b/src/dodal/cli.py index 06894e2752..80d0c03199 100644 --- a/src/dodal/cli.py +++ b/src/dodal/cli.py @@ -39,6 +39,13 @@ def main(ctx: click.Context) -> None: "attempt any I/O. Useful as a a dry-run.", default=False, ) +@click.option( + "-l", + "--lab-mode", + is_flag=True, + help="Connect to a lab environment paired with the beamline. For instance i22 and p38", + default=False +) def connect(beamline: str, all: bool, sim_backend: bool) -> None: """Initialises a beamline module, connects to all devices, reports any connection issues.""" From 55de85e4e60cb0ba01a4bb2191214f5794234da4 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Wed, 31 Jul 2024 13:56:30 +0100 Subject: [PATCH 05/23] dirty hack to get cli lab connection working --- src/dodal/beamlines/i22.py | 30 +++++++++++++++++------------- src/dodal/cli.py | 15 +++++++++++---- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index 217f26937d..303da4e2c9 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -27,12 +27,16 @@ from dodal.devices.undulator import Undulator from dodal.log import set_beamline as set_log_beamline from dodal.utils import BeamlinePrefix, get_beamline_name, skip_device +from dodal.cli import LAB_NAME, LAB_FLAG -BL = get_beamline_name("i22") + +BL = LAB_NAME if LAB_FLAG else get_beamline_name("i22") +print("BL NAME: ", BL) set_log_beamline(BL) set_utils_beamline(BL) -IS_LAB = BL == "p38" +IS_LAB = LAB_FLAG and BL == LAB_NAME +print("is this lab? : ",IS_LAB) # Currently we must hard-code the visit, determining the visit at runtime requires # infrastructure that is still WIP. @@ -68,15 +72,15 @@ def saxs( fake_with_ophyd_sim, drv_suffix="DET:" , hdf_suffix="HDF5:", - metadata_holder=NXSasMetadataHolder( - x_pixel_size=(1.72e-1, "mm"), - y_pixel_size=(1.72e-1, "mm"), - description="Dectris Pilatus3 2M", - type="Photon Counting Hybrid Pixel", - sensor_material="silicon", - sensor_thickness=(0.45, "mm"), - distance=(4711.833684146172, "mm"), - ), + # metadata_holder=NXSasMetadataHolder( + # x_pixel_size=(1.72e-1, "mm"), + # y_pixel_size=(1.72e-1, "mm"), + # description="Dectris Pilatus3 2M", + # type="Photon Counting Hybrid Pixel", + # sensor_material="silicon", + # sensor_thickness=(0.45, "mm"), + # distance=(4711.833684146172, "mm"), + # ), directory_provider=get_directory_provider(), ) @@ -101,7 +105,7 @@ def saxs( ) -@skip_device(IS_LAB) +@skip_device(lambda: BL == LAB_NAME) def synchrotron( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> Synchrotron: @@ -376,7 +380,7 @@ def panda3( ) -@skip_device(IS_LAB) +@skip_device(lambda: BL == LAB_NAME) def panda4( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, diff --git a/src/dodal/cli.py b/src/dodal/cli.py index 80d0c03199..9bfc35dc88 100644 --- a/src/dodal/cli.py +++ b/src/dodal/cli.py @@ -8,7 +8,8 @@ from dodal.utils import make_all_devices from . import __version__ - +LAB_FLAG = False +LAB_NAME = "p38" @click.group(invoke_without_command=True) @click.version_option(version=__version__, message="%(version)s") @@ -28,7 +29,7 @@ def main(ctx: click.Context) -> None: "-a", "--all", is_flag=True, - help="Attempt to connect to devices marked as skipped", + help="collect_factoriesAttempt to connect to devices marked as skipped", default=False, ) @click.option( @@ -46,9 +47,13 @@ def main(ctx: click.Context) -> None: help="Connect to a lab environment paired with the beamline. For instance i22 and p38", default=False ) -def connect(beamline: str, all: bool, sim_backend: bool) -> None: +def connect(beamline: str, all: bool, sim_backend: bool, lab_mode: bool) -> None: """Initialises a beamline module, connects to all devices, reports any connection issues.""" + if lab_mode: + global LAB_FLAG + LAB_FLAG = True + print(f"Lab mode enabled for {beamline}") os.environ["BEAMLINE"] = beamline @@ -58,9 +63,11 @@ def connect(beamline: str, all: bool, sim_backend: bool) -> None: # We need to make a RunEngine to allow ophyd-async devices to connect. # See https://blueskyproject.io/ophyd-async/main/explanations/event-loop-choice.html RunEngine() + real_connection_target = LAB_NAME if LAB_FLAG else beamline - print(f"Attempting connection to {beamline} (using {full_module_path})") + print(f"Attempting connection to {real_connection_target} (using {full_module_path})") devices, exceptions = make_all_devices( + full_module_path, include_skipped=all, fake_with_ophyd_sim=sim_backend, From 068418db1a501410908d4c01eaf7504d3906b864 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Wed, 31 Jul 2024 13:57:20 +0100 Subject: [PATCH 06/23] lint --- src/dodal/beamlines/i22.py | 14 ++++++-------- src/dodal/cli.py | 9 ++++++--- src/dodal/common/types.py | 3 ++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index 303da4e2c9..94339a6515 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -4,6 +4,7 @@ from ophyd_async.epics.adpilatus import PilatusDetector from ophyd_async.fastcs.panda import HDFPanda +from dodal.cli import LAB_FLAG, LAB_NAME from dodal.common.beamlines.beamline_utils import ( device_instantiation, get_path_provider, @@ -27,8 +28,6 @@ from dodal.devices.undulator import Undulator from dodal.log import set_beamline as set_log_beamline from dodal.utils import BeamlinePrefix, get_beamline_name, skip_device -from dodal.cli import LAB_NAME, LAB_FLAG - BL = LAB_NAME if LAB_FLAG else get_beamline_name("i22") print("BL NAME: ", BL) @@ -36,7 +35,7 @@ set_utils_beamline(BL) IS_LAB = LAB_FLAG and BL == LAB_NAME -print("is this lab? : ",IS_LAB) +print("is this lab? : ", IS_LAB) # Currently we must hard-code the visit, determining the visit at runtime requires # infrastructure that is still WIP. @@ -62,15 +61,14 @@ def saxs( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> AravisDetector | NXSasPilatus: - if IS_LAB: return device_instantiation( - AravisDetector , + AravisDetector, "d11", "-DI-DCAM-03:", wait_for_connection, fake_with_ophyd_sim, - drv_suffix="DET:" , + drv_suffix="DET:", hdf_suffix="HDF5:", # metadata_holder=NXSasMetadataHolder( # x_pixel_size=(1.72e-1, "mm"), @@ -85,8 +83,8 @@ def saxs( ) return device_instantiation( - NXSasPilatus, - "saxs", + NXSasPilatus, + "saxs", "-EA-PILAT-01:", wait_for_connection, fake_with_ophyd_sim, diff --git a/src/dodal/cli.py b/src/dodal/cli.py index 9bfc35dc88..ff01600794 100644 --- a/src/dodal/cli.py +++ b/src/dodal/cli.py @@ -8,9 +8,11 @@ from dodal.utils import make_all_devices from . import __version__ + LAB_FLAG = False LAB_NAME = "p38" + @click.group(invoke_without_command=True) @click.version_option(version=__version__, message="%(version)s") @click.pass_context @@ -45,7 +47,7 @@ def main(ctx: click.Context) -> None: "--lab-mode", is_flag=True, help="Connect to a lab environment paired with the beamline. For instance i22 and p38", - default=False + default=False, ) def connect(beamline: str, all: bool, sim_backend: bool, lab_mode: bool) -> None: """Initialises a beamline module, connects to all devices, reports @@ -65,9 +67,10 @@ def connect(beamline: str, all: bool, sim_backend: bool, lab_mode: bool) -> None RunEngine() real_connection_target = LAB_NAME if LAB_FLAG else beamline - print(f"Attempting connection to {real_connection_target} (using {full_module_path})") + print( + f"Attempting connection to {real_connection_target} (using {full_module_path})" + ) devices, exceptions = make_all_devices( - full_module_path, include_skipped=all, fake_with_ophyd_sim=sim_backend, diff --git a/src/dodal/common/types.py b/src/dodal/common/types.py index 22c546c655..69ea928e2d 100644 --- a/src/dodal/common/types.py +++ b/src/dodal/common/types.py @@ -19,4 +19,5 @@ class UpdatingPathProvider(PathProvider, ABC): @abstractmethod async def data_session(self) -> str: ... @abstractmethod - async def update(self, **kwargs) -> None: ... + async def update(self, **kwargs) -> None: + ... From e3ca0bd0b37625fcd79cfda750f48755df42588b Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Wed, 31 Jul 2024 14:00:18 +0100 Subject: [PATCH 07/23] correct the lambda call --- src/dodal/beamlines/i22.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index 94339a6515..4ef72e5594 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -103,7 +103,7 @@ def saxs( ) -@skip_device(lambda: BL == LAB_NAME) +@skip_device(lambda _: BL == LAB_NAME) def synchrotron( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> Synchrotron: @@ -378,7 +378,7 @@ def panda3( ) -@skip_device(lambda: BL == LAB_NAME) +@skip_device(lambda _: BL == LAB_NAME) def panda4( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, From eada0b136b8884aec91500b0a1a873cfa11e8c60 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Wed, 31 Jul 2024 14:24:57 +0100 Subject: [PATCH 08/23] reference the fake devices correctly --- src/dodal/beamlines/i22.py | 90 ++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index 4ef72e5594..8339854003 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -57,7 +57,24 @@ ) +# d3 at p38 +def oav( + wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False +) -> AravisDetector: + return device_instantiation( + AravisDetector if IS_LAB else NXSasOAV, + "d3" if IS_LAB else "oav", + f"-DI-{'DCAM' if IS_LAB else 'OAV'}-01:", + wait_for_connection, + fake_with_ophyd_sim, + drv_suffix="DET:", + hdf_suffix="HDF5:", + directory_provider=get_path_provider(), + ) + + # d11 at p38, but disconnected +@skip_device(lambda: BL == LAB_NAME) def saxs( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> AravisDetector | NXSasPilatus: @@ -79,7 +96,7 @@ def saxs( # sensor_thickness=(0.45, "mm"), # distance=(4711.833684146172, "mm"), # ), - directory_provider=get_directory_provider(), + directory_provider=get_path_provider(), ) return device_instantiation( @@ -103,7 +120,7 @@ def saxs( ) -@skip_device(lambda _: BL == LAB_NAME) +@skip_device(lambda: BL == LAB_NAME) def synchrotron( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> Synchrotron: @@ -156,9 +173,16 @@ def i0( ) +# +# The following devices are fake by default since P38 has no optics, +# but having mock devices here means they will be reflected in downstream data +# processing, where they may be required. +# + + def it( wait_for_connection: bool = True, - fake_with_ophyd_sim: bool = False, + fake_with_ophyd_sim: bool = IS_LAB, ) -> TetrammDetector: return device_instantiation( TetrammDetector, @@ -173,7 +197,7 @@ def it( def vfm( wait_for_connection: bool = True, - fake_with_ophyd_sim: bool = False, + fake_with_ophyd_sim: bool = IS_LAB, ) -> FocusingMirror: return device_instantiation( FocusingMirror, @@ -186,7 +210,7 @@ def vfm( def hfm( wait_for_connection: bool = True, - fake_with_ophyd_sim: bool = False, + fake_with_ophyd_sim: bool = IS_LAB, ) -> FocusingMirror: return device_instantiation( FocusingMirror, @@ -199,7 +223,7 @@ def hfm( def dcm( wait_for_connection: bool = True, - fake_with_ophyd_sim: bool = False, + fake_with_ophyd_sim: bool = IS_LAB, ) -> DoubleCrystalMonochromator: return device_instantiation( DoubleCrystalMonochromator, @@ -227,7 +251,7 @@ def dcm( def undulator( wait_for_connection: bool = True, - fake_with_ophyd_sim: bool = False, + fake_with_ophyd_sim: bool = IS_LAB, ) -> Undulator: return device_instantiation( Undulator, @@ -242,16 +266,9 @@ def undulator( ) -# -# The following devices are fake by default since P38 has no optics, -# but having mock devices here means they will be reflected in downstream data -# processing, where they may be required. -# - - def slits_1( wait_for_connection: bool = True, - fake_with_ophyd_sim: bool = False, + fake_with_ophyd_sim: bool = IS_LAB, ) -> Slits: return numbered_slits( 1, @@ -262,7 +279,7 @@ def slits_1( def slits_2( wait_for_connection: bool = True, - fake_with_ophyd_sim: bool = False, + fake_with_ophyd_sim: bool = IS_LAB, ) -> Slits: return numbered_slits( 2, @@ -273,7 +290,7 @@ def slits_2( def slits_3( wait_for_connection: bool = True, - fake_with_ophyd_sim: bool = False, + fake_with_ophyd_sim: bool = IS_LAB, ) -> Slits: return numbered_slits( 3, @@ -284,7 +301,7 @@ def slits_3( def slits_4( wait_for_connection: bool = True, - fake_with_ophyd_sim: bool = False, + fake_with_ophyd_sim: bool = IS_LAB, ) -> Slits: return numbered_slits( 4, @@ -295,7 +312,7 @@ def slits_4( def slits_5( wait_for_connection: bool = True, - fake_with_ophyd_sim: bool = False, + fake_with_ophyd_sim: bool = IS_LAB, ) -> Slits: return numbered_slits( 5, @@ -306,7 +323,7 @@ def slits_5( def slits_6( wait_for_connection: bool = True, - fake_with_ophyd_sim: bool = False, + fake_with_ophyd_sim: bool = IS_LAB, ) -> Slits: return numbered_slits( 6, @@ -317,7 +334,7 @@ def slits_6( def fswitch( wait_for_connection: bool = True, - fake_with_ophyd_sim: bool = False, + fake_with_ophyd_sim: bool = IS_LAB, ) -> FSwitch: return device_instantiation( FSwitch, @@ -334,6 +351,7 @@ def fswitch( # Must find which PandA IOC(s) are compatible # Must document what PandAs are physically connected to # See: https://github.com/bluesky/ophyd-async/issues/284 +@skip_device(lambda: BL == LAB_NAME) def panda1( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, @@ -378,7 +396,7 @@ def panda3( ) -@skip_device(lambda _: BL == LAB_NAME) +@skip_device(lambda: BL == LAB_NAME) def panda4( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, @@ -393,29 +411,15 @@ def panda4( ) -# d3 at p38 -def oav( - wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False -) -> AravisDetector: - return device_instantiation( - AravisDetector if IS_LAB else NXSasOAV, - "d3" if IS_LAB else "oav", - f"-DI-{'DCAM' if IS_LAB else 'OAV'}-01:", - wait_for_connection, - fake_with_ophyd_sim, - drv_suffix="DET:", - hdf_suffix="HDF5:", - metadata_holder=NXSasMetadataHolder( - x_pixel_size=(3.45e-3, "mm"), # Double check this figure - y_pixel_size=(3.45e-3, "mm"), - description="AVT Mako G-507B", - distance=(-1.0, "m"), - ), - path_provider=get_path_provider(), - ) +LINKAM_IS_IN_LAB = False -@skip_device() +@skip_device( + lambda: BL == LAB_NAME + and not LINKAM_IS_IN_LAB + or BL != LAB_NAME + and LINKAM_IS_IN_LAB +) def linkam( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> Linkam3: From 93b951d349b643dbece5e7d28c5ec013c7fbca79 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Wed, 31 Jul 2024 14:42:31 +0000 Subject: [PATCH 09/23] lint --- src/dodal/common/types.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dodal/common/types.py b/src/dodal/common/types.py index 69ea928e2d..22c546c655 100644 --- a/src/dodal/common/types.py +++ b/src/dodal/common/types.py @@ -19,5 +19,4 @@ class UpdatingPathProvider(PathProvider, ABC): @abstractmethod async def data_session(self) -> str: ... @abstractmethod - async def update(self, **kwargs) -> None: - ... + async def update(self, **kwargs) -> None: ... From b675b80f2a7d9b57168a760203a529593009f0b4 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Fri, 2 Aug 2024 08:16:46 +0000 Subject: [PATCH 10/23] parametrize the test --- src/dodal/beamlines/__init__.py | 36 +++++++++++++++++++ src/dodal/beamlines/i22.py | 4 ++- src/dodal/cli.py | 9 +++-- .../beamlines/test_device_instantiation.py | 28 +++++++++++++-- 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/dodal/beamlines/__init__.py b/src/dodal/beamlines/__init__.py index 7e71435698..daddbcd286 100644 --- a/src/dodal/beamlines/__init__.py +++ b/src/dodal/beamlines/__init__.py @@ -19,6 +19,10 @@ "p49": "training_rig", } +BEAMLINE_LAB_MAPPINGS: dict[str, str] = { + "i22": "p38", +} + def all_beamline_modules() -> Iterable[str]: """ @@ -89,3 +93,35 @@ def module_name_for_beamline(beamline: str) -> str: """ return _BEAMLINE_NAME_OVERRIDES.get(beamline, beamline) + + +def get_module_by_beamline_name(name: str) -> Iterable[str]: + """ + Get the names of specific importable modules that match the beamline name. + + Args: + name (str): The beamline name to filter modules. + + Returns: + Iterable[str]: An iterable of matching beamline module names. + """ + + # This is done by inspecting file names rather than modules to avoid + # premature importing + spec = importlib.util.find_spec(__name__) + if spec is not None: + assert spec.submodule_search_locations + search_paths = [Path(path) for path in spec.submodule_search_locations] + + for path in search_paths: + for subpath in path.glob("**/*"): + if ( + subpath.name.endswith(".py") + and subpath.name != "__init__.py" + and ("__pycache__" not in str(subpath)) + ): + module_name = subpath.with_suffix("").name + if name in module_name: + yield module_name + else: + raise KeyError(f"Unable to find {__name__} module") diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index 8339854003..ec9fe88c19 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -4,7 +4,7 @@ from ophyd_async.epics.adpilatus import PilatusDetector from ophyd_async.fastcs.panda import HDFPanda -from dodal.cli import LAB_FLAG, LAB_NAME +from dodal.cli import LAB_FLAG from dodal.common.beamlines.beamline_utils import ( device_instantiation, get_path_provider, @@ -29,6 +29,8 @@ from dodal.log import set_beamline as set_log_beamline from dodal.utils import BeamlinePrefix, get_beamline_name, skip_device +LAB_NAME = "p38" + BL = LAB_NAME if LAB_FLAG else get_beamline_name("i22") print("BL NAME: ", BL) set_log_beamline(BL) diff --git a/src/dodal/cli.py b/src/dodal/cli.py index ff01600794..50cc6c2051 100644 --- a/src/dodal/cli.py +++ b/src/dodal/cli.py @@ -4,13 +4,16 @@ from bluesky.run_engine import RunEngine from ophyd_async.core import NotConnected -from dodal.beamlines import all_beamline_names, module_name_for_beamline +from dodal.beamlines import ( + BEAMLINE_LAB_MAPPINGS, + all_beamline_names, + module_name_for_beamline, +) from dodal.utils import make_all_devices from . import __version__ LAB_FLAG = False -LAB_NAME = "p38" @click.group(invoke_without_command=True) @@ -65,7 +68,7 @@ def connect(beamline: str, all: bool, sim_backend: bool, lab_mode: bool) -> None # We need to make a RunEngine to allow ophyd-async devices to connect. # See https://blueskyproject.io/ophyd-async/main/explanations/event-loop-choice.html RunEngine() - real_connection_target = LAB_NAME if LAB_FLAG else beamline + real_connection_target = BEAMLINE_LAB_MAPPINGS[beamline] if LAB_FLAG else beamline print( f"Attempting connection to {real_connection_target} (using {full_module_path})" diff --git a/tests/common/beamlines/test_device_instantiation.py b/tests/common/beamlines/test_device_instantiation.py index 704bad1343..6e843f64d5 100644 --- a/tests/common/beamlines/test_device_instantiation.py +++ b/tests/common/beamlines/test_device_instantiation.py @@ -1,8 +1,9 @@ from typing import Any +from unittest.mock import patch import pytest -from dodal.beamlines import all_beamline_modules +from dodal.beamlines import BEAMLINE_LAB_MAPPINGS, all_beamline_modules from dodal.common.beamlines import beamline_utils from dodal.utils import BLUESKY_PROTOCOLS, make_all_devices @@ -21,7 +22,7 @@ def test_device_creation(RE, module_and_devices_for_beamline): Ensures that for every beamline all device factories are using valid args and creating types that conform to Bluesky protocols. """ - module, devices = module_and_devices_for_beamline + _, 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 for {module}, " @@ -31,6 +32,29 @@ def test_device_creation(RE, module_and_devices_for_beamline): assert len(beamline_utils.ACTIVE_DEVICES) == len(devices) +@pytest.mark.parametrize( + "module_and_devices_for_beamline", + set(BEAMLINE_LAB_MAPPINGS), + indirect=True, +) +def test_lab_version_of_a_beamline(RE, module_and_devices_for_beamline): + """ + Ensures that for every lab beamline all device factories are using valid args + and creating types that conform to Bluesky protocols. + """ + # todo mock this import boolean flag as true + # from dodal.cli import LAB_FLAG + with patch("dodal.cli.LAB_FLAG", True): + _, 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()}" + ) + assert follows_bluesky_protocols(device) + assert len(beamline_utils.ACTIVE_DEVICES) == len(devices) + + @pytest.mark.parametrize( "module_and_devices_for_beamline", set(all_beamline_modules()), From 68005d2fce30c4dc1da0379d357462f314bf8a25 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Fri, 2 Aug 2024 10:12:03 +0100 Subject: [PATCH 11/23] attempt to read the dirs --- src/dodal/beamlines/__init__.py | 34 +------------ src/dodal/beamlines/i22.py | 3 +- src/dodal/cli.py | 4 +- .../beamlines/test_device_instantiation.py | 51 ++++++++++++++++--- tests/conftest.py | 2 +- 5 files changed, 50 insertions(+), 44 deletions(-) diff --git a/src/dodal/beamlines/__init__.py b/src/dodal/beamlines/__init__.py index daddbcd286..50cded242c 100644 --- a/src/dodal/beamlines/__init__.py +++ b/src/dodal/beamlines/__init__.py @@ -19,7 +19,7 @@ "p49": "training_rig", } -BEAMLINE_LAB_MAPPINGS: dict[str, str] = { +BEAMLINE_LAB_MAPPING: dict[str, str] = { "i22": "p38", } @@ -93,35 +93,3 @@ def module_name_for_beamline(beamline: str) -> str: """ return _BEAMLINE_NAME_OVERRIDES.get(beamline, beamline) - - -def get_module_by_beamline_name(name: str) -> Iterable[str]: - """ - Get the names of specific importable modules that match the beamline name. - - Args: - name (str): The beamline name to filter modules. - - Returns: - Iterable[str]: An iterable of matching beamline module names. - """ - - # This is done by inspecting file names rather than modules to avoid - # premature importing - spec = importlib.util.find_spec(__name__) - if spec is not None: - assert spec.submodule_search_locations - search_paths = [Path(path) for path in spec.submodule_search_locations] - - for path in search_paths: - for subpath in path.glob("**/*"): - if ( - subpath.name.endswith(".py") - and subpath.name != "__init__.py" - and ("__pycache__" not in str(subpath)) - ): - module_name = subpath.with_suffix("").name - if name in module_name: - yield module_name - else: - raise KeyError(f"Unable to find {__name__} module") diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index ec9fe88c19..6a0fcfc6c7 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -4,6 +4,7 @@ from ophyd_async.epics.adpilatus import PilatusDetector from ophyd_async.fastcs.panda import HDFPanda +from dodal.beamlines import BEAMLINE_LAB_MAPPING from dodal.cli import LAB_FLAG from dodal.common.beamlines.beamline_utils import ( device_instantiation, @@ -29,7 +30,7 @@ from dodal.log import set_beamline as set_log_beamline from dodal.utils import BeamlinePrefix, get_beamline_name, skip_device -LAB_NAME = "p38" +LAB_NAME = BEAMLINE_LAB_MAPPING.get("i22", "i22") BL = LAB_NAME if LAB_FLAG else get_beamline_name("i22") print("BL NAME: ", BL) diff --git a/src/dodal/cli.py b/src/dodal/cli.py index 50cc6c2051..439da889c7 100644 --- a/src/dodal/cli.py +++ b/src/dodal/cli.py @@ -5,7 +5,7 @@ from ophyd_async.core import NotConnected from dodal.beamlines import ( - BEAMLINE_LAB_MAPPINGS, + BEAMLINE_LAB_MAPPING, all_beamline_names, module_name_for_beamline, ) @@ -68,7 +68,7 @@ def connect(beamline: str, all: bool, sim_backend: bool, lab_mode: bool) -> None # We need to make a RunEngine to allow ophyd-async devices to connect. # See https://blueskyproject.io/ophyd-async/main/explanations/event-loop-choice.html RunEngine() - real_connection_target = BEAMLINE_LAB_MAPPINGS[beamline] if LAB_FLAG else beamline + real_connection_target = BEAMLINE_LAB_MAPPING[beamline] if LAB_FLAG else beamline print( f"Attempting connection to {real_connection_target} (using {full_module_path})" diff --git a/tests/common/beamlines/test_device_instantiation.py b/tests/common/beamlines/test_device_instantiation.py index 6e843f64d5..5fa9addcaf 100644 --- a/tests/common/beamlines/test_device_instantiation.py +++ b/tests/common/beamlines/test_device_instantiation.py @@ -1,13 +1,50 @@ +import importlib.util +from collections.abc import Iterable +from pathlib import Path from typing import Any from unittest.mock import patch import pytest -from dodal.beamlines import BEAMLINE_LAB_MAPPINGS, all_beamline_modules +from dodal.beamlines import BEAMLINE_LAB_MAPPING, all_beamline_modules from dodal.common.beamlines import beamline_utils from dodal.utils import BLUESKY_PROTOCOLS, make_all_devices +def get_module_by_beamline_name(name: str) -> Iterable[str]: + """ + Get the names of specific importable modules that match the beamline name. + + Args: + name (str): The beamline name to filter modules. + + Returns: + Iterable[str]: An iterable of matching beamline module names. + """ + + # This is done by inspecting file names rather than modules to avoid + # premature importing + spec = importlib.util.find_spec("dodal.beamlines") + if spec is not None: + assert spec.submodule_search_locations + search_paths = [Path(path) for path in spec.submodule_search_locations] + # todo the error is here in the search paths + # possibly has to do with the execution location, in dodal.beamlines this worked, not here + + for path in search_paths: + for subpath in path.glob("**/*"): + if ( + subpath.name.endswith(".py") + and subpath.name != "__init__.py" + and ("__pycache__" not in str(subpath)) + ): + module_name = subpath.with_suffix("").name + if name in module_name: + yield module_name + else: + raise KeyError(f"Unable to find {__name__} module") + + def follows_bluesky_protocols(obj: Any) -> bool: return any(isinstance(obj, protocol) for protocol in BLUESKY_PROTOCOLS) @@ -33,19 +70,19 @@ def test_device_creation(RE, module_and_devices_for_beamline): @pytest.mark.parametrize( - "module_and_devices_for_beamline", - set(BEAMLINE_LAB_MAPPINGS), + "mappings", + set(BEAMLINE_LAB_MAPPING), indirect=True, ) -def test_lab_version_of_a_beamline(RE, module_and_devices_for_beamline): +def test_lab_version_of_a_beamline(RE, mappings): """ Ensures that for every lab beamline all device factories are using valid args and creating types that conform to Bluesky protocols. """ - # todo mock this import boolean flag as true - # from dodal.cli import LAB_FLAG with patch("dodal.cli.LAB_FLAG", True): - _, devices = module_and_devices_for_beamline + # get the devices file for the beamline namespace + # but instantiate using the IS_FLAG logic + module, devices = get_module_by_beamline_name(mappings[0]) for device_name, device in devices.items(): assert device_name in beamline_utils.ACTIVE_DEVICES, ( f"No device named {device_name} was created, devices " diff --git a/tests/conftest.py b/tests/conftest.py index 0fd442216c..5bb79bae48 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -59,7 +59,7 @@ def mock_beamline_module_filepaths(bl_name, bl_module): @pytest.fixture(scope="function") -def module_and_devices_for_beamline(request): +def mappings(request): beamline = request.param with patch.dict(os.environ, {"BEAMLINE": beamline}, clear=True): bl_mod = importlib.import_module("dodal.beamlines." + beamline) From f8dab50c52e551ee7318e830c5c4d71247a8a44a Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Fri, 2 Aug 2024 15:21:16 +0100 Subject: [PATCH 12/23] t respond to feedback --- src/dodal/beamlines/i22.py | 81 +++++++++++++++------------- src/dodal/cli.py | 2 +- src/dodal/devices/i22/NXSasAravis.py | 22 ++++++++ 3 files changed, 66 insertions(+), 39 deletions(-) create mode 100644 src/dodal/devices/i22/NXSasAravis.py diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index 6a0fcfc6c7..a1d11d29c8 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -14,7 +14,7 @@ from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline from dodal.common.beamlines.device_helpers import numbered_slits from dodal.common.visit import ( - LocalDirectoryServiceClient, + DirectoryServiceClient, RemoteDirectoryServiceClient, StaticVisitPathProvider, ) @@ -22,6 +22,7 @@ from dodal.devices.i22.dcm import CrystalMetadata, DoubleCrystalMonochromator from dodal.devices.i22.fswitch import FSwitch from dodal.devices.i22.nxsas import NXSasMetadataHolder, NXSasOAV, NXSasPilatus +from dodal.devices.i22.NXSasAravis import NXSasAravis from dodal.devices.linkam3 import Linkam3 from dodal.devices.slits import Slits from dodal.devices.synchrotron import Synchrotron @@ -40,6 +41,7 @@ IS_LAB = LAB_FLAG and BL == LAB_NAME print("is this lab? : ", IS_LAB) +LINKAM_IS_IN_LAB = False # Currently we must hard-code the visit, determining the visit at runtime requires # infrastructure that is still WIP. # Communication with GDA is also WIP so for now we determine an arbitrary scan number @@ -49,7 +51,7 @@ StaticVisitPathProvider( BL, Path("/dls/p38/data/2024/cm37282-2/bluesky"), - client=LocalDirectoryServiceClient(), + client=RemoteDirectoryServiceClient("https://p38-control:8088/api"), ) if IS_LAB else StaticVisitPathProvider( @@ -60,45 +62,29 @@ ) -# d3 at p38 -def oav( - wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False -) -> AravisDetector: - return device_instantiation( - AravisDetector if IS_LAB else NXSasOAV, - "d3" if IS_LAB else "oav", - f"-DI-{'DCAM' if IS_LAB else 'OAV'}-01:", - wait_for_connection, - fake_with_ophyd_sim, - drv_suffix="DET:", - hdf_suffix="HDF5:", - directory_provider=get_path_provider(), - ) - - # d11 at p38, but disconnected @skip_device(lambda: BL == LAB_NAME) def saxs( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False -) -> AravisDetector | NXSasPilatus: +) -> NXSasAravis | NXSasPilatus: if IS_LAB: return device_instantiation( - AravisDetector, - "d11", + NXSasAravis, + "saxs", "-DI-DCAM-03:", wait_for_connection, fake_with_ophyd_sim, drv_suffix="DET:", hdf_suffix="HDF5:", - # metadata_holder=NXSasMetadataHolder( - # x_pixel_size=(1.72e-1, "mm"), - # y_pixel_size=(1.72e-1, "mm"), - # description="Dectris Pilatus3 2M", - # type="Photon Counting Hybrid Pixel", - # sensor_material="silicon", - # sensor_thickness=(0.45, "mm"), - # distance=(4711.833684146172, "mm"), - # ), + metadata_holder=NXSasMetadataHolder( + x_pixel_size=(1.72e-1, "mm"), + y_pixel_size=(1.72e-1, "mm"), + description="Dectris Pilatus3 2M", + type="Photon Counting Hybrid Pixel", + sensor_material="silicon", + sensor_thickness=(0.45, "mm"), + distance=(4711.833684146172, "mm"), + ), directory_provider=get_path_provider(), ) @@ -142,7 +128,7 @@ def waxs( ) -> PilatusDetector: return device_instantiation( AravisDetector if IS_LAB else NXSasPilatus, - "d12" if IS_LAB else "waxs", + "waxs", "-DI-DCAM-04:" if IS_LAB else "-EA-PILAT-03:", wait_for_connection, fake_with_ophyd_sim, @@ -414,15 +400,34 @@ def panda4( ) -LINKAM_IS_IN_LAB = False +# d3 at p38 +def oav( + wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False +) -> AravisDetector: + return device_instantiation( + AravisDetector if IS_LAB else NXSasOAV, + "oav", + f"-DI-{'DCAM' if IS_LAB else 'OAV'}-01:", + wait_for_connection, + fake_with_ophyd_sim, + drv_suffix="DET:", + hdf_suffix="HDF5:", + metadata_holder=None + if IS_LAB + else NXSasMetadataHolder( + x_pixel_size=(1.72e-1, "mm"), + y_pixel_size=(1.72e-1, "mm"), + description="Dectris Pilatus3 2M", + type="Photon Counting Hybrid Pixel", + sensor_material="silicon", + sensor_thickness=(0.45, "mm"), + distance=(4711.833684146172, "mm"), + ), + directory_provider=get_path_provider(), + ) -@skip_device( - lambda: BL == LAB_NAME - and not LINKAM_IS_IN_LAB - or BL != LAB_NAME - and LINKAM_IS_IN_LAB -) +@skip_device(lambda: IS_LAB != LINKAM_IS_IN_LAB) def linkam( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> Linkam3: diff --git a/src/dodal/cli.py b/src/dodal/cli.py index 439da889c7..38a150611c 100644 --- a/src/dodal/cli.py +++ b/src/dodal/cli.py @@ -34,7 +34,7 @@ def main(ctx: click.Context) -> None: "-a", "--all", is_flag=True, - help="collect_factoriesAttempt to connect to devices marked as skipped", + help="Attempt to connect to devices marked as skipped", default=False, ) @click.option( diff --git a/src/dodal/devices/i22/NXSasAravis.py b/src/dodal/devices/i22/NXSasAravis.py new file mode 100644 index 0000000000..012db3b8bf --- /dev/null +++ b/src/dodal/devices/i22/NXSasAravis.py @@ -0,0 +1,22 @@ +from ophyd_async.core import DirectoryProvider +from ophyd_async.epics.areadetector import AravisDetector + +from dodal.devices.i22.nxsas import NXSasMetadataHolder + + +class NXSasAravis(AravisDetector): + metadata_holder: NXSasMetadataHolder + + def __init__( + self, + prefix: str, + directory_provider: DirectoryProvider, + name: str, + metadata_holder: NXSasMetadataHolder, + ): + self._metadata_holder = metadata_holder + super().__init__( + prefix=prefix, + directory_provider=directory_provider, + name=name, + ) From 9012fc85fa5eb5c5375157f864dc6935b656b51a Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Mon, 5 Aug 2024 14:35:14 +0100 Subject: [PATCH 13/23] revert lab flag changes --- src/dodal/beamlines/__init__.py | 4 ---- src/dodal/beamlines/i22.py | 18 ++++++++---------- src/dodal/cli.py | 22 ++-------------------- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/src/dodal/beamlines/__init__.py b/src/dodal/beamlines/__init__.py index 50cded242c..7e71435698 100644 --- a/src/dodal/beamlines/__init__.py +++ b/src/dodal/beamlines/__init__.py @@ -19,10 +19,6 @@ "p49": "training_rig", } -BEAMLINE_LAB_MAPPING: dict[str, str] = { - "i22": "p38", -} - def all_beamline_modules() -> Iterable[str]: """ diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index a1d11d29c8..b000bf570d 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -4,8 +4,6 @@ from ophyd_async.epics.adpilatus import PilatusDetector from ophyd_async.fastcs.panda import HDFPanda -from dodal.beamlines import BEAMLINE_LAB_MAPPING -from dodal.cli import LAB_FLAG from dodal.common.beamlines.beamline_utils import ( device_instantiation, get_path_provider, @@ -31,14 +29,14 @@ from dodal.log import set_beamline as set_log_beamline from dodal.utils import BeamlinePrefix, get_beamline_name, skip_device -LAB_NAME = BEAMLINE_LAB_MAPPING.get("i22", "i22") - -BL = LAB_NAME if LAB_FLAG else get_beamline_name("i22") +BL = get_beamline_name("i22") print("BL NAME: ", BL) set_log_beamline(BL) set_utils_beamline(BL) -IS_LAB = LAB_FLAG and BL == LAB_NAME +_LAB_NAME = "p38" + +IS_LAB = BL == _LAB_NAME print("is this lab? : ", IS_LAB) LINKAM_IS_IN_LAB = False @@ -63,7 +61,7 @@ # d11 at p38, but disconnected -@skip_device(lambda: BL == LAB_NAME) +@skip_device(lambda: BL == _LAB_NAME) def saxs( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> NXSasAravis | NXSasPilatus: @@ -109,7 +107,7 @@ def saxs( ) -@skip_device(lambda: BL == LAB_NAME) +@skip_device(lambda: BL == _LAB_NAME) def synchrotron( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> Synchrotron: @@ -340,7 +338,7 @@ def fswitch( # Must find which PandA IOC(s) are compatible # Must document what PandAs are physically connected to # See: https://github.com/bluesky/ophyd-async/issues/284 -@skip_device(lambda: BL == LAB_NAME) +@skip_device(lambda: BL == _LAB_NAME) def panda1( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, @@ -385,7 +383,7 @@ def panda3( ) -@skip_device(lambda: BL == LAB_NAME) +@skip_device(lambda: BL == _LAB_NAME) def panda4( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, diff --git a/src/dodal/cli.py b/src/dodal/cli.py index 38a150611c..ceada00368 100644 --- a/src/dodal/cli.py +++ b/src/dodal/cli.py @@ -5,7 +5,6 @@ from ophyd_async.core import NotConnected from dodal.beamlines import ( - BEAMLINE_LAB_MAPPING, all_beamline_names, module_name_for_beamline, ) @@ -13,8 +12,6 @@ from . import __version__ -LAB_FLAG = False - @click.group(invoke_without_command=True) @click.version_option(version=__version__, message="%(version)s") @@ -45,20 +42,9 @@ def main(ctx: click.Context) -> None: "attempt any I/O. Useful as a a dry-run.", default=False, ) -@click.option( - "-l", - "--lab-mode", - is_flag=True, - help="Connect to a lab environment paired with the beamline. For instance i22 and p38", - default=False, -) -def connect(beamline: str, all: bool, sim_backend: bool, lab_mode: bool) -> None: +def connect(beamline: str, all: bool, sim_backend: bool) -> None: """Initialises a beamline module, connects to all devices, reports any connection issues.""" - if lab_mode: - global LAB_FLAG - LAB_FLAG = True - print(f"Lab mode enabled for {beamline}") os.environ["BEAMLINE"] = beamline @@ -68,11 +54,7 @@ def connect(beamline: str, all: bool, sim_backend: bool, lab_mode: bool) -> None # We need to make a RunEngine to allow ophyd-async devices to connect. # See https://blueskyproject.io/ophyd-async/main/explanations/event-loop-choice.html RunEngine() - real_connection_target = BEAMLINE_LAB_MAPPING[beamline] if LAB_FLAG else beamline - - print( - f"Attempting connection to {real_connection_target} (using {full_module_path})" - ) + print(f"Attempting connection to {beamline} (using {full_module_path})") devices, exceptions = make_all_devices( full_module_path, include_skipped=all, From 87efc29a1befc4e0f5ef2ccca55e8766018bbc5e Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Mon, 5 Aug 2024 14:39:03 +0100 Subject: [PATCH 14/23] tests change --- .../beamlines/test_device_instantiation.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/common/beamlines/test_device_instantiation.py b/tests/common/beamlines/test_device_instantiation.py index 5fa9addcaf..9ec2104a66 100644 --- a/tests/common/beamlines/test_device_instantiation.py +++ b/tests/common/beamlines/test_device_instantiation.py @@ -6,7 +6,7 @@ import pytest -from dodal.beamlines import BEAMLINE_LAB_MAPPING, all_beamline_modules +from dodal.beamlines import all_beamline_modules from dodal.common.beamlines import beamline_utils from dodal.utils import BLUESKY_PROTOCOLS, make_all_devices @@ -71,7 +71,7 @@ def test_device_creation(RE, module_and_devices_for_beamline): @pytest.mark.parametrize( "mappings", - set(BEAMLINE_LAB_MAPPING), + set({"i22": "p38"}), indirect=True, ) def test_lab_version_of_a_beamline(RE, mappings): @@ -79,16 +79,16 @@ def test_lab_version_of_a_beamline(RE, mappings): Ensures that for every lab beamline all device factories are using valid args and creating types that conform to Bluesky protocols. """ + # todo patch the environment with patch("dodal.cli.LAB_FLAG", True): # get the devices file for the beamline namespace - # but instantiate using the IS_FLAG logic module, devices = get_module_by_beamline_name(mappings[0]) - 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()}" - ) - assert follows_bluesky_protocols(device) + # 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()}" + # ) + # assert follows_bluesky_protocols(device) assert len(beamline_utils.ACTIVE_DEVICES) == len(devices) From 6a6a700193df9149b3a1357c256c347627045bb7 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Mon, 5 Aug 2024 15:03:46 +0100 Subject: [PATCH 15/23] slightly adapt the test, still where to put the mapping --- .../common/beamlines/test_device_instantiation.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/common/beamlines/test_device_instantiation.py b/tests/common/beamlines/test_device_instantiation.py index 9ec2104a66..0ff6ac3e54 100644 --- a/tests/common/beamlines/test_device_instantiation.py +++ b/tests/common/beamlines/test_device_instantiation.py @@ -80,15 +80,15 @@ def test_lab_version_of_a_beamline(RE, mappings): and creating types that conform to Bluesky protocols. """ # todo patch the environment - with patch("dodal.cli.LAB_FLAG", True): + with patch.dict(os.environ, {"BEAMLINE": mappings[1]}): # get the devices file for the beamline namespace module, devices = get_module_by_beamline_name(mappings[0]) - # 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()}" - # ) - # assert follows_bluesky_protocols(device) + 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()}" + ) + assert follows_bluesky_protocols(device) assert len(beamline_utils.ACTIVE_DEVICES) == len(devices) From 13d2ce8d12df1b4f5de26365b3e27f9e85288210 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Mon, 5 Aug 2024 15:32:27 +0100 Subject: [PATCH 16/23] import os --- tests/common/beamlines/test_device_instantiation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/common/beamlines/test_device_instantiation.py b/tests/common/beamlines/test_device_instantiation.py index 0ff6ac3e54..d3ba7392af 100644 --- a/tests/common/beamlines/test_device_instantiation.py +++ b/tests/common/beamlines/test_device_instantiation.py @@ -1,4 +1,5 @@ import importlib.util +import os from collections.abc import Iterable from pathlib import Path from typing import Any From 632ff68c96610514af21e4b5fcb19b8ca7cb2556 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Thu, 8 Aug 2024 15:43:48 +0100 Subject: [PATCH 17/23] try to fix the naming --- tests/common/beamlines/test_device_instantiation.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/common/beamlines/test_device_instantiation.py b/tests/common/beamlines/test_device_instantiation.py index d3ba7392af..f755dd083a 100644 --- a/tests/common/beamlines/test_device_instantiation.py +++ b/tests/common/beamlines/test_device_instantiation.py @@ -9,10 +9,14 @@ from dodal.beamlines import all_beamline_modules from dodal.common.beamlines import beamline_utils -from dodal.utils import BLUESKY_PROTOCOLS, make_all_devices +from dodal.utils import ( + BLUESKY_PROTOCOLS, + get_beamline_based_on_environment_variable, + make_all_devices, +) -def get_module_by_beamline_name(name: str) -> Iterable[str]: +def get_module_name_by_beamline_name(name: str) -> Iterable[str]: """ Get the names of specific importable modules that match the beamline name. @@ -82,8 +86,9 @@ def test_lab_version_of_a_beamline(RE, mappings): """ # todo patch the environment with patch.dict(os.environ, {"BEAMLINE": mappings[1]}): + module = get_beamline_based_on_environment_variable() # get the devices file for the beamline namespace - module, devices = get_module_by_beamline_name(mappings[0]) + _, devices = get_module_name_by_beamline_name(mappings[0]) for device_name, device in devices.items(): assert device_name in beamline_utils.ACTIVE_DEVICES, ( f"No device named {device_name} was created, devices " From c535d100845c9dd44ed216c9c95b1e454a1f5d96 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Tue, 20 Aug 2024 10:21:35 +0100 Subject: [PATCH 18/23] respond to feedback --- src/dodal/beamlines/i22.py | 65 ++++++++++++------- src/dodal/devices/i22/NXSasAravis.py | 22 ------- .../beamlines/test_device_instantiation.py | 8 +-- tests/conftest.py | 2 +- 4 files changed, 48 insertions(+), 49 deletions(-) delete mode 100644 src/dodal/devices/i22/NXSasAravis.py diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index b000bf570d..7687457f45 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -20,7 +20,6 @@ from dodal.devices.i22.dcm import CrystalMetadata, DoubleCrystalMonochromator from dodal.devices.i22.fswitch import FSwitch from dodal.devices.i22.nxsas import NXSasMetadataHolder, NXSasOAV, NXSasPilatus -from dodal.devices.i22.NXSasAravis import NXSasAravis from dodal.devices.linkam3 import Linkam3 from dodal.devices.slits import Slits from dodal.devices.synchrotron import Synchrotron @@ -30,14 +29,12 @@ from dodal.utils import BeamlinePrefix, get_beamline_name, skip_device BL = get_beamline_name("i22") -print("BL NAME: ", BL) set_log_beamline(BL) set_utils_beamline(BL) _LAB_NAME = "p38" IS_LAB = BL == _LAB_NAME -print("is this lab? : ", IS_LAB) LINKAM_IS_IN_LAB = False # Currently we must hard-code the visit, determining the visit at runtime requires @@ -64,10 +61,10 @@ @skip_device(lambda: BL == _LAB_NAME) def saxs( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False -) -> NXSasAravis | NXSasPilatus: +) -> NXSasOAV | NXSasPilatus: if IS_LAB: return device_instantiation( - NXSasAravis, + NXSasOAV, "saxs", "-DI-DCAM-03:", wait_for_connection, @@ -109,7 +106,7 @@ def saxs( @skip_device(lambda: BL == _LAB_NAME) def synchrotron( - wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False + wait_for_connection: bool = True, fake_with_ophyd_sim: bool = IS_LAB ) -> Synchrotron: return device_instantiation( Synchrotron, @@ -124,13 +121,34 @@ def synchrotron( def waxs( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> PilatusDetector: + if IS_LAB: + return device_instantiation( + AravisDetector, + "waxs", + "-DI-DCAM-04:", + wait_for_connection, + fake_with_ophyd_sim, + drv_suffix="DET:", + hdf_suffix="HDF5:", + metadata_holder=NXSasMetadataHolder( + x_pixel_size=(1.72e-1, "mm"), + y_pixel_size=(1.72e-1, "mm"), + description="Dectris Pilatus3 2M", + type="Photon Counting Hybrid Pixel", + sensor_material="silicon", + sensor_thickness=(0.45, "mm"), + distance=(175.4199417092314, "mm"), + ), + directory_provider=get_directory_provider(), + ) + return device_instantiation( - AravisDetector if IS_LAB else NXSasPilatus, + NXSasPilatus, "waxs", - "-DI-DCAM-04:" if IS_LAB else "-EA-PILAT-03:", + "-EA-PILAT-03:", wait_for_connection, fake_with_ophyd_sim, - drv_suffix="DET:" if IS_LAB else "CAM:", + drv_suffix="CAM:", hdf_suffix="HDF5:", metadata_holder=NXSasMetadataHolder( x_pixel_size=(1.72e-1, "mm"), @@ -335,10 +353,9 @@ def fswitch( ) -# Must find which PandA IOC(s) are compatible # Must document what PandAs are physically connected to # See: https://github.com/bluesky/ophyd-async/issues/284 -@skip_device(lambda: BL == _LAB_NAME) +@skip_device(lambda: IS_LAB) def panda1( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, @@ -353,7 +370,7 @@ def panda1( ) -@skip_device() +@skip_device(lambda: IS_LAB) def panda2( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, @@ -368,7 +385,7 @@ def panda2( ) -@skip_device() +@skip_device(lambda: IS_LAB) def panda3( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, @@ -413,13 +430,10 @@ def oav( metadata_holder=None if IS_LAB else NXSasMetadataHolder( - x_pixel_size=(1.72e-1, "mm"), - y_pixel_size=(1.72e-1, "mm"), - description="Dectris Pilatus3 2M", - type="Photon Counting Hybrid Pixel", - sensor_material="silicon", - sensor_thickness=(0.45, "mm"), - distance=(4711.833684146172, "mm"), + x_pixel_size=(3.45e-3, "mm"), + y_pixel_size=(3.45e-3, "mm"), + description="AVT Mako G-507B", + distance=(-1.0, "m"), ), directory_provider=get_path_provider(), ) @@ -429,11 +443,18 @@ def oav( def linkam( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> Linkam3: + if IS_LAB: + return device_instantiation( + Linkam3, + "linkam", + "-EA-LINKM-02", + wait_for_connection, + fake_with_ophyd_sim, + ) return device_instantiation( Linkam3, "linkam", - "-EA-TEMPC-05" if IS_LAB else "-EA-TEMPC-05", - # note alternatively -EA-LINKM-02: + "-EA-TEMPC-05", wait_for_connection, fake_with_ophyd_sim, ) diff --git a/src/dodal/devices/i22/NXSasAravis.py b/src/dodal/devices/i22/NXSasAravis.py deleted file mode 100644 index 012db3b8bf..0000000000 --- a/src/dodal/devices/i22/NXSasAravis.py +++ /dev/null @@ -1,22 +0,0 @@ -from ophyd_async.core import DirectoryProvider -from ophyd_async.epics.areadetector import AravisDetector - -from dodal.devices.i22.nxsas import NXSasMetadataHolder - - -class NXSasAravis(AravisDetector): - metadata_holder: NXSasMetadataHolder - - def __init__( - self, - prefix: str, - directory_provider: DirectoryProvider, - name: str, - metadata_holder: NXSasMetadataHolder, - ): - self._metadata_holder = metadata_holder - super().__init__( - prefix=prefix, - directory_provider=directory_provider, - name=name, - ) diff --git a/tests/common/beamlines/test_device_instantiation.py b/tests/common/beamlines/test_device_instantiation.py index f755dd083a..430a31665c 100644 --- a/tests/common/beamlines/test_device_instantiation.py +++ b/tests/common/beamlines/test_device_instantiation.py @@ -75,20 +75,20 @@ def test_device_creation(RE, module_and_devices_for_beamline): @pytest.mark.parametrize( - "mappings", + "module_and_devices_for_beamline", set({"i22": "p38"}), indirect=True, ) -def test_lab_version_of_a_beamline(RE, mappings): +def test_lab_version_of_a_beamline(RE, module_and_devices_for_beamline): """ Ensures that for every lab beamline all device factories are using valid args and creating types that conform to Bluesky protocols. """ # todo patch the environment - with patch.dict(os.environ, {"BEAMLINE": mappings[1]}): + with patch.dict(os.environ, {"BEAMLINE": module_and_devices_for_beamline[1]}): module = get_beamline_based_on_environment_variable() # get the devices file for the beamline namespace - _, devices = get_module_name_by_beamline_name(mappings[0]) + _, devices = get_module_name_by_beamline_name(module_and_devices_for_beamline[0]) for device_name, device in devices.items(): assert device_name in beamline_utils.ACTIVE_DEVICES, ( f"No device named {device_name} was created, devices " diff --git a/tests/conftest.py b/tests/conftest.py index 5bb79bae48..0fd442216c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -59,7 +59,7 @@ def mock_beamline_module_filepaths(bl_name, bl_module): @pytest.fixture(scope="function") -def mappings(request): +def module_and_devices_for_beamline(request): beamline = request.param with patch.dict(os.environ, {"BEAMLINE": beamline}, clear=True): bl_mod = importlib.import_module("dodal.beamlines." + beamline) From 34d3bec6955ff81987c2e4fb8b40f363189a7d60 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Tue, 20 Aug 2024 09:25:38 +0000 Subject: [PATCH 19/23] lint --- tests/common/beamlines/test_device_instantiation.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/common/beamlines/test_device_instantiation.py b/tests/common/beamlines/test_device_instantiation.py index 430a31665c..cf0f6c5710 100644 --- a/tests/common/beamlines/test_device_instantiation.py +++ b/tests/common/beamlines/test_device_instantiation.py @@ -11,7 +11,6 @@ from dodal.common.beamlines import beamline_utils from dodal.utils import ( BLUESKY_PROTOCOLS, - get_beamline_based_on_environment_variable, make_all_devices, ) @@ -64,7 +63,7 @@ def test_device_creation(RE, module_and_devices_for_beamline): Ensures that for every beamline all device factories are using valid args and creating types that conform to Bluesky protocols. """ - _, devices = 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 for {module}, " @@ -86,9 +85,10 @@ def test_lab_version_of_a_beamline(RE, module_and_devices_for_beamline): """ # todo patch the environment with patch.dict(os.environ, {"BEAMLINE": module_and_devices_for_beamline[1]}): - module = get_beamline_based_on_environment_variable() # get the devices file for the beamline namespace - _, devices = get_module_name_by_beamline_name(module_and_devices_for_beamline[0]) + _, devices = get_module_name_by_beamline_name( + module_and_devices_for_beamline[0] + ) for device_name, device in devices.items(): assert device_name in beamline_utils.ACTIVE_DEVICES, ( f"No device named {device_name} was created, devices " From 03c189c02a761f367fc2f204ab86ba77be52e2ab Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Tue, 20 Aug 2024 11:24:59 +0000 Subject: [PATCH 20/23] fix the iterator in the test --- .../beamlines/test_device_instantiation.py | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/common/beamlines/test_device_instantiation.py b/tests/common/beamlines/test_device_instantiation.py index cf0f6c5710..b906e14ab8 100644 --- a/tests/common/beamlines/test_device_instantiation.py +++ b/tests/common/beamlines/test_device_instantiation.py @@ -73,22 +73,32 @@ def test_device_creation(RE, module_and_devices_for_beamline): assert len(beamline_utils.ACTIVE_DEVICES) == len(devices) +def get_module_and_devices_for_beamline(beamline): + bl_mod = importlib.import_module("dodal.beamlines." + beamline) + importlib.reload(bl_mod) + devices, _ = make_all_devices( + bl_mod, + include_skipped=True, + fake_with_ophyd_sim=True, + ) + yield (bl_mod, devices) + beamline_utils.clear_devices() + del bl_mod + + @pytest.mark.parametrize( - "module_and_devices_for_beamline", - set({"i22": "p38"}), - indirect=True, + "mapping", + [{"beamline": "i22", "lab": "p38"}], ) -def test_lab_version_of_a_beamline(RE, module_and_devices_for_beamline): +def test_lab_version_of_a_beamline(RE, mapping): """ Ensures that for every lab beamline all device factories are using valid args and creating types that conform to Bluesky protocols. """ - # todo patch the environment - with patch.dict(os.environ, {"BEAMLINE": module_and_devices_for_beamline[1]}): + with patch.dict(os.environ, {"BEAMLINE": mapping["lab"]}): # get the devices file for the beamline namespace - _, devices = get_module_name_by_beamline_name( - module_and_devices_for_beamline[0] - ) + result = get_module_and_devices_for_beamline(mapping["beamline"]) + _, devices = next(result) for device_name, device in devices.items(): assert device_name in beamline_utils.ACTIVE_DEVICES, ( f"No device named {device_name} was created, devices " From 12786842eac9969ba73c9fa76c8291763a1afb87 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Tue, 27 Aug 2024 10:05:35 +0000 Subject: [PATCH 21/23] add tests for device init for i22 --- src/dodal/beamlines/i22.py | 2 -- tests/beamlines/unit_tests/test_i22.py | 14 ++++++++++++++ tests/beamlines/unit_tests/test_p38.py | 13 +++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/beamlines/unit_tests/test_i22.py create mode 100644 tests/beamlines/unit_tests/test_p38.py diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index 7687457f45..bf3856cf9a 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -57,8 +57,6 @@ ) -# d11 at p38, but disconnected -@skip_device(lambda: BL == _LAB_NAME) def saxs( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False ) -> NXSasOAV | NXSasPilatus: diff --git a/tests/beamlines/unit_tests/test_i22.py b/tests/beamlines/unit_tests/test_i22.py new file mode 100644 index 0000000000..c50ba76077 --- /dev/null +++ b/tests/beamlines/unit_tests/test_i22.py @@ -0,0 +1,14 @@ +from dodal.beamlines import i22 +from dodal.common.beamlines import beamline_utils +from dodal.devices.i22.nxsas import NXSasPilatus + + +def test_list(): + beamline_utils.clear_devices() + i22.synchrotron(wait_for_connection=False, fake_with_ophyd_sim=True) + saxs = i22.saxs(wait_for_connection=False, fake_with_ophyd_sim=True) + assert ( + saxs.__class__ == NXSasPilatus + ), f"Expected NXSasPilatus, got {saxs.__class__}" + + assert beamline_utils.list_active_devices() == ["synchrotron", "saxs"] diff --git a/tests/beamlines/unit_tests/test_p38.py b/tests/beamlines/unit_tests/test_p38.py new file mode 100644 index 0000000000..71d2b43773 --- /dev/null +++ b/tests/beamlines/unit_tests/test_p38.py @@ -0,0 +1,13 @@ +import os + +from dodal.common.beamlines import beamline_utils +from dodal.devices.i22.nxsas import NXSasOAV + +os.environ["BEAMLINE"] = "p38" +from dodal.beamlines import i22 + + +def test_devices_diff_when_in_lab(): + beamline_utils.clear_devices() + saxs = i22.saxs(wait_for_connection=False, fake_with_ophyd_sim=True) + assert saxs.__class__ == NXSasOAV, f"Expected NXSasOav, got {saxs.__class__}" From 15c574425d2f56494f53336c3e3f6d37f24a9c68 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Mon, 23 Sep 2024 15:34:42 +0000 Subject: [PATCH 22/23] fix import error --- src/dodal/beamlines/i22.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index bf3856cf9a..7a46f52ef4 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -12,7 +12,6 @@ from dodal.common.beamlines.beamline_utils import set_beamline as set_utils_beamline from dodal.common.beamlines.device_helpers import numbered_slits from dodal.common.visit import ( - DirectoryServiceClient, RemoteDirectoryServiceClient, StaticVisitPathProvider, ) @@ -137,7 +136,7 @@ def waxs( sensor_thickness=(0.45, "mm"), distance=(175.4199417092314, "mm"), ), - directory_provider=get_directory_provider(), + directory_provider=get_path_provider(), ) return device_instantiation( From 0348787c89db6cf23111408e83adc935b6e8f31c Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Mon, 23 Sep 2024 15:41:13 +0000 Subject: [PATCH 23/23] outlined the tests to fix --- tests/beamlines/unit_tests/test_p38.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/beamlines/unit_tests/test_p38.py b/tests/beamlines/unit_tests/test_p38.py index 71d2b43773..afca137eb0 100644 --- a/tests/beamlines/unit_tests/test_p38.py +++ b/tests/beamlines/unit_tests/test_p38.py @@ -1,5 +1,7 @@ import os +import pytest + from dodal.common.beamlines import beamline_utils from dodal.devices.i22.nxsas import NXSasOAV @@ -11,3 +13,20 @@ def test_devices_diff_when_in_lab(): beamline_utils.clear_devices() saxs = i22.saxs(wait_for_connection=False, fake_with_ophyd_sim=True) assert saxs.__class__ == NXSasOAV, f"Expected NXSasOav, got {saxs.__class__}" + + +# todo fix the following tests +# FAILED tests/beamlines/unit_tests/test_i03.py::test_list - KeyError: "No beamline parameter path found, maybe 'BEAMLINE' environment variable is not set!" +# FAILED tests/beamlines/unit_tests/test_p38.py::test_devices_diff_when_in_lab - AssertionError: Expected NXSasOav, got +# assert == NXSasOAV +# + where = .__class__ + + +@pytest.mark.parametrize("module_and_devices_for_beamline", ["p38"], indirect=True) +def test_device_creation(RE, module_and_devices_for_beamline): + _, devices = module_and_devices_for_beamline + saxs: NXSasOAV = devices["saxs"] # type: ignore + + print(saxs) + assert saxs.prefix == "BL24I-MO-VGON-01:" + assert saxs.kappa.prefix == "BL24I-MO-VGON-01:KAPPA"