braket.timings.time_series module

class braket.timings.time_series.TimeSeriesItem(time: 'Number', value: 'Number')[source]

Bases: object

time: Number
value: Number
class braket.timings.time_series.StitchBoundaryCondition(value)[source]

Bases: str, Enum

An enumeration.

MEAN = 'mean'
LEFT = 'left'
RIGHT = 'right'
class braket.timings.time_series.TimeSeries[source]

Bases: object

put(time: Number, value: Number) TimeSeries[source]

Puts a value to the time series at the given time. A value passed to an existing time will overwrite the current value.

Parameters:
  • time (Number) – The time of the value.

  • value (Number) – The value to add to the time series.

Returns:

TimeSeries – returns self (to allow for chaining).

times() list[Number][source]

Returns the times in the time series.

Returns:

list[Number] – The times in the time series.

values() list[Number][source]

Returns the values in the time series.

Returns:

list[Number] – The values in the time series.

static from_lists(times: list[float], values: list[float]) TimeSeries[source]

Create a time series from the list of time and value points

Parameters:
  • times (list[float]) – list of time points

  • values (list[float]) – list of value points

Returns:

TimeSeries – time series constructed from lists

Raises:

ValueError – If the len of times does not equal len of values.

static constant_like(times: list | float | TimeSeries, constant: float = 0.0) TimeSeries[source]

Obtain a constant time series given another time series or the list of time points, and the constant values.

Parameters:
  • times (list | float | TimeSeries) – list of time points or a time series

  • constant (float) – constant value

Returns:

TimeSeries – A constant time series

concatenate(other: TimeSeries) TimeSeries[source]

Concatenates two time series ino to a single time series. The time points in the final time series are obtained by concatenating two lists of time points from the first and the second time series. Similarly, the values in the final time series is a concatenated list of the values in the first and the second time series.

Parameters:

other (TimeSeries) – The second time series to be concatenated Notes: Keeps the time points in both time series unchanged. Assumes that the time points in the first TimeSeries are at earlier times then the time points in the second TimeSeries.

Returns:

TimeSeries – The concatenated time series.

Raises:

ValueError – If the timeseries is not empty and time points in the first TimeSeries are not strictly smaller than in the second.

Example:

time_series_1 = TimeSeries.from_lists(times=[0, 0.1], values=[1, 2])
time_series_2 = TimeSeries.from_lists(times=[0.2, 0.3], values=[4, 5])

concat_ts = time_series_1.concatenate(time_series_2)

Result:
    concat_ts.times() = [0, 0.1, 0.2, 0.3]
    concat_ts.values() = [1, 2, 4, 5]
stitch(other: TimeSeries, boundary: StitchBoundaryCondition = StitchBoundaryCondition.MEAN) TimeSeries[source]

Stitch two time series to a single time series. The time points of the second time series are shifted such that the first time point of the second series coincides with the last time point of the first series. The boundary point value is handled according to StitchBoundaryCondition argument value.

Parameters:
  • other (TimeSeries) – The second time series to be stitched with.

  • boundary (StitchBoundaryCondition) –

    {“mean”, “left”, “right”}. Boundary point handler.

    Possible options are

    • ”mean” - take the average of the boundary value points of the first and the second time series.

    • ”left” - use the last value from the left time series as the boundary point.

    • ”right” - use the first value from the right time series as the boundary point.

Returns:

TimeSeries – The stitched time series.

Raises:

ValueError – If boundary is not one of {“mean”, “left”, “right”}.

Example (StitchBoundaryCondition.MEAN):

time_series_1 = TimeSeries.from_lists(times=[0, 0.1], values=[1, 2])
time_series_2 = TimeSeries.from_lists(times=[0.2, 0.4], values=[4, 5])

stitch_ts = time_series_1.stitch(time_series_2, boundary=StitchBoundaryCondition.MEAN)

Result:
    stitch_ts.times() = [0, 0.1, 0.3]
    stitch_ts.values() = [1, 3, 5]

Example (StitchBoundaryCondition.LEFT):

stitch_ts = time_series_1.stitch(time_series_2, boundary=StitchBoundaryCondition.LEFT)

Result:
    stitch_ts.times() = [0, 0.1, 0.3]
    stitch_ts.values() = [1, 2, 5]

Example (StitchBoundaryCondition.RIGHT):

stitch_ts = time_series_1.stitch(time_series_2, boundary=StitchBoundaryCondition.RIGHT)

Result:
    stitch_ts.times() = [0, 0.1, 0.3]
    stitch_ts.values() = [1, 4, 5]
discretize(time_resolution: Decimal | None, value_resolution: Decimal | None) TimeSeries[source]

Creates a discretized version of the time series, rounding all times and values to the closest multiple of the corresponding resolution.

Parameters:
  • time_resolution (Optional[Decimal]) – Time resolution

  • value_resolution (Optional[Decimal]) – Value resolution

Returns:

TimeSeries – A new discretized time series.

static periodic_signal(times: list[float], values: list[float], num_repeat: int = 1) TimeSeries[source]

Create a periodic time series by repeating the same block multiple times.

Parameters:
  • times (list[float]) – List of time points in a single block

  • values (list[float]) – Values for the time series in a single block

  • num_repeat (int) – Number of block repetitions

Raises:

ValueError – If the first and last values are not the same

Returns:

TimeSeries – A new periodic time series.

static trapezoidal_signal(area: float, value_max: float, slew_rate_max: float, time_separation_min: float = 0.0) TimeSeries[source]

Get a trapezoidal time series with specified area, maximum value, maximum slew rate and minimum separation of time points

Parameters:
  • area (float) – Total area under the time series

  • value_max (float) – The maximum value of the time series

  • slew_rate_max (float) – The maximum slew rate

  • time_separation_min (float) – The minimum separation of time points

Raises:

ValueError – If the time separation is negative

Returns:

TimeSeries – A trapezoidal time series

Notes: The area of a time series f(t) is defined as the time integral of f(t) from t=0 to t=T, where T is the duration. We also assume the trapezoidal time series starts and ends at zero.