summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-05-11 16:24:03 +0200
committerNao Pross <np@0hm.ch>2024-05-11 16:24:03 +0200
commit6769fe24ce41fb53b86d13eb4df38d36e330b6a8 (patch)
tree154f98e9fd5710e677be2fc6eb74d6db2993f344
parentBugfix in CVXOpt interface when problem is QP (diff)
downloadsumofsquares-6769fe24ce41fb53b86d13eb4df38d36e330b6a8.tar.gz
sumofsquares-6769fe24ce41fb53b86d13eb4df38d36e330b6a8.zip
Create SolverError exception
-rw-r--r--sumofsquares/error.py3
-rw-r--r--sumofsquares/solver/cvxopt.py23
2 files changed, 15 insertions, 11 deletions
diff --git a/sumofsquares/error.py b/sumofsquares/error.py
index 1f30b2a..70c00cc 100644
--- a/sumofsquares/error.py
+++ b/sumofsquares/error.py
@@ -5,6 +5,9 @@ Errors and exceptions raised by the sum of squares package.
class NotSupportedBySolver(Exception):
""" The chosen solver cannot solve this problem. """
+class SolverError(Exception):
+ """ The solver failed to solve the problem """
+
class AlgebraicError(Exception):
""" TODO """
diff --git a/sumofsquares/solver/cvxopt.py b/sumofsquares/solver/cvxopt.py
index 7be4e0d..4534a8c 100644
--- a/sumofsquares/solver/cvxopt.py
+++ b/sumofsquares/solver/cvxopt.py
@@ -6,9 +6,6 @@ import numpy as np
import math
from collections import UserDict
-from numpy.typing import NDArray
-from dataclasses import dataclass, fields
-from pprint import pprint
import polymatrix as poly
from polymatrix.expression.expression import Expression
@@ -16,7 +13,7 @@ from polymatrix.polymatrix.index import MonomialIndex, VariableIndex
from ..abc import Problem, SolverInfo
from ..constraints import NonNegative, EqualToZero, PositiveSemiDefinite, ExponentialCone
-from ..error import NotSupportedBySolver
+from ..error import NotSupportedBySolver, SolverError
from ..variable import OptVariable
@@ -166,13 +163,17 @@ def solve_sos_cone(prob: Problem, verbose: bool = False,
# info = {}
info = {"q": q, "G": G, "h": h, "A": A, "b": b, "dims": dims}
- if is_qp:
- P = cvxopt.matrix(P)
- info |= cvxopt.solvers.coneqp(P=P, q=q, G=G, h=h, A=A, b=b,
- dims=dims, *args, **kwargs)
- else:
- info |= cvxopt.solvers.conelp(c=q, G=G, h=h, A=A, b=b,
- *args, **kwargs)
+ try:
+ if is_qp:
+ P = cvxopt.matrix(P)
+ info |= cvxopt.solvers.coneqp(P=P, q=q, G=G, h=h, A=A, b=b,
+ dims=dims, *args, **kwargs)
+ else:
+ info |= cvxopt.solvers.conelp(c=q, G=G, h=h, A=A, b=b,
+ *args, **kwargs)
+
+ except Exception as e:
+ raise SolverError("CVXOpt can't solve this problem.") from e
results = {}