Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
2.05k stars 523 forks source link

Using Windows version of gams from WSL #3147

Open frankpiedra opened 9 months ago

frankpiedra commented 9 months ago

Summary

I want to use gams as a solver with:

solver = SolverFactory('gams')

The problem is that I work from a Windows machine using WSL for the python-side, but gams is installed on the Windows-side. pyomo doesn't seems capable of finding gams executable, even when adding gams folder to my PATH or symlinking it to my ~/.local/bin folder. I can run gams from the WSL terminal with no problem though

Steps to reproduce the issue

from pyomo.opt import SolverFactory
solver = SolverFactory('gams')
solver.available()

Error Message

NameError                                 Traceback (most recent call last)
Cell In[32], [line 1](vscode-notebook-cell:?execution_count=32&line=1)
----> [1](vscode-notebook-cell:?execution_count=32&line=1) solver.available()

File [~/.virtualenvs/forest_problem/lib/python3.10/site-packages/pyomo/solvers/plugins/solvers/GAMS.py:667](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/d/Papers_propios/Paper3/Pyomo_Code_Debug/~/.virtualenvs/forest_problem/lib/python3.10/site-packages/pyomo/solvers/plugins/solvers/GAMS.py:667), in GAMSShell.available(self, exception_flag)
    [665](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/d/Papers_propios/Paper3/Pyomo_Code_Debug/~/.virtualenvs/forest_problem/lib/python3.10/site-packages/pyomo/solvers/plugins/solvers/GAMS.py:665) avail = self._run_simple_model(1)
    [666](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/d/Papers_propios/Paper3/Pyomo_Code_Debug/~/.virtualenvs/forest_problem/lib/python3.10/site-packages/pyomo/solvers/plugins/solvers/GAMS.py:666) if not avail and exception_flag:
--> [667](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/d/Papers_propios/Paper3/Pyomo_Code_Debug/~/.virtualenvs/forest_problem/lib/python3.10/site-packages/pyomo/solvers/plugins/solvers/GAMS.py:667)     raise NameError(
    [668](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/d/Papers_propios/Paper3/Pyomo_Code_Debug/~/.virtualenvs/forest_problem/lib/python3.10/site-packages/pyomo/solvers/plugins/solvers/GAMS.py:668)         "'gams' command failed to solve a simple model - "
    [669](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/d/Papers_propios/Paper3/Pyomo_Code_Debug/~/.virtualenvs/forest_problem/lib/python3.10/site-packages/pyomo/solvers/plugins/solvers/GAMS.py:669)         "GAMS shell solver functionality is not available."
    [670](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/d/Papers_propios/Paper3/Pyomo_Code_Debug/~/.virtualenvs/forest_problem/lib/python3.10/site-packages/pyomo/solvers/plugins/solvers/GAMS.py:670)     )
    [671](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/mnt/d/Papers_propios/Paper3/Pyomo_Code_Debug/~/.virtualenvs/forest_problem/lib/python3.10/site-packages/pyomo/solvers/plugins/solvers/GAMS.py:671) return avail

NameError: 'gams' command failed to solve a simple model - GAMS shell solver functionality is not available.

Information on your system

Pyomo version:6.7.0 Python version:3.10.12 Operating system: Windows 10 with Ubuntu WSL How Pyomo was installed (PyPI, conda, source): PyPI Solver (if applicable): gams CPLEX

mrmundt commented 9 months ago

This may seem like a silly question, but are you importing all of pyomo.environ as well? I am on a Mac, and when I run:

In [1]: from pyomo.opt import SolverFactory

In [2]: solver = SolverFactory('gams')

I get a warning:

WARNING: Failed to create solver with name 'gams': The solver plugin was not
registered. Please confirm that the 'pyomo.environ' package has been imported.
Traceback (most recent call last):
  File "/pyomo/opt/base/solvers.py", line 161, in __call__
    raise RuntimeError(
RuntimeError:   The solver plugin was not registered.
  Please confirm that the 'pyomo.environ' package has been imported.
frankpiedra commented 9 months ago

I'm not doing that import, should it be done when using gams? I didn't have problems on Windows

While debugging I replicated the command that's generated inside solver.available() (removing lo=0 to see the output) and I get a 145 code error:

$ /mnt/c/GAMS/45/gams /tmp/tmp595n4d7p/test.gms curdir=/tmp/tmp595n4d7p                        

--- Job test.gms Start 02/20/24 10:05:15 45.4.0 19dc3313 WEX-WEI x86 64bit/MS Windows                                   
*** Unable to open input file (RC=2) /tmp/tmp595n4d7p/test.gms                                                          
*** SysMsg: No such file or directory                                                                                   
--- Applying:                                                                                                               
C:\GAMS\45\gmsprmNT.txt                                                                                                 C:\Users\Usuario\Documents\GAMS\gamsconfig.yaml                                                                     
--- GAMS Parameters defined                                                                                                 
Input /tmp/tmp595n4d7p/test.gms                                                                                         
ScrDir \\wsl.localhost\Ubuntu\tmp\tmp595n4d7p\225a\                                                                     
SysDir C:\GAMS\45\                                                                                                     
CurDir \\wsl.localhost\Ubuntu\tmp\tmp595n4d7p\
*** Status: Terminated due to parameter errors 
--- Job test.gms Stop 02/20/24 10:05:15 elapsed 0:00:00.006
frankpiedra commented 9 months ago

Moving that tmp file to the Windows filesystem seems to make it solve correctly though

frankpiedra commented 9 months ago

Seems to be related to GAMS Windows executable not being able to read into WSL directories.

Steps to make a dirty fix

mrmundt commented 9 months ago

@frankpiedra I'm glad it's working for you now. We are actively in the process of redesigning the solver interfaces (see #3137 and #1030 ). I'm going to add this to the very long list of "solver-related issues" on that PEP issue.