idmtools.entities.itask module

Defines our ITask interface.

Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.

class idmtools.entities.itask.ITask(command: str | ~idmtools.entities.command_line.CommandLine = <property object>, platform_requirements: ~typing.Set[~idmtools.entities.platform_requirements.PlatformRequirements] = <factory>, _ITask__pre_creation_hooks: ~typing.List[~typing.Callable[[Simulation | IWorkflowItem, IPlatform], ~typing.NoReturn]] = <factory>, _ITask__post_creation_hooks: ~typing.List[~typing.Callable[[Simulation | IWorkflowItem, IPlatform], ~typing.NoReturn]] = <factory>, common_assets: ~idmtools.assets.asset_collection.AssetCollection = <factory>, transient_assets: ~idmtools.assets.asset_collection.AssetCollection = <factory>)[source]

Bases: object

ITask represents a task to be ran on a remote system.

A Task should provide all the files and command needed to run remotely.

platform_requirements: Set[PlatformRequirements]
common_assets: AssetCollection

Common(Experiment-level) assets

transient_assets: AssetCollection

Transient(Simulation-level) assets

property command

The Command to run

property metadata_fields

Collect all metadata fields.

Returns: set of metadata filed names

add_pre_creation_hook(hook: Callable[[Simulation | IWorkflowItem, IPlatform], NoReturn])[source]

Called before a simulation is created on a platform. Each hook receives either a Simulation or WorkflowTask.

Parameters:

hook – Function to call on event

Returns:

None

add_post_creation_hook(hook: Callable[[Simulation | IWorkflowItem, IPlatform], NoReturn])[source]

Called after a simulation has been created on a platform. Each hook receives either a Simulation or WorkflowTask.

Parameters:

hook – Function to call on event

Returns:

None

add_platform_requirement(requirement: PlatformRequirements | str) NoReturn[source]

Adds a platform requirements to a task.

Parameters:

requirement – Requirement to add task

Returns:

None

pre_creation(parent: Simulation | IWorkflowItem, platform: IPlatform)[source]

Optional Hook called at the time of creation of task. Can be used to setup simulation and experiment level hooks.

Parameters:
  • parent – Parent of Item

  • platform – Platform executing the task. Useful for querying platform before execution

Returns:

None

post_creation(parent: Simulation | IWorkflowItem, platform: IPlatform)[source]

Optional Hook called at the after creation task. Can be used to setup simulation and experiment level hooks.

Parameters:
  • parent – Parent of Item

  • platform – Platform executing the task. Useful for querying platform before execution

Returns:

None

abstract gather_common_assets() AssetCollection[source]

Function called at runtime to gather all assets in the collection.

abstract gather_transient_assets() AssetCollection[source]

Function called at runtime to gather all assets in the collection.

gather_all_assets() AssetCollection[source]

Collect all common and transient assets.

Returns: new AssetCollection

copy_simulation(base_simulation: Simulation) Simulation[source]

Called when copying a simulation for batching. Override you your task has specific concerns when copying simulations.

reload_from_simulation(simulation: Simulation)[source]

Optional hook that is called when loading simulations from a platform.

to_simulation()[source]

Convert task to simulation.

Returns: new simulation

pre_getstate()[source]

Return default values for pickle_ignore_fields().

Call before pickling.

Returns: dict

post_setstate()[source]

Post load from pickle.

property pickle_ignore_fields

Pickle ignore fields.

Returns:

List of fields to ignore

__init__(command: str | ~idmtools.entities.command_line.CommandLine = <property object>, platform_requirements: ~typing.Set[~idmtools.entities.platform_requirements.PlatformRequirements] = <factory>, _ITask__pre_creation_hooks: ~typing.List[~typing.Callable[[Simulation | IWorkflowItem, IPlatform], ~typing.NoReturn]] = <factory>, _ITask__post_creation_hooks: ~typing.List[~typing.Callable[[Simulation | IWorkflowItem, IPlatform], ~typing.NoReturn]] = <factory>, common_assets: ~idmtools.assets.asset_collection.AssetCollection = <factory>, transient_assets: ~idmtools.assets.asset_collection.AssetCollection = <factory>) None
to_dict() Dict[source]

Select metadata fields and make a new dict.

Returns: dict