Skip to content

Solving

CommonSolve.solve Method
julia
solve(
    ocp::CTModels.Models.AbstractModel,
    description::Symbol...;
    kwargs...
) -> CTModels.Solutions.Solution{TimeGridModelType, TimesModelType, StateModelType, ControlModelType, VariableModelType, ModelType, CostateModelType, Float64, DualModelType, CTModels.Solutions.SolverInfos{Any, Dict{Symbol, Any}}} where {TimeGridModelType<:CTModels.Solutions.AbstractTimeGridModel, TimesModelType<:CTModels.Components.AbstractTimesModel, StateModelType<:CTModels.Components.AbstractStateModel, ControlModelType<:CTModels.Components.AbstractControlModel, VariableModelType<:CTModels.Components.AbstractVariableModel, ModelType<:CTModels.Models.AbstractModel, CostateModelType<:Function, DualModelType<:CTModels.Solutions.AbstractDualModel}

Main entry point for optimal control problem resolution.

This function orchestrates the complete solve workflow by:

  • Detecting the resolution mode (explicit vs descriptive) from arguments

  • Extracting or creating the strategy registry for component completion

  • Dispatching to the appropriate Layer 2 solver based on the detected mode

Arguments

  • ocp::CTModels.AbstractModel: The optimal control problem to solve

  • description::Symbol...: Symbolic description tokens (e.g., :collocation, :adnlp, :ipopt)

  • kwargs...: All keyword arguments. Action options (initial_guess/init, display) are extracted by the appropriate Layer 2 function. Explicit components (discretizer, modeler, solver) are identified by abstract type. A registry keyword can be provided to override the default strategy registry.

Returns

  • CTModels.AbstractSolution: Solution to the optimal control problem

Examples

julia
# Descriptive mode (symbolic description)
solve(ocp, :collocation, :adnlp, :ipopt)

# With initial guess alias
solve(ocp, :collocation; init=x0, display=false)

# Explicit mode (typed components)
solve(ocp; discretizer=OptimalControl.Collocation(),
           modeler=OptimalControl.ADNLP(), solver=OptimalControl.Ipopt())

Throws

Notes

  • This is the main entry point (Layer 1) of the solve architecture

  • Mode detection determines whether to use explicit or descriptive resolution path

  • The registry can be injected for testing or customization purposes

  • Action options and strategy-specific options are handled by Layer 2 functions

See also: _explicit_or_descriptive, solve_explicit, solve_descriptive, get_strategy_registry

CommonSolve.solve Method
julia
solve(
    ocp::CTModels.Models.AbstractModel,
    initial_guess::CTModels.Init.AbstractInitialGuess,
    discretizer::CTSolvers.DOCP.AbstractDiscretizer,
    modeler::CTSolvers.Modelers.AbstractNLPModeler,
    solver::CTSolvers.Solvers.AbstractNLPSolver;
    display
)

Resolve an optimal control problem using fully specified, concrete components (Layer 3).

This is the lowest-level execution layer for solving an optimal control problem. It expects all components (initial guess, discretizer, modeler, and solver) to be fully instantiated and normalized. It discretizes the problem and passes it to the underlying solve pipeline.

Arguments

  • ocp::CTModels.AbstractModel: The optimal control problem to solve

  • initial_guess::CTModels.AbstractInitialGuess: Normalized initial guess for the solution

  • discretizer::CTSolvers.DOCP.AbstractDiscretizer: Concrete discretization strategy

  • modeler::CTSolvers.Modelers.AbstractNLPModeler: Concrete NLP modeling strategy

  • solver::CTSolvers.Solvers.AbstractNLPSolver: Concrete NLP solver strategy

  • display::Bool: Whether to display the OCP configuration before solving

Returns

  • CTModels.AbstractSolution: The solution to the optimal control problem

Example

julia
# Conceptual usage pattern for Layer 3 solve
ocp = Model(time=:final)
# ... define OCP ...
init = CTModels.build_initial_guess(ocp, nothing)
disc = OptimalControl.Collocation(grid_size=100)
mod  = OptimalControl.ADNLP()
sol  = OptimalControl.Ipopt()

solution = solve(ocp, init, disc, mod, sol; display=true)

Notes

  • This is Layer 3 of the solve architecture - all inputs must be concrete, fully specified types

  • No defaults, no normalization, no component completion occurs at this level

  • The function performs: (1) optional configuration display, (2) problem discretization, (3) NLP solving

  • This function is typically called by higher-level solvers (solve_explicit, solve_descriptive)

See also: solve_explicit, solve_descriptive

Base.methods Method
julia
methods() -> NTuple{12, NTuple{4, Symbol}}

Return the tuple of available method quadruplets for solving optimal control problems.

Each quadruplet consists of (discretizer_id, modeler_id, solver_id, parameter) where:

  • discretizer_id::Symbol: Discretization strategy identifier (e.g., :collocation)

  • modeler_id::Symbol: NLP modeling strategy identifier (e.g., :adnlp, :exa)

  • solver_id::Symbol: NLP solver identifier (e.g., :ipopt, :madnlp, :madncl, :knitro)

  • parameter::Symbol: Execution parameter (:cpu or :gpu)

Returns

  • Tuple{Vararg{Tuple{Symbol, Symbol, Symbol, Symbol&#125;&#125;}: Available method combinations

Examples

julia
julia> m = methods()
((:collocation, :adnlp, :ipopt, :cpu), (:collocation, :adnlp, :madnlp, :cpu), ...)

julia> length(m)
12  # 10 CPU methods + 2 GPU methods

julia> # CPU methods
julia> methods()[1]
(:collocation, :adnlp, :ipopt, :cpu)

julia> methods()[9]
(:collocation, :exa, :madncl, :cpu)

julia> # GPU methods
julia> methods()[11]
(:collocation, :exa, :madnlp, :gpu)

Notes

  • Returns a precomputed constant tuple (allocation-free, type-stable)

  • All methods currently use :collocation discretization

  • CPU methods (10 total): All combinations of {adnlp, exa} × {ipopt, madnlp, uno, madncl, knitro}

  • GPU methods (2 total): Only GPU-capable combinations exa × {madnlp, madncl}

  • GPU-capable strategies use parameterized types with automatic defaults

  • Used by CTBase.Descriptions.complete to complete partial method descriptions

See also: solve, CTBase.Descriptions.complete, get_strategy_registry

CTSolvers.DOCP.discretize Function
julia
discretize(
    ocp::CTModels.Models.AbstractModel,
    discretizer::CTSolvers.DOCP.AbstractDiscretizer
) -> CTSolvers.DOCP.DiscretizedModel{TO, CTDirect.Collocation, TC} where {TO<:CTModels.Models.AbstractModel, TC<:CTDirect.DOCPCache}

Discretize an optimal control problem into a CTSolvers.DOCP.DiscretizedModel.

Contract

Must be implemented in the package providing discretizer, dispatching on its concrete type, e.g. CTSolvers.discretize(ocp, ::Collocation) in CTDirect.

Arguments

  • ocp::CTModels.AbstractModel: The optimal control problem.

  • discretizer::AbstractDiscretizer: The discretization strategy.

Returns

See also: build_model, build_solution.

julia
discretize(
    ocp::CTModels.Models.AbstractModel,
    discretizer::CTDirect.Collocation
) -> CTSolvers.DOCP.DiscretizedModel{TO, CTDirect.Collocation, TC} where {TO<:CTModels.Models.AbstractModel, TC<:CTDirect.DOCPCache}

Discretize an OCP with the Collocation strategy into a CTSolvers.DiscretizedModel holding a DOCPCache with the precomputed DOCP.

julia
discretize(
    ocp::CTModels.Models.AbstractModel,
    discretizer::CTDirect.DirectShooting
) -> CTSolvers.DOCP.DiscretizedModel{TO, CTDirect.DirectShooting, TC} where {TO<:CTModels.Models.AbstractModel, TC<:CTDirect.DOCPCache}

Discretize an OCP with the DirectShooting strategy into a CTSolvers.DiscretizedModel holding a DOCPCache with the precomputed DOCP.

CTSolvers.DOCP.ocp_model Function
julia
ocp_model(
    docp::CTSolvers.DOCP.DiscretizedModel
) -> CTModels.Models.AbstractModel

Extract the original optimal control problem from a discretized problem.

Arguments

  • docp::DiscretizedModel: The discretized optimal control problem

Returns

  • The original optimal control problem

Example

julia
ocp = ocp_model(docp)

See also: DiscretizedModel

CTSolvers.DOCP.nlp_model Function
julia
nlp_model(
    prob::CTSolvers.DOCP.DiscretizedModel,
    initial_guess,
    modeler::CTSolvers.Modelers.AbstractNLPModeler
) -> Any

Build an NLP model from a discretized optimal control problem.

This is a convenience wrapper around build_model that returns only the backend NLP model (the nlp field of the CTSolvers.Optimization.BuiltModel). Use build_model directly when the build-time cache is needed (e.g. before build_solution).

Arguments

  • prob::DiscretizedModel: The discretized OCP

  • initial_guess: Initial guess for the NLP solver

  • modeler: The modeler to use (e.g., Modelers.ADNLP, Modelers.Exa)

Returns

  • NLPModels.AbstractNLPModel: The NLP model

Example

julia
nlp = nlp_model(docp, initial_guess, modeler)

See also: ocp_solution, Optimization.build_model, Optimization.BuiltModel

CTSolvers.DOCP.ocp_solution Function
julia
ocp_solution(
    built::CTSolvers.Optimization.BuiltModel,
    model_solution::SolverCore.AbstractExecutionStats,
    modeler::CTSolvers.Modelers.AbstractNLPModeler
) -> Any

Build an optimal control solution from NLP execution statistics.

This is a convenience wrapper around build_solution that dispatches on the CTSolvers.Optimization.BuiltModel returned by build_model and ensures the return type is an optimal control solution.

Arguments

  • built::BuiltModel: The built model bundle returned by build_model

  • model_solution::SolverCore.AbstractExecutionStats: NLP solver output

  • modeler: The modeler used for building

Returns

  • AbstractSolution: The OCP solution

Example

julia
built = build_model(docp, initial_guess, modeler)
sol = ocp_solution(built, nlp_stats, modeler)

See also: nlp_model, Optimization.build_solution, Optimization.BuiltModel

CTModels.Models.get_build_examodel Function
julia
get_build_examodel(
    ocp::CTModels.Models.Model{<:CTBase.Traits.TimeDependence, <:CTModels.Components.AbstractTimesModel, <:CTModels.Components.AbstractStateModel, <:CTModels.Components.AbstractControlModel, <:CTModels.Components.AbstractVariableModel, <:Function, <:CTModels.Components.AbstractObjectiveModel, <:CTModels.Components.AbstractConstraintsModel, <:CTModels.Components.AbstractDefinition, BE<:Function}
) -> Function

Return the build_examodel.

Arguments

  • ocp::Model: The optimal control problem with ExaModels builder.

Returns

  • BE: The ExaModels builder function.

See also: CTModels.Models.dynamics.

julia
get_build_examodel(
    _::CTModels.Models.Model{<:CTBase.Traits.TimeDependence, <:CTModels.Components.AbstractTimesModel, <:CTModels.Components.AbstractStateModel, <:CTModels.Components.AbstractControlModel, <:CTModels.Components.AbstractVariableModel, <:Function, <:CTModels.Components.AbstractObjectiveModel, <:CTModels.Components.AbstractConstraintsModel, <:CTModels.Components.AbstractDefinition, <:Nothing}
)

Fallback: throw when no Exa builder is present.