Skip to content

Commit

Permalink
don't add forward-differentiated sensitivities to constants no longer…
Browse files Browse the repository at this point in the history
… present
  • Loading branch information
bqpd committed Mar 10, 2021
1 parent 3aa5baa commit 3f0381a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions gpkit/constraints/gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,17 @@ def solve(self, solver=None, *, verbosity=1, gen_result=True, **kwargs):
msg = ("The model ran to an infinitely low cost;"
" bounding the right variables would prevent this.")
elif isinstance(infeasibility, UnknownInfeasible):
msg = "The solver failed for an unknown reason."
msg = ("Solver failed for an unknown reason. Relaxing"
" constraints/constants, bounding variables, or"
" using a different solver might fix it.")
if (verbosity > 0 and solver_out["soltime"] < 1
and hasattr(self, "model")): # fast, top-level model
print(msg + "\nSince the model solved in less than a second,"
" let's run `.debug()` to analyze what happened.\n`")
return self.model.debug(solver=solver)
# else, raise a clarifying error
msg += (" Running `.debug()` may pinpoint the trouble. You can"
" also try another solver, or increase the verbosity.")
msg += (" Running `.debug()` or increasing verbosity may pinpoint"
" the trouble.")
raise infeasibility.__class__(msg) from infeasibility

if not gen_result:
Expand Down Expand Up @@ -329,9 +331,10 @@ def _compile_result(self, solver_out):
for c, dv_dc in v.gradients.items():
with warnings.catch_warnings(): # skip pesky divide-by-zeros
warnings.simplefilter("ignore")
if c not in result["constants"]:
continue
dlogv_dlogc = dv_dc * result["constants"][c]/val
before = gpv_ss.get(c, 0)
gpv_ss[c] = before + dlogcost_dlogv*dlogv_dlogc
gpv_ss[c] = gpv_ss.get(c, 0) + dlogcost_dlogv*dlogv_dlogc
if v in cost_senss:
if c in self.cost.vks:
dlogcost_dlogv = cost_senss.pop(v)
Expand Down

0 comments on commit 3f0381a

Please sign in to comment.