# constant_pwc

Source: https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/constant_pwc

```python
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.

### Parameters
* **constant** (*number* *or* *np.ndarray* *or* [*Tensor*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.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.
### Returns
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
[Pwc](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Pwc.md#boulderopal.graph.Pwc)

### SEE ALSO
[`Graph.constant_pwc_operator`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/constant_pwc_operator.md#boulderopal.graph.Graph.constant_pwc_operator)
: Create constant Pwc operators.

[`Graph.constant_stf`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/constant_stf.md#boulderopal.graph.Graph.constant_stf)
: Corresponding operation for Stfs.

[`Graph.pwc`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/pwc.md#boulderopal.graph.Graph.pwc)
: Create piecewise-constant functions.

## Notes

For more information on Pwc nodes see the [Working with time-dependent functions in
Boulder Opal](https://docs.q-ctrl.com/boulder-opal/topics/working-with-time-dependent-functions-in-boulder-opal) topic.

## Examples

Create a batched piecewise-constant function.

```pycon
>>> 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](https://docs.q-ctrl.com/boulder-opal/tutorials/simulate-the-dynamics-of-a-single-qubit-using-computational-graphs) tutorial.
