Skip to content

Commit

Permalink
fix diff, repeatable test printing
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Apr 27, 2021
1 parent 8283615 commit 68a48f0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 36 deletions.
6 changes: 3 additions & 3 deletions docs/source/examples/issue_1513.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setup(self):
return constraints, substitutions

m = System()
sol = m.solve()
sol = m.solve(verbosity=0)
print(sol.table())

# now with more fleets per system
Expand All @@ -50,7 +50,7 @@ def setup(self):
return constraints

m = System2()
sol = m.solve()
sol = m.solve(verbosity=0)
print(sol.table())


Expand Down Expand Up @@ -81,5 +81,5 @@ def setup(self):
"y": ("sweep", [1, 2, 3]),
"z": lambda v: v("y")**2,
})
sol = m.solve()
sol = m.solve(verbosity=0)
print(sol.table())
10 changes: 0 additions & 10 deletions docs/source/examples/issue_1513_output.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
Using solver 'cvxopt'
for 3 free variables
in 4 posynomial inequalities.
Solving took 0.00804 seconds.

Optimal Cost
------------
Expand Down Expand Up @@ -40,10 +36,6 @@ Most Sensitive Constraints
+0.75 : a[0,0] ≥ 1
+0.25 : a[1,0] ≥ 1

Using solver 'cvxopt'
for 9 free variables
in 10 posynomial inequalities.
Solving took 0.0195 seconds.

Optimal Cost
------------
Expand Down Expand Up @@ -87,8 +79,6 @@ Most Sensitive Constraints
+0.25 : a[0,0] ≥ 1
+0.25 : a[0,1] ≥ 1

Sweeping with 1 solves:
Sweeping took 0.0224 seconds.

Optimal Cost
------------
Expand Down
4 changes: 2 additions & 2 deletions docs/source/examples/issue_1522.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setup(self):
return constraints

m = Yum1()
sol = m.solve()
sol = m.solve(verbosity=0)
print(sol.table())

class Yum2(Model):
Expand All @@ -50,5 +50,5 @@ def setup(self):
return constraints

m = Yum2()
sol = m.solve()
sol = m.solve(verbosity=0)
print(sol.table())
12 changes: 2 additions & 10 deletions docs/source/examples/issue_1522_output.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
Using solver 'cvxopt'
for 5 free variables
in 11 posynomial inequalities.
Solving took 0.0145 seconds.

Optimal Cost
------------
15

Model Sensitivities (sorts models in sections below)
-------------------
+1.0 : Yum1.Cake.Pie
: Yum1.Cake
+1.0 : Yum1.Cake
: Yum1.Cake.Pie

Free Variables
--------------
Expand Down Expand Up @@ -40,10 +36,6 @@ Most Sensitive Constraints
+0.2 : y[3] ≥ x[1,3]
+0.2 : y[4] ≥ x[1,4]

Using solver 'cvxopt'
for 1 free variables
in 3 posynomial inequalities.
Solving took 0.0132 seconds.

Optimal Cost
------------
Expand Down
8 changes: 3 additions & 5 deletions docs/source/examples/simpleflight_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ V_{min} : [ -9.1% -9.1% +13.6% +13.6% ] takeoff speed
W : [ -6.8% -12.8% -5.1% -12.2% ] total aircraft weight
C_f : [ -7.3% -12.7% - -5.0% ] skin friction coefficient

Absolute Differences |above 0|
------------------------------
Absolute Differences |above 0.1|
--------------------------------
Re : [ +1.7e+06 +3.6e+06 -4.1e+04 +1.1e+06 ] Reynold's number
W : [ -5e+02 -9.4e+02 -3.8e+02 -9e+02 ] [N] total aircraft weight
W_w : [ -5e+02 -9.4e+02 -3.8e+02 -9e+02 ] [N] wing weight
Expand All @@ -114,9 +114,7 @@ Absolute Differences |above 0|
S : [ +2.1 +0.9 -4.4 -5.3 ] [m²] total wing area
V_{min} : [ -2 -2 +3 +3 ] [m/s] takeoff speed
A : [ -2.3 -3.7 +0.38 -1.3 ] aspect ratio
C_L : [ -0.2 -0.3 -0.036 -0.19 ] Lift coefficent of wing
C_D : [ -0.006 -0.0083 -0.001 -0.0049 ] Drag coefficient of wing
C_f : [ -0.00026 -0.00046 +8e-06 -0.00018 ] skin friction coefficient
C_L : [ -0.2 -0.3 - -0.19 ] Lift coefficent of wing

Sensitivity Differences |above 0.1|
-----------------------------------
Expand Down
12 changes: 6 additions & 6 deletions gpkit/solution_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def msenss_table(data, _, **kwargs):
if "models" not in data.get("sensitivities", {}):
return ""
data = sorted(data["sensitivities"]["models"].items(),
key=lambda i: -np.mean(i[1]))
key=lambda i: (-round(np.mean(i[1]), 1), i[0]))
lines = ["Model Sensitivities", "-------------------"]
if kwargs["sortmodelsbysenss"]:
lines[0] += " (sorts models in sections below)"
Expand Down Expand Up @@ -389,7 +389,7 @@ def almost_equal(self, other, reltol=1e-3, sens_abstol=0.01):
# pylint: disable=too-many-locals, too-many-branches, too-many-statements
def diff(self, other, showvars=None, *,
constraintsdiff=True, senssdiff=False, sensstol=0.1,
absdiff=False, abstol=0, reldiff=True, reltol=1.0,
absdiff=False, abstol=0.1, reldiff=True, reltol=1.0,
sortmodelsbysenss=True, **tableargs):
"""Outputs differences between this solution and another
Expand All @@ -401,9 +401,9 @@ def diff(self, other, showvars=None, *,
if True, show sensitivity differences
sensstol : float
the smallest sensitivity difference worth showing
abssdiff : boolean
absdiff : boolean
if True, show absolute differences
absstol : float
abstol : float
the smallest absolute difference worth showing
reldiff : boolean
if True, show relative differences
Expand Down Expand Up @@ -465,7 +465,7 @@ def diff(self, other, showvars=None, *,
"Relative Differences |above %g%%|" % reltol,
valfmt="%+.1f%% ", vecfmt="%+6.1f%% ",
minval=reltol, printunits=False, **tableargs)
if lines[-2][:10] == "-"*10: # nothing larger than sensstol
if lines[-2][:10] == "-"*10: # nothing larger than reltol
lines.insert(-1, ("The largest is %+g%%."
% unrolled_absmax(rel_diff.values())))
if absdiff:
Expand All @@ -474,7 +474,7 @@ def diff(self, other, showvars=None, *,
"Absolute Differences |above %g|" % abstol,
valfmt="%+.2g", vecfmt="%+8.2g",
minval=abstol, **tableargs)
if lines[-2][:10] == "-"*10: # nothing larger than sensstol
if lines[-2][:10] == "-"*10: # nothing larger than abstol
lines.insert(-1, ("The largest is %+g."
% unrolled_absmax(abs_diff.values())))
if senssdiff:
Expand Down

0 comments on commit 68a48f0

Please sign in to comment.