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

878 grid scans should move dectector in and open shutter#978

Merged
rtuck99 merged 6 commits into
mainfrom
878_grid_scans_should_move_dectector_in_and_open_shutter
Nov 20, 2023
Merged

878 grid scans should move dectector in and open shutter#978
rtuck99 merged 6 commits into
mainfrom
878_grid_scans_should_move_dectector_in_and_open_shutter

Conversation

@rtuck99

@rtuck99 rtuck99 commented Nov 15, 2023

Copy link
Copy Markdown
Contributor

Fixes #878

Also adds some new testing infrastructure that allows lightweight integration test.

Link to dodal PR (if required): https://github.com/DiamondLightSource/dodal/pull/237

Please check:

  • That I'm getting the detector_position from the right parameters
  • That removing the wait_for_det_to_finish shouldn't break anything and that the ready_for_data_collection is waited at the correct location
  • That the values for the various mocks in the unit tests are at least somewhat realistic / robust to future changes
  • Is there any corresponding change in the caller to hyperion needed to disable their detector move?
  • Whether this sort of test belongs in the unit tests or the integration tests?

@codecov

codecov Bot commented Nov 16, 2023

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3ad94ff) 93.48% compared to head (295bdc9) 93.71%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #978      +/-   ##
==========================================
+ Coverage   93.48%   93.71%   +0.23%     
==========================================
  Files          54       56       +2     
  Lines        2623     2673      +50     
==========================================
+ Hits         2452     2505      +53     
+ Misses        171      168       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rtuck99
rtuck99 requested a review from noemifrisina November 16, 2023 10:13

@d-perl d-perl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is great! This must be the most well-tested little function we've got. I look forward to using your simulator in other tests.

  • yes, you're using the right parameter for detector_distance
  • I think your yield from bps.wait("ready_for_data_collection") is in the right place
  • the mock values look okay to me

Although this test is complex and kind of like an integration test as far as components of hyperion are concerned, the distinction between unit/system tests here is basically whether we need to connect to real EPICS PVs (whether from a simulator or the real hardware ones) in order to run the test. If it can run self-sufficiently, it should be grouped with unit tests even if conceptually more complex.

magic_mock.smargon = smargon
magic_mock.detector_motion = detector_motion
scan = make_fake_device(FastGridScan)("prefix", name="fake_fgs")
# scan.scan_invalid.sim_put(True)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should: please remove commented code

@@ -0,0 +1,161 @@
from typing import Callable, Generator, Sequence

from bluesky import Msg

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should: import this from bluesky.utils instead

from unittest.mock import MagicMock, patch

import pytest
from bluesky import Msg

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should: please import this from bluesky.utils

)
@patch(
"hyperion.external_interaction.callbacks.xray_centre.zocalo_callback.XrayCentreZocaloCallback.wait_for_results",
lambda self, x: ([0, 0, 0], [1, 1, 1]),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: it would be more idiomatic to make the arguments _, __ as they're not used

"hyperion.external_interaction.callbacks.xray_centre.zocalo_callback.XrayCentreZocaloCallback.wait_for_results",
lambda self, x: ([0, 0, 0], [1, 1, 1]),
)
def test_when_pin_centre_xray_centre_called_then_detector_positioned(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test is fantastic! The whole reason plans are built from generators is for us to be able to introspect them like this, and we've never so far bothered. Thanks for writing this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@rtuck99 - seconding this, it's really good, thank you!

and msg.kwargs["group"] == "ready_for_data_collection",
)
)
assert messages_from_where(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Is this supposed to just assert it's not an empty list? if so, the assertion in message_from_where() will already take care of that - maybe give it an error message saying nothing matched the predicate?

and msg.kwargs["subplan_name"] == "do_fgs",
)


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: maybe it would be better for this function to live with the run engine simulator? it seems reusable

"event",
{
"data": {
"oav_snapshot_last_saved_path": "xxx",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these can probably just be something like "/tmp/image1.png", "/tmp/image2.png", "/tmp/image3.png"

yield from bps.abs_set(eiger.do_arm, 1, group=group)

yield from set_detector_z_position(detector_motion, detector_distance, group)
yield from set_shutter(detector_motion, ShutterState.OPEN, group)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we wait for these moves to have completed before doing the next plan? We have the groups here but they're never waited for

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The group is already waited for in flyscan_xray_centre_plan, the unit test calls all the subplans and asserts that this group is waited for before the main fast grid scan starts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ah yes, thanks

@rtuck99
rtuck99 requested a review from d-perl November 17, 2023 14:15

@d-perl d-perl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Brilliant, thanks!

@rtuck99
rtuck99 merged commit 1f9bec6 into main Nov 20, 2023
@rtuck99
rtuck99 deleted the 878_grid_scans_should_move_dectector_in_and_open_shutter branch November 20, 2023 13:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Grid scans should move detector in and open shutter

4 participants