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 16 commits into
base: lightweight-events
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

Attention: Patch coverage is 89.13043% with 15 lines in your changes missing coverage. Please review.

Project coverage is 80.19%. Comparing base (1ff6b78) to head (bd50284).

Additional details and impacted files
@@                  Coverage Diff                   @@
##           lightweight-events     #625      +/-   ##
======================================================
+ Coverage               80.11%   80.19%   +0.08%     
======================================================
  Files                      98       99       +1     
  Lines                    6845     6949     +104     
======================================================
+ Hits                     5484     5573      +89     
- Misses                   1361     1376      +15     
Components Coverage Δ
i24 SSX 60.20% <ø> (ø)
hyperion 96.42% <88.80%> (-0.35%) ⬇️
other 95.00% <100.00%> (+0.04%) ⬆️

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?

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.

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 +82
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 +45
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 +331
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
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.

2 participants