# square_pulse_pwc

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

```python
signals.square_pulse_pwc(duration, segment_count, amplitude, start_time=0, end_time=None, segmentation=SegmentationType.UNIFORM, *, name=None)
```

Create a Pwc representing a square pulse.

The entire signal lasts from time 0 to the given duration with the
square pulse being applied from the start time to the end time.

### Parameters
* **duration** (*float*) – The duration of the signal.
* **segment_count** (*int*) – The number of segments in the PWC.
  Only used if the segmentation type is “UNIFORM” .
* **amplitude** (*float* *or* *complex* *or* [*Tensor*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor)) – The amplitude of the square pulse, $A$.
  It must either be a scalar or contain a single element.
* **start_time** (*float* *,* *optional*) – The start time of the square pulse, $t_\mathrm{start}$.
  Defaults to 0.
* **end_time** (*float* *or* *None* *,* *optional*) – The end time of the square pulse, $t_\mathrm{end}$.
  Must be greater than the start time.
  Defaults to the value of the given duration.
* **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 pulse.
  With a “MINIMAL” segmentation, the returned Pwc has
  between one and three segments, depending on the start time,
  end time, and duration 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 square pulse.
### Return type
[Pwc](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Pwc.md#boulderopal.graph.Pwc)

### SEE ALSO
[`Graph.signals.cosine_pulse_pwc`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/signals/cosine_pulse_pwc.md#boulderopal.graph.signals.cosine_pulse_pwc)
: Create a Pwc representing a cosine pulse.

[`Graph.signals.gaussian_pulse_pwc`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/signals/gaussian_pulse_pwc.md#boulderopal.graph.signals.gaussian_pulse_pwc)
: Create a Pwc representing a Gaussian pulse.

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

[`boulderopal.signals.square_pulse`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/signals/square_pulse.md#boulderopal.signals.square_pulse)
: Create a Signal object representing a square pulse.

## Notes

The square pulse is defined as

$$
\mathop{\mathrm{Square}}(t)
= A \theta(t-t_\mathrm{start}) \theta(t_\mathrm{end}-t) ,
$$

where $\theta(t)$ is the
[Heaviside step function](https://en.wikipedia.org/wiki/Heaviside_step_function).

## Examples

Define a square pulse with an optimizable amplitude.

```pycon
>>> amplitude = graph.optimizable_scalar(
...     lower_bound=0, upper_bound=2.*np.pi, name="amplitude"
... )
>>> graph.signals.square_pulse_pwc(
...     duration=4.0, amplitude=amplitude, segment_count=100, name="square"
... )
<Pwc: name="square", operation_name="pwc_signal", value_shape=(), batch_shape=()>
```

Define a square PWC pulse.

```pycon
>>> graph.signals.square_pulse_pwc(
...     duration=4.0,
...     segment_count=5,
...     amplitude=2.5,
...     start_time=1.0,
...     end_time=3.0,
...     name="square",
... )
<Pwc: name="square", operation_name="pwc_signal", value_shape=(), batch_shape=()>
>>> result = bo.execute_graph(graph=graph, output_node_names="square")
>>> result["output"]["square"]
{
    'durations': array([0.8, 0.8, 0.8, 0.8, 0.8]),
    'values': array([0. , 2.5, 2.5, 2.5, 0. ]),
    'time_dimension': 0
}
```

Define a square PWC pulse with a minimal segmentation.

```pycon
>>> graph.signals.square_pulse_pwc(
...     duration=4.0,
...     segment_count=None,
...     amplitude=2.5,
...     start_time=1.0,
...     end_time=3.0,
...     segmentation="MINIMAL",
...     name="square",
... )
<Pwc: name="square", operation_name="time_concatenate_pwc", value_shape=(), batch_shape=()>
>>> result = bo.execute_graph(graph=graph, output_node_names="square")
>>> result["output"]["square"]
{
    'durations': array([1., 2., 1.]),
    'values': array([0. , 2.5, 0. ]),
    'time_dimension': 0
}
```
