Repository: Pyomo/pyomo

Issue:
GAMS interface ignoring tmpdir keyword argument
Despite using `solve(tmpdir='/tmp/')`, the `225a/` directory was still created in the current working directory. My understanding is that `tmpdir=None` would use the system default temporary directory anyways, so this was surprising.

Platform: Ubuntu 16.04 LTS, Python 2.7, commit 16c30973c77503f6daddfd9c31c219138b1533ac (up to date with master)


Discussion:
@qtothec Is this still an issue? Does it happen with the api or the shell, or both?
The default, which I think is shell. As far as I know, this still happens. Test it by starting a large model and then killing it to see if you're left with a 225 folder in the current working directory.
Is this with `keepfiles=False`?
Correct.

On Thu, May 24, 2018, 18:18 Grant Seastream <notifications@github.com>
wrote:

> Is this with keepfiles=False?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <https://github.com/Pyomo/pyomo/issues/359#issuecomment-391883528>, or mute
> the thread
> <https://github.com/notifications/unsubscribe-auth/AFowrBgMiHoKjlDqfiSIRxkzkUX8gNo3ks5t1zG7gaJpZM4SQauj>
> .
>

@qtothec I found the issue. The `225x` directories are created by GAMS as its own temporary files and are typically deleted after a run completes, and take the form of `225a`, `225b`, and so on. They're called the scratch directory. Refs: https://support.gams.com/gams:the_225_-_subdirectories

The solver only specified to write the temp files we cared about in the provided `tmpdir`, those being the gms, lst, and put files. That's why the `225` dir was still showing up.

If desired, a solution to this is to specify the `curdir` option on the command line call to be the provided `tmpdir`, and then reorganize all the other file names in the code to be consistent with this choice. This way the `225` directory will be nested under the `tmpdir`. Thoughts?
@gseastream: Yes: I think that changing the working directory for the gams subprocess is the right way to go.

Resolving patch:
diff --git a/pyomo/solvers/plugins/solvers/GAMS.py b/pyomo/solvers/plugins/solvers/GAMS.py
--- a/pyomo/solvers/plugins/solvers/GAMS.py
+++ b/pyomo/solvers/plugins/solvers/GAMS.py
@@ -714,12 +714,15 @@ def solve(self, *args, **kwds):
             os.makedirs(tmpdir)
             newdir = True
 
-        output_filename = os.path.join(tmpdir, 'model.gms')
-        lst_filename = os.path.join(tmpdir, 'output.lst')
-        statresults_filename = os.path.join(tmpdir, 'resultsstat.dat')
+        output = "model.gms"
+        output_filename = os.path.join(tmpdir, output)
+        lst = "output.lst"
+        lst_filename = os.path.join(tmpdir, lst)
 
-        io_options['put_results'] = os.path.join(tmpdir, 'results')
-        results_filename = os.path.join(tmpdir, 'results.dat')
+        put_results = "results"
+        io_options["put_results"] = put_results
+        results_filename = os.path.join(tmpdir, put_results + ".dat")
+        statresults_filename = os.path.join(tmpdir, put_results + "stat.dat")
 
         if isinstance(model, IBlockStorage):
             # Kernel blocks have slightly different write method
@@ -744,7 +747,7 @@ def solve(self, *args, **kwds):
         ####################################################################
 
         exe = self.executable()
-        command = [exe, output_filename, 'o=' + lst_filename]
+        command = [exe, output, "o=" + lst, "curdir=" + tmpdir]
         if tee and not logfile:
             # default behaviour of gams is to print to console, for
             # compatability with windows and *nix we want to explicitly log to


Test patch: