Source code for thread_chunks._checkpoint

 1from typing import Any, List, Optional
 2
 3from saveable_objects import SaveableObject
 4
[docs] 5class CheckpointFailedWarning(Warning): 6 "Warns that a checkpoint failed to save." 7 pass
8
[docs] 9class Checkpoint(SaveableObject): 10 """A data structure to store the progress of the parallel execution of a 11 function `func`. 12 """ 13 func_name : str 14 """The name of the function being executed in parallel. 15 """ 16 17 parameters : List[List[Any]] 18 """A list of argument lists for the function. The ``i`` th call of the 19 function is ``func_name(*parameters[i])``.""" 20 21 output : List[Any] 22 """An ordered list of the outputs of the function: 23 ``output[i]=func_name(*parameters[i])``. ``output[i]`` should be set 24 to ``None`` if `func_name(*parameters[i])` is yet to finish execution.""" 25 26 completed : List[bool] 27 """A list of which outputs have been computed. ``True`` represents the ith 28 output has been computed.""" 29 30 index : int 31 """The largest index of the parameter list currently being computed.""" 32 33 done : int 34 """The number of outputs already computed.""" 35
[docs] 36 def __init__(self, 37 func_name: str, 38 parameters: List[List[Any]], 39 output: List[Any], 40 completed: List[bool], 41 index: int, 42 done: int, 43 path: Optional[str] = None): 44 """Initialises a data structure to store the progress of the parallel 45 execution of a function. 46 47 Parameters 48 ---------- 49 func_name : str 50 The name of the function being executed in parallel. 51 parameters : List[List[Any]] 52 A list of argument lists for the function. The `i`th call of the 53 function is ``func_name(*parameters[i])``. 54 output : List[Any] 55 An ordered list of the outputs of the function: 56 ``output[i]=func_name(*parameters[i])``. ``output[i]`` should be set 57 to `None` if `func_name(*parameters[i])` is yet to finish execution. 58 completed : List[bool] 59 A list of which outputs have been computed. ``True`` represents the 60 ith output has been computed. 61 index : int 62 The largest index of the parameter list currently being computed. 63 done : int 64 The number of outputs already computed. 65 path : str, optional 66 File path to save the object to. If ``None`` then the object is not 67 saved. By default ``None``. 68 """ 69 self.func_name = func_name 70 self.parameters = parameters 71 self.output = output 72 self.completed = completed 73 self.index = index 74 self.done = done 75 super().__init__(path=path)