diff options
author | Nao Pross <np@0hm.ch> | 2024-05-27 12:10:19 +0200 |
---|---|---|
committer | Nao Pross <np@0hm.ch> | 2024-05-27 12:10:19 +0200 |
commit | d5751aadddaaa18600aa6b2e294c32f2e2bb9299 (patch) | |
tree | 750888bd96b02543fc05b3565182118cb272cec6 | |
parent | Create aliases maximize and minimize for make_problem (diff) | |
download | sumofsquares-d5751aadddaaa18600aa6b2e294c32f2e2bb9299.tar.gz sumofsquares-d5751aadddaaa18600aa6b2e294c32f2e2bb9299.zip |
Temporary fix of ConicResult.value_of(v) for v that have shapes that are expression
Diffstat (limited to '')
-rw-r--r-- | sumofsquares/problems.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/sumofsquares/problems.py b/sumofsquares/problems.py index 02d5a1e..2800423 100644 --- a/sumofsquares/problems.py +++ b/sumofsquares/problems.py @@ -15,6 +15,7 @@ from typing import Any, Sequence from typing_extensions import override from polymatrix.expression.expression import Expression, VariableExpression +from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin from polymatrix.expressionstate import ExpressionState from polymatrix.polymatrix.mixins import PolyMatrixMixin from polymatrix.polymatrix.index import MonomialIndex @@ -121,8 +122,16 @@ class ConicResult(Result): var = var.underlying if var not in self.values: - raise KeyError(f"There is no result for the variable {var}, " - "was the problem successfully solved?") + # FIXME: this is a temporary fix here. + if isinstance(var.shape, ExpressionBaseMixin): + state = poly.make_state() + state, shapepm = var.shape.apply(state) + shape = (shapepm.at(0,0).constant(), shapepm.at(1,0).constant()) + var = replace(var, shape=shape) + + if var not in self.values: + raise KeyError(f"There is no result for the variable {var}. " + f"Was the problem successfully solved?") return self.values[var] |