leap_c.parameters.utils

Parameter type alias and numpy helpers for stage-varying MPC parameters.

Attributes

ParamSplits

How a differentiable parameter varies across the MPC horizon.

Functions

broadcast_default_param(→ numpy.ndarray | dict[str, ...)

Broadcast a per-stage default parameter to the batch shape implied by obs.

n_segments(→ int)

Return the number of independent segments a splits specification produces.

Module Contents

leap_c.parameters.utils.broadcast_default_param(default: numpy.ndarray | dict[str, numpy.ndarray], obs: numpy.ndarray | torch.Tensor | None = None) numpy.ndarray | dict[str, numpy.ndarray][source]

Broadcast a per-stage default parameter to the batch shape implied by obs.

For a batched obs of shape (B, obs_dim), the default is broadcast to (B, *param_shape). Without obs (or a 1-D obs) the unbatched default is returned. Handles both np.ndarray and dict[str, np.ndarray] defaults.

leap_c.parameters.utils.n_segments(splits: ParamSplits, N_horizon: int) int[source]

Return the number of independent segments a splits specification produces.

Parameters:
  • splits – The split specification (see ParamSplits).

  • N_horizon – The MPC horizon length (number of shooting intervals).

Returns:

1 for "global", N_horizon + 1 for "stagewise", splits for an int, and len(splits) for a list.

Return type:

The number of segments

leap_c.parameters.utils.ParamSplits

How a differentiable parameter varies across the MPC horizon.

  • "global": one value shared across all stages.

  • "stagewise": one independent value per stage (N+1 values total).

  • int: number of equal-sized stage segments.

  • list[int]: explicit stage boundaries (ascending), e.g. [4, 9].