Skip to content

feat: ControlLaw, PseudoHamiltonian, feedback trait, and pseudo-Hamiltonian AD contracts#472

Merged
ocots merged 6 commits into
mainfrom
feat/pseudo-hamiltonian-and-control-law
Jul 4, 2026
Merged

feat: ControlLaw, PseudoHamiltonian, feedback trait, and pseudo-Hamiltonian AD contracts#472
ocots merged 6 commits into
mainfrom
feat/pseudo-hamiltonian-and-control-law

Conversation

@ocots

@ocots ocots commented Jul 4, 2026

Copy link
Copy Markdown
Member

Summary

Implements Part A of the dynamic closed-loop plan: feedback trait, ControlLaw, PseudoHamiltonian, and pseudo-Hamiltonian AD contracts.

Changes

Feedback trait (src/Traits/feedback.jl)

  • AbstractFeedback with concrete subtypes: OpenLoopFeedback, ClosedLoopFeedback, DynClosedLoopFeedback
  • Type-parameter-only pattern (no guard functions)
  • Trait accessors: feedback, is_open_loop, is_closed_loop, is_dyn_closed_loop

ControlLaw (src/Data/abstract_control_law.jl, src/Data/control_law.jl)

  • AbstractControlLaw{FB, TD, VD} with feedback, time-dependence, variable-dependence traits
  • ControlLaw struct with user-facing constructors: OpenLoop, ClosedLoop, DynClosedLoop
  • Natural and feedback-dependent uniform call signatures:
    • OpenLoop: uniform u(t, v) — no state, no costate (open-loop by definition)
    • ClosedLoop: uniform u(t, x, v) — state but no costate (controlled dynamics flow)
    • DynClosedLoop: uniform u(t, x, p, v) — state and costate (Hamiltonian flow)

PseudoHamiltonian (src/Data/abstract_pseudo_hamiltonian.jl, src/Data/pseudo_hamiltonian.jl)

  • AbstractPseudoHamiltonian{TD, VD} with time and variable dependence traits
  • PseudoHamiltonian struct with explicit control argument u
  • Natural and uniform call signatures (t, x, p, u, v)

AD contracts (src/Differentiation/abstract_ad_backend.jl, ext/CTBaseDifferentiationInterface.jl)

  • pseudo_hamiltonian_gradient → returns (∂H̃/∂x, ∂H̃/∂p) — for the Hamiltonian flow
  • pseudo_hamiltonian_control_gradient → returns ∂H̃/∂u — for PMP stationarity checks
  • Split justified by: along a PMP solution, ∂H̃/∂u = 0, so the flow only needs (∂H̃/∂x, ∂H̃/∂p)

Helpers (src/Data/helpers.jl)

  • _fb_label, _natural_sig_cl, _natural_args_cl, _uniform_sig_cl — all dispatch-based (no if statements)
  • _natural_sig_ph, _uniform_sig_ph for PseudoHamiltonian

Tests

  • test/suite/traits/test_feedback.jl — feedback trait tests
  • test/suite/data/test_control_law.jl — construction, call signatures, type stability, subtyping
  • test/suite/data/test_pseudo_hamiltonian.jl — construction, call signatures, type stability
  • test/suite/differentiation/test_pseudo_hamiltonian_gradient.jl — AD contracts (both functions)
  • Updated test_data_module.jl and test_differentiation_module.jl for new exports

Test results

All 4256 tests pass.

…amiltonian AD contracts

Add feedback trait hierarchy (OpenLoopFeedback, ClosedLoopFeedback,
DynClosedLoopFeedback) using the type-parameter-only pattern.

Implement AbstractControlLaw and ControlLaw with feedback, time-dependence,
and variable-dependence traits. Provide OpenLoop, ClosedLoop, DynClosedLoop
constructors. Natural and uniform call signatures are feedback-dependent:
- OpenLoop: uniform u(t, v) — no state, no costate
- ClosedLoop: uniform u(t, x, v) — state but no costate
- DynClosedLoop: uniform u(t, x, p, v) — state and costate

Implement AbstractPseudoHamiltonian and PseudoHamiltonian with time and
variable dependence traits and explicit control argument u. Natural and
uniform call signatures (t, x, p, u, v).

Implement two AD contracts:
- pseudo_hamiltonian_gradient: returns (∂H̃/∂x, ∂H̃/∂p) for the Hamiltonian flow
- pseudo_hamiltonian_control_gradient: returns ∂H̃/∂u for stationarity checks

Split justified by PMP stationarity condition ∂H̃/∂u = 0 along solutions.

Add comprehensive unit tests for traits, construction, call signatures,
type stability, subtyping, and AD contracts.
@ocots ocots added the run ci Trigger CI label Jul 4, 2026
Add feedback.jl to Traits module config.
Add abstract_control_law.jl, control_law.jl, abstract_pseudo_hamiltonian.jl,
pseudo_hamiltonian.jl to Data module config.

Without these entries, the new types and functions would not appear in
the generated API reference documentation.
@ocots ocots removed the run ci Trigger CI label Jul 4, 2026
ocots added 4 commits July 4, 2026 22:19
Fix Documenter cross-reference warnings by qualifying all unqualified
@ref links with their full module paths (CTBase.Traits.*, CTBase.Data.*,
CTBase.Differentiation.*, CTBaseDifferentiationInterface.*).

Unqualified links like [`AbstractFeedback`](@ref) could not be resolved
by Documenter when the docstring was rendered in a different module
context (e.g. Data docs referencing Traits symbols).
- Convert # See also sections to See also: inline lines (feedback.jl)
- Add # Returns sections to trait accessors and predicates
- Add # Arguments sections to time_dependence/variable_dependence accessors
- Add # Arguments/# Output to Base.show methods
- Add # Arguments/# Returns to typed constructors
- Add descriptive sentence to MIME text/plain show methods

Follows the control-toolbox Handbook docstring template:
https://github.com/control-toolbox/Handbook/blob/main/philosophy/docstrings.md
- traits.md: add Feedback trait family section (AbstractFeedback,
  OpenLoopFeedback, ClosedLoopFeedback, DynClosedLoopFeedback) with
  type-parameter-only contract note, predicates, and dynamics trait mapping;
  add Feedback to Other families table and accessor/predicate summary
- data.md: add PseudoHamiltonian section (construction, calling, dynamics
  trait); add ControlLaw section (OpenLoop/ClosedLoop/DynClosedLoop
  constructors, call signatures, feedback→dynamics mapping); update overview
  table, typed constructors, and See also
- differentiation.md: update contract count to nine methods; add
  pseudo_hamiltonian_gradient and pseudo_hamiltonian_control_gradient section
  with examples; update extension note and See also
Update CHANGELOGS.md with new features (Feedback trait family,
PseudoHamiltonian, ControlLaw, pseudo-Hamiltonian gradient methods),
documentation, and testing entries. Add non-breaking note to BREAKINGS.md.
@ocots
ocots merged commit 6051f5d into main Jul 4, 2026
4 checks passed
@ocots
ocots deleted the feat/pseudo-hamiltonian-and-control-law branch July 4, 2026 20:31
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