summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2024-05-26 23:44:26 +0200
committerNao Pross <np@0hm.ch>2024-05-27 00:02:26 +0200
commite3a3d6e925a32174d6bd6724fa5074e091cedd38 (patch)
tree33d2f7c6cabb63edbd87b322349765665e729110
parentFix bug in ParametrizeExprMixin (diff)
downloadpolymatrix-e3a3d6e925a32174d6bd6724fa5074e091cedd38.tar.gz
polymatrix-e3a3d6e925a32174d6bd6724fa5074e091cedd38.zip
Add comment and exception for problematic edge case in from_any()
Diffstat (limited to '')
-rw-r--r--polymatrix/expression/from_.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/polymatrix/expression/from_.py b/polymatrix/expression/from_.py
index 65b636d..a3ee56e 100644
--- a/polymatrix/expression/from_.py
+++ b/polymatrix/expression/from_.py
@@ -7,12 +7,14 @@ from typing import Iterable, Any
import polymatrix.expression.init as init
+from polymatrix.expression.init import init_variable_expr
from polymatrix.expression.mixins.expressionbasemixin import ExpressionBaseMixin
from polymatrix.expression.typing import FromSupportedTypes
from polymatrix.expressionstate import ExpressionState
from polymatrix.statemonad import StateMonad
from polymatrix.polymatrix.mixins import PolyMatrixMixin
from polymatrix.utils.deprecation import deprecated
+from polymatrix.variable import Variable
from polymatrix.expression.expression import (
init_expression, Expression,
@@ -43,6 +45,29 @@ def from_any_or(value: FromSupportedTypes, value_if_not_supported: Any) -> Expre
elif isinstance(value, ExpressionBaseMixin):
return init_expression(value)
+ elif isinstance(value, Variable) and not isinstance(value, ExpressionBaseMixin):
+ # This happens when a variable is constructed somewhere using
+ # polymatrix.variable.init_variable. What should happen here?
+
+ # This is problematic because if there is already another variable in
+ # the state with the same name, but different type (eg a VariableExpr)
+ # it will throw an error.
+
+ # Also we need to consider the case when a variable was created by
+ # another package, e.g. is an optimization variable. What happens then?
+
+ # Should polymatrix.variable.VariableImpl even exist in the first
+ # place? It was part of the proposed architecture but I think it causes
+ # more problems than it is solving.
+
+ # Commented code below won't work
+
+ # value = init_variable_expr(value.name, shape=value.shape)
+ # return init_variable_expression(value)
+
+ raise NotImplementedError("You have encountered a convoluted edge case. "
+ "I'm very sorry it doesn't work yet.")
+
elif isinstance(value, int | float):
return from_number(value)