Skip to content

Commit e3f0914

Browse files
committed
feat: get min hardware config for workflows
1 parent 611ed8c commit e3f0914

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

doc/source/_autosummary/_autosummary/ikomia.dataprocess.pydataprocess.CWorkflow.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ CWorkflow
3737
~CWorkflow.get_final_tasks
3838
~CWorkflow.get_in_edges
3939
~CWorkflow.get_last_run_folder
40+
~CWorkflow.get_min_hardware_config
4041
~CWorkflow.get_out_edges
4142
~CWorkflow.get_output_count
4243
~CWorkflow.get_outputs
@@ -92,6 +93,7 @@ CWorkflow
9293
.. automethod:: get_final_tasks
9394
.. automethod:: get_in_edges
9495
.. automethod:: get_last_run_folder
96+
.. automethod:: get_min_hardware_config
9597
.. automethod:: get_out_edges
9698
.. automethod:: get_output_count
9799
.. automethod:: get_outputs

doc/source/_autosummary/ikomia.dataprocess.workflow.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
.. autosummary::
2121

2222
create
23+
get_min_hardware_config
2324
install_requirements
2425
load
2526
prepare_runtime_env
2627

2728
.. rubric:: Details
2829

2930
.. autofunction:: create
31+
.. autofunction:: get_min_hardware_config
3032
.. autofunction:: install_requirements
3133
.. autofunction:: load
3234
.. autofunction:: prepare_runtime_env

ikomia/dataprocess/workflow.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from ikomia.core import config, IODataType, CWorkflowTask, CWorkflowTaskIO, auth # pylint: disable=E0611
2929
from ikomia.core.task import conform_parameters, get_output
3030
from ikomia.dataio import CDataImageIO, CDataVideoIO # pylint: disable=E0611
31-
from ikomia.dataprocess import CWorkflow, CImageIO, CVideoIO, CPathIO # pylint: disable=E0611
31+
from ikomia.dataprocess import CWorkflow, CImageIO, CVideoIO, CPathIO, CHardwareConfig # pylint: disable=E0611
3232
from ikomia.dataprocess.registry import IkomiaRegistry, ik_registry
3333

3434

@@ -786,8 +786,7 @@ def prepare_runtime_env(workflow_path: str):
786786
Args:
787787
workflow_path (str): path to workflow definition file (.json)
788788
"""
789-
wf = Workflow()
790-
tasks = wf.get_required_tasks(workflow_path)
789+
tasks = Workflow.get_required_tasks(workflow_path)
791790
available_tasks = ik_registry.get_algorithms()
792791
private_hub = bool(auth.ik_api_session.is_authenticated())
793792

@@ -796,7 +795,7 @@ def prepare_runtime_env(workflow_path: str):
796795
try:
797796
ik_registry.create_algorithm(name=t, public_hub=True, private_hub=private_hub)
798797
except Exception as e:
799-
raise RuntimeError(f"Workflow preparation failed at task {t} for the following reason: {e}") from e
798+
raise RuntimeError(f"Workflow preparation failed at algorithm {t} for the following reason: {e}") from e
800799

801800

802801
def install_requirements(path: str) -> bool:
@@ -810,8 +809,7 @@ def install_requirements(path: str) -> bool:
810809
Returns:
811810
True if all installations succeeded else False
812811
"""
813-
wf = Workflow("untitled", ik_registry)
814-
tasks = wf.get_required_tasks(path)
812+
tasks = Workflow.get_required_tasks(path)
815813
available_tasks = ik_registry.get_algorithms()
816814
plugins_directory = ik_registry.get_plugins_directory()
817815

@@ -821,7 +819,32 @@ def install_requirements(path: str) -> bool:
821819
if os.path.isdir(plugin_dir):
822820
utils.plugintools.install_requirements(plugin_dir)
823821
else:
824-
msg = f"Workflow preparation failed: task {t} cannot be found."
822+
msg = f"Requirements installation failed: algorithm folder {t} cannot be found."
825823
logger.error(msg)
826824
return False
827825
return True
826+
827+
828+
def get_min_hardware_config(path: str) -> CHardwareConfig:
829+
"""
830+
Get minimum hardware configuration for the given workflow file.
831+
The configuration is determined from the minimum hardware configuration of workflow tasks.
832+
833+
Args:
834+
path (str): path to workflow definition file (.json)
835+
836+
Returns:
837+
:py:class:`~ikomia.dataprocess.pydataprocess.CHardwareConfig`: hardware configuration
838+
"""
839+
prepare_runtime_env(path)
840+
min_hw_config = CHardwareConfig()
841+
task_names = Workflow.get_required_tasks(path)
842+
843+
for name in task_names:
844+
info = ik_registry.get_algorithm_info(name)
845+
min_hw_config.min_cpu = max(min_hw_config.min_cpu, info.hardware_config.min_cpu)
846+
min_hw_config.min_ram = max(min_hw_config.min_ram, info.hardware_config.min_ram)
847+
min_hw_config.gpu_required = min_hw_config.gpu_required or info.hardware_config.gpu_required
848+
min_hw_config.min_vram = max(min_hw_config.min_vram, info.hardware_config.min_vram)
849+
850+
return min_hw_config

0 commit comments

Comments
 (0)