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

Only use config server if GDA didn't supply params #496

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/mx_bluesky/hyperion/external_interaction/config_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def config_server() -> ConfigServer:
class FeatureFlags(BaseModel):
# The default value will be used as the fallback when doing a best-effort fetch
# from the service
use_panda_for_gridscan: bool = False
use_gpu_for_gridscan: bool = False
set_stub_offsets: bool = False
use_panda_for_gridscan: bool = CONST.I03.USE_PANDA_FOR_GRIDSCAN
use_gpu_for_gridscan: bool = CONST.I03.USE_PANDA_FOR_GRIDSCAN
set_stub_offsets: bool = CONST.I03.SET_STUB_OFFSETS

@classmethod
def _get_flags(cls):
Expand Down
1 change: 1 addition & 0 deletions src/mx_bluesky/hyperion/parameters/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class I03Constants:
USE_PANDA_FOR_GRIDSCAN = False
USE_GPU_FOR_GRIDSCAN_ANALYSIS = False
THAWING_TIME = 20
SET_STUB_OFFSETS = False


@dataclass(frozen=True)
Expand Down
18 changes: 15 additions & 3 deletions src/mx_bluesky/hyperion/parameters/gridscan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
from typing import Any

from dodal.devices.aperturescatterguard import ApertureValue
from dodal.devices.detector import (
Expand All @@ -10,10 +11,11 @@
PandAGridScanParams,
ZebraGridScanParams,
)
from pydantic import Field, PrivateAttr
from pydantic import Field, PrivateAttr, model_validator
from scanspec.core import Path as ScanPath
from scanspec.specs import Line, Static

from mx_bluesky.hyperion.external_interaction.config_server import FeatureFlags
from mx_bluesky.hyperion.parameters.components import (
DiffractionExperimentWithSample,
IspybExperimentType,
Expand All @@ -29,19 +31,29 @@
class GridCommon(
DiffractionExperimentWithSample, OptionalGonioAngleStarts, WithOavCentring
):
use_panda: bool
use_gpu: bool
grid_width_um: float = Field(default=CONST.PARAM.GRIDSCAN.WIDTH_UM)
exposure_time_s: float = Field(default=CONST.PARAM.GRIDSCAN.EXPOSURE_TIME_S)
use_roi_mode: bool = Field(default=CONST.PARAM.GRIDSCAN.USE_ROI)
panda_runup_distance_mm: float = Field(
default=CONST.HARDWARE.PANDA_FGS_RUN_UP_DEFAULT
)
use_panda: bool = Field(default=CONST.I03.USE_PANDA_FOR_GRIDSCAN)
use_gpu: bool = Field(default=CONST.I03.USE_GPU_FOR_GRIDSCAN_ANALYSIS)
ispyb_experiment_type: IspybExperimentType = Field(
default=IspybExperimentType.GRIDSCAN_3D
)
selected_aperture: ApertureValue | None = Field(default=ApertureValue.SMALL)

@model_validator(mode="before")
@classmethod
def set_default_feature_flags(cls, values) -> Any:
cls.features = FeatureFlags()
if "use_panda" not in values:
values["use_panda"] = cls.features.best_effort().use_panda_for_gridscan
if "use_gpu" not in values:
values["use_gpu"] = cls.features.best_effort().use_gpu_for_gridscan
return values

@property
def detector_params(self):
self.det_dist_to_beam_converter_path = (
Expand Down
11 changes: 11 additions & 0 deletions tests/unit_tests/hyperion/parameters/test_parameter_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,14 @@ def test_selected_aperture_uses_default():
raw_params["selected_aperture"] = None
params = RotationScan(**raw_params)
assert params.selected_aperture == ApertureValue.LARGE


def test_feature_flags_overriden_if_supplied(minimal_3d_gridscan_params):
test_params = ThreeDGridScan(**minimal_3d_gridscan_params)
assert test_params.use_panda is False
assert test_params.use_gpu is False
minimal_3d_gridscan_params["use_panda"] = True
minimal_3d_gridscan_params["use_gpu"] = True
test_params = ThreeDGridScan(**minimal_3d_gridscan_params)
assert test_params.use_gpu
assert test_params.use_panda
Loading