Closed andrewlee94 closed 3 years ago
I would like to echo this sentiment. It does not appear to be isolated to just this case. Just running the simple code below triggers the same error for me:
m = ConcreteModel()
m.x = Var(bounds=(1, 2))
def myfun(x):
return x
m.fun = ExternalFunction(function=myfun)
m.obj = Objective(expr=m.fun(m.x))
m.write("test.nl")
Traceback (most recent call last):
File "~/pyoexternal.py", line 143, in <module>
run()
File "~/pyoexternal.py", line 81, in run
m.write("test.nl")
File "~/anaconda3/envs/pyotest/lib/python3.7/site-packages/pyomo/core/base/block.py", line 1716, in write
io_options)
File "~/anaconda3/envs/pyotest/lib/python3.7/site-packages/pyomo/repn/plugins/ampl/ampl_.py", line 378, in __call__
include_all_variable_bounds=include_all_variable_bounds)
File "~/anaconda3/envs/pyotest/lib/python3.7/site-packages/pyomo/repn/plugins/ampl/ampl_.py", line 1587, in _print_model_NL
wrapped_repn.repn.nonlinear_expr)
File "~/anaconda3/envs/pyotest/lib/python3.7/site-packages/pyomo/repn/plugins/ampl/ampl_.py", line 568, in _print_nonlinear_terms_NL
elif arg.is_fixed():
AttributeError: 'int' object has no attribute 'is_fixed'
From what I can see, arg[0]
is an integer counter, and arg[1]
is a _VarData
instance in this case.
I have the same problem. A simple python external function does not work.
I have a case where I am using
ExternalFunctions
as part of my model. TheExternalFunction
takes three arguments:As the first argument is a constant, internal option I would like to provide it as a pure Python variable rather than a Pyomo component. However, if I provide the first argument as a Python
int
then I get the following error:The reason is that line 569 in ampl_.py presumes that the argument is a Pyomo component, and thus has the
is_fixed
attribute:Obviously, this precludes using anything other than a
Param
orVar
for these arguments. However, I would prefer to avoid creating a Pyomo component just for this purpose. Would it be possible to add support for non-Pyomo components are arguments toExternalFunctions
?