Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

New external parameter model #1284

Merged
merged 48 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
adc81d1
(#698) introduce new parameter model skeleton side by side
d-perl Mar 22, 2024
d4a75c6
(#698) start writing some tests
d-perl Mar 22, 2024
1140f99
(#698) start writing some tests
d-perl Mar 22, 2024
c31720e
(#698) fix some typing
d-perl Mar 22, 2024
f56d9e0
(#698) fix some typing
d-perl Mar 22, 2024
fdc6746
(#698) add ispyb extras
d-perl Mar 25, 2024
a82bf40
(#698) start testing difference between old and new params
d-perl Mar 25, 2024
ead8167
(#698) make old and new detector and ispyb params match
d-perl Mar 25, 2024
5ecb0fe
(#698) disallow extra params
d-perl Mar 25, 2024
d1785cf
(#698) add new params
d-perl Mar 25, 2024
b41b1d4
(#698) ignore pyright errors
d-perl Mar 25, 2024
dbd1c1e
(#698) fix pyright errors
d-perl Mar 25, 2024
ac62c6d
(#698) remove all uses of @cache because it doesn't play nice with py…
d-perl Mar 26, 2024
9079d6d
(#698) make old and new rotation params match
d-perl Mar 26, 2024
81d0972
(#698) replace param types in registry
d-perl Mar 26, 2024
d03254f
(#698) delete schema and validation
d-perl Mar 26, 2024
042bca1
(#698) fix most tests
d-perl Mar 26, 2024
4602a90
(#698) implement 3d scan spec
d-perl Mar 27, 2024
a421f7b
(#698) add omega to scanspec
d-perl Mar 27, 2024
04841d4
(#698) fix some typing
d-perl Mar 27, 2024
274bf28
(#698) add scan indices to 3d gridscan
d-perl Mar 27, 2024
5be82c7
(#698) fix tests
d-perl Mar 27, 2024
f12c703
(#698) allow using new params in FGS plan
d-perl Mar 27, 2024
e261ded
(#698) fix typing
d-perl Mar 27, 2024
59916e7
(#698) fix typing
d-perl Mar 27, 2024
1448c88
(#698) add test that all plans have correct param input type
d-perl Mar 27, 2024
992dac6
(#698) start adding new params to more plan inputs
d-perl Mar 27, 2024
3ad112d
Merge branch 'main' into 698_new_external_param_model
d-perl Mar 27, 2024
7acd80c
(#698) add new params to all plan inputs
d-perl Mar 28, 2024
354c9e8
(#698) add test comparing new params added to GDA
d-perl Mar 28, 2024
df3d538
(#698) fix stuff in response to review comments
d-perl Apr 3, 2024
00dd6a0
(#698) fix stuff in response to review comments
d-perl Apr 3, 2024
ba3baeb
Merge branch 'main' into 698_new_external_param_model
d-perl Apr 3, 2024
d8af6e1
Merge branch 'main' into 698_new_external_param_model
d-perl Apr 4, 2024
4deaf03
(#698) fix errors from merge and tests
d-perl Apr 4, 2024
f71170e
(#698) add test mode lut path
d-perl Apr 4, 2024
9b01f68
(#698) fix typo
d-perl Apr 4, 2024
24f32b6
(#698) add comment to test
d-perl Apr 4, 2024
c72fdce
(#698) add comments things which can be removed in 1277
d-perl Apr 4, 2024
f8435f3
(#698) add test for new vs old rotation scan params
d-perl Apr 5, 2024
8b70b08
remove 2d grid scan params
d-perl Apr 11, 2024
f87e6ea
(#698) address review comments
d-perl Apr 11, 2024
b3e7cfe
merge main
d-perl Apr 11, 2024
3588167
(#698) fix up from merge
d-perl Apr 11, 2024
6d8a8c1
(#698) make directories if necessary
d-perl Apr 12, 2024
5b68ead
Merge branch 'main' into 698_new_external_param_model
d-perl Apr 12, 2024
0b1298c
Merge branch 'main' into 698_new_external_param_model
d-perl Apr 22, 2024
746f9d9
add some comments
d-perl Apr 22, 2024
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
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"debug-test"
],
"env": {
"PYTEST_ADDOPTS": "--no-cov --random-order"
"PYTEST_ADDOPTS": "--no-cov --random-order -vv"
},
}
]
Expand Down
2 changes: 2 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pytest

environ["HYPERION_TEST_MODE"] = "true"

print("Adjusting S03 EPICS environment ...")
s03_epics_server_port = getenv("S03_EPICS_CA_SERVER_PORT")
s03_epics_repeater_port = getenv("S03_EPICS_CA_REPEATER_PORT")
Expand Down
20 changes: 10 additions & 10 deletions src/hyperion/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import atexit
import json
import threading
from dataclasses import asdict
from queue import Queue
Expand Down Expand Up @@ -34,8 +35,8 @@
)
from hyperion.log import LOGGER, do_default_logging_setup
from hyperion.parameters.cli import parse_cli_args
from hyperion.parameters.components import HyperionParameters
from hyperion.parameters.constants import CONST, Actions, Status
from hyperion.parameters.internal_parameters import InternalParameters
from hyperion.tracing import TRACER
from hyperion.utils.context import setup_context

Expand All @@ -47,7 +48,7 @@ class Command:
action: Actions
devices: Optional[Any] = None
experiment: Optional[Callable[[Any, Any], MsgGenerator]] = None
parameters: Optional[InternalParameters] = None
parameters: Optional[HyperionParameters] = None
callbacks: Optional[CallbacksFactory] = None


Expand Down Expand Up @@ -109,7 +110,7 @@ def __init__(
def start(
self,
experiment: Callable,
parameters: InternalParameters,
parameters: HyperionParameters,
plan_name: str,
callbacks: Optional[CallbacksFactory],
) -> StatusAndMessage:
Expand Down Expand Up @@ -225,13 +226,12 @@ def compose_start_args(context: BlueskyContext, plan_name: str, action: Actions)
raise PlanNotFound(
f"Experiment plan '{plan_name}' not found in context. Context has {context.plan_functions.keys()}"
)

parameters = experiment_internal_param_type.from_json(request.data)
if plan_name != parameters.hyperion_params.experiment_type:
raise PlanNotFound(
f"Wrong experiment parameters ({parameters.hyperion_params.experiment_type}) "
f"for plan endpoint {plan_name}."
)
try:
parameters = experiment_internal_param_type(**json.loads(request.data))
except Exception as e:
raise ValueError(
"Supplied parameters don't match the plan for this endpoint"
) from e
return plan, parameters, plan_name, callback_type


Expand Down
40 changes: 18 additions & 22 deletions src/hyperion/experiment_plans/experiment_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,25 @@
create_gridscan_callbacks,
create_rotation_callbacks,
)
from hyperion.parameters.gridscan import (
GridScanWithEdgeDetect,
PinTipCentreThenXrayCentre,
RobotLoadThenCentre,
ThreeDGridScan,
)
from hyperion.parameters.plan_specific.grid_scan_with_edge_detect_params import (
GridScanWithEdgeDetectInternalParameters,
GridScanWithEdgeDetectParams,
)
from hyperion.parameters.plan_specific.gridscan_internal_params import (
GridscanInternalParameters,
)
from hyperion.parameters.plan_specific.panda.panda_gridscan_internal_params import (
PandAGridscanInternalParameters,
)
from hyperion.parameters.plan_specific.pin_centre_then_xray_centre_params import (
PinCentreThenXrayCentreInternalParameters,
PinCentreThenXrayCentreParams,
)
from hyperion.parameters.plan_specific.robot_load_then_center_params import (
RobotLoadThenCentreInternalParameters,
RobotLoadThenCentreParams,
)
from hyperion.parameters.plan_specific.rotation_scan_internal_params import (
RotationInternalParameters,
RotationScanParams,
)
from hyperion.parameters.rotation import RotationScan


def not_implemented():
Expand All @@ -54,12 +51,11 @@ def do_nothing():
class ExperimentRegistryEntry(TypedDict):
setup: Callable
internal_param_type: type[
GridscanInternalParameters
| GridScanWithEdgeDetectInternalParameters
| RotationInternalParameters
| PinCentreThenXrayCentreInternalParameters
| RobotLoadThenCentreInternalParameters
| PandAGridscanInternalParameters
ThreeDGridScan
| GridScanWithEdgeDetect
| RotationScan
| PinTipCentreThenXrayCentre
| RobotLoadThenCentre
]
experiment_param_type: type[AbstractExperimentWithBeamParams]
callbacks_factory: CallbacksFactory
Expand All @@ -69,37 +65,37 @@ class ExperimentRegistryEntry(TypedDict):
PLAN_REGISTRY: dict[str, ExperimentRegistryEntry] = {
"panda_flyscan_xray_centre": {
"setup": panda_flyscan_xray_centre_plan.create_devices,
"internal_param_type": PandAGridscanInternalParameters,
"internal_param_type": ThreeDGridScan,
"experiment_param_type": PandAGridScanParams,
"callbacks_factory": create_gridscan_callbacks,
},
"flyscan_xray_centre": {
"setup": flyscan_xray_centre_plan.create_devices,
"internal_param_type": GridscanInternalParameters,
"internal_param_type": ThreeDGridScan,
"experiment_param_type": GridScanParams,
"callbacks_factory": create_gridscan_callbacks,
},
"grid_detect_then_xray_centre": {
"setup": grid_detect_then_xray_centre_plan.create_devices,
"internal_param_type": GridScanWithEdgeDetectInternalParameters,
"internal_param_type": GridScanWithEdgeDetect,
"experiment_param_type": GridScanWithEdgeDetectParams,
"callbacks_factory": create_gridscan_callbacks,
},
"rotation_scan": {
"setup": rotation_scan_plan.create_devices,
"internal_param_type": RotationInternalParameters,
"internal_param_type": RotationScan,
"experiment_param_type": RotationScanParams,
"callbacks_factory": create_rotation_callbacks,
},
"pin_tip_centre_then_xray_centre": {
"setup": pin_centre_then_xray_centre_plan.create_devices,
"internal_param_type": PinCentreThenXrayCentreInternalParameters,
"internal_param_type": PinTipCentreThenXrayCentre,
"experiment_param_type": PinCentreThenXrayCentreParams,
"callbacks_factory": create_gridscan_callbacks,
},
"robot_load_then_centre": {
"setup": robot_load_then_centre_plan.create_devices,
"internal_param_type": RobotLoadThenCentreInternalParameters,
"internal_param_type": RobotLoadThenCentre,
Copy link
Contributor

Choose a reason for hiding this comment

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

When I started in Hyperion, I found it confusing that we sometimes call it 'centring' and sometimes 'xray-centing' - I thought they were different things

Copy link
Collaborator

Choose a reason for hiding this comment

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

They sort of are. In this case centre means pin tip centre centre then xray centre. I think it's ok to basically assume "centre" means do the full centring. But I appreciate it's not obvious

"experiment_param_type": RobotLoadThenCentreParams,
"callbacks_factory": create_gridscan_callbacks,
},
Expand Down
30 changes: 20 additions & 10 deletions src/hyperion/experiment_plans/flyscan_xray_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@
from hyperion.exceptions import WarningException
from hyperion.log import LOGGER
from hyperion.parameters.constants import CONST
from hyperion.parameters.gridscan import ThreeDGridScan
from hyperion.parameters.plan_specific.gridscan_internal_params import (
GridscanInternalParameters,
)
from hyperion.tracing import TRACER
from hyperion.utils.aperturescatterguard import (
load_default_aperture_scatterguard_positions_if_unset,
)
from hyperion.utils.context import device_composite_from_context

if TYPE_CHECKING:
from hyperion.parameters.plan_specific.gridscan_internal_params import (
GridscanInternalParameters,
)

PandaOrZebraGridscan = FastGridScan | PandAFastGridScan
from scanspec.core import AxesPoints, Axis

Expand Down Expand Up @@ -324,7 +324,7 @@ def run_gridscan_and_move(

def flyscan_xray_centre(
composite: FlyScanXRayCentreComposite,
parameters: Any,
parameters: ThreeDGridScan | GridscanInternalParameters | Any,
) -> MsgGenerator:
"""Create the plan to run the grid scan based on provided parameters.

Expand All @@ -337,15 +337,25 @@ def flyscan_xray_centre(
Returns:
Generator: The plan for the gridscan
"""
composite.eiger.set_detector_parameters(parameters.hyperion_params.detector_params)
composite.zocalo.zocalo_environment = parameters.hyperion_params.zocalo_environment

old_parameters = (
parameters
if isinstance(parameters, GridscanInternalParameters)
else parameters.old_parameters()
)
composite.eiger.set_detector_parameters(
old_parameters.hyperion_params.detector_params
)
composite.zocalo.zocalo_environment = (
old_parameters.hyperion_params.zocalo_environment
)

@bpp.set_run_key_decorator(CONST.PLAN.GRIDSCAN_OUTER)
@bpp.run_decorator( # attach experiment metadata to the start document
md={
"subplan_name": CONST.PLAN.GRIDSCAN_OUTER,
CONST.TRIGGER.ZOCALO: CONST.PLAN.DO_FGS,
"hyperion_internal_parameters": parameters.json(),
"hyperion_internal_parameters": old_parameters.json(),
"activate_callbacks": [
"GridscanISPyBCallback",
"GridscanNexusFileCallback",
Expand All @@ -356,9 +366,9 @@ def flyscan_xray_centre(
@transmission_and_xbpm_feedback_for_collection_decorator(
composite.xbpm_feedback,
composite.attenuator,
parameters.experiment_params.transmission_fraction,
old_parameters.experiment_params.transmission_fraction,
)
def run_gridscan_and_move_and_tidy(fgs_composite, params):
yield from run_gridscan_and_move(fgs_composite, params)

return run_gridscan_and_move_and_tidy(composite, parameters)
return run_gridscan_and_move_and_tidy(composite, old_parameters)
30 changes: 17 additions & 13 deletions src/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import dataclasses
import json
from typing import TYPE_CHECKING, Any
from typing import Any

import numpy as np
from blueapi.core import BlueskyContext, MsgGenerator
Expand All @@ -19,6 +19,7 @@
from dodal.devices.oav.oav_detector import OAV
from dodal.devices.oav.oav_parameters import OAV_CONFIG_JSON, OAVParameters
from dodal.devices.oav.pin_image_recognition import PinTipDetection
from dodal.devices.panda_fast_grid_scan import PandAFastGridScan
from dodal.devices.robot import BartRobot
from dodal.devices.s4_slit_gaps import S4SlitGaps
from dodal.devices.smargon import Smargon
Expand All @@ -27,6 +28,7 @@
from dodal.devices.xbpm_feedback import XBPMFeedback
from dodal.devices.zebra import Zebra
from dodal.devices.zocalo import ZocaloResults
from ophyd_async.panda import PandA

from hyperion.device_setup_plans.utils import (
start_preparing_data_collection_then_do_plan,
Expand All @@ -51,6 +53,11 @@
OavSnapshotCallback,
)
from hyperion.log import LOGGER
from hyperion.parameters.gridscan import GridScanWithEdgeDetect
from hyperion.parameters.plan_specific.grid_scan_with_edge_detect_params import (
GridScanWithEdgeDetectInternalParameters,
GridScanWithEdgeDetectParams,
)
from hyperion.parameters.plan_specific.gridscan_internal_params import (
GridscanInternalParameters,
GridScanParams,
Expand All @@ -64,14 +71,6 @@
)
from hyperion.utils.context import device_composite_from_context

if TYPE_CHECKING:
from hyperion.parameters.plan_specific.grid_scan_with_edge_detect_params import (
GridScanWithEdgeDetectInternalParameters,
GridScanWithEdgeDetectParams,
)
from dodal.devices.panda_fast_grid_scan import PandAFastGridScan
from ophyd_async.panda import PandA


@dataclasses.dataclass
class GridDetectThenXRayCentreComposite:
Expand Down Expand Up @@ -249,28 +248,33 @@ def run_grid_detection_plan(

def grid_detect_then_xray_centre(
composite: GridDetectThenXRayCentreComposite,
parameters: Any,
parameters: GridScanWithEdgeDetectInternalParameters | GridScanWithEdgeDetect | Any,
oav_config: str = OAV_CONFIG_JSON,
) -> MsgGenerator:
"""
A plan which combines the collection of snapshots from the OAV and the determination
of the grid dimensions to use for the following grid scan.
"""
old_parameters = (
parameters
if isinstance(parameters, GridScanWithEdgeDetectInternalParameters)
else parameters.old_parameters()
)
eiger: EigerDetector = composite.eiger

eiger.set_detector_parameters(parameters.hyperion_params.detector_params)
eiger.set_detector_parameters(old_parameters.hyperion_params.detector_params)

oav_params = OAVParameters("xrayCentring", oav_config)

plan_to_perform = detect_grid_and_do_gridscan(
composite,
parameters,
old_parameters,
oav_params,
)

return start_preparing_data_collection_then_do_plan(
eiger,
composite.detector_motion,
parameters.hyperion_params.detector_params.detector_distance,
old_parameters.hyperion_params.detector_params.detector_distance,
plan_to_perform,
)
Loading
Loading