refactor(DOCP): implement the CTSolvers dispatch contract#601
Draft
ocots wants to merge 5 commits into
Draft
Conversation
Move to the CTSolvers dispatch-based DOCP contract (no closures/builders):
- AbstractDiscretizer now owned by CTSolvers; remove the local abstract type
and the discretize wrappers; import Strategies/Options/Core/Exceptions from CTBase
- new DOCP_cache.jl: DOCPCache <: CTBase.Core.AbstractCache (docp + exa_getter),
making the build_model -> build_solution Exa coupling explicit (no captured closure)
- unify get_docp into DOCP_data.jl (shared by all discretizers; resolves the TODO)
- collocation.jl / direct_shooting.jl: replace the (discretizer)(ocp) closure factory
with named CTSolvers.discretize / build_model / build_solution methods dispatching
on (DiscretizedModel{<:Disc}, modeler). DirectShooting x Exa left to the
CTSolvers NotImplemented stub.
- Project.toml: CTBase moved to deps; bump compat (CTBase 0.25, CTModels 0.13,
ExaModels 0.11); docs project CTBase 0.25
- tests: CTDirect.discretize -> CTSolvers.discretize; manual-backend nnz test via
CTSolvers.build_model(docp, init, ADNLP(backend=:manual))
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
DOCPCache(docp) = DOCPCache(docp, nothing) inferred the field parameter E as Nothing, freezing exa_getter::Nothing — so build_model(::Exa)'s `dm.cache.exa_getter = exa_getter` threw "cannot convert a value to nothing". Drop the E type parameter and type the field as Any (the cache is created with nothing by discretize, then reassigned to a backend getter by build_model). With this fix the full CTDirect suite is green against the CTBase 0.25 / CTModels 0.13 / CTSolvers 0.4 stack (406 passed, incl. all ADNLP and Exa cases). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
ocots
marked this pull request as draft
June 27, 2026 09:54
DOCPCache becomes immutable (holds only the docp). The Exa getter, produced together with the ExaModel, now rides an ExaBuildCache carried by the CTSolvers.BuiltModel returned by build_model — no more mutation of the shared DiscretizedModel cache. - build_model returns CTSolvers.BuiltModel(dm, nlp, cache): NoCache for ADNLP / DirectShooting, ExaBuildCache(getter) for Exa. - build_solution dispatches on the BuiltModel; reads docp via built.problem.cache and the getter via built.cache (drops the nothing-check, guaranteed by the type). - test: use CTSolvers.nlp_model where a bare NLP is expected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Update compat: CTBase 0.28, CTModels 0.15, CTSolvers 0.4
- Add Strategies.parameter(::Type{<:Collocation}) = nothing
- Add Strategies.parameter(::Type{<:DirectShooting}) = nothing
- Add parameter contract for DummyDiscretizer in test
- Update docs/Project.toml CTBase compat to 0.28
- Add CTParser to [deps] (was only in [extras])
Co-Authored-By: Cascade <noreply@cascade.ai>
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.
Context
Companion to control-toolbox/CTSolvers.jl#155, which replaces the closure-factory / builder-accessor indirection with a direct multiple-dispatch DOCP contract (problem-first, no closures, no builders). This PR migrates CTDirect to that contract.
Previously,
(discretizer::Collocation)(ocp)built 4 closures wrapped into aDiscretizedModel{4 builders}, with a capturedexa_getter = nothingmutated as a side effect (temporal coupling). That is replaced by named methods dispatching on(DiscretizedModel{<:Discretizer}, modeler).Changes
Source
AbstractDiscretizeris now owned by CTSolvers; the local abstract type and thediscretizewrappers are removed. ImportsStrategies/Options/Core/Exceptionsfrom CTBase.DOCP_cache.jl:DOCPCache <: CTBase.Core.AbstractCache(docp+exa_getter), making thebuild_model → build_solutionExa coupling explicit (no captured closure).get_docpunified inDOCP_data.jl(shared by all discretizers; resolves the long-standing TODO).collocation.jl/direct_shooting.jl: closure factory → namedCTSolvers.discretize/build_model/build_solutionmethods.DirectShooting × Exais intentionally left to the CTSolversNotImplementedstub.Project / compat
CTBasemoved to[deps]; compat bumped to the new stack:CTBase 0.25,CTModels 0.13,ExaModels 0.11(+docs/Project.tomltoCTBase 0.25, required by the[workspace]).CTParserstays test-only ([extras]/[targets]), not in[deps].Tests
CTDirect.discretize→CTSolvers.discretize; the manual-backend nnz test builds viaCTSolvers.build_model(docp, init, ADNLP(backend=:manual)).Validation
Full suite green against the CTBase 0.25 / CTModels 0.13 / CTSolvers 0.4 stack: 406 passed, 0 failed, 0 errored — all ADNLP and Exa cases (collocation, all schemes, continuation, param estimation, zero-control, …).
DOCPCacheis amutable structand itsexa_getterfield is typedAnyso it can be reassigned after construction. A mutable cache is not ideal; thebuild_model → build_solutioncoupling (the Exa getter) would be cleaner handled some other way (recompute fromdm, immutable cache rebuilt, aRef, …). To revisit.Dependencies (merge order)
This PR depends on, and should land after:
CI here will stay red until CTSolvers 0.4.x and CTParser 0.8.16(+) are available from the registry. Locally validated with all four packages dev'd by path.
🤖 Generated with Claude Code