idmtools.entities.iplatform module

Here we define the Platform interface.

IPlatform is responsible for all the communication to our platform and translation from idmtools objects to platform specific objects and vice versa.

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

class idmtools.entities.iplatform.IPlatform(*args, **kwargs)

Bases: IItem, CacheEnabled

Interface defining a platform.

A platform needs to implement basic operation such as:

  • Creating experiment

  • Creating simulation

  • Commissioning

  • File handling

platform_type_map: Dict[Type, ItemType] = None

Maps the platform types to idmtools types

supported_types: Set[ItemType]
validate_inputs_types() NoReturn

Validate user inputs and case attributes with the correct data types.

Returns:

None

get_item(item_id: Union[str, UUID], item_type: Optional[ItemType] = None, force: bool = False, raw: bool = False, **kwargs) Optional[Union[Experiment, Suite, Simulation, IWorkflowItem, AssetCollection]]

Retrieve an object from the platform.

This function is cached; force allows you to force the refresh of the cache. If no object_type is passed, the function will try all the types (experiment, suite, simulation).

Parameters:
  • item_id – The ID of the object to retrieve.

  • item_type – The type of the object to be retrieved.

  • force – If True, force the object fetching from the platform.

  • raw – Return either an idmtools object or a platform object.

Returns:

The object found on the platform or None.

Raises:
get_children(item_id: UUID, item_type: ItemType, force: bool = False, raw: bool = False, item: Optional[Any] = None, **kwargs) Any

Retrieve the children of a given object.

Parameters:
  • item_id – The ID of the object for which we want the children.

  • force – If True, force the object fetching from the platform.

  • raw – Return either an idmtools object or a platform object.

  • item_type – Pass the type of the object for quicker retrieval.

  • item – optional platform or idm item to use instead of loading

Returns:

The children of the object or None.

get_children_by_object(parent: IEntity) List[IEntity]

Returns a list of children for an entity.

Parameters:

parent – Parent object

Returns:

List of children

get_parent_by_object(child: IEntity) IEntity

Parent of object.

Parameters:

child – Child object to find parent for

Returns:

Returns parent object

get_parent(item_id: UUID, item_type: Optional[ItemType] = None, force: bool = False, raw: bool = False, **kwargs)

Retrieve the parent of a given object.

Parameters:
  • item_id – The ID of the object for which we want the parent.

  • force – If True, force the object fetching from the platform.

  • raw – Return either an idmtools object or a platform object.

  • item_type – Pass the type of the object for quicker retrieval.

Returns:

The parent of the object or None.

get_cache_key(force, item_id, item_type, kwargs, raw, prefix='p')

Get cache key for an item.

Parameters:
  • force – Should we force the load

  • item_id – Item id

  • item_type – Item type

  • kwargs – Kwargs

  • raw – Should we use raw storage?

  • prefix – Prefix for the item

Returns:

Cache Key

create_items(items: Union[List[IEntity], IEntity], **kwargs) List[IEntity]

Create items (simulations, experiments, or suites) on the platform.

The function will batch the items based on type and call the self._create_batch for creation.

Parameters:
  • items – The list of items to create.

  • kwargs – Extra arguments

Returns:

List of item IDs created.

run_items(items: Union[IEntity, List[IEntity]], **kwargs)

Run items on the platform.

Parameters:

items – Items to run

Returns:

None

validate_item_for_analysis(item: object, analyze_failed_items=False)

Check if item is valid for analysis.

Parameters:
  • item – Which item to flatten

  • analyze_failed_items – bool

Returns: bool

flatten_item(item: object, **kwargs) List[object]

Flatten an item: resolve the children until getting to the leaves.

For example, for an experiment, will return all the simulations. For a suite, will return all the simulations contained in the suites experiments.

Parameters:
  • item – Which item to flatten

  • kwargs – extra parameters

Returns:

List of leaves

refresh_status(item: IEntity) NoReturn

Populate the platform item and specified item with its status.

Parameters:

item – The item to check status for.

get_files(item: IEntity, files: Union[Set[str], List[str]], output: Optional[str] = None, **kwargs) Union[Dict[str, Dict[str, bytearray]], Dict[str, bytearray]]

Get files for a platform entity.

Parameters:
  • item – Item to fetch files for

  • files – List of file names to get

  • output – save files to

  • kwargs – Platform arguments

Returns:

For simulations, this returns a dictionary with filename as key and values being binary data from file or a dict.

For experiments, this returns a dictionary with key as sim id and then the values as a dict of the simulations described above

get_files_by_id(item_id: UUID, item_type: ItemType, files: Union[Set[str], List[str]], output: Optional[str] = None) Union[Dict[str, Dict[str, bytearray]], Dict[str, bytearray]]

Get files by item id (UUID).

Parameters:
  • item_id – COMPS Item, say, Simulation Id or WorkItem Id

  • item_type – Item Type

  • files – List of files to retrieve

  • output – save files to

Returns: dict with key/value: file_name/file_content

are_requirements_met(requirements: Union[PlatformRequirements, Set[PlatformRequirements]]) bool

Does the platform support the list of requirements.

Parameters:

requirements – Requirements should be a list of PlatformRequirements or a single PlatformRequirements

Returns:

True if all the requirements are supported

is_task_supported(task: ITask) bool

Is a task supported on this platform.

This depends on the task properly setting its requirements. See idmtools.entities.itask.ITask.platform_requirements and idmtools.entities.platform_requirements.PlatformRequirements

Parameters:

task – Task to check support of

Returns:

True if the task is supported, False otherwise.

wait_till_done(item: IRunnableEntity, timeout: int = 86400, refresh_interval: int = 5, progress: bool = True)

Wait for the experiment to be done.

Parameters:
  • item – Experiment/Workitem to wait on

  • refresh_interval – How long to wait between polling.

  • timeout – How long to wait before failing.

  • progress – Should we display progress

See also

idmtools.entities.iplatform.IPlatform.wait_till_done_progress() idmtools.entities.iplatform.IPlatform.__wait_until_done_progress_callback() idmtools.entities.iplatform.IPlatform.__wait_till_callback()

wait_till_done_progress(item: IRunnableEntity, timeout: int = 86400, refresh_interval: int = 5, wait_progress_desc: Optional[str] = None)

Wait on an item to complete with progress bar.

Parameters:
  • item – Item to monitor

  • timeout – Timeout on waiting

  • refresh_interval – How often to refresh

  • wait_progress_desc – Wait Progress Description

Returns:

None

See also

idmtools.entities.iplatform.IPlatform.__wait_until_done_progress_callback() idmtools.entities.iplatform.IPlatform.wait_till_done() idmtools.entities.iplatform.IPlatform.__wait_till_callback()

Retrieve all related objects.

Parameters:
  • item – SSMTWorkItem

  • relation_type – Depends or Create

Returns: dict with key the object type

is_regather_assets_on_modify() bool

Return default behaviour for platform when rerunning experiment and gathering assets.

Returns:

True or false

is_windows_platform(item: Optional[IEntity] = None) bool

Returns is the target platform is a windows system.

property common_asset_path

Return the path to common assets stored on the platform.

Returns:

Common Asset Path

join_path(*args) str

Join path using platform rules.

Parameters:

*args – List of paths to join

Returns:

Joined path as string

id_from_file(filename: str)

Load just the id portion of an id file.

Parameters:

filename – Filename

Returns:

Item id laoded from file

get_item_from_id_file(id_filename: Union[PathLike, str], item_type: Optional[ItemType] = None) IEntity

Load an item from an id file. This ignores the platform in the file.

Parameters:
  • id_filename – Filename to load

  • item_type – Optional item type

Returns:

Item from id file.

get_defaults_by_type(default_type: Type) List[IPlatformDefault]

Returns any platform defaults for specific types.

Parameters:

default_type – Default type

Returns:

List of default of that type

__init__(_uid: ~typing.Optional[~uuid.UUID] = None, _IItem__pre_creation_hooks: ~typing.List[~typing.Callable[[~idmtools.core.interfaces.iitem.IItem, ~idmtools.entities.iplatform.IPlatform], None]] = <factory>, _IItem__post_creation_hooks: ~typing.List[~typing.Callable[[~idmtools.core.interfaces.iitem.IItem, ~idmtools.entities.iplatform.IPlatform], None]] = <factory>, _platform_defaults: ~typing.List[~idmtools.entities.iplatform_default.IPlatformDefault] = <factory>, _config_block: ~typing.Optional[str] = None) None