Skip to content

Control v2 Cleanup - #313

Merged
MatthieuDarcy merged 9 commits into
control_v2from
control_v2-ml
Aug 13, 2026
Merged

Control v2 Cleanup#313
MatthieuDarcy merged 9 commits into
control_v2from
control_v2-ml

Conversation

@mattlevine22

@mattlevine22 mattlevine22 commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR hardens and cleans up the closed-loop control implementation introduced in control_v2. It clarifies simulator contracts and current limitations, fixes online-filter initialization and randomness handling, improves typing and documentation, and adds focused coverage without changing the MPPI algorithm.

(heavy use of codex, but reviewed and iterated most things and culled a lot of the big changes it made to code + docs)

Key changes relative to control_v2

  • Requires controlled simulation to use filter_source="cuthbert" and raises a clear error for unsupported backends.
  • Gives the initial online filter update a valid preceding time, preventing degenerate zero-duration transitions and possible NaNs in time-scaled dynamics.
  • Separates environment and filter PRNG streams and honors filter_config.crn_seed.
  • Makes initial_policy_state an explicit Simulator.simulate argument.
  • Rejects ctrl_times and ctrl_values when controls are computed online.
  • Validates that a policy returns one control vector with the model’s declared control dimension.
  • Explicitly rejects plated controlled simulation; n_simulations > 1 also remains unsupported.
  • Improves type annotations, variable names, and docstrings around the controlled simulator and one-step Cuthbert filtering.
  • Moves the extensive control-loop explanation into dedicated API documentation and adds the control tutorials and API page to the documentation navigation.
  • Corrects control tutorial imports, equations, terminology, and typographical errors.
  • Keeps MPPI’s implementation and dsx.simulate rollout semantics unchanged, while correcting inaccurate documentation about its formulation, differentiable fields, and dt default.
  • Removes obsolete commented-out tests and adds focused coverage for handler routing, policy output shape, and unsupported plated execution.

@mattlevine22
mattlevine22 changed the base branch from main to control_v2 August 12, 2026 04:52
@mattlevine22
mattlevine22 requested review from MatthieuDarcy and removed request for MatthieuDarcy August 12, 2026 05:04
@mattlevine22 mattlevine22 changed the title Control v2 ml Control v2 Cleanup Aug 12, 2026
@mattlevine22
mattlevine22 marked this pull request as ready for review August 12, 2026 05:08
@mattlevine22 mattlevine22 mentioned this pull request Aug 12, 2026
Controlled simulation currently supports one trajectory at a time. Its online
filter update is implemented with Cuthbert and supports `KFConfig`, `EKFConfig`,
`EnKFConfig`, and `PFConfig`. `dsx.plate` and `n_simulations > 1` are rejected
explicitly. Controlled simulation requires `filter_source="cuthbert"` and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding this, I added a draft PR #314 to illustrate some of the issues and limitations with using the CD-dynamax backend. Not a serious proposal, more of an illustration of some of current limitations

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! Another way to deal with that is to update CD-Dynamax to expose lower-level predict/update steps.

And then integrate them into a unifying mid-level Dynestyx Filter object (#295 )

@MatthieuDarcy MatthieuDarcy Aug 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the correct approach, it probably would be useful for other projects as well. I can take a look at it soonish.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't prioritize the CD-Dynamax side too heavily, because once #299 lands (better discretizers), we will be able to use those w/ Cuthbert filters to get most of the CD-Dynamax features.

But indeed, setting up #295 will be generally very useful for many other projects---I think a great direction to get us up to cutting-edge would be to implement/learn "enhanced filters" this way.

Comment thread dynestyx/control/mppi.py Outdated
Comment thread dynestyx/control/mppi.py Outdated
Comment thread mkdocs.yml
- Quick Example L63: quick_example.ipynb
- SDEs with Non-Gaussian Observations: tutorials/sde_non_gaussian_observations.ipynb
- Closed-loop Control:
- Controller basics: tutorials/control/controller_demo.ipynb

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be worth it to add the basic tutorial into the gentle introduction?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make that a separate PR so we can have a chance to look more carefully at the "pedagogy" and make sure it is as simple and clear as possible?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! I think it would be very nice to have a basic example of online control in the intro tutorial

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened issue #316 for this.

@MatthieuDarcy MatthieuDarcy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good, I focused on understanding substantial changes to the code, but the documentation is much improved, thanks Matt!

Comment thread docs/api_reference/public/control.md

@DanWaxman DanWaxman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks mostly there to me, a few small nits

Comment thread dynestyx/control/discrete_controller_simulators.py

`u` is the control that drove the transition into the state being filtered:
$u_k$ for the transition from $x_k$ to $x_{k+1}$ and observation
$y_{k+1}$. For a bootstrap update (`prev_state=None`), `t_prev` must still

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry what is bootstrapping here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is just how to start with prev_state=None; this was @MatthieuDarcy 's wording, perhaps through Claude haha. I had codex re-word this stuff...

@MatthieuDarcy could you double check its explanation? my brain is a bit split

Comment thread dynestyx/simulation/auto.py
@mattlevine22
mattlevine22 requested a review from DanWaxman August 13, 2026 21:12
@MatthieuDarcy
MatthieuDarcy merged commit e6bf79d into main Aug 13, 2026
3 checks passed
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.

3 participants