Executing a Workflow (Lattice) Multiple Times#

Execute a lattice multiple times with different parameters by starting the lattice from a loop. Covalent parallelizes the execution of the runs.


Start the Covalent server.


  1. Write the lattice. This example takes a single scalar parameter, but the principle is the same for more complex inputs.

import covalent as ct

def identity(x):
    return x

def square(x):
    return x * x

def workflow(a):
    val_1 = identity(x=a)
    return square(x=val_1)
  1. Dispatch the tasks separately:

params = [1, 2, 3, 4]
dispatch_ids = [ct.dispatch(workflow)(a=param) for param in params]

  1. The dispatch IDs are your keys to the results of each run; you will use them to process or view the results. One option is to simply save the dispatch IDs so that you can retrieve the results later:

with open("dispatch_ids.txt", 'w') as id_file:
    id_file.writelines("%s\n" % id for id in dispatch_ids)

See Also#


Executing a Lattice as an Electron (Sublattice)