Skip to content

Define observation/control alignment for discrete-time models - #331

Open
MatthieuDarcy wants to merge 4 commits into
mainfrom
md-control-alignment
Open

Define observation/control alignment for discrete-time models#331
MatthieuDarcy wants to merge 4 commits into
mainfrom
md-control-alignment

Conversation

@MatthieuDarcy

@MatthieuDarcy MatthieuDarcy commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Add observation_control_alignment for discrete-time Simulator (#312).

Mathematical summary

Implements the same_time vs previous time distinction. same_time (default, preserves the existing behavior) implements:

$$ \begin{aligned} x_0 &\sim p_0 \\ y_0 &\sim p(\cdot |x_0, u_0) \end{aligned} $$

and subsequently

$$ \begin{aligned} x_{k+1} &\sim p(\cdot | x_k, u_k)\\ y_k &\sim p(\cdot| x_k, u_k) \end{aligned} $$

previous_time implements

$$ \begin{aligned} x_0 &\sim p_{0}\\ x_{k+1} &\sim p(\cdot | x_k, u_k) \\ y_{k+1} &\sim p(\cdot| x_{k+1}, u_k) \end{aligned} $$

Summary of changes

Adds an explicit property of DynamicalModel defined at initialization called observation_control_alignment: Literal[ "same_time", "previous_transition" ] = "same_time"

When defined as previous_transition, this results in the following behavior

  1. $y_0$ cannot be sampled. Hence observations $y$ is of size $T-1$ while the states $x$ are of size $T$.
  2. I added the controls $u$ in the returnedSimulatedResults. This is very practical when doing MPC. This leads to a similar behavior as observations: when using "same_time" it is of size $T$, when using "previous_time" it is of size $T-1$.

This means that states and times are of different sizes to controls and observations (specifically size $T$ vs $T-1$) when using previous_transition.

  1. MPPI is updated to use this convention in Fixed MPPI #348

Still to be done

  1. previous_transition only works for simulation, no conditioning and not filtering. Worth delegating to a seperate PR?

@MatthieuDarcy
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
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