Skip to content

Commit f0ce71f

Browse files
committed
Fix docs
1 parent 020a92f commit f0ce71f

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

Diff for: docs/src/submodules/Nonlinear/overview.md

+26-28
Original file line numberDiff line numberDiff line change
@@ -302,35 +302,17 @@ However, we cannot call gradient terms such as
302302
[`eval_objective_gradient`](@ref) because [`Nonlinear.ExprGraphOnly`](@ref) does
303303
not have the capability to differentiate a nonlinear expression.
304304

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`.
310309
```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,
328312
Nonlinear.SparseReverseMode(),
329313
[x],
330314
)
331-
332-
julia> data
333-
NonlinearData with available features:
315+
Nonlinear.Evaluator with available features:
334316
* :Grad
335317
* :Jac
336318
* :JacVec
@@ -339,7 +321,7 @@ NonlinearData with available features:
339321

340322
However, before calling anything, we need to call [`initialize`](@ref):
341323
```jldoctest nonlinear_developer
342-
julia> MOI.initialize(data, [:Grad, :Jac, :JacVec, :ExprGraph])
324+
julia> MOI.initialize(evaluator, [:Grad, :Jac, :JacVec, :ExprGraph])
343325
```
344326

345327
Now we can call methods like [`eval_objective`](@ref):
@@ -348,7 +330,7 @@ julia> x = [1.0]
348330
1-element Vector{Float64}:
349331
1.0
350332
351-
julia> MOI.eval_objective(data, x)
333+
julia> MOI.eval_objective(evaluator, x)
352334
7.268073418273571
353335
```
354336
and [`eval_objective_gradient`](@ref):
@@ -357,13 +339,29 @@ julia> grad = [NaN]
357339
1-element Vector{Float64}:
358340
NaN
359341
360-
julia> MOI.eval_objective_gradient(data, grad, x)
342+
julia> MOI.eval_objective_gradient(evaluator, grad, x)
361343
362344
julia> grad
363345
1-element Vector{Float64}:
364346
1.909297426825682
365347
```
366348

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+
367365
## Expression-graph representation
368366

369367
[`Nonlinear.Model`](@ref) stores nonlinear expressions in

0 commit comments

Comments
 (0)