ERGO-Code/HiGHS

import errors and segmentation fault with highspy-1.7.1.dev1 and examples/call_highs_from_python.py

Closed this issue · 6 comments

I'm trying to get callbacks working with PuLP and highspy and in the processing of working out why mip_solution seems to have the wrong dimension, I fell back to examples/call_highs_from_python.py. However, this first gave the following issue:

$ python call_highs_from_python.py
Traceback (most recent call last):
  File "/home/wpette/src/git/HiGHS/examples/call_highs_from_python.py", line 6, in <module>
    import highspy.cb as hscb
ModuleNotFoundError: No module named 'highspy.cb'

I can get around this by changing import highspy.cb as hscb to hscb = highspy.cb but then I get

$ python call_highs_from_python.py
highspy.kHighsInf =  inf h.getInfinity() =  inf
[1]    423131 segmentation fault  python call_highs_from_python.py

I added some prints, and the segmentation fault happens on

h.changeColsCost(2, np.array([0, 1]), np.array([0, 1], dtype=np.double))

Firstly, is my change to hscb = highspy.cb correct? Does call_highs_from_python.py work as-is for other people (using highspy-1.7.1.dev1)?

I've tested

python call_highs_from_python.py

this (on Linux) and it runs fine

Can I ask what version of Python highspy you are testing this with? I just tried again on a different machine, and still get the initial ModuleNotFoundError: No module named 'highspy.cb' error. I get this using Python 3.11, and with either highspy==1.7.1.dev1 or highspy==1.5.3.

Is it possible that this is happening because I'm installing highspy from pypi? Do I need to run call_highs_from_python.py from a repository where I have built both highs and highspy from scratch?

Let me test these on my linux as well. highspy.cb is the callback module, which we have yet to test more extensively.

I tested this locally and, with the example code from our latest branch and highspy from pypi, I get a different error. It is best to use the examples/ code corresponding to the highspy version you are using.

If you want to install highspy from source, it is not necessary to install highs with cmake beforehand. It is enough to call pip install . from the HiGHS/ directory, and this would build highs and the bindings, wrapped up in the highspy package.

For call_highs_from_python.py, this example loads a file from the check/ subdir and it should be run from the root dir.

Would you please check if the following steps would work? I tested this on my linux and it resolved the issue.

python -m pip uninstall highspy
Check out our latest code from the latest branch on GitHub

And then, from the root directory, call

python -m pip install .
python examples/call_highs_from_python.py

Aah, I think I see. Yes, what you suggested works. I guess it may be best for me to wait until there is a semi-stable version of highspy before I delve further into using callbacks via PuLP.

Thanks :)

Yes, we are planing to include callbacks in the upcoming release of HiGHS, once we have tested a bit more and with documentation. Closing this for now, until further issues are encountered.