Closed codykarcher closed 8 years ago
Only Model implements .controlpanel()
right now.
I'll make it so you can make that a Model
Hmm, but I think conrtolpanels might still only work with .solve
...
Yea, that was the error I was getting. Sorry, should have posted:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-dcd8be9650e5> in <module>()
----> 1 m.controlpanel()
/Users/codykarcher/Dropbox (MIT)/Research/gpkit/gpkit/constraints/costed.pyc in controlpanel(self, *args, **kwargs)
83 """
84 from ..interactive.widgets import modelcontrolpanel
---> 85 return modelcontrolpanel(self, *args, **kwargs)
/Users/codykarcher/Dropbox (MIT)/Research/gpkit/gpkit/interactive/widgets.pyc in modelcontrolpanel(model, *args, **kwargs)
94 """
95
---> 96 sliders = model.interact(*args, **kwargs)
97 sliderboxes = []
98 for sl in sliders.children:
/Users/codykarcher/Dropbox (MIT)/Research/gpkit/gpkit/constraints/costed.pyc in interact(self, ranges, fn_of_sol, **solvekwargs)
74 """
75 from ..interactive.widgets import modelinteract
---> 76 return modelinteract(self, ranges, fn_of_sol, **solvekwargs)
77
78 def controlpanel(self, *args, **kwargs):
/Users/codykarcher/Dropbox (MIT)/Research/gpkit/gpkit/interactive/widgets.pyc in modelinteract(model, ranges, fn_of_sol, **solvekwargs)
82 # print(out)
83
---> 84 resolve()
85
86 return widgets.interactive(resolve, **ranges)
/Users/codykarcher/Dropbox (MIT)/Research/gpkit/gpkit/interactive/widgets.pyc in resolve(**subs)
65 try:
66 try:
---> 67 model.solve(**solvekwargs)
68 except ValueError:
69 model.localsolve(**solvekwargs)
AttributeError: 'SignomialProgram' object has no attribute 'solve'
Okay, so now the following code works:
m = Model(objective, constraints)
sp = m.sp(require_signomials=False)
sp.localsolve('cvxopt', verbosity=1)
sp.controlpanel()
The control panel does what you'd expect, so it's more interesting off the bat if you set Re
to 1e6.
@cjk12, @whoburg, these "signomial programs that do not require signomials" could probably use a catchier name: LocalPrograms
? Which would imply you could create one with m.lp()
...
Did you push this?
oops, committed but did not push. Pushed now!
Ok, this is pretty cool... Whatever nomenclature is fine with me.
can someone post the full working example?
from gpkit import VectorVariable, Variable, units, Model
from gpkit.constraints.set import ConstraintSet
Re = Variable("Re", 1e6, "-", "Reynolds Number")
CL = Variable("C_L", "-", "Lift Coefficient")
CD = Variable("C_D", "-", "Drag Coefficient")
def xfoil(x0):
return [CD >= 0.01]
class AeroModel(ConstraintSet):
def as_gpconstr(self, x0):
gpconstr = super(AeroModel, self).as_gpconstr(x0)
if x0 and x0["Re"] >= 1e6:
constraints = xfoil(x0)
else:
constraints = [CD >= 1. + CL**2]
return ConstraintSet([gpconstr, constraints])
constraints = AeroModel([CL >= 1.0, Re >= 1e4*CL])
objective = CD
m = Model(objective, constraints)
sp = m.sp(require_signomials=False)
sp.localsolve('cvxopt', verbosity=1)
sp.controlpanel()
Thanks. @bqpd, yeah - I tend to think that ideally users would not need the lines
sp = m.sp(require_signomials=False)
sp.localsolve('cvxopt', verbosity=1)
and that Model.controlpanel()
would just work. Might make sense to update the error logic that spits out No Signomials remained after substitution.
A more precise name for LocalPrograms
might be SequentialGP
. Maybe we should rename CostedConstraintSet
to SequentialGP
? It's a model that can be solved as a sequence of GP's, and this includes the AeroModel
above as well as SignomialProgram
.
SequentialGP seems strictly less precise to me; we have a program whose constraints are a sequence of local approximations of GPs.
re Model.controlpanel
working, all that's missing is localsolve
. Should localsolve
work for non-SP locally approximable programs?
Closing this issue, will link in the PR thread.
yes, I think it's fine for localsolve
to work for models that contain no signomials but that contain locally approximable constraints (e.g. for external solvers)
Hmm, okay! Great.
that sounded suspicious -- am I missing something? I guess the elephant in the room is whether localsolve
should work for GPs?
Yup. See the PR for the added
def as_posyslt1(self):
raise ValueError("must be checked during solve")
which lets Cody's example Just Work.
So I'm doing the example from #590, and I can't do a
controlpanel()
on the SP. Is there a way to do this?