Skip to content

Commit

Permalink
Merge branch 'main' into 240_do_not_robot_load_if_pin_already_loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Sep 13, 2024
2 parents eeee9ac + cc3b1f0 commit 0b562ff
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 19 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/publish_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ jobs:
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
tags: |
${{ steps.meta.outputs.tags }}
${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
file: Dockerfile.release
- name: Generate artifact attestation
# v1.4.0
uses: actions/attest-build-provenance@210c1913531870065f03ce1f9440dd87bc0938cd
Expand Down
20 changes: 11 additions & 9 deletions helmchart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ spec:
hostPath:
path: "{{ .Values.dodal.projectDir | clean }}"
type: Directory
{{- if .Values.hyperion.dev }}
- name: devlogs
- name: logs
hostPath:
path: "{{ .Values.hyperion.projectDir }}/tmp"
type: Directory
{{- end }}
path: "{{ .Values.hyperion.logDir }}"
- name: data
hostPath:
type: Directory
path: "{{ .Values.hyperion.dataDir }}"
containers:
- name: hyperion
image: {{ .Values.hyperion.imageRepository}}/hyperion:{{ .Values.hyperion.appVersion }}
Expand All @@ -66,7 +68,7 @@ spec:
protocol: TCP
env:
- name: HYPERION_LOG_DIR
value: {{ .Values.hyperion.logDir }}
value: /var/log/bluesky
- name: BEAMLINE
value: "{{ .Values.hyperion.beamline }}"
{{- if not .Values.hyperion.dev }}
Expand Down Expand Up @@ -105,7 +107,7 @@ spec:
name: utility-scripts
- mountPath: "/app/dodal"
name: dodal
{{- if .Values.hyperion.dev }}
- mountPath: "/app/hyperion/tmp"
name: devlogs
{{ end }}
- mountPath: "/var/log/bluesky"
name: logs
- mountPath: "/dls/{{ .Values.hyperion.beamline }}/data"
name: data
1 change: 1 addition & 0 deletions helmchart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ hyperion:
beamline: i03
dev: false
logDir: "/dls_sw/i03/logs/bluesky"
dataDir: "/dls/i03/data"
# These should be overridden at install time
projectDir: SET_ON_INSTALL
appVersion: SET_ON_INSTALL
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ filterwarnings = [
"ignore:(.*)unclosed event loop(.*):ResourceWarning",
# Ignore pydantic 2 issues from blueapi, see https://github.com/DiamondLightSource/blueapi/issues/622
"ignore::DeprecationWarning:blueapi",
# Ignore deprecation warning from python-workflows https://github.com/DiamondLightSource/python-workflows/issues/180
"ignore:.*pkg_resources.*:DeprecationWarning",
]
# Doctest python code in docs, python code in src docstrings, test functions in tests
testpaths = "docs src tests/unit_tests"
Expand Down
7 changes: 7 additions & 0 deletions src/mx_bluesky/hyperion/parameters/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from enum import Enum

from dodal.devices.aperturescatterguard import ApertureValue
from dodal.devices.detector import EIGER2_X_16M_SIZE
from pydantic.dataclasses import dataclass

Expand Down Expand Up @@ -77,6 +78,11 @@ class GridscanParamConstants:
OMEGA_2 = 90.0


@dataclass(frozen=True)
class RotationParamConstants:
DEFAULT_APERTURE_POSITION = ApertureValue.LARGE


@dataclass(frozen=True)
class DetectorParamConstants:
BEAM_XY_LUT_PATH = (
Expand All @@ -90,6 +96,7 @@ class DetectorParamConstants:
class ExperimentParamConstants:
DETECTOR = DetectorParamConstants()
GRIDSCAN = GridscanParamConstants()
ROTATION = RotationParamConstants()


_test_oav_file = "tests/test_data/test_OAVCentring.json"
Expand Down
23 changes: 20 additions & 3 deletions src/mx_bluesky/hyperion/parameters/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
from typing import Annotated, Any

from annotated_types import Len
from dodal.devices.aperturescatterguard import ApertureValue
from dodal.devices.detector import DetectorParams
from dodal.devices.zebra import (
RotationDirection,
)
from pydantic import Field, model_validator
from dodal.log import LOGGER
from pydantic import Field, field_validator, model_validator
from scanspec.core import AxesPoints
from scanspec.core import Path as ScanPath
from scanspec.specs import Line
Expand All @@ -25,7 +27,10 @@
TemporaryIspybExtras,
WithScan,
)
from mx_bluesky.hyperion.parameters.constants import CONST, I03Constants
from mx_bluesky.hyperion.parameters.constants import (
CONST,
I03Constants,
)


class RotationScanPerSweep(OptionalGonioAngleStarts, OptionalXyzStarts):
Expand All @@ -45,7 +50,7 @@ class RotationExperiment(DiffractionExperimentWithSample):
)

def _detector_params(self, omega_start_deg: float):
self.det_dist_to_beam_converter_path: str = (
self.det_dist_to_beam_converter_path = (
self.det_dist_to_beam_converter_path
or CONST.PARAM.DETECTOR.BEAM_XY_LUT_PATH
)
Expand All @@ -70,6 +75,18 @@ def _detector_params(self, omega_start_deg: float):
**optional_args,
)

@field_validator("selected_aperture")
@classmethod
def _set_default_aperture_position(cls, aperture_position: ApertureValue | None):
if not aperture_position:
default_aperture = CONST.PARAM.ROTATION.DEFAULT_APERTURE_POSITION
LOGGER.warning(
f"No aperture position selected. Defaulting to {default_aperture}"
)
return default_aperture
else:
return aperture_position


class RotationScan(WithScan, RotationScanPerSweep, RotationExperiment):
@property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import patch

import pytest
from bluesky.run_engine import RunEngine
from dodal.devices.aperturescatterguard import ApertureScatterguard, ApertureValue

Expand All @@ -8,13 +9,24 @@
)


@pytest.mark.parametrize(
"set_position",
[
(ApertureValue.SMALL),
(ApertureValue.MEDIUM),
(ApertureValue.ROBOT_LOAD),
(ApertureValue.LARGE),
],
)
async def test_move_aperture_goes_to_correct_position(
aperture_scatterguard: ApertureScatterguard, RE: RunEngine
aperture_scatterguard: ApertureScatterguard,
RE: RunEngine,
set_position,
):
with patch.object(aperture_scatterguard, "set") as mock_set:
RE(move_aperture_if_required(aperture_scatterguard, ApertureValue.LARGE))
RE(move_aperture_if_required(aperture_scatterguard, set_position))
mock_set.assert_called_once_with(
ApertureValue.LARGE,
set_position,
)


Expand Down
10 changes: 10 additions & 0 deletions tests/unit_tests/hyperion/parameters/test_parameter_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path

import pytest
from dodal.devices.aperturescatterguard import ApertureValue
from pydantic import ValidationError

from mx_bluesky.hyperion.parameters.constants import GridscanParamConstants
Expand Down Expand Up @@ -111,3 +112,12 @@ def test_osc_is_used():
params = RotationScan(**raw_params)
assert params.rotation_increment_deg == osc
assert params.num_images == int(params.scan_width_deg / osc)


def test_selected_aperture_uses_default():
raw_params = raw_params_from_file(
"tests/test_data/parameter_json_files/good_test_rotation_scan_parameters.json"
)
raw_params["selected_aperture"] = None
params = RotationScan(**raw_params)
assert params.selected_aperture == ApertureValue.LARGE
7 changes: 4 additions & 3 deletions utility_scripts/deploy/deploy_hyperion_to_k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@ hyperion.dev=true,\
hyperion.runAsUser=$EUID,\
hyperion.runAsGroup=$GID,\
hyperion.supplementalGroups=[$SUPPLEMENTAL_GIDS],\
hyperion.logDir=/app/hyperion/tmp,\
hyperion.logDir=$PROJECTDIR/tmp,\
hyperion.dataDir=$PROJECTDIR/tmp/data,\
hyperion.externalHostname=test-hyperion.diamond.ac.uk "
mkdir -p $PROJECTDIR/tmp
mkdir -p $PROJECTDIR/tmp/data
DEPLOYMENT_DIR=$PROJECTDIR
else
DEPLOYMENT_DIR=/dls_sw/i03/software/bluesky/mx_bluesky_v${APP_VERSION}/hyperion
DEPLOYMENT_DIR=/dls_sw/i03/software/bluesky/mx_bluesky_${APP_VERSION}/hyperion
fi

HELM_OPTIONS+="--set hyperion.appVersion=$APP_VERSION,\
Expand Down

0 comments on commit 0b562ff

Please sign in to comment.