qat.experimental.waveforms.shapes.soft_square module

Implements the sampling definitions for a Soft Square waveform shape.

This waveform has a fractional_rise and fall at the edges of the waveform, with a roughly square region in the center. It is implemented by two hyperbolic tangent (tanh) functions in opposite directions.

The first tanh is centered at -fractional_top_width and second is centered at fractional_top_width, where fractional_top_width is a dimensionless parameter between 0 and 1 that defined the width of the roughly square region in the center of the waveform. The sharpness of the fractional_rise and fall edges are defined by the parameter fractional_rise, which is a dimensionless parameter that defines the sharpness of the fractional_rise and fall. Optionally, the regularize parameter can be set to True so that the waveform is zero at the edges and unity at the center.

The waveform has the formula

\[f(x) = \frac{1}{N}\left[ \tanh\left(\frac{x + w_t}{r}\right) - \tanh\left(\frac{x - w_t}{r}\right) - C \right]\]

where \(w_t\) is fractional_top_width and \(r\) is fractional_rise. \(C\) is the shift value, and \(N\) is the rescale (regularize) value, which are zero and one respectively if regularize is set to False, and otherwise

\[C = \left[ \tanh\left(\frac{1 + w_t}{r}\right) - \tanh\left(\frac{1 - w_t}{r}\right) \right]\]
\[N = \tanh\left(\frac{w_t}{r}\right) - \tanh\left(-\frac{w_t}{r}\right) - C.\]

This waveform implements the SoftSquareWaveform, the SofterSquareWaveform, and the ExtraSoftSquareWaveform shapes in the legacy implementation, under the following parameterisations:

  • SoftSquareWaveform: fractional_top_width = 1 - fractional_rise / width, fractional_rise = 2 * fractional_rise / width, regularize = False.

  • SofterSquareWaveform: fractional_top_width = (std_dev - 2 * fractional_rise) / width, fractional_rise = 2 * fractional_rise / width, regularize = True.

  • ExtraSoftSquareWaveform: fractional_top_width = (std_dev - 4 * fractional_rise) / width, fractional_rise = 2 * fractional_rise / width, regularize = True.

You can see the fractional_top_width parameterisation effectively becoming smaller as we make the squares softer in this parameterisation.

class SoftSquareWaveformShape(fractional_top_width=0.5, fractional_rise=0.1, regularize=False)

Bases: WaveformShape

Waveform-shape wrapper for soft-square sampling functions.

derivative(x, order=1)

Evaluates the derivative of the soft-square waveform shape.

Return type:

ndarray[tuple[int, ...], dtype[complexfloating]]

evaluate(x)

Evaluates the soft-square waveform shape at the sample points.

Return type:

ndarray[tuple[int, ...], dtype[complexfloating]]

fractional_rise: float = 0.1
fractional_top_width: float = 0.5
classmethod from_absolute(width, absolute_top_width, absolute_rise, regularize=False)

Constructs from absolute parameters.

Parameters:
  • width (float) – The waveform width.

  • absolute_top_width (float) – The “top width” of the Soft Square function.

  • absolute_rise (float) – The sharpness of the fractional_rise and fall edges of the Soft Square function.

  • regularize (bool) – If True, applies a shift and rescaling so that the waveform is zero at the edges with maximum component one. Default is False.

Return type:

SoftSquareWaveformShape

classmethod from_extra_soft_square_waveform(std_dev, rise, width)

Constructs from legacy ExtraSoftSquareWaveform parameters.

Parameters:
  • std_dev (float) – The std_dev parameter from the legacy implementation.

  • rise (float) – The rise parameter from the legacy implementation.

  • width (float) – The waveform width.

Return type:

SoftSquareWaveformShape

classmethod from_soft_square_waveform(rise, width)

Constructs from legacy SoftSquareWaveform parameters.

Parameters:
  • rise (float) – The rise parameter from the legacy implementation.

  • width (float) – The waveform width.

Return type:

SoftSquareWaveformShape

classmethod from_softer_square_waveform(std_dev, rise, width)

Constructs from legacy SofterSquareWaveform parameters.

Parameters:
  • std_dev (float) – The std_dev parameter from the legacy implementation.

  • rise (float) – The rise parameter from the legacy SofterSquareWaveform implementation.

  • width (float) – The waveform width.

Return type:

SoftSquareWaveformShape

regularize: bool = False
sample_soft_square_waveform(x, *, fractional_top_width=0.5, fractional_rise=0.1, regularize=False)

Samples a Soft Square waveform shape.

Parameters:
  • x (ndarray[tuple[int, ...], dtype[floating]] | list[float]) – The list of values in the range [-1, 1] to sample the waveform for.

  • fractional_top_width (float) – The width of the roughly square region in the center of the waveform, default is 0.5.

  • fractional_rise (float) – The sharpness of the fractional_rise and fall edges of the waveform, default is 0.1.

  • regularize (bool) – Whether to regularize the waveform to be zero at the edges and unity at the center, default is False.

Return type:

ndarray[tuple[int, ...], dtype[complexfloating]]

Returns:

The sampled Soft Square waveform as a complex-valued array.

sample_soft_square_waveform_derivative(x, order=1, *, fractional_top_width=0.5, fractional_rise=0.1, regularize=False)

Samples the derivative of a Soft Square waveform shape.

Parameters:
  • x (ndarray[tuple[int, ...], dtype[floating]] | list[float]) – The list of values in the range [-1, 1] to sample the waveform for.

  • fractional_top_width (float) – The width of the roughly square region in the center of the waveform, default is 0.5.

  • fractional_rise (float) – The sharpness of the fractional_rise and fall edges of the waveform, default is 0.1.

  • regularize (bool) – Whether to apply the same regularize scale as the waveform, default is False.

  • order (int) – The order of the derivative to sample, default is 1.

Return type:

ndarray[tuple[int, ...], dtype[complexfloating]]