Skip to content

Commit

Permalink
Merge pull request #78 from VukManojlovic/CTX-4333
Browse files Browse the repository at this point in the history
CTX-4333: Run output parameter submission
  • Loading branch information
igorperic17 authored Oct 27, 2023
2 parents 2a17c62 + 8183157 commit 2061907
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions coretex/entities/task_run/task_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,78 @@ def submitMetrics(self, metricValues: Dict[str, Tuple[float, float]]) -> bool:
response = networkManager.post(f"{self._endpoint()}/metrics", parameters)
return not response.hasFailed()

def submitOutput(self, parameterName: str, value: Any) -> None:
"""
Submit an output of this task to act as a parameter in tasks
downstream in the Workflow
Parameters
----------
parameterName : str
name of the parameter
value : Any
value that will be sent (id of the object will be sent
in case Coretex objects like CustomDataset, Model etc. is submited)
Raises
------
NetworkRequestError -> if the request failed
Example
-------
>>> from coretex import TaskRun
\b
>>> ExecutingTaskRun.current().submitOutputParameter(
parameterName = "outputDataset"
value = outputDataset
)
"""

self.submitOutputs({parameterName: value})

def submitOutputs(self, outputs: Dict[str, Any]) -> None:
"""
Submit multiple outputs of this task to act as parameters in tasks
downstream in the Workflow
Parameters
----------
outputs : Dict[str, Any]
dictionary with outputs, with key being the name of the parameter
(id of the object will be sent in case Coretex objects like
CustomDataset, Model etc. is submited)
Raises
------
NetworkRequestError -> if the request failed
Example
-------
>>> from coretex import TaskRun
\b
>>> result = ExecutingTaskRun.current().submitOutputParameters({
"outputDataset": outputDataset,
"numbers": 123
})
"""

outputParameters: List[Dict[str, Any]] = []

for key, value in outputs.items():
if isinstance(value, NetworkObject):
value = value.id

outputParameters.append({key: value})

parameters: Dict[str, Any] = {
"id": self.id,
"parameters": outputParameters
}

response = networkManager.post(f"{self._endpoint()}/output-parameter", parameters)
if response.hasFailed():
raise NetworkRequestError(response, ">> [Coretex] Failed to submit outputs")

def downloadTask(self) -> bool:
"""
Downloads task snapshot linked to the TaskRun
Expand Down

0 comments on commit 2061907

Please sign in to comment.