Querying the Results of Tasks (Electrons) in a Workflow#

Query the result values of all electrons in a lattice at once or individually.

Prerequisites#

Create and dispatch a lattice.

[24]:
import covalent as ct

@ct.electron
def add(x, y):
    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)

dispatch_id = ct.dispatch(workflow)(x=2, y=3)

Procedure#

  1. Retrieve the workflow result object using the Covalent get_result() function.

[25]:
result = ct.get_result(dispatch_id=dispatch_id, wait=True)
  1. Query the electron executions using the get_all_node_ouputs() method.

[26]:
result.get_all_node_outputs()
[26]:
{'add(0)': <covalent.TransportableObject at 0x11a79d400>,
 ':parameter:2(1)': <covalent.TransportableObject at 0x11a79d8e0>,
 ':parameter:3(2)': <covalent.TransportableObject at 0x11a79de50>,
 'multiply(3)': <covalent.TransportableObject at 0x11aab7640>,
 ':parameter:3(4)': <covalent.TransportableObject at 0x11ab01280>}
  1. Note the ID number of the nodes in which you are interested. The node ID is in parentheses after the node name.

    The list of nodes contains both electrons and parameters. In this example, node 0 and node 3 (add and multiply, respectively) are electrons.

  2. Use the result.get_node_result() function to examine the result of an individual node.

[27]:
result.get_node_result(node_id=0)
[27]:
{'node_id': 0,
 'node_name': 'add',
 'start_time': datetime.datetime(2023, 2, 1, 21, 9, 0, 618814, tzinfo=datetime.timezone.utc),
 'end_time': datetime.datetime(2023, 2, 1, 21, 9, 0, 680075, tzinfo=datetime.timezone.utc),
 'status': Status(STATUS='COMPLETED'),
 'output': <covalent.TransportableObject at 0x11a79d400>,
 'error': None,
 'sublattice_result': None,
 'stdout': '',
 'stderr': ''}

See Also#

Querying the Status of an Electron