feat: ControlLaw, PseudoHamiltonian, feedback trait, and pseudo-Hamiltonian AD contracts#472
Merged
Merged
Conversation
…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.
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.
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.
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.
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)AbstractFeedbackwith concrete subtypes:OpenLoopFeedback,ClosedLoopFeedback,DynClosedLoopFeedbackfeedback,is_open_loop,is_closed_loop,is_dyn_closed_loopControlLaw (
src/Data/abstract_control_law.jl,src/Data/control_law.jl)AbstractControlLaw{FB, TD, VD}with feedback, time-dependence, variable-dependence traitsControlLawstruct with user-facing constructors:OpenLoop,ClosedLoop,DynClosedLoopu(t, v)— no state, no costate (open-loop by definition)u(t, x, v)— state but no costate (controlled dynamics flow)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 traitsPseudoHamiltonianstruct with explicit control argumentu(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 flowpseudo_hamiltonian_control_gradient→ returns∂H̃/∂u— for PMP stationarity checks∂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 (noifstatements)_natural_sig_ph,_uniform_sig_phfor PseudoHamiltonianTests
test/suite/traits/test_feedback.jl— feedback trait teststest/suite/data/test_control_law.jl— construction, call signatures, type stability, subtypingtest/suite/data/test_pseudo_hamiltonian.jl— construction, call signatures, type stabilitytest/suite/differentiation/test_pseudo_hamiltonian_gradient.jl— AD contracts (both functions)test_data_module.jlandtest_differentiation_module.jlfor new exportsTest results
All 4256 tests pass.