ERGO-Code/HiGHS

Building and using highspy 1.6.0 on Linux?

Closed this issue · 23 comments

I have build HiGHS 1.6.0, succesfully. I have ran pip install ./ and my LD_LIBRARY_PATH is exported to /opt/highs/lib64

(venv) skinkie@thinkpad ~/Sources/HiGHS $ pip install ./ --no-cache-dir --ignore-installed --force-reinstall
Processing /mnt/storage/home/skinkie/Sources/HiGHS
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting numpy>=1.7.0 (from highspy==1.6.0.dev0)
  Downloading numpy-1.26.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.2/61.2 kB 6.9 MB/s eta 0:00:00
Downloading numpy-1.26.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.2/18.2 MB 25.3 MB/s eta 0:00:00
Building wheels for collected packages: highspy
  Building wheel for highspy (pyproject.toml) ... done
  Created wheel for highspy: filename=highspy-1.6.0.dev0-cp311-cp311-linux_x86_64.whl size=6461284 sha256=a0a379834d065604a8e403ae7344b415421b473bff68091cd3f6af18b93b157c
  Stored in directory: /tmp/pip-ephem-wheel-cache-x_0g_faa/wheels/ad/90/fd/2d2d08b4e65263dcfe6f805033648eff1964166e8306a6a751
Successfully built highspy
Installing collected packages: numpy, highspy
Successfully installed highspy-1.6.0.dev0 numpy-1.26.1
(venv) skinkie@thinkpad ~/Sources/HiGHS $ python examples/minimal.py 
Traceback (most recent call last):
  File "/mnt/storage/home/skinkie/Sources/HiGHS/examples/minimal.py", line 6, in <module>
    h = highspy.Highs()
        ^^^^^^^^^^^^^
AttributeError: module 'highspy' has no attribute 'Highs'

Any clue what may go wrong here?

We are working on the highspy update, apologies that it is not working yet. dev0 should be a pre-release version.

The python interface is a top priority and we hope to have this resolved soon.

@galabovaa thanks, in the mean time I was able to use PuLP with the HiGHS binary, which is a nice way to interface as well. But I would love to make a 'native' example interface.

Hi @galabovaa, I was wondering if you already know when we can expect the next highspy release? I would like to use setSolution which I see has been added to master in July. Good to note in the docs it says this method is already available, so take some digging for users to find out it is not the case yet :).

Hi @timellemeet! Very soon: we are cleaning up some of the interface code, but the build issues are largely resolved now.

In the meantime, if you wish, you could try our development branch ppy-clean. Just check out the branch, and try "python3 -m pip install ." from the root dir. Please let me know if this works for you, I have tested it on my machines and it seems to work locally.

Processing /mnt/storage/home/skinkie/Sources/HiGHS
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: highspy
  Building wheel for highspy (pyproject.toml) ... done
  Created wheel for highspy: filename=highspy-1.6.0.dev8-cp311-cp311-linux_x86_64.whl size=1708718 sha256=da022008318c1bb3668d449655db2a5dbef491daf4c65ca3bb374a3d945bcc63
  Stored in directory: /tmp/pip-ephem-wheel-cache-orbwcymf/wheels/ad/90/fd/2d2d08b4e65263dcfe6f805033648eff1964166e8306a6a751
Successfully built highspy
Installing collected packages: highspy
Successfully installed highspy-1.6.0.dev8

But...

python minimal.py 
Traceback (most recent call last):
  File "/mnt/storage/home/skinkie/Sources/HiGHS/examples/minimal.py", line 4, in <module>
    import highspy
ModuleNotFoundError: No module named 'highspy'

Thank you for this, is this happening on Windows? Which version? Which python version?

I observed some unusual behaviour on my computers, if I simply "pip install" it installs in some default location and then the python I actually use does not see the module. If I run "python3 -m pip install . " or, on Windows, "python -m pip install . " then it installs in the correct location and is later seen by python.

I was not sure if these are occurring due to multiple python installations I've had and was curious if it behaves the same for others as well.

@galabovaa This issue is about Linux ;-) This is Python 3.11. The installation was done in my python 'home' folder.

skinkie@thinkpad ~/.local $ find | grep highs
./lib/python3.11/site-packages/highspy.cpython-312-x86_64-linux-gnu.so
./lib/python3.11/site-packages/highspy-1.6.0.dev8.dist-info
./lib/python3.11/site-packages/highspy-1.6.0.dev8.dist-info/REQUESTED
./lib/python3.11/site-packages/highspy-1.6.0.dev8.dist-info/LICENSE
./lib/python3.11/site-packages/highspy-1.6.0.dev8.dist-info/RECORD
./lib/python3.11/site-packages/highspy-1.6.0.dev8.dist-info/top_level.txt
./lib/python3.11/site-packages/highspy-1.6.0.dev8.dist-info/direct_url.json
./lib/python3.11/site-packages/highspy-1.6.0.dev8.dist-info/WHEEL
./lib/python3.11/site-packages/highspy-1.6.0.dev8.dist-info/INSTALLER
./lib/python3.11/site-packages/highspy-1.6.0.dev8.dist-info/METADATA
./lib/python3.11/site-packages/highspy-1.6.0.dev8.dist-info/AUTHORS

Sure, and you can confirm that on your machine "python" is mapped to Python 3.11, rather than Python 2?

Exactly.

skinkie@thinkpad ~/.local $ python --version
Python 3.11.7

Sweet, thank you. And which Linux is this on?

Sweet, thank you. And which Linux is this on?

Gentoo.

Thank you: it is not one we have tested on yet. I will try to set up a VM and reproduce the behaviour locally.

Thank you: it is not one we have tested on yet. I will try to set up a VM and reproduce the behaviour locally.

I am happy to test it on ArchLinux as well.

On Gentoo I have done:

python3 -m pip  install --user --break-system-packages .

Local installation of highspy for the 'ppy' branch seems to be working

@jajhall can you at least show the minimal.py is working? It does not make sense that you close a ticket that is not about building, that worked, but fails to run any example.

skinkie@thinkpad ~/Sources/HiGHS $ python
Python 3.11.7 (main, Dec 28 2023, 13:07:05) [GCC 13.2.1 20231216] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import highspy
>>> 
>>> h = highspy.Highs()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'highspy' has no attribute 'Highs'

The standard highspy interface works, but not the modelling language extension that is used by minimal.py

The modelling language is not yet formally part of HiGHS

Hence, what we support is functioning in the context of your issue

@jajhall can you give me a simple example that runs within python. It does not really make sense to a have a module, and you cannot find any example how to run it.

I cannot import highspy when I am not in the folder, so there is still something with this installation.

I created a venv and copied the installation in it, please give me a hint what i am doing wrong.

(venv) skinkie@thinkpad ~/Sources/HiGHS $ python3 -m pip  install  .
Processing /mnt/storage/home/skinkie/Sources/HiGHS
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting numpy (from highspy==1.6.0.dev8)
  Using cached numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
Using cached numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.3 MB)
Building wheels for collected packages: highspy
  Building wheel for highspy (pyproject.toml) ... done
  Created wheel for highspy: filename=highspy-1.6.0.dev8-cp311-cp311-linux_x86_64.whl size=1825905 sha256=a1115ded6950f664de9b4cb907958a907fc5934387bf9146673d9bbf0d497f49
  Stored in directory: /tmp/pip-ephem-wheel-cache-gqp9ck15/wheels/ad/90/fd/2d2d08b4e65263dcfe6f805033648eff1964166e8306a6a751
Successfully built highspy
Installing collected packages: numpy, highspy
  Attempting uninstall: highspy
    Found existing installation: highspy 1.6.0.dev8
    Uninstalling highspy-1.6.0.dev8:
      Successfully uninstalled highspy-1.6.0.dev8
Successfully installed highspy-1.6.0.dev8 numpy-1.26.4

[notice] A new release of pip is available: 23.3.2 -> 24.0
[notice] To update, run: pip install --upgrade pip
(venv) skinkie@thinkpad ~/Sources/HiGHS $ cd /tmp/
(venv) skinkie@thinkpad /tmp $ python
Python 3.11.7 (main, Dec 28 2023, 13:07:05) [GCC 13.2.1 20231216] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import highspy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'highspy'
>>> 

Ok, removed the build directory, and it now imports, that is progress.

(venv) skinkie@thinkpad ~/Sources/HiGHS $ python3 -m pip  install  .
Processing /mnt/storage/home/skinkie/Sources/HiGHS
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in /tmp/venv/lib/python3.11/site-packages (from highspy==1.6.0.dev8) (1.26.4)
Building wheels for collected packages: highspy
  Building wheel for highspy (pyproject.toml) ... done
  Created wheel for highspy: filename=highspy-1.6.0.dev8-cp311-cp311-linux_x86_64.whl size=1705963 sha256=c8623dc127219a02f4beed10fc1c230fcdc0a6c82fa865e6e728345b190667da
  Stored in directory: /tmp/pip-ephem-wheel-cache-v47aa0s5/wheels/ad/90/fd/2d2d08b4e65263dcfe6f805033648eff1964166e8306a6a751
Successfully built highspy
Installing collected packages: highspy
  Attempting uninstall: highspy
    Found existing installation: highspy 1.6.0.dev8
    Uninstalling highspy-1.6.0.dev8:
      Successfully uninstalled highspy-1.6.0.dev8
Successfully installed highspy-1.6.0.dev8

[notice] A new release of pip is available: 23.3.2 -> 24.0
[notice] To update, run: pip install --upgrade pip
(venv) skinkie@thinkpad ~/Sources/HiGHS $ cd /
(venv) skinkie@thinkpad / $ python
Python 3.11.7 (main, Dec 28 2023, 13:07:05) [GCC 13.2.1 20231216] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import highspy
>>> h = highspy.Highs()
>>> x1 = h.addVar(lb=-h.inf)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'highspy.Highs' object has no attribute 'inf'

@jajhall can you give me a simple example that runs within python. It does not really make sense to a have a module, and you cannot find any example how to run it.

The following uses of the supported Python interface work fine for me

  • examples/call_highs_from_python.py
  • examples/branch-and-price.py
(venv) skinkie@thinkpad /tmp $ python /home/skinkie/Sources/HiGHS/examples/call_highs_from_python.py 
Traceback (most recent call last):
  File "/home/skinkie/Sources/HiGHS/examples/call_highs_from_python.py", line 9, in <module>
    import highspy._highs
ModuleNotFoundError: No module named 'highspy._highs'; 'highspy' is not a package

/home/skinkie/Sources/HiGHS/examples/branch-and-price.py works.

Solution by column generation: 15 bins
Bin 1 (15 <= 15): [21, 1]
Bin 2 (15 <= 15): [23, 9]
Bin 3 (15 <= 15): [35, 33]
Bin 4 (15 <= 15): [26, 20]
Bin 5 (15 <= 15): [6, 28]
Bin 6 (15 <= 15): [4, 3]
Bin 7 (15 <= 15): [10, 12, 19]
Bin 8 (15 <= 15): [0, 5, 13, 14]
Bin 9 (15 <= 15): [15, 24, 30]
Bin 10 (15 <= 15): [11, 18, 22]
Bin 11 (15 <= 15): [2, 29, 38]
Bin 12 (15 <= 15): [34, 36, 37]
Bin 13 (15 <= 15): [27, 31, 32]
Bin 14 (15 <= 15): [7, 25]
Bin 15 (14 <= 15): [8, 16, 17, 39]
Finished in  8.41s

Greedy : 16 bins,   0.00s
Compact: 15 bins,  26.90s
ColGen : 15 bins,   8.41s

Looking forward to a new release, too.