TemoaProject / temoa

Tools for Energy Model Optimization and Analysis
http://temoacloud.com
GNU General Public License v2.0
84 stars 48 forks source link

Factory.services() is not defined #6

Closed gschivley closed 5 years ago

gschivley commented 5 years ago

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.
gschivley commented 5 years ago

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.

lcford2 commented 5 years ago

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:

TemoaProject commented 5 years ago

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?

lcford2 commented 5 years ago

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:

lcford2 commented 5 years ago

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

TemoaProject commented 5 years ago

Thanks @lcford2 for helping to resolve this issue.