coin-or / python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Eclipse Public License 2.0
514 stars 89 forks source link

mip still not working on raspberry pi "out of the box" #276

Closed corneel27 closed 2 years ago

corneel27 commented 2 years ago

I was installing mip on a raspberry pi, but it is still not working "out of the box" I have build the binary by myself from https://github.com/coin-or / Cbc And with a softlink to the builded binary the mip library works fine. But I want to use it in Appdaemon of Home Assistant and that docker image doesn't allow me to install binaries. Is it possible to get this to work with an arm-binary?

Originally posted by @Cees-van-Beek in https://github.com/coin-or/python-mip/issues/19#issuecomment-1121188936

sebheger commented 2 years ago

@Cees-van-Beek We are working on a new way of integrating binaries to python-mip. Hopefully, more architectures will be supported. But this will take some time as a lot of research needs to be done.

corneel27 commented 2 years ago

I finally compiled a version for raspberry pi 4 (64 bit) I compiled it in a separate docker container form Home Assistant and copied all the binaries to my working python docker container. But the loading of the library didn't succeed. I tried it manually at the python prompt:

>> from cffi import FFI
>>> ffi = FFI()
>>> ffi.dlopen('/config/appdaemon/mip/lib/libCbcSolver.so')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/site-packages/cffi/api.py", line 150, in dlopen
    lib, function_cache = _make_ffi_library(self, name, flags)
  File "/usr/lib/python3.9/site-packages/cffi/api.py", line 832, in _make_ffi_library
    backendlib = _load_backend_lib(backend, libname, flags)
  File "/usr/lib/python3.9/site-packages/cffi/api.py", line 828, in _load_backend_lib
    return backend.load_library(path, flags)
OSError: cannot load library '/config/appdaemon/mip/lib/libCbcSolver.so': Error loading shared library libnauty.so.2: No such file or directory (needed by /config/appdaemon/mip/lib/libCbcSolver.so)

So I am missing libnauty.so.2 What did I wrong?

sebheger commented 2 years ago

@Cees-van-Beek Pls ask this question in the cbc repository under discussion. I think that is something related to correct build process

corneel27 commented 2 years ago

I solved my problem as follows: Because I want to use it in Home Assistant on my Raspberry PI4 I build docker-container baed on debian. The standard base there is Alpine-linux but that didn't succeed so I switched to debian. This is my Dockerfile:

ARG BUILD_FROM
FROM ${BUILD_FROM}

# Set shell
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN apt-get update -y

RUN apt-get install -y wget gcc g++ gfortran libgfortran-9-dev\
    liblapack-dev libamd2 libcholmod3 libmetis-dev libsuitesparse-dev libnauty2-dev git\
    make pkgconf nano file mariadb-client
WORKDIR /root/build
RUN wget https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew
RUN chmod a+x ./coinbrew
RUN ./coinbrew fetch Cbc@master --no-prompt
RUN mkdir -p /root/build/miplib
RUN ./coinbrew build Cbc@master --no-prompt --prefix=/root/build/miplib/ --tests=none --enable-cbc-parallel --enable-relocatable
RUN cd /root/build/miplib/lib && ln -s libCbc.so.0.0.0 libCbcSolver.so
RUN export PMIP_CBC_LIBRARY="/root/build/miplib/lib/libCbcSolver.so"
RUN export LD_LIBRARY_PATH="/root/build/miplib/lib/"
RUN echo 'export PMIP_CBC_LIBRARY="/root/build/miplib/lib/libCbcSolver.so"' >> ~/.bashrc
RUN echo 'LD_LIBRARY_PATH="/root/build/miplib/lib/"' >> ~/.bashrc

RUN apt-get install python3 -y\
    python3-pip -y

RUN pip3 install mip pandas entsoe-py mysql-connector-python

# Copy data for add-on
WORKDIR /root
COPY run.sh .
COPY worker.py .
RUN chmod a+x run.sh
RUN bash
CMD [ "/root/run.sh" ]

This works great!!