-
Notifications
You must be signed in to change notification settings - Fork 37
Parametric AD API #557
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
Closed
Closed
Parametric AD API #557
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6733cff
parametric api
klamike b90d8d6
update meta
klamike 05b7e6a
no more ParametricNLPModelMeta, just extend NLPModelMeta
klamike fee4330
finish getting rid of ParametricNLPModelMeta
klamike e7dfe84
tests
klamike 0e2f1d8
use meta getters
klamike 1c6d42e
nnz sanity checks
klamike 57ee69e
use `get_*(nlp.meta)` instead of `get_*(nlp)` (#558)
klamike 85fda29
add get_param/set_param!
klamike d8bdadd
add docs
klamike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| # Parametric API | ||
|
|
||
| This section documents the optional parametric API of `NLPModels.jl`. | ||
| The parametric API provides derivatives of the problem data with respect to parameters `p`, for problems of the form | ||
|
|
||
| ```math | ||
| \begin{aligned} | ||
| \min \quad & f(x, p) \\ | ||
| & c_L(p) \leq c(x, p) \leq c_U(p) \\ | ||
| & \ell(p) \leq x \leq u(p). | ||
| \end{aligned} | ||
| ``` | ||
|
|
||
| The main use-case is implicit differentation of KKT conditions, where the forming the RHS requires evaluating the derivatives of the problem data with respect to parameters. | ||
|
|
||
| Note that `p` does not appear as an explicit argument to any of the functions below. | ||
| Implementations are responsible for storing the current parameter values internally (e.g., as a field of the model struct) and reading them when evaluating the functions. | ||
|
|
||
| --- | ||
|
|
||
| ## Parameter access | ||
|
|
||
| NLPModels provides a common interface for setting and getting the current parameter values: | ||
|
|
||
| | Function | Signature | | ||
| |:--------:|:---------:| | ||
| | `get_param_values` | `p = get_param_values(nlp)` | | ||
| | `set_param_values!` | `set_param_values!(nlp, p)` | | ||
|
|
||
| --- | ||
|
|
||
| ## Objective gradient wrt parameters | ||
|
|
||
| Evaluate ``\nabla_p f(x, p)``, the gradient of the objective with respect to the parameters at the current `x`: | ||
|
|
||
| | Function | Signature | | ||
| |:--------:|:---------:| | ||
| | `grad_param` | `g = grad_param(nlp, x)` | | ||
| | `grad_param!` | `g = grad_param!(nlp, x, g)` | | ||
|
|
||
| --- | ||
|
|
||
| ## Sparse constraint Jacobian wrt parameters | ||
|
|
||
| Evaluate ``J_p(x) = \nabla_p c(x, p)^T``, the Jacobian of the constraints with respect to the parameters: | ||
|
|
||
| | Function | Signature | | ||
| |:--------:|:---------:| | ||
| | `jac_param_structure` | `(rows, cols) = jac_param_structure(nlp)` | | ||
| | `jac_param_structure!` | `(rows, cols) = jac_param_structure!(nlp, rows, cols)` | | ||
| | `jac_param_coord` | `vals = jac_param_coord(nlp, x)` | | ||
| | `jac_param_coord!` | `vals = jac_param_coord!(nlp, x, vals)` | | ||
|
|
||
| --- | ||
|
|
||
| ## Constraint Jacobian-vector products wrt parameters | ||
|
|
||
| Evaluate products with ``J_p(x)`` and ``J_p(x)^T`` without forming the matrix explicitly: | ||
|
|
||
| | Function | Signature | | ||
| |:--------:|:---------:| | ||
| | `jpprod` | `Jv = jpprod(nlp, x, v)` | | ||
| | `jpprod!` | `Jv = jpprod!(nlp, x, v, Jv)` | | ||
| | `jptprod` | `Jtv = jptprod(nlp, x, v)` | | ||
| | `jptprod!` | `Jtv = jptprod!(nlp, x, v, Jtv)` | | ||
|
|
||
| --- | ||
|
|
||
| ## Sparse variable-parameter Hessian of the Lagrangian | ||
|
|
||
| Evaluate ``\nabla^2_{xp} L(x, y, p)``, the mixed variable-parameter Hessian of the Lagrangian. | ||
| When `y` is omitted, only the objective contribution should be included (i.e., `y = 0`): | ||
|
|
||
| | Function | Signature | | ||
| |:--------:|:---------:| | ||
| | `hess_param_structure` | `(rows, cols) = hess_param_structure(nlp)` | | ||
| | `hess_param_structure!` | `(rows, cols) = hess_param_structure!(nlp, rows, cols)` | | ||
| | `hess_param_coord` | `vals = hess_param_coord(nlp, x; obj_weight)` | | ||
| | `hess_param_coord` | `vals = hess_param_coord(nlp, x, y; obj_weight)` | | ||
| | `hess_param_coord!` | `vals = hess_param_coord!(nlp, x, vals; obj_weight)` | | ||
| | `hess_param_coord!` | `vals = hess_param_coord!(nlp, x, y, vals; obj_weight)` | | ||
|
|
||
| --- | ||
|
|
||
| ## Variable-parameter Hessian-vector products | ||
|
|
||
| Evaluate products with ``\nabla^2_{xp} L(x, y, p)`` and its transpose. | ||
| When `y` is omitted, only the objective contribution should be included (i.e., `y = 0`): | ||
|
|
||
| | Function | Signature | | ||
| |:--------:|:---------:| | ||
| | `hpprod` | `Hv = hpprod(nlp, x, v; obj_weight)` | | ||
| | `hpprod` | `Hv = hpprod(nlp, x, y, v; obj_weight)` | | ||
| | `hpprod!` | `Hv = hpprod!(nlp, x, v, Hv; obj_weight)` | | ||
| | `hpprod!` | `Hv = hpprod!(nlp, x, y, v, Hv; obj_weight)` | | ||
| | `hptprod` | `Htv = hptprod(nlp, x, y, v; obj_weight)` | | ||
| | `hptprod!` | `Htv = hptprod!(nlp, x, y, v, Htv; obj_weight)` | | ||
|
|
||
| --- | ||
|
|
||
| ## Sparse constraint lower-bound Jacobian wrt parameters | ||
|
|
||
| Evaluate ``\nabla_p c_L(p)``, the Jacobian of the constraint lower bounds with respect to the parameters: | ||
|
|
||
| | Function | Signature | | ||
| |:--------:|:---------:| | ||
| | `lcon_jac_param_structure` | `(rows, cols) = lcon_jac_param_structure(nlp)` | | ||
| | `lcon_jac_param_structure!` | `(rows, cols) = lcon_jac_param_structure!(nlp, rows, cols)` | | ||
| | `lcon_jac_param_coord` | `vals = lcon_jac_param_coord(nlp)` | | ||
| | `lcon_jac_param_coord!` | `vals = lcon_jac_param_coord!(nlp, vals)` | | ||
| | `lcon_jpprod` | `Jv = lcon_jpprod(nlp, v)` | | ||
| | `lcon_jpprod!` | `Jv = lcon_jpprod!(nlp, v, Jv)` | | ||
| | `lcon_jptprod` | `Jtv = lcon_jptprod(nlp, v)` | | ||
| | `lcon_jptprod!` | `Jtv = lcon_jptprod!(nlp, v, Jtv)` | | ||
|
|
||
| --- | ||
|
|
||
| ## Sparse constraint upper-bound Jacobian wrt parameters | ||
|
|
||
| Evaluate ``\nabla_p c_U(p)``, the Jacobian of the constraint upper bounds with respect to the parameters: | ||
|
|
||
| | Function | Signature | | ||
| |:--------:|:---------:| | ||
| | `ucon_jac_param_structure` | `(rows, cols) = ucon_jac_param_structure(nlp)` | | ||
| | `ucon_jac_param_structure!` | `(rows, cols) = ucon_jac_param_structure!(nlp, rows, cols)` | | ||
| | `ucon_jac_param_coord` | `vals = ucon_jac_param_coord(nlp)` | | ||
| | `ucon_jac_param_coord!` | `vals = ucon_jac_param_coord!(nlp, vals)` | | ||
| | `ucon_jpprod` | `Jv = ucon_jpprod(nlp, v)` | | ||
| | `ucon_jpprod!` | `Jv = ucon_jpprod!(nlp, v, Jv)` | | ||
| | `ucon_jptprod` | `Jtv = ucon_jptprod(nlp, v)` | | ||
| | `ucon_jptprod!` | `Jtv = ucon_jptprod!(nlp, v, Jtv)` | | ||
|
|
||
| --- | ||
|
|
||
| ## Sparse variable lower-bound Jacobian wrt parameters | ||
|
|
||
| Evaluate ``\nabla_p \ell(p)``, the Jacobian of the variable lower bounds with respect to the parameters: | ||
|
|
||
| | Function | Signature | | ||
| |:--------:|:---------:| | ||
| | `lvar_jac_param_structure` | `(rows, cols) = lvar_jac_param_structure(nlp)` | | ||
| | `lvar_jac_param_structure!` | `(rows, cols) = lvar_jac_param_structure!(nlp, rows, cols)` | | ||
| | `lvar_jac_param_coord` | `vals = lvar_jac_param_coord(nlp)` | | ||
| | `lvar_jac_param_coord!` | `vals = lvar_jac_param_coord!(nlp, vals)` | | ||
| | `lvar_jpprod` | `Jv = lvar_jpprod(nlp, v)` | | ||
| | `lvar_jpprod!` | `Jv = lvar_jpprod!(nlp, v, Jv)` | | ||
| | `lvar_jptprod` | `Jtv = lvar_jptprod(nlp, v)` | | ||
| | `lvar_jptprod!` | `Jtv = lvar_jptprod!(nlp, v, Jtv)` | | ||
|
|
||
| --- | ||
|
|
||
| ## Sparse variable upper-bound Jacobian wrt parameters | ||
|
|
||
| Evaluate ``\nabla_p u(p)``, the Jacobian of the variable upper bounds with respect to the parameters: | ||
|
|
||
| | Function | Signature | | ||
| |:--------:|:---------:| | ||
| | `uvar_jac_param_structure` | `(rows, cols) = uvar_jac_param_structure(nlp)` | | ||
| | `uvar_jac_param_structure!` | `(rows, cols) = uvar_jac_param_structure!(nlp, rows, cols)` | | ||
| | `uvar_jac_param_coord` | `vals = uvar_jac_param_coord(nlp)` | | ||
| | `uvar_jac_param_coord!` | `vals = uvar_jac_param_coord!(nlp, vals)` | | ||
| | `uvar_jpprod` | `Jv = uvar_jpprod(nlp, v)` | | ||
| | `uvar_jpprod!` | `Jv = uvar_jpprod!(nlp, v, Jv)` | | ||
| | `uvar_jptprod` | `Jtv = uvar_jptprod(nlp, v)` | | ||
| | `uvar_jptprod!` | `Jtv = uvar_jptprod!(nlp, v, Jtv)` | | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,4 +44,6 @@ end | |
| include("nlp/batch_api.jl") | ||
| include("nlp/batch_meta.jl") | ||
|
|
||
| include("nlp/param_api.jl") | ||
|
|
||
| end # module | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should add a section on the new
metafields