idaes-pse
idaes-pse copied to clipboard
Error when generating kriging model expression
Summary
The expression generation in krigging model gives error when using scalar variable
Steps to reproduce the issue
# example.py
import pandas
import pyomo.environ as pyo
from idaes.surrogate.pysmo import kriging
x = [0, 30, 50, 70, 100]
y = [0, 40, 70, 80, 100]
df = pandas.DataFrame(data=zip(x, y), columns=['x', 'y'])
krg_init = kriging.KrigingModel(df)
krg_init.training()
m1 = pyo.ConcreteModel()
m1.v1 = pyo.ScalarVar(initialize=0)
m1.s1 = pyo.Set(initialize=[0,1])
m1.v2 = pyo.Var(m1.s1, initialize=0)
expr = krg_init.generate_expression([m1.v2[0]])
expr = krg_init.generate_expression([m1.v1])
Error Message
tests/pyomo_test/model3/test_block_temp.py:None (tests/pyomo_test/model3/test_block_temp.py)
test_block_temp.py:19: in <module>
expr = krg_init.generate_expression([m1.v1])
/home/admin/.virtualenvs/empc/lib/python3.9/site-packages/idaes/surrogate/pysmo/kriging.py:551: in generate_expression
curr_term = exp(-curr_term)
/home/admin/.virtualenvs/empc/lib/python3.9/site-packages/pyomo/core/expr/current.py:179: in exp
return _generate_intrinsic_function_expression(arg, 'exp', math.exp)
pyomo/core/expr/numeric_expr.pyx:1985: in pyomo.core.expr.numeric_expr._generate_intrinsic_function_expression
???
pyomo/core/expr/numvalue.pyx:616: in pyomo.core.expr.numvalue.NumericValue.__float__
???
E TypeError: Implicit conversion of Pyomo numeric value (- 0.5925597988832185*(0.01*v1)**2) to float is disabled.
E This error is often the result of using Pyomo components as arguments to
E one of the Python built-in math module functions when defining
E expressions. Avoid this error by using Pyomo-provided math functions or
E explicitly resolving the numeric value using the Pyomo value() function.
pyomo/core/expr/numvalue.pyx:616: TypeError
Information on your system
Pyomo version: 6.4.1 Python version: 3.9 Operating system: Debian Solver (if applicable):
Additional information
@vova292 This is not exactly an error: PySMO's initial implementation was designed to be compatible with indexed variables only.
However, we recently made changes to PySMO that makes it compatible with scalar variables, so updating to the latest version of IDAES should solve your problem. Your example runs just fine on my end with the latest IDAES.
Please let me know if it still doesn't work for you after the update.
@vova292, closing this though feel free to re-open if needed.