Choosing an Executor for a Task (Electron)#

Within a lattice, every electron can use a different executor. These exectors can have different capabilities: different hardware, different computation strategies, and so on.

Executors are plugins. Any executor plugins found by the dispatcher are imported as classes in the covalent.executor name space.


  1. Start the Covalent server.

  2. Import covalent.

import covalent as ct


Initialize an executor with its class:

executor1 = ct.executor.LocalExecutor()
  1. Assign the executor to an electron using the keyword argument executor:

def identity(x):
    return x

Another way to specify an executor is by the short name of the executor plugin.

In this case, the short name of the LocalExecutor is local:

def square(x):
    return x * x
  1. Construct rest of the workflow as usual within a lattice:

def workflow(a):
    val_1 = identity(x=a)
    return square(x=val_1)
  1. Submit the workflow using the dispatch method:

dispatch_id = ct.dispatch(workflow)(a=2)

Dispatching the workflow generates a dispatch ID.

Use this ID to query the status of the task and retrieve the results:

output = ct.get_result(dispatch_id=dispatch_id, wait=True)

Lattice Result
result: 4
input args: []
input kwargs: {'a': '2'}
error: None

start_time: 2023-01-31 21:20:27.871124
end_time: 2023-01-31 21:20:28.054424

results_dir: /Users/mini-me/agnostiq/covalent/doc/source/how_to/execution/results
dispatch_id: 5f0e220f-35dc-4a75-92c6-a00176f530e2

Node Outputs
identity(0): 2
:parameter:2(1): 2
square(2): 4

See Also#

Getting the Results of an Electron Execution

Getting Results of Previous Runs