or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

core-solving.mddata-structures.mdindex.mdsolvers.mdutilities.md

solvers.mddocs/

0

# Individual Solver Interfaces

1

2

Direct access to specific QP solver implementations. Each solver function provides solver-specific parameters and optimizations while maintaining compatibility with the unified API structure.

3

4

## Capabilities

5

6

### Solver Discovery

7

8

Functions and variables for discovering available solvers and their capabilities.

9

10

```python { .api }

11

available_solvers: List[str] # All solvers available on the system

12

dense_solvers: List[str] # Solvers that work with dense matrices

13

sparse_solvers: List[str] # Solvers that work with sparse matrices

14

```

15

16

Usage example:

17

18

```python

19

from qpsolvers import available_solvers, dense_solvers, sparse_solvers

20

21

print("All available solvers:", available_solvers)

22

print("Dense matrix solvers:", dense_solvers)

23

print("Sparse matrix solvers:", sparse_solvers)

24

25

# Check if a specific solver is available

26

if "osqp" in available_solvers:

27

print("OSQP solver is available")

28

29

# Select solver based on matrix format

30

import numpy as np

31

P = np.eye(100) # dense matrix

32

solver = "proxqp" if "proxqp" in dense_solvers else dense_solvers[0]

33

```

34

35

### Open Source Solvers

36

37

High-performance open source QP solvers with different algorithmic approaches.

38

39

```python { .api }

40

def osqp_solve_qp(

41

P: Union[np.ndarray, spa.csc_matrix],

42

q: np.ndarray,

43

G: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

44

h: Optional[np.ndarray] = None,

45

A: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

46

b: Optional[np.ndarray] = None,

47

lb: Optional[np.ndarray] = None,

48

ub: Optional[np.ndarray] = None,

49

initvals: Optional[np.ndarray] = None,

50

verbose: bool = False,

51

**kwargs

52

) -> Optional[np.ndarray]:

53

"""

54

OSQP solver interface (Augmented Lagrangian, sparse matrices).

55

56

Solver-specific parameters via **kwargs:

57

- eps_abs: Absolute tolerance (default: 1e-3)

58

- eps_rel: Relative tolerance (default: 1e-3)

59

- max_iter: Maximum iterations (default: 4000)

60

- polish: Enable solution polishing (default: True)

61

- adaptive_rho: Enable adaptive penalty parameter (default: True)

62

"""

63

64

def proxqp_solve_qp(

65

P: Union[np.ndarray, spa.csc_matrix],

66

q: Union[np.ndarray, spa.csc_matrix],

67

G: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

68

h: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

69

A: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

70

b: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

71

lb: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

72

ub: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

73

initvals: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

74

verbose: bool = False,

75

backend: Optional[str] = None,

76

**kwargs

77

) -> Optional[np.ndarray]:

78

"""

79

ProxQP solver interface (Augmented Lagrangian, dense & sparse).

80

81

Solver-specific parameters:

82

- backend: "dense" or "sparse" (auto-detected if None)

83

- eps_abs: Absolute tolerance (default: 1e-9)

84

- eps_rel: Relative tolerance (default: 0.0)

85

- max_iter: Maximum iterations (default: 10000)

86

"""

87

88

def clarabel_solve_qp(

89

P: Union[np.ndarray, spa.csc_matrix],

90

q: np.ndarray,

91

G: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

92

h: Optional[np.ndarray] = None,

93

A: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

94

b: Optional[np.ndarray] = None,

95

lb: Optional[np.ndarray] = None,

96

ub: Optional[np.ndarray] = None,

97

initvals: Optional[np.ndarray] = None,

98

verbose: bool = False,

99

**kwargs

100

) -> Optional[np.ndarray]:

101

"""

102

Clarabel solver interface (Interior point, sparse matrices).

103

104

Written in Rust with Python bindings for high performance.

105

"""

106

107

def daqp_solve_qp(

108

P: np.ndarray,

109

q: np.ndarray,

110

G: Optional[np.ndarray] = None,

111

h: Optional[np.ndarray] = None,

112

A: Optional[np.ndarray] = None,

113

b: Optional[np.ndarray] = None,

114

lb: Optional[np.ndarray] = None,

115

ub: Optional[np.ndarray] = None,

116

initvals: Optional[np.ndarray] = None,

117

verbose: bool = False,

118

**kwargs

119

) -> Optional[np.ndarray]:

120

"""

121

DAQP solver interface (Active set, dense matrices).

122

123

Dual Active Set algorithm optimized for dense problems.

124

"""

125

```

126

127

### Classical Solvers

128

129

Well-established QP solvers widely used in academia and industry.

130

131

```python { .api }

132

def cvxopt_solve_qp(

133

P: Union[np.ndarray, spa.csc_matrix],

134

q: np.ndarray,

135

G: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

136

h: Optional[np.ndarray] = None,

137

A: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

138

b: Optional[np.ndarray] = None,

139

lb: Optional[np.ndarray] = None,

140

ub: Optional[np.ndarray] = None,

141

solver: Optional[str] = None,

142

initvals: Optional[np.ndarray] = None,

143

verbose: bool = False,

144

**kwargs

145

) -> Optional[np.ndarray]:

146

"""

147

CVXOPT solver interface (Interior point, dense & sparse).

148

149

Parameters:

150

- solver: CVXOPT solver backend ("conelp" default)

151

"""

152

153

def quadprog_solve_qp(

154

P: np.ndarray,

155

q: np.ndarray,

156

G: Optional[np.ndarray] = None,

157

h: Optional[np.ndarray] = None,

158

A: Optional[np.ndarray] = None,

159

b: Optional[np.ndarray] = None,

160

lb: Optional[np.ndarray] = None,

161

ub: Optional[np.ndarray] = None,

162

initvals: Optional[np.ndarray] = None,

163

verbose: bool = False,

164

**kwargs

165

) -> Optional[np.ndarray]:

166

"""

167

quadprog solver interface (Active set, dense matrices).

168

169

Requires positive definite P matrix.

170

"""

171

172

def qpoases_solve_qp(

173

P: np.ndarray,

174

q: np.ndarray,

175

G: Optional[np.ndarray] = None,

176

h: Optional[np.ndarray] = None,

177

A: Optional[np.ndarray] = None,

178

b: Optional[np.ndarray] = None,

179

lb: Optional[np.ndarray] = None,

180

ub: Optional[np.ndarray] = None,

181

initvals: Optional[np.ndarray] = None,

182

verbose: bool = False,

183

max_wsr: int = 1000,

184

time_limit: Optional[float] = None,

185

**kwargs

186

) -> Optional[np.ndarray]:

187

"""

188

qpOASES solver interface (Active set, dense matrices).

189

190

Parameters:

191

- max_wsr: Maximum working set recalculations

192

- time_limit: Time limit in seconds

193

"""

194

```

195

196

### Commercial Solvers

197

198

High-performance commercial solvers for production use.

199

200

```python { .api }

201

def gurobi_solve_qp(

202

P: np.ndarray,

203

q: np.ndarray,

204

G: Optional[np.ndarray] = None,

205

h: Optional[np.ndarray] = None,

206

A: Optional[np.ndarray] = None,

207

b: Optional[np.ndarray] = None,

208

lb: Optional[np.ndarray] = None,

209

ub: Optional[np.ndarray] = None,

210

initvals: Optional[np.ndarray] = None,

211

verbose: bool = False,

212

**kwargs

213

) -> Optional[np.ndarray]:

214

"""

215

Gurobi solver interface (Interior point, sparse matrices).

216

217

Requires Gurobi license. High performance for large problems.

218

"""

219

220

def mosek_solve_qp(

221

P: Union[np.ndarray, spa.csc_matrix],

222

q: np.ndarray,

223

G: Union[np.ndarray, spa.csc_matrix],

224

h: np.ndarray,

225

A: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

226

b: Optional[np.ndarray] = None,

227

lb: Optional[np.ndarray] = None,

228

ub: Optional[np.ndarray] = None,

229

initvals: Optional[np.ndarray] = None,

230

verbose: bool = False,

231

**kwargs

232

) -> Optional[np.ndarray]:

233

"""

234

MOSEK solver interface (Interior point, sparse matrices).

235

236

Requires MOSEK license. Note: G and h parameters are required.

237

"""

238

```

239

240

### Specialized Solvers

241

242

Solvers with specific algorithmic focuses or integration features.

243

244

```python { .api }

245

def highs_solve_qp(

246

P: Union[np.ndarray, spa.csc_matrix],

247

q: np.ndarray,

248

G: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

249

h: Optional[np.ndarray] = None,

250

A: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

251

b: Optional[np.ndarray] = None,

252

lb: Optional[np.ndarray] = None,

253

ub: Optional[np.ndarray] = None,

254

initvals: Optional[np.ndarray] = None,

255

verbose: bool = False,

256

**kwargs

257

) -> Optional[np.ndarray]:

258

"""

259

HiGHS solver interface (Active set, sparse matrices).

260

261

Open source solver known for linear and mixed-integer programming.

262

"""

263

264

def jaxopt_osqp_solve_qp(

265

P: Union[np.ndarray, spa.csc_matrix],

266

q: np.ndarray,

267

G: Optional[np.ndarray] = None,

268

h: Optional[np.ndarray] = None,

269

A: Optional[np.ndarray] = None,

270

b: Optional[np.ndarray] = None,

271

lb: Optional[np.ndarray] = None,

272

ub: Optional[np.ndarray] = None,

273

initvals: Optional[np.ndarray] = None,

274

verbose: bool = False,

275

**kwargs

276

) -> Optional[np.ndarray]:

277

"""

278

jaxopt.OSQP solver interface (Augmented Lagrangian, dense matrices).

279

280

JAX-based implementation with automatic differentiation support.

281

"""

282

283

def qpax_solve_qp(

284

P: Union[np.ndarray, spa.csc_matrix],

285

q: np.ndarray,

286

G: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

287

h: Optional[np.ndarray] = None,

288

A: Optional[Union[np.ndarray, spa.csc_matrix]] = None,

289

b: Optional[np.ndarray] = None,

290

lb: Optional[np.ndarray] = None,

291

ub: Optional[np.ndarray] = None,

292

initvals: Optional[np.ndarray] = None,

293

verbose: bool = False,

294

**kwargs

295

) -> Optional[np.ndarray]:

296

"""

297

qpax solver interface (Interior point, dense matrices).

298

299

JAX-based QP solver with GPU acceleration support.

300

"""

301

```

302

303

### Additional Solvers

304

305

```python { .api }

306

def piqp_solve_qp(...) -> Optional[np.ndarray]:

307

"""PIQP solver (Proximal interior point, dense & sparse)."""

308

309

def qpalm_solve_qp(...) -> Optional[np.ndarray]:

310

"""QPALM solver (Augmented Lagrangian, sparse matrices)."""

311

312

def scs_solve_qp(...) -> Optional[np.ndarray]:

313

"""SCS solver (Augmented Lagrangian, sparse matrices)."""

314

315

def sip_solve_qp(...) -> Optional[np.ndarray]:

316

"""SIP solver (Barrier Augmented Lagrangian, sparse matrices)."""

317

318

def ecos_solve_qp(...) -> Optional[np.ndarray]:

319

"""ECOS solver (Interior point, converts to SOCP)."""

320

321

def hpipm_solve_qp(...) -> Optional[np.ndarray]:

322

"""HPIPM solver (Interior point, dense matrices)."""

323

324

def kvxopt_solve_qp(...) -> Optional[np.ndarray]:

325

"""KVXOPT solver (Interior point, dense & sparse)."""

326

327

def qpswift_solve_qp(...) -> Optional[np.ndarray]:

328

"""qpSWIFT solver (Interior point, sparse matrices)."""

329

330

def nppro_solve_qp(...) -> Optional[np.ndarray]:

331

"""NPPro solver (Active set, dense matrices, unsupported)."""

332

```

333

334

## Usage Examples

335

336

### Solver Selection Strategy

337

338

```python

339

from qpsolvers import available_solvers, solve_qp

340

import numpy as np

341

342

# Define problem

343

P = np.eye(10)

344

q = np.ones(10)

345

346

# Try solvers in order of preference

347

preferred_solvers = ["proxqp", "osqp", "cvxopt"]

348

solver = next((s for s in preferred_solvers if s in available_solvers), available_solvers[0])

349

350

x = solve_qp(P, q, solver=solver)

351

```

352

353

### Solver-Specific Parameters

354

355

```python

356

from qpsolvers import osqp_solve_qp, proxqp_solve_qp

357

358

# OSQP with custom parameters

359

x_osqp = osqp_solve_qp(

360

P, q, G, h,

361

eps_abs=1e-6, # tighter tolerance

362

max_iter=10000, # more iterations

363

polish=True, # solution polishing

364

adaptive_rho=True # adaptive penalty

365

)

366

367

# ProxQP with backend selection

368

x_proxqp = proxqp_solve_qp(

369

P, q, G, h,

370

backend="sparse", # force sparse backend

371

eps_abs=1e-9, # very tight tolerance

372

max_iter=50000 # many iterations

373

)

374

```

375

376

### Performance Comparison

377

378

```python

379

import time

380

from qpsolvers import solve_qp, available_solvers

381

382

# Compare solver performance

383

results = {}

384

for solver in available_solvers:

385

try:

386

start_time = time.time()

387

x = solve_qp(P, q, G, h, solver=solver)

388

solve_time = time.time() - start_time

389

results[solver] = {

390

'time': solve_time,

391

'solution': x,

392

'success': x is not None

393

}

394

except Exception as e:

395

results[solver] = {'error': str(e)}

396

397

# Find fastest successful solver

398

successful = {k: v for k, v in results.items() if v.get('success', False)}

399

fastest = min(successful.items(), key=lambda x: x[1]['time'])

400

print(f"Fastest solver: {fastest[0]} ({fastest[1]['time']:.4f}s)")

401

```