Docstrings
NonconvexCore.NonconvexCore — Module
NonconvexCoreThe modelling and automatic differentiation core of the Nonconvex ecosystem: the optimization model types, objective and constraint functions, the differentiation machinery shared by the solver packages, and the solver capability system. See the Introduction for an overview.
NonconvexCore.ConstraintCapabilities — Type
ConstraintCapabilities(; linear_eq = missing, nonlinear_eq = missing,
linear_ineq = missing, nonlinear_ineq = missing,
sd = missing, box = missing,
continuous = missing, binary = missing,
integer = missing, infinite_bounds = missing)Declares which constraint/variable features an optimizer supports:
linear_eq: linear equality constraints,nonlinear_eq: nonlinear equality constraints,linear_ineq: linear inequality constraints,nonlinear_ineq: nonlinear inequality constraints,linear_sd: linear semidefinite constraints,nonlinear_sd: nonlinear semidefinite constraints,box: finite variable bounds,continuous: continuous variables,binary: binary (0/1) variables,integer: integer (non-binary) variables,infinite_bounds: variables with infinite (unbounded) bounds.
Each field is one of true (supported), false (not supported) or missing (unknown/not declared). A solver that returns nothing from solver_capabilities declares nothing at all.
NonconvexCore.CustomGradFunction — Type
CustomGradFunction(f, g)Wraps the function f so that its gradient (or Jacobian, for vector-valued f) is computed by the user-supplied function g instead of automatic differentiation.
NonconvexCore.CustomHessianFunction — Type
CustomHessianFunction(f, g, h; hvp = false)Wraps the scalar-valued function f so that its gradient is computed by g and its Hessian by h (or, with hvp = true, by a Hessian-vector product operator).
NonconvexCore.DictModel — Type
DictModel(obj = nothing)An AbstractModel whose variables are named: each variable has a Symbol or String key and arbitrary structured values, collected in an OrderedDict. The JuMP model conversion is provided by the NonconvexCoreJuMPExt extension when JuMP is loaded.
NonconvexCore.FunctionWrapper — Type
struct FunctionWrapper <: AbstractFunction
f::Function
dim::Int
endA function wrapper type that wraps the function f where the function f is declared to return an output of dimension dim.
NonconvexCore.FunctionWrapper — Method
(f::FunctionWrapper)(args...; kwargs...)Calls the wrapped function in f with arguments args and keyword arguments kwargs and returns the output.
NonconvexCore.GenericCriteria — Type
GenericCriteriaThis is a generic convergence criteria that uses:
- The maximum change in the solution,
Δx, - The change in the objective value,
Δf, and - The change percentage in the objective value,
Δf, and - The maximum infeasibility
infeas.
to assess convergence. More details are given in assess_convergence!.
NonconvexCore.IpoptCriteria — Type
IpoptCriteriaThis convergence criteria uses a scaled version of the Karush-Kuhn-Tucker (KKT) residual and maximum infeasibility to assess convergence. This scaled KKT residual is used in the IPOPT nonlinear programming solver as explained in this paper. More details are given in assess_convergence!.
NonconvexCore.JuMPSymbolicFunction — Type
JuMPSymbolicFunction(expr::MOI.AbstractScalarFunction, vars::Vector{MOI.VariableIndex})Returns a callable that evaluates expr at a flat vector x (ordered like vars) with value, gradient and Hessian computed by MathOptInterface's Nonlinear sparse reverse-mode evaluator. Reverse-mode differentiation of the callable uses a ChainRules rrule; the gradient and Hessian are also available via jump_symbolic_gradient and jump_symbolic_hessian.
NonconvexCore.KKTCriteria — Type
KKTCriteriaThis convergence criteria uses the Karush-Kuhn-Tucker residual and maximum infeasibility to assess convergence. More details are given in assess_convergence!.
NonconvexCore.LazyJacobian — Type
LazyJacobian(; jvp = nothing, jtvp = nothing, symmetric = false)Represents a Jacobian by its matrix-free Jacobian-vector (jvp) and vector-Jacobian (jtvp) product operators instead of a matrix. Supports adjoint, transpose and matrix-vector multiplication.
NonconvexCore.Model — Type
struct Model <: AbstractModel
objective::Objective
eq_constraints::VectorOfFunctions
ineq_constraints::VectorOfFunctions
box_min::AbstractVector
box_max::AbstractVector
init::AbstractVector
integer::AbstractVector
endThe Model structs stores information about the nonlinear optimization problem.
objective: the objective function of the problem of typeObjective.eq_constraints: the equality constraints of the problem of typeVectorOfFunctions. Each function inineq_constraintscan be an instance ofIneqConstraintorAbstractFunction. If the function is not anIneqConstraint, its right-hand-side bound is assumed to be 0.ineq_constraints: the inequality constraints of the problem of typeVectorOfFunctions. Each function inineq_constraintscan be an instance ofIneqConstraintorAbstractFunction. If the function is not anIneqConstraint, its right-hand-side bound is assumed to be 0.sd_constraints: a list of matrix-valued functions which must be positive semidefinite at any feasible solution.
NonconvexCore.Model — Type
Model()
Model(f)Constructs an empty model or a model with objective function f. The decision variables are assumed to be of type Vector{Any}.
NonconvexCore.Model — Method
Model(::Type{T}, f::Union{Nothing, Function}) where {T}Constructs an empty model with objective function f and decision variable value type Vector{T}. f can be an instance of Base.Function but must return a number, or it can be an intance of Objective. f can also be nothing in which case, the objective function can be defined later using set_objective!.
NonconvexCore.ScaledKKTCriteria — Type
ScaledKKTCriteriaThis convergence criteria uses another scaled version of the Karush-Kuhn-Tucker (KKT) residual and maximum infeasibility to assess convergence. In particular if the objective was scaled by a factor m, the KKT residual will be scaled down by a factor max(m, 1/m). This scaling was found to make the convergence criteria less sensitive to scale compared to using the traditional KKT residual. More details are given in assess_convergence!.
NonconvexCore.Tolerance — Type
ToleranceA struct specifying the different tolerances used to assess the convergence of the algorithms. The following are the fields of Tolerance:
x: the tolerance forΔxinConvergenceState.x_convergedwill be true ifΔxis less than thextolerance inTolerance. This is used to assess convergence when theGenericCriteriais used as the convergence criteria.fabs: the tolerance forΔfinConvergenceState.f_convergedwill be true ifΔfis less than thefabstolerance inTolerance. This is used to assess convergence when theGenericCriteriais used as the convergence criteria.frel: the tolerance forrelΔfinConvergenceState.f_convergedwill be true ifrelΔfis less than thefreltolerance inTolerance. This is used to assess convergence when theGenericCriteriais used as the convergence criteria.kkt: the KKT tolerance.kkt_convergedinConvergenceStatewill be true if thekkt_residualis less than the KKT tolerance. Andipopt_convergedinConvergenceStatewill be true ifipopt_residualis less than the KKT tolerance. This is used to assess convergence when theKKTCriteria, theScaledKKTCriteriaorIpoptCriteriacriteria is used as the convergence criteria.infeas: the maximum infeasibility tolerance.infeas_convergedinConvergenceStatewill be true if the maximum infeasibility is less than the infeasibility tolerance. This is used to assess convergence regardless of the convergence criteria used.
For more on convergence criteria, see GenericCriteria, KKTCriteria, ScaledKKTCriteria and IpoptCriteria.
NonconvexCore.TraceFunction — Type
TraceFunction(f; on_call = ..., on_grad = ...)Wraps f and records a trace of where it is evaluated (on the function call and/or on gradient evaluations), for debugging which part of a model calls a function during optimization.
NonconvexCore.Workspace — Type
WorkspaceAbstract Workspace, which is a struct that stores states and information needed for optimization process. Implementation depends on specific algorithm.
NonconvexCore.add_eq_constraint! — Function
add_eq_constraint!(model::AbstractModel, f::EqConstraint)
add_eq_constraint!(model::AbstractModel, fs::Vector{<:EqConstraint})Adds a new equality constraint f or multiple new equality constraints fs to model.
NonconvexCore.add_ineq_constraint! — Function
add_ineq_constraint!(model::AbstractModel, f::IneqConstraint)
add_ineq_constraint!(model::AbstractModel, fs::Vector{<:IneqConstraint})Adds a new constraint f or multiple new constraints fs to model.
NonconvexCore.add_sd_constraint! — Function
add_sd_constraint!(model::AbstractModel, f::SDConstraint)Adds a new semidefinite constraint f to model.
NonconvexCore.addvar! — Function
addvar!(model::AbstractModel, lb::Number, ub::Number; init = lb, integer = false)Adds a new variable to model with lower and upper bounds lb and ub, initial value init and integer = true if the variable is integer.
NonconvexCore.checksubproblem! — Method
checksubproblem!(model::VecModel, optimizer; assumed = nothing,
hint = "", context = "the model")Validates the features present in model against solver_capabilities of optimizer. Semantics per present feature:
- declared
true→ pass; - declared
false→ArgumentErrornaming the solver, the feature and a hint on how to work around it; - undeclared (
missingor no declaration at all) →ArgumentErrorrequiring the solver to declare the capability viasolver_capabilities(strict-by-default: no opt-in).
Keyword arguments:
assumed: optionalConstraintCapabilitiesto use instead of querying the solver (for meta-algorithms that override their sub-solver's declaration),hint: extra text appended to error messages,context: description of the model used in error messages.
NonconvexCore.diffy — Function
diffy(f, x, [backend])Returns a callable that evaluates f and differentiates through an eagerly prepared backend. See prepare_gradient and prepare_jacobian.
NonconvexCore.get_ad_backend — Method
get_ad_backend()Returns the package-wide default automatic differentiation backend, see set_ad_backend!.
NonconvexCore.getmax — Function
getmax(model::AbstractModel)Returns the variables' upper bounds of model.
NonconvexCore.getmin — Function
getmin(model::AbstractModel)Returns the variables' lower bounds of model.
NonconvexCore.getobjective — Function
getobjective(model::AbstractModel)Returns a that when called with input x returns the objective value of model at x.
NonconvexCore.jump_symbolic_gradient — Method
jump_symbolic_gradient(f::JuMPSymbolicFunction, x)Returns the gradient of the wrapped function at x, computed by the MathOptInterface Nonlinear evaluator.
NonconvexCore.jump_symbolic_hessian — Method
jump_symbolic_hessian(f::JuMPSymbolicFunction, x)Returns the Hessian of the wrapped function at x, computed by the MathOptInterface Nonlinear evaluator.
NonconvexCore.merge_capabilities — Method
merge_capabilities(base::Union{ConstraintCapabilities,Nothing}; kwargs...)Returns a new ConstraintCapabilities where fields not overridden by kwargs are taken from base (nothing fields become missing). Useful for meta-algorithms that forward part of their sub-solver's capabilities.
NonconvexCore.optimize — Method
optimize(
model::AbstractModel,
optimizer::AbstractOptimizer,
x0;
options,
convcriteria::ConvergenceCriteria = KKTCriteria(),
callback = NoCallback(),
kwargs...,
)
Optimizes model using the algorithm optimizer (a solver package's AbstractOptimizer instance, e.g. IpoptAlg() from NonconvexIpopt). x0 is the initial solution, and defaults to getinit when omitted. The keyword arguments are:
options: the solver options object of the selected algorithm.convcriteria: an instance ofConvergenceCriteriathat specifies the convergence criteria of the algorithm.callback: a function that is called onsolutionin every iteration of the algorithm. This can be used to store information about the optimization process.
The model is validated against the solver's declared capabilities with checksubproblem! before the optimization starts, and the returned result contains the minimum and minimizer fields (see Optimization result).
NonconvexCore.optimize — Method
optimize without x0
NonconvexCore.optimize — Method
Generic optimize for VecModel
NonconvexCore.optimize — Method
Workspace constructor without x0
NonconvexCore.prepare_gradient — Function
prepare_gradient(f, x, [backend])
prepare_jacobian(f, x, [backend])
prepare_hessian(f, x, [backend])Explicitly prepares the differentiation backend backend (an ADTypes backend, defaulting to the package-wide backend) for f at the representative point x. The preparation (chunk selection, tape compilation, sparsity detection and coloring, ...) is cached by (f, backend) and used by default by value_gradient, value_jacobian and value_hessian afterwards.
NonconvexCore.prepare_gradient — Function
prepare_gradient(f, x, [backend])Explicitly prepares the gradient backend of f; cached and used by default.
NonconvexCore.prepare_hessian — Function
prepare_hessian(f, x, [backend])Explicitly prepares the Hessian backend of f; cached and used by default.
NonconvexCore.prepare_jacobian — Function
prepare_jacobian(f, x, [backend])Explicitly prepares the Jacobian backend of f; cached and used by default.
NonconvexCore.prepare_model — Function
prepare_model(model, [x], [backend]; gradient = true, hessian = true, jacobian = true)Explicitly prepares the differentiation backend for the selected pieces of model at the initial point, and returns the prepared vectorized model:
gradient: the objective gradient,hessian: the objective Hessian (not always required, e.g. for first-order solvers),jacobian: the Jacobians of all the constraints.
The preparations are cached per function and backend and are used by default by the value-and-derivative and sparse derivative functions on the returned model.
NonconvexCore.prepare_sparse_hessian — Function
prepare_sparse_hessian(f, x, [backend])Explicitly prepares the sparse Hessian pipeline of f; cached and used by default by sparse_hessian.
NonconvexCore.prepare_sparse_jacobian — Function
prepare_sparse_jacobian(f, x, [backend])
prepare_sparse_hessian(f, x, [backend])Explicitly prepares the sparse derivative pipeline (sparsity detection with SparseConnectivityTracer, coloring with SparseMatrixColorings and the colored DifferentiationInterface evaluation) for f at the representative point x. The preparation is cached by (f, backend) and used by default by sparse_jacobian and sparse_hessian.
NonconvexCore.prepare_sparse_jacobian — Function
prepare_sparse_jacobian(f, x, [backend])Explicitly prepares the sparse Jacobian pipeline of f; cached and used by default by sparse_jacobian.
NonconvexCore.set_ad_backend! — Method
set_ad_backend!(backend::ADTypes.AbstractADType)Sets the package-wide default automatic differentiation backend used by value_gradient, value_jacobian, sparse_jacobian and the solver-facing derivative evaluators. The package providing the backend (e.g. Enzyme.jl for AutoEnzyme()) must be loaded by the caller.
NonconvexCore.set_objective! — Function
set_objective!(model::AbstractModel, f)Sets the objective function f of model.
NonconvexCore.setinteger! — Function
setinteger!(model::AbstractModel, i, integer)Constrains the ith variable of model to be integer (or relaxes the constraint) when integer is true (false).
NonconvexCore.setmax! — Function
setmax!(model::AbstractModel, max::Union{Number, AbstractVector})
setmax!(model::AbstractModel, i::Integer, max::Number)Sets the variables' upper bound in model to max. Or if i is given, it sets the upper bound of the i^th variable in model to max.
NonconvexCore.setmin! — Function
setmin!(model::AbstractModel, min::Union{Number, AbstractVector})
setmin!(model::AbstractModel, i::Integer, min::Number)Sets the variables' lower bounds in model to min. Or if i is given, it sets the lower bound of the i^th variable in model to min.
NonconvexCore.solver_capabilities — Method
solver_capabilities(::AbstractOptimizer)Returns the ConstraintCapabilities of the optimizer, or nothing when the solver does not declare capabilities. Every optimizer that can receive constrained models must specialize this method: optimize validates the model against the declaration via checksubproblem! and errors when capabilities are undeclared or unsupported.
NonconvexCore.symbolify — Function
symbolify(f, x...; flatteny = true, kwargs...)Returns a version of f whose value, gradient and Hessian are computed symbolically with Symbolics. The Symbolics-specific implementation lives in the NonconvexCoreSymbolicsExt package extension (Symbolics is an optional dependency of NonconvexCore).
NonconvexCore.AbstractFunction — Type
abstract type AbstractFunction <: Function endAn abstract function type.
NonconvexCore.AbstractConstraint — Type
abstract type AbstractConstraint <: AbstractFunction endAn abstract constraint type.
NonconvexCore.Objective — Type
struct Objective <: AbstractFunction
f
multiple
flags::Set{Symbol}
endThe objective function to be optimized. The objective is always assumed to be of dimension 1. multiple is of type Ref{<:Number}. When an instance of Objective is called, its output will be scaled by a multiplier multiple[]. This is 1 by default.
NonconvexCore.IneqConstraint — Type
struct IneqConstraint <: AbstractConstraint
f::Function
rhs
dim::Int
flags::Set{Symbol}
endA struct for an inequality constraint of the form f(x) .- rhs .<= 0. The dimension of the constraint is dim. Calling the struct will return f(x) .- rhs.
NonconvexCore.EqConstraint — Type
struct EqConstraint <: AbstractConstraint
f::Function
rhs
dim::Int
flags::Set{Symbol}
endA struct for an equality constraint of the form f(x) .- rhs .== 0. The dimension of the constraint is dim. Calling the struct will return f(x) .- rhs.
NonconvexCore.SDConstraint — Type
Used in semidefinite programming
NonconvexCore.VectorOfFunctions — Type
struct VectorOfFunctions <: AbstractFunction
fs
endA struct for a collection of instances of AbstractFunction. The dimension of this function is the sum of the dimensions of the individual functions and the outputs are concatenated in a vector.
NonconvexCore.getfunction — Function
getfunction(f::AbstractFunction)Returns any wrapped function inside the function f.
NonconvexCore.getdim — Function
getdim(f::AbstractFunction)Returns the dimension of the function f, i.e. the number of outputs.
NonconvexCore.value_gradient — Function
value_gradient(f, x, [backend])Returns the value and gradient of the scalar-valued function f at x.
NonconvexCore.value_jacobian — Function
value_jacobian(f, x, [backend])Returns the value and Jacobian of the function (or VectorOfFunctions collection) f at x.
NonconvexCore.value_hessian — Function
value_hessian(f, x, [backend])Returns the Hessian of the scalar-valued function f at x.
NonconvexCore.sparse_jacobian — Function
sparse_jacobian(f, x, [backend::ADTypes.AbstractADType])Returns the structurally sparse Jacobian of f at x as a SparseMatrixCSC. The sparsity pattern is detected with SparseConnectivityTracer, colored with SparseMatrixColorings and the entries are computed with the automatic differentiation backend backend (defaults to the package-wide backend, see get_ad_backend). If the sparse pipeline fails for f, the values are assembled from per-function derivatives at the detected pattern positions. Failures (for example, sparsity detection on functions whose internals branch on values) raise errors rather than degrading silently.
NonconvexCore.sparse_hessian — Function
sparse_hessian(f, x, [backend::ADTypes.AbstractADType])Returns the structurally sparse Hessian of the scalar-valued function f at x as a SparseMatrixCSC. The sparsity pattern is detected with SparseConnectivityTracer, colored with SparseMatrixColorings and the entries are computed by forward-mode differentiation of the gradient computed with backend (defaults to the package-wide backend, see get_ad_backend). Failures raise errors rather than degrading silently.
NonconvexCore.second_order_backend — Function
second_order_backend(backend::ADTypes.AbstractADType)Returns the backend used to compose second derivatives from backend for sparse_hessian. The default is forward-mode differentiation over the gradient computed with backend (DI.SecondOrder(AutoForwardDiff(), backend)). This function can be specialized for specific backends, e.g. to use a forward-over-reverse composition with the same engine.
NonconvexCore.getinit — Function
getinit(model::AbstractModel)Returns the initial solution of model.
NonconvexCore.getnvars — Function
getnvars(model::AbstractModel)Returns the number of variables in model.
NonconvexCore.getnconstraints — Function
getnconstraints(model::AbstractModel)Returns the total number of constraints in model.
NonconvexCore.getineqconstraints — Function
getineqconstraints(model::AbstractModel)Returns a that when called with input x returns the constraint violation values of all the inequality constraints of model at x.
NonconvexCore.geteqconstraints — Function
geteqconstraints(model::AbstractModel)Returns a that when called with input x returns the constraint violation values of all the equality constraints of model at x.
NonconvexCore.getobjectiveconstraints — Function
getobjectiveconstraints(model::AbstractModel)Returns an instance of AbstractFunction that when called with input x returns the objective and constraint values of model at x in a single vector.
NonconvexCore.getnineqconstraints — Function
getnineqconstraints(model::AbstractModel)Returns the number of inequality constraints in model.
NonconvexCore.getneqconstraints — Function
getneqconstraints(model::AbstractModel)Returns the number of equality constraints in model.
NonconvexCore.ConvergenceCriteria — Type
ConvergenceCriteriaThis an abstract type with 4 subtypes:
NonconvexCore.ConvergenceState — Type
ConvergenceStateA struct that summarizes the convergence state of a solution. The fields in this struct are:
Δx: the infinity norm of the change in the solutionx.Δf: the change in the objective valuef.relΔf: the ratio of change in the objective valuef.kkt_residual: the Karush-Kuhn-Tucker (KKT) residual of the solution. IfScaledKKTCriteriais used instead ofKKTCriteria, thekkt_residualwill be divided by a factor.ipopt_residual: the modified KKT residual used in the IPOPT solver.infeas: maximum infeasibility amount. This is 0 if the solution is feasible.x_converged: true ifΔxis less than thextolerance inTolerance.fabs_converged: true ifΔfis less than theftolerance inTolerance.frel_converged: true ifrelΔfis less than theftolerance inTolerance.kkt_converged: true if thekkt_residualis less than the KKT tolerance inTolerance.ipopt_converged: true if theipopt_residualis less than the KKT tolerance inTolerance.infeas_converged: true ifinfeasis less than the infeasibility tolerance inTolerance.f_increased: true if the objective value of the current solution is higher than that of the previous solution.converged: true if the solution satisfies the convergence criteria of choice. SeeConvergenceCriteriafor more on the different convergence criteria available.
NonconvexCore.assess_convergence! — Function
assess_convergence!(workspace::Workspace)Updates the workspace by evaluating the convergence criteria against the model at the current solution.
NonconvexCore.JuMPEvaluator — Type
JuMPEvaluatorA single MathOptInterface Nonlinear evaluator over an entire JuMP model converted into a NonconvexCore model. The objective and every constraint are expressions of one MOI.Nonlinear.Model, so shared subexpressions are evaluated once per pass, and the whole Jacobian and Lagrangian Hessian come from single evaluator calls.
The constraints are keyed by their ConstraintIndex, because neither the JuMP constraint iteration order nor the evaluator row order is meaningful; the evaluator's own row order is recovered from ordered_constraints. Converted rows are exposed inequality-first (sorted by constraint index), then equalities (also sorted by constraint index). Inequality row k has value sign * f_k(x) + shift (Nonconvex convention: feasible when <= 0); equality row k has value f_k(x) + shift (feasible when 0). The objective is objective_sign * f_obj(x).
NonconvexCore.JuMPModelObjective — Type
JuMPModelObjective(m::JuMPEvaluator, ks)The objective of a JuMP-converted model: evaluates the converted objective expression on the model's variable container through the shared JuMPEvaluator.
NonconvexCore.JuMPModelIneq — Type
JuMPModelIneq(m::JuMPEvaluator, ks)The inequality constraints of a JuMP-converted model: a single vector-valued function evaluating every converted inequality row (in the converted row order) through the shared JuMPEvaluator.
NonconvexCore.JuMPModelEq — Type
JuMPModelEq(m::JuMPEvaluator, ks)The equality constraints of a JuMP-converted model: a single vector-valued function evaluating every converted equality row through the shared JuMPEvaluator.
NonconvexCore.jump_objective_gradient — Function
jump_objective_gradient(m::JuMPEvaluator, x)Returns the gradient of the converted objective at x, computed by the MathOptInterface Nonlinear evaluator.
NonconvexCore.jump_jacobian — Function
jump_jacobian(m::JuMPEvaluator, x)Returns the constraint Jacobian of the converted model at x as a sparse matrix, computed by the MathOptInterface Nonlinear evaluator.
NonconvexCore.jump_jacobian_structure — Function
jump_jacobian_structure(m::JuMPEvaluator)Returns (rows, columns) of the converted model's constraint Jacobian, with rows ordered inequality-first like the constraint values.
NonconvexCore.jump_hessian_structure — Function
jump_hessian_structure(m::JuMPEvaluator)Returns (rows, columns) of the converted model's Lagrangian Hessian in lower-triangular form.
NonconvexCore.@params — Macro
@params struct_defA macro that changes all fields' types to type parameters while respecting the type bounds specificied by the user. For example:
@params struct MyType{T}
f1::T
f2::AbstractVector{T}
f3::AbstractVector{<:Real}
f4
endwill define:
struct MyType{T, T1 <: T, T2 <: AbstractVector{T}, T3 <: AbstractVector{<:Real}, T4}
f1::T1
f2::T2
f3::T3
f4::T4
endThe default non-parameteric constructor, e.g. MyType(f1, f2, f3, f4), will always work if all the type parameters used in the type header are used in the field types. Using a type parameter in the type header that is not used in the field types such as:
struct MyType{T}
f1
f2
endis not recommended.
NonconvexCore.get_variable_info — Function
get_variable_info(model::JuMP.Model)Returns the lower bounds, upper bounds, initial points and integer flags of the variables of a JuMP model as OrderedDicts, in the structure NonconvexCore models use.
NonconvexCore._ordered_jump_variables — Function
_ordered_jump_variables(model::JuMP.Model, ks)Returns the JuMP model's variables ordered like the flattened model vector with keys ks.
NonconvexCore._nonlinear_constraints — Function
_nonlinear_constraints(model::JuMP.Model)Returns the model's nonlinear (and quadratic and affine, when a nonlinear expression is present) constraints as (expr, set) pairs with the expressions converted to MathOptInterface scalar functions.
NonconvexCore.get_jump_problem — Function
get_jump_problem(model::VecModel, x0 = getinit(model); optimizer, first_order, backend, kwargs...)Builds a JuMP model wrapping a NonconvexCore model through a custom MOI.AbstractNLPEvaluator, for solvers that interface through JuMP.
NonconvexCore.Solution — Type
SolutionA struct that stores all the information about a solution. The following are the fields of Solution:
x: the current primal solutionprevx: the previous primal solutionλ: the current dual solutionf: the objective value ofxprevf: the obejctive value ofprevx∇f: the gradient of the objective atxg: the constraint function value atx∇g: the Jacobian of the constraint functions atxconvstate: the convergence state of the solution
NonconvexCore.Trace — Type
TraceA struct that stores the history of solutions.
NonconvexCore.AbstractResult — Type
AbstractResultAn abstract type that stores optimization result.
NonconvexCore.GenericResult — Type
GenericResultA summary result struct returned by optimize, including following fields:
optimizer: the optimization algorithm usedinitial_x: the initial primal solutionminimizer: the best solution foundminimum: the optimal valueiter: number of inner iterations runmaxiter_reached: true if the algorithm stopped due to reaching the maximum number of iterationstol: an instance ofTolerancethat specifies the convergence tolerancesconvstate: an instance ofConvergenceCriteriathat summarizes the convergence state of the best solution foundfcalls: the number of times the objective and constraint functions were called during the optimization
NonconvexCore.PlottingCallback — Type
PlottingCallback
A callback function that plots a number of convergence metrics using ConvergencePlots.jl. The following are the fields of the struct:
plot: an instance ofConvergencePlots.ConvergencePlot.n: the number of history points to keep track of.iter: the number of times the callback was called.
NonconvexCore.LazyPlottingCallback — Type
LazyPlottingCallbackA callback function that plots a number of convergence metrics using ConvergencePlots.jl only when show is called. The following are the fields of the struct:
plot: an instance ofConvergencePlots.ConvergencePlot.n: the number of history points to keep track of.iter: the number of times the callback was called.
NonconvexCore.PreparedFunction — Type
diffy(f, x, [backend])Returns a callable that evaluates f and whose derivatives are computed by the differentiation backend backend (an ADTypes backend, defaulting to the package-wide backend), prepared eagerly at the representative point x. The returned function can be used in place of f in objectives and constraints; any ChainRules-compatible outer differentiation uses the prepared backend.
NonconvexCore.FlattenedFunction — Type
FlattenedFunctionA callable that evaluates the wrapped function f on the structure rebuilt by unflattenx from a flat vector, and flattens the output. The raw function and the input unflattening are exposed via getrawfunction and getinputunflatten so that solvers can evaluate all model functions against a single reconstructed structure per point.
NonconvexCore.DEFAULT_AD_BACKEND — Constant
DEFAULT_AD_BACKENDThe automatic differentiation backend used by default wherever NonconvexCore computes derivatives, e.g. in value_gradient, value_jacobian, sparse_jacobian and the solver-facing derivative evaluators. It is initially ADTypes.AutoZygote(), whose ChainRules-based design supports arbitrary argument types (dictionaries, structs, arrays) through the model-flattening machinery. Change it with set_ad_backend!, or pass a backend explicitly to the functions above.
NonconvexCore.check_finite_start! — Method
check_finite_start!(model, args)Throws a descriptive error when the objective or any constraint returns a non-finite value at the initial point. args carries the initial point when optimize was called with one; the model's init is used otherwise.
Base.length — Method
length(f::AbstractFunction)Returns the number of outputs of f.
NonconvexCore.getinputunflatten — Method
getinputunflatten(f)Returns the callable that rebuilds the user-facing input structure of the function f from a flat vector.
NonconvexCore.getrawfunction — Method
getrawfunction(f)Returns the raw function wrapped by f, callable on the structure returned by getinputunflatten. For a FlattenedFunction this is the function as defined by the user before flattening.
NonconvexCore.getfunctions — Method
getfunctions(f::VectorOfFunctions)Returns the vector or tuple of functions wrapped in f.
NonconvexCore.set_objective — Method
set_objective!(m::AbstractModel, f::Function)Sets the objective of the moodel m to the function f. f must return a scalar.
NonconvexCore.hasconverged — Method
hasconverged(s::Solution)
Returns true if hasconverged(s.convstate) is true.
NonconvexCore.hasconverged — Method
hasconverged(s::ConvergenceState)
Returns true if s.converged is true.
NonconvexCore.correctsolution! — Method
correctsolution!(solution, model, options)Default no-op fallback: solvers may specialize this to undo any scaling applied to the model during the optimization, e.g. to correct solution.f by the objective multiple before reporting the result.
NonconvexCore.clamp_and_evaluate! — Method
Clamp the box constraint and evaluate objective function at point x
NonconvexCore.jump_symbolic_hessian_sparsity — Function
jump_symbolic_hessian_sparsity(f::JuMPSymbolicFunction, n)Returns the sparse Hessian structure (row, column) of the wrapped expression with respect to a vector of length n.
NonconvexCore.get_objective_multiple — Function
get_objective_multiple(model::AbstractModel)Returns the factor by which the objective of model was scaled. This is 1 by default.
NonconvexCore.set_objective_multiple! — Function
set_objective_multiple!(model::AbstractModel, multiple::Number)Set the objective's scaling factor of model to multiple.
NonconvexCore.tovecmodel — Method
tovecmodel(m::DictModel, x0::AbstractVector)A DictModel stores variables keyed by name, so an initial solution must be a dict-like structure with the variable names as keys. This method throws a descriptive error instead of failing deep inside the flattening machinery.
NonconvexCore.geteqconstraint — Function
geteqconstraint(model::AbstractModel, i::Integer)Returns a that when called with input x returns the constraint violation value of the i^th equality constraint of model at x.
NonconvexCore.getineqconstraint — Function
getineqconstraint(model::AbstractModel, i::Integer)Returns a that when called with input x returns the constraint violation value of the i^th inequality constraint of model at x.
NonconvexCore.setbox! — Function
setbox!(model::AbstractModel, min::Union{Number, AbstractVector}, max::Union{Number, AbstractVector})
setbox!(model::AbstractModel, i::Integer, min::Number, max::Number)Sets the variables' lower and upper bounds in model to min and max respectively. Or if i is given, it sets the lower and upper bounds of the i^th variable in model to min and max respectively.
NonconvexCore.sparse_gradient — Function
sparse_gradient(f, x, [backend::ADTypes.AbstractADType])Returns the gradient of the scalar-valued function f at x computed with the automatic differentiation backend backend (defaults to the package-wide backend, see get_ad_backend).
NonconvexCore.jump_constraint_linearity — Function
jump_constraint_linearity(m::JuMPEvaluator)Returns (ineq_linear, eq_linear): per-row Bools recording whether each converted inequality and equality row is a linear expression.