diff --git a/pyomo/solver/IPOPT.py b/pyomo/solver/IPOPT.py index 79c33abcd6e..0029d638290 100644 --- a/pyomo/solver/IPOPT.py +++ b/pyomo/solver/IPOPT.py @@ -183,9 +183,9 @@ def _write_options_file(self, ostream: io.TextIOBase, options: Mapping): def _create_command_line(self, basename: str, config: IPOPTConfig): cmd = [ str(config.executable), - basename + '.nl', + os.path.join(basename, '.nl'), '-AMPL', - 'option_file_name=' + basename + '.opt', + 'option_file_name=' + os.path.join(basename, '.opt'), ] if 'option_file_name' in config.solver_options: raise ValueError( @@ -232,10 +232,11 @@ def solve(self, model, **kwds): if not os.path.exists(dname): os.mkdir(dname) basename = os.path.join(dname, model.name) - if os.path.exists(basename + '.nl'): + if os.path.exists(os.path.join(basename, '.nl')): raise RuntimeError( f"NL file with the same name {basename + '.nl'} already exists!" ) + print(basename, os.path.join(basename, '.nl')) with ( open(os.path.join(basename, '.nl'), 'w') as nl_file, open(os.path.join(basename, '.row'), 'w') as row_file, @@ -248,7 +249,7 @@ def solve(self, model, **kwds): col_file, symbolic_solver_labels=config.symbolic_solver_labels, ) - with open(basename + '.opt', 'w') as opt_file: + with open(os.path.join(basename, '.opt'), 'w') as opt_file: self._write_options_file( ostream=opt_file, options=config.solver_options ) @@ -288,7 +289,7 @@ def solve(self, model, **kwds): else: # TODO: Make a context manager out of this and open the file # to pass to the results, instead of doing this thing. - with open(basename + '.sol', 'r') as sol_file: + with open(os.path.join(basename, '.sol'), 'r') as sol_file: results = self._parse_solution(sol_file, self.info) if (