# Python¶

## Setup¶

The solver is initialized by creating an OSQP object

```
m = osqp.OSQP()
```

The problem is specified in the setup phase by running

```
m.setup(P=P, q=q, A=A, l=l, u=u, **settings)
```

The arguments `q`

, `l`

and `u`

are numpy arrays. The elements of `l`

and `u`

can be \(\pm \infty\) ( using `numpy.inf`

).

The arguments `P`

and `A`

are scipy sparse matrices in CSC format. If they are sparse matrices are in another format, the interface will attemp to convert them. There is no need to specify all the arguments.

The keyword arguments `**settings`

specify the solver settings. The allowed parameters are defined in Solver settings.

## Solve¶

The problem can be solved by

```
results = m.solve()
```

The `results`

object contains the primal solution `x`

, the dual solution `y`

, certificate of primal infeasibility `prim_inf_cert`

, certificate of dual infeasibility `dual_inf_cert`

and the `info`

object containing the solver statistics defined in the following table

Member | Description |
---|---|

`iter` |
Number of iterations |

`status` |
Solver status |

`status_val` |
Solver status value as in Status values |

`status_polish` |
Polishing status |

`obj_val` |
Objective value |

`pri_res` |
Primal residual |

`dua_res` |
Dual residual |

`setup_time` |
Setup time |

`solve_time` |
Solve time |

`polish_time` |
Polish time |

`run_time` |
Total run time: setup + solve + polish |

`rho_estimate` |
Optimal rho estimate |

`rho_updates` |
Number of rho updates |

Note that if multiple solves are executed from single setup, then after the
first one `run_time`

includes only `solve_time`

+ `polish_time`

.

## Update¶

Part of problem data and settings can be updated without requiring a new problem setup.

### Update problem vectors¶

Vectors `q`

, `l`

and `u`

can be updated with new values `q_new`

, `l_new`

and `u_new`

by just running

```
m.update(q=q_new, l=l_new, u=u_new)
```

The user does not have to specify all the keyword arguments.

### Update settings¶

Settings can be updated by running

```
m.update_settings(**kwargs)
```

where `kwargs`

are the settings that can be updated which are marked with an * in Solver settings.

## Warm start¶

OSQP 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

```
m.warm_start(x=x0, y=y0)
```

where `x0`

and `y0`

are the new primal and dual variables.