convexengineering / gpkit

Geometric programming for engineers
http://gpkit.readthedocs.org
MIT License
206 stars 40 forks source link

Trying to run .debug() on SPaircraft replaces a sub with nan (!?). #1485

Closed 1ozturkbe closed 4 years ago

1ozturkbe commented 4 years ago

Here is the error message I get when running SPaircraft/killer_plots.py.

GP Solve 4
Using solver 'mosek_cli'
 for 1191 free variables
  in 4689 posynomial inequalities.
Solving took 0.0542 seconds.
The solver failed for an unknown reason.
Since this model solved in less than a second, let's run `.debug()` automatically to check.
`
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-37f50fc60393> in <module>
----> 1 standard_killer_plot()

~/Code/SPaircraft/killer_plots.py in standard_killer_plot()
     39         substitutions.update({'R_{req}': 3000.*units('nmi'),
     40                               'n_{pass}': 180.})
---> 41         sol[i] = optimize_aircraft(m, substitutions, fixedBPRList[i], pRatOptList[i], mutategpargList[i])
     42         wf.append(sol[i]('W_{f_{total}}'))
     43

~/Code/SPaircraft/SPaircraft.py in optimize_aircraft(m, substitutions, fixedBPR, pRatOpt, x0)
     58     m.substitutions.update(substitutions)
     59     m = Model(m.cost, Bounded(m), m.substitutions)
---> 60     sol = m.localsolve(verbosity=2, iteration_limit=200, reltol=0.01)
     61     return sol
     62

~/.local/lib/python3.6/site-packages/gpkit/constraints/prog_factories.py in solvefn(self, solver, verbosity, skipsweepfailures, **solveargs)
    124         else:
    125             self.program, progsolve = genfunction(self)
--> 126             result = progsolve(solver, verbosity=verbosity, **solveargs)
    127             if solveargs.get("process_result", True):
    128                 self.process_result(result)

~/.local/lib/python3.6/site-packages/gpkit/constraints/sgp.py in localsolve(self, solver, verbosity, x0, reltol, iteration_limit, **solveargs)
    156                 print("===============")
    157             solver_out = gp.solve(solver, verbosity=verbosity-1,
--> 158                                   gen_result=False, **solveargs)
    159             self.solver_outs.append(solver_out)
    160             cost = float(solver_out["objective"])

~/.local/lib/python3.6/site-packages/gpkit/constraints/gp.py in solve(self, solver, verbosity, gen_result, **kwargs)
    218                 print(msg + "\nSince this model solved in less than a second,"
    219                       " let's run `.debug()` automatically to check.\n`")
--> 220                 return self.model.debug(solver=solver)
    221             msg += (" Running `.debug()` may pinpoint the trouble. You can"
    222                     " also try another solver, or increase the verbosity.")

AttributeError: 'NoneType' object has no attribute 'debug'
1ozturkbe commented 4 years ago

Solve fails, tries to run debug and errors. Will investigate.

1ozturkbe commented 4 years ago

Really weird behavior, but if I take the model in SPaircraft, and instead of calling .localsolve I call .debug, it replaces a particular substitution with nan.

In [26]: m.substitutions['M_{4a}']
Out[26]:
array([[   nan],
       [0.1025],
       [0.1025],
       [0.1025],
       [0.1025]], dtype=float32)

No idea why...

bqpd commented 4 years ago

huh. have you tried going step-by-step through the debug method to see what line this happens in? Maybe this is a bug in RelaxConstants?

On Mon, Apr 20, 2020 at 8:32 AM Berk Ozturk notifications@github.com wrote:

Really weird behavior, but if I take the model in SPaircraft, and instead of calling .localsolve I call .debug, it replaces a particular substitution with nan.

In [26]: m.substitutions['M_{4a}'] Out[26]: array([[ nan], [0.1025], [0.1025], [0.1025], [0.1025]], dtype=float32)

No idea why...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/convexengineering/gpkit/issues/1485#issuecomment-616630078, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALKAGEDGR7GHLOFXNZAHNTRNRTIVANCNFSM4MMQZ2SQ .

1ozturkbe commented 4 years ago

I'm going to do it today, just had other fish to fry for a little.

1ozturkbe commented 4 years ago

Issue is in varkeys for VectorVariables. Eg. In ConstantsRelaxed, constants.keys() has VectorVariable[i=1,...,k] as VarKeys, whereas the substitutions have VectorVariable[:] only. Since the keys don't match, any model with VectorVariables does not support debug at all right now.

1ozturkbe commented 4 years ago

A little shocked that we didn't have a test for this. Perhaps adding some debugs to gpkit example tests would resolve this.

1ozturkbe commented 4 years ago

The nans however are more odd. It seems like, when a substitutions are passed for only some elements of a VectorVariable, the dict is filled with nans for the non-substituted indices.

bqpd commented 4 years ago

that is expected behaviour: we use nan to flag non-substituted variables.

On Thu, Apr 23, 2020 at 9:00 AM Berk Ozturk notifications@github.com wrote:

The nans however are more odd. It seems like, when a substitutions are passed for only some elements of a VectorVariable, the dict is filled with nans for the non-substituted indices.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/convexengineering/gpkit/issues/1485#issuecomment-618484428, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALKAGGNYJDR6I57V2QFY7DROBQYVANCNFSM4MMQZ2SQ .

bqpd commented 4 years ago

related to #1488, I think