From a066a38515266485086dc1e576fe989b72225de4 Mon Sep 17 00:00:00 2001 From: Oliver Silvester Date: Thu, 19 Sep 2024 17:46:08 +0100 Subject: [PATCH 1/5] update panda to use SeqTable.row --- .../device_setup_plans/setup_panda.py | 21 ++--- .../device_setup_plans/test_setup_panda.py | 87 +++++++++---------- 2 files changed, 50 insertions(+), 58 deletions(-) diff --git a/src/mx_bluesky/hyperion/device_setup_plans/setup_panda.py b/src/mx_bluesky/hyperion/device_setup_plans/setup_panda.py index df8e93602..0f287a0f5 100644 --- a/src/mx_bluesky/hyperion/device_setup_plans/setup_panda.py +++ b/src/mx_bluesky/hyperion/device_setup_plans/setup_panda.py @@ -11,9 +11,7 @@ from ophyd_async.fastcs.panda import ( HDFPanda, SeqTable, - SeqTableRow, SeqTrigger, - seq_table_from_rows, ) import mx_bluesky.hyperion.resources.panda as panda_resource @@ -85,10 +83,10 @@ def _get_seq_table( # BITA_1 trigger wired from TTLIN1, this is the trigger input # +ve direction scan - rows = [SeqTableRow(trigger=SeqTrigger.BITA_1, time2=1)] - rows.append( - SeqTableRow( + table = ( + SeqTable.row(trigger=SeqTrigger.BITA_1, time2=1) + + SeqTable.row( repeats=num_pulses, trigger=SeqTrigger.POSA_GT, position=start_of_grid_x_counts, @@ -97,13 +95,10 @@ def _get_seq_table( time2=delay_between_pulses - PULSE_WIDTH_US, outa2=False, ) - ) - - # -ve direction scan - rows.append(SeqTableRow(trigger=SeqTrigger.BITA_1, time2=1)) - - rows.append( - SeqTableRow( + + + # -ve direction scan + SeqTable.row(trigger=SeqTrigger.BITA_1, time2=1) + + SeqTable.row( repeats=num_pulses, trigger=SeqTrigger.POSA_LT, position=end_of_grid_x_counts + exposure_distance_x_counts, @@ -114,8 +109,6 @@ def _get_seq_table( ) ) - table = seq_table_from_rows(*rows) - return table diff --git a/tests/unit_tests/hyperion/device_setup_plans/test_setup_panda.py b/tests/unit_tests/hyperion/device_setup_plans/test_setup_panda.py index 3c347fd38..65e7e3b17 100644 --- a/tests/unit_tests/hyperion/device_setup_plans/test_setup_panda.py +++ b/tests/unit_tests/hyperion/device_setup_plans/test_setup_panda.py @@ -1,5 +1,4 @@ from datetime import datetime -from typing import NamedTuple from unittest.mock import MagicMock, patch import numpy as np @@ -9,7 +8,7 @@ from bluesky.simulators import RunEngineSimulator, assert_message_and_return_remaining from dodal.common.types import UpdatingPathProvider from dodal.devices.fast_grid_scan import PandAGridScanParams -from ophyd_async.fastcs.panda import SeqTrigger +from ophyd_async.fastcs.panda import SeqTable, SeqTrigger from mx_bluesky.hyperion.device_setup_plans.setup_panda import ( MM_TO_ENCODER_COUNTS, @@ -69,16 +68,6 @@ def test_setup_panda_performs_correct_plans(mock_load_device, sim_run_engine): assert num_of_waits == 3 -class SeqRow(NamedTuple): - repeats: int - trigger: SeqTrigger - position: int - time1: int - outa1: int - time2: int - outa2: int - - @pytest.mark.parametrize( "x_steps, x_step_size, x_start, run_up_distance_mm, time_between_x_steps_ms, exposure_time_s", [ @@ -142,44 +131,54 @@ def test_setup_panda_correctly_configures_table( PULSE_WIDTH_US = 1 SPACE_WIDTH_US = int(time_between_x_steps_ms * 1000 - PULSE_WIDTH_US) - expected_seq_rows: list[SeqRow] = [ - SeqRow(1, SeqTrigger.BITA_1, 0, 0, 0, 1, 0), - SeqRow( - x_steps, - SeqTrigger.POSA_GT, - int(params.x_start * MM_TO_ENCODER_COUNTS), - PULSE_WIDTH_US, - 1, - SPACE_WIDTH_US, - 0, - ), - ] exposure_distance_counts = exposure_distance_mm * MM_TO_ENCODER_COUNTS - expected_seq_rows.extend( - [ - SeqRow(1, SeqTrigger.BITA_1, 0, 0, 0, 1, 0), - SeqRow( - x_steps, - SeqTrigger.POSA_LT, - int( - (params.x_start + (params.x_steps - 1) * params.x_step_size) - * MM_TO_ENCODER_COUNTS - + exposure_distance_counts - ), - PULSE_WIDTH_US, - 1, - SPACE_WIDTH_US, - 0, + expected_seq_table: SeqTable = ( + SeqTable.row( + repeats=1, + trigger=SeqTrigger.BITA_1, + position=0, + time1=False, + outa1=False, + time2=True, + outa2=False, + ) + + SeqTable.row( + repeats=x_steps, + trigger=SeqTrigger.POSA_GT, + position=int(params.x_start * MM_TO_ENCODER_COUNTS), + time1=PULSE_WIDTH_US, + outa1=True, + time2=SPACE_WIDTH_US, + outa2=False, + ) + + SeqTable.row( + repeats=1, + trigger=SeqTrigger.BITA_1, + position=0, + time1=False, + outa1=False, + time2=True, + outa2=False, + ) + + SeqTable.row( + repeats=x_steps, + trigger=SeqTrigger.POSA_LT, + position=int( + (params.x_start + (params.x_steps - 1) * params.x_step_size) + * MM_TO_ENCODER_COUNTS + + exposure_distance_counts ), - ] + time1=PULSE_WIDTH_US, + outa1=True, + time2=SPACE_WIDTH_US, + outa2=False, + ) ) - for key in SeqRow._fields: + for attr_name in table.__annotations__.keys(): np.testing.assert_array_equal( - table.get(key), - [getattr(row, key) for row in expected_seq_rows], - f"Sequence table for field {key} does not match", + getattr(table, attr_name), getattr(expected_seq_table, attr_name) ) From 9312c9cee36be48bf019df6a8d48fbcebf5d8229 Mon Sep 17 00:00:00 2001 From: Oliver Silvester Date: Fri, 20 Sep 2024 13:47:57 +0100 Subject: [PATCH 2/5] New dodal pin --- hyperion_other/workflows/test_data/setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperion_other/workflows/test_data/setup.cfg b/hyperion_other/workflows/test_data/setup.cfg index e16c14c2f..a1b6392d9 100644 --- a/hyperion_other/workflows/test_data/setup.cfg +++ b/hyperion_other/workflows/test_data/setup.cfg @@ -29,7 +29,7 @@ install_requires = opentelemetry-exporter-jaeger ophyd semver - dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@0aabdb389f65a30e629cec60a36c3b5298b7647f + dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@3f59ce090dd5c5f94f761b4b80a61cbd34d90564 pydantic<2.0 # See https://github.com/DiamondLightSource/hyperion/issues/774 scipy pyzmq From 13adc23a75a145f5134445fb587bac416977b1ec Mon Sep 17 00:00:00 2001 From: Oliver Silvester Date: Fri, 20 Sep 2024 13:56:46 +0100 Subject: [PATCH 3/5] Pin dodal in correct place --- hyperion_other/workflows/test_data/setup.cfg | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hyperion_other/workflows/test_data/setup.cfg b/hyperion_other/workflows/test_data/setup.cfg index a1b6392d9..e16c14c2f 100644 --- a/hyperion_other/workflows/test_data/setup.cfg +++ b/hyperion_other/workflows/test_data/setup.cfg @@ -29,7 +29,7 @@ install_requires = opentelemetry-exporter-jaeger ophyd semver - dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@3f59ce090dd5c5f94f761b4b80a61cbd34d90564 + dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@0aabdb389f65a30e629cec60a36c3b5298b7647f pydantic<2.0 # See https://github.com/DiamondLightSource/hyperion/issues/774 scipy pyzmq diff --git a/pyproject.toml b/pyproject.toml index 0b4d50da6..2dffd57e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,7 @@ dependencies = [ "ophyd == 1.9.0", "ophyd-async >= 0.3a5", "bluesky >= 1.13.0a4", - "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@040a72885deaca1055a930f09eccef4acca812f5", + "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@3f59ce090dd5c5f94f761b4b80a61cbd34d90564", ] From 7e860eaaa8e8d72388236159aecd5b32aed103ad Mon Sep 17 00:00:00 2001 From: Oliver Silvester Date: Fri, 20 Sep 2024 14:57:01 +0100 Subject: [PATCH 4/5] Support modified undulator_dcm --- .../device_setup_plans/dcm_pitch_roll_mirror_adjuster.py | 4 ++-- tests/conftest.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mx_bluesky/hyperion/device_setup_plans/dcm_pitch_roll_mirror_adjuster.py b/src/mx_bluesky/hyperion/device_setup_plans/dcm_pitch_roll_mirror_adjuster.py index 1b9a9c17a..9ece161c4 100644 --- a/src/mx_bluesky/hyperion/device_setup_plans/dcm_pitch_roll_mirror_adjuster.py +++ b/src/mx_bluesky/hyperion/device_setup_plans/dcm_pitch_roll_mirror_adjuster.py @@ -87,7 +87,7 @@ def adjust_dcm_pitch_roll_vfm_from_lut( bragg_deg = yield from bps.rd(dcm.bragg_in_degrees.user_readback) LOGGER.info(f"Read Bragg angle = {bragg_deg} degrees") dcm_pitch_adjuster = lookup_table_adjuster( - linear_interpolation_lut(undulator_dcm.dcm_pitch_converter_lookup_table_path), + linear_interpolation_lut(undulator_dcm.pitch_energy_table_path), dcm.pitch_in_mrad, bragg_deg, ) @@ -97,7 +97,7 @@ def adjust_dcm_pitch_roll_vfm_from_lut( # DCM Roll dcm_roll_adjuster = lookup_table_adjuster( - linear_interpolation_lut(undulator_dcm.dcm_roll_converter_lookup_table_path), + linear_interpolation_lut(undulator_dcm.roll_energy_table_path), dcm.roll_in_mrad, bragg_deg, ) diff --git a/tests/conftest.py b/tests/conftest.py index 3bb0ddaf4..d477f08e3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -439,10 +439,10 @@ def vfm_mirror_voltages(): def undulator_dcm(RE, dcm): undulator_dcm = i03.undulator_dcm(fake_with_ophyd_sim=True) undulator_dcm.dcm = dcm - undulator_dcm.dcm_roll_converter_lookup_table_path = ( + undulator_dcm.roll_energy_table_path = ( "tests/test_data/test_beamline_dcm_roll_converter.txt" ) - undulator_dcm.dcm_pitch_converter_lookup_table_path = ( + undulator_dcm.pitch_energy_table_path = ( "tests/test_data/test_beamline_dcm_pitch_converter.txt" ) yield undulator_dcm From c3009f115ecf122a8a3773fc947fc416a354bbc6 Mon Sep 17 00:00:00 2001 From: Oliver Silvester Date: Fri, 20 Sep 2024 16:49:30 +0100 Subject: [PATCH 5/5] Fix test plan system --- .../hyperion/experiment_plans/test_plan_system.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/system_tests/hyperion/experiment_plans/test_plan_system.py b/tests/system_tests/hyperion/experiment_plans/test_plan_system.py index f7f699c68..b0d4eb682 100644 --- a/tests/system_tests/hyperion/experiment_plans/test_plan_system.py +++ b/tests/system_tests/hyperion/experiment_plans/test_plan_system.py @@ -25,7 +25,9 @@ async def test_getting_data_for_ispyb(): params = GDABeamlineParameters.from_file(BEAMLINE_PARAMETER_PATHS["i03"]) undulator = Undulator( - f"{CONST.SIM.INSERTION_PREFIX}-MO-SERVC-01:", name="undulator" + f"{CONST.SIM.INSERTION_PREFIX}-MO-SERVC-01:", + name="undulator", + id_gap_lookup_table_path="/dls_sw/i03/software/daq_configuration/lookup/BeamLine_Undulator_toGap.txt", ) synchrotron = i03.synchrotron(fake_with_ophyd_sim=True) slit_gaps = S4SlitGaps(f"{CONST.SIM.BEAMLINE}-AL-SLITS-04:", name="slits")