leap_c.utils.collate¶
Collate helpers for leap-c context objects.
These helpers are useful when batching nested data with
AcadosDiffMpcCtx objects inside, for example to reuse single-sample contexts
as one batched warm start.
For a full user-facing example, see
notebooks/getting_started/07_imitation_learning.py.
Attributes¶
PyTorch-style |
Functions¶
Collate a batch of single-sample contexts into one batched context. |
|
|
Collate a batch with PyTorch defaults plus leap-c context support. |
Module Contents¶
- leap_c.utils.collate.collate_acados_diff_mpc_ctx(batch: collections.abc.Sequence[leap_c.diff_mpc.function.AcadosDiffMpcCtx], collate_fn_map: dict[str, collections.abc.Callable] | None = None) leap_c.diff_mpc.function.AcadosDiffMpcCtx[source]¶
Collate a batch of single-sample contexts into one batched context.
Stacks the iterate and solver input arrays along a new batch axis and concatenates statuses into a 1-D array.
logis set toNonesince per-sample logs do not merge meaningfully.- Parameters:
batch – Non-empty sequence of
AcadosDiffMpcCtxobjects, each holding a single-sample iterate and solver input.collate_fn_map – Optional PyTorch-style collate map. Accepted for protocol compatibility but unused.
- Returns:
A single
AcadosDiffMpcCtxwhoseiterate.N_batchequalslen(batch).
- leap_c.utils.collate.collate_torch(batch: collections.abc.Sequence[Any]) Any[source]¶
Collate a batch with PyTorch defaults plus leap-c context support.
This is a convenience function for PyTorch
DataLoaderinstances, replay buffers, or downstream training code that storesAcadosDiffMpcCtxvalues for batched warm starts. PyTorch handles tensors, numpy arrays, mappings, tuples, scalars, etc.; leap-c only adds the missing rule for MPC contexts.- Parameters:
batch – Sequence of samples to collate.
- Returns:
The PyTorch-collated batch.
- leap_c.utils.collate.LEAPC_COLLATE_FN_MAP¶
PyTorch-style
collate_fn_mapforAcadosDiffMpcCtx.Use this when an external batching utility accepts a custom collate map and may encounter
AcadosDiffMpcCtxobjects. If users only need to stack contexts directly, they can callcollate_acados_diff_mpc_ctx()instead.