Workflow Components#

Electron#

class covalent._workflow.electron.Electron(function, node_id=None, metadata=None, task_group_id=None, packing_tasks=False)[source]#

An electron (or task) object that is a modular component of a work flow and is returned by electron.

function#

Function to be executed.

node_id#

Node id of the electron.

metadata#

Metadata to be used for the function execution.

kwargs#

Keyword arguments if any.

task_group_id#

the group to which the task be assigned when it is bound to a graph node. If unset, the group id will default to node id.

packing_tasks#

Flag to indicate whether task packing is enabled.

Attributes:

as_transportable_dict

Get transportable electron object and metadata.

Methods:

connect_node_with_others(node_id, …)

Adds a node along with connecting edges for all the arguments to the electron.

get_metadata(name)

Get value of the metadata of given name.

get_op_function(operand_1, operand_2, op)

Function to handle binary operations with electrons as operands.

set_metadata(name, value)

Function to add/edit metadata of given name and value to electron’s metadata.

wait_for(electrons)

Waits for the given electrons to complete before executing this one.

property as_transportable_dict: Dict#

Get transportable electron object and metadata.

Return type

Dict

connect_node_with_others(node_id, param_name, param_value, param_type, arg_index, transport_graph)[source]#

Adds a node along with connecting edges for all the arguments to the electron.

Parameters
  • node_id (int) – Node number of the electron

  • param_name (str) – Name of the parameter

  • param_value (Union[Any, ForwardRef]) – Value of the parameter

  • param_type (str) – Type of parameter, positional or keyword

  • transport_graph (_TransportGraph) – Transport graph of the lattice

Returns

None

get_metadata(name)[source]#

Get value of the metadata of given name.

Parameters

name (str) – Name of the metadata whose value is needed.

Returns

Value of the metadata of given name.

Return type

value

Raises

KeyError – If metadata of given name is not present.

get_op_function(operand_1, operand_2, op)[source]#

Function to handle binary operations with electrons as operands. This will not execute the operation but rather create another electron which will be postponed to be executed according to the default electron configuration/metadata.

This also makes sure that if these operations are being performed outside of a lattice, then they are performed as is.

Parameters
  • operand_1 (Union[Any, Electron]) – First operand of the binary operation.

  • operand_2 (Union[Any, Electron]) – Second operand of the binary operation.

  • op (str) – Operator to be used in the binary operation.

Returns

Electron object corresponding to the operation execution.

Behaves as a normal function call if outside a lattice.

Return type

electron

set_metadata(name, value)[source]#

Function to add/edit metadata of given name and value to electron’s metadata.

Parameters
  • name (str) – Name of the metadata to be added/edited.

  • value (Any) – Value of the metadata to be added/edited.

Return type

None

Returns

None

wait_for(electrons)[source]#

Waits for the given electrons to complete before executing this one. Adds the necessary edges between this and those electrons without explicitly connecting their inputs/outputs.

Useful when execution of this electron relies on a side-effect from the another one.

Parameters

electrons (Union[Electron, Iterable[Electron]]) – Electron(s) which will be waited for to complete execution before starting execution for this one

Returns

Electron

Examples#


Lattice#

class covalent._workflow.lattice.Lattice(workflow_function, transport_graph=None)[source]#

A lattice workflow object that holds the work flow graph and is returned by lattice decorator.

workflow_function#

The workflow function that is decorated by lattice decorator.

transport_graph#

The transport graph which will be the basis on how the workflow is executed.

metadata#

Dictionary of metadata of the lattice.

post_processing#

Boolean to indicate if the lattice is in post processing mode or not.

kwargs#

Keyword arguments passed to the workflow function.

electron_outputs#

Dictionary of electron outputs received after workflow execution.

Methods:

build_graph(*args, **kwargs)

Builds the transport graph for the lattice by executing the workflow function which will trigger the call of all underlying electrons and they will get added to the transport graph for later execution.

dispatch(*args, **kwargs)

DEPRECATED: Function to dispatch workflows.

dispatch_sync(*args, **kwargs)

DEPRECATED: Function to dispatch workflows synchronously by waiting for the result too.

draw(*args, **kwargs)

Generate lattice graph and display in UI taking into account passed in arguments.

get_metadata(name)

Get value of the metadata of given name.

set_metadata(name, value)

Function to add/edit metadata of given name and value to lattice’s metadata.

build_graph(*args, **kwargs)[source]#

Builds the transport graph for the lattice by executing the workflow function which will trigger the call of all underlying electrons and they will get added to the transport graph for later execution.

Also redirects any print statements inside the lattice function to null and ignores any exceptions caused while executing the function.

GRAPH WILL NOT BE BUILT AFTER AN EXCEPTION HAS OCCURRED.

Parameters
  • *args – Positional arguments to be passed to the workflow function.

  • **kwargs – Keyword arguments to be passed to the workflow function.

Return type

None

Returns

None

dispatch(*args, **kwargs)[source]#

DEPRECATED: Function to dispatch workflows.

Parameters
  • *args – Positional arguments for the workflow

  • **kwargs – Keyword arguments for the workflow

Return type

str

Returns

Dispatch id assigned to job

dispatch_sync(*args, **kwargs)[source]#

DEPRECATED: Function to dispatch workflows synchronously by waiting for the result too.

Parameters
  • *args – Positional arguments for the workflow

  • **kwargs – Keyword arguments for the workflow

Return type

Result

Returns

Result of workflow execution

draw(*args, **kwargs)[source]#

Generate lattice graph and display in UI taking into account passed in arguments.

Parameters
  • *args – Positional arguments to be passed to build the graph.

  • **kwargs – Keyword arguments to be passed to build the graph.

Return type

None

Returns

None

get_metadata(name)[source]#

Get value of the metadata of given name.

Parameters

name (str) – Name of the metadata whose value is needed.

Returns

Value of the metadata of given name.

Return type

value

Raises

KeyError – If metadata of given name is not present.

set_metadata(name, value)[source]#

Function to add/edit metadata of given name and value to lattice’s metadata.

Parameters
  • name (str) – Name of the metadata to be added/edited.

  • value (Any) – Value of the metadata to be added/edited.

Return type

None

Returns

None

Examples#


Lepton#

Language Decorators#

Decorator to use languages other than Python, including scripting languages.

Language Classes#

More robust definition of languages other than Python.

Examples#