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 \(c\) of the function on the constant segment. To create a batch of \(B_1 \times \ldots \times B_n\) piecewise-constant functions of shape \(D_1 \times \ldots \times D_m\), provide this constant parameter as an object of shape \(B_1\times\ldots\times B_n\times D_1\times\ldots\times D_m\).

  • duration (float) – The duration \(\tau\) for the resulting piecewise-constant function.

  • batch_dimension_count (int, optional) – The number of batch dimensions, \(n\) in constant. If provided, the first \(n\) dimensions of constant are considered batch dimensions. Defaults to 0, which corresponds to no batch.

  • name (str or None, optional) – The name of the node.


The constant function \(f(t) = c\) (for \(0\leq t\leq\tau\)) (or a batch of constant functions, if you provide batch_dimension_count).

Return type:


See also


Create constant Pwc operators.


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.