Skip to content

Commit

Permalink
Summary table & sundry lint (#1032)
Browse files Browse the repository at this point in the history
* summary table
* make summary default in examples
* consistently put positive senss above negative
* don't require ipywidgets to import from interactive
* add table filtering to controlpanel, summary edits
* fix on numpy 1.12
  • Loading branch information
bqpd authored Jan 16, 2017
1 parent 5007541 commit 5321eda
Show file tree
Hide file tree
Showing 28 changed files with 222 additions and 239 deletions.
Binary file modified docs/source/controlpanel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/source/examples/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def setup(self, N=4):
b = Beam(N=6, substitutions={"L": 6, "EI": 1.1e4, "q": 110*np.ones(6)})
b.zero_lower_unbounded_variables()
sol = b.solve(verbosity=0)
print sol.table()
print sol.summary()
w_gp = sol("w") # deflection along beam

L, EI, q = sol("L"), sol("EI"), sol("q")
Expand Down
22 changes: 4 additions & 18 deletions docs/source/examples/beam_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,9 @@ Free Variables
\theta : [ - 0.177 0.285 0.341 ... ] Slope
w : [ - 0.106 0.384 0.759 ... ] [m] Displacement

Constants
---------
EI : 1.1e+04 [N*m**2]
L : 6 [m] Overall beam length
M_{tip} : 0 [N*m] Tip moment
V_{tip} : 0 [N] Tip loading
\theta_{base} : 0 Base angle
w_{base} : 0 [m] Base deflection
M : [ - - - - ... ] [N*m] Internal moment
V : [ - - - - ... ] [N] Internal shear
\theta : [ 0 - - - ... ] Slope
q : [ 110 110 110 110 ... ] [N/m] Distributed load at each point
w : [ 0 - - - ... ] [m] Displacement

Sensitivities
-------------
L : 4 Overall beam length
q : [ 0.0072 0.0416 0.118 0.234 ... ] Distributed load at each point
Most Sensitive
--------------
L : +4 Overall beam length
EI : -1
q : [ +0.0072 +0.042 +0.12 +0.23 ... ] Distributed load at each point

3 changes: 1 addition & 2 deletions docs/source/examples/external_sp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
]

m = Model(objective, constraints)
sol = m.localsolve(verbosity=0)
print sol.table()
print m.localsolve(verbosity=0).summary()
3 changes: 1 addition & 2 deletions docs/source/examples/external_sp2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ def y_ext(self, x0):
y = Variable("y", externalfn=y_ext)

m = Model(y, [np.pi/4 <= x, x <= np.pi/2])
sol = m.localsolve(verbosity=0)
print sol.table()
print m.localsolve(verbosity=0).summary()
19 changes: 12 additions & 7 deletions docs/source/examples/performance_modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
from gpkit import Model, Variable, Vectorize


class Aircraft(Model):
"The vehicle model"
def setup(self):
Expand Down Expand Up @@ -58,14 +59,14 @@ class Mission(Model):
"A sequence of flight segments"
def setup(self, aircraft):
with Vectorize(4): # four flight segments
fs = FlightSegment(aircraft)
self.fs = FlightSegment(aircraft)

Wburn = fs.aircraftp["W_{burn}"]
Wfuel = fs.aircraftp["W_{fuel}"]
Wburn = self.fs.aircraftp["W_{burn}"]
Wfuel = self.fs.aircraftp["W_{fuel}"]
self.takeoff_fuel = Wfuel[0]

return fs, [Wfuel[:-1] >= Wfuel[1:] + Wburn[:-1],
Wfuel[-1] >= Wburn[-1]]
return self.fs, [Wfuel[:-1] >= Wfuel[1:] + Wburn[:-1],
Wfuel[-1] >= Wburn[-1]]


class Wing(Model):
Expand Down Expand Up @@ -116,5 +117,9 @@ def setup(self):
AC = Aircraft()
MISSION = Mission(AC)
M = Model(MISSION.takeoff_fuel, [MISSION, AC])
SOL = M.solve(verbosity=0)
print SOL.table()
sol = M.solve(verbosity=0)

vars_of_interest = set(AC.varkeys)
vars_of_interest.update(MISSION.fs.aircraftp.unique_varkeys)
vars_of_interest.add("D")
print sol.summary(vars_of_interest)
42 changes: 11 additions & 31 deletions docs/source/examples/performance_modeling_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,24 @@ W_{burn} : [ 0.487 0.486 0.485 0.485 ] [lbf] segment fuel burn
W_{fuel} : [ 1.94 1.46 0.97 0.485 ] [lbf] fuel weight

| Mission/FlightSegment/AircraftP/WingAero
C_D : [ 0.00783 0.00782 0.00781 0.0078 ] drag coefficient
C_L : [ 0.47 0.469 0.468 0.467 ] lift coefficient
D : [ 4.87 4.86 4.85 4.85 ] [lbf] drag force
Re : [ 7.56e+05 7.56e+05 7.56e+05 7.56e+05 ] Reynold's number

Constants
---------
Sensitivities
-------------
| Aircraft/Fuselage
W : 100 [lbf] weight
W : +0.25 weight

| Aircraft/Wing
A : 27 aspect ratio
S : 190 [ft**2] surface area
\rho : 1 [lbf/ft**2] areal density
S : +0.68 surface area
\rho : +0.48 areal density
A : -0.31 aspect ratio

Next Largest Sensitivities
--------------------------
| Mission/FlightSegment/AircraftP/WingAero
e : [ 0.9 0.9 0.9 0.9 ] Oswald efficiency

| Mission/FlightSegment/FlightState
V : [ 40 40 40 40 ] [kt] true airspeed
\mu : [ 1.63e-05 1.63e-05 1.63e-05 1.63e-05 ] [N*s/m**2] dynamic viscosity
\rho : [ 0.74 0.74 0.74 0.74 ] [kg/m**3] air density
e : [ -0.093 -0.092 -0.092 -0.092 ] Oswald efficiency

Sensitivities
-------------
| Mission/FlightSegment/FlightState
V : [ 0.0997 0.1 0.101 0.102 ] true airspeed
\rho : [ 0.034 0.0344 0.0347 0.0351 ] air density
\mu : [ 0.0316 0.0317 0.0317 0.0318 ] dynamic viscosity

| Mission/FlightSegment/AircraftP/WingAero
e : [ -0.0926 -0.0924 -0.0922 -0.092 ] Oswald efficiency

| Aircraft/Wing
S : 0.6831 surface area
\rho : 0.4816 areal density
A : -0.3056 aspect ratio

| Aircraft/Fuselage
W : 0.2535 weight
V : [ +0.1 +0.1 +0.1 +0.1 ] true airspeed
\rho : [ +0.034 +0.034 +0.035 +0.035 ] air density

4 changes: 2 additions & 2 deletions docs/source/examples/relaxation_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ x_min : 2

Sensitivities
-------------
x_min : 0.5
x_min : +0.5
x_max : -0.5


Expand Down Expand Up @@ -66,7 +66,7 @@ x_min : 2

Sensitivities
-------------
x_min : 1
x_min : +1
x_max : -0.99


Expand Down
7 changes: 3 additions & 4 deletions docs/source/examples/simple_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@
w = Variable("w", "m", "width")
d = Variable("d", "m", "depth")

#Constraints
# Constraints
constraints = [A_wall >= 2*h*w + 2*h*d,
A_floor >= w*d,
h/w >= alpha,
h/w <= beta,
d/w >= gamma,
d/w <= delta]

#Objective function
# Objective function
V = h*w*d
objective = 1/V # To maximize V, we minimize its reciprocal

# Formulate the Model
m = Model(objective, constraints)

# Solve the Model and print the results table
sol = m.solve(verbosity=0)
print sol.table()
print m.solve(verbosity=0).table()
8 changes: 6 additions & 2 deletions docs/source/examples/simple_box_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ A_{floor} : 50 [m**2] upper limit, floor area

Sensitivities
-------------
alpha : 0.5 lower limit, wall aspect ratio
A_{wall} : -1.5 upper limit, wall area
A_{wall} : -1.5 upper limit, wall area
alpha : +0.5 lower limit, wall aspect ratio
gamma : +0.0003 lower limit, floor aspect ratio
A_{floor} : -5.7e-09 upper limit, floor area
beta : -1.4e-09 upper limit, wall aspect ratio
delta : -1.4e-09 upper limit, floor aspect ratio

5 changes: 2 additions & 3 deletions docs/source/examples/simple_sp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@

# create and solve the SP
m = gpkit.Model(x, constraints)
sol = m.localsolve(verbosity=0)
print sol.table()
assert abs(sol(x) - 0.9) < 1e-6
print m.localsolve(verbosity=0).summary()
assert abs(m.solution(x) - 0.9) < 1e-6
6 changes: 3 additions & 3 deletions docs/source/examples/simpleflight.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"Minimizes airplane drag for a simple drag and structure model."
import numpy as np
from gpkit import Variable, Model
pi = np.pi


# Constants
k = Variable("k", 1.2, "-", "form factor")
e = Variable("e", 0.95, "-", "Oswald efficiency factor")
mu = Variable("\\mu", 1.78e-5, "kg/m/s", "viscosity of air")
pi = Variable("\\pi", np.pi, "-", "half of the circle constant")
rho = Variable("\\rho", 1.23, "kg/m^3", "density of air")
tau = Variable("\\tau", 0.12, "-", "airfoil thickness to chord ratio")
N_ult = Variable("N_{ult}", 3.8, "-", "ultimate load factor")
Expand Down Expand Up @@ -57,12 +57,12 @@
print("SINGLE\n======")
m = Model(D, constraints)
sol = m.solve(verbosity=0)
print(sol.table())
print(sol.summary())

print("SWEEP\n=====")
N = 2
sweeps = {V_min: ("sweep", np.linspace(20, 25, N)),
V: ("sweep", np.linspace(45, 55, N)), }
m.substitutions.update(sweeps)
sweepsol = m.solve(verbosity=0)
print(sweepsol.table())
print(sweepsol.summary())
80 changes: 14 additions & 66 deletions docs/source/examples/simpleflight_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,13 @@ C_f : 0.003599 skin friction coefficient
W : 7341 [N] total aircraft weight
W_w : 2401 [N] wing weight

Constants
---------
(CDA0) : 0.031 [m**2] fuselage drag area
(\frac{S}{S_{wet}}) : 2.05 wetted area ratio
C_{L,max} : 1.5 max CL with flaps down
N_{ult} : 3.8 ultimate load factor
V_{min} : 22 [m/s] takeoff speed
W_0 : 4940 [N] aircraft weight excluding wing
W_{W_{coeff1}} : 8.71e-05 [1/m] Wing Weight Coefficent 1
W_{W_{coeff2}} : 45.24 [Pa] Wing Weight Coefficent 2
\mu : 1.78e-05 [kg/m/s] viscosity of air
\pi : 3.142 half of the circle constant
\rho : 1.23 [kg/m**3] density of air
\tau : 0.12 airfoil thickness to chord ratio
e : 0.95 Oswald efficiency factor
k : 1.2 form factor

Sensitivities
-------------
W_0 : 1.011 aircraft weight excluding wing
k : 0.4299 form factor
(\frac{S}{S_{wet}}) : 0.4299 wetted area ratio
W_{W_{coeff1}} : 0.2903 Wing Weight Coefficent 1
N_{ult} : 0.2903 ultimate load factor
W_{W_{coeff2}} : 0.1303 Wing Weight Coefficent 2
(CDA0) : 0.09156 fuselage drag area
\mu : 0.08599 viscosity of air
C_{L,max} : -0.1839 max CL with flaps down
\rho : -0.2269 density of air
\tau : -0.2903 airfoil thickness to chord ratio
V_{min} : -0.3678 takeoff speed
e : -0.4785 Oswald efficiency factor
\pi : -0.4785 half of the circle constant
Most Sensitive
--------------
W_0 : +1 aircraft weight excluding wing
e : -0.48 Oswald efficiency factor
(\frac{S}{S_{wet}}) : +0.43 wetted area ratio
k : +0.43 form factor
V_{min} : -0.37 takeoff speed

SWEEP
=====
Expand All @@ -76,37 +50,11 @@ C_f : [ 0.00333 0.00361 0.00314 0.00342 ] skin friction coefficie
W : [ 6.85e+03 6.97e+03 6.4e+03 6.44e+03 ] [N] total aircraft weight
W_w : [ 1.91e+03 2.03e+03 1.46e+03 1.5e+03 ] [N] wing weight

Constants
---------
(CDA0) : 0.031 [m**2] fuselage drag area
(\frac{S}{S_{wet}}) : 2.05 wetted area ratio
C_{L,max} : 1.5 max CL with flaps down
N_{ult} : 3.8 ultimate load factor
W_0 : 4940 [N] aircraft weight excluding wing
W_{W_{coeff1}} : 8.71e-05 [1/m] Wing Weight Coefficent 1
W_{W_{coeff2}} : 45.24 [Pa] Wing Weight Coefficent 2
\mu : 1.78e-05 [kg/m/s] viscosity of air
\pi : 3.142 half of the circle constant
\rho : 1.23 [kg/m**3] density of air
\tau : 0.12 airfoil thickness to chord ratio
e : 0.95 Oswald efficiency factor
k : 1.2 form factor

Sensitivities
-------------
W_0 : [ 0.919 0.947 0.845 0.847 ] aircraft weight excluding wing
V : [ 0.589 0.249 0.975 0.746 ] cruising speed
k : [ 0.561 0.454 0.63 0.536 ] form factor
(\frac{S}{S_{wet}}) : [ 0.561 0.454 0.63 0.536 ] wetted area ratio
W_{W_{coeff1}} : [ 0.179 0.247 0.108 0.155 ] Wing Weight Coefficent 1
N_{ult} : [ 0.179 0.247 0.108 0.155 ] ultimate load factor
(CDA0) : [ 0.114 0.131 0.146 0.177 ] fuselage drag area
W_{W_{coeff2}} : [ 0.141 0.0911 0.126 0.0787 ] Wing Weight Coefficent 2
\mu : [ 0.112 0.0907 0.126 0.107 ] viscosity of air
\rho : [ -0.172 -0.129 -0.097 -0.0331 ] density of air
\tau : [ -0.179 -0.247 -0.108 -0.155 ] airfoil thickness to chord ratio
e : [ -0.325 -0.415 -0.225 -0.287 ] Oswald efficiency factor
\pi : [ -0.325 -0.415 -0.225 -0.287 ] half of the circle constant
C_{L,max} : [ -0.411 -0.207 -0.521 -0.353 ] max CL with flaps down
V_{min} : [ -0.822 -0.415 -1.04 -0.705 ] takeoff speed
Most Sensitive
--------------
W_0 : [ +0.92 +0.95 +0.85 +0.85 ] aircraft weight excluding wing
V_{min} : [ -0.82 -0.41 -1 -0.71 ] takeoff speed
V : [ +0.59 +0.25 +0.97 +0.75 ] cruising speed
(\frac{S}{S_{wet}}) : [ +0.56 +0.45 +0.63 +0.54 ] wetted area ratio
k : [ +0.56 +0.45 +0.63 +0.54 ] form factor

3 changes: 1 addition & 2 deletions docs/source/examples/sin_approx_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@
]

m = Model(objective, constraints)
sol = m.solve(verbosity=0)
print sol.table()
print m.solve(verbosity=0).summary()
2 changes: 1 addition & 1 deletion docs/source/examples/unbounded.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
m = Model(1/x, Bounded(constraints))
# by default, prints bounds warning during solve
sol = m.solve(verbosity=0)
print sol.table()
print sol.summary()
print "sol['boundedness'] is:", sol["boundedness"]
4 changes: 2 additions & 2 deletions docs/source/examples/vectorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def setup(self):
print "SCALAR"
m = Test()
m.cost = m["x"]
print m.solve(verbosity=0).table()
print m.solve(verbosity=0).summary()

print "__________\n"
print "VECTORIZED"
with Vectorize(3):
m = Test()
m.cost = m["x"].prod()
m.append(m["x"][1] >= 2)
print m.solve(verbosity=0).table()
print m.solve(verbosity=0).summary()
2 changes: 1 addition & 1 deletion docs/source/examples/water_tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

m = Model(A, constraints)
sol = m.solve(verbosity=0)
print sol.table()
print sol.summary()
9 changes: 2 additions & 7 deletions docs/source/examples/water_tank_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ A : 1.293 [m**2] Surface Area of the Tank
V : 0.1 [m**3] Volume of the Tank
d : [ 0.464 0.464 0.464 ] [m] Dimension Vector

Constants
---------
M : 100 [kg] Mass of Water in the Tank
\rho : 1000 [kg/m**3] Density of Water in the Tank

Sensitivities
-------------
M : 0.6667 Mass of Water in the Tank
\rho : -0.6667 Density of Water in the Tank
M : +0.67 Mass of Water in the Tank
\rho : -0.67 Density of Water in the Tank

Loading

0 comments on commit 5321eda

Please sign in to comment.