Skip to content

Public API ​

This page lists exported symbols of CTSolvers.DOCP.


From CTSolvers.DOCP ​

CTSolvers.DOCP [Module] ​

CTSolvers.DOCP Module

DOCP (Discretized Optimal Control Problem) module.

This module defines the DiscretizedModel type and the associated API to build NLP models and reconstruct OCP solutions via the Optimization and Modelers contracts.

The DOCP layer is the bridge between continuous-time models (from CTModels) and the solver/modeler infrastructure provided by CTSolvers.

AbstractDiscretizer [Abstract Type] ​

CTSolvers.DOCP.AbstractDiscretizer Type
julia
abstract type AbstractDiscretizer <: CTBase.Strategies.AbstractStrategy

Abstract base type for all discretization strategies.

Concrete subtypes implement specific transcription methods (collocation, direct shooting, etc.) and are defined in the package providing the method. A discretizer is a Strategies.AbstractStrategy: it carries validated options and drives discretize to turn an optimal control problem into a CTSolvers.DOCP.DiscretizedModel.

See also: DiscretizedModel, discretize.

DiscretizedModel [Struct] ​

CTSolvers.DOCP.DiscretizedModel Type
julia
struct DiscretizedModel{TO<:CTModels.Models.AbstractModel, TD<:CTSolvers.DOCP.AbstractDiscretizer, TC<:CTBase.Core.AbstractCache} <: CTSolvers.Optimization.AbstractOptimizationProblem

Discretized optimal control problem ready for NLP solving.

A thin pairing of an optimal control problem with the discretizer that produced it, plus a backend cache. The actual NLP model and OCP solution are produced by multiple dispatch on (DiscretizedModel, modeler) through the build_model / build_solution contract, implemented in the package providing the discretizer (e.g. CTDirect). This mirrors Flow{system, integrator} on the ODE side.

Fields

  • ocp::TO: The original optimal control problem.

  • discretizer::TD: The discretization strategy used.

  • cache::TC: Backend cache (<: CTBase.Core.AbstractCache), opaque to CTSolvers, populated by the implementing package (e.g. CTDirect's DOCPCache).

Type parameters

  • TO <: CTModels.AbstractModel

  • TD <: AbstractDiscretizer

  • TC <: CTBase.Core.AbstractCache

Display

Shown in the REPL as a short tree (problem spaces and times, discretizer options, cache type name) whose length does not depend on the grid size, and by print on one line.

See also: ocp_model, discretize, build_model, build_solution.

discretize [Function] ​

CTSolvers.DOCP.discretize Function
julia
discretize(
    ocp::CTModels.Models.AbstractModel,
    discretizer::CTSolvers.DOCP.AbstractDiscretizer
)

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.

nlp_model [Function] ​

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

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: CTSolvers.DOCP.ocp_solution, CTSolvers.Optimization.build_model, CTSolvers.Optimization.BuiltModel

julia
nlp_model(
    built::CTSolvers.Optimization.BuiltModel{<:CTSolvers.DOCP.DiscretizedModel}
) -> Any

Return the NLP model of a built discretized optimal control problem.

Accessor of the CTSolvers.Optimization.BuiltModel returned by build_model for a CTSolvers.DOCP.DiscretizedModel: it returns the NLP that was built, without building anything. A BuiltModel of another problem type has no such method.

Arguments

  • built::Optimization.BuiltModel{<:DiscretizedModel}: The built model bundle returned by build_model for a DiscretizedModel

Returns

  • The backend NLP model (e.g. an ADNLPModel or an ExaModel), the nlp field of built

Throws

  • MethodError: if built holds a problem that is not a DiscretizedModel

Example

julia
built = build_model(docp, initial_guess, modeler)
stats = ipopt(nlp_model(built))
sol = ocp_solution(built, stats, modeler)

See also: CTSolvers.DOCP.ocp_model, CTSolvers.DOCP.ocp_solution, CTSolvers.Optimization.build_model

ocp_model [Function] ​

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: CTSolvers.DOCP.DiscretizedModel, CTSolvers.DOCP.nlp_model

julia
ocp_model(
    built::CTSolvers.Optimization.BuiltModel{<:CTSolvers.DOCP.DiscretizedModel}
) -> CTModels.Models.AbstractModel

Return the original optimal control problem of a built discretized optimal control problem.

Accessor of the CTSolvers.Optimization.BuiltModel returned by build_model for a CTSolvers.DOCP.DiscretizedModel: same result as ocp_model on the DiscretizedModel it was built from. A BuiltModel of another problem type has no such method.

Arguments

  • built::Optimization.BuiltModel{<:DiscretizedModel}: The built model bundle returned by build_model for a DiscretizedModel

Returns

  • The original optimal control problem

Throws

  • MethodError: if built holds a problem that is not a DiscretizedModel

Example

julia
built = build_model(docp, initial_guess, modeler)
ocp_model(built) === ocp_model(docp)  # true

See also: CTSolvers.DOCP.nlp_model, CTSolvers.DOCP.DiscretizedModel

ocp_solution [Function] ​

CTSolvers.DOCP.ocp_solution Function
julia
ocp_solution(
    built::CTSolvers.Optimization.BuiltModel{<:CTSolvers.DOCP.DiscretizedModel},
    model_solution::SolverCore.AbstractExecutionStats,
    modeler::CTSolvers.Modelers.AbstractNLPModeler
)

Build an optimal control solution from NLP execution statistics.

This is a convenience wrapper around build_solution for the CTSolvers.Optimization.BuiltModel returned by build_model for a CTSolvers.DOCP.DiscretizedModel. A BuiltModel of another problem type has no such method: call build_solution directly for it.

Arguments

  • built::Optimization.BuiltModel{<:DiscretizedModel}: The built model bundle returned by build_model for a DiscretizedModel

  • model_solution::SolverCore.AbstractExecutionStats: NLP solver output

  • modeler: The modeler used for building

Returns

  • The OCP solution, as returned by build_solution

Throws

  • MethodError: if built holds a problem that is not a DiscretizedModel

Example

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

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