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.
Methods:
add_collection_node_to_graph
(graph, prefix)Adds the node to lattice’s transport graph in the case where a collection of electrons is passed as an argument to another electron.
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.
Attributes:
Get transportable electron object and metadata.
- add_collection_node_to_graph(graph, prefix)[source]#
Adds the node to lattice’s transport graph in the case where a collection of electrons is passed as an argument to another electron.
- Parameters
graph (_TransportGraph) – Transport graph of the lattice
prefix (
str
) – Prefix of the node
- Returns
Node id of the added node
- Return type
node_id
- 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 electronparam_name (
str
) – Name of the parameterparam_value (
Union
[Any
,ForwardRef
]) – Value of the parameterparam_type (
str
) – Type of parameter, positional or keywordtransport_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
- 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