cvxgrp / ncvx

GNU General Public License v3.0
73 stars 17 forks source link

examples/tsp.py - "IndexError: index 0 is out of bounds for axis 0 with size 0" #4

Closed mikeroberts3000 closed 6 years ago

mikeroberts3000 commented 7 years ago

Hey Steven,

This library looks great. I'm excited to try out some of the examples. I noticed that running examples/tsp.py returns an error:

DN0a22a81f:examples mike$ python tsp.py
lower bound = -inf
Traceback (most recent call last):
  File "tsp.py", line 71, in <module>
    max_iter=50)
  File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/cvxpy-0.4.9-py2.7.egg/cvxpy/problems/problem.py", line 207, in solve
    return func(self, *args, **kwargs)
  File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/ncvx-0.1.4-py2.7.egg/ncvx/admm_problem.py", line 270, in admm
    prox_polished, polish_depth, lower_bound, alpha, args, kwargs) for idx, rho_val in enumerate(rho)])
  File "/Applications/Canopy.app/appdata/canopy-1.7.4.3348.macosx-x86_64/Canopy.app/Contents/lib/python2.7/multiprocessing/pool.py", line 251, in map
    return self.map_async(func, iterable, chunksize).get()
  File "/Applications/Canopy.app/appdata/canopy-1.7.4.3348.macosx-x86_64/Canopy.app/Contents/lib/python2.7/multiprocessing/pool.py", line 567, in get
    raise self._value
IndexError: index 0 is out of bounds for axis 0 with size 0

Note that I was able to successfully run examples/circle_packing.py.

SteveDiamond commented 7 years ago

It looks like you're using ncvx 0.1.4, but the latest is 0.1.5. Could you try 0.1.5 and let me know if it works?

mikeroberts3000 commented 7 years ago

Same error after pulling from ncvx master. But this did appear to update me to ncvx 0.1.5.

DN0a22a81f:examples mike$ python tsp.py 
lower bound = -inf
Traceback (most recent call last):
  File "tsp.py", line 71, in <module>
    max_iter=50)
  File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/cvxpy-0.4.9-py2.7.egg/cvxpy/problems/problem.py", line 207, in solve
    return func(self, *args, **kwargs)
  File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/ncvx-0.1.5-py2.7.egg/ncvx/admm_problem.py", line 270, in admm
    prox_polished, polish_depth, lower_bound, alpha, args, kwargs) for idx, rho_val in enumerate(rho)])
  File "/Applications/Canopy.app/appdata/canopy-1.7.4.3348.macosx-x86_64/Canopy.app/Contents/lib/python2.7/multiprocessing/pool.py", line 251, in map
    return self.map_async(func, iterable, chunksize).get()
  File "/Applications/Canopy.app/appdata/canopy-1.7.4.3348.macosx-x86_64/Canopy.app/Contents/lib/python2.7/multiprocessing/pool.py", line 567, in get
    raise self._value
IndexError: index 0 is out of bounds for axis 0 with size 0

Do I need to be on the 1.0 branch of cvxgrp/cvxpy?

SteveDiamond commented 7 years ago

No it works for me on the normal cvxpy branch. Are you using the latest cvxpy? Also sorry for the slow reply. I was traveling.

mikeroberts3000 commented 7 years ago

Hi Steven, sorry the delayed reply. I am still getting this same error.

I am on the latest master branch of ncvx. I am also on the latest master branch of cvxpy. I installed cvxpy from source by typing "python setup.py install" from the top-level cvxpy folder. Printing out the cvxpy.__version__ string indicates that I'm on cvxpy version 0.4.10.

Mikes-MacBook-Pro:examples mike$ python tsp.py 
lower bound = -inf
Traceback (most recent call last):
  File "tsp.py", line 71, in <module>
    max_iter=50)
  File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/cvxpy-0.4.10-py2.7.egg/cvxpy/problems/problem.py", line 207, in solve
    return func(self, *args, **kwargs)
  File "/Users/mike/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/ncvx-0.1.5-py2.7.egg/ncvx/admm_problem.py", line 270, in admm
    prox_polished, polish_depth, lower_bound, alpha, args, kwargs) for idx, rho_val in enumerate(rho)])
  File "/Applications/Canopy.app/appdata/canopy-1.7.4.3348.macosx-x86_64/Canopy.app/Contents/lib/python2.7/multiprocessing/pool.py", line 251, in map
    return self.map_async(func, iterable, chunksize).get()
  File "/Applications/Canopy.app/appdata/canopy-1.7.4.3348.macosx-x86_64/Canopy.app/Contents/lib/python2.7/multiprocessing/pool.py", line 567, in get
    raise self._value
IndexError: index 0 is out of bounds for axis 0 with size 0
Mikes-MacBook-Pro:examples mike$ 
SteveDiamond commented 7 years ago

I feel bad for taking so long to reply again. I'm not sure what to say though. I couldn't replicate this bug. Does it happen for the other examples? I've never used Canopy before so maybe that's a culprit. Sorry I can't be more help.

djma commented 6 years ago

I'm getting the same error, also with graph_isomorphism.py. I'm on python 3.6, looks like mikeroberts3000 is on 2.7. My cvxpy is 0.4.11.

Traceback (most recent call last):
  File "/Users/davidma/anaconda3/envs/scheduler/lib/python3.6/multiprocessing/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/Users/davidma/anaconda3/envs/scheduler/lib/python3.6/multiprocessing/pool.py", line 44, in mapstar
    return list(map(*args))
  File "/Users/davidma/anaconda3/envs/scheduler/lib/python3.6/site-packages/ncvx/admm_problem.py", line 64, in admm_inner_iter
    prox = Prox(orig_prob, xvars)
  File "/Users/davidma/anaconda3/envs/scheduler/lib/python3.6/site-packages/scsprox/prox_obj.py", line 39, in __init__
    data, self._indmap, self._solmap = stuffed_prox(prob, x_vars)
  File "/Users/davidma/anaconda3/envs/scheduler/lib/python3.6/site-packages/scsprox/scsprox.py", line 17, in stuffed_prox
    data, indmap = param_map(pxprob, x0_vars)
  File "/Users/davidma/anaconda3/envs/scheduler/lib/python3.6/site-packages/scsprox/scs_mapping.py", line 117, in param_map
    ind = ind[0]
IndexError: index 0 is out of bounds for axis 0 with size 0

@SteveDiamond, could you make a list of all the package dependencies and their versions?

djma commented 6 years ago

Naturally, the error does not occur if I change the optimizer to 'relax-round-polish'.

The code runs without any trouble.

SteveDiamond commented 6 years ago

Ok now I get the bug. It should be fixed now. You need to install this repo from source: https://github.com/SteveDiamond/scsprox Just clone then run python setup.py install. Sorry about that.

djma commented 6 years ago

Thanks @SteveDiamond! That fixed it. Does this TSP solution look expected? It looks a bit under-optimized to me.

screen shot 2017-09-18 at 6 10 04 pm
SteveDiamond commented 6 years ago

No that doesn't look right. You would have to play around with the parameters. Honestly though it works much much better for continuous variables than for discrete variables. For discrete variables you should just use a MIP solver.