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)[source]

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[source]

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

Returns:

None

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

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: str, item_type: ItemType, force: bool = False, raw: bool = False, item: Any | None = None, **kwargs) Any[source]

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][source]

Returns a list of children for an entity.

Parameters:

parent – Parent object

Returns:

List of children

get_parent_by_object(child: IEntity) IEntity[source]

Parent of object.

Parameters:

child – Child object to find parent for

Returns:

Returns parent object

get_parent(item_id: str, item_type: ItemType | None = None, force: bool = False, raw: bool = False, **kwargs)[source]

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')[source]

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: List[IEntity] | IEntity, **kwargs) List[IEntity][source]

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: IEntity | List[IEntity], **kwargs)[source]

Run items on the platform.

Parameters:

items – Items to run

Returns:

None

validate_item_for_analysis(item: object, analyze_failed_items=False)[source]

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][source]

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[source]

Populate the platform item and specified item with its status.

Parameters:

item – The item to check status for.

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

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: str, item_type: ItemType, files: Set[str] | List[str], output: str | None = None) Dict[str, Dict[str, bytearray]] | Dict[str, bytearray][source]

Get files by item id (str).

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: PlatformRequirements | Set[PlatformRequirements]) bool[source]

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[source]

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)[source]

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: str | None = None)[source]

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[source]

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

Returns:

True or false

is_windows_platform(item: IEntity | None = None) bool[source]

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[source]

Join path using platform rules.

Parameters:

*args – List of paths to join

Returns:

Joined path as string

id_from_file(filename: str)[source]

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: PathLike | str, item_type: ItemType | None = None) IEntity[source]

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][source]

Returns any platform defaults for specific types. :param default_type: Default type

Returns:

List of default of that type

create_sim_directory_map(item_id: str, item_type: ItemType) Dict[source]

Build simulation working directory mapping. :param item_id: Entity id :param item_type: ItemType

Returns:

Dict of simulation id as key and working dir as value

create_sim_directory_df(exp_id: str, include_tags: bool = True) DataFrame[source]

Build simulation working directory mapping. :param exp_id: experiment id :param include_tags: True/False

Returns:

DataFrame

save_sim_directory_df_to_csv(exp_id: str, include_tags: bool = True, output: str = '/home/docs/checkouts/readthedocs.org/user_builds/institute-for-disease-modeling-idmtools/checkouts/latest/docs', save_header=False, file_name: str | None = None) None[source]

Save simulation directory df to csv file. :param exp_id: experiment id :param include_tags: True/False :param output: output directory :param save_header: True/False :param file_name: user csv file name

Returns:

None

__init__(_uid: str | None = 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: str | None = None) None