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

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


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
cd ../Lapack
cd ../Mumps
cd ../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
make -j 4                        #Compile using 4 cores (if you have them)
make install

Hopefully JModelica is done downloading by now.

Compile JModelica

cd ~/
mkdir build
cd build
../configure --with-ipopt=$HOME/Ipopt-3.12.4/build --prefix=$HOME
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-
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 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/ /usr/local/lib/

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 "", but the following error occured: /usr/local/lib/ 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 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 "", but the following error occured: 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 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.



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


You get the bug: fatal error: IpTNLP.hpp: No such file or directory #include


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/': Permission denied

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

You get the bug:

Linking CXX shared library ../../../lib/
/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/] Error 1
make[4]: Leaving directory `/home/$USER/grains/'

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:

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="/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 you get the error:

python: error while loading shared libraries: cannot open shared object file: No such file or directory

It's because 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, you get the error:

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

Then you need to install jpype.

Acquire it:


Install it

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

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

ImportError: No module named lxml


pip install --user lxml-3.5.0b1.tar.gz

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

ImportError: No module named


module load scipy/2.7

Then edit ~/bin/ so that the line:

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

reads instead:


If, when you run a model or, 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

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
  sed 's/^#define SWIGPYTHON/#include <cstddef>\n #define SWIGPYTHON/' -i ModelicaCasADiInterfaceBuild/modelicacasadi_wrapper/swig/ casadi_interfacePYTHON_wrap.cxx