@@ -302,35 +302,17 @@ However, we cannot call gradient terms such as
302
302
[ ` eval_objective_gradient ` ] ( @ref ) because [ ` Nonlinear.ExprGraphOnly ` ] ( @ref ) does
303
303
not have the capability to differentiate a nonlinear expression.
304
304
305
- Instead of passing [ ` Nonlinear.Evaluator ` ] ( @ref ) directly to solvers,
306
- solvers query the [ ` NLPBlock ` ] ( @ref ) attribute, which returns an
307
- [ ` NLPBlockData ` ] ( @ref ) . This object wraps an [ ` Nonlinear.Evaluator ` ] ( @ref ) and
308
- includes other information such as constraint bounds and whether the evaluator
309
- has a nonlinear objective. Create and set [ ` NLPBlockData ` ] ( @ref ) as follows:
305
+ If, instead, we pass [ ` Nonlinear.SparseReverseMode ` ] ( @ref ) , then we get access
306
+ to ` :Grad ` , the gradient of the objective function, ` :Jac ` , the jacobian matrix
307
+ of the constraints, ` :JacVec ` , the ability to compute Jacobian-vector products,
308
+ and ` :ExprGraph ` .
310
309
``` jldoctest nonlinear_developer
311
- julia> block = MOI.NLPBlockData(evaluator);
312
-
313
- julia> model = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}());
314
-
315
- julia> MOI.set(model, MOI.NLPBlock(), block);
316
- ```
317
- !!! warning
318
- Only call [ ` NLPBlockData ` ] ( @ref ) once you have finished modifying the
319
- problem in ` model ` .
320
-
321
- If, instead, we set [ ` Nonlinear.SparseReverseMode ` ] ( @ref ) , then we get access to
322
- ` :Grad ` , the gradient of the objective function, ` :Jac ` , the jacobian matrix of
323
- the constraints, ` :JacVec ` , the ability to compute Jacobian-vector products, and
324
- ` :ExprGraph ` .
325
- ``` jldoctest nonlinear_developer
326
- julia> Nonlinear.set_differentiation_backend(
327
- data,
310
+ julia> evaluator = Nonlinear.Evaluator(
311
+ model,
328
312
Nonlinear.SparseReverseMode(),
329
313
[x],
330
314
)
331
-
332
- julia> data
333
- NonlinearData with available features:
315
+ Nonlinear.Evaluator with available features:
334
316
* :Grad
335
317
* :Jac
336
318
* :JacVec
@@ -339,7 +321,7 @@ NonlinearData with available features:
339
321
340
322
However, before calling anything, we need to call [ ` initialize ` ] ( @ref ) :
341
323
``` jldoctest nonlinear_developer
342
- julia> MOI.initialize(data , [:Grad, :Jac, :JacVec, :ExprGraph])
324
+ julia> MOI.initialize(evaluator , [:Grad, :Jac, :JacVec, :ExprGraph])
343
325
```
344
326
345
327
Now we can call methods like [ ` eval_objective ` ] ( @ref ) :
@@ -348,7 +330,7 @@ julia> x = [1.0]
348
330
1-element Vector{Float64}:
349
331
1.0
350
332
351
- julia> MOI.eval_objective(data , x)
333
+ julia> MOI.eval_objective(evaluator , x)
352
334
7.268073418273571
353
335
```
354
336
and [ ` eval_objective_gradient ` ] ( @ref ) :
@@ -357,13 +339,29 @@ julia> grad = [NaN]
357
339
1-element Vector{Float64}:
358
340
NaN
359
341
360
- julia> MOI.eval_objective_gradient(data , grad, x)
342
+ julia> MOI.eval_objective_gradient(evaluator , grad, x)
361
343
362
344
julia> grad
363
345
1-element Vector{Float64}:
364
346
1.909297426825682
365
347
```
366
348
349
+ Instead of passing [ ` Nonlinear.Evaluator ` ] ( @ref ) directly to solvers,
350
+ solvers query the [ ` NLPBlock ` ] ( @ref ) attribute, which returns an
351
+ [ ` NLPBlockData ` ] ( @ref ) . This object wraps an [ ` Nonlinear.Evaluator ` ] ( @ref ) and
352
+ includes other information such as constraint bounds and whether the evaluator
353
+ has a nonlinear objective. Create and set [ ` NLPBlockData ` ] ( @ref ) as follows:
354
+ ``` jldoctest nonlinear_developer
355
+ julia> block = MOI.NLPBlockData(evaluator);
356
+
357
+ julia> model = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}());
358
+
359
+ julia> MOI.set(model, MOI.NLPBlock(), block);
360
+ ```
361
+ !!! warning
362
+ Only call [ ` NLPBlockData ` ] ( @ref ) once you have finished modifying the
363
+ problem in ` model ` .
364
+
367
365
## Expression-graph representation
368
366
369
367
[ ` Nonlinear.Model ` ] ( @ref ) stores nonlinear expressions in
0 commit comments