How to query lattice execution time#

We can query the lattice execution time after the workflow has been dispatched. First, we define the workflow as shown below.

[1]:
import covalent as ct
import time

@ct.electron
def add(x, y):
    time.sleep(1)
    return x + y

@ct.electron
def multiply(x, y):
    return x * y

@ct.lattice
def workflow(x, y):
    res_1 = add(x=x, y=y)
    return multiply(x=res_1, y=y)

We dispatch the workflow and retrieve the results. The wait parameter is set to True so that the result is queried once the execution is completed. Following that, we can query the execution time as shown below.

[2]:
dispatch_id = ct.dispatch(workflow)(x=2, y=3)
result = ct.get_result(dispatch_id=dispatch_id, wait=True)
print(f"Execution time: {(result.end_time - result.start_time).total_seconds():.2f} seconds")
Execution time: 1.06 seconds