CallbackSaveToDisk¶
-
class
odl.solvers.util.callback.
CallbackSaveToDisk
(saveto, step=1, impl='pickle', **kwargs)[source]¶ Bases:
odl.solvers.util.callback.Callback
Callback for saving iterates to disk.
Methods
reset
(self)Set
iter
to 0.-
__init__
(self, saveto, step=1, impl='pickle', \*\*kwargs)[source]¶ Initialize a new instance.
- Parameters
- savetostring
Format string for the name of the file(s) where iterates are saved. The file name is generated as
filename = saveto.format(cur_iter_num)
where
cur_iter_num
is the current iteration number.- steppositive int, optional
Number of iterations between saves.
- impl{‘pickle’, ‘numpy’, ‘numpy_txt’}, optional
The format to store the iterates in. Numpy formats are only usable if the data can be converted to an array via
numpy.asarray
.
- Other Parameters
- kwargs :
Optional arguments passed to the save function.
Examples
Store each iterate:
>>> callback = CallbackSaveToDisk('my_path/my_iterate')
Save every fifth overwriting the previous one:
>>> callback = CallbackSaveToDisk(saveto='my_path/my_iterate', ... step=5)
Save each fifth iterate in
numpy
format, indexing the files with the iteration number:>>> callback = CallbackSaveToDisk(saveto='my_path/my_iterate_{}', ... step=5, impl='numpy')
-