Skip to content

Conversation

@hejung
Copy link
Contributor

@hejung hejung commented May 4, 2020

This builds on #911 and #755. It should only be merged after them.

This adds a GraciousKillHook that writes the current simulation state to storage and ends the simulation loop by raising a GraciousKillError when a given maximum walltime is reached.
You can also pass a custom callable as final_call at hook construction, in case you want to do anything else than closing the storage when the simulation is terminated.

Example usage (assuming your steps are not superfast the code below should end the simulation after something sligthly smaller than 3 min 34 s):

kill_hook = GraciousKillHook("3 minutes 34 seconds")
# sampler is a `PathSimulator`
sampler.attach_hook(kill_hook)
try:
   sampler.run(2000)
except GraciousKillError:
   print("Simulation ended due to maximum walltime reached")

@dwhswenson dwhswenson added this to the 1.5 milestone Dec 23, 2020
@dwhswenson
Copy link
Member

With #911 in, checking on this one: it looks like the code is largely completed. It will need some conflict resolution (which is hopefully easy to accomplish -- probably some are cases of "added two functions in the same location of the old code").

Main question: Is this close enough (and do you, @hejung, have time enough to finish it up) that it is worth holding off on the 1.5 release until this is included? Thematically, it would be nice to include it with the other work on hooks in 1.5, but if it will take more than a week to get done, it might be better to include it in 1.6.

@hejung hejung force-pushed the GraciousKillHook branch from 9ebe509 to fae89f8 Compare July 4, 2021 10:07
@hejung
Copy link
Contributor Author

hejung commented Jul 4, 2021

With #911 in, checking on this one: it looks like the code is largely completed. It will need some conflict resolution (which is hopefully easy to accomplish -- probably some are cases of "added two functions in the same location of the old code").

I cherry-picked the commit that introduces the GraciousKillHook onto the current master and changed the tests to use a patched time.time (as for the PathSamplingOutputHook).

Main question: Is this close enough (and do you, @hejung, have time enough to finish it up) that it is worth holding off on the 1.5 release until this is included? Thematically, it would be nice to include it with the other work on hooks in 1.5, but if it will take more than a week to get done, it might be better to include it in 1.6.

I would say it is done.
Only thing I noticed that we might want to consider, is that the GraciousKillHook is the only hook that uses logging. I did that to see in the ops main simulation log if the hook ended the simulation.
However I realized now that the reason the other hooks do not use logging might be that logging and dask do not play nicely together (similar to logging and multiprocessing), but I have no experience with logging from dask. @dwhswenson Should I rather convert the calls to logging to print statements? (Then they would/should go to std-out and would normally be captured by the queuing system in my intended use-case)

@hejung hejung changed the title [WIP] Gracious kill hook Gracious kill hook Jul 4, 2021
@codecov
Copy link

codecov bot commented Jul 4, 2021

Codecov Report

Merging #914 (b437d85) into master (08fb2bc) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #914      +/-   ##
==========================================
+ Coverage   81.47%   81.51%   +0.04%     
==========================================
  Files         140      140              
  Lines       15362    15399      +37     
==========================================
+ Hits        12516    12553      +37     
  Misses       2846     2846              
Impacted Files Coverage Δ
openpathsampling/beta/hooks.py 100.00% <100.00%> (ø)

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 08fb2bc...b437d85. Read the comment docs.

Copy link
Member

@dwhswenson dwhswenson left a comment

Choose a reason for hiding this comment

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

Looks good. Very tiny change to keep the line lengths down -- you may want the link listed in my comment instead of the one in the single-click suggestion -- and some unused as clauses in tests.

As to logging vs. writing to an output stream:

  1. The general advantage of logging is that it allows the user to control where/whether/how the output is reported. We limit user options on that in progress reporting because it might mess up our tools for refreshing the output (although users can still silence/redirect output by changing the output_stream, giving at least some choice). This use case seems reasonable for logging in serial.

  2. I think that, in order for Dask to report task logging, you need to set up the logging inside the task, and do so in a way that gets the information back to you (i.e., use a unique file name). (I remember investigating this in detail at one point, but don't remember exactly what I could/couldn't do -- in any case, logs from remote processes are at best a headache to process). However, GraciousKill probably won't be running inside a remote Dask process, since each Dask process may be running on a different job from your queuing system (so it's hard for GraciousKill to track time remaining).

In other words, this probably isn't an issue: the GraciousKillHook will be very useful for some workflows/simulation types (e.g., running TPS or other simulations where we can't do multiple shooting moves as once), but it probably won't be used in combination with Dask-based workflows.

@hejung
Copy link
Contributor Author

hejung commented Jul 5, 2021

Done! (I also removed the unnecessary as from the PathSamplingOutputHook...I seem to always forget that you can use with without as....)

@dwhswenson
Copy link
Member

LGTM. Merging! (And I will start the 1.5.0 release process soon.)

@dwhswenson dwhswenson merged commit 9aff946 into openpathsampling:master Jul 5, 2021
@hejung hejung deleted the GraciousKillHook branch July 5, 2021 15:45
@dwhswenson dwhswenson mentioned this pull request Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants