Q-CTRL logo

Jupyter Get the notebook

How to monitor activity and retrieve results

Monitor job status and retrieve results from previously run calculations in Boulder Opal

You can use the activity monitor to view the progress and status of previously run actions. Boulder Opal provides multiple ways to accessing this activity monitor. Moreover, each time you perform a calculation using Boulder Opal (for example, with qctrl.functions.calculate_graph), it is assigned a unique action_id, which you can use to retrieve the results later.

In this user guide we demonstrate how to access the activity monitor and how to retrieve the results of past calculations.

Monitoring activity

Boulder Opal web app

You can access the activity monitor through the Boulder Opal web app. There you can see the status of current and past calculations, and use the interactive interface to cancel running actions.

Command-line interface

The command-line interface method allows you to use the qctrl activity command through your terminal to view previously run actions. If you have not used the interactive authentication method mentioned here, you will be redirected to the interactive authentication method first. Information on the qctrl activity command can be found as follows:

qctrl activity --help

Pagination and filtering by status and action type is supported. All filtering commands are optional. If called without any additional commands the script will return the most recent actions you have run.

qctrl activity --limit 10 --offset 0 --status SUCCESS --type ROBUST_OPTIMIZE

The various --status and --type options are viewable through the --options command. For example to view the different type options to filter by, you can run the following command:

qctrl activity --options type

Qctrl() object

The activity monitor can also be accessed through the Qctrl() object.

from qctrl import Qctrl

qctrl = Qctrl()
qctrl.activity_monitor()
                              Activity monitor                              
┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Action name        ┃         ┃         ┃ Created at           ┃          ┃
┃ (Type)             ┃ ID      ┃ Status  ┃ Completed at         ┃ Runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ calculate_graph    │ 1240128 │ SUCCESS │ 2022-09-02 02:41:22  │ 0:00:01  │
│ (CORE_CALCULATION) │         │ (100%)  │ 2022-09-02 02:41:24  │          │
├────────────────────┼─────────┼─────────┼──────────────────────┼──────────┤
│ calculate_graph    │ 1240127 │ SUCCESS │ 2022-09-02 02:41:17  │ 0:00:01  │
│ (CORE_CALCULATION) │         │ (100%)  │ 2022-09-02 02:41:19  │          │
├────────────────────┼─────────┼─────────┼──────────────────────┼──────────┤
│ calculate_graph    │ 1240126 │ SUCCESS │ 2022-09-02 02:41:12  │ 0:00:01  │
│ (CORE_CALCULATION) │         │ (100%)  │ 2022-09-02 02:41:13  │          │
├────────────────────┼─────────┼─────────┼──────────────────────┼──────────┤
│ calculate_graph    │ 1239830 │ SUCCESS │ 2022-09-01 13:54:22  │ 0:00:02  │
│ (CORE_CALCULATION) │         │ (100%)  │ 2022-09-01 13:54:24  │          │
├────────────────────┼─────────┼─────────┼──────────────────────┼──────────┤
│ calculate_graph    │ 1239829 │ SUCCESS │ 2022-09-01 13:53:42  │ 0:00:04  │
│ (CORE_CALCULATION) │         │ (100%)  │ 2022-09-01 13:53:46  │          │
└────────────────────┴─────────┴─────────┴──────────────────────┴──────────┘

Note that the times are displayed in UTC. Similarly to the command line option, this option also supports pagination and filtering by status and action type and returns the most recent actions you have run (if no filtering options are provided).

qctrl.activity_monitor(
    limit=2, offset=6, status="FAILURE", action_type="CORE_CALCULATION"
)
                                Activity monitor                                
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Action name             ┃        ┃         ┃ Created at           ┃          ┃
┃ (Type)                  ┃ ID     ┃ Status  ┃ Completed at         ┃ Runtime  ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┩
│ calculate_optimization  │ 834475 │ FAILURE │ 2022-01-14 03:31:03  │ 0:00:11  │
│ (CORE_CALCULATION)      │        │ (100%)  │ 2022-01-14 03:31:15  │          │
├─────────────────────────┼────────┼─────────┼──────────────────────┼──────────┤
│ calculate_stochastic_op │ 834471 │ FAILURE │ 2022-01-14 03:28:42  │ 0:00:03  │
│ timization              │        │ (100%)  │ 2022-01-14 03:28:45  │          │
│ (CORE_CALCULATION)      │        │         │                      │          │
└─────────────────────────┴────────┴─────────┴──────────────────────┴──────────┘

Retrieving results

Each call to a function in the qctrl.functions namespace of Boulder Opal is assigned a unique action_id. These IDs are printed when you call the function, or you can find them in the activity monitor.

You can use the qctrl.get_result method with an action_id to retrieve the result of that call. You can use this in case your connection dropped during a calculation or to retrieve results you forgot to save.

qctrl.get_result(action_id=1190686)
Result(output={'abs': [{'value': 1.0, 'duration': 1}, {'value': 2.0, 'duration': 1}]}, metadata={}, errors=None, action=CoreAction(created_at=None, definition=None, errors=None, job_data=None, job_id=None, model_id='1190686', model_type=None, mutation_name=None, name='core__calculateGraph', progress=1.0, result=None, runtime=0.915606, started_at=None, status='SUCCESS', tasks=None, terminated_at=None, transactions=None, updated_at=None, user=None))

This notebook was run using the following package versions. It should also be compatible with newer versions of the Q-CTRL Python package.

Package Version
Python 3.9.12
numpy 1.23.3
scipy 1.9.1
qctrl 19.5.0
qctrl-commons 17.3.0
qctrl-toolkit 1.9.0