Open frankpiedra opened 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.
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
Moving that tmp file to the Windows filesystem seems to make it solve correctly though
Seems to be related to GAMS Windows executable not being able to read into WSL directories.
gams.exe
into some PATH directory, in my case ln -s /mnt/c/GAMS/45/gams.exe ~/.local/bin/gams
tmpdir
:
SolverFactory('gams').solve(
model, solver='CPLEX',
tee=True,
add_options=['option reslim=30; option optcr = 0.0;'],
tmpdir="wsl.localhost/Ubuntu/mnt/d/tmpmodels",
keepfiles=True
)
tmp
directory and can't be setted up
! GAMS.py lines 677-695
def _run_simple_model(self, n):
solver_exec = self.executable()
if solver_exec is None:
return False
tmpdir = mkdtemp()
try:
test = os.path.join(tmpdir, 'test.gms')
with open(test, 'w') as FILE:
FILE.write(self._simple_model(n))
result = subprocess.run(
[solver_exec, test, "curdir=" + tmpdir, 'lo=0'],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
# This little hack:
return True
# return not result.returncode
finally:
shutil.rmtree(tmpdir)
return False
@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.
Summary
I want to use
gams
as a solver with: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 thoughSteps to reproduce the issue
Error Message
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