10
0
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-07-22 10:47:38 +02:00
QuantumPackage/configure
2020-02-27 10:34:04 +01:00

326 lines
7.2 KiB
Bash
Executable File

#!/bin/bash
#
# Quantum Package configuration script
#
EZFIO_TGZ="EZFIO.1.6.2.tar.gz"
# --------- Functions ----------------------------------------------------------------
function not_found() {
echo 'not_found'
}
function find_exe() {
command -v $1 2> /dev/null || not_found
}
function find_python2_lib() {
python2 -c "import $1" &> /dev/null && echo "$1" || not_found
}
function find_python3_lib() {
python3 -c "import $1" &> /dev/null && echo "$1" || not_found
}
function find_lib() {
echo "int main() { return 0; }" > "${QP_ROOT}"/external/tmp.c
gcc $@ "${QP_ROOT}"/external/tmp.c -o "${QP_ROOT}"/external/tmp.exe 2> /dev/null
if [[ -x "${QP_ROOT}"/external/tmp.exe ]] ; then
rm "${QP_ROOT}"/external/tmp.exe "${QP_ROOT}"/external/tmp.c
echo "$lib"
else
rm "${QP_ROOT}"/external/tmp.c
not_found
fi
}
function find_dir() {
if [[ -d $1 ]] ; then
echo "$1"
else
not_found
fi
}
function fail() {
echo ""
echo "Configuration failed"
exit 1
}
function success() {
echo ""
echo "Configuration successful"
exit 0
}
function help()
{
cat <<EOF
Quantum Package configuration script.
Usage:
$(basename $0) -c <file> | --config=<file>
$(basename $0) -h | --help
Options:
-c, --config=<file> Define a COMPILATION configuration file,
in "${QP_ROOT}/config/".
-h, --help Print the HELP message
Example:
./$(basename $0) -c config/gfortran.cfg
Note:
Users are encouraged to create their own configuration files instead of
modifying the existing ones.
EOF
exit
}
function failwith() {
>&2 echo "$(basename $0): $@"
fail
}
function execute () {
local _command
echo "Executing:"
while read -r line; do
echo " " $line
_command+="${line} ;"
done
sleep 1
echo ""
printf "\e[0;94m"
( eval "set -x ; $_command set +x" ) || exit -1
printf "\e[m"
echo ""
}
function check_if_git_is_installed() {
if [[ $(find_exe git) == "no" ]] ; then
failwith "git command not found"
fi
}
function set_qp_root() {
export QP_ROOT="$( cd "$(dirname "$0")" ; pwd -P )"
echo "QP_ROOT="${QP_ROOT}
echo "export QP_ROOT=\"$QP_ROOT\"" > ${QP_ROOT}/etc/00.qp_root.rc
}
function parse_command_line() {
TEMP=$(getopt -o c:i:h -l config:,install:,help -n $0 -- "$@") || exit 1
eval set -- "$TEMP"
while true ; do
case "$1" in
-c|--config)
case "$2" in
"") help ; break;;
*) if [[ -f $2 ]] ; then
CONFIG="$2"
else
failwith "Configuration file $2 not found."
fi
esac
shift 2;;
-h|-help|--help)
help
exit 0;;
--) shift ; break ;;
*)
failwith "Unknown option $1, try --help"
exit 2;;
esac
done
}
function update_submodules() {
if [[ $(find_dir "${QP_ROOT}"/external/spack/bin) = $(not_found) ]] ; then
check_if_git_is_installed
git submodule update --init --recursive
fi
# Extract EZFIO if needed
EZFIO=$(find_dir "${QP_ROOT}"/external/ezfio)
if [[ ${EZFIO} = $(not_found) ]] ; then
cd "${QP_ROOT}"/external || failwith "Unable to extract EZFIO"
tar --gunzip --extract --file ${EZFIO_TGZ}
rm -rf ezfio
mv EZFIO ezfio
fi
}
function source_spack() {
source ${QP_ROOT}/external/spack/share/spack/setup-env.sh
}
function install_exe() {
NAME=$1
shift
if [[ $(find_exe $@) = $(not_found) ]] ; then
# spack add $NAME
SPACK_LINE+="^$NAME"
fi
}
function install_lib() {
NAME=$1
shift
if [[ $(find_lib $@) = $(not_found) ]] ; then
# spack add $NAME
SPACK_LINE+="^$NAME"
fi
}
shift
if [[ $(find_python2_lib $@) = $(not_found) ]] ; then
# spack add $NAME
SPACK_LINE+="^$NAME"
fi
}
function install_spack_packages() {
spack env deactivate
spack env create qp || :
spack env activate qp
spack add python@2.7:2.8
spack add py-docopt ^python@2.7:2.8
spack add py-resultsfile@1.0 ^python@2.7:2.8
spack add py-irpf90 ^python@2.7:2.8
spack add bats
spack add ninja ^python@2.7:2.8
spack add f77-zmq ^libzmq~libsodium ^python@2.7:2.8
spack add opam@2.0:
spack add openblas threads=openmp
spack concretize -f
spack install
}
function install_python_packages() {
PYTHON_PACKAGES="irpf90 docopt resultsFile basis-set-exchange"
pip install $PYTHON_PACKAGES
if [[ $? -ne 0 ]] ; then
pip install --user $PYTHON_PACKAGES
fi
}
function install_ocaml_packages() {
OCAML_PACKAGES="ocamlbuild cryptokit zmq sexplib ppx_sexp_conv ppx_deriving getopt"
OPAMROOT=${OPAMROOT:-${QP_ROOT}/external/opam}
mkdir -p $OPAMROOT
opam init --disable-sandboxing --compiler=4.10.0 --no-setup --root=$OPAMROOT
eval $(opam env)
opam install -y ${OCAML_PACKAGES}
}
install_bse() {
if [[ $(find_exe pip) ]] ; then
pip install --user basis_set_exchange
fi
}
function configure_ninja_build() {
if [[ -n $CONFIG ]] ; then
"${QP_ROOT}"/scripts/compilation/qp_create_ninja create --development "${CONFIG}"
fi
}
function set_environment_variables() {
FILE=${QP_ROOT}/etc/local.rc
if [[ ! -z $QP_MAXMEM ]] ; then
echo "export QP_MAXMEM=$QP_MAXMEM" >> $FILE
fi
if [[ ! -z $QP_NTHREADS_DAVIDSON ]] ; then
echo "export QP_NTHREADS_DAVIDSON=$QP_NTHREADS_DAVIDSON" >> $FILE
fi
if [[ ! -z $QP_NTHREADS_PT2 ]] ; then
echo "export QP_NTHREADS_PT2=$QP_NTHREADS_PT2" >> $FILE
fi
if [[ ! -z $QP_NIC ]] ; then
echo "export QP_NIC=$QP_NIC" >> $FILE
fi
}
# ------------------------------------------------------------------------------------
set_qp_root
parse_command_line
update_submodules
source_spack
install_spack_packages
install_ocaml_packages
source quantum_package.rc
if [[ -n $CONFIG ]] ; then
configure_ninja_build
set_environment_variables
fi
printf "\e[0;34m"
echo " ___________________________ "
echo "< All dependencies installed. >"
echo " --------------------------- "
echo " \ ^__^ "
echo " \ (oo)\_______ "
echo " (__)\ )\/\. "
echo " ||----w | "
echo " || || "
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
if [[ -z ${QP_NIC} ]] ; then
echo ""
echo "Now, set edit the $QP_ROOT/etc/local.rc file to"
echo "enter the correct network interface to be used for parallel calculations"
echo "with the QP_NIC environment variable."
fi
if [[ $(find_exe bse) = $(not_found) ]] ; then
echo ""
echo "If you have PIP, you can install the Basis Set Exchange command-line tool:"
echo ""
echo " pip install basis-set-exchange"
echo ""
echo "This will enable the usage of qp_basis to install extra basis sets."
fi
echo ""
printf "\e[m\n"
if [[ -f ${QP_ROOT}/build.ninja ]] ; then
[[ -z ${TRAVIS} ]] && echo "You can now run ${QP_ROOT}/bin/qpsh to enter in the QP shell mode :)"
echo ""
echo "${QP_ROOT}/build.ninja does not exist,"
echo "you need to specify the COMPILATION configuration file."
echo "See ./configure --help for more detail."
echo ""
fi
exit 0