How to mute status messages during calculations
Change the verbosity of the messaging
When running calculations on Boulder Opal, the Qctrl
object informs you of their status by printing messages.
These display for instance, whether a task has started or completed, and include a unique action ID you can use to identify and manage the calculation.
In this user guide we demonstrate how to change this behavior and mute these messages.
Selecting the message verbosity
Choosing the display behavior during authentication
You can use the verbosity
parameter when instantiating a Qctrl
object to choose how you want to be notified of the progress of your tasks.
By default (not passing a verbosity
, equivalent to setting verbosity="VERBOSE"
) messsages and progress bars will be displayed during calculations.
Alternatively, you can mute them by passing verbosity="QUIET"
to the Qctrl
object constructor.
def run_calculation():
"""
Run a simple π-pulse simulation and print the resulting infidelity.
"""
graph = qctrl.create_graph()
amplitude = np.pi * 1e5 # rad/s
duration = 5e-6 # s
pi_pulse = graph.constant_pwc(amplitude, duration)
infidelity = graph.infidelity_pwc(
hamiltonian=pi_pulse * graph.pauli_matrix("X"),
target=graph.target(graph.pauli_matrix("X")),
name="infidelity",
)
result = qctrl.functions.calculate_graph(
graph=graph, output_node_names=["infidelity"]
)
print(f"Infidelity: {result.output['infidelity']['value']:.3e}")
return result
import numpy as np
from qctrl import Qctrl
# Start a Boulder Opal session, muting messages.
qctrl = Qctrl(verbosity="QUIET")
# Run simple calculation.
result = run_calculation()
Infidelity: 4.441e-16
Changing the display behavior
During your session with the API, you can turn messages and progress bars on again using the qctrl.set_verbosity
method with the "VERBOSE"
tag:
# Turning on output messages.
qctrl.set_verbosity("VERBOSE")
result = run_calculation()
Your task calculate_graph (action_id="1605133") has completed.
Infidelity: 4.441e-16
Similarly, you can turn them off with the "QUIET"
tag.
# Turning off output messages.
qctrl.set_verbosity("QUIET")
result = run_calculation()
Infidelity: 4.441e-16
Retrieving action IDs
Note that by muting the messages for calculations, their corresponding action IDs will not be displayed.
These are useful in case you want to retrieve the calculation results at a later time, see this user guide for more details.
In that case, you can still retrieve the action ID by consulting the Boulder Opal web app, or from the Result
object of the calculation.
print("Action ID of the previous calculation:", result.action_id)
Action ID of the previous calculation: 1605134
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.10.8 |
numpy | 1.24.1 |
scipy | 1.10.0 |
qctrl | 20.1.1 |
qctrl-commons | 17.7.0 |
boulder-opal-toolkits | 2.0.0-beta.3 |