Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_component_data_iter I think doesn't use sorted_robust? #1845

Closed
emma58 opened this issue Mar 1, 2021 · 3 comments · Fixed by #1852
Closed

_component_data_iter I think doesn't use sorted_robust? #1845

emma58 opened this issue Mar 1, 2021 · 3 comments · Fixed by #1852
Labels

Comments

@emma58
Copy link
Contributor

emma58 commented Mar 1, 2021

This is still related to #567, but now I'm confused. On master (after #1842), now the pprint statement in the following code works, but the writer still throws the TypeError because it cannot sort the tuples in m.ick:

from pyomo.environ import *

m = ConcreteModel()
m.ick = Set(initialize=[(1, 'str1'), ('str2', 'str3')], ordered=True,
            within=Any)
m.v = Var(m.ick, within=Binary)
m.obj = Objective(expr=m.v[1, 'str1'])
m.cons = Constraint(expr=m.v[1,'str1'] >= m.v['str2', 'str3'])

m.pprint() # this is okay
SolverFactory('gurobi').solve(m, tee=True) # this throws the error below
Traceback (most recent call last):
  File "sorting_stuff.py", line 11, in <module>
    SolverFactory('gurobi').solve(m, tee=True)
  File "/home/esjohn/src/pyomo/pyomo/opt/base/solvers.py", line 574, in solve
    self._presolve(*args, **kwds)
  File "/home/esjohn/src/pyomo/pyomo/solvers/plugins/solvers/GUROBI.py", line 230, in _presolve
    ILMLicensedSystemCallSolver._presolve(self, *args, **kwds)
  File "/home/esjohn/src/pyomo/pyomo/opt/solver/shellcmd.py", line 200, in _presolve
    OptSolver._presolve(self, *args, **kwds)
  File "/home/esjohn/src/pyomo/pyomo/opt/base/solvers.py", line 674, in _presolve
    **kwds)
  File "/home/esjohn/src/pyomo/pyomo/opt/base/solvers.py", line 740, in _convert_problem
    **kwds)
  File "/home/esjohn/src/pyomo/pyomo/opt/base/convert.py", line 100, in convert_problem
    problem_files, symbol_map = converter.apply(*tmp, **tmpkw)
  File "/home/esjohn/src/pyomo/pyomo/solvers/plugins/converter/model.py", line 82, in apply
    io_options=io_options)
  File "/home/esjohn/src/pyomo/pyomo/core/base/block.py", line 1812, in write
    io_options)
  File "/home/esjohn/src/pyomo/pyomo/repn/plugins/cpxlp.py", line 172, in __call__
    include_all_variable_bounds=include_all_variable_bounds)
  File "/home/esjohn/src/pyomo/pyomo/repn/plugins/cpxlp.py", line 451, in _print_model_LP
    Var, sort=sortOrder) )
  File "/home/esjohn/src/pyomo/pyomo/core/base/block.py", line 1435, in component_data_objects
    sort=sort):
  File "/home/esjohn/src/pyomo/pyomo/core/base/block.py", line 1361, in _component_data_iter
    _items = sorted(_items, key=itemgetter(0))
TypeError: '<' not supported between instances of 'str' and 'int'

Should _component_data_iter be using sorted_robust?

@michaelbynum
Copy link
Contributor

I think the LP writer can now be switched to not sort by default since sets are now ordered by default?

@michaelbynum
Copy link
Contributor

Although it probably still makes sense to fix Block._component_data_iter

@emma58
Copy link
Contributor Author

emma58 commented Mar 2, 2021

Yeah, this also means you can't call m.component_data_objects(Var, sort=SortComponents.deterministic) which is a thing that several transformations need to do, at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants