Skip to content

Fixed MPPI - #348

Open
MatthieuDarcy wants to merge 11 commits into
md-control-alignmentfrom
md-mppi-fix
Open

Fixed MPPI#348
MatthieuDarcy wants to merge 11 commits into
md-control-alignmentfrom
md-mppi-fix

Conversation

@MatthieuDarcy

@MatthieuDarcy MatthieuDarcy commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Solves part of #337 .

MPPI now uses the previous_transition convention from dsx.simulate directly.

The implementation is now mathematically correct: it does not duplicate controls.

The initial state $x_0$ or the initial observation $y_0$ are not present in the SimulatedResult fieldsstates and observations, which will avoid a user using them in their loss accidentally. The initial condition $x_0$ is available through res.x_0. This is intuitive from a user perspective (you basically never want to use the initial condition in your loss), but differs from the usual contract, I don't know if its a good idea.

Add observation_control_alignment for discrete-time Simulator (#312)

Add an explicit observation_control_alignment: Literal["same_time",
"previous_transition"] field to DynamicalModel, defaulting to "same_time"
(today's behavior, unchanged). "previous_transition" pairs y_{k+1} with u_k
(the control that produced x_{k+1}) instead of pairing y_k with u_k, matching
DiscreteControlLoopSimulator's existing closed-loop convention and avoiding
the acausal y_0-depends-on-u_0 coupling.

For "previous_transition", DiscreteTimeSimulator/dsx.simulate never samples
y_0 and excludes x_0/t_0 from the returned SimulatedResult -- states,
observations, times, and the caller's ctrl_values all end up the same length,
with no padding or off-by-one bookkeeping required.

Scope: the plain Simulator/DiscreteTimeSimulator/dsx.simulate generation path
only. mppi.py and discrete_controller_simulators.py are unchanged, deferred
to a follow-up.
Include x_0 in all results; add controls to SimulatedResult

For observation_control_alignment="previous_transition", the result now keeps
x_0 and the full times/states path (length T), matching "same_time". Only
observations stay one shorter (y_1..y_{T-1}, length T-1) since y_0 is never
sampled -- so states[k+1] pairs with observations[k].

Add a controls field to SimulatedResult carrying the aligned ctrl_values used
(length T for same_time, T-1 for previous_transition; None when uncontrolled).

Also drop the bespoke _sample_discrete_observation_path in favor of calling
_emit_observations directly with sliced states/times, and fix
_sample_observation_path to vmap over arrays rather than indexing by a scanned
integer, which crashed on zero-length observation paths.
Simplified docstring
MPPI now uses the `previous_transition` convention from `dsx.simulate` directly.

The implementation is now mathemaitcally  correct: it does not duplicate control.

The initial state $x_0$ or the initial observation $y_0$ are not present in the `SimulatedResult` `states` and `observations` but $x_0$ is available through `res.x_0`.
MPPI now uses the `previous_transition` convention from `dsx.simulate` directly.

The implementation is now mathemaitcally  correct: it does not duplicate control.

The initial state $x_0$ or the initial observation $y_0$ are not present in the `SimulatedResult` `states` and `observations` but $x_0$ is available through `res.x_0`.
@MatthieuDarcy

Copy link
Copy Markdown
Contributor Author

Now uses vmap directly over SimulatedResult thanks to #350

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant