pwc_pairs_to_arrays
The Boulder Opal Toolkits are currently in beta phase of development. Breaking changes may be introduced.
- pwc_pairs_to_arrays(pwc)
Extract arrays with the durations and values representing a piecewise-constant function from a list of dictionaries with “value” and “duration” keys.
You can use this function to retrieve the durations and values of a PWC extracted from a Boulder Opal graph calculation.
- Parameters:
pwc (list[...list[list[dict]]]) – A nested list of lists of … of list of dictionaries. The outer lists represent batches. The dictionaries in the innermost list must have “value” and “duration” keys, defining a PWC.
- Returns:
np.ndarray – The durations of the PWC.
np.ndarray – The values of the PWC.
int – The number of batch dimensions.
See also
utils.pwc_arrays_to_pairs()
Perform the inverse conversion.
Examples
>>> pwc_example = [ {'duration': 1.0, 'value': 3}, {'duration': 0.5, 'value': -2}, {'duration': 0.5, 'value': 4}, ] >>> qctrl.utils.pwc_pairs_to_arrays(pwc_example) (array([1., 0.5, 0.5]), array([3, -2, 4]), 0)
>>> pwc_example = [ [{'duration': 1.0, 'value': 3}, {'duration': 0.5, 'value': -2}, {'duration': 0.5, 'value': 4}], [{'duration': 1.0, 'value': 2}, {'duration': 0.5, 'value': 3}, {'duration': 0.5, 'value': -1}] ] >>> qctrl.utils.pwc_pairs_to_arrays(pwc_example) (array([1., 0.5, 0.5]), array([[3, -2, 4], [2, 3, -1]]), 1)
Define a PWC from a graph calculation.
>>> graph.pwc(*qctrl.utils.pwc_pairs_to_arrays(result.output['signal'])) <Pwc: name="pwc_#1", operation_name="pwc", value_shape=(), batch_shape=(4, 3)>