From cc98d0285ece0992cc255136c5bed266a107d1d3 Mon Sep 17 00:00:00 2001 From: Edward Burnell Date: Sun, 9 Aug 2020 20:38:37 -0800 Subject: [PATCH] constraint ordering and pint printing consistency --- docs/source/examples/autosweep.py | 3 ++- docs/source/examples/autosweep_output.txt | 2 +- docs/source/examples/performance_modeling.py | 20 +++++++++---------- .../examples/performance_modeling_output.txt | 4 ++-- gpkit/constraints/relax.py | 8 ++++---- gpkit/interactive/sankey.py | 3 ++- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/docs/source/examples/autosweep.py b/docs/source/examples/autosweep.py index fa9a7b799..1c16e8c30 100644 --- a/docs/source/examples/autosweep.py +++ b/docs/source/examples/autosweep.py @@ -17,7 +17,8 @@ l_vals = np.linspace(1, 10, 10) sol1 = bst1.sample_at(l_vals) print("values of l: %s" % l_vals) -print("values of A: %s" % sol1("A")) +print("values of A: [%s] %s" % + (" ".join("% .1f" % n for n in sol1("A").magnitude), sol1("A").units)) cost_estimate = sol1["cost"] cost_lb, cost_ub = sol1.cost_lb(), sol1.cost_ub() print("cost lower bound:\n%s\n" % cost_lb) diff --git a/docs/source/examples/autosweep_output.txt b/docs/source/examples/autosweep_output.txt index 23ccf6ea9..a9fa1c52d 100644 --- a/docs/source/examples/autosweep_output.txt +++ b/docs/source/examples/autosweep_output.txt @@ -1,6 +1,6 @@ Solved after 33 passes, cost logtol +/-0.000992 values of l: [ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.] -values of A: [ 1.99999973 5.00052732 10.00251992 17.00358613 26.0083274 37.00812871 50.0199693 65.02146472 82.03758369 100.99995485] meter ** 2 +values of A: [ 2.0 5.0 10.0 17.0 26.0 37.0 50.0 65.0 82.0 101.0] meter ** 2 cost lower bound: [3.99999897e+00 2.49990635e+01 9.99519417e+01 2.88964405e+02 6.75761038e+02 1.36887689e+03 2.49888336e+03 4.22418997e+03 diff --git a/docs/source/examples/performance_modeling.py b/docs/source/examples/performance_modeling.py index 76b5c64cd..8c002557c 100644 --- a/docs/source/examples/performance_modeling.py +++ b/docs/source/examples/performance_modeling.py @@ -113,8 +113,8 @@ def setup(self, aircraft): self.Wburn = self.aircraftp.Wburn self.Wfuel = self.aircraftp.Wfuel - return {"flightstate": self.flightstate, - "aircraft performance": self.aircraftp} + return {"aircraft performance": self.aircraftp, + "flightstate": self.flightstate} class Mission(Model): @@ -179,12 +179,12 @@ def setup(self, wing, state): mu = state.mu return { - "drag model": - CD >= 0.074/Re**0.2 + CL**2/np.pi/A/e, + "definition of D": + D >= 0.5*rho*V**2*CD*S, "definition of Re": Re == rho*V*c/mu, - "definition of D": - D >= 0.5*rho*V**2*CD*S} + "drag model": + CD >= 0.074/Re**0.2 + CL**2/np.pi/A/e} class Wing(Model): @@ -208,10 +208,10 @@ class Wing(Model): """ @parse_variables(__doc__, globals()) def setup(self): - return {"parametrization of wing weight": - W >= S*rho, - "definition of mean chord": - c == (S/A)**0.5} + return {"definition of mean chord": + c == (S/A)**0.5, + "parametrization of wing weight": + W >= S*rho} dynamic = WingAero diff --git a/docs/source/examples/performance_modeling_output.txt b/docs/source/examples/performance_modeling_output.txt index bab074f6d..98c5404c8 100644 --- a/docs/source/examples/performance_modeling_output.txt +++ b/docs/source/examples/performance_modeling_output.txt @@ -13,10 +13,10 @@ Constraints FlightSegment AircraftP - "fuel burn rate": - Wburn[:] >= 0.1·D[:] "lift": Aircraft.W + Wfuel[:] <= 0.5·rho[:]·CL[:]·S·V[:]² + "fuel burn rate": + Wburn[:] >= 0.1·D[:] "performance": WingAero "definition of D": diff --git a/gpkit/constraints/relax.py b/gpkit/constraints/relax.py index 79aed018b..4b01827e5 100644 --- a/gpkit/constraints/relax.py +++ b/gpkit/constraints/relax.py @@ -39,8 +39,8 @@ def __init__(self, original_constraints): for c in original_constraints.flat()] ConstraintSet.__init__(self, { - "relaxed constraints": relaxed_constraints, - "minimum relaxation": self.relaxvar >= 1}, original_substitutions) + "minimum relaxation": self.relaxvar >= 1, + "relaxed constraints": relaxed_constraints}, original_substitutions) class ConstraintsRelaxed(ConstraintSet): @@ -78,8 +78,8 @@ def __init__(self, original_constraints): for i, c in enumerate(original_constraints.flat())] ConstraintSet.__init__(self, { - "relaxed constraints": relaxed_constraints, - "minimum relaxation": self.relaxvars >= 1}, original_substitutions) + "minimum relaxation": self.relaxvars >= 1, + "relaxed constraints": relaxed_constraints}, original_substitutions) class ConstantsRelaxed(ConstraintSet): diff --git a/gpkit/interactive/sankey.py b/gpkit/interactive/sankey.py index 27be3c9e4..4f27be981 100644 --- a/gpkit/interactive/sankey.py +++ b/gpkit/interactive/sankey.py @@ -1,5 +1,6 @@ "implements Sankey" -from collections import defaultdict, Iterable +from collections import defaultdict +from collections.abc import Iterable import numpy as np from ipywidgets import Layout from ipysankeywidget import SankeyWidget # pylint: disable=import-error