convexengineering / gpkit

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

ValueError: Rank(A) < p using cvxopt and RuntimeWarning: invalid value in data.py #771

Closed pgkirsch closed 8 years ago

pgkirsch commented 8 years ago

Posting to help any future GPkit'ers debug.

I have a GPkit model (casey.py) that prompts the following error/traceback when solved with cvxopt:

$ ipython casey.py
C:\Python27\lib\site-packages\gpkit\nomials\data.py:189: RuntimeWarning: invalid value encountered in double_scalars
  mmap[i][j] = mag(expmap[exp][j]/c)
variable1 has no upper bound
Using solver 'cvxopt'
Solving for 40 variables.
     pcost       dcost       gap    pres   dres
 0:  0.0000e+00      nan  7e+01    nan    nan
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
C:\Users\philippe.kirschen\Documents\casey.py in <module>()
    191
    192 m = Model(objective, constraints, substitutions)
--> 193 m.solve(verbosity=5)

C:\Python27\lib\site-packages\gpkit\constraints\prog_factories.pyc in solvefn(self, solver, verbosity, skipsweepfailures, *args, **kwargs
)
     78         else:
     79             self.program, solvefn = genfunction(self, verbosity-1)
---> 80             result = solvefn(solver, verbosity-1, *args, **kwargs)
     81             solution.append(result)
     82         solution.program = self.program

C:\Python27\lib\site-packages\gpkit\geometric_program.pyc in solve(self, solver, verbosity, *args, **kwargs)
    180             sys.stdout = self.solver_log   # CAPTURED
    181             solver_out = solverfn(c=self.cs, A=self.A, p_idxs=self.p_idxs,
--> 182                                   k=self.k, *args, **kwargs)
    183             self.solver_out = solver_out
    184         finally:

C:\Python27\lib\site-packages\gpkit\_cvxopt.pyc in cvxoptimize(c, A, k, *args, **kwargs)
     42     g = log(matrix(c))
     43     F = spmatrix(A.data, A.row, A.col, tc='d')
---> 44     solution = gpsolver(k, F, g, *args, **kwargs)
     45     return dict(status=solution['status'],
     46                 primal=solution['x'],

C:\Python27\lib\site-packages\gpkit\_cvxopt.pyc in gp118(K, F, g, G, h, A, b, kktsolver, **kwargs)
    257         else: return f, Df, H
    258
--> 259     return cp(Fgp, G, h, dims, A, b, kktsolver = kktsolver)

C:\Python27\lib\site-packages\cvxopt\cvxprog.pyc in cp(F, G, h, dims, A, b, kktsolver, xnewcopy, xdot, xaxpy, xscal, ynewcopy, ydot, yaxp
y, yscal)
   1967
   1968     sol = cpl(c, F_e, G_e, h, dims, A_e, b, kktsolver_e, xnewcopy_e,
-> 1969          xdot_e, xaxpy_e, xscal_e)
   1970
   1971     sol['x'] = sol['x'][0]

C:\Python27\lib\site-packages\cvxopt\cvxprog.pyc in cpl(c, F, G, h, dims, A, b, kktsolver, xnewcopy, xdot, xaxpy, xscal, ynewcopy, ydot,
yaxpy, yscal)
    786             singular_kkt_matrix = False
    787             if iters == 0:
--> 788                 raise ValueError("Rank(A) < p or "\
    789                     "Rank([H(x); A; Df(x); G]) < n")
    790

ValueError: Rank(A) < p or Rank([H(x); A; Df(x); G]) < n
pgkirsch commented 8 years ago

With MOSEK the error was

/Users/philippekirschen/Documents/MIT/Research/GPkit/gpkit/gpkit/nomials/data.py:189: RuntimeWarning: invalid value encountered in double_scalars
  mmap[i][j] = mag(expmap[exp][j]/c)
variable1 has no upper bound
Using solver 'mosek'
Solving for 40 variables.
Warning: The variable with index '0' has only negative coefficients akj.
 The problem is possibly ill-posed.
MOSEK error 1375: A large value of      inf has been specified in cx for variable '' (11).
Number of Hessian non-zeros: 47
* Solving exponential optimization problem on dual form. *
* The following log information refers to the solution of the dual problem. *
Computer
  Platform               : MACOSX/64-X86   

Problem
  Name                   :                 
  Objective sense        : max             
  Type                   : GECO (general convex optimization problem)
  Constraints            : 41              
  Cones                  : 0               
  Scalar variables       : 87              
  Matrix variables       : 0               
  Integer variables      : 0               

Optimizer started.
Interior-point optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator - tries                  : 0                 time                   : 0.00            
Eliminator - elim's                 : 6               
Lin. dep.  - tries                  : 1                 time                   : 0.00            
Lin. dep.  - number                 : 0               
Presolve terminated. Time: 0.01    
Matrix reordering started.
Local matrix reordering started.
Local matrix reordering terminated.
Matrix reordering terminated.
Optimizer  - threads                : 4               
Optimizer  - solved problem         : the primal      
Optimizer  - Constraints            : 5
Optimizer  - Cones                  : 0
Optimizer  - Scalar variables       : 16                conic                  : 0               
Optimizer  - Semi-definite variables: 0                 scalarized             : 0               
Factor     - setup time             : 0.02              dense det. time        : 0.00            
Factor     - ML order time          : 0.00              GP order time          : 0.00            
Factor     - nonzeros before factor : 62                after factor           : 86              
Factor     - dense dim.             : 0                 flops                  : 0.00e+00        
ITE PFEAS    DFEAS    GFEAS    PRSTATUS   POBJ              DOBJ              MU       TIME  
0   0.0e+00  0.0e+00  0.0e+00  0.00e+00   0.000000000e+00   0.000000000e+00   0.0e+00  0.04  
Interior-point optimizer terminated. Time: 0.04. 

Optimizer terminated. Time: 0.07    
Return code from optimize - 1432

Interior-point solution summary
  Problem status  : UNKNOWN
  Solution status : UNKNOWN
* End solution on dual form. *
Transforming to primal solution.
Solving took 0.098 seconds.
---------------------------------------------------------------------------
RuntimeWarning                            Traceback (most recent call last)
/Users/philippekirschen/Desktop/casey.py in <module>()
    191 
    192 m = Model(objective, constraints, substitutions)
--> 193 m.solve(verbosity=5)

/Users/philippekirschen/Documents/MIT/Research/GPkit/gpkit/gpkit/constraints/prog_factories.pyc in solvefn(self, solver, verbosity, skipsweepfailures, *args, **kwargs)
     78         else:
     79             self.program, solvefn = genfunction(self, verbosity-1)
---> 80             result = solvefn(solver, verbosity-1, *args, **kwargs)
     81             solution.append(result)
     82         solution.program = self.program

/Users/philippekirschen/Documents/MIT/Research/GPkit/gpkit/gpkit/geometric_program.pyc in solve(self, solver, verbosity, *args, **kwargs)
    199                 " If the problem was Primal Infeasible, you can generate a"
    200                 " feasibility-finding relaxation with model.feasibility()." %
--> 201                 (solvername, solver_out.get("status", None)))
    202 
    203         self._generate_nula(solver_out)

RuntimeWarning: final status of solver 'mosek' was 'UNKNOWN', not 'optimal'.

The infeasible solve's result is stored in model.program.solver_out. A result dict can be generated  via program._compile_result(program.solver_out). If the problem was Primal Infeasible, you can generate a feasibility-finding relaxation with model.feasibility().
pgkirsch commented 8 years ago

The (embarrassing) mistake was that one of my substitutions was 'variable7': 3000/3600, which evaluates to zero (should have been 3000./3600).