fmagrini / ot-rays

Tracing Rays through Optimal Transport
4 stars 0 forks source link

Issue concerning idx out of bound #1

Open feng-spinning opened 1 year ago

feng-spinning commented 1 year ago

After compiling the setup.py python setup.py build_ext --inplace, I've got an raytracing_ot.cp39-win_amd64.pyd. Then after running the fig_4.py, I've faced with this issue:

line 132, in solve_ot 
    idx_2d = np.unravel_index(idx, cost_matrix_shape)
  File "<__array_function__ internals>", line 180, in unravel_index
ValueError: index -2147095045 is out of bounds for array with size 187295066176
fmagrini commented 1 year ago

Your error points to the presence of negative entries (-2147095045) in the variable idx (line 130). I suspect the issue is connected to the compilation of the Cython code on Windows, as idx is derived from the function get_finite_idx_and_cost, which is defined in raytracing_ot.pyx. Note that a negative entry in idx should never occur.

I also suspect that there is no issue with the definition of the velocity model; however, please double-check. If you downloaded vp.bin from https://www.geoazur.fr/WIND/bin/view/Main/Data/Marmousi, your velocity (lines 229-230) should be an array with the shape (376, 1151).

Unfortunately, I cannot reproduce your error on my machine (Linux, Ubuntu). If you are unable to switch to either Linux or Mac (e.g., through a virtual machine), the only suggestion I can offer is that you rewrite the function get_finite_idx_and_cost in Python. This should be fairly straightforward; the only "major" change in this conversion involves switching from the use of cpp_vectors to traditional Python lists (and translating cpp_vector.push_back into list.append). Another change, of course, is that the function will run much slower.

For reference, I successfully tested the code on two different Linux machines with Cython versions 0.29.33 and 3.0.0.

feng-spinning commented 1 year ago

Thanks a lot! This issue does not occur on my remote server with linux operation system. I've pip installed seislib and docplex, but now there shows docplex.mp.utils.DOcplexException: Cannot solve model: no CPLEX runtime found.. I think this might occur because i haven't got the IBM optimization software. Is this the key problem? Or i installed seislib and docplex in a wrong way. Please forgive my stupidity QAQ

fmagrini commented 1 year ago

No worries! Glad you solved your initial issue.

I suspect you will need to install the IBM optimisation software. In doing so, make sure to register and get a CPLEX license (if you are an academic, you can get one for free). The license will be needed to solve relatively large linear programming problems, such as that concerning Fig. 4.