The Boulder Opal Toolkits are currently in beta phase of development. Breaking changes may be introduced.

pwc_arrays_to_pairs(durations, values)

Create a list of dictionaries with “value” and “duration” keys representing a piecewise-constant function from arrays containing the durations and values.

You can use this function to prepare a control to be plotted with the plot_controls function from the Q-CTRL Visualizer package.

  • durations (np.ndarray or float) – The durations of the PWC segments as a 1D array or as a float. If a single (float) value is passed, it is taken as the total duration of the PWC and all segments are assumed to have the same duration.

  • values (np.ndarray) – The values of the PWC.


A list of dictionaries (with “value” and “duration” keys) defining a PWC.

Return type


See also


Perform the inverse conversion.


>>> qctrl.utils.pwc_arrays_to_pairs(1.0, np.array([3,-2,4,1]))
    {'duration': 0.25, 'value': 3},
    {'duration': 0.25, 'value': -2},
    {'duration': 0.25, 'value': 4},
    {'duration': 0.25, 'value': 1}

Plot a control using the function plot_controls from the Q-CTRL Visualizer package.

>>> plot_controls(
...     plt.figure(),
...     {"control": qctrl.utils.pwc_arrays_to_pairs(np.array([1,3,2]), np.array([-1,1,2]))},
... )