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

add stop to experiment #484

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

add stop to experiment #484

wants to merge 6 commits into from

Conversation

MarcusZuber
Copy link
Member

@MarcusZuber MarcusZuber commented May 2, 2022

Add a possibility to stop a running experiment without killing all tasks.

ToDo:

  • Implementation in the base experiment
  • Implementation in the different experiments
  • Tests
  • Documentation

@MarcusZuber MarcusZuber force-pushed the add-stop-to-experiment branch 4 times, most recently from 15677e9 to dd35cad Compare May 2, 2022 10:25
@tfarago
Copy link
Contributor

tfarago commented May 2, 2022

How is this different from calling ex.run().cancel()?

@MarcusZuber
Copy link
Member Author

It's class method, so you can stop even when you forget to store the handle to exp.run() and it is more structurized stop that tries to finish stuff in a that you can actually re-run the experiment afterwards (e.g. if a cont. motor is moving the cancel would only stop it in the acceleration phase).

@tfarago
Copy link
Contributor

tfarago commented May 2, 2022

I see, alright.

@MarcusZuber
Copy link
Member Author

I thought to catch the CancelError and then make a structured stop, but then this would shadow the cancel of the motors etc. which might be also required in some cases.

@codecov
Copy link

codecov bot commented May 31, 2022

Codecov Report

Merging #484 (3f6ef18) into master (66d9bb9) will increase coverage by 0.01%.
The diff coverage is 92.59%.

❗ Current head 3f6ef18 differs from pull request most recent head 2adc08a. Consider uploading reports for the commit 2adc08a to get more accurate results

@@            Coverage Diff             @@
##           master     #484      +/-   ##
==========================================
+ Coverage   87.53%   87.54%   +0.01%     
==========================================
  Files         114      114              
  Lines        7819     7843      +24     
==========================================
+ Hits         6844     6866      +22     
- Misses        975      977       +2     
Impacted Files Coverage Δ
concert/tests/integration/test_experiments.py 99.51% <83.33%> (-0.49%) ⬇️
concert/experiments/imaging.py 92.28% <90.90%> (-0.09%) ⬇️
concert/experiments/base.py 89.06% <100.00%> (+0.53%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 66d9bb9...2adc08a. Read the comment docs.

Copy link
Contributor

@tfarago tfarago left a comment

Choose a reason for hiding this comment

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

Not quite there yet I think.

concert/experiments/base.py Outdated Show resolved Hide resolved
for i in range(int(number)):
if self._stop:
Copy link
Contributor

@tfarago tfarago Jun 1, 2022

Choose a reason for hiding this comment

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

Also, instead of checking this in every experiment class, we can catch a stop request in the Acquistion, namely you can wrap the broadcast into something which accepts a stop request.

Copy link
Member Author

Choose a reason for hiding this comment

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

But what will it change? I have to write everywhere, where right now is if self._stop a handler of the stop request?

Copy link
Contributor

Choose a reason for hiding this comment

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

You will have one check in the Acquisition class instead of N checks where N is the number of all possible producers.

I have to write everywhere, where right now is if self._stop a handler of the stop request?

Of course not, you don't have to write anything in the producers, that's the point.

Copy link
Member Author

Choose a reason for hiding this comment

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

But a clean stop is very experiment specific. So I abort all the acquisitions and then call a clean-up function, that has to take care that everything is back in a well defined state?

Copy link
Contributor

Choose a reason for hiding this comment

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

In all your producers you just do if stop then break, so no clean up. And of course if special handler is needed you can always override the Experiment.stop method.

@MarcusZuber
Copy link
Member Author

How about this? It is basically the cancel, but with a different exception. So in a generator I can catch it and make a structured stop.

@MarcusZuber
Copy link
Member Author

Oh no:

asyncio.Task inherits from Future all of its APIs except Future.set_result() and Future.set_exception().

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.

None yet

2 participants