linear_ramp_pwc
The Boulder Opal Toolkits are currently in beta phase of development. Breaking changes may be introduced.
- linear_ramp_pwc(duration, segment_count, end_value, start_value=None, start_time=0.0, end_time=None, segmentation='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) – 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, 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, optional) – The time at which the linear ramp ends, \(t_\mathrm{end}\). Defaults to the given duration \(T\).
segmentation (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, optional) – The name of the node.
- Returns
The sampled linear ramp.
- Return type
See also
signals.linear_ramp()
Function to create a Signal object representing a linear ramp.
signals.linear_ramp_stf()
Corresponding operation with Stf output.
signals.tanh_ramp_pwc()
Create a Pwc representing a hyperbolic tangent ramp.
Notes
The linear ramp is defined as
\[\begin{split}\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} .\end{split}\]Examples
Define a linear PWC ramp.
>>> 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 = qctrl.functions.calculate_graph(graph=graph, output_node_names=["linear_ramp"]) >>> result.output["linear_ramp"] [ {'duration': 0.4, 'value': 0.6}, {'duration': 0.4, 'value': 0.8}, {'duration': 0.4, 'value': 1.0}, {'duration': 0.4, 'value': 1.2}, {'duration': 0.4, 'value': 1.4}, ]
Define a linear ramp with start and end times.
>>> 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 = qctrl.functions.calculate_graph(graph=graph, output_node_names=["linear"]) >>> result.output["linear"] [ {'value': -2.0, 'duration': 0.5}, {'value': -2.0, 'duration': 0.5}, {'value': -1.5, 'duration': 0.5}, {'value': -0.5, 'duration': 0.5}, {'value': 0.5, 'duration': 0.5}, {'value': 1.5, 'duration': 0.5}, {'value': 2.0, 'duration': 0.5}, {'value': 2.0, 'duration': 0.5}, ]
Define a linear ramp with minimal segmentation.
>>> 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 = qctrl.functions.calculate_graph(graph=graph, output_node_names=["linear"]) >>> result.output["linear"] [ {'value': -2.0, 'duration': 1.0}, {'value': -1.5, 'duration': 0.5}, {'value': -0.5, 'duration': 0.5}, {'value': 0.5, 'duration': 0.5}, {'value': 1.5, 'duration': 0.5}, {'value': 2.0, 'duration': 1.0}, ]
Define a linear ramp with an optimizable slope around 0.
>>> duration = 4.0 >>> slope = graph.optimization_variable( ... count=1, 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=()>