Define observation/control alignment for discrete-time models - #331
Open
MatthieuDarcy wants to merge 4 commits into
Open
Define observation/control alignment for discrete-time models#331MatthieuDarcy wants to merge 4 commits into
MatthieuDarcy wants to merge 4 commits into
Conversation
MatthieuDarcy
marked this pull request as ready for review
August 31, 2026 19:09
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
MatthieuDarcy
force-pushed
the
md-control-alignment
branch
from
September 1, 2026 13:58
bdacde1 to
007bab7
Compare
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.
Add observation_control_alignment for discrete-time Simulator (#312).
Mathematical summary
Implements the
same_timevsprevious time distinction.same_time(default, preserves the existing behavior) implements:and subsequently
previous_timeimplementsSummary of changes
Adds an explicit property of
DynamicalModeldefined at initialization calledobservation_control_alignment: Literal[ "same_time", "previous_transition" ] = "same_time"When defined as
previous_transition, this results in the following behaviorSimulatedResults. This is very practical when doing MPC. This leads to a similar behavior as observations: when using "same_time" it is of sizeThis means that$T$ vs $T-1$ ) when using
statesandtimesare of different sizes tocontrolsandobservations(specifically sizeprevious_transition.Still to be done
previous_transitiononly works for simulation, no conditioning and not filtering. Worth delegating to a seperate PR?