Fixed MPPI - #348
Open
MatthieuDarcy wants to merge 11 commits into
Open
Conversation
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
force-pushed
the
md-mppi-fix
branch
from
September 1, 2026 13:58
2f7483b to
d7dd107
Compare
… into md-mppi-fix
MPPI now uses vmap over controls
Contributor
Author
|
Now uses |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Solves part of #337 .
MPPI now uses the
previous_transitionconvention fromdsx.simulatedirectly.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 $x_0$ is available through
SimulatedResultfieldsstatesandobservations, which will avoid a user using them in their loss accidentally. The initial conditionres.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.