summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-06-05 16:30:17 +0200
committerNao Pross <np@0hm.ch>2024-06-05 16:30:17 +0200
commitaa6dc1f005ddc3684208fbb989760fcbb913fc29 (patch)
treefa8da398ec4607dd018e9e4e4baa0b956c3651b4
parentFix construction of PutinarPSatz multipliers (diff)
downloadsumofsquares-aa6dc1f005ddc3684208fbb989760fcbb913fc29.tar.gz
sumofsquares-aa6dc1f005ddc3684208fbb989760fcbb913fc29.zip
Remove concatenation of constraints in SOSProblem.apply
Diffstat (limited to '')
-rw-r--r--sumofsquares/problems.py47
1 files changed, 29 insertions, 18 deletions
diff --git a/sumofsquares/problems.py b/sumofsquares/problems.py
index 2ba9ee4..a646d0e 100644
--- a/sumofsquares/problems.py
+++ b/sumofsquares/problems.py
@@ -262,26 +262,29 @@ class SOSProblem(Problem):
raise NotImplementedError(f"Cannot process constraint of type {type(c)} (yet).")
# Convert Expressions into PolyMatrix objects
- # Concatenate constraints so that there is only a big constraint per cone.
pm_constraints: list[Constraint[PolyMatrixMixin]] = []
+ for c in constraints:
+ state, pm = c.expression.apply(state)
+ pm_constraints.append(replace(c, expression=pm))
# TODO: can we get rid of for loop inside InternalSOSProblem.to_conic_problem?
- for (ctype, group) in groupby(constraints, key=type):
- if ctype in (EqualToZero, NonNegative):
- state, pm = poly.v_stack((c.expression for c in group)).apply(state)
- pm_constraints.append(ctype(pm))
+ # Concatenate constraints so that there is only a big constraint per cone.
+ # for (ctype, group) in groupby(constraints, key=type):
+ # if ctype in (EqualToZero, NonNegative):
+ # state, pm = poly.v_stack((c.expression for c in group)).apply(state)
+ # pm_constraints.append(ctype(pm))
- elif ctype is PositiveSemiDefinite:
- expressions = (c.expression for c in group)
- state, pm = poly.block_diag(expressions).apply(state)
- pm_constraints.append(ctype(pm))
+ # elif ctype is PositiveSemiDefinite:
+ # expressions = (c.expression for c in group)
+ # state, pm = poly.block_diag(expressions).apply(state)
+ # pm_constraints.append(ctype(pm))
- elif ctype is ExponentialCone:
- state, pm = poly.v_stack((c.expression for c in group)).apply(state)
- pm_constraints.append(ctype(pm))
+ # elif ctype is ExponentialCone:
+ # state, pm = poly.v_stack((c.expression for c in group)).apply(state)
+ # pm_constraints.append(ctype(pm))
- else:
- raise NotImplementedError(f"Cannot process constraint of type {ctype} (yet).")
+ # else:
+ # raise NotImplementedError(f"Cannot process constraint of type {ctype} (yet).")
return state, InternalSOSProblem(cost, tuple(pm_constraints),
tuple(variables), polynomial_variables,
@@ -386,7 +389,7 @@ class InternalSOSProblem(Problem):
elif isinstance(c, ExponentialCone):
# Interpret row-wise
- dims["ep"].extend(1 for _ in range(nrows))
+ dims["ep"].extend(tuple(1 for _ in range(nrows)))
for i in range(nrows):
constraints["e"].append((
tuple(m[i, :] for m in linear),
@@ -400,10 +403,18 @@ class InternalSOSProblem(Problem):
raise ValueError("Optimization problem is unconstrained!")
if verbose:
- # print("Conic problem has shapes: \n"
- # f"\t {q.shape = }\n")
- pass
+ logstr = ""
+ if P is not None:
+ logstr += f"{P.shape = }\n"
+
+ if q is not None:
+ logstr += f"{q.shape = }\n"
+
+ for ctype, d in dims.items():
+ if d:
+ logstr += f" {ctype}: {sum(d)} {tuple(d)}\n"
+ print("Conic problem has shapes: \n", logstr)
return ConicProblem(P=P, q=q, constraints=constraints,
dims=dims, is_qp=is_qp,