blob: 37d08e1a20ef2c9ee22e2dfa8bf11af8ea86c832 [file] [log] [blame]
Austin Schuh9049e202022-02-20 17:34:16 -08001.. _julia_interface:
2
3Julia
4======
5
6Load the module
7---------------
8The OSQP module can be load with
9
10.. code:: julia
11
12 using OSQP
13
14
15.. _julia_setup:
16
17Setup
18-----
19
20The solver is initialized by creating an OSQP Model
21
22.. code:: julia
23
24 m = OSQP.Model()
25
26The problem is specified in the setup phase by running
27
28.. code:: julia
29
30 OSQP.setup!(m; P=P, q=q, A=A, l=l, u=u, settings...)
31
32
33The arguments :code:`q`, :code:`l` and :code:`u` are :code:`Vector{Float64}`.
34The elements of :code:`l` and :code:`u` can be :math:`\pm \infty` ( using :code:`Inf`).
35
36The arguments :code:`P` and :code:`A` are sparse matrices of type :code:`SparseMatrixCSC`.
37Matrix :code:`P` can be either complete or just the upper triangular
38part. OSQP will make use of only the upper triangular part.
39If they are sparse matrices are in another format, the interface will attempt to convert them.
40There is no need to specify all the arguments.
41
42The argument :code:`settings` specifies the solver settings.
43Settings can also be passed as indipendent keyword arguments such as :code:`max_iter=1000`.
44The allowed parameters are defined in :ref:`solver_settings`.
45
46Solve
47-----
48
49The problem can be solved by
50
51.. code:: julia
52
53 results = OSQP.solve!(m)
54
55
56The output :code:`results` contains the primal solution :code:`x`, the dual solution :code:`y`, certificate of primal infeasibility :code:`prim_inf_cert`, certificate of dual infeasibility :code:`dual_inf_cert` and the :code:`info` object containing the solver statistics defined in the following table
57
58
59+-----------------------+------------------------------------------------+
60| Member | Description |
61+=======================+================================================+
62| :code:`iter` | Number of iterations |
63+-----------------------+------------------------------------------------+
64| :code:`status` | Solver status |
65+-----------------------+------------------------------------------------+
66| :code:`status_val` | Solver status value as in :ref:`status_values` |
67+-----------------------+------------------------------------------------+
68| :code:`status_polish` | Polishing status |
69+-----------------------+------------------------------------------------+
70| :code:`obj_val` | Objective value |
71+-----------------------+------------------------------------------------+
72| :code:`pri_res` | Primal residual |
73+-----------------------+------------------------------------------------+
74| :code:`dua_res` | Dual residual |
75+-----------------------+------------------------------------------------+
76| :code:`setup_time` | Setup time |
77+-----------------------+------------------------------------------------+
78| :code:`solve_time` | Solve time |
79+-----------------------+------------------------------------------------+
80| :code:`update_time` | Update time |
81+-----------------------+------------------------------------------------+
82| :code:`polish_time` | Polish time |
83+-----------------------+------------------------------------------------+
84| :code:`run_time` | Total run time: setup/update + solve + polish |
85+-----------------------+------------------------------------------------+
86| :code:`rho_estimate` | Optimal rho estimate |
87+-----------------------+------------------------------------------------+
88| :code:`rho_updates` | Number of rho updates |
89+-----------------------+------------------------------------------------+
90
91Note that if multiple solves are executed from single setup, then after the
92first one :code:`run_time` includes :code:`update_time` + :code:`solve_time`
93+ :code:`polish_time`.
94
95
96Update
97------
98Part of problem data and settings can be updated without requiring a new problem setup.
99
100Update problem vectors
101^^^^^^^^^^^^^^^^^^^^^^
102Vectors :code:`q`, :code:`l` and :code:`u` can be updated with new values :code:`q_new`, :code:`l_new` and :code:`u_new` by just running
103
104.. code:: julia
105
106 OSQP.update!(m; q=q_new, l=l_new, u=u_new)
107
108
109The user does not have to specify all the keyword arguments.
110
111
112Update problem matrices
113^^^^^^^^^^^^^^^^^^^^^^^^
114Matrices :code:`A` and :code:`P` can be updated by changing the value of their elements but not their sparsity pattern. The interface is designed to mimic the :ref:`C/C++ counterpart <c_cpp_update_data>` with the Julia 1-based indexing. Note that the new values of :code:`P` represent only the upper triangular part while :code:`A` is always represented as a full matrix.
115
116You can update the values of all the elements of :code:`P` by executing
117
118.. code:: julia
119
120 OSQP.update!(m, Px=Px_new)
121
122
123If you want to update only some elements, you can pass
124
125.. code:: julia
126
127 OSQP.update!(m, Px=Px_new, Px_idx=Px_new_idx)
128
129where :code:`Px_new_idx` is the vector of indices of mapping the elements of :code:`Px_new` to the original vector :code:`Px` representing the data of the sparse matrix :code:`P`.
130
131Matrix :code:`A` can be changed in the same way. You can also change both matrices at the same time by running, for example
132
133
134.. code:: julia
135
136 OSQP.update!(m, Px=Px_new, Px_idx=Px_new_idx, Ax=Ax_new, Ax=Ax_new_idx)
137
138
139
140
141
142.. _julia_update_settings:
143
144Update settings
145^^^^^^^^^^^^^^^
146
147Settings can be updated by running
148
149.. code:: julia
150
151 OSQP.update_settings!(m; new_settings)
152
153
154where :code:`new_settings` are the new settings specified as keyword arguments that can be updated which are marked with an * in :ref:`solver_settings`.
155
156
157Warm start
158----------
159
160OSQP automatically warm starts primal and dual variables from the previous QP solution. If you would like to warm start their values manually, you can use
161
162.. code:: julia
163
164 OSQP.warm_start!(m; x=x0, y=y0)
165
166
167where :code:`x0` and :code:`y0` are the new primal and dual variables.