hpcflow.sdk.core.workflow.WorkflowTemplate#

class hpcflow.sdk.core.workflow.WorkflowTemplate(name, doc=None, tasks=<factory>, loops=<factory>, workflow=None, resources=None, environments=None, env_presets=None, source_file=None, store_kwargs=<factory>, merge_resources=True, merge_envs=True)#

Bases: JSONLike

Class to represent initial parametrisation of a {app_name} workflow, with limited validation logic.

Parameters:
  • name (str) – A string name for the workflow. By default this name will be used in combination with a date-time stamp when generating a persistent workflow from the template.

  • tasks (list[Task]) – A list of Task objects to include in the workflow.

  • loops (list[Loop]) – A list of Loop objects to include in the workflow.

  • workflow (Workflow | None) – The associated concrete workflow.

  • resources (dict[str, dict] | list[ResourceSpec] | ResourceList) – Template-level resources to apply to all tasks as default values. This can be a dict that maps action scopes to resources (e.g. {{“any”: {{“num_cores”: 2}}}}) or a list of ResourceSpec objects, or a ResourceList object.

  • environments (Mapping[str, Mapping[str, Any]] | None) – The execution environments to use.

  • env_presets (str | list[str] | None) – The environment presets to use.

  • source_file (str | None) – The file this was derived from.

  • store_kwargs (dict[str, Any]) – Additional arguments to pass to the persistent data store constructor.

  • merge_resources (bool) – If True, merge template-level resources into element set resources. If False, template-level resources are ignored.

  • merge_envs (bool) – Whether to merge the environemtns into task resources.

  • doc (list[str] | str | None) –

Methods

from_JSON_file

Load from a JSON file.

from_JSON_string

Load from a JSON string.

from_YAML_file

Load from a YAML file.

from_YAML_string

Load from a YAML string.

from_file

Load from either a YAML or JSON file, depending on the file extension.

from_json_like

Make an instance of this class from JSON (or YAML) data.

to_dict

Serialize this object as a dictionary.

to_json_like

Serialize this object as an object structure that can be trivially converted to JSON.

Attributes

doc

Documentation information.

env_presets

The environment presets to use.

environments

The execution environments to use.

merge_envs

Whether to merge the environemtns into task resources.

merge_resources

Whether to merge template-level resources into element set resources.

resources

Template-level resources to apply to all tasks as default values.

source_file

The file this was derived from.

workflow

The associated concrete workflow.

name

A string name for the workflow.

tasks

A list of Task objects to include in the workflow.

loops

A list of Loop objects to include in the workflow.

store_kwargs

Additional arguments to pass to the persistent data store constructor.

doc: list[str] | str | None = None#

Documentation information.

env_presets: str | list[str] | None = None#

The environment presets to use.

environments: Mapping[str, Mapping[str, Any]] | None = None#

The execution environments to use.

classmethod from_JSON_file(path, variables=None)#

Load from a JSON file.

Parameters:
  • path (PathLike) – The path to the JSON file containing the workflow template parametrisation.

  • variables (dict[str, str] | None) – String variables to substitute in the file given by path.

Return type:

WorkflowTemplate

classmethod from_JSON_string(string, variables=None)#

Load from a JSON string.

Parameters:
  • string (str) – The JSON string containing the workflow template parametrisation.

  • variables (dict[str, str] | None) – String variables to substitute in string.

Return type:

WorkflowTemplate

classmethod from_YAML_file(path, variables=None)#

Load from a YAML file.

Parameters:
  • path (PathLike) – The path to the YAML file containing the workflow template parametrisation.

  • variables (dict[str, str] | None) – String variables to substitute in the file given by path.

Return type:

WorkflowTemplate

classmethod from_YAML_string(string, variables=None)#

Load from a YAML string.

Parameters:
  • string (str) – The YAML string containing the workflow template parametrisation.

  • variables (dict[str, str] | None) – String variables to substitute in string.

Return type:

WorkflowTemplate

classmethod from_file(path, template_format=None, variables=None)#

Load from either a YAML or JSON file, depending on the file extension.

Parameters:
  • path (PathLike) – The path to the file containing the workflow template parametrisation.

  • template_format (Literal['yaml', 'json'] | None) – The file format to expect at path. One of “json” or “yaml”, if specified. By default, “yaml”.

  • variables (dict[str, str] | None) – String variables to substitute in the file given by path.

Return type:

WorkflowTemplate

classmethod from_json_like(json_like, shared_data=None)#

Make an instance of this class from JSON (or YAML) data.

Parameters:
  • json_like (str | Mapping[str, JSONed] | Sequence[Mapping[str, JSONed]] | None) – The data to deserialise.

  • shared_data (Mapping[str, ObjectList[JSONable]] | None) – Shared context data.

Return type:

The deserialised object.

loops: list[Loop]#

A list of Loop objects to include in the workflow.

merge_envs: bool = True#

Whether to merge the environemtns into task resources.

merge_resources: bool = True#

Whether to merge template-level resources into element set resources.

name: str#

A string name for the workflow.

resources: Resources = None#

Template-level resources to apply to all tasks as default values.

source_file: str | None = None#

The file this was derived from.

store_kwargs: dict[str, Any]#

Additional arguments to pass to the persistent data store constructor.

tasks: list[Task]#

A list of Task objects to include in the workflow.

to_dict()#

Serialize this object as a dictionary.

Return type:

dict[str, Any]

to_json_like(dct=None, shared_data=None, exclude=(), path=None)#

Serialize this object as an object structure that can be trivially converted to JSON. Note that YAML can also be produced from the result of this method; it just requires a different final serialization step.

Parameters:
  • dct (dict[str, JSONable] | None) –

  • shared_data (_JSONDeserState) –

  • exclude (Container[str | None]) –

  • path (list | None) –

Return type:

tuple[JSONDocument, _JSONDeserState]

workflow: Workflow | None = None#

The associated concrete workflow.