convexengineering / gplibrary

Useful subsystem models
MIT License
10 stars 11 forks source link

"Setup" Error #21

Closed mjburton11 closed 8 years ago

mjburton11 commented 8 years ago

Hey @bqpd do you know why this is happening:

from gpkit import Model, Variable, units
from gpkit.shortcuts import Var, Model
from cost import DAPCA4Cost
from breguet_range import BreguetRange

class RvsC(Model):
    def setup(self):
        cost = DAPCA4Cost()
        rng = BreguetRange()

        C_fly = cost["C_{fly}"]
        R = rng["R"]

        R_min = Var("R_{min}", 200, "nautical_miles", "Minimum Range")

        objective = C_fly # minimize cost
        constraints = [R >= R_min]

        model = Model(objective, constraints)

        for subm in [cost, rng]:
            model = model & subm

        return model

    def test(self):
        self.solve(verbosity=0)

print RvsC().solve(verbosity=0).table(["cost", "freevariables"])

Error message:


The 'setup' method of this model had an error.
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-9-1bc47da1572c> in <module>()
     27         self.solve(verbosity=0)
     28 
---> 29 print RvsC().solve(verbosity=0).table(["cost", "freevariables"])
     30 

/Users/mjburton11/Documents/SuperUROP/gpkit/gpkit/model.pyc in __init__(self, cost, constraints, substitutions, *args, **kwargs)
     84                 extended_args.extend(args)
     85                 name = kwargs.pop("name", self.__class__.__name__)
---> 86                 setup = self.setup(*extended_args, **kwargs)
     87             except:
     88                 print("The 'setup' method of this model had an error.")

<ipython-input-9-1bc47da1572c> in setup(self)
      9         rng = BreguetRange()
     10 
---> 11         C_fly = cost["C_{fly}"]
     12         R = rng["R"]
     13 

/Users/mjburton11/Documents/SuperUROP/gpkit/gpkit/model.pyc in __getitem__(self, item)
    155         # note: this rebuilds the dictionary on every acess
    156         # if this is too slow, there could be some hashing and caching
--> 157         return self.varsbyname[item]
    158 
    159     def merge(self, other, excluded=None):

KeyError: 'C_{fly}'
bqpd commented 8 years ago

Err, it looks like there isn't a variable called C_{fly} in cost()

whoburg commented 8 years ago

the DAPCA4Cost model on master does have a C_{fly} variable -- @mjburton11 are you sure you're working on an up-to-date master branch?

mjburton11 commented 8 years ago

Oh I'm sorry, I resolved this issue and forgot to close it.