diff --git a/ixmp/model/gams.py b/ixmp/model/gams.py index 63b3835a6..151113084 100644 --- a/ixmp/model/gams.py +++ b/ixmp/model/gams.py @@ -1,6 +1,7 @@ import os from pathlib import Path from subprocess import check_call +from tempfile import TemporaryDirectory from ixmp.backend.jdbc import JDBCBackend @@ -76,15 +77,17 @@ class GAMSModel(Model): defaults = { 'model_file': '{model_name}.gms', 'case': "{scenario.model}_{scenario.scenario}", - 'in_file': '{model_name}_in.gdx', - 'out_file': '{model_name}_out.gdx', + 'in_file': str(Path('{temp_dir}', '{model_name}_in.gdx')), + 'out_file': str(Path('{temp_dir}', '{model_name}_out.gdx')), 'solve_args': ['--in="{in_file}"', '--out="{out_file}"'], + # Not formatted 'gams_args': ['LogOption=4'], 'check_solution': True, 'comment': None, 'equ_list': None, 'var_list': None, + 'use_temp_dir': True, } def __init__(self, name=None, **model_options): @@ -100,6 +103,12 @@ def run(self, scenario): self.scenario = scenario + if self.use_temp_dir: + # Create a temporary directory; automatically deleted at the end of + # the context + _temp_dir = TemporaryDirectory() + self.temp_dir = _temp_dir.name + def format(key): value = getattr(self, key) try: