Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly pass parameters through all of Hyperion's UDC parameters #746

Merged
merged 12 commits into from
Jan 17, 2025
2 changes: 1 addition & 1 deletion src/mx_bluesky/common/parameters/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
GridscanParamConstants,
)

PARAMETER_VERSION = Version.parse("5.2.0")
PARAMETER_VERSION = Version.parse("5.3.0")


class RotationAxis(StrEnum):
Expand Down
13 changes: 0 additions & 13 deletions src/mx_bluesky/common/parameters/gridscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
GridscanParamConstants,
HardwareConstants,
)
from mx_bluesky.common.parameters.robot_load import RobotLoadAndEnergyChange


class GridCommon(
Expand Down Expand Up @@ -73,20 +72,8 @@ def detector_params(self):
**optional_args,
)


class RobotLoadThenCentre(GridCommon):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with @rtuck99 - we're so far off any non-hyperion beamlines doing anything other than a grid scan, it's probably good to get rid of some of the common parameters like this one

thawing_time: float = Field(default=HardwareConstants.THAWING_TIME)
tip_offset_um: float = Field(default=HardwareConstants.TIP_OFFSET_UM)

def robot_load_params(self):
my_params = self.model_dump()
return RobotLoadAndEnergyChange(**my_params)

def pin_centre_then_xray_centre_params(self):
my_params = self.model_dump()
del my_params["thawing_time"]
return PinTipCentreThenXrayCentre(**my_params)


class GridScanWithEdgeDetect(GridCommon):
box_size_um: float = Field(default=GridscanParamConstants.BOX_WIDTH_UM)
Expand Down
14 changes: 14 additions & 0 deletions src/mx_bluesky/common/parameters/robot_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,23 @@
WithVisit,
)
from mx_bluesky.common.parameters.constants import HardwareConstants
from mx_bluesky.common.parameters.gridscan import GridCommon, PinTipCentreThenXrayCentre


class RobotLoadAndEnergyChange(
MxBlueskyParameters, WithSample, WithSnapshot, WithOptionalEnergyChange, WithVisit
):
thawing_time: float = Field(default=HardwareConstants.THAWING_TIME)


class RobotLoadThenCentre(GridCommon):
thawing_time: float = Field(default=HardwareConstants.THAWING_TIME)

def robot_load_params(self):
my_params = self.model_dump()
return RobotLoadAndEnergyChange(**my_params)

Check warning on line 25 in src/mx_bluesky/common/parameters/robot_load.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/common/parameters/robot_load.py#L24-L25

Added lines #L24 - L25 were not covered by tests

def pin_centre_then_xray_centre_params(self):
my_params = self.model_dump()
del my_params["thawing_time"]
return PinTipCentreThenXrayCentre(**my_params)

Check warning on line 30 in src/mx_bluesky/common/parameters/robot_load.py

View check run for this annotation

Codecov / codecov/patch

src/mx_bluesky/common/parameters/robot_load.py#L28-L30

Added lines #L28 - L30 were not covered by tests
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from mx_bluesky.common.parameters.gridscan import (
GridScanWithEdgeDetect,
PinTipCentreThenXrayCentre,
RobotLoadThenCentre,
)
from mx_bluesky.hyperion.experiment_plans import (
grid_detect_then_xray_centre_plan,
Expand All @@ -25,6 +24,7 @@
)
from mx_bluesky.hyperion.parameters.gridscan import HyperionThreeDGridScan
from mx_bluesky.hyperion.parameters.load_centre_collect import LoadCentreCollect
from mx_bluesky.hyperion.parameters.robot_load import HyperionRobotLoadThenCentre
from mx_bluesky.hyperion.parameters.rotation import MultiRotationScan, RotationScan


Expand All @@ -44,8 +44,8 @@ class ExperimentRegistryEntry(TypedDict):
| RotationScan
| MultiRotationScan
| PinTipCentreThenXrayCentre
| RobotLoadThenCentre
| LoadCentreCollect
| HyperionRobotLoadThenCentre
]
callbacks_factory: CallbacksFactory

Expand Down Expand Up @@ -73,7 +73,7 @@ class ExperimentRegistryEntry(TypedDict):
},
"robot_load_then_centre": {
"setup": robot_load_then_centre_plan.create_devices,
"param_type": RobotLoadThenCentre,
"param_type": HyperionRobotLoadThenCentre,
"callbacks_factory": create_robot_load_and_centre_callbacks,
},
"multi_rotation_scan": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from ophyd_async.fastcs.panda import HDFPanda

from mx_bluesky.common.parameters.constants import OavConstants
from mx_bluesky.common.parameters.gridscan import RobotLoadThenCentre
from mx_bluesky.hyperion.device_setup_plans.utils import (
fill_in_energy_if_not_supplied,
start_preparing_data_collection_then_do_plan,
Expand All @@ -64,6 +63,7 @@
set_energy_plan,
)
from mx_bluesky.hyperion.parameters.constants import CONST
from mx_bluesky.hyperion.parameters.robot_load import HyperionRobotLoadThenCentre


@pydantic.dataclasses.dataclass(config={"arbitrary_types_allowed": True})
Expand Down Expand Up @@ -113,7 +113,7 @@ def create_devices(context: BlueskyContext) -> RobotLoadThenCentreComposite:

def _flyscan_plan_from_robot_load_params(
composite: RobotLoadThenCentreComposite,
params: RobotLoadThenCentre,
params: HyperionRobotLoadThenCentre,
oav_config_file: str = OavConstants.OAV_CONFIG_JSON,
):
yield from pin_centre_then_flyscan_plan(
Expand All @@ -124,7 +124,7 @@ def _flyscan_plan_from_robot_load_params(

def _robot_load_then_flyscan_plan(
composite: RobotLoadThenCentreComposite,
params: RobotLoadThenCentre,
params: HyperionRobotLoadThenCentre,
oav_config_file: str = OavConstants.OAV_CONFIG_JSON,
):
yield from robot_load_and_change_energy_plan(
Expand All @@ -137,7 +137,7 @@ def _robot_load_then_flyscan_plan(

def robot_load_then_centre(
composite: RobotLoadThenCentreComposite,
parameters: RobotLoadThenCentre,
parameters: HyperionRobotLoadThenCentre,
) -> MsgGenerator:
"""Perform pin-tip detection followed by a flyscan to determine centres of interest.
Performs a robot load if necessary. Centre on the best diffracting centre.
Expand All @@ -158,7 +158,7 @@ def robot_load_then_centre(

def robot_load_then_xray_centre(
composite: RobotLoadThenCentreComposite,
parameters: RobotLoadThenCentre,
parameters: HyperionRobotLoadThenCentre,
) -> MsgGenerator:
"""Perform pin-tip detection followed by a flyscan to determine centres of interest.
Performs a robot load if necessary."""
Expand Down
5 changes: 3 additions & 2 deletions src/mx_bluesky/hyperion/parameters/components.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pydantic import BaseModel, Field
from pydantic import Field

from mx_bluesky.common.parameters.components import WithPandaGridScan
from mx_bluesky.hyperion.external_interaction.config_server import HyperionFeatureFlags


class WithHyperionFeatures(BaseModel):
class WithHyperionUDCFeatures(WithPandaGridScan):
features: HyperionFeatureFlags = Field(default=HyperionFeatureFlags())
23 changes: 14 additions & 9 deletions src/mx_bluesky/hyperion/parameters/gridscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@
ZebraGridScanParams,
)

from mx_bluesky.common.parameters.components import (
WithPandaGridScan,
)
from mx_bluesky.common.parameters.gridscan import (
GridScanWithEdgeDetect,
PinTipCentreThenXrayCentre,
ThreeDGridScan,
)
from mx_bluesky.hyperion.parameters.components import WithHyperionFeatures
from mx_bluesky.hyperion.parameters.components import WithHyperionUDCFeatures
from mx_bluesky.hyperion.parameters.constants import CONST, I03Constants


class HyperionThreeDGridScan(
ThreeDGridScan,
WithPandaGridScan,
WithHyperionFeatures,
):
class HyperionThreeDGridScan(ThreeDGridScan, WithHyperionUDCFeatures):
"""Hyperion's 3D grid scan varies from the common class due to: optionally using a PandA, optionally using dev_shm for GPU analysis, and using a config server for features"""

# These detector params only exist so that we can properly select enable_dev_shm. Remove in
Expand Down Expand Up @@ -103,3 +98,13 @@ def panda_FGS_params(self) -> PandAGridScanParams:


class OddYStepsException(Exception): ...


class HyperionPinTipCentreThenXrayCentre(
PinTipCentreThenXrayCentre, WithHyperionUDCFeatures
): ...


class HyperionGridScanWithEdgeDetect(
olliesilvester marked this conversation as resolved.
Show resolved Hide resolved
GridScanWithEdgeDetect, WithHyperionUDCFeatures
): ...
17 changes: 11 additions & 6 deletions src/mx_bluesky/hyperion/parameters/load_centre_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
WithSample,
WithVisit,
)
from mx_bluesky.common.parameters.gridscan import (
RobotLoadThenCentre,
from mx_bluesky.hyperion.parameters.components import WithHyperionUDCFeatures
from mx_bluesky.hyperion.parameters.robot_load import (
HyperionRobotLoadThenCentre,
)
from mx_bluesky.hyperion.parameters.rotation import MultiRotationScan

Expand All @@ -23,20 +24,24 @@ def construct_from_values(parent_context: dict, child_dict: dict, t: type[T]) ->


class LoadCentreCollect(
MxBlueskyParameters, WithVisit, WithSample, WithCentreSelection
MxBlueskyParameters,
WithVisit,
WithSample,
WithCentreSelection,
WithHyperionUDCFeatures,
):
"""Experiment parameters to perform the combined robot load,
pin-tip centre and rotation scan operations."""

robot_load_then_centre: RobotLoadThenCentre
robot_load_then_centre: HyperionRobotLoadThenCentre
multi_rotation_scan: MultiRotationScan

@model_validator(mode="before")
@classmethod
def validate_model(cls, values):
allowed_keys = (
LoadCentreCollect.model_fields.keys()
| RobotLoadThenCentre.model_fields.keys()
| HyperionRobotLoadThenCentre.model_fields.keys()
| MultiRotationScan.model_fields.keys()
)

Expand Down Expand Up @@ -66,7 +71,7 @@ def validate_model(cls, values):
)

new_robot_load_then_centre_params = construct_from_values(
values, values["robot_load_then_centre"], RobotLoadThenCentre
values, values["robot_load_then_centre"], HyperionRobotLoadThenCentre
)
new_multi_rotation_scan_params = construct_from_values(
values, values["multi_rotation_scan"], MultiRotationScan
Expand Down
23 changes: 23 additions & 0 deletions src/mx_bluesky/hyperion/parameters/robot_load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pydantic import Field

from mx_bluesky.common.parameters.constants import HardwareConstants
from mx_bluesky.common.parameters.robot_load import (
RobotLoadAndEnergyChange,
RobotLoadThenCentre,
)
from mx_bluesky.hyperion.parameters.components import WithHyperionUDCFeatures
from mx_bluesky.hyperion.parameters.gridscan import HyperionPinTipCentreThenXrayCentre


class HyperionRobotLoadThenCentre(RobotLoadThenCentre, WithHyperionUDCFeatures):
thawing_time: float = Field(default=HardwareConstants.THAWING_TIME)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thawing_time is also in RobotLoadThenCentre
tip_offset_um is also in GridCommon

tip_offset_um: float = Field(default=HardwareConstants.TIP_OFFSET_UM)

def robot_load_params(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these methods have annotations? That way tooling can help more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes to annotations!

I'll make them properties as that's probably more consistent with the other params

my_params = self.model_dump()
return RobotLoadAndEnergyChange(**my_params)

def pin_centre_then_xray_centre_params(self):
my_params = self.model_dump()
del my_params["thawing_time"]
return HyperionPinTipCentreThenXrayCentre(**my_params)
4 changes: 2 additions & 2 deletions src/mx_bluesky/hyperion/parameters/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
SplitScan,
WithScan,
)
from mx_bluesky.hyperion.parameters.components import WithHyperionFeatures
from mx_bluesky.hyperion.parameters.components import WithHyperionUDCFeatures
from mx_bluesky.hyperion.parameters.constants import (
CONST,
I03Constants,
Expand All @@ -53,7 +53,7 @@ class RotationScanPerSweep(OptionalGonioAngleStarts, OptionalXyzStarts):
nexus_vds_start_img: int = Field(default=0, ge=0)


class RotationExperiment(DiffractionExperimentWithSample, WithHyperionFeatures):
class RotationExperiment(DiffractionExperimentWithSample, WithHyperionUDCFeatures):
shutter_opening_time_s: float = Field(default=CONST.I03.SHUTTER_TIME_S)
rotation_increment_deg: float = Field(default=0.1, gt=0)
ispyb_experiment_type: IspybExperimentType = Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"exposure_time_s": 0.004,
"use_roi_mode": false,
"demand_energy_ev": 11100,
"run_number": 0
"run_number": 0,
"features": {"use_panda_for_gridscan": false, "compare_cpu_and_gpu_zocalo": true},
"panda_runup_distance_mm": 0.17
},
"multi_rotation_scan": {
"comment": "Rotation",
Expand Down
Loading
Loading