convexengineering / gpkit

Geometric programming for engineers
http://gpkit.readthedocs.org
MIT License
206 stars 40 forks source link

RuntimeWarning: could not read mskexpopt output file #1516

Closed vignesh99 closed 4 years ago

vignesh99 commented 4 years ago

I run into this particular error [1] while using gpkit which occurs at the statement model.solve(). I tried reading the docs, but I don't seem to understand why this error (Runtime Warning) is occurring or how to debug it. Upon adding an implicit constraint (since it is taken care of with the way constraints are written and just assumes all variables are positive) to the original problem I get the following error [2]. Could someone please tell as to what these error mean and is there some way to solve them?

[1] /usr/local/lib/python3.6/dist-packages/gpkit/constraints/prog_factories.py in solvefn(self, solver, verbosity, skipsweepfailures, kwargs) 122 else: 123 self.program, progsolve = genfunction(self) --> 124 result = progsolve(solver, verbosity, kwargs) 125 solution.append(result) 126 solution.program = self.program

/usr/local/lib/python3.6/dist-packages/gpkit/constraints/gp.py in solve(self, solver, verbosity, warn_on_check, process_result, gen_result, kwargs) 166 sys.stdout = self.solver_log # CAPTURED 167 solver_out = solverfn(c=self.cs, A=self.A, p_idxs=self.p_idxs, --> 168 k=self.k, solver_kwargs) 169 self.solver_out = solver_out 170 finally:

/usr/local/lib/python3.6/dist-packages/gpkit/_mosek/cli_expopt.py in imize(c, A, p_idxs, *args, **kwargs) 99 if status == "PRIMAL_AND_DUAL_FEASIBLE": 100 status = "optimal" --> 101 assert_line(f, "SOLUTION STATUS : OPTIMAL\n") 102 # line looks like "OBJECTIVE : 2.763550e+002" 103 objective_val = float(f.readline().split()[2])

/usr/local/lib/python3.6/dist-packages/gpkit/_mosek/cli_expopt.py in assert_line(fil, expected) 147 if tuple(expected[:-1].split()) != tuple(received[:-1].split()): 148 errstr = repr(expected)+" is not the same as "+repr(received) --> 149 raise RuntimeWarning("could not read mskexpopt output file: "+errstr) 150 151

RuntimeWarning: could not read mskexpopt output file: 'SOLUTION STATUS : OPTIMAL\n' is not the same as 'SOLUTION STATUS : UNKNOWN\n'

[2] CalledProcessError Traceback (most recent call last) /usr/local/lib/python3.6/dist-packages/gpkit/_mosek/cli_expopt.py in imize(c, A, p_idxs, *args, **kwargs) 89 for logline in check_output(["mskexpopt", filename, "-sol", ---> 90 solution_filename]).split(b"\n"): 91 print(logline)

6 frames /usr/lib/python3.6/subprocess.py in check_output(timeout, *popenargs, *kwargs) 355 return run(popenargs, stdout=PIPE, timeout=timeout, check=True, --> 356 **kwargs).stdout 357

/usr/lib/python3.6/subprocess.py in run(input, timeout, check, *popenargs, **kwargs) 437 raise CalledProcessError(retcode, process.args, --> 438 output=stdout, stderr=stderr) 439 return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command '['mskexpopt', '/tmp/tmpyl9lqxfj/gpkit_mosek', '-sol', '/tmp/tmpyl9lqxfj/gpkit_mosek.sol']' returned non-zero exit status 22. During handling of the above exception, another exception occurred:

RuntimeWarning Traceback (most recent call last)

/usr/local/lib/python3.6/dist-packages/gpkit/constraints/prog_factories.py in solvefn(self, solver, verbosity, skipsweepfailures, kwargs) 122 else: 123 self.program, progsolve = genfunction(self) --> 124 result = progsolve(solver, verbosity, kwargs) 125 solution.append(result) 126 solution.program = self.program

/usr/local/lib/python3.6/dist-packages/gpkit/constraints/gp.py in solve(self, solver, verbosity, warn_on_check, process_result, gen_result, kwargs) 166 sys.stdout = self.solver_log # CAPTURED 167 solver_out = solverfn(c=self.cs, A=self.A, p_idxs=self.p_idxs, --> 168 k=self.k, solver_kwargs) 169 self.solver_out = solver_out 170 finally:

/usr/local/lib/python3.6/dist-packages/gpkit/_mosek/cli_expopt.py in imize(c, A, p_idxs, *args, **kwargs) 91 print(logline) 92 except CalledProcessError as e: ---> 93 raise RuntimeWarning(str(e)) 94 with open(solution_filename) as f: 95 status = f.readline().split("PROBLEM STATUS : ")

RuntimeWarning: Command '['mskexpopt', '/tmp/tmpyl9lqxfj/gpkit_mosek', '-sol', '/tmp/tmpyl9lqxfj/gpkit_mosek.sol']' returned non-zero exit status 22.

bqpd commented 4 years ago

Hi @vignesh99, thanks for raising this issue.

Error (1) mean that your model is infeasible; check the docs for more information, or try m.debug(). Error (2) is a little less clear; 22 is not in the list of mosek response codes, but those are sometimes platform dependent; my guess is that it's still an infeasibility error, and m.debug() would probably handle it as well.

I actually added some new error messages to address these confusing ones some time ago, but just realized I hadn't uploaded those to pypi; if you try updating GPkit and run these models again you should see both the improved error messages and it should try automatically debugging it for you!

vignesh99 commented 4 years ago

Hey @bqpd , thank you for your response! I tried using m.debug() in the morning and it was able to solve the problem upon relaxing the constraints. Just now used the updated library which automatically runs the m.debug() if the solution is infeasible. Thanks for the change.

Just a clarification, when it says there was 1 constraint which has to be relaxed by a certain percentage (as it is in our case), does it mean that it is the sole constraint responsible for the infeasibility and tweaking/correcting that could be sufficient to make it feasible? Or does it mean the whole set of constraints is responsible and this happens to be a one particular relaxation that can solve it? I am assuming it is the latter but wanted to clarify to be sure.

vignesh99 commented 4 years ago

In case you are interested, that error message (2), 22 response code, is what I get when I run on Google Colab

bqpd commented 4 years ago

@vignesh99 glad it worked! and re: "1 constraint which has to be relaxed by a certain percentage", you're mostly right: it means that relaxing only that constraint is an optimal relaxation (the default cost function being the product of each constraint's relaxation), but there may be other relaxations with the same optimal cost. To disambiguate this further you could change that cost function, or relax only certain constraints.

vignesh99 commented 4 years ago

Oh, @bqpd how do I change the cost function or choose which constraints to relax? As inputs to the m.debug() function?

bqpd commented 4 years ago

hopefully the examples in https://gpkit.readthedocs.io/en/latest/debugging.html#relaxation answer your question; if not we should rewrite them!

vignesh99 commented 4 years ago

Thanks @bqpd, I'll take a look at it.