Skip to content

Commit

Permalink
Pretty printing and speedups (#1408)
Browse files Browse the repository at this point in the history
- prettier printing
  - ordered printing
  - new printing conventions (model.submodel.variable, variable[index])
    - exclude unnecessary lineage in constraint and table printing
  - print full list of constraints for named models
  - use unicode strings and literals
- speedups
  - gp.gen()
  - x0 generation for SPs
  - algebra via pint operation caching
- python 3 consistent ordering fixes
  • Loading branch information
bqpd committed Jun 30, 2019
1 parent df532f7 commit 20d82e3
Show file tree
Hide file tree
Showing 64 changed files with 1,001 additions and 612 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Expand Up @@ -61,7 +61,7 @@ confidence=
# --disable=W"
#disable=import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating

disable=superfluous-parens,locally-disabled,misplaced-comparison-constant,too-few-public-methods,no-self-use,invalid-sequence-index,keyword-arg-before-vararg,wrong-import-order,assignment-from-no-return
disable=misplaced-comparison-constant,locally-disabled,too-few-public-methods,no-self-use,keyword-arg-before-vararg,cyclic-import,assignment-from-no-return

[REPORTS]

Expand Down
8 changes: 4 additions & 4 deletions docs/source/examples/beam_output.txt
Expand Up @@ -20,8 +20,8 @@ EI : -1 Bending stif
Tightest Constraints
--------------------
+4 : L = 5*dx
+1 : w_(5,) >= 0.5*dx*th_(4,) + 0.5*dx*th_(5,) + w_(4,)
+0.74 : th_(2,) >= 0.5*EI**-1*M_(1,)*dx + 0.5*EI**-1*M_(2,)*dx + th_(1,)
+0.73 : w_(4,) >= 0.5*dx*th_(3,) + 0.5*dx*th_(4,) + w_(3,)
+0.64 : M_(1,) >= 0.5*V_(1,)*dx + 0.5*V_(2,)*dx + M_(2,)
+1 : w[5] >= w[4] + 0.5*dx*(th[5] + th[4])
+0.74 : th[2] >= th[1] + 0.5*dx*(M[2] + M[1])/EI
+0.73 : w[4] >= w[3] + 0.5*dx*(th[4] + th[3])
+0.64 : M[1] >= M[2] + 0.5*dx*(V[1] + V[2])

25 changes: 15 additions & 10 deletions docs/source/examples/boundschecking_output.txt
@@ -1,11 +1,16 @@
BoundsChecking
==============

# minimize
F
# subject to
F >= D + T
D = Ap*V**2*rf
Ap = nu
T = V*mf
mf >= mb + mi
mf = V*rf
Fs <= mi
Cost
----
F

Constraints
-----------
F >= D + T
D = rf*V^2*Ap
Ap = nu
T = mf*V
mf >= mi + mb
mf = rf*V
Fs <= mi
6 changes: 3 additions & 3 deletions docs/source/examples/docstringparsing_output.txt
Expand Up @@ -46,7 +46,7 @@ h : +0.3 minimum height

Tightest Constraints
--------------------
+1 : A >= 2*s_(0,)*s_(1,) + 2*s_(0,)*s_(2,) + 2*s_(1,)*s_(2,)
+0.57 : V <= s_(0,)*s_(1,)*s_(2,)
+0.3 : s_(2,) >= h
+1 : A >= 2*(s[0]*s[1] + s[1]*s[2] + s[2]*s[0])
+0.57 : V <= s[:].prod()
+0.3 : s[2] >= h

6 changes: 3 additions & 3 deletions docs/source/examples/model_var_access_output.txt
@@ -1,3 +1,3 @@
Getting the only var 'E': E_PowerSystem/Battery [MJ]
The top-level var 'm': m_PowerSystem [lb]
All the variables 'm': [gpkit.Variable(m_PowerSystem [lb]), gpkit.Variable(m_PowerSystem/Battery [lb]), gpkit.Variable(m_PowerSystem/Motor [lb])]
Getting the only var 'E': PowerSystem.Battery.E [MJ]
The top-level var 'm': PowerSystem.m [lb]
All the variables 'm': [gpkit.Variable(PowerSystem.Battery.m [lb]), gpkit.Variable(PowerSystem.Motor.m [lb]), gpkit.Variable(PowerSystem.m [lb])]
2 changes: 1 addition & 1 deletion docs/source/examples/performance_modeling.py
Expand Up @@ -228,10 +228,10 @@ class Fuselage(Model):
def setup(self):
exec(parse_variables(Fuselage.__doc__))


AC = Aircraft()
MISSION = Mission(AC)
M = Model(MISSION.takeoff_fuel, [MISSION, AC])
print(M)
sol = M.solve(verbosity=0)
# save solution to some files
sol.savemat()
Expand Down
74 changes: 57 additions & 17 deletions docs/source/examples/performance_modeling_output.txt
@@ -1,4 +1,47 @@

Cost
----
Wfuel[0]

Constraints
-----------
Mission
"definition of Wburn":
Wfuel[:3] >= Wfuel[1:] + Wburn[:3]
"require fuel for the last leg":
Wfuel[3] >= Wburn[3]

FlightSegment
AircraftP
"fuel burn rate":
Wburn[:] >= 0.1*D[:]
"lift":
Aircraft.W + Wfuel[:] <= 0.5*rho[:]*CL[:]*S*V[:]^2
"performance":
WingAero
"definition of D":
D[:] >= 0.5*rho[:]*V[:]^2*CD[:]*S
"definition of Re":
Re[:] = rho[:]*V[:]*c/mu[:]
"drag model":
CD[:] >= 0.074/Re[:]^0.2 + CL[:]^2/PI/A/e[:]

FlightState
(no constraints)

Aircraft
"definition of W":
Aircraft.W >= Aircraft.Fuselage.W + Aircraft.Wing.W
"components":
Fuselage
(no constraints)

Wing
"definition of mean chord":
c = (S/A)^0.5
"parametrization of wing weight":
Aircraft.Wing.W >= S*Aircraft.Wing.rho

Cost
----
1.091 [lbf]
Expand All @@ -8,51 +51,48 @@ Free Variables
| Aircraft
W : 144.1 [lbf] weight

| Aircraft/Wing
| Aircraft.Wing
S : 44.14 [ft**2] surface area
W : 44.14 [lbf] weight
c : 1.279 [ft] mean chord

| Mission/FlightSegment/AircraftP
| Mission.FlightSegment.AircraftP
Wburn : [ 0.274 0.273 0.272 0.272 ] [lbf] segment fuel burn
Wfuel : [ 1.09 0.817 0.544 0.272 ] [lbf] fuel weight

| Mission/FlightSegment/AircraftP/WingAero
| Mission.FlightSegment.AircraftP.WingAero
D : [ 2.74 2.73 2.72 2.72 ] [lbf] drag force

Sensitivities
-------------
| Aircraft/Fuselage
| Aircraft.Fuselage
W : +0.97 weight

| Aircraft/Wing
| Aircraft.Wing
A : -0.67 aspect ratio
rho : +0.43 areal density

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

| Mission/FlightSegment/FlightState
| Mission.FlightSegment.FlightState
V : [ -0.22 -0.21 -0.21 -0.21 ] true airspeed
rho : [ -0.12 -0.11 -0.11 -0.11 ] air density

Tightest Constraints
--------------------
| Aircraft
+1.4 : W_ >= W_/Fuselage + W_/Wing
+1.4 : .W >= .Fuselage.W + .Wing.W

| Mission
+1 : Wfuel_/FlightSegment/AircraftP_(0,) >= Wburn_/FlightSegment/AircraftP_(0,)
+ Wfuel_/FlightSegment/AircraftP_(1,)
+0.75 : Wfuel_/FlightSegment/AircraftP_(1,) >= Wburn_/FlightSegment/AircraftP_(1,)
+ Wfuel_/FlightSegment/AircraftP_(2,)
+0.5 : Wfuel_/FlightSegment/AircraftP_(2,) >= Wburn_/FlightSegment/AircraftP_(2,)
+ Wfuel_/FlightSegment/AircraftP_(3,)

| Aircraft/Wing
+0.43 : W_ >= S_*rho_
+1 : Wfuel[0] >= Wfuel[1] + Wburn[0]
+0.75 : Wfuel[1] >= Wfuel[2] + Wburn[1]
+0.5 : Wfuel[2] >= Wfuel[3] + Wburn[2]

| Aircraft.Wing
+0.43 : .W >= S*.rho

All Loose Constraints
---------------------
Expand Down
107 changes: 61 additions & 46 deletions docs/source/examples/relaxation_output.txt
@@ -1,23 +1,29 @@
Original model
==============

# minimize
x
# subject to
x <= x_max
x >= x_min
Cost
----
x

Constraints
-----------
x <= x_max
x >= x_min

With constraints relaxed equally
================================

# minimize
C_Relax
# subject to
"relaxed constraints":
x <= C_Relax*x_max
x_min <= C_Relax*x
"minimum relaxation":
C_Relax >= 1
Cost
----
C

Constraints
-----------
"minimum relaxation":
C >= 1
"relaxed constraints":
x <= C*x_max
x_min <= C*x

Cost
----
Expand All @@ -37,26 +43,29 @@ x_min : 2

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

Tightest Constraints
--------------------
+0.5 : x <= C_Relax*x_max
+0.5 : x_min <= C_Relax*x
+0.5 : x <= C*x_max
+0.5 : x_min <= C*x


With constraints relaxed individually
=====================================

# minimize
C_Relax.1_(0,)*C_Relax.1_(1,)*x**0.01
# subject to
"relaxed constraints":
x <= C_Relax.1_(0,)*x_max
x_min <= C_Relax.1_(1,)*x
"minimum relaxation":
C_Relax.1 >= 1
Cost
----
C[:].prod()*x^0.01

Constraints
-----------
"minimum relaxation":
C[:] >= 1
"relaxed constraints":
x <= C[0]*x_max
x_min <= C[1]*x

Cost
----
Expand All @@ -66,7 +75,7 @@ Free Variables
--------------
x : 1

| Relax.1
| Relax1
C : [ 1 2 ]

Constants
Expand All @@ -81,27 +90,33 @@ x_max : -0.99

Tightest Constraints
--------------------
+1 : x_min <= C_Relax.1_(1,)*x
+0.99 : x <= C_Relax.1_(0,)*x_max
+0.01 : C_Relax.1_(0,) >= 1
+1 : x_min <= C[1]*x
+0.99 : x <= C[0]*x_max
+0.01 : C[0] >= 1


With constants relaxed individually
===================================

# minimize
x**0.01*x_max_Relax.2*x_min_Relax.2
# subject to
"original constraints":
x <= x_max
x >= x_min
"relaxation constraints":
x_max_Relax.2 >= 1
x_max >= x_max_Relax.2**-1*x_max_{before}_Relax.2
x_max <= x_max_Relax.2*x_max_{before}_Relax.2
x_min_Relax.2 >= 1
x_min >= x_min_Relax.2**-1*x_min_{before}_Relax.2
x_min <= x_min_Relax.2*x_min_{before}_Relax.2
Cost
----
[Relax2.x_max, Relax2.x_min].prod()*x^0.01

Constraints
-----------
Relax2
"original constraints":
x <= x_max
x >= x_min
"relaxation constraints":
"x_max":
Relax2.x_max >= 1
x_max >= x_max_{prelax}/Relax2.x_max
x_max <= x_max_{prelax}*Relax2.x_max
"x_min":
Relax2.x_min >= 1
x_min >= x_min_{prelax}/Relax2.x_min
x_min <= x_min_{prelax}*Relax2.x_min

Cost
----
Expand All @@ -113,14 +128,14 @@ Free Variables
x_max : 1
x_min : 1

| Relax.2
| Relax2
x_max : 1
x_min : 2

Constants
---------
x_max_{before} : 1
x_min_{before} : 2
x_max_{prelax} : 1
x_min_{prelax} : 2

Sensitivities
-------------
Expand All @@ -130,8 +145,8 @@ x_max : -0.99
Tightest Constraints
--------------------
+1 : x >= x_min
+1 : x_min >= x_min_Relax.2**-1*x_min_{before}_Relax.2
+1 : x_min >= x_min_{prelax}/x_min
+0.99 : x <= x_max
+0.99 : x_max <= x_max_Relax.2*x_max_{before}_Relax.2
+0.99 : x_max <= x_max_{prelax}*x_max


4 changes: 2 additions & 2 deletions docs/source/examples/simple_box_output.txt
Expand Up @@ -25,6 +25,6 @@ A_{wall} : -1.5 upper limit, wall area

Tightest Constraints
--------------------
+1.5 : A_{wall} >= 2*d*h + 2*h*w
+0.5 : alpha <= h*w**-1
+1.5 : A_{wall} >= 2*h*w + 2*h*d
+0.5 : alpha <= h/w

2 changes: 1 addition & 1 deletion docs/source/examples/simple_sp_output.txt
Expand Up @@ -10,7 +10,7 @@ y : 0.1

Tightest Constraints
--------------------
+1.1 : -y + 1 <= x
+1.1 : 1 - y <= x
+0.11 : y <= 0.1

x values of each GP solve (note convergence)
Expand Down

0 comments on commit 20d82e3

Please sign in to comment.