# linear_ramp_pwc

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

```python
signals.linear_ramp_pwc(duration, segment_count, end_value, start_value=None, start_time=0, end_time=None, segmentation=SegmentationType.UNIFORM, *, name=None)
```

Create a Pwc representing a linear ramp.

### Parameters
* **duration** (*float*) – The duration of the signal, $T$.
* **segment_count** (*int*) – The number of segments in the PWC.
* **end_value** (*float* *or* *complex* *or* [*Tensor*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor)) – The value of the ramp at $t = t_\mathrm{end}$, $a_\mathrm{end}$.
  It must either be a scalar or contain a single element.
* **start_value** (*float* *or* *complex* *or* [*Tensor*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor) *or* *None* *,* *optional*) – The value of the ramp at $t = t_\mathrm{start}$, $a_\mathrm{start}$.
  If passed, it must either be a scalar or contain a single element.
  Defaults to $-a_\mathrm{end}$.
* **start_time** (*float* *,* *optional*) – The time at which the linear ramp starts, $t_\mathrm{start}$.
  Defaults to 0.
* **end_time** (*float* *or* *None* *,* *optional*) – The time at which the linear ramp ends, $t_\mathrm{end}$.
  Defaults to the given duration $T$.
* **segmentation** ([`SegmentationType`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/signals/SegmentationType.md#boulderopal.graph.signals.SegmentationType)) – The type of segmentation for the signal.
  With a “MINIMAL” segmentation, most of the segments are placed in the
  non-constant parts of the signal.
  Defaults to “UNIFORM”, in which case the segments are uniformly
  distributed along the signal’s duration.
* **name** (*str* *or* *None* *,* *optional*) – The name of the node.
### Returns
The sampled linear ramp.
### Return type
[Pwc](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Pwc.md#boulderopal.graph.Pwc)

### SEE ALSO
[`boulderopal.signals.linear_ramp`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/signals/linear_ramp.md#boulderopal.signals.linear_ramp)
: Create a Signal object representing a linear ramp.

[`Graph.signals.linear_ramp_stf`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/signals/linear_ramp_stf.md#boulderopal.graph.signals.linear_ramp_stf)
: Corresponding operation with Stf output.

[`Graph.signals.tanh_ramp_pwc`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/signals/tanh_ramp_pwc.md#boulderopal.graph.signals.tanh_ramp_pwc)
: Create a Pwc representing a hyperbolic tangent ramp.

## Notes

The linear ramp is defined as

$$
\mathop{\mathrm{Linear}}(t) =
\begin{cases}
    a_\mathrm{start} &\mathrm{if} \quad t < t_\mathrm{start}\\
    a_\mathrm{start} + (a_\mathrm{end} - a_\mathrm{start})
        \frac{t - t_\mathrm{start}}{t_\mathrm{end} - t_\mathrm{start}}
        &\mathrm{if} \quad t_\mathrm{start} \le t \le t_\mathrm{end} \\
    a_\mathrm{end} &\mathrm{if} \quad t > t_\mathrm{end}
\end{cases} .
$$

## Examples

Define a linear PWC ramp.

```pycon
>>> graph.signals.linear_ramp_pwc(
...     duration=2.0, segment_count=5, end_value=1.5, start_value=0.5, name="linear_ramp"
... )
<Pwc: name="linear_ramp", operation_name="pwc_signal", value_shape=(), batch_shape=()>
>>> result = bo.execute_graph(graph=graph, output_node_names="linear_ramp")
>>> result["output"]["linear_ramp"]
{
    'durations': array([0.4, 0.4, 0.4, 0.4, 0.4]),
    'values': array([0.6, 0.8, 1. , 1.2, 1.4]),
    'time_dimension': 0
}
```

Define a linear ramp with start and end times.

```pycon
>>> graph.signals.linear_ramp_pwc(
...     duration=4,
...     segment_count=8,
...     end_value=2,
...     start_time=1,
...     end_time=3,
...     name="linear",
... )
<Pwc: name="linear", operation_name="pwc_signal", value_shape=(), batch_shape=()>
>>> result = bo.execute_graph(graph=graph, output_node_names="linear")
>>> result["output"]["linear"]
{
    'durations': array([0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]),
    'values': array([-2. , -2. , -1.5, -0.5,  0.5,  1.5,  2. ,  2. ]),
    'time_dimension': 0
}
```

Define a linear ramp with minimal segmentation.

```pycon
>>> graph.signals.linear_ramp_pwc(
...     duration=4,
...     segment_count=6,
...     end_value=2,
...     start_time=1,
...     end_time=3,
...     segmentation="MINIMAL",
...     name="linear",
... )
<Pwc: name="linear", operation_name="time_concatenate_pwc", value_shape=(), batch_shape=()>
>>> result = bo.execute_graph(graph=graph, output_node_names="linear")
>>> result["output"]["linear"]
{
    'durations': array([1. , 0.5, 0.5, 0.5, 0.5, 1. ]),
    'values': array([-2. , -1.5, -0.5,  0.5,  1.5,  2. ]),
    'time_dimension': 0
}
```

Define a linear ramp with an optimizable slope around 0.

```pycon
>>> duration = 4.0
>>> slope = graph.optimizable_scalar(
...     lower_bound=-30, upper_bound=30, name="slope"
... )
>>> end_value = slope * duration / 2
>>> graph.signals.linear_ramp_pwc(
...     duration=duration, segment_count=64, end_value=end_value, name="linear_ramp"
... )
<Pwc: name="linear_ramp", operation_name="pwc_signal", value_shape=(), batch_shape=()>
```
