|
10 | 10 |
|
11 | 11 | For more on how to construct a backend struct for each AD package, please refer to the README file of the [`AbstractDifferentiation`](https://github.com/JuliaDiff/AbstractDifferentiation.jl) repository.
|
12 | 12 |
|
| 13 | +## `abstractdiffy`ing a function |
| 14 | + |
13 | 15 | In order to use a specific `AbstractDifferentiation`-compatible AD package to differentiate a function `f(x...)` used in a `Nonconvex` objective/constraint, you can use the `abstractdiffy` function modifier from `Nonconvex`:
|
14 | 16 | ```julia
|
15 | 17 | F = abstractdiffy(f, backend, x...)
|
@@ -42,3 +44,22 @@ which is short for:
|
42 | 44 | backend = AbstractDifferentiation.ForwardDiffBackend()
|
43 | 45 | F = abstractdiffy(f, backend, x...)
|
44 | 46 | ```
|
| 47 | + |
| 48 | +## `abstractdiffy`ing a model |
| 49 | + |
| 50 | +Instead of `abstractdiffy`ing or `forwarddiffy`ing one function at a time, the user can instead `abstractdiffy` or `forwarddiffy` an entire `Nonconvex` model including the objective, all the inequality constraint functions, all the equality constraint functions and all the semidefinite constraint functions. |
| 51 | +```julia |
| 52 | +ad_model = abstractdiffy(model, backend) |
| 53 | +``` |
| 54 | +where `model` is of type `Model` or `DictModel`. `ad_model` can now be optimized using any of the `Nonconvex` algorithms compatible with the model. Similarly, `forwarddiffy` can be used on an entire model: |
| 55 | +```julia |
| 56 | +fd_model = forwarddiffy(model) |
| 57 | +``` |
| 58 | + |
| 59 | +By default, the objective and all the constraint functions will be modified with `abstractdiffy`/`forwarddiffy`. To prevent the modification of some component of the model, any of the following keyword arguments can be set to `false` (default is `true`): |
| 60 | +- `objective = false` |
| 61 | +- `ineq_constraints = false` |
| 62 | +- `eq_constraints = false` |
| 63 | +- `sd_constraints = false` |
| 64 | + |
| 65 | +Setting the `objective`, `ineq_constraints`, `eq_constraints`, and/or `sd_constraints` keyword arguments to `false` (default is `true`) will prevent the modification of the objective, all the inequality constraint functions, all the equality constraint functions, and/or all the semidefinite constraint functions respectively. |
0 commit comments