Добавление контекста: я использую Python и IPOPT в качестве числового решателя. Модель оптимизации построена с использованием Egret.
Мне удалось запустить код, обратившись к значению переменной с помощью функции value(), но я собираюсь сделать не это. Входные данные гауссовского процесса не являются фиксированными параметрами — они являются фактическими переменными модели оптимизации. Я попытался построить x с помощью ComponentMap() как:
Код: Выделить всё
# Construct the input
m.X = ComponentMap()
m.X[0] = a
m.X[1] = b
m.X[2] = c
m.X[3] = d
# Create ROGP object
xvar = rogp.pyomo_to_np(m.X).T
# Get GP prediction
gp = gp_models[0]
mu = gp.predict(xvar)[0]
Код: Выделить всё
ERROR: Rule failed when generating expression for Constraint gp_stability with
index 0: PyomoException: Cannot convert non-constant Pyomo expression (0 >> m.x = Var()
>>> if m.x >= 1:
... pass
and
>>> m.y = Var()
>>> if m.y in [m.x, m.y]:
... pass
would both cause this exception.
ERROR: Constructing component 'gp_stability' from data=None failed:
PyomoException: Cannot convert non-constant Pyomo expression (0 >> m.x = Var()
>>> if m.x >= 1:
... pass
and
>>> m.y = Var()
>>> if m.y in [m.x, m.y]:
... pass
would both cause this exception.
Код: Выделить всё
(GP_env) (base) -@Vincenzos-MacBook-Pro GP % cd /Users/-/Documents/GitHub/GP ; /usr/bin/env /Users/-/anaconda3/envs/GP_env/bin/python /Users/-/.vscode/extensions/ms-python.debugpy-2024.14.0-darwin-
arm64/bundled/libs/debugpy/adapter/../../debugpy/launcher 52854 -- /Users/-/Documents/GitHub/GP/Egret-main/script.py
/Users/-/Documents/GitHub/GP/GPY_MIMO_RIVANNA.py:396: SyntaxWarning: tuple indices must be integers or slices, not tuple; perhaps you missed a comma?
output = model(valid_x.reshape((int(n_interval**3)//2, sup-inf, 5)[0,:]))
Loading GP model 0...
Backend macosx is interactive backend. Turning interactive mode on.
xvar shape: (1, 4)
Expected input shape for GP: (800, 4)
xvar content: [[
]]
ERROR: Rule failed when generating expression for Constraint gp_stability with
index 0: PyomoException: Cannot convert non-constant Pyomo expression (0 >> m.x = Var()
>>> if m.x >= 1:
... pass
and
>>> m.y = Var()
>>> if m.y in [m.x, m.y]:
... pass
would both cause this exception.
ERROR: Constructing component 'gp_stability' from data=None failed:
PyomoException: Cannot convert non-constant Pyomo expression (0 >> m.x = Var()
>>> if m.x >= 1:
... pass
and
>>> m.y = Var()
>>> if m.y in [m.x, m.y]:
... pass
would both cause this exception.
Подробнее здесь: https://stackoverflow.com/questions/793 ... tpyomorogp