How to choose an executor for a subtask#
Each electron can utilise different so-called executors. These exectors can have different capabilities, eg, different hardware, or different computation strategy.
Executors are plugins; any executor-plugins which are found are imported as classes in the covalent.executor name-space.
[1]:
import covalent as ct
An executor can be initialized with it’s class, with various input parameters:
[2]:
executor1 = ct.executor.LocalExecutor()
@ct.electron(executor=executor1)
def identity(x):
return x
Or an executor can be specified by the name of the module which contains the executor-plugin. In this case, we are specifying the executor-plugin found in covalent/executor/executor_plugins/local.py
[3]:
@ct.electron(executor="local")
def square(x):
return x * x
The rest of the workflow continues as usual, within a lattice
:
[4]:
@ct.lattice
def workflow(a):
val_1 = identity(x=a)
return square(x=val_1)
Note
Ensure that Covalent services have been started properly before attempting to execute the lattice.
Following that, the workflow can now be submitted using the dispatch
method.
[5]:
dispatch_id = ct.dispatch(workflow)(a=2)
print(dispatch_id)
36e61674-049d-4835-8aed-1e550fdb8f26
When the workflow is dispatched, a dispatch id is generated. This id is then used to query the status of the task and retrieve the results as discussed in How to query electron execution result and How to query lattice execution result.
[6]:
output = ct.get_result(dispatch_id=dispatch_id, wait=True)
print(output)
Lattice Result
==============
status: COMPLETED
result: 4
inputs: {'args': [], 'kwargs': {'a': 2}}
error: None
start_time: 2022-01-23 01:02:02.745038+00:00
end_time: 2022-01-23 01:02:02.796901+00:00
results_dir: /tmp/results
dispatch_id: 36e61674-049d-4835-8aed-1e550fdb8f26
Node Outputs
------------
identity(0): 2
:parameter:2(1): 2
square(2): 4