Skip to content

Commit ea24c19

Browse files
authored
[docs] update to Documenter@1.0 (#204)
1 parent a7e3844 commit ea24c19

9 files changed

Lines changed: 228 additions & 166 deletions

File tree

.github/workflows/documentation.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ jobs:
1212
- uses: actions/checkout@v4
1313
- uses: julia-actions/setup-julia@latest
1414
with:
15-
# Build documentation on Julia 1.6
16-
version: '1.6'
15+
version: '1.10'
1716
- name: Install dependencies
1817
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
1918
- name: Build and deploy

docs/Project.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
4+
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
5+
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
6+
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
7+
ParametricOptInterface = "0ce4ce61-57bf-432b-a095-efac525d185e"
8+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
39

410
[compat]
5-
Documenter = "0.27"
11+
Documenter = "1"

docs/make.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
using Documenter
77
using ParametricOptInterface
88

9-
makedocs(
9+
Documenter.makedocs(;
1010
modules = [ParametricOptInterface],
11-
doctest = false,
1211
clean = true,
1312
# See https://github.com/JuliaDocs/Documenter.jl/issues/868
1413
format = Documenter.HTML(
@@ -28,9 +27,10 @@ makedocs(
2827
],
2928
"reference.md",
3029
],
30+
checkdocs = :none,
3131
)
3232

33-
deploydocs(
33+
Documenter.deploydocs(;
3434
repo = "github.com/jump-dev/ParametricOptInterface.jl.git",
3535
push_preview = true,
3636
)

docs/src/Examples/example.md

Lines changed: 76 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44

55
Let's write a step-by-step example of `POI` usage at the MOI level.
66

7-
First, we declare a [`ParametricOptInterface.Optimizer`](@ref) on top of a `MOI` optimizer. In the example, we consider `HiGHS` as the underlying solver:
7+
First, we declare a [`ParametricOptInterface.Optimizer`](@ref) on top of a `MOI`
8+
optimizer. In the example, we consider `HiGHS` as the underlying solver:
89

910
```@example moi1
10-
using HiGHS
11-
using MathOptInterface
12-
using ParametricOptInterface
13-
14-
const MOI = MathOptInterface
15-
const POI = ParametricOptInterface
16-
11+
import HiGHS
12+
import MathOptInterface as MOI
13+
import ParametricOptInterface as POI
1714
optimizer = POI.Optimizer(HiGHS.Optimizer())
1815
```
1916

20-
We declare the variable `x` as in a typical `MOI` model, and we add a non-negativity constraint:
17+
We declare the variable `x` as in a typical `MOI` model, and we add a
18+
non-negativity constraint:
2119

2220
```@example moi1
2321
x = MOI.add_variables(optimizer, 2)
@@ -26,15 +24,19 @@ for x_i in x
2624
end
2725
```
2826

29-
Now, let's consider 3 `MOI.Parameter`. Two of them, `y`, `z`, will be placed in the constraints and one, `w`, in the objective function. We'll start all three of them with a value equal to `0`:
27+
Now, let's consider 3 `MOI.Parameter`. Two of them, `y`, `z`, will be placed in
28+
the constraints and one, `w`, in the objective function. We'll start all three
29+
of them with a value equal to `0`:
3030

3131
```@example moi1
3232
w, cw = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0))
3333
y, cy = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0))
3434
z, cz = MOI.add_constrained_variable(optimizer, MOI.Parameter(0.0))
3535
```
3636

37-
Let's add the constraints. Notice that we treat parameters and variables in the same way when building the functions that will be placed in some set to create a constraint (`Function-in-Set`):
37+
Let's add the constraints. Notice that we treat parameters and variables in the
38+
same way when building the functions that will be placed in some set to create a
39+
constraint (`Function-in-Set`):
3840

3941
```@example moi1
4042
cons1 = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([2.0, 1.0, 3.0], [x[1], x[2], y]), 0.0)
@@ -59,61 +61,87 @@ MOI.get(optimizer, MOI.TerminationStatus())
5961
MOI.get(optimizer, MOI.PrimalStatus())
6062
```
6163

62-
Given the optimized solution, we check that its value is, as expected, equal to `28/3`, and the solution vector `x` is `[4/3, 4/3]`:
64+
Given the optimized solution, we check that its value is, as expected, equal to
65+
`28/3`, and the solution vector `x` is `[4/3, 4/3]`:
6366

6467
```@example moi1
6568
isapprox(MOI.get(optimizer, MOI.ObjectiveValue()), 28/3, atol = 1e-4)
6669
isapprox(MOI.get(optimizer, MOI.VariablePrimal(), x[1]), 4/3, atol = 1e-4)
6770
isapprox(MOI.get(optimizer, MOI.VariablePrimal(), x[2]), 4/3, atol = 1e-4)
6871
```
6972

70-
We can also retrieve the dual values associated to each parameter, **as they are all additive**:
73+
We can also retrieve the dual values associated to each parameter,
74+
**as they are all additive**:
7175

7276
```@example moi1
7377
MOI.get(optimizer, MOI.ConstraintDual(), cy)
7478
MOI.get(optimizer, MOI.ConstraintDual(), cz)
7579
MOI.get(optimizer, MOI.ConstraintDual(), cw)
7680
```
7781

78-
Notice the direct relationship in this case between the parameters' duals and the associated constraints' duals.
79-
The `y` parameter, for example, only appears in the `cons1`. If we compare their duals, we can check that the dual of `y` is equal to its coefficient in `cons1` multiplied by the constraint's dual itself, as expected:
82+
Notice the direct relationship in this case between the parameters' duals and
83+
the associated constraints' duals.
84+
85+
The `y` parameter, for example, only appears in the `cons1`. If we compare
86+
their duals, we can check that the dual of `y` is equal to its coefficient in
87+
`cons1` multiplied by the constraint's dual itself, as expected:
8088

8189
```@example moi1
82-
isapprox(MOI.get(optimizer, MOI.ConstraintDual(), cy), 3*MOI.get(optimizer, MOI.ConstraintDual(), ci1), atol = 1e-4)
90+
isapprox(
91+
MOI.get(optimizer, MOI.ConstraintDual(), cy),
92+
3*MOI.get(optimizer, MOI.ConstraintDual(), ci1);
93+
atol = 1e-4,
94+
)
8395
```
8496

85-
The same is valid for the remaining parameters. In case a parameter appears in more than one constraint, or both some constraints and in the objective function, its dual will be equal to the linear combination of the functions' duals multiplied by the respective coefficients.
97+
The same is valid for the remaining parameters. In case a parameter appears in
98+
more than one constraint, or both some constraints and in the objective
99+
function, its dual will be equal to the linear combination of the functions'
100+
duals multiplied by the respective coefficients.
101+
102+
So far, we only added some parameters that had no influence at first in solving
103+
the model. Let's change the values associated to each parameter to assess its
104+
implications.
86105

87-
So far, we only added some parameters that had no influence at first in solving the model. Let's change the values associated to each parameter to assess its implications.
88-
First, we set the value of parameters `y` and `z` to `1.0`. Notice that we are changing the feasible set of the decision variables:
106+
First, we set the value of parameters `y` and `z` to `1.0`. Notice that we are
107+
changing the feasible set of the decision variables:
89108

90109
```@example moi1
91110
MOI.set(optimizer, POI.ParameterValue(), y, 1.0)
92111
MOI.set(optimizer, POI.ParameterValue(), z, 1.0)
93112
```
94113

95-
However, if we check the optimized model now, there will be no changes in the objective function value or the in the optimized decision variables:
114+
However, if we check the optimized model now, there will be no changes in the
115+
objective function value or the in the optimized decision variables:
96116

97117
```@example moi1
98118
isapprox.(MOI.get(optimizer, MOI.ObjectiveValue()), 28/3, atol = 1e-4)
99119
isapprox.(MOI.get(optimizer, MOI.VariablePrimal(), x[1]), 4/3, atol = 1e-4)
100120
isapprox.(MOI.get(optimizer, MOI.VariablePrimal(), x[2]), 4/3, atol = 1e-4)
101121
```
102122

103-
Although we changed the parameter values, we didn't optimize the model yet. Thus, **to apply the parameters' changes, the model must be optimized again**:
123+
Although we changed the parameter values, we didn't optimize the model yet.
124+
Thus, **to apply the parameters' changes, the model must be optimized again**:
104125

105126
```@example moi1
106127
MOI.optimize!(optimizer)
107128
```
108129

109-
The `MOI.optimize!()` function handles the necessary updates, properly fowarding the new outer model (`POI` model) additions to the inner model (`MOI` model) which will be handled by the solver. Now we can assess the updated optimized information:
130+
The `MOI.optimize!()` function handles the necessary updates, properly fowarding
131+
the new outer model (`POI` model) additions to the inner model (`MOI` model)
132+
which will be handled by the solver. Now we can assess the updated optimized
133+
information:
110134

111135
```@example moi1
112136
isapprox.(MOI.get(optimizer, MOI.ObjectiveValue()), 3.0, atol = 1e-4)
113137
MOI.get.(optimizer, MOI.VariablePrimal(), x) == [0.0, 1.0]
114138
```
115139

116-
If we update the parameter `w`, associated to the objective function, we are simply adding a constant to it. Notice how the new objective function is precisely equal to the previous one plus the new value of `w`. In addition, as we didn't update the feasible set, the optimized decision variables remain the same.
140+
If we update the parameter `w`, associated to the objective function, we are
141+
simply adding a constant to it. Notice how the new objective function is
142+
precisely equal to the previous one plus the new value of `w`. In addition, as
143+
we didn't update the feasible set, the optimized decision variables remain the
144+
same.
117145

118146
```@example moi1
119147
MOI.set(optimizer, POI.ParameterValue(), w, 2.0)
@@ -128,7 +156,8 @@ MOI.get.(optimizer, MOI.VariablePrimal(), x) == [0.0, 1.0]
128156

129157
Let's write a step-by-step example of `POI` usage at the JuMP level.
130158

131-
First, we declare a `Model` on top of a `Optimizer` of an underlying solver. In the example, we consider `HiGHS` as the underlying solver:
159+
First, we declare a `Model` on top of a `Optimizer` of an underlying solver. In
160+
the example, we consider `HiGHS` as the underlying solver:
132161

133162
```@example jump1
134163
using HiGHS
@@ -146,15 +175,18 @@ We declare the variable `x` as in a typical `JuMP` model:
146175
@variable(model, x[i = 1:2] >= 0)
147176
```
148177

149-
Now, let's consider 3 `MOI.Parameter`. Two of them, `y`, `z`, will be placed in the constraints and one, `w`, in the objective function. We'll start all three of them with a value equal to `0`:
178+
Now, let's consider 3 `MOI.Parameter`. Two of them, `y`, `z`, will be placed in
179+
the constraints and one, `w`, in the objective function. We'll start all three
180+
of them with a value equal to `0`:
150181

151182
```@example jump1
152183
@variable(model, y in MOI.Parameter(0.0))
153184
@variable(model, z in MOI.Parameter(0.0))
154185
@variable(model, w in MOI.Parameter(0.0))
155186
```
156187

157-
Let's add the constraints. Notice that we treat parameters the same way we treat variables when writing the model:
188+
Let's add the constraints. Notice that we treat parameters the same way we treat
189+
variables when writing the model:
158190

159191
```@example jump1
160192
@constraint(model, c1, 2x[1] + x[2] + 3y <= 4)
@@ -175,7 +207,8 @@ termination_status(model)
175207
primal_status(model)
176208
```
177209

178-
Given the optimized solution, we check that its value is, as expected, equal to `28/3`, and the solution vector `x` is `[4/3, 4/3]`:
210+
Given the optimized solution, we check that its value is, as expected, equal to
211+
`28/3`, and the solution vector `x` is `[4/3, 4/3]`:
179212

180213
```@example jump1
181214
isapprox(objective_value(model), 28/3)
@@ -320,56 +353,36 @@ Users that just want everything to work can use the default value `POI.ONLY_CONS
320353
Let's start with a simple quadratic problem
321354

322355
```@example moi2
323-
using Ipopt
324-
using MathOptInterface
325-
using ParametricOptInterface
326-
327-
const MOI = MathOptInterface
328-
const POI = ParametricOptInterface
329-
330-
optimizer = POI.Optimizer(Ipopt.Optimizer())
331-
332-
x = MOI.add_variable(optimizer)
333-
y = MOI.add_variable(optimizer)
334-
MOI.add_constraint(optimizer, x, MOI.GreaterThan(0.0))
335-
MOI.add_constraint(optimizer, y, MOI.GreaterThan(0.0))
336-
337-
cons1 = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([2.0, 1.0], [x, y]), 0.0)
338-
ci1 = MOI.add_constraint(optimizer, cons1, MOI.LessThan(4.0))
339-
cons2 = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 2.0], [x, y]), 0.0)
340-
ci2 = MOI.add_constraint(optimizer, cons2, MOI.LessThan(4.0))
341-
342-
MOI.set(optimizer, MOI.ObjectiveSense(), MOI.MAX_SENSE)
343-
obj_func = MOI.ScalarQuadraticFunction(
344-
[MOI.ScalarQuadraticTerm(1.0, x, x)
345-
MOI.ScalarQuadraticTerm(1.0, y, y)],
346-
MOI.ScalarAffineTerm{Float64}[],
347-
0.0,
348-
)
349-
MOI.set(
350-
optimizer,
351-
MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{Float64}}(),
352-
obj_func,
353-
)
356+
import Ipopt
357+
import MathOptInterface as MOI
358+
import ParametricOptInterface as POI
359+
model = POI.Optimizer(Ipopt.Optimizer())
360+
x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0))
361+
y, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(0.0))
362+
ci1 = MOI.add_constraint(model, 2.0 * x + 1.0 * y, MOI.LessThan(4.0))
363+
ci2 = MOI.add_constraint(model, 1.0 * x + 2.0 * y, MOI.LessThan(4.0))
364+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
365+
obj_func = 1.0 * x * x + 1.0 * y * y
366+
MOI.set(model, MOI.ObjectiveFunction{typeof(obj_func)}(), obj_func)
354367
```
355368

356369
To multiply a parameter in a quadratic term, the user will
357370
need to use the `POI.QuadraticObjectiveCoef` model attribute.
358371

359372
```@example moi2
360-
p = first(MOI.add_constrained_variable.(optimizer, MOI.Parameter(1.0)))
361-
MOI.set(optimizer, POI.QuadraticObjectiveCoef(), (x,y), p)
373+
p, _ = MOI.add_constrained_variable.(model, MOI.Parameter(1.0))
374+
MOI.set(model, POI.QuadraticObjectiveCoef(), (x, y), p)
362375
```
363376

364377
This function will add the term `p*xy` to the objective function.
365378
It's also possible to multiply a scalar affine function to the quadratic term.
366379

367380
```@example moi2
368-
MOI.set(optimizer, POI.QuadraticObjectiveCoef(), (x,y), 2p+3)
381+
MOI.set(model, POI.QuadraticObjectiveCoef(), (x, y), 2 * p + 3)
369382
```
370383

371-
This will set the term `(2p+3)*xy` to the objective function (it overwrites the last set).
372-
Then, just optimize the model.
384+
This will set the term `(2p+3)*xy` to the objective function (it overwrites the
385+
last set). Then, just optimize the model.
373386

374387
```@example moi2
375388
MOI.optimize!(model)

0 commit comments

Comments
 (0)