Skip to content

Commit e46731d

Browse files
authored
Fix/osqp (#280)
* fix settings for osqp version 1 * update tox * update tox * update release notes * update release notes * try with arm * remove workaround
1 parent 0097ef4 commit e46731d

4 files changed

Lines changed: 29 additions & 19 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ jobs:
1010
strategy:
1111
fail-fast: false
1212
matrix:
13-
os: [ubuntu-latest, macos-13, windows-latest]
14-
python-version: ["3.9", "3.11", "3.13"]
13+
os: [ubuntu-latest, macos-latest, windows-latest]
14+
python-version: ["3.10", "3.14"]
1515

1616
steps:
1717
- uses: actions/checkout@v4

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
Next Release
44
-----
55

6+
1.9.0
7+
-----
8+
* enable Python 3.14
9+
* bump OSQP to 1.0+
10+
611
1.8.3
712
-----
813
* fix the objective offset test for compatibility with Debian sid

src/optlang/hybrid_interface.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,18 @@ def __init__(self):
110110
def osqp_settings(self):
111111
"""Map internal settings to OSQP settings."""
112112
settings = {
113-
"linsys_solver": "qdldl",
113+
"solver_type": "direct",
114114
"max_iter": self.settings["iteration_limit"],
115115
"eps_abs": self.settings["optimality_tolerance"],
116116
"eps_rel": self.settings["optimality_tolerance"],
117117
"eps_prim_inf": self.settings["primal_inf_tolerance"],
118118
"eps_dual_inf": self.settings["dual_inf_tolerance"],
119-
"polish": True,
119+
"polishing": True,
120120
"verbose": int(self.settings["verbose"] > 0),
121121
"scaling": 10 if self.settings["presolve"] is True else 0,
122-
"time_limit": self.settings["time_limit"],
122+
"time_limit": (
123+
self.settings["time_limit"] if self.settings["time_limit"] > 0 else 1e10
124+
),
123125
"adaptive_rho": True,
124126
"rho": 1.0,
125127
"alpha": 1.6,
@@ -154,9 +156,15 @@ def solve_osqp(self):
154156
sp = self.build(add_variable_constraints=True)
155157
solver = osqp.OSQP()
156158
log.debug("Setting up OSQP problem.")
157-
solver.setup(
158-
P=sp.P, q=sp.q, A=sp.A, l=sp.bounds[:, 0], u=sp.bounds[:, 1], **settings
159-
)
159+
try:
160+
solver.setup(
161+
P=sp.P, q=sp.q, A=sp.A, l=sp.bounds[:, 0], u=sp.bounds[:, 1], **settings
162+
)
163+
except osqp.interface.OSQPException as err:
164+
reason = ",".join(str(a) for a in err.args)
165+
if len(err.args) > 0 and err.args[0] == 4:
166+
reason = "non-convex problem"
167+
raise ValueError(f"OSQP error: {reason}")
160168
if self._solution is not None:
161169
if self.still_valid(sp):
162170
solver.warm_start(x=self._solution["x"], y=self._solution["y"])
@@ -244,9 +252,7 @@ def still_valid(self, problem):
244252
"""Check if previous solutions is still feasible."""
245253
nv, nc = len(self.variables), len(self.constraints)
246254
b = problem.bounds
247-
if len(self._solution["x"]) != nv or len(
248-
self._solution["y"]
249-
) != nc + nv:
255+
if len(self._solution["x"]) != nv or len(self._solution["y"]) != nc + nv:
250256
return False
251257
c = problem.A.dot(self._solution["x"])
252258
tol = self.settings["primal_inf_tolerance"]

tox.ini

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ envlist =
1010

1111
[gh-actions]
1212
python =
13-
3.9: safety, py39, py39-symengine
14-
3.11: safety, py311, py311-symengine
15-
3.13: safety, py313, py313-symengine
13+
3.10: safety, py310, py310-symengine
14+
3.14: safety, py314, py314-symengine
1615

1716
;[testenv]
1817
;deps =
@@ -32,11 +31,11 @@ deps =
3231
pytest-cov
3332
scipy <1.15.0 # until https://github.com/scipy/scipy/issues/22257 is fixed
3433
numpy >=1.13
35-
osqp >=0.6.2
36-
mip >=1.9.1; python_version < "3.13"
34+
osqp >=1.1.0
35+
mip >=1.9.1; python_version < "3.14"
3736
highspy >=1.5.3
38-
cplex; python_version < "3.12"
39-
gurobipy; python_version < "3.13"
37+
cplex
38+
gurobipy
4039
symengine: symengine
4140
passenv = CI
4241
commands =
@@ -70,7 +69,7 @@ deps=
7069
pip>=21.1
7170
safety
7271
commands=
73-
safety check --full-report -i 70612
72+
safety check --full-report
7473

7574
[testenv:mypy]
7675
skip_install = True

0 commit comments

Comments
 (0)