Skip to content

We happily build logical expressions with DisjunctDatas as nodes.... #2855

Open
@emma58

Description

@emma58

Summary

You can put a DisjunctData in an exactly expression and not have the expression system complain. It doesn't currently die until it hits the logical to disjunctive walker.

Steps to reproduce the issue

from pyomo.environ import *
from pyomo.gdp import *

m = ConcreteModel()
m.x = Var()
m.y = Var()
m.disjunction1 = Disjunction(expr=[
    [m.x == 0],
    [m.x <= 7],
])
m.disjunction2 = Disjunction(expr=[
    [m.y == 0],
    [m.y <= 8],
])

m.lc = LogicalConstraint(expr=exactly(1, [m.disjunction1.disjuncts[0],
                                          m.disjunction2.disjuncts[0]]))
m.lc.pprint()

TransformationFactory('contrib.logical_to_disjunctive').apply_to(m)

Error Message

lc : Size=1, Index=None, Active=True
    Key  : Body                                                               : Active
    None : exactly(1: [disjunction1_disjuncts[0], disjunction2_disjuncts[0]]) :   True
exactly(1: [disjunction1_disjuncts[0], disjunction2_disjuncts[0]])
Traceback (most recent call last):
  File "/home/esjohn/src/distribution/distribution/models/continuous_time_gdp/agh.py", line 20, in <module>
    TransformationFactory('contrib.logical_to_disjunctive').apply_to(m)
  File "/home/esjohn/src/pyomo/pyomo/core/base/transformation.py", line 75, in apply_to
    self._apply_to(model, **kwds)
  File "/home/esjohn/src/pyomo/pyomo/contrib/cp/transform/logical_to_disjunctive_program.py", line 77, in _apply_to
    self._transform_block(t, model, visitor, transBlocks)
  File "/home/esjohn/src/pyomo/pyomo/contrib/cp/transform/logical_to_disjunctive_program.py", line 109, in _transform_block
    self._transform_constraint(
  File "/home/esjohn/src/pyomo/pyomo/contrib/cp/transform/logical_to_disjunctive_program.py", line 92, in _transform_constraint
    self._transform_constraintData(constraint[i], visitor, transBlocks)
  File "/home/esjohn/src/pyomo/pyomo/contrib/cp/transform/logical_to_disjunctive_program.py", line 129, in _transform_constraintData
    visitor.walk_expression(logical_constraint.expr)
  File "/home/esjohn/src/pyomo/pyomo/core/expr/visitor.py", line 269, in walk_expression
    result = self._process_node(root, RECURSION_LIMIT)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/esjohn/src/pyomo/pyomo/core/expr/visitor.py", line 465, in _process_node_bx
    tmp = self.beforeChild(node, child, child_idx)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/esjohn/src/pyomo/pyomo/contrib/cp/transform/logical_to_disjunctive_walker.py", line 261, in beforeChild
    return _before_child_dispatcher[child.__class__](self, child)
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
KeyError: <class 'pyomo.gdp.disjunct._DisjunctData'>

Information on your system

Pyomo version: main branch
Python version: 3.11
Operating system: linux
How Pyomo was installed (PyPI, conda, source): source
Solver (if applicable):

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions