インストール

Linux上において,python-fabmのセットアップを行った備忘録です.ホームディレクトリ~/直下にインストールすることを想定します.また,Python 2.7が必要です.minicondaでPython 2.7の仮想環境pyfabmを作成し,activateしておきます.さらに,jupyter notebookをはじめ,一通りのパッケージがpyfabm環境でインストールされている必要があります.

ソースコードの入手

Githubから最新のソースコードを入手します.展開すると,~/fabm/が作成されます.

~/$ git clone https://github.com/fabm-model/fabm.git

インストールスクリプトの準備

ビルド用のディレクトリ~/fabm/build/を作成しておきます.
~/fabm/scripts/linux/に存在するconfigureとbuild用のスクリプト,fabm_configure_python.shfabm_build_python.sh~/fabm/build/[cci]にコピーします.[cci]fabm_configure_python.shを適切に編集します.ifortでコンパイルする場合の例を以下に示します.

#!/bin/sh

# if not set use the suggested source code installation directories
FABM_BASE=${FABM_BASE:=~/fabm}

# default Fortran compiler is gfortran - overide by setting compuiler like:
export compiler=ifort
compiler=${compiler:=gfortran}

host=python
# ready to configure
mkdir -p $host/$compiler
cd $host/$compiler
cmake $FABM_BASE/src/drivers/python \
      -DFABM_EMBED_VERSION=on \
      -DCMAKE_Fortran_COMPILER=$compiler
cd ../..

次に,fabm_build_python.shを以下のように編集します.

#!/bin/bash

if [ "$1" != "" ]; then
   action=$1
   echo "doing a "$action
else
   action=install
fi

# default Fortran compiler is gfortran - overide by setting compuiler like:
export compiler=ifort
compiler=${compiler:=gfortran}

host=python

np=-j8
cd $host/$compiler
make $np $action
cd ../..

ビルド

用意したスクリプトを用いてconfigureおよびbuildしインストールします.~/fabm/build/に移動します.

~/fabm/build$ ./fabm_configure_python.sh
-- The Fortran compiler identification is Intel 18.0.3.20180410
-- Check for working Fortran compiler: /opt/intel/compilers_and_libraries_2018.3.222/linux/bin/intel64/ifort
-- Check for working Fortran compiler: /opt/intel/compilers_and_libraries_2018.3.222/linux/bin/intel64/ifort  -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /opt/intel/compilers_and_libraries_2018.3.222/linux/bin/intel64/ifort supports Fortran 90
-- Checking whether /opt/intel/compilers_and_libraries_2018.3.222/linux/bin/intel64/ifort supports Fortran 90 -- yes
-- Found PythonInterp: /home/username/miniconda3/envs/pyfabm/bin/python (found version "2.7.15")
-- Installation prefix: /home/username/.local/lib/python2.7/site-packages
-- Configuring done
-- Generating done
-- Build files have been written to: /home/username/fabm/build/python/ifort
"Release"
-- Installing: /home/username/.local/lib/python2.7/site-packages/pyfabm/libpython_fabm.so
-- Up-to-date: /home/username/.local/lib/python2.7/site-packages/pyfabm
-- Installing: /home/username/.local/lib/python2.7/site-packages/pyfabm/complete_yaml.py
-- Installing: /home/username/.local/lib/python2.7/site-packages/pyfabm/gui_qt.py
-- Installing: /home/username/.local/lib/python2.7/site-packages/pyfabm/utils
-- Installing: /home/username/.local/lib/python2.7/site-packages/pyfabm/utils/fabm_complete_yaml.py
-- Installing: /home/username/.local/lib/python2.7/site-packages/pyfabm/utils/fabm_configuration_gui.py
-- Installing: /home/username/.local/lib/python2.7/site-packages/pyfabm/utils/fabm_describe_model.py
-- Installing: /home/username/.local/lib/python2.7/site-packages/pyfabm/utils/fabm_evaluate.py
-- Installing: /home/username/.local/lib/python2.7/site-packages/pyfabm/utils/fabm_stress_test.py
-- Installing: /home/username/.local/lib/python2.7/site-packages/pyfabm/utils/__init__.py
-- Installing: /home/username/.local/lib/python2.7/site-packages/pyfabm/__init__.py

Follow me!