Skip to content

Commit

Permalink
add err_on_relax to PCCP solves, True by default
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Mar 2, 2022
1 parent a3e5fc2 commit 6f060f2
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions gpkit/constraints/sgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(self, cost, model, substitutions,

# pylint: disable=too-many-locals,too-many-branches,too-many-statements
def localsolve(self, solver=None, *, verbosity=1, x0=None, reltol=1e-4,
iteration_limit=50, **solveargs):
iteration_limit=50, err_on_relax=True, **solveargs):
"""Locally solves a SequentialGeometricProgram and returns the solution.
Arguments
Expand Down Expand Up @@ -196,17 +196,21 @@ def localsolve(self, solver=None, *, verbosity=1, x0=None, reltol=1e-4,
if excess_slack > EPS:
msg = ("Final PCCP solution let non-GP constraints slacken by"
" %.2g%%." % (100*excess_slack))
appendsolwarning(msg, (1 + excess_slack), self.result,
"Slack Non-GP Constraints")
if verbosity > -1:
print(msg +
" Calling .localsolve(pccp_penalty=...) with a higher"
" `pccp_penalty` (it was %.3g this time) will reduce"
" slack if the model is solvable with less. To verify"
" that the slack is needed, generate an SGP with"
" `use_pccp=False` and start it from this model's"
" solution: e.g. `m.localsolve(use_pccp=False, x0="
"m.solution[\"variables\"])`." % self.pccp_penalty)
expl = (msg +
" Calling .localsolve(pccp_penalty=...) with a higher"
" `pccp_penalty` (it was %.3g this time) will reduce"
" slack if the model is solvable with less. To verify"
" that the slack is needed, generate an SGP with"
" `use_pccp=False` and start it from this model's"
" solution: e.g. `m.localsolve(use_pccp=False, x0="
"m.solution[\"variables\"])`." % self.pccp_penalty)
if err_on_relax:
raise Infeasible(expl)
else:
appendsolwarning(msg, (1 + excess_slack), self.result,
"Slack Non-GP Constraints")
if verbosity > -1:
print(expl)
self.result["cost function"] = self.cost
del self.result["freevariables"][self.slack.key] # pylint: disable=no-member
del self.result["variables"][self.slack.key] # pylint: disable=no-member
Expand Down

0 comments on commit 6f060f2

Please sign in to comment.