Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MOO struct in scimlfunctions.jl #799

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 101 additions & 4 deletions src/scimlfunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1930,11 +1930,104 @@ end

"""
$(TYPEDEF)

A representation of a multi-objective optimization problem, where multiple objective functions `f1, f2, ..., fn` are to be minimized:

'''math
\\min_{u} F(u, p) = [f1(u, p), f2(u, p), ..., fn(u, p)]
'''

`F` represents a vector of objective functions, where `u` are the optimization variables and `p` are fixed parameters or data. This struct defines all related functions such as Jacobians, Hessians, constraint functions, and their derivatives needed to solve multi-objective optimization problems.

## Constructor

```julia
MultiObjectiveOptimizationFunction{iip}(F, adtype::AbstractADType = NoAD();
jac = nothing, hess = nothing, hv = nothing,
cons = nothing, cons_j = nothing, cons_jvp = nothing,
cons_vjp = nothing, cons_h = nothing,
hess_prototype = nothing,
cons_jac_prototype = nothing,
cons_hess_prototype = nothing,
observed = __has_observed(F) ? F.observed : DEFAULT_OBSERVED_NO_TIME,
lag_h = nothing,
hess_colorvec = __has_colorvec(F) ? F.colorvec : nothing,
cons_jac_colorvec = __has_colorvec(F) ? F.colorvec : nothing,
cons_hess_colorvec = __has_colorvec(F) ? F.colorvec : nothing,
lag_hess_colorvec = nothing,
sys = __has_sys(F) ? F.sys : nothing)
```

## Positional Arguments

- `F(u, p, args...)`: The vector-valued multi-objective function `F` to be minimized. `u` is the vector of decision variables,
`p` contains the parameters, and extra arguments can be passed as needed. Each element of `F` corresponds to an individual objective function `f1, f2, ..., fn`.

## Keyword Arguments
- `jac(J, u, p)` or `J = jac(u, p)`: Jacobian of the multi-objective function `F` with respect to `u`. Can accept additional arguments: `jac(J, u, p, args...)`.
- `hess(H, u, p)` or `H = hess(u, p)`: Hessian matrix of the multi-objective function `F`. Accepts additional arguments: `hess(H, u, p, args...)`.
- `hv(Hv, u, v, p)` or `Hv = hv(u, v, p)`: Hessian-vector product for the multi-objective function `F`. Extra arguments: `hv(Hv, u, v, p, args...)`.
- `cons(res,u,p)` or `res=cons(u,p)` : the constraints function, should mutate the passed `res` array
with value of the `i`th constraint, evaluated at the current values of variables
inside the optimization routine. This takes just the function evaluations
and the equality or inequality assertion is applied by the solver based on the constraint
bounds passed as `lcons` and `ucons` to [`OptimizationProblem`](@ref), in case of equality
constraints `lcons` and `ucons` should be passed equal values.
- `cons_j(J,u,p)` or `J=cons_j(u,p)`: the Jacobian of the constraints.
- `cons_jvp(Jv,u,v,p)` or `Jv=cons_jvp(u,v,p)`: the Jacobian-vector product of the constraints.
- `cons_vjp(Jv,u,v,p)` or `Jv=cons_vjp(u,v,p)`: the Jacobian-vector product of the constraints.
- `cons_h(H,u,p)` or `H=cons_h(u,p)`: the Hessian of the constraints, provided as
an array of Hessians with `res[i]` being the Hessian with respect to the `i`th output on `cons`.
- `hess_prototype`: a prototype matrix matching the type that matches the Hessian. For example,
if the Hessian is tridiagonal, then an appropriately sized `Hessian` matrix can be used
as the prototype and optimization solvers will specialize on this structure where possible. Non-structured
sparsity patterns should use a `SparseMatrixCSC` with a correct sparsity pattern for the Hessian.
The default is `nothing`, which means a dense Hessian.
- `cons_jac_prototype`: a prototype matrix matching the type that matches the constraint Jacobian.
The default is `nothing`, which means a dense constraint Jacobian.
- `cons_hess_prototype`: a prototype matrix matching the type that matches the constraint Hessian.
This is defined as an array of matrices, where `hess[i]` is the Hessian w.r.t. the `i`th output.
For example, if the Hessian is sparse, then `hess` is a `Vector{SparseMatrixCSC}`.
The default is `nothing`, which means a dense constraint Hessian.
- `lag_h(res,u,sigma,mu,p)` or `res=lag_h(u,sigma,mu,p)`: the Hessian of the Lagrangian,
where `sigma` is a multiplier of the cost function and `mu` are the Lagrange multipliers
multiplying the constraints. This can be provided instead of `hess` and `cons_h`
to solvers that directly use the Hessian of the Lagrangian.
- `hess_colorvec`: a color vector according to the SparseDiffTools.jl definition for the sparsity
pattern of the `hess_prototype`. This specializes the Hessian construction when using
finite differences and automatic differentiation to be computed in an accelerated manner
based on the sparsity pattern. Defaults to `nothing`, which means a color vector will be
internally computed on demand when required. The cost of this operation is highly dependent
on the sparsity pattern.
- `cons_jac_colorvec`: a color vector according to the SparseDiffTools.jl definition for the sparsity
pattern of the `cons_jac_prototype`.
- `cons_hess_colorvec`: an array of color vector according to the SparseDiffTools.jl definition for
the sparsity pattern of the `cons_hess_prototype`.
-`num_dimensions`: the number of dimensions of the constraint box for OptimizationBBO.jl.
-`fitness_scheme`: the fitness scheme for OptimizationBBO.jl.

When [Symbolic Problem Building with ModelingToolkit](https://docs.sciml.ai/Optimization/stable/tutorials/symbolic/) interface is used the following arguments are also relevant:

- `observed`: an algebraic combination of optimization variables that is of interest to the user
which will be available in the solution. This can be single or multiple expressions.
- `sys`: field that stores the `OptimizationSystem`.

## iip: In-Place vs Out-Of-Place

For more details on this argument, see the ODEFunction documentation.

## specialize: Controlling Compilation and Specialization

For more details on this argument, see the ODEFunction documentation.

## Fields

The fields of the MultiObjectiveOptimizationFunction type directly match the names of the inputs.
"""

struct MultiObjectiveOptimizationFunction{
iip, AD, F, J, H, HV, C, CJ, CJV, CVJ, CH, HP, CJP, CHP, O,
EX, CEX, SYS, LH, LHP, HCV, CJCV, CHCV, LHCV} <:
EX, CEX, SYS, LH, LHP, HCV, CJCV, CHCV, LHCV, ND, FS<:FitnessScheme} <:
AbstractOptimizationFunction{iip}
f::F
adtype::AD
Expand All @@ -1959,6 +2052,8 @@ struct MultiObjectiveOptimizationFunction{
cons_jac_colorvec::CJCV
cons_hess_colorvec::CHCV
lag_hess_colorvec::LHCV
num_dimensions::ND
fitness_scheme::FS
end

"""
Expand Down Expand Up @@ -3885,7 +3980,9 @@ function MultiObjectiveOptimizationFunction{iip}(f, adtype::AbstractADType = NoA
nothing,
cons_hess_colorvec = __has_colorvec(f) ? f.colorvec :
nothing,
lag_hess_colorvec = nothing) where {iip}
lag_hess_colorvec = nothing,
num_dimensions = 0,
fitness_scheme = TupleFitnessScheme) where {iip}
isinplace(f, 2; has_two_dispatches = false, isoptimization = true)
sys = sys_or_symbolcache(sys, syms, paramsyms)
MultiObjectiveOptimizationFunction{
Expand All @@ -3899,14 +3996,14 @@ function MultiObjectiveOptimizationFunction{iip}(f, adtype::AbstractADType = NoA
typeof(expr), typeof(cons_expr), typeof(sys), typeof(lag_h),
typeof(lag_hess_prototype), typeof(hess_colorvec),
typeof(cons_jac_colorvec), typeof(cons_hess_colorvec),
typeof(lag_hess_colorvec)
typeof(lag_hess_colorvec), typeof(num_dimensions), typeof(fitness_scheme)
}(f, adtype, jac, hess,
hv, cons, cons_j, cons_jvp,
cons_vjp, cons_h,
hess_prototype, cons_jac_prototype,
cons_hess_prototype, observed, expr, cons_expr, sys,
lag_h, lag_hess_prototype, hess_colorvec, cons_jac_colorvec,
cons_hess_colorvec, lag_hess_colorvec)
cons_hess_colorvec, lag_hess_colorvec, num_dimensions, fitness_scheme)
end

function BVPFunction{iip, specialize, twopoint}(f, bc;
Expand Down