TemoaProject/temoa

Factory.services() is not defined

gschivley opened this issue · 6 comments

When trying to run the basic help command I ran into the error below. In this environment I'm running python 2.7 and pyomo 5.6.1.

$ python  temoa_model/ --help
Traceback (most recent call last):
  File "/Users/greg/miniconda3/envs/temoa-py2/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/Users/greg/miniconda3/envs/temoa-py2/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/Users/greg/Documents/GitHub/temoa/temoa_model/__main__.py", line 30, in <module>
    runModel()
  File "temoa_model/temoa_model.py", line 491, in runModel
    solver = TemoaSolver(model, dummy)
  File "temoa_model/temoa_run.py", line 85, in __init__
    self.temoa_setup()
  File "temoa_model/temoa_run.py", line 102, in temoa_setup
    self.options, config_flag = parse_args()
  File "temoa_model/temoa_run.py", line 463, in parse_args
    available_solvers, default_solver = get_solvers()
  File "temoa_model/temoa_run.py", line 423, in get_solvers
    for sname in SF.services():   # list of solver interface names
  File "/Users/greg/miniconda3/envs/temoa-py2/lib/python2.7/site-packages/pyutilib/factory/factory.py", line 77, in services
    raise RuntimeError("ERROR: Factory.services() is not defined.  Use Factory.__iter__() instead.")
RuntimeError: ERROR: Factory.services() is not defined.  Use Factory.__iter__() instead.

It looks like the function get_solvers is trying to determine the available solvers. Not sure what version of pyomo (or related packages) this works on but I ended up looping through a list of common solvers.

for sname in ['glpk', 'cplex', 'gurobi', 'cbc']: #SF.services():   # list of solver interface names

Obviously it's nicer to automatically find solvers but this works for now.

SolverFactory.services() is deprecated in newer versions of Pyomo. It has been replaced by the iter() method on the SolverFactory class. If the following change is made then the issue is resolved.

for sname in SF.services(): needs to become for sname in SF:

Hi Lucas -- Thanks for the tip. I tried with for sname in SF as you suggested, but get the following error:

File "temoa_model/temoa_run.py", line 421, in get_solvers for sname in SF: TypeError: 'new' object is not iterable

Any thoughts?

SolverFactoryClass inherits the Factory class from pyutilib. This is where __iter__() is defined. I have no issues with for sname in SF: in python2 or python3. It could be that the pyutilib package is not current.

I currently am running:

  • pyomo version 5.6.6 (this is the only difference between the environment.yml where pyomo is required to be 5.5.

  • pyutilib version 5.7.1

  • python version 2.7.16 and 3.7.3

I was able to recreate the issue described by TemoaProject by using pyutilib version 5.6.3. However, I was was able to use SolverFactory.services() to perform the same action using this environment.

In pyutilib versions up to 5.6.3, the SF.services() should work. Beginning in pyutilib version 5.6.4, the Factory class is created and .services() is deprecated and its functionality replaced with the __iter__() method. So using the most current pyutilib package (5.7.1) will allow for sname in SF:.

Thanks @lcford2 for helping to resolve this issue.