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

595 write to ispyb sample status after collection #625

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

rtuck99
Copy link
Contributor

@rtuck99 rtuck99 commented Nov 7, 2024

Fixes #595
Requires #606

The blSampleStatus field in ispyb will now be updated on successful robot load to LOADED, when the load_centre_collect plan is used.

In the event of the pin not being found or no diffraction, blSampleStatus will be updated to ERROR - sample to indicate an issue with the sample
If any other error occurs, blSampleStatus will be updated to ERROR - beamline to indicate a general problem with the beamline.

On normal completion the blSampleStatus will be left at LOADED

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.50%. Comparing base (89e436f) to head (679f338).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #625      +/-   ##
==========================================
+ Coverage   85.31%   85.50%   +0.19%     
==========================================
  Files         101      101              
  Lines        6726     6816      +90     
==========================================
+ Hits         5738     5828      +90     
  Misses        988      988              
Components Coverage Δ
i24 SSX 69.57% <ø> (ø)
hyperion 96.85% <100.00%> (+0.07%) ⬆️
other 95.16% <100.00%> (+0.03%) ⬆️
---- 🚨 Try these New Features:

Copy link
Contributor

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

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

Great, thanks. Really like the additional system tests! I think we could have a few more unit tests alongside them to test more of the code paths though

@@ -105,8 +108,13 @@ def grid_detection_plan(
# See #673 for improvements
yield from bps.sleep(CONST.HARDWARE.OAV_REFRESH_DELAY)

tip_x_px, tip_y_px = yield from catch_exception_and_warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should: With this removed catch_exception_and_warn is never used other than here, can we just re purpose it to raise a SampleException rather than WarningException then keep the call here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively we can remove catch_exception_and_warn as it's no longer needed but I like having this behind a function as it's a bit confusing at first glance.

Comment on lines 50 to 54
# Below causes close_run not received before open_run in _open_run
# @set_run_key_decorator(CONST.PLAN.LOAD_CENTRE_COLLECT)
# @run_decorator(md={"metadata": {"sample_id": params.sample_id},
# "activate_callbacks": ["SampleHandlingCallback"]})
# @sample_handling_callback_decorator()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should: This commented out code is exactly what is written below? What is the comment trying to tell me?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is something I added as a note whilst I was trying to figure out what the hell was going on wrt run key decorator, I will remove it. The problem was caused elsewhere in the code.

PinNotFoundException, wait_for_tip_to_be_found, pin_tip_detection
def wrap_exception(e: Exception) -> Generator[Msg, Any, Any]:
if isinstance(e, PinNotFoundException):
raise SampleException(str(e))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should:

Suggested change
raise SampleException(str(e))
raise SampleException from e

will give better chaining information



class SampleHandlingCallback(PlanReactiveCallback):
"""Intercepts"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Should: Can we have a nicer docstring please?

Comment on lines 84 to 89
if not exit_status:
reason = "Exit status not available in stop document!"
elif not self._metadata:
reason = "Metadata not received before stop document."
else:
reason = doc.get("reason") or "OK"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should: I agree with codcov that some unit tests around this would be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think these lines are reachable in practice so I'm replacing them with asserts

bl_sample_status: str | None


class ExpeyeSampleHandlingInteraction:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should: I think some unit tests on this would be good, even if they're just smoke tests really

Comment on lines +76 to +80
def _record_exception(self, exception_type: str):
expeye = ExpeyeSampleHandlingInteraction()
assert self._sample_id, "Unable to record exception due to no sample ID"
sample_status = self._decode_sample_status(exception_type)
expeye.update_sample_status(self._sample_id, sample_status)

def _decode_sample_status(self, exception_type: str) -> BLSampleStatus:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should: Would be good to have a couple of tests covering these functions

Comment on lines +43 to +42
sample_handling_callback_decorator = make_decorator(
partial(contingency_wrapper, except_plan=_exception_interceptor)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I like this, does a good job of hiding the shenanigans

Comment on lines +323 to +374
set_mock_value(
ophyd_pin_tip_detection.triggered_top_edge,
numpy.array([]),
)

set_mock_value(
ophyd_pin_tip_detection.triggered_bottom_edge,
numpy.array([]),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We don't nee to set the edges to [] here for the pin tip to not be found



@pytest.fixture(autouse=True)
def use_real_ispyb():
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:

Suggested change
def use_real_ispyb():
def use_dev_ispyb():

@DominicOram
Copy link
Contributor

I have also just been told about #636. I think it probably makes sense to assume the new endpoints for this issue

@rtuck99 rtuck99 force-pushed the 595_write_to_ispyb_sample_status_after_collection branch from ccf3dcf to bd50284 Compare November 14, 2024 16:33
@rtuck99 rtuck99 force-pushed the 595_write_to_ispyb_sample_status_after_collection branch from bd50284 to 8e4d49c Compare November 22, 2024 10:53
Base automatically changed from lightweight-events to main November 22, 2024 15:34
@rtuck99 rtuck99 force-pushed the 595_write_to_ispyb_sample_status_after_collection branch from b5da656 to 679f338 Compare November 22, 2024 16:27
@rtuck99
Copy link
Contributor Author

rtuck99 commented Nov 25, 2024

I have also just been told about #636. I think it probably makes sense to assume the new endpoints for this issue

Code has already been updated for the new endpoints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write to ispyb sample status after collection
2 participants