Repository: valohai/valohai-yaml

Issue:
Define maximum queued executions for Task
It would be useful to be able to define the number of max queued executions in the `valohai.yaml`.

Comments:

Patch:
diff --git a/examples/task-example.yaml b/examples/task-example.yaml
index 1405282..160e18f 100644
--- a/examples/task-example.yaml
+++ b/examples/task-example.yaml
@@ -49,6 +49,8 @@
     type: RANDOM-SEARCH # will be normalized
     execution-batch-size: 42
     execution-count: 420
+    maximum-queued-executions: 17
+    on-child-error: stop_all-AND_error # will be normalized
     optimization-target-metric: goodness
     optimization-target-value: 7.2
     parameters:
diff --git a/valohai_yaml/objs/task.py b/valohai_yaml/objs/task.py
index eb00644..2ec1cc1 100644
--- a/valohai_yaml/objs/task.py
+++ b/valohai_yaml/objs/task.py
@@ -33,6 +33,23 @@ class TaskType(Enum):
         return TaskType(value)
 
 
+class TaskOnChildError(Enum):
+    """Represents the possible actions that can be taken when a task's child fails."""
+
+    CONTINUE_AND_COMPLETE = "continue-and-complete"
+    CONTINUE_AND_ERROR = "continue-and-error"
+    STOP_ALL_AND_ERROR = "stop-all-and-error"
+
+    @classmethod
+    def cast(cls, value: TaskOnChildError | str | None) -> TaskOnChildError | None:
+        if not value:
+            return None
+        if isinstance(value, TaskOnChildError):
+            return value
+        value = str(value).lower().replace("_", "-")
+        return TaskOnChildError(value)
+
+
 class Task(Item):
     """Represents a task definition."""
 
@@ -42,9 +59,11 @@ class Task(Item):
     name: str
     execution_count: int | None
     execution_batch_size: int | None
+    maximum_queued_executions: int | None
     optimization_target_metric: str | None
     optimization_target_value: float | None
     engine: str | None
+    on_child_error: TaskOnChildError | None
 
     def __init__(
         self,
@@ -55,9 +74,11 @@ class Task(Item):
         parameters: list[VariantParameter] | None = None,
         execution_count: int | None = None,
         execution_batch_size: int | None = None,
+        maximum_queued_executions: int | None = None,
         optimization_target_metric: str | None = None,
         optimization_target_value: float | None = None,
         engine: str | None = None,
+        on_child_error: TaskOnChildError | None = None,
         stop_condition: str | None = None,
     ) -> None:
         self.name = name
@@ -66,9 +87,11 @@ class Task(Item):
         self.parameters = check_type_and_listify(parameters, VariantParameter)
         self.execution_count = execution_count
         self.execution_batch_size = execution_batch_size
+        self.maximum_queued_executions = maximum_queued_executions
         self.optimization_target_metric = optimization_target_metric
         self.optimization_target_value = optimization_target_value
         self.engine = engine
+        self.on_child_error = TaskOnChildError.cast(on_child_error)
         self.stop_condition = stop_condition
 
     @classmethod
diff --git a/valohai_yaml/schema/task.yaml b/valohai_yaml/schema/task.yaml
index 7b84fb9..3c1365e 100644
--- a/valohai_yaml/schema/task.yaml
+++ b/valohai_yaml/schema/task.yaml
@@ -12,6 +12,8 @@ properties:
     type: integer
   execution-batch-size:
     type: integer
+  maximum-queued-executions:
+    type: integer
   optimization-target-metric:
     type: string
   optimization-target-value:
@@ -20,6 +22,8 @@ properties:
     type: string
   type:
     type: string
+  on-child-error:
+    type: string
   name:
     type: string
     description: The unique name for this task.


Test patch:
diff --git a/tests/test_task.py b/tests/test_task.py
index 7595524..15af964 100644
--- a/tests/test_task.py
+++ b/tests/test_task.py
@@ -1,5 +1,5 @@
 from valohai_yaml.objs import Config, Task
-from valohai_yaml.objs.task import TaskType
+from valohai_yaml.objs.task import TaskOnChildError, TaskType
 from valohai_yaml.objs.variant_parameter import VariantParameterStyle
 
 
@@ -18,6 +18,8 @@ def test_task_additional_fields(task_config: Config):
     task = task_config.tasks["task 4 logspace"]
     assert task.execution_batch_size == 42
     assert task.execution_count == 420
+    assert task.maximum_queued_executions == 17
+    assert task.on_child_error == TaskOnChildError.STOP_ALL_AND_ERROR
     assert task.optimization_target_metric == "goodness"
     assert task.optimization_target_value == 7.2
     assert task.type == TaskType.RANDOM_SEARCH