summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 = {}