ANUGA Checkpoints
Since ANUGA may take a long time to run a simulation, it can be prudent to save off the partial results at different stages of execution in case of hardware failure or power loss.
cPickle Method
NOTE: You cannot pickle function objects! This means you are limited to the standard boundaries using this method.
Many people have requested restore point functionality in ANUGA to deal with interruptions to a running script. Python already has the ability to save state to a file using the cPickle module.
You can use code like this in your application to implement restore points:
import cPickle start_time = 0.0 if use_restore_point is True: print 'resuming from restore point...' domain = cPickle.load(open('domain_pickle.txt')) start_time = domain.time else: # do your normal domain initialisation here for restorepoint in range(start_time, 10): # evolve domain in small chunks, regularly pickling a restore point for t in domain.evolve(yieldstep=0.1, finaltime=restorepoint): pass print 'saving restore point...' cPickle.dump(domain, open('domain_pickle.txt', 'w'))
To use this code normally, make sure use_restore_point is False. If your script is interrupted for any reason, set use_restore_point to be True, and it will continue from the last save point.
cPickle.dump will store an entire class on disk. cPickle.load will restore that class from disk. So when you pickle the domain, you can reload its exact state using cPickle.load.
use_cache Method
ANUGA also has inbuilt caching functionality. You can set the use_cache = True parameter on many functions, and the results of the operation will be stored on disk for the next time the same operation is executed.