Repository navigation
Public trait joins; AbstractConstrainedPseudoHamiltonian as an extension point - #667
Merged
Merged
Conversation
…dependence Traits.join_time_dependence and Traits.join_variable_dependence join one or more trait values (Autonomous / Fixed only if all are). They replace the private Data._join_td and Data._join_vd, so that CTModels and CTFlows can reuse them instead of re-implementing them (#666). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
Phase A — public trait joins (6dfefaf)APITraits.join_time_dependence(Traits.Autonomous, Traits.NonAutonomous) # NonAutonomous
Traits.join_variable_dependence(Traits.Fixed, Traits.Fixed, Traits.Fixed) # Fixed
Implementation
TestsThe tests are in
The existing tests of the composed types (traits joined) still pass, as non-regression. Checks
Next: phase B, |
freeze_multiplier and ComposedConstrainedHamiltonian accept any subtype of AbstractConstrainedPseudoHamiltonian that implements the call contract (natural and uniform calls), not only the concrete ConstrainedPseudoHamiltonian (TYP5), as Differentiation already does for the other abstract Hamiltonians. Contract tests with a top-level fake: values, traits, type stability and AD gradients equal to those of the concrete type (#666). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
Phase B —
|
| Signature | Before | Now |
|---|---|---|
freeze_multiplier(h, μ) |
h::ConstrainedPseudoHamiltonian |
h::AbstractConstrainedPseudoHamiltonian |
ComposedConstrainedHamiltonian(h, law, μ) |
h::ConstrainedPseudoHamiltonian |
h::AbstractConstrainedPseudoHamiltonian |
type parameter PH of ComposedConstrainedHamiltonian |
<:ConstrainedPseudoHamiltonian |
<:AbstractConstrainedPseudoHamiltonian |
- Why. These two functions only use the call contract of the abstract type: the natural call of its traits and the uniform call
(t, x, p, u, μ, v). A package can now subtypeAbstractConstrainedPseudoHamiltoniandirectly (TYP5), asDifferentiationalready allows forAbstractHamiltonianandAbstractPseudoHamiltonian. - Non-breaking. Only upper bounds are widened: every call that worked before still works and gives the same value.
- The private functor
_FrozenMultipliernow dispatches onAbstractConstrainedPseudoHamiltonian{TD,VD}.
Tests
A fake FakeConstrainedPH{TD,VD} <: AbstractConstrainedPseudoHamiltonian{TD,VD} sits at module top level (TST3). It is a callable struct that implements the natural and uniform calls, and nothing else.
- Contract,
freeze_multiplier:- the 4 TD×VD combinations: it returns a
PseudoHamiltonianwith the traits of the fake; - natural and uniform calls give the closed form;
@inferred.
- the 4 TD×VD combinations: it returns a
- Contract,
ComposedConstrainedHamiltonian:- the value is the same as with the concrete type for the same function;
- natural and uniform calls, getter,
@inferred; - the traits of the fake enter the join (
NonAutonomous,NonFixed).
- AD (
test_constrained_hamiltonian_gradient.jl): through the fake, the partial gradients (freeze_multiplier) and the total gradients (composed Hamiltonian) are equal to those through the concrete type. - Error:
freeze_multiplierstill rejects aPseudoHamiltonianand a plain function (MethodError). The existing rejections inComposedConstrainedHamiltonianare unchanged.
Checks
suite/dataandsuite/differentiation: 1198/1198.suite/meta: 73/74, with the sameCTBaseMooncakefailure as onmain(see phase A).- The touched files were formatted with JuliaFormatter (Blue style). This also re-wraps one line of phase A.
Next: phase C, with the docstrings, the guides (traits and data), CHANGELOG.md, the CHG4 note in BREAKING.md, the docs build and the full suite.
Docstrings of Traits.join_time_dependence and join_variable_dependence, the interface requirements of AbstractConstrainedPseudoHamiltonian, and the widened signatures. A "Joining traits" section in the Traits guide and an executed example of a custom subtype in the Data guide. CHANGELOG entries with the missing Compatibility footer, and a CHG4 note in BREAKING.md for the removed private helpers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
Phase C — docs, docstrings, changelog (56b01de)Docstrings (
|
…extension-trait-join # Conflicts: # BREAKING.md # CHANGELOG.md
ocots
marked this pull request as ready for review
November 24, 2026 17:11
ocots
added a commit
to control-toolbox/CTModels.jl
that referenced
this pull request
Nov 24, 2026
_stacked_multiplier joins the traits of the multipliers with CTBase.Traits.join_time_dependence and join_variable_dependence (control-toolbox/CTBase.jl#667) instead of private copies. [sources] points to CTBase main, where #663 and #667 are merged; the branch of #663 is deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 24, 2026
Closed
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.
Closes #666. Follow-up of #663, from the review in control-toolbox/CTModels.jl#536.
Conventions: ct-conventions v0.15.0, ct-agents v0.5.0.
Two changes to make before CTBase 0.30.15 is released, while the API is not public yet.
Phases
Traits.join_time_dependenceandTraits.join_variable_dependencereplace the privateData._join_tdandData._join_vd.AbstractConstrainedPseudoHamiltonianas an extension point:freeze_multiplierandComposedConstrainedHamiltonianaccept any subtype that implements the call contract (TYP5), asDifferentiationalready does forAbstractHamiltonianandAbstractPseudoHamiltonian.CHANGELOG.md,BREAKING.md(aCHG4note for the removed private helpers).Each phase is one commit with an explanatory comment.
Public API
Traits.join_time_dependenceandTraits.join_variable_dependence.freeze_multiplierandComposedConstrainedHamiltoniannow take anyAbstractConstrainedPseudoHamiltonian(phase B).Data._join_tdandData._join_vd. Nothing in the ecosystem uses them; I checked CTModels, CTFlows, CTDirect, CTSolvers, CTParser and OptimalControl.Out of scope
ComposedHamiltonian, toAbstractPseudoHamiltonian.🤖 Generated with Claude Code