Glossary¶
For an alphabetical listing of all commands, check out the Index
The GPkit Package¶
Lightweight GP Modeling Package
For examples please see the examples folder.
Requirements¶
numpy MOSEK or CVXOPT scipy(optional): for complete sparse matrix support sympy(optional): for latex printing in iPython Notebook
Attributes¶
- settings : dict
- Contains settings loaded from ./env/settings
- gpkit.disableUnits()¶
Disables units support in a particular instance of GPkit.
Posynomials created after this is run are incompatible with those created before. If gpkit is imported multiple times, this needs to be run each time.
- gpkit.enableUnits()¶
Enables units support in a particular instance of GPkit.
Posynomials created after this is run are incompatible with those created before. If gpkit is imported multiple times, this needs to be run each time.
Subpackages¶
Submodules¶
gpkit.geometric_program¶
Module for creating GP instances.
Example¶
>>> gp = gpkit.GP(cost, constraints, substitutions)
- class gpkit.geometric_program.GP(cost, constraints, substitutions={}, solver=None, options={})¶
Bases: gpkit.model.Model
Holds a model and cost function for passing to solvers.
- cost : Constraint
- Posynomial to minimize when solving
- constraints : list of (lists of) Constraints
- Constraints to maintain when solving (MonoEQConstraints will be turned into <= and >= constraints)
- substitutions : dict {varname: float or int} (optional)
- Substitutions to be applied before solving (including sweeps)
- solver : str (optional)
- Name of solver to use
- options : dict (optional)
- Options to pass to solver
>>> gp = gpkit.GP( # minimize 0.5*rho*S*C_D*V**2, [ # subject to Re <= (rho/mu)*V*(S/A)**0.5, C_f >= 0.074/Re**0.2, W <= 0.5*rho*S*C_L*V**2, W <= 0.5*rho*S*C_Lmax*V_min**2, W >= W_0 + W_w, W_w >= W_w_surf + W_w_strc, C_D >= C_D_fuse + C_D_wpar + C_D_ind ], substitutions) >>> gp.solve()
- solve(solver=None, printing=True, skipfailures=False)¶
Solves a GP and returns the solution.
- printing : bool (optional)
- If True (default), then prints out solver used and time to solve.
- solution : dict
- A dictionary containing the optimal values for each free variable.
- class gpkit.geometric_program.GPSolutionArray¶
Bases: gpkit.small_classes.DictOfLists
DictofLists extended with posynomial substitution.
- senssubinto(p)¶
Returns array of each solution’s sensitivity substituted into p
Returns only scalar values.
- subinto(p)¶
Returns numpy array of each solution substituted into p.
- table(tables=['cost', 'free_variables', 'constants', 'sensitivities'])¶
gpkit.model¶
Module for creating models.
Currently these are only used for GP instances, but they may be further abstractable.
gpkit.nomials¶
- class gpkit.nomials.Constraint(p1, p2)¶
Bases: gpkit.nomials.Posynomial
TODO: Add docstring
- class gpkit.nomials.MonoEQConstraint(p1, p2)¶
Bases: gpkit.nomials.Constraint
TODO: Add docstring
- class gpkit.nomials.Monomial(exps=None, cs=1, var_locs=None, allow_negative=False, **descr)¶
Bases: gpkit.nomials.Posynomial
TODO: Add docstring
- class gpkit.nomials.Posynomial(exps=None, cs=1, var_locs=None, allow_negative=False, **descr)¶
Bases: object
A representation of a posynomial.
- exps: tuple of dicts
- Exponent dicts for each monomial term
- cs: tuple
- Coefficient values for each monomial term
- var_locs: dict
- mapping from variable name to list of indices of monomial terms that variable appears in
Posynomial (if the input has multiple terms) Monomial (if the input has one term)
- descr(descr)¶
- sub(substitutions, val=None, allow_negative=False)¶
- subcmag(substitutions, val=None)¶
- to(arg)¶
- class gpkit.nomials.VarKey(k=None, **kwargs)¶
Bases: object
Used in the declaration of Posynomials to correspond to each ‘variable name’.
- k : object (usually str)
- The variable’s name attribute is derived from str(k).
- **kwargs :
- Any additional attributes, which become the descr attribute (a dict).
VarKey with the given name and descr.
- new_unnamed_id = <method-wrapper 'next' of itertools.count object at 0x7fe3e52b8290>¶
- class gpkit.nomials.Variable(*args, **descr)¶
Bases: gpkit.nomials.Monomial
- class gpkit.nomials.VectorVariable¶
Bases: gpkit.posyarray.PosyArray
A described vector of singlet Monomials.
- length : int
- Length of vector.
- *args : list
- may contain “name” (Strings)
- “value” (Iterable) “units” (Strings + Quantity)
and/or “label” (Strings)
- **descr : dict
- VarKey description
PosyArray of Monomials, each containing a VarKey with name ‘$name_{i}’, where $name is the vector’s name and i is the VarKey’s index.
gpkit.posyarray¶
Module for creating PosyArray instances.
Example¶
>>> x = gpkit.Monomial('x')
>>> px = gpkit.PosyArray([1, x, x**2])
- class gpkit.posyarray.PosyArray¶
Bases: numpy.ndarray
A Numpy array with elementwise inequalities and substitutions.
input_array : array-like
>>> px = gpkit.PosyArray([1, x, x**2])
- c¶
- outer(other)¶
Returns the array and argument’s outer product.
- prod()¶
Returns the product of the array.
- sub(subs, val=None, allow_negative=False)¶
Substitutes into the array
- sum()¶
Returns the sum of the array.
gpkit.small_classes¶
- class gpkit.small_classes.CootMatrix¶
Bases: gpkit.small_classes.CootMatrix
A very simple sparse matrix representation.
- append(i, j, x)¶
- shape = (None, None)¶
- tocoo()¶
Converts to a Scipy sparse coo_matrix
- tocsc()¶
- tocsr()¶
- todense()¶
- todia()¶
- todok()¶
- update_shape()¶
- gpkit.small_classes.CootMatrixTuple¶
alias of CootMatrix
- class gpkit.small_classes.DictOfLists¶
Bases: dict
A hierarchy of dicionaries, with lists at the bottom.
- append(sol)¶
Appends a dict (of dicts) of lists to all held lists.
- atindex(i)¶
Indexes into each list independently.
- toarray(shape=None)¶
Converts all lists into arrays.
- class gpkit.small_classes.HashVector¶
Bases: dict
A simple, sparse, string-indexed immutable vector. Inherits from dict.
The HashVector class supports element-wise arithmetic: any undeclared variables are assumed to have a value of zero.
arg : iterable
>>> x = gpkit.nomials.Monomial('x') >>> exp = gpkit.small_classes.HashVector({x: 2})
- class gpkit.small_classes.PosyTuple¶
Bases: tuple
PosyTuple(exps, cs, var_locs, substitutions)
- cs¶
Alias for field number 1
- exps¶
Alias for field number 0
- substitutions¶
Alias for field number 3
- var_locs¶
Alias for field number 2
- gpkit.small_classes.append_dict(i, o)¶
Recursviely travels dict o and appends items found in i.
- gpkit.small_classes.enlist_dict(i, o)¶
Recursviely copies dict i into o, placing non-dict items into lists.
- gpkit.small_classes.enray_dict(i, o)¶
Recursively turns lists into numpy arrays.
- gpkit.small_classes.index_dict(idx, i, o)¶
Recursviely travels dict i, placing items at idx into dict o.
gpkit.small_scripts¶
- gpkit.small_scripts.flatten(ible, classes)¶
Flatten an iterable that contains other iterables
- l : Iterable
- Top-level container
- out : list
- List of all objects found in the nested iterables
- TypeError
- If an object is found whose class was not in classes
- gpkit.small_scripts.invalid_types_for_oper(oper, a, b)¶
Raises TypeError for unsupported operations.
- gpkit.small_scripts.is_sweepvar(sub)¶
Determines if a given substitution indicates a sweep.
- gpkit.small_scripts.latex_num(c)¶
- gpkit.small_scripts.locate_vars(exps)¶
From exponents form a dictionary of which monomials each variable is in.
- gpkit.small_scripts.mag(c)¶
Return magnitude of a Number or Quantity
- gpkit.small_scripts.results_table(data, title, senss=False)¶
- gpkit.small_scripts.sort_and_simplify(exps, cs)¶
Reduces the number of monomials, and casts them to a sorted form.
- gpkit.small_scripts.unitstr(v, into='%s', options='~')¶
gpkit.substitution¶
Module containing the substitution function
- gpkit.substitution.substitution(var_locs, exps, cs, substitutions, val=None)¶
Efficient substituton into a list of monomials.
- var_locs : dict
- Dictionary of monomial indexes for each variable.
- exps : dict
- Dictionary of variable exponents for each monomial.
- cs : list
- Coefficients each monomial.
- substitutions : dict
- Substitutions to apply to the above.
- val : number (optional)
- Used to substitute singlet variables.
- gpkit.substitution.vectorsub(subs, var, sub, varset)¶
Vectorized substitution via vecmons and Variables.