summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-05-27 14:29:33 +0200
committerNao Pross <np@0hm.ch>2024-05-27 14:29:33 +0200
commit1be9b7f8e1672d361f5c2853663bb1182a9663d0 (patch)
treeb0ac5c8a3f3d7e5772ac2fee5864ab7886d0e88e
parentFix bug when LP has no cost function (diff)
downloadsumofsquares-1be9b7f8e1672d361f5c2853663bb1182a9663d0.tar.gz
sumofsquares-1be9b7f8e1672d361f5c2853663bb1182a9663d0.zip
Clean up solve_problem, do not use PSatz by default
-rw-r--r--sumofsquares/__init__.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/sumofsquares/__init__.py b/sumofsquares/__init__.py
index 44dad85..a29b055 100644
--- a/sumofsquares/__init__.py
+++ b/sumofsquares/__init__.py
@@ -99,7 +99,7 @@ def make_problem(
cost: Expression | None = None,
constraints: Iterable[Constraint] = (),
solver: Solver = Solver.CVXOPT,
- psatz: type[Canonicalization] = PutinarPSatz
+ psatz: type[Canonicalization] | None = None,
) -> SOSProblem:
"""
Create a sum-of-squares optimization problem.
@@ -109,7 +109,10 @@ def make_problem(
elif cost is None:
cost = poly.from_number(0)
- return psatz(SOSProblem(cost, constraints, solver))
+ prob = SOSProblem(cost, constraints, solver)
+ if psatz is not None:
+ return psatz(SOSProblem(cost, constraints, solver))
+ return prob
def minimize(cost, *args, **kwargs) -> SOSProblem:
@@ -122,18 +125,14 @@ def maximize(cost, *args, **kwargs) -> SOSProblem:
return make_problem(-cost, *args, **kwargs)
-def solve_problem(
- cost: Expression,
- constraints: Iterable[Constraint] = (),
- solver: Solver = Solver.CVXOPT,
- verbose: bool = False,
- state: ExpressionState | None = None
- ) -> tuple[Problem, Result]:
+def solve_problem(*args, verbose: bool = True, **kwargs) -> tuple[Problem, Result]:
"""
Solve a sum-of-squares optimization problem.
- """
- if state is None:
- state = poly.make_state()
+ This function is just a shorthand for
+ .. py::
- prob = make_problem(cost, constraints, solver)
- return prob, prob.solve(verbose)
+ prob = sos.make_problem(...)
+ result = prob.solve(verbose)
+ """
+ prob = make_problem(*args, **kwargs)
+ return prob, prob.solve(verbose=verbose)