Open blnicho opened 5 years ago
Hi there, I am adding here some additional information about this issue. And describing new strange behaviour, I think this might be linked but may be worth a new issue (?)
from pyomo.environ import ConcreteModel, Var, Block, Expression, TransformationFactory
from pyomo.dae import ContinuousSet, Integral
# an expression for test
def _instant_obj(m, t):
return m.x[t]
m = ConcreteModel(name='m')
m.b = Block()
m.t = ContinuousSet(bounds=(0, 1))
m.b.x = Var(m.t)
m.b.exp = Expression(m.t, rule=_instant_obj)
# m.b.int_cost = Integral(m.t, wrt=m.t, rule=lambda m, t: m.exp[t]) # Not working --> issue#764
m.int_cost = Integral(m.t, wrt=m.t, rule=lambda m, t: m.b.exp[t]) # Working cause the integral is declared within the block that holds the "time"
TransformationFactory('dae.finite_difference').apply_to(m, nfe=4)
m.pprint()
del m
m = ConcreteModel(name='m')
m.b = Block()
m.b.t = ContinuousSet(bounds=(0, 1))
m.b.x = Var(m.b.t)
m.b.exp = Expression(m.b.t, rule=_instant_obj)
m.b.int_cost = Integral(m.b.t, wrt=m.b.t, rule=lambda m, t: m.exp[t]) # Seems to work cause the block 'b' holds the time set.
# m.int_cost = Integral(m.b.t, wrt=m.b.t, rule=lambda m, t: m.b.exp[t]) # Not working --> same behaviour as in issue#764
TransformationFactory('dae.finite_difference').apply_to(m, nfe=4)
m.pprint()
Output :
int_cost : Size=1, Index=None
Key : Expression
None : 0.5*(b.x[1] + b.x[0])
In this case, the integral is defined within the block as expected but the Transformation does not behave the same as the first case, and depends on whether the integral is declared within m or m.b.
I am not sure we are facing one or multiple issues, I hope it will help...
Greetings
A bug report submitted to the forum found that Integral components cannot be declared on Blocks:
Here is a minimal example :
Here is the Traceback of the Error :
It seems that m.find_component(wrt.local_name) is empty. So an error is raised when trying to sort it. It is empty cause he is trying to find the component 'time' in the block 'b', whereas it is a component of the model 'm'.