diff options
Diffstat (limited to '')
-rw-r--r-- | sumofsquares/problems.py | 47 |
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, |