Querying Lattice Execution Time#

Calculate execution time of a workflow (lattice) after it ends by querying the Result object and subtracting the start time from the end time.


Define a workflow.

import covalent as ct
import time

def add(x, y):
    return x + y

def multiply(x, y):
    return x * y

def workflow(x, y):
    res_1 = add(x=x, y=y)
    return multiply(x=res_1, y=y)


  1. Use the Covalent dispatch() function to dispatch the workflow.

dispatch_id = ct.dispatch(workflow)(x=2, y=3)
  1. Retrieve the Covalent result object, setting the wait parameter to True so that execution finishes before the result is retrieved.

result = ct.get_result(dispatch_id=dispatch_id, wait=True)
  1. Use the result object’s start_time and end_time attributes to calculate the duration of the dispatch:

print(f"Execution time: {(result.end_time - result.start_time).total_seconds():.2f} seconds")
Execution time: 2.18 seconds

See Also#

Dispatching a Workflow

Querying the Status of a Lattice

Querying the Status of an Electron