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.
Prerequisites#
Define a workflow.
[1]:
import covalent as ct
import time
@ct.electron
def add(x, y):
time.sleep(2)
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)
Procedure#
Use the Covalent
dispatch()
function to dispatch the workflow.
[2]:
dispatch_id = ct.dispatch(workflow)(x=2, y=3)
Retrieve the Covalent result object, setting the
wait
parameter toTrue
so that execution finishes before the result is retrieved.
[3]:
result = ct.get_result(dispatch_id=dispatch_id, wait=True)
Use the result object’s
start_time
andend_time
attributes to calculate the duration of the dispatch:
[4]:
print(f"Execution time: {(result.end_time - result.start_time).total_seconds():.2f} seconds")
Execution time: 2.18 seconds