|
1 | 1 | # Tutorial |
2 | 2 |
|
3 | | -## Input |
4 | | - |
5 | | -RipQP uses the package [QuadraticModels.jl](https://github.com/JuliaSmoothOptimizers/QuadraticModels.jl) to model |
6 | | -convex quadratic problems. |
7 | | - |
8 | | -Here is a basic example: |
9 | | - |
10 | | -```@example QM |
11 | | -using QuadraticModels, LinearAlgebra, SparseMatricesCOO |
12 | | -Q = [6. 2. 1. |
13 | | - 2. 5. 2. |
14 | | - 1. 2. 4.] |
15 | | -c = [-8.; -3; -3] |
16 | | -A = [1. 0. 1. |
17 | | - 0. 2. 1.] |
18 | | -b = [0.; 3] |
19 | | -l = [0.;0;0] |
20 | | -u = [Inf; Inf; Inf] |
21 | | -QM = QuadraticModel(c, SparseMatrixCOO(tril(Q)), A=SparseMatrixCOO(A), lcon=b, ucon=b, |
22 | | - lvar=l, uvar=u, c0=0., name="QM") |
23 | | -``` |
24 | | - |
25 | | -Once your `QuadraticModel` is loaded, you can simply solve it RipQP: |
26 | | - |
27 | | -```@example QM |
28 | | -using RipQP |
29 | | -stats = ripqp(QM) |
30 | | -println(stats) |
31 | | -``` |
32 | | - |
33 | | -The `stats` output is a |
34 | | -[GenericExecutionStats](https://juliasmoothoptimizers.github.io/SolverCore.jl/dev/reference/#SolverCore.GenericExecutionStats). |
35 | | - |
36 | | -It is also possible to use the package [QPSReader.jl](https://github.com/JuliaSmoothOptimizers/QPSReader.jl) in order to |
37 | | -read convex quadratic problems in MPS or SIF formats: |
38 | | - |
39 | | -```julia |
40 | | -using QPSReader, QuadraticModels |
41 | | -QM = QuadraticModel(readqps("QAFIRO.SIF")) |
42 | | -``` |
43 | | - |
44 | | -## Logging |
45 | | - |
46 | | -RipQP displays some logs at each iterate. |
47 | | - |
48 | | -You can deactivate logging with |
49 | | - |
50 | | -```julia |
51 | | -stats = ripqp(QM, display = false) |
52 | | -``` |
53 | | - |
54 | | -It is also possible to get a history of several quantities such as the primal and dual residuals and the relative primal-dual gap. |
55 | | -These quantites are available in the dictionnary `solver_specific` of the `stats`. |
56 | | - |
57 | | -```julia |
58 | | -stats = ripqp(QM, history = true) |
59 | | -pddH = stats.solver_specific[:pddH] |
60 | | -``` |
61 | | - |
62 | | -## Change configuration and tolerances |
63 | | - |
64 | | -You can use `RipQP` without scaling with: |
65 | | - |
66 | | -```julia |
67 | | -stats = ripqp(QM, scaling = false) |
68 | | -``` |
69 | | - |
70 | | -You can also change the [`RipQP.InputTol`](@ref) type to change the tolerances for the stopping criteria: |
71 | | - |
72 | | -```julia |
73 | | -stats = ripqp(QM, itol = InputTol(max_iter = 100, ϵ_rb = 1.0e-4), scaling = false) |
74 | | -``` |
75 | | - |
76 | | -## Save the Interior-Point system |
77 | | - |
78 | | -At every iteration, RipQP solves two linear systems with the default Predictor-Corrector method (the affine system and the corrector-centering system), or one linear system with the Infeasible Path-Following method. |
79 | | - |
80 | | -To save these systems, you can use: |
81 | | - |
82 | | -```julia |
83 | | -w = SystemWrite(write = true, name="test_", kfirst = 4, kgap=3) |
84 | | -stats1 = ripqp(QM, w = w) |
85 | | -``` |
86 | | - |
87 | | -This will save one matrix and the associated two right-hand sides of the PC method every three iterations starting at iteration four. |
88 | | -Then, you can read the saved files with: |
89 | | - |
90 | | -```julia |
91 | | -using DelimitedFiles, MatrixMarket |
92 | | -K = MatrixMarket.mmread("test_K_iter4.mtx") |
93 | | -rhs_aff = readdlm("test_rhs_iter4_aff.rhs", Float64)[:] |
94 | | -rhs_cc = readdlm("test_rhs_iter4_cc.rhs", Float64)[:] |
95 | | -``` |
96 | | - |
97 | | -## Timers |
98 | | - |
99 | | -You can see the elapsed time with: |
100 | | - |
101 | | -```julia |
102 | | -stats1.elapsed_time |
103 | | -``` |
104 | | - |
105 | | -For more advanced timers you can use [`TimerOutputs.jl`](https://github.com/KristofferC/TimerOutputs.jl): |
106 | | - |
107 | | -```julia |
108 | | -using TimerOutputs |
109 | | -TimerOutputs.enable_debug_timings(RipQP) |
110 | | -reset_timer!(RipQP.to) |
111 | | -stats = ripqp(QM) |
112 | | -TimerOutputs.complement!(RipQP.to) # print complement of timed sections |
113 | | -show(RipQP.to, sortby = :firstexec) |
114 | | -``` |
| 3 | +Check an [introduction to RipQP](https://jso-docs.github.io/introduction-to-ripqp/) and more tutorials on the [JSO tutorials page](https://juliasmoothoptimizers.github.io/tutorials/). |
0 commit comments