refactor: immutable BuiltModel bundle replacing the mutable DOCP cache#157
Merged
Conversation
build_model now returns an immutable BuiltModel{problem, nlp, cache} consumed by
build_solution, eliminating the mutable backend cache (the Exa getter used to be
mutated into the shared DiscretizedModel). This also removes a latent bug where
two builds on the same DiscretizedModel could clobber each other's getter.
- Optimization: add BuiltModel + NoCache; build_solution dispatches on the bundle;
the orchestrator threads built.nlp into the solver. The solve(nlp, solver) stub
stays untyped (NLPModels weak dep).
- DOCP: nlp_model returns the bare NLP; ocp_solution realigned onto BuiltModel.
- Move extract_solver_infos from Optimization to Solvers (solver-side utility).
- KernelAbstractions promoted to a hard dep so the ExaModels extension triggers on
ExaModels alone (CTDirect needn't load KernelAbstractions); Aqua stale_deps
ignores it since the main module does not reference it.
- Tests: import ADNLPModels/ExaModels in each modeler-using test file so the
extensions trigger under per-file isolation; wrap fixtures in BuiltModel.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Documents the immutable BuiltModel refactor, the extract_solver_infos move to Solvers, and the KernelAbstractions return to a hard dependency. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Replaces the mutable backend cache in the DOCP flow with an immutable
BuiltModel.build_modelpreviously returned a bare NLP and (for the Exa backend) mutatedexa_getterinto the sharedDiscretizedModel.cacheso thatbuild_solutioncould reuse it. The getter is a co-product of building the model and cannot be
cheaply recomputed. This PR makes
build_modelreturn an immutable bundle thatcarries both the NLP and any build-time auxiliary, so nothing is mutated.
Changes
BuiltModel{problem, nlp, cache}+NoCache.build_modelreturns a
BuiltModel;build_solution(built, sol, modeler)dispatches on it.The orchestrator threads
built.nlpinto the solver; the mid-levelsolve(nlp, solver)stub stays untyped (NLPModels weak dep).nlp_modelreturns the bare NLP (build_model(...).nlp);ocp_solutionrealigned ontoBuiltModel.extract_solver_infosmoved here fromOptimization(solver-side utility).KernelAbstractionspromoted to a hard dep so theCTSolversExaModelsextension triggers on
ExaModelsalone (downstream packages such as CTDirectneedn't
using KernelAbstractions); Aquastale_depsignores it since the mainmodule does not reference it directly.
ADNLPModels/ExaModelsso theextensions trigger under per-file isolation; fixtures wrapped in
BuiltModel.Why it matters
build_modelcalls on the sameDiscretizedModelcould clobber each other's getter; a stale getter could survive an ADNLP build.
Companion
CTDirect adopts the same bundle (DOCPCache becomes immutable, getter rides an
ExaBuildCache) on itsrefactor/docp-dispatchbranch (PR #601).Tests
Full CTSolvers suite green (non-extension suites + extensions, ~3100 tests),
including Aqua.
🤖 Generated with Claude Code