Install JModelica on Lubuntu 15.04

(This entry has been updated to discuss installing JModelica on XSEDE's Comet supercomputer: see below. Many of the initial steps are the same.)

My computer had 8GB of RAM. It may be that this simply will not work with 2GB of RAM or less.

Update package list

sudo apt-get update

Download and install screen, so we can work quickly, and subversion, so we can start downloading stuff:

sudo apt-get -y install screen subversion

Run screen (with automatic logging!):

screen -L

Download and install required packages

sudo apt-get -y install g++ gfortran ipython cmake swig ant python-dev python-numpy python-scipy python-matplotlib cython
python-lxml python-nose python-jpype libzip-dev openjdk-7-jdk libboost-dev jcc pkg-config

We modify the JModelica required packages to include:

  • openjdk-7-jdk - we are trying this instead of JModelica's recommended openjdk-6-jdk. Keepin' up with the times.

  • libzip-dev is necessary for JModelica as well.

  • libboost-dev provisions boost-flyweight, which is needed to run make casadi_interface

Download JModelica on one screen (I've set it here to a revision where I know things worked for my purposes):

svn co https://svn.jmodelica.org/trunk@7885 JModelica.org

While Ipopt is available as a pre-compiled package for Ubuntu, it is recommended to build Ipopt from sources. The Ipopt packages provided for Ubuntu have had flaws (including the version provided for Ubuntu 12.04) that prevented usage with JModelica.org. Also, compiling Ipopt from sources is required when using the linear solvers MA27 or MA57 from the HSL library, since these are not available as open source software.

Get IPOPT on another screen:

wget http://www.coin-or.org/download/source/Ipopt/Ipopt-3.12.4.tgz

Unpack IPOPT in the home directory. It must be in the home directory.

tar xvzf Ipopt-3.12.4.tgz

Get IPOPT third-party packages:

cd ~/Ipopt-3.12.4/ThirdParty/Blas
./get.Blas
cd ../Lapack
./get.Lapack
cd ../Mumps
./get.Mumps
cd ../Metis
./get.Metis
cd ../../                        #Go back to the IPOPT base dir

If you have access to the HSL codes MA57 or MA27 (you'll need to fetch them from here) you'll want to install them. I had them on my local machine and was installing to a server, so I used scp to move them over:

scp -C coinhsl-2014.01.10.tar.gz root@IP_ADDRESS:~/

Unpack the archive and move the contents to a place where IPOPT will see them.

cd ~/Ipopt-3.12.4/ThirdParty/HSL
tar xvzf ~/coinhsl-2014.01.10.tar.gz
mv coinhsl-2014.01.10 coinhsl

Compile IPOPT:

cd ~/Ipopt-3.12.4/
mkdir build
cd build
../configure
make -j 4                        #Compile using 4 cores (if you have them)
make install

Hopefully JModelica is done downloading by now.

Compile JModelica

cd ~/JModelica.org
mkdir build
cd build
../configure --with-ipopt=$HOME/Ipopt-3.12.4/build --prefix=$HOME
make
make install
make install_casadi

Depending on how you have your Java set up, you may need to set up some environment variables as follows. That should not be necessary for the process described here, since we have installed the correct version of Java and set up expected paths.

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
export LD_LIBRARY_PATH="$JAVA_HOME/jre/lib/amd64/server:$LD_LIBRARY_PATH"

On XSEDE these paths are:

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75.x86_64
export LD_LIBRARY_PATH="$JAVA_HOME/jre/lib/amd64/server:$LD_LIBRARY_PATH"

Once you have the paths set up, finish installing.

make install casadi_interface

Woo! It should be working!

But probably it isn't. When I did the above process, IPOPT did not find HSL, even though it was supposed to be baked in. If you get complaints about libhsl.so being missing try the following first, then look below in "Compilation & Execution Issues" for another important debugging step.

cd ~
tar xvzf coinhsl-2014.01.10.tar.gz
cd coinhsl-2014.01.10
./configure LIBS="-llapack" --with-blas="-L/usr/lib -lblas" CXXFLAGS="-g -O2 -fopenmp" FCFLAGS="-g -O2 -fopenmp" CFLAGS="-g -O2 -fopenmp"
make -j 4
make install

The library will be installed to /usr/local/lib, but IPOPT won't detect it because it will have the wrong name. Let's fix that:

ln -s /usr/local/lib/libcoinhsl.so /usr/local/lib/libhsl.so

And IPOPT still won't detect it because you need to set LD_LIBRARY_PATH:

export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH"

You can check on your dynamically loading libraries with ldconfig -v.

HSL will run with a single core unless you set the OpenMP environmental variable:

export OMP_NUM_THREADS=7 #or the number of cores you want to use

Compilation & Execution Issues

You get the message

ImportError: cannot import name transfer_optimization_problem

You didn't run make install casadi_interface. Shame on you.


You get the message

Tried to obtain MA27 from shared library "libhsl.so", but the following error occured: /usr/local/lib/libhsl.so: undefined symbol: dtrsm_

This is probably because you just ran ./configure when you compiled HSL. Use this instead:

./configure LIBS="-llapack" --with-blas="-L/usr/lib -lblas" CXXFLAGS="-g -O2 -fopenmp" FCFLAGS="-g -O2 -fopenmp"

When running a script with jm_python.sh you get the message:

Exception of type: OPTION_INVALID in file "../../../../Ipopt/src/Algorithm/IpAlgBuilder.cpp" at line 321: Exception message: Selected linear solver MA27 not available. Tried to obtain MA27 from shared library "libhsl.so", but the following error occured: libhsl.so: cannot open shared object file: No such file or directory

and it won't go away.

This is because the folks at JModelica decided to overwrite the LD_LIBRARY_PATH variable, rather than to append to it as is standard. Go into jm_python.sh and edit the line

LD_LIBRARY_PATH=:/root/Ipopt-3.12.4/build/lib/:/usr/local/jmodelica/ThirdParty/Sundials/lib:/usr/local/jmodelica/ThirdParty/CasADi/lib \

to read

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/Ipopt-3.12.4/build/lib/:/usr/local/jmodelica/ThirdParty/Sundials/lib:/usr/local/jmodelica/ThirdParty/CasADi/lib \

Note that this has been fixed (at my urging) in Revision 7984.

Compiling on XSEDE (Added 02015-10-28)

The following is known to work with Revision 8148, but some of the fixes mentioned above are utilized. I am not sure if the following bugs are new errors or the result of building in a different environment.

Use:

/share/apps/compute/interactive/req.1x24.compute

to spin up an interactive node.

Set up the environment:

module load python/1
module load cmake/3.1.0
export JAVA_HOME=$HOME/os/jdk/jdk1.8.0_65
export LD_LIBRARY_PATH="$JAVA_HOME/jre/lib:$LD_LIBRARY_PATH"
export ANT_HOME="$HOME/apache-ant-1.9.6"
export CXX=/opt/gnu/gcc/bin/g++
export CC=/opt/gnu/gcc/bin/gcc

Install Ipopt with --prefix=$HOME. Configure JModelica with:

../configure --with-ipopt=$HOME --prefix=$HOME

If you get the error:

../../../JMI/src/jmi_opt_coll_ipopt.cpp:21:34: fatal error: IpIpoptApplication.hpp: No such file or directory

then you didn't put Ipopt-3.12.4 in your home directory.

If you get the error:

/home/$USER/JModelica.org/Compiler/ModelicaCompiler/build.xml:28: Problem: failed to create task or type include
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

it is because ant is old XSEDE was running "Apache Ant version 1.7.1 compiled on June 27 2008". Acquire Ant 1.9.6, and be sure to set your environment variable correctly:

export ANT_HOME="$HOME/apache-ant-1.9.6"

You get the bug:

build/casadi_build/swig/casadi_corePYTHON_wrap.cxx:3036:13: error: ?ptrdiff_t? does not name a type

Solution: Add the following to the top of this file:

#include<cstddef>

You get the bug:

JModelica.org/ThirdParty/CasADi/CasADi/casadi/interfaces/ipopt/ipopt_nlp.hpp:29:22: fatal error: IpTNLP.hpp: No such file or directory #include

Solution:

export C_INCLUDE_PATH=/home/$USER/Ipopt-3.12.4/build/include/coin/
export CPLUS_INCLUDE_PATH=/home/$USER/Ipopt-3.12.4/build/include/coin/
export CPATH="/home/$USER/Ipopt-3.12.4/build/include/coin/:$CPATH"

You get the bug:

cp: cannot create regular file `/home/$USER/grains/JModelica.org/build2/docbook/UsersGuide/.svn/dir-prop-base': Permission denied

Solution: Run chmod -R u+w * on build

You get the bug:

Linking CXX shared library ../../../lib/libcasadi_nlpsolver_ipopt.so
/opt/gnu/bin/ld: cannot find -lipopt
/opt/gnu/bin/ld: cannot find -lcoinmumps
/opt/gnu/bin/ld: cannot find -lcoinhsl
/opt/gnu/bin/ld: cannot find -lcoinmetis
/opt/gnu/bin/ld: cannot find -lcoinlapack
/opt/gnu/bin/ld: cannot find -lcoinblas
collect2: error: ld returned 1 exit status
make[4]: *** [lib/libcasadi_nlpsolver_ipopt.so] Error 1
make[4]: Leaving directory `/home/$USER/grains/JModelica.org/build/casadi_build'

Solution: Set

export LIBRARY_PATH="/home/$USER/Ipopt-3.12.4/build/lib:$LIBRARY_PATH"

After It Is Installed

Running on XSEDE

To get the environment working:

/share/apps/compute/interactive/req.1x24.compute
module load python/1
module load cmake/3.1.0
module load scipy/2.7
export JAVA_HOME=$HOME/os/jdk/jdk1.8.0_65
export LD_LIBRARY_PATH="$JAVA_HOME/jre/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="/opt/python/lib/:$LD_LIBRARY_PATH"

Errors and Issues

Many of these errors and issues stem from the relatively minimalist environment provided by XSEDE. Since we cannot install packages ourselves to the system, the solution is to install them locally.

If, while running jm_python.sh you get the error:

python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

It's because jm_python.sh needs to be modified so that the definition of LD_LIBRARY_PATH refers to itself, similar to the following:

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/root/Ipopt-3.12.4/build/lib/:/usr/local/jmodelica/ThirdParty/Sundials/lib:/usr/local/jmodelica/ThirdParty/CasADi/lib \

If, when you run a model or jm_python.sh, you get the error:

WARNING:root:Version file not found. Environment may be corrupt.
Traceback (most recent call last):
  File "./modelica_basic.py", line 73, in <module>
    from pyjmi import transfer_optimization_problem
  File "/home/$USER/Python/pyjmi/__init__.py", line 51, in <module>
    execfile(_f)
  File "/home/$USER/startup.py", line 35, in <module>
    import jpype
ImportError: No module named jpype

Then you need to install jpype.

Acquire it:

wget https://pypi.python.org/packages/source/J/JPype1/JPype1-0.6.1.tar.gz

Install it

pip install --user JPype1-0.6.1.tar.gz

If, when you run a model or jm_python.sh, you get the error:

ImportError: No module named lxml

Then:

wget https://pypi.python.org/packages/source/l/lxml/lxml-3.5.0b1.tar.gz
pip install --user lxml-3.5.0b1.tar.gz

If, when you run a model or jm_python.sh, you get the error:

ImportError: No module named scipy.io

Then:

module load scipy/2.7

Then edit ~/bin/jm_python.sh so that the line:

PYTHONPATH=:/home/$USER/Python/: \

reads instead:

PYTHONPATH=:/home/$USER/Python/:$PYTHONPATH \

If, when you run a model or jm_python.sh, you get the error:

ImportError: cannot import name transfer_optimization_problem

Then you need to run:

make install casadi_interface

If you get the error

Assertion `in_remote[0] != '\"'' failed.

in association with cmake, then your cmake version has some kind of bug. I built cmake 3.3.2 from source and this resolved the issue.

If you get the error

Failed to get JCC installation path

Then get JCC

wget https://pypi.python.org/packages/source/J/JCC/JCC-2.21.tar.gz
export JCC_JDK=$HOME/os/jdk/jdk1.8.0_65
export LIBRARY_PATH="$HOME/os/jdk/jdk1.8.0_65/jre/lib/amd64/server:$LIBRARY_PATH"
pip install --user JCC-2.21.tar.gz

If this gives you:

/opt/gnu/bin/ld: skipping incompatible

then you have the wrong verison of Java for your machine, like an i586 build instead of an x64. Get the right one, and try again.

If, during make install casadi_interface, you get the error

ModelicaCasADiInterfaceBuild/modelicacasadi_wrapper/swig/casadi_interfacePYTHON_wrap.cxx error: ?ptrdiff_t? does not name a type

There isn't a great way to fix it since the files in question seem to be generated during the build process and I haven't figured out which source file is at fault. However, there is an ugly hack that can fix it. Run the following in a separate terminal during compilation: it will fix the issue after the files are generated but before the compiler gets to them (this may be one of the ugliest things I've ever done):

while true
do
  sed 's/^#define SWIGPYTHON/#include <cstddef>\n #define SWIGPYTHON/' -i ModelicaCasADiInterfaceBuild/modelicacasadi_wrapper/swig/ casadi_interfacePYTHON_wrap.cxx
done

links