Skip to content

Error when solving a block that has a constraint that contains a variable not in the block #1864

Open
@eslickj

Description

@eslickj

This is just a request for improvement in the exception message or logging when there is an exception that happens because you try to solve a block that has a constraint that references a variable that is not in the block. It looks like there is some code in

def _symbolMapKeyError(self, err, model, map, vars):
to provide a better message but what I see is below, and if you don't know why it happens it can be hard to understand.

Traceback (most recent call last):
  File "proto_gt.py", line 78, in <module>
    m, solver = main()
  File "proto_gt.py", line 69, in main
    m.fs.mx1.initialize()
  File "c:\users\eslickj\git\idaes-pse\idaes\generic_models\unit_models\mixer.py", line 940, in initialize
    res = opt.solve(blk, tee=slc.tee)
  File "c:\users\eslickj\git\pyomo\pyomo\opt\base\solvers.py", line 575, in solve
    self._presolve(*args, **kwds)
  File "c:\users\eslickj\git\pyomo\pyomo\opt\solver\shellcmd.py", line 198, in _presolve
    OptSolver._presolve(self, *args, **kwds)
  File "c:\users\eslickj\git\pyomo\pyomo\opt\base\solvers.py", line 675, in _presolve
    **kwds)
  File "c:\users\eslickj\git\pyomo\pyomo\opt\base\solvers.py", line 746, in _convert_problem
    **kwds)
  File "c:\users\eslickj\git\pyomo\pyomo\opt\base\convert.py", line 105, in convert_problem
    problem_files, symbol_map = converter.apply(*tmp, **tmpkw)
  File "c:\users\eslickj\git\pyomo\pyomo\solvers\plugins\converter\model.py", line 191, in apply
    io_options=io_options)
  File "c:\users\eslickj\git\pyomo\pyomo\core\base\block.py", line 1814, in write
    io_options)
  File "c:\users\eslickj\git\pyomo\pyomo\repn\plugins\ampl\ampl_.py", line 370, in __call__
    include_all_variable_bounds=include_all_variable_bounds)
  File "c:\users\eslickj\git\pyomo\pyomo\repn\plugins\ampl\ampl_.py", line 994, in _print_model_NL
    list(self_varID_map[id(var)] for var in linear_vars),
  File "c:\users\eslickj\git\pyomo\pyomo\repn\plugins\ampl\ampl_.py", line 994, in <genexpr>
    list(self_varID_map[id(var)] for var in linear_vars),
KeyError: 2041211129752

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