Skip to content

Commit

Permalink
Introduce a concept of non-final results
Browse files Browse the repository at this point in the history
  • Loading branch information
WardLT committed Mar 8, 2024
1 parent 3c20721 commit 861ca58
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions colmena/models/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class Result(BaseModel):
value: Any = Field(None, description="Output of a function")
method: Optional[str] = Field(None, description="Name of the method to run.")
success: Optional[bool] = Field(None, description="Whether the task completed successfully")
complete: Optional[bool] = Field(None, description="Whether this result is the last for a task instead of an intermediate result")

# Store task information
task_info: Optional[Dict[str, Any]] = Field(default_factory=dict,
Expand Down Expand Up @@ -325,7 +326,7 @@ def mark_compute_ended(self):
"""Mark when the task finished executing"""
self.timestamp.compute_ended = datetime.now().timestamp()

def set_result(self, result: Any, runtime: float = nan):
def set_result(self, result: Any, runtime: float = nan, intermediate: bool = False):
"""Set the value of this computation
Automatically sets the "time_result_completed" field and, if known, defines the runtime.
Expand All @@ -335,13 +336,15 @@ def set_result(self, result: Any, runtime: float = nan):
Args:
result: Result to be stored
runtime (float): Runtime for the function
runtime: Runtime for the function
intermediate: If this result is not the final one in a workflow
"""
self.value = result
if not self.keep_inputs:
self.inputs = ((), {})
self.time.running = runtime
self.success = True
self.complete = not intermediate

def serialize(self) -> Tuple[float, List[Proxy]]:
"""Stores the input and value fields as a pickled objects
Expand Down

0 comments on commit 861ca58

Please sign in to comment.