checkpointing.decorator.default
1from checkpointing.decorator.base import DecoratorCheckpoint 2from checkpointing.identifier.func_call import AutoFuncCallIdentifier 3from checkpointing.cache import PickleFileCache 4 5 6def checkpoint( 7 directory: str = None, 8 on_error: str = "warn", 9 cache_pickle_protocol: int = None, 10) -> DecoratorCheckpoint: 11 """ 12 Alias for a default decorator checkpoint, which hashes the function code and parameter values, 13 and save the return value as pickle files in a given directory. 14 15 Args: 16 directory: the directory used for saving the results. If None, use the global default 17 `cache.filesystem.directory` 18 19 on_error: the behavior when retrieval or saving raises unexpected exceptions. Possible values are: 20 - `"raise"`, the exception will be raised. 21 - `"warn"`, a warning will be issued to inform that the checkpointing task has failed. 22 But the user function will be invoked and executed as if it wasn't checkpointed. 23 - `"ignore"`, the exception will be ignored and the user function will be invoked and executed normally. 24 If None, use the global default `checkpoint.on_error` 25 26 cache_pickle_protocol: the pickle protocol used by the cache to save results to the disk. 27 If None, use the global default `cache.pickle_protocol` 28 29 Optionally user can directly decorate the function with `@checkpoint` (without parenthesis), 30 this will cause the function to be passed in directly with the `directory` parameter. 31 """ 32 33 # If true, the `directory` is actually the decorated function 34 # and the actual `directory` is None 35 used_without_parenthesis = callable(directory) 36 37 identifier = AutoFuncCallIdentifier() 38 cache = PickleFileCache(None if used_without_parenthesis else directory, cache_pickle_protocol) 39 decorator = DecoratorCheckpoint(identifier, cache, on_error) 40 41 return decorator(directory) if used_without_parenthesis else decorator
def
checkpoint( directory: str = None, on_error: str = 'warn', cache_pickle_protocol: int = None) -> checkpointing.decorator.base.DecoratorCheckpoint:
7def checkpoint( 8 directory: str = None, 9 on_error: str = "warn", 10 cache_pickle_protocol: int = None, 11) -> DecoratorCheckpoint: 12 """ 13 Alias for a default decorator checkpoint, which hashes the function code and parameter values, 14 and save the return value as pickle files in a given directory. 15 16 Args: 17 directory: the directory used for saving the results. If None, use the global default 18 `cache.filesystem.directory` 19 20 on_error: the behavior when retrieval or saving raises unexpected exceptions. Possible values are: 21 - `"raise"`, the exception will be raised. 22 - `"warn"`, a warning will be issued to inform that the checkpointing task has failed. 23 But the user function will be invoked and executed as if it wasn't checkpointed. 24 - `"ignore"`, the exception will be ignored and the user function will be invoked and executed normally. 25 If None, use the global default `checkpoint.on_error` 26 27 cache_pickle_protocol: the pickle protocol used by the cache to save results to the disk. 28 If None, use the global default `cache.pickle_protocol` 29 30 Optionally user can directly decorate the function with `@checkpoint` (without parenthesis), 31 this will cause the function to be passed in directly with the `directory` parameter. 32 """ 33 34 # If true, the `directory` is actually the decorated function 35 # and the actual `directory` is None 36 used_without_parenthesis = callable(directory) 37 38 identifier = AutoFuncCallIdentifier() 39 cache = PickleFileCache(None if used_without_parenthesis else directory, cache_pickle_protocol) 40 decorator = DecoratorCheckpoint(identifier, cache, on_error) 41 42 return decorator(directory) if used_without_parenthesis else decorator
Alias for a default decorator checkpoint, which hashes the function code and parameter values, and save the return value as pickle files in a given directory.
Args
- directory: the directory used for saving the results. If None, use the global default
cache.filesystem.directory - on_error: the behavior when retrieval or saving raises unexpected exceptions. Possible values are:
"raise", the exception will be raised."warn", a warning will be issued to inform that the checkpointing task has failed. But the user function will be invoked and executed as if it wasn't checkpointed."ignore", the exception will be ignored and the user function will be invoked and executed normally. If None, use the global defaultcheckpoint.on_error
- cache_pickle_protocol: the pickle protocol used by the cache to save results to the disk.
If None, use the global default
cache.pickle_protocol
Optionally user can directly decorate the function with @checkpoint (without parenthesis),
this will cause the function to be passed in directly with the directory parameter.