Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
WPettersson opened this issue Apr 16, 2024 · 6 comments
Assignees

Comments

@WPettersson
Copy link

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)?

@jajhall jajhall self-assigned this Apr 17, 2024
@galabovaa galabovaa self-assigned this Apr 21, 2024
@jajhall
Copy link
Sponsor Member

jajhall commented May 2, 2024

I've tested

python call_highs_from_python.py

this (on Linux) and it runs fine

@WPettersson
Copy link
Author

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?

@galabovaa
Copy link
Contributor

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

@galabovaa
Copy link
Contributor

galabovaa commented May 10, 2024

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

@WPettersson
Copy link
Author

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 :)

@galabovaa
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants