TimeBlockData

class flexops.core.time_block.TimeBlockData(component)

A discrete, bounded time horizon at a configurable resolution.

Holds the ordered integer time set (time_index), the elapsed-time Param (time, i*dt), the unit-carrying step size (dt), datetime↔index utilities, and the rolling-horizon hooks (register_initial_state, window) that flexschedule drives. Time points are interval starts: point i is the timestamp start_date + i * dt; end_date is the exclusive horizon end and is not itself a time point.

A single TimeBlock spans at most max_length (default one calendar month); longer studies are composed from multiple TimeBlock blocks by the rolling-horizon driver or the design-mode wrapper.

Example

>>> from pyomo.environ import units as pyunits
>>> m = pyo.ConcreteModel()
>>> m.time_block = TimeBlock(
...     start_date="2025-01-01", end_date="2025-01-31",
...     time_step=15 * pyunits.min,
... )
build() → None

Construct time_index, time, dt, and the datetime/state registries.

property datetime_index: DatetimeIndex

timestamps of every time point.

Type:

pandas.DatetimeIndex

property horizon

Total horizon length as a unit-carrying expression, n_points * dt.

index_of(timestamp) → int

Return the time-point index for a timestamp.

Parameters:

timestamp – A pd.Timestamp, datetime, or ISO-8601 string that must fall exactly on a grid point.

Returns:

The integer time-point index.

Raises:

FlexConfigError – If timestamp is off-grid or outside the horizon.

property initial_state_params: tuple

the registered rolling-horizon initial states (fixed scalar Vars or mutable Params).

Type:

tuple

property n_points: int

Number of time points, N.

Type:

int

register_initial_state(param) → None

Register a fixed scalar Var or mutable Param as initial state.

A fixed scalar Var (as built by declare_process_parameter()) is preferred: a sweep can set it and a scenario can unfix it and solve for it in place. Mutable Param s are still accepted.

Parameters:

param – A fixed scalar Pyomo Var or a mutable Param (e.g. tank level, battery SOC, on/off status) that the rolling-horizon driver sets between windows.

Raises:

FlexConfigError – If param is neither; if it is an indexed or unfixed Var; or if it is a Param declared with mutable=False.

timestamp_of(i: int) → Timestamp

Return the timestamp for a time-point index.

Parameters:

i – A time-point index.

Returns:

The corresponding pd.Timestamp.

Raises:

FlexConfigError – If i is outside [0, n_points).

window(start: int, length: int) → TimeWindow

Return metadata for a contiguous slice of the horizon.

Parameters:
  • start – First time-point index of the window.

  • length – Requested number of time points; clipped if the window would run past the horizon.

Returns:

The window metadata.

Raises:

FlexConfigError – If start is outside [0, n_points).