Skip to content

Commit

Permalink
add constraint differences
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Mar 4, 2020
1 parent 983a92e commit efc9535
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
14 changes: 13 additions & 1 deletion docs/source/examples/performance_modeling_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ Solution difference for selected variables
==========================================
(positive means the argument is smaller)

Constraint differences
**********************

--- removed in argument
+++ added in argument
@@ -41,4 +41,3 @@
c = (S/A)^0.5
"parametrization of wing weight":
Aircraft.Wing.W >= S·Aircraft.Wing.rho
- Wburn[:] >= 0.2·D[:]
**********************

Relative differences >1%
------------------------
Wburn : [ +102.1% +101.6% +101.1% +100.5% ] segment fuel burn
Expand All @@ -110,5 +122,5 @@ Wfuel : [ +101.3% +101.1% +100.8% +100.5% ] fuel weight

Sensitivity differences >0.1
----------------------------
The largest is -0.00451643
The largest is -0.00451643.

4 changes: 2 additions & 2 deletions docs/source/examples/simpleflight_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ Solution difference

Relative differences >1%
------------------------
The largest is 0%
The largest is +0%.

Sensitivity differences >0.1
----------------------------
The largest is +0
The largest is +0.

SWEEP
=====
Expand Down
15 changes: 12 additions & 3 deletions gpkit/solution_array.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Defines SolutionArray class"""
import re
import difflib
from operator import sub
import warnings as pywarnings
import pickle
Expand Down Expand Up @@ -342,6 +343,14 @@ def diff(self, other, showvars=None, *, senssdiff=True, sensstol=0.1,
showvars = self._parse_showvars(showvars)
svks = {k for k in showvars if k in svars}
ovks = {k for k in showvars if k in ovars}
if self.modelstr != other.modelstr:
lines += ["Constraint differences",
"**********************", ""]
lines.extend(difflib.unified_diff(
self.modelstr.split("\n"), other.modelstr.split("\n"),
fromfile="removed in argument", tofile="added in argument",
lineterm="", n=3))
lines += ["**********************", ""]
if svks - ovks:
lines.append("Variable(s) of this solution"
" which are not in the argument:")
Expand All @@ -361,7 +370,7 @@ def diff(self, other, showvars=None, *, senssdiff=True, sensstol=0.1,
valfmt="%+.1f%% ", vecfmt="%+6.1f%% ",
minval=reltol, printunits=False, **tableargs)
if lines[-2][:10] == "-"*10: # nothing larger than sensstol
lines.insert(-1, ("The largest is %g%%"
lines.insert(-1, ("The largest is %+g%%."
% unrolled_absmax(rel_diff.values())))
# absolute difference #
if absdiff:
Expand All @@ -370,7 +379,7 @@ def diff(self, other, showvars=None, *, senssdiff=True, sensstol=0.1,
valfmt="%+.2g", vecfmt="%+8.2g",
minval=abstol, **tableargs)
if lines[-2][:10] == "-"*10: # nothing larger than sensstol
lines.insert(-1, ("The largest is %+g"
lines.insert(-1, ("The largest is %+g."
% unrolled_absmax(abs_diff.values())))
# sensitivity difference #
if senssdiff:
Expand All @@ -383,7 +392,7 @@ def diff(self, other, showvars=None, *, senssdiff=True, sensstol=0.1,
valfmt="%+-.2f ", vecfmt="%+-6.2f",
minval=sensstol, printunits=False, **tableargs)
if lines[-2][:10] == "-"*10: # nothing larger than sensstol
lines.insert(-1, ("The largest is %+g"
lines.insert(-1, ("The largest is %+g."
% unrolled_absmax(senss_delta.values())))
return "\n".join(lines)

Expand Down

0 comments on commit efc9535

Please sign in to comment.