Skip to content

Support for Integrals on hierarchical models #764

Open
@blnicho

Description

@blnicho

A bug report submitted to the forum found that Integral components cannot be declared on Blocks:

Here is a minimal example :

from pyomo.dae.integral import Integral
from pyomo.environ import *
from pyomo.dae.contset import ContinuousSet

m = ConcreteModel(name='m')
m.time = ContinuousSet(bounds=(0,1), name='time')

m.block = Block()
m.block.x = Var(m.time)

def _instant_obj(m, t):
    return m.x[t]
m.block.int_cost = Integral(m.time, wrt=m.time, rule=_instant_obj)   # this line raise an error

Here is the Traceback of the Error :

Traceback (most recent call last):
  File "/home/admin/Documents/02-Recherche/02-Python/lms2/lms2/template/bug_Integrals_blocks.py", line 20, in <module>
    m.block.int_cost = Integral(m.time, wrt=m.time, rule=_instant_obj)
  File "/home/admin/Documents/02-Recherche/02-Python/lms2/venv/lib/python3.6/site-packages/pyomo/core/base/block.py", line 540, in __setattr__
    self.add_component(name, val)
  File "/home/admin/Documents/02-Recherche/02-Python/lms2/venv/lib/python3.6/site-packages/pyomo/core/base/block.py", line 980, in add_component
    val.construct(data)
  File "/home/admin/Documents/02-Recherche/02-Python/lms2/venv/lib/python3.6/site-packages/pyomo/core/base/expression.py", line 410, in construct
    self.add(None, _init_rule(self._parent()))
  File "/home/admin/Documents/02-Recherche/02-Python/lms2/venv/lib/python3.6/site-packages/pyomo/dae/integral.py", line 135, in _trap_rule
    ds = sorted(m.find_component(wrt.local_name))
TypeError: 'NoneType' object is not iterable

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'.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions