Graph.constant_pwc(constant, duration, batch_dimension_count=0, *, name=None)

Create a piecewise-constant function of time that is constant over a specified duration.


  • constant (number or np.ndarray or Tensor) – The value cc of the function on the constant segment. To create a batch of B1××BnB_1 \times \ldots \times B_n piecewise-constant functions of shape D1××DmD_1 \times \ldots \times D_m, provide this constant parameter as an object of shape B1××Bn×D1××DmB_1\times\ldots\times B_n\times D_1\times\ldots\times D_m
  • duration (float) – The duration τ\tau
  • batch_dimension_count (int , optional) – The number of batch dimensions, nn in constant. If provided, the first nn
  • name (str or None , optional) – The name of the node.


The constant function f(t)=cf(t) = c (for 0tτ0\leq t\leq\tau

Return type



Graph.constant_pwc_operator : Create constant Pwc operators.

Graph.constant_stf : Corresponding operation for Stfs. : Create piecewise-constant functions.


For more information on Pwc nodes see the Working with time-dependent functions in Boulder Opal topic.


Create a batched piecewise-constant function.

>>> constant = np.arange(12).reshape((2, 2, 3))
>>> graph.constant_pwc(
...     constant=constant, duration=0.1, batch_dimension_count=1, name="constant"
... )
<Pwc: name="constant", operation_name="constant_pwc", value_shape=(2, 3), batch_shape=(2,)>
>>> result = bo.execute_graph(graph=graph, output_node_names="constant")
>>> result["output"]["constant"]
    'durations': array([0.1]),
    'values': array([
        [[[ 0.,  1.,  2.], [ 3.,  4.,  5.]]],
        [[[ 6.,  7.,  8.], [ 9., 10., 11.]]]
    'time_dimension': 1

See more examples in the Simulate the dynamics of a single qubit using computational graphs tutorial.

Was this useful?