Skip to content

Commit f547ec0

Browse files
authored
Merge pull request #270 from control-toolbox/migration
migrate to CTBase
2 parents e08eba4 + 5e62d16 commit f547ec0

158 files changed

Lines changed: 2229 additions & 2361 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/CI.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ on:
1010
jobs:
1111
call:
1212
uses: control-toolbox/CTActions/.github/workflows/ci.yml@main
13+
with:
14+
runs_on: '["ubuntu-latest","macos-latest"]'
15+
use_ct_registry: true
16+
secrets:
17+
SSH_KEY: ${{ secrets.SSH_KEY }}

Project.toml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
name = "CTModels"
22
uuid = "34c4fa32-2049-4079-8329-de33c2a22e2d"
3-
version = "0.7.1-beta"
3+
version = "0.8.0-beta"
44
authors = ["Olivier Cots <olivier.cots@toulouse-inp.fr>"]
55

66
[deps]
7-
ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a"
87
CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"
98
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
10-
ExaModels = "1037b233-b668-4ce9-9b63-f9f681f55dd2"
119
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
12-
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
1310
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1411
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
1512
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
16-
NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6"
1713
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1814
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
1915
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
20-
SolverCore = "ff4d7338-4cf1-434d-91df-b86cb86fb843"
2116

2217
[weakdeps]
2318
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
2419
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
25-
MadNLP = "2621e9c9-9eb4-46b1-8089-e8c72242dfb6"
2620
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
2721

2822
[extensions]
2923
CTModelsJLD = "JLD2"
3024
CTModelsJSON = "JSON3"
31-
CTModelsMadNLP = "MadNLP"
3225
CTModelsPlots = "Plots"
3326

3427
[extras]
@@ -41,32 +34,25 @@ test = [
4134
"Aqua",
4235
"JLD2",
4336
"JSON3",
44-
"MadNLP",
4537
"Plots",
4638
"Random",
4739
"Test"
4840
]
4941

5042
[compat]
51-
ADNLPModels = "0.8"
5243
Aqua = "0.8"
53-
CTBase = "0.16, 0.17"
44+
CTBase = "0.18"
5445
DocStringExtensions = "0.9"
55-
ExaModels = "0.9"
5646
Interpolations = "0.16"
5747
JLD2 = "0.6"
5848
JSON3 = "1"
59-
KernelAbstractions = "0.9"
6049
LinearAlgebra = "1"
61-
MadNLP = "0.8"
6250
MLStyle = "0.4"
6351
MacroTools = "0.5"
64-
NLPModels = "0.21"
6552
OrderedCollections = "1"
6653
Parameters = "0.12"
6754
Plots = "1"
6855
Random = "1"
6956
RecipesBase = "1"
70-
SolverCore = "0.3"
7157
Test = "1"
72-
julia = "1.10"
58+
julia = "1.10"

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ MarkdownAST = "d0879d2d-cac2-40c8-9cee-1863dc0c7391"
77
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
88

99
[compat]
10-
CTBase = "0.17"
10+
CTBase = "0.18"
1111
Documenter = "1"
1212
JLD2 = "0.6"
1313
JSON3 = "1"

docs/api_reference.jl

Lines changed: 195 additions & 345 deletions
Large diffs are not rendered by default.

docs/make.jl

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Documenter
22
using CTModels
3-
using CTBase # For automatic_reference_documentation
3+
using CTBase
44
using Plots
55
using JSON3
66
using JLD2
@@ -20,12 +20,10 @@ const CTModelsJSON = Base.get_extension(CTModels, :CTModelsJSON)
2020
const CTModelsJLD = Base.get_extension(CTModels, :CTModelsJLD)
2121
const DocumenterReference = Base.get_extension(CTBase, :DocumenterReference)
2222

23-
# Reset DocumenterReference configuration for proper local/remote link generation
2423
if !isnothing(DocumenterReference)
2524
DocumenterReference.reset_config!()
2625
end
2726

28-
# to add docstrings from external packages
2927
Modules = [Plots, CTModelsPlots, CTModelsJSON, CTModelsJLD]
3028
for Module in Modules
3129
isnothing(DocMeta.getdocmeta(Module, :DocTestSetup)) &&
@@ -48,61 +46,20 @@ include("api_reference.jl")
4846
with_api_reference(src_dir, ext_dir) do api_pages
4947
makedocs(;
5048
draft=draft,
51-
remotes=nothing, # Disable remote links. Needed for DocumenterReference
52-
warnonly=true,
49+
remotes=nothing,
50+
warnonly=[:cross_references],
5351
sitename="CTModels.jl",
5452
format=Documenter.HTML(;
5553
repolink="https://" * repo_url,
5654
prettyurls=false,
57-
#size_threshold_ignore=["api.md", "dev.md"],
58-
#size_threshold=300_000, # 300 KiB threshold
5955
assets=[
6056
asset("https://control-toolbox.org/assets/css/documentation.css"),
6157
asset("https://control-toolbox.org/assets/js/documentation.js"),
6258
],
6359
),
64-
checkdocs=:none,
6560
pages=[
6661
"Introduction" => "index.md",
67-
"User Guide" => [
68-
"Defining Problems" => "interfaces/optimization_problems.md",
69-
"Building Solutions" => "interfaces/ocp_solution_builders.md",
70-
],
71-
"Developer Guide" => [
72-
"Tutorials" => [
73-
"Creating a Strategy" => "tutorials/creating_a_strategy.md",
74-
"Creating a Strategy Family" => "tutorials/creating_a_strategy_family.md",
75-
],
76-
"Interfaces" => [
77-
"Strategies" => "interfaces/strategies.md",
78-
"Strategy Families" => "interfaces/strategy_families.md",
79-
"Orchestration & Routing" => "interfaces/orchestration.md",
80-
"Optimization Modelers" => "interfaces/optimization_modelers.md",
81-
],
82-
"Examples" => [
83-
"Simple Strategy" => "examples/simple_strategy.md",
84-
"Strategy with Options" => "examples/strategy_with_options.md",
85-
"Strategy Family" => "examples/strategy_family.md",
86-
"Option Routing" => "examples/routing_example.md",
87-
"Integration Example" => "examples/integration_example.md",
88-
"Migration Example" => "examples/migration_example.md",
89-
],
90-
],
91-
"API Reference" => [
92-
"Public API" => [
93-
"Options" => "options/options_public.md",
94-
"Strategies (Contract)" => "strategies/strategies_contract_public.md",
95-
"Strategies (API)" => "strategies/strategies_api_public.md",
96-
"Orchestration" => "orchestration/orchestration_public.md",
97-
],
98-
"Internal API" => [
99-
"Options (Internal)" => "options/options_internal.md",
100-
"Strategies Contract (Internal)" => "strategies/strategies_contract_internal.md",
101-
"Strategies API (Internal)" => "strategies/strategies_api_internal.md",
102-
"Orchestration (Internal)" => "orchestration/orchestration_internal.md",
103-
],
104-
"Core & OCP" => api_pages,
105-
],
62+
"API Reference" => api_pages,
10663
],
10764
)
10865
end

docs/src/index.md

Lines changed: 57 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ It provides the **mathematical model layer** for optimal control problems:
99

1010
- **types and building blocks** for states, controls, variables, time grids, and constraints;
1111
- an `AbstractModel`/`Model` and `AbstractSolution`/`Solution` hierarchy for optimal control problems;
12-
- tools to build **initial guesses**, connect to **NLP backends**, and interpret their solutions;
13-
- optional extensions for **exporting solutions** (JSON/JLD) and **plotting**.
12+
- tools to build **initial guesses** for optimization;
13+
- optional extensions for **exporting/importing solutions** (JSON/JLD) and **plotting**.
14+
15+
!!! info "CTModels vs CTSolvers"
16+
17+
**CTModels** focuses on **defining** optimal control problems and representing their solutions.
18+
For **solving** these problems (discretization, NLP backends, optimization strategies),
19+
see [CTSolvers.jl](https://github.com/control-toolbox/CTSolvers.jl).
1420

1521
!!! note
1622

@@ -64,25 +70,11 @@ At a high level, CTModels is responsible for:
6470
`AbstractSolution` / `Solution` store state, control, dual variables, and solver information.
6571
- **Managing time grids and dimensions** through convenient type aliases.
6672
- **Structuring constraints** (path, boundary, box constraints on state, control, and variables).
67-
- **Connecting to NLP backends** (ADNLPModels, ExaModels, etc.) via modelers and builders.
68-
- **Strategy architecture** (NEW):
69-
- **Options**: Generic option handling with aliases and validation
70-
- **Strategies**: Configurable components (modelers, solvers, discretizers)
7173
- **Providing utilities** for initial guesses, export/import, and plotting of solutions.
7274

7375
Most of the public API is organized in a way that closely mirrors the mathematical
7476
objects you manipulate when formulating an optimal control problem.
7577

76-
## Strategy Architecture
77-
78-
CTModels provides a modern, type-stable architecture for configurable components:
79-
80-
- **Options Module**: Low-level option extraction, validation, and alias resolution.
81-
- **Strategies Module**: Strategy contract, metadata, registry, and builders.
82-
83-
This architecture replaces the legacy `AbstractOCPTool` interface with a cleaner,
84-
more maintainable design. See the **Developer Guide → Interfaces → Strategies** section for details.
85-
8678
## Time grids and basic aliases
8779

8880
CTModels defines a few central type aliases that appear throughout the API:
@@ -121,37 +113,30 @@ These objects are the main bridge between the mathematical problem and the NLP b
121113
## Initial guesses
122114

123115
Good initial guesses are crucial for challenging optimal control problems.
124-
CTModels provides a small layer to organize them:
116+
CTModels provides a layer to organize them:
125117

126118
- `pre_initial_guess` builds an `OptimalControlPreInit` object from raw user data
127119
(functions, vectors, or constants for state, control, and variables).
128120
- `initial_guess` turns this into an `OptimalControlInitialGuess`, checking consistency
129-
with the chosen `AbstractOptimalControlProblem`.
130-
131-
The corresponding API is implemented in `src/init/initial_guess.jl` and is documented
132-
in the *Initial Guess* section of the API reference.
133-
134-
## NLP backends and modelers
135-
136-
CTModels does **not** solve the NLP itself. Instead, it connects to external NLP
137-
backends via modelers and builders defined in `src/nlp/`:
121+
with the chosen `AbstractModel`.
122+
- `build_initial_guess` constructs initial guess objects from various input formats.
123+
- `validate_initial_guess` ensures consistency with the problem dimensions.
138124

139-
- `ADNLPModeler` (based on `ADNLPModels.jl`),
140-
- `ExaModeler` (based on `ExaModels.jl`),
141-
- additional builder types and helper functions.
125+
The corresponding API is documented in the *InitialGuess* section of the API reference.
142126

143-
These modelers:
127+
## Solving optimal control problems
144128

145-
- expose options through the generic `AbstractOCPTool` interface from CTBase
146-
(see the *Interfaces → OCP Tools* page),
147-
- build backend-specific NLP models from an `AbstractOptimizationProblem`,
148-
- optionally map NLP solutions back to `CTModels.Solution` objects.
129+
CTModels defines the **problem structure** but does **not** solve it.
130+
For solving optimal control problems, use [CTSolvers.jl](https://github.com/control-toolbox/CTSolvers.jl),
131+
which provides:
149132

150-
The *Interfaces* section of the documentation contains detailed guides for:
133+
- **Discretization strategies** (direct collocation, multiple shooting, etc.)
134+
- **NLP backends** (ADNLPModels, ExaModels, etc.)
135+
- **Optimization modelers** to connect problems to solvers
136+
- **Strategy architecture** for configurable components
151137

152-
- implementing new **optimization problems**,
153-
- implementing new **optimization modelers**, and
154-
- implementing new **OCP solution builders**.
138+
CTModels provides the `AbstractModel` type alias `AbstractOptimalControlProblem`
139+
for compatibility with CTSolvers.
155140

156141
## Extensions: JSON, JLD, and plotting
157142

@@ -183,56 +168,37 @@ throw a descriptive `CTBase.ExtensionError`.
183168

184169
## How this documentation is organized
185170

186-
The documentation is split into two main parts:
187-
188-
- **Interfaces**
189-
- *OCP Tools*: how to implement new configurable tools (backends, discretizers, solvers).
190-
- *Optimization Problems*: how to define `AbstractOptimizationProblem` types.
191-
- *Optimization Modelers*: how to map optimization problems to specific NLP backends.
192-
- *Solution Builders*: how to turn NLP execution statistics into `CTModels.Solution` objects.
193-
194-
- **API Reference**
195-
- *Types*: core types for models, solutions, and internal structures.
196-
- *Model / Times / Dynamics / Objective / Constraints*: detailed API for building OCP models.
197-
- *Solution & Dual*: how solutions and dual variables are represented.
198-
- *Initial Guess*: utilities to build and validate initial guesses.
199-
- *NLP Backends*: ADNLPModels/ExaModels-based backends and related options.
200-
- *Extensions*: Plot, JSON, and JLD extensions.
201-
202-
You can start by reading the **Interfaces** pages to understand the high-level
203-
design, then use the **API Reference** to look up the details of particular
204-
functions and types.
205-
206-
## I am X, I want to do Y → read…
207-
208-
### User Guide
209-
210-
- **I want to formulate a new optimal control / optimization problem**
211-
Read **User Guide → Optimization Problems**, then **API Reference → Model / Times / Dynamics / Objective / Constraints**
212-
for details about fields and conventions.
213-
- **I want to build good initial guesses for my problems**
214-
Read **User Guide → Solution Builders** for the overall philosophy, then **API Reference → Initial Guess**
215-
for the `pre_initial_guess` and `initial_guess` functions.
216-
- **I want to save / reload solutions (for example for numerical experiments)**
217-
Read **API Reference → Extensions (JSON & JLD)** and the pages associated with the `CTModelsJSON` and `CTModelsJLD` modules.
218-
- **I want to plot solution trajectories nicely**
219-
Read **API Reference → Extensions (Plot Extension)**, and look at the examples using `Plots.plot(sol)` and `Plots.plot!(sol)`.
220-
- **I use OptimalControl.jl and I just want to understand what CTModels does in the background**
221-
Read this introduction page, then skim through the **User Guide** section to see how
222-
problems, modelers, and builders fit together.
223-
224-
### Developer Guide
225-
226-
- **I want to create a new strategy (modeler, solver, discretizer)**
227-
Read **Developer Guide → Tutorials → Creating a Strategy**, then **Developer Guide → Interfaces → Strategies**
228-
for the complete contract specification.
229-
- **I want to create a family of related strategies**
230-
Read **Developer Guide → Tutorials → Creating a Strategy Family**, then **Developer Guide → Interfaces → Strategy Families**
231-
for registry integration and best practices.
232-
- **I want to migrate from AbstractOCPTool to AbstractStrategy**
233-
Read **Developer Guide → Interfaces → Strategies → Migration Guide** for step-by-step instructions.
234-
- **I want to connect a new NLP backend or tweak an existing backend**
235-
Read **Developer Guide → Interfaces → Optimization Modelers** (updated) and the **API Reference → NLP Backends** section.
236-
- **I want to contribute to the core of CTModels (types, constraints, dual variables, etc.)**
237-
Start with **API Reference → Types**, then **Solution & Dual** and **Constraints** to understand the internal structures
238-
before modifying or adding new fields.
171+
The documentation consists of:
172+
173+
- **Introduction** (this page): Overview of CTModels and its role in the control-toolbox ecosystem.
174+
175+
- **API Reference**: Complete documentation of all modules and functions:
176+
- *CTModels*: Main module and exports
177+
- *Utils*: Utilities (interpolation, macros, matrix operations)
178+
- *OCP*: Optimal Control Problem types, components, building, and validation
179+
- *Display*: Text display and printing
180+
- *Serialization*: Export/import functionality
181+
- *InitialGuess*: Initial guess management
182+
- *Extensions*: Plots, JSON, and JLD2 extensions
183+
184+
Use the **API Reference** to look up the details of particular functions and types.
185+
186+
## Quick start guide
187+
188+
- **I want to define an optimal control problem**
189+
See **API Reference → OCP Components** for `state!`, `control!`, `dynamics!`, `objective!`, `constraint!`, etc.
190+
191+
- **I want to build initial guesses**
192+
See **API Reference → InitialGuess** for `pre_initial_guess`, `initial_guess`, and `build_initial_guess`.
193+
194+
- **I want to save/load solutions**
195+
See **API Reference → Serialization** and the JSON/JLD2 extension pages for `export_ocp_solution` and `import_ocp_solution`.
196+
197+
- **I want to plot solution trajectories**
198+
See **API Reference → Plots Extension** for `plot(sol)` and `plot!(sol)` with `Plots.jl`.
199+
200+
- **I want to solve an optimal control problem**
201+
Use [CTSolvers.jl](https://github.com/control-toolbox/CTSolvers.jl) which provides discretization, NLP backends, and optimization strategies.
202+
203+
- **I use OptimalControl.jl**
204+
CTModels provides the underlying types and building blocks. OptimalControl.jl offers a higher-level interface.

ext/CTModelsPlots.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using MLStyle: MLStyle
66

77
#
88
using CTBase
9+
using CTBase: Exceptions
910
using CTModels
1011
using LinearAlgebra
1112
using Plots # redefine plot, plot!
@@ -16,4 +17,6 @@ include("plot_utils.jl")
1617
include("plot_default.jl")
1718
include("plot.jl")
1819

20+
export plot, plot!
21+
1922
end

0 commit comments

Comments
 (0)