# pwc_sum

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

```python
Graph.pwc_sum(terms, *, name=None)
```

Create the sum of multiple piecewise-constant terms.

### Parameters
* **terms** (*list* *[*[*Pwc*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Pwc.md#boulderopal.graph.Pwc) *]*) – The individual piecewise-constant terms $\{v_j(t)\}$ to sum. All
  terms must have the same duration, values of the same shape, and the
  same batch shape, but may have different segmentations (different
  numbers of segments of different durations) and different dtypes of
  segment values.
* **name** (*str* *or* *None* *,* *optional*) – The name of the node.
### Returns
The piecewise-constant function (or batch of functions) of time
$\sum_j v_j(t)$. Its values have the same shape as the values of
each of the terms that you provided. If each of the terms represents
a batch of functions, this result represents a batch of functions with
the same batch shape. If any term has complex-valued segments, the
value of the returned Pwc is complex, otherwise is float.
### Return type
[Pwc](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Pwc.md#boulderopal.graph.Pwc)

### SEE ALSO
[`Graph.discretize_stf`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/discretize_stf.md#boulderopal.graph.Graph.discretize_stf)
: Discretize an Stf into a Pwc.

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

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

[`Graph.pwc_signal`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/pwc_signal.md#boulderopal.graph.Graph.pwc_signal)
: Create Pwc signals from (possibly complex) values.

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

## 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

Sum a list of piecewise-constant terms of different durations.

```pycon
>>> x = graph.pwc(durations=np.array([0.1, 0.3]), values=np.array([1, 2]))
>>> y = graph.pwc(durations=np.array([0.2, 0.2]), values=np.array([3, 1]))
>>> graph.pwc_sum([x, y], name="sum")
<Pwc: name="sum", operation_name="pwc_sum", value_shape=(), batch_shape=()>
>>> result = bo.execute_graph(graph=graph, output_node_names="sum")
>>> result["output"]["sum"]
{
    'durations': array([0.1, 0.1, 0.2]),
    'values': array([4., 5., 3.]),
    'time_dimension': 0
}
```

See more examples in the [How to optimize controls robust to strong noise sources](https://docs.q-ctrl.com/boulder-opal/user-guides/how-to-optimize-controls-robust-to-strong-noise-sources) user guide.
