Skip to content

Commit

Permalink
Merge 37f1d59 into c8cf2b3
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Jan 8, 2022
2 parents c8cf2b3 + 37f1d59 commit b212587
Show file tree
Hide file tree
Showing 46 changed files with 2,153 additions and 375 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ attr-rgx=[a-z_][a-z0-9_]{2,30}$
attr-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,30}|nu|la|ax$
argument-rgx=[a-z_][a-z0-9_]{2,30}|nu|la|ax|vk$

# Naming hint for argument names
argument-name-hint=[a-z_][a-z0-9_]{2,30}$
Expand Down
5 changes: 5 additions & 0 deletions docs/source/_static/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import 'theme.css';

div[class^='highlight-breakdowns'] pre {
line-height: 1.15 !important;
}
6 changes: 6 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

html_css_files = [
'css/custom.css',
]

html_style = 'css/custom.css'

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
Expand Down
7 changes: 5 additions & 2 deletions docs/source/debugging.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Debugging Models
****************

A number of errors and warnings may be raised when attempting to solve a model.
A number of errors and warnings may be raised when attempting to solve a model.
A model may be primal infeasible: there is no possible solution that satisfies all constraints. A model may be dual infeasible: the optimal value of one or more variables is 0 or infinity (negative and positive infinity in logspace).

For a GP model that does not solve, solvers may be able to prove its primal or dual infeasibility, or may return an unknown status.
Expand All @@ -11,6 +11,7 @@ GPkit contains several tools for diagnosing which constraints and variables migh
.. literalinclude:: examples/debug.py

.. literalinclude:: examples/debug_output.txt
:language: breakdowns

Note that certain modeling errors (such as omitting or forgetting a constraint) may be difficult to diagnose from this output.

Expand All @@ -33,7 +34,7 @@ Potential errors and warnings
- ``RuntimeWarning: Dual cost nan does not match primal cost 1.00122315152``
- Similarly to the above, this warning may be seen in dual infeasible models, see *Dual Infeasibility* below.

..
..
note: remove the above when we match solver tolerance in GPkit (issue #753)

Expand All @@ -54,6 +55,7 @@ For example, Mosek returns ``DUAL_INFEAS_CER`` when attempting to solve the foll
Upon viewing the printed output,

.. literalinclude:: examples/unbounded_output.txt
:language: breakdowns

The problem, unsurprisingly, is that the cost ``1/x`` has no lower bound because ``x`` has no upper bound.

Expand Down Expand Up @@ -84,3 +86,4 @@ If you suspect your model is primal infeasible, you can find the nearest primal
.. literalinclude:: examples/relaxation.py

.. literalinclude:: examples/relaxation_output.txt
:language: breakdowns
5 changes: 5 additions & 0 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ minimize :math:`x` subject to the constraint :math:`x \ge 1`.
Of course, the optimal value is 1. Output:

.. literalinclude:: examples/x_greaterthan_1_output.txt
:language: breakdowns

Maximizing the Volume of a Box
==============================
Expand All @@ -27,6 +28,7 @@ This example comes from Section 2.4 of the `GP tutorial <http://stanford.edu/~bo
The output is

.. literalinclude:: examples/simple_box_output.txt
:language: breakdowns

Water Tank
==========
Expand All @@ -37,6 +39,7 @@ Say we had a fixed mass of water we wanted to contain within a tank, but also wa
The output is:

.. literalinclude:: examples/water_tank_output.txt
:language: breakdowns

Simple Wing
===========
Expand All @@ -47,6 +50,7 @@ This example comes from Section 3 of `Geometric Programming for Aircraft Design
The output is:

.. literalinclude:: examples/simpleflight_output.txt
:language: breakdowns

Simple Beam
===========
Expand All @@ -57,6 +61,7 @@ In this example we consider a beam subjected to a uniformly distributed transver
The output is:

.. literalinclude:: examples/beam_output.txt
:language: breakdowns

By plotting the deflection, we can see that the agreement between the analytical solution and the GP solution is good.

Expand Down
61 changes: 44 additions & 17 deletions docs/source/examples/beam_output.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@

Optimal Cost
------------
1.621
┃┓ ┓ ┓ ┓ ┓
┃┃ ┃ ┃ ┃ ┣╸th[2]╶⎨
┃┃ ┃ ┃ ┣╸w[2] ┛ (0.285)
┃┃ ┃ ┃ ┃ (0.384m) ┣╸th[1]╶⎨
┃┃ ┃ ┣╸w[3] ┛ ┣╸w[1]╶⎨
┃┃ ┃ ┃ (0.76m) ┣╸th[3] ┣╸th[2]╶⎨
┃┃ ┃ ┃ ┛ (0.341) ┛
┃┃ ┣╸w[4] ┃ ┣╸th[2]╶⎨
┃┃ ┃ (1.18m) ┛ ┛
Cost╺┫┃ ┃ ┣╸th[3] ┣╸th[2]╶⎨
(1.62m) ┃┣╸w[5] ┃ ┛ ┛
┃┃ (1.62m) ┃ ┓ ┓
┃┃ ┃ ┣╸th[4] ┣╸th[2]╶⎨
┃┃ ┛ ┛ (0.363) ┛
┃┃ ┓ ┓
┃┃ ┣╸th[5] ┣╸th[2]╶⎨
┃┃ ┛ (0.367) ┛
┃┃ ┓ ┓
┃┃ ┣╸th[4] ┣╸th[2]╶⎨
┃┛ ┛ ┛



┃┓ ┓
┃┃ ┃
┃┃ ┣╸L = 5·dx
┃┃ ┛
┃┃ ┓
┃┃ ┃
┃┃ ┣╸L = 6m
┃┃ ┛
┃┃ ┣╸EI = 11,000N·m²
Model╺┫┃ ┣╸w[5] ≥ w[4] + 0.5·dx·(th[5] + th[4])
┃┣╸Beam ┣╸th[2] ≥ th[1] + 0.5·dx·(M[2] + M[1])/EI
┃┃ ┣╸w[4] ≥ w[3] + 0.5·dx·(th[4] + th[3])
┃┃ ┣╸M[1] ≥ M[2] + 0.5·dx·(V[1] + V[2])
┃┃ ┣╸th[3] ≥ th[2] + 0.5·dx·(M[3] + M[2])/EI
┃┃ ┣╸V[3] ≥ V[4] + 0.5·dx·(q[3] + q[4])
┃┃ ┣╸th[1] ≥ th[0] + 0.5·dx·(M[1] + M[0])/EI
┃┃ ┓
┃┃ ┃
┃┃ ┣╸[17 terms]
┃┛ ┛


Free Variables
--------------
Expand All @@ -11,17 +52,3 @@ dx : 1.2 [m] Lengt
th : [ 0.0002 0.177 0.285 0.341 0.363 0.367 ] Slope
w : [ 0.0002 0.107 0.384 0.76 1.18 1.62 ] [m] Displacement

Most Sensitive Variables
------------------------
L : +4 Overall beam length
EI : -1 Bending stiffness
q : [ +0.0072 +0.042 +0.12 +0.23 +0.37 +0.22 ] Distributed load

Most Sensitive Constraints
--------------------------
+4 : L = 5·dx
+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])

54 changes: 54 additions & 0 deletions docs/source/examples/breakdowns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"An example to show off Breakdowns"
import os
import sys
import pickle
from gpkit.breakdowns import Breakdowns

# the code to create solar.p is in ./breakdowns/solartest.py
filepath = os.path.dirname(os.path.realpath(__file__)) + os.sep + "solar.p"
print(filepath)
sol = pickle.load(open(filepath, "rb"))
bds = Breakdowns(sol)

print("Cost breakdown (you may be familiar with this from solution tables)")
print("==============")
try:
bds.plot("cost")
except AttributeError: # if the pint version differs from the pickled solution
sys.exit(0)

print("Variable breakdowns (note the two methods of access)")
print("===================")
varkey, = sol["variables"].keymap[("Mission.FlightSegment.AircraftPerf"
".AircraftDrag.Poper")]
bds.plot(varkey)
bds.plot("AircraftPerf.AircraftDrag.MotorPerf.Q")

print("Combining the two above by increasing maxwidth")
print("----------------------------------------------")
bds.plot("AircraftPerf.AircraftDrag.Poper", maxwidth=105)

print("Model sensitivity breakdowns (note the two methods of access)")
print("============================")
bds.plot("model sensitivities")
bds.plot("Aircraft")

print("Exhaustive variable breakdown traces (and configuration arguments)")
print("====================================")
# often useful as a reference point when reading traces
bds.plot("AircraftPerf.AircraftDrag.Poper", height=12)
# includes factors, can be useful for reading traces as well
bds.plot("AircraftPerf.AircraftDrag.Poper", showlegend=True)
print("\nPermissivity = 2 (the default)")
print("----------------")
bds.trace("AircraftPerf.AircraftDrag.Poper")
print("\nPermissivity = 1 (stops at Pelec = v·i)")
print("----------------")
bds.trace("AircraftPerf.AircraftDrag.Poper", permissivity=1)

# you can also produce Plotly treemaps/icicle plots of your breakdowns
fig = bds.treemap("model sensitivities", returnfig=True)
fig = bds.icicle("cost", returnfig=True)
# uncommenting any of the below makes and shows the plot directly
# bds.icicle("model sensitivities")
# bds.treemap("cost")
6 changes: 6 additions & 0 deletions docs/source/examples/breakdowns/solartest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from solar.solar import *
Vehicle = Aircraft(Npod=3, sp=True)
M = Mission(Vehicle, latitude=[20])
M.cost = M[M.aircraft.Wtotal]

M.localsolve().save("solar.p")
Loading

0 comments on commit b212587

Please sign in to comment.