thread_chunks.Checkpoint¶
- class thread_chunks.Checkpoint(*args, **kwargs)[source]¶
Bases:
SaveableObjectA data structure to store the progress of the parallel execution of a function func.
Attributes
The file name of the object (without the file extension).
The current file path of the object.
The name of the function being executed in parallel.
A list of argument lists for the function.
An ordered list of the outputs of the function:
output[i]=func_name(*parameters[i]).A list of which outputs have been computed.
The largest index of the parameter list currently being computed.
The number of outputs already computed.
Methods
Initialises a data structure to store the progress of the parallel execution of a function.
Loads a pickled instance.
Attempts to load from a specified path.
Attempts to
load()from a specified path.Pickles the current instance.
Attempts to
load()from the specified path.Pickles the current instance and retains the saved arguments if they exist.
- classmethod load(path: str, new_path: str | None = None, strict_typing: bool = True) SaveableObject¶
Loads a pickled instance.
- Parameters:
path (str) – The path of the pickle.
new_path (str, optional) – The path to replace the previous path with. If
Nonethe path is not replaced. By defaultNone.strict_typing (bool, optional) – If
Truethen the loaded instance must be an instance of cls. By defaultTrue.
- Returns:
The loaded instance.
- Return type:
SaveableObject
- Raises:
TypeError – If strict_typing and the loaded instance is not an instance of cls.
Notes
strict_typing=Trueacts as a safety guard. Settingstrict_typing=Falsemay increase the probability of unexpected or uncaught errors.
- classmethod loadif(*args, **kwargs) Tuple[SaveableObject, bool]¶
Attempts to load from a specified path. If the loading fails or no path is specified then a new instance of the object is generated with the specified *args and **kwargs.
- Parameters:
- Returns:
The loaded or initialised instance followed by
Trueif the instance was loaded andFalseif the instance was initialised.- Return type:
(SaveableObject, bool)
- classmethod loadifparams(*args, dependencies: dict = {}, **kwargs) Tuple[SaveableObject, bool]¶
Attempts to
load()from a specified path. If the loading fails or no path is specified or the parameters do not match the saved parameters then a new instance of the object is generated with the specified *args and **kwargs.- Parameters:
*args – The arguments to pass to the initialisation on a failed
load().path (str, optional) – The path of the pickle, by default the parameter is not specified.
dependencies (dict, optional, must be specified as a keyword argument) – A dictionary of additional dependencies to check.
**kwargs – The keyword arguments to pass to the initialisation on a failed
load().
- Returns:
The loaded or initialised instance followed by
Trueif the instance was loaded andFalseif the instance was initialised.- Return type:
(SaveableObject, bool)
- classmethod tryload(path: str | None, new_path: str | None = None, strict_typing: bool = True) SaveableObject | Literal[False]¶
Attempts to
load()from the specified path. If the loading fails thenFalseis returned.- Parameters:
path (str, optional) – The path of the pickle. If
NonethenFalseis returned.new_path (str, optional) – The path to replace the previous path with. If
Nonethe path is not replaced. By defaultNone.strict_typing (bool, optional) – If
Truethen the loaded instance must be an instance of cls. By defaultTrue.
- Returns:
If succeeded the loaded instance, else False.
- Return type:
SaveableObject | Literal[False]
Notes
strict_typing=Trueacts as a safety guard. Settingstrict_typing=Falsemay increase the probability of unexpected or uncaught errors.
- __init__(func_name: str, parameters: List[List[Any]], output: List[Any], completed: List[bool], index: int, done: int, path: str | None = None)[source]¶
Initialises a data structure to store the progress of the parallel execution of a function.
- Parameters:
func_name (str) – The name of the function being executed in parallel.
parameters (List[List[Any]]) – A list of argument lists for the function. The i`th call of the function is ``func_name(*parameters[i])`.
output (List[Any]) – An ordered list of the outputs of the function:
output[i]=func_name(*parameters[i]).output[i]should be set to None if func_name(*parameters[i]) is yet to finish execution.completed (List[bool]) – A list of which outputs have been computed.
Truerepresents the ith output has been computed.index (int) – The largest index of the parameter list currently being computed.
done (int) – The number of outputs already computed.
path (str, optional) – File path to save the object to. If
Nonethen the object is not saved. By defaultNone.
- save(path: str | None = None)¶
Pickles the current instance.
- Parameters:
path (str, optional) – The path to pickle the instance to. If
Noneis specified then the attributepathis used instead. By defaultNone.- Raises:
ValueError – Raised if no path specified either by the parameter path or the attribute
path.
Notes
If no file extension is provided then the class name and the
.pklextension are appended to the file name.
- update_save(path: str | None = None) bool¶
Pickles the current instance and retains the saved arguments if they exist.
- Parameters:
path (str, optional) – The path to pickle the instance to. If
Noneis specified then the attributepathis used instead. By defaultNone.- Returns:
Trueif there was an argument pickle to retain.Falseif there was not an argument pickle to retain.- Return type:
bool
- Raises:
ValueError – Raised if no path specified.
Notes
If no file extension is provided then the class name and the
.pklextension are appended to the file name.
- completed: List[bool]¶
A list of which outputs have been computed.
Truerepresents the ith output has been computed.
- done: int¶
The number of outputs already computed.
- func_name: str¶
The name of the function being executed in parallel.
- index: int¶
The largest index of the parameter list currently being computed.
- property name: str | None¶
The file name of the object (without the file extension). Note that name is read only.
- output: List[Any]¶
An ordered list of the outputs of the function:
output[i]=func_name(*parameters[i]).output[i]should be set toNoneif func_name(*parameters[i]) is yet to finish execution.
- parameters: List[List[Any]]¶
A list of argument lists for the function. The
ith call of the function isfunc_name(*parameters[i]).
- property path: str | None¶
The current file path of the object.
Notes
On setting the value, if no file extension is provided then the class name and the
.pklextension are appended to the file name.