Closed whoburg closed 8 years ago
How about test as a class method? On Mar 31, 2016 10:20, "Warren Hoburg" notifications@github.com wrote:
What's the best practice for writing test methods for models in the model library? I'd like the general philosophy to be:
- models don't have default values placed directly in the variables or constraints
- test methods substitute some default values and choose a reasonable objective, and then solve
I don't want to use .substitutions.update in test(self, ...) because then calling test mutates the substitutions of the model, which is unexpected.
Should models also expose some sort of defaults() method that gives default substitutions?
Can we get an example of a simple model with a test method?
— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/hoburg/gpkit-models/issues/59
example:
class Atmosphere(ConstraintSet):
# ...
@classmethod
def test(cls):
import numpy.testing as npt
from gpkit import Model
cs = cls()
substitutions = {} # ...
m = Model(cs["\\rho"], cs, substitutions)
sol = m.solve()
# test the solution
Atmosphere.test()
sounds good.
@bqpd: @whoburg and I discussed using this same structure for making different variants on models e.g.
@classmethod
def standalone_737(cls):
objective = ...
substitutions = {...}
m = Model(....)
return m
@classmethod
def aircraft_737(cls): # for full aircraft model
substitutions = {....} # shorter substitutions dict
m = Model(....)
return m
How do you feel about this? I'm currently in the middle of implementing it for my GPjet models as a test before porting over to gpkit models and (hopefully) ending GPjet for good.
Where the original
class VerticalTail(Model):
...
becomes
class VerticalTail(ConstraintSet):
...
Ooh, I like that!
Sweet. One thing I can't figure out: does this mean ConstraintSet
will need a __getitem__
method to be able to do something like objective = cs['W_{vt}']
?
Yeah, I'm going to rename constraintset to something else so it can have user-facing things like that.
But for now you could just use strings.
what do you mean use strings?
One thing I have figure out is how to do it with CostedConstraintSet, which also works pretty well I think
Oh, derp. I was thinking for substitutions. For cost there's no nice way to do it right now.
Yeah, costedconstraintset has getitem
What's the best practice for writing test methods for models in the model library? I'd like the general philosophy to be:
I don't want to use
.substitutions.update
intest(self, ...)
because then calling test mutates the substitutions of the model, which is unexpected.Should models also expose some sort of
defaults()
method that gives default substitutions?Can we get an example of a simple model with a test method?