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

Make stage synchronous if arming not started #92

Merged

Conversation

olliesilvester
Copy link
Collaborator

@olliesilvester olliesilvester commented Jun 14, 2023

Fixes #76

This should also fix the very slow unit tests introduced in #43

To test:
Run new tests and check they are sensible
Check changes satisfy the criteria
See if this fixes DiamondLightSource/hyperion#686

@olliesilvester olliesilvester changed the title 76 make stage synchronous if arming not started rebased Make stage synchronous if arming not started Jun 14, 2023
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This isn't related to #76 but I noticed the the status in the final function in the callback chain was never being checked

@codecov
Copy link

codecov bot commented Jun 14, 2023

Codecov Report

Merging #92 (bc45b1e) into main (8af1733) will increase coverage by 0.06%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #92      +/-   ##
==========================================
+ Coverage   89.07%   89.13%   +0.06%     
==========================================
  Files          57       57              
  Lines        1949     1960      +11     
==========================================
+ Hits         1736     1747      +11     
  Misses        213      213              
Impacted Files Coverage Δ
src/dodal/devices/eiger.py 99.35% <100.00%> (+0.04%) ⬆️
src/dodal/devices/utils.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

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.

Thanks, I think suggested change cleans things up a bit. Can you try and write a test to prove if you've fixed DiamondLightSource/hyperion#686? Basically add somewhere in the fast_grid_scan_plan tests confirming the eiger gets armed

Comment on lines 93 to 98
def stage(self):
if self.armed_state.value == "unarmed":
self.async_stage().wait(60)

return self.do_arming_chain()
elif self.armed_state.value == "arming":
self.arming_status.wait(60)
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 we can do this slightly more cleanly:

  • If the arming_status is not complete then wait on it to finish
  • If it is and self.cam.acquire is high assume you're armed, otherwise assume not and do an async arm

I think this means you can then remove armed_state all together.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this also means we can remove the None return

Copy link
Collaborator Author

@olliesilvester olliesilvester Jun 20, 2023

Choose a reason for hiding this comment

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

The last part of staging is awaiting for self.odin.fan.ready to be set to 1, shouldn't we check this value rather than self.cam.acquire?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good spot, I think we should confirm acquire and fan.ready. Can you make a new function called something like is_armed that we use to check both of these?

@@ -79,8 +86,19 @@ def async_stage(self):
status_ok, error_message = self.odin.check_odin_initialised()
if not status_ok:
raise Exception(f"Odin not initialised: {error_message}")
self.armed_state = self.ArmedState.ARMING
self.arming_status = self.do_arming_chain()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should: You should create a placeholder class variable for this that's initialised to a complete status, this helps autocomplete etc.

@@ -290,7 +306,7 @@ def do_arming_chain(self) -> Status:
self.set_odin_pvs,
self.set_mx_settings_pvs,
self.set_num_triggers_and_captures,
lambda: await_value(self.STALE_PARAMS_TIMEOUT, 0, 60),
lambda: await_value(self.stale_params, 0, 60),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This typo looks like it should have broken the arming, not sure how it was working before if this was in there

Copy link
Contributor

Choose a reason for hiding this comment

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

Yh, it's probably just not covered well in the tests

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.

Good work, thanks. Couple of comment

src/dodal/devices/eiger.py Outdated Show resolved Hide resolved
@@ -290,7 +306,7 @@ def do_arming_chain(self) -> Status:
self.set_odin_pvs,
self.set_mx_settings_pvs,
self.set_num_triggers_and_captures,
lambda: await_value(self.STALE_PARAMS_TIMEOUT, 0, 60),
lambda: await_value(self.stale_params, 0, 60),
Copy link
Contributor

Choose a reason for hiding this comment

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

Yh, it's probably just not covered well in the tests

Comment on lines 93 to 98
def stage(self):
if self.armed_state.value == "unarmed":
self.async_stage().wait(60)

return self.do_arming_chain()
elif self.armed_state.value == "arming":
self.arming_status.wait(60)
Copy link
Contributor

Choose a reason for hiding this comment

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

Good spot, I think we should confirm acquire and fan.ready. Can you make a new function called something like is_armed that we use to check both of these?

else:
if self.odin.fan.ready.get() != 1:
# Arming hasn't started, do it asynchronously
self.async_stage()
Copy link
Contributor

Choose a reason for hiding this comment

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

Must: I think in this case we need to be synchronous so we should have a wait here

Comment on lines 92 to 93
else:
if self.odin.fan.ready.get() != 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This can be an elif

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.

Minor nit change, otherwise good, thanks!

src/dodal/devices/eiger.py Outdated Show resolved Hide resolved
@DominicOram DominicOram merged commit 0de42e3 into main Jun 27, 2023
@DominicOram DominicOram deleted the 76_make_stage_synchronous_if_arming_not_started_rebased branch June 27, 2023 12:34
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.

Make stage synchronous if arming not yet started Fast grid scan without grid detect broken
2 participants