How to execute multiple lattices#
Multiple lattices (whether in the form of different workflows or the same workflow with different parameters) can be executed with just some minor tweaks. For example, consider the lattice shown below, that we’d like to run for different parameters.
[1]:
import covalent as ct
@ct.electron
def identity(x):
return x
@ct.electron
def square(x):
return x * x
@ct.lattice
def workflow(a):
val_1 = identity(x=a)
return square(x=val_1)
In order to run the workflow for different parameters, we can simply use a for loop to dispatch the tasks.
[2]:
params = [1, 2, 3, 4]
dispatch_ids = [ct.dispatch(workflow)(a=param) for param in params]
dispatch_ids
[2]:
['822a0a20-c3a4-4b57-80c7-07970298b8aa',
'ef7f5a27-ebaf-4356-ae7e-9d73a8068d7c',
'95a9961c-e851-4101-bbad-eab179c7224e',
'32c30773-bf82-4c95-a13a-ede34a575886']
We store the dispatch ids so that we can later query the results.