9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-11-07 14:03:37 +01:00
qp2/configure

320 lines
7.1 KiB
Plaintext
Raw Normal View History

2020-02-26 15:58:14 +01:00
#!/bin/bash
2019-01-25 11:39:31 +01:00
#
# Quantum Package configuration script
#
2020-02-25 10:50:10 +01:00
EZFIO_TGZ="EZFIO.1.6.2.tar.gz"
2019-01-25 11:39:31 +01:00
2019-11-19 18:55:21 +01:00
2020-02-25 10:50:10 +01:00
# --------- Functions ----------------------------------------------------------------
2019-01-25 11:39:31 +01:00
2020-02-25 10:50:10 +01:00
function not_found() {
echo 'not_found'
}
2019-10-21 14:32:25 +02:00
2020-02-25 10:50:10 +01:00
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
}
2019-10-21 14:11:47 +02:00
2019-01-25 11:39:31 +01:00
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,
2020-02-26 15:58:14 +01:00
in "${QP_ROOT}/config/".
2019-01-25 11:39:31 +01:00
-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
}
2020-02-25 10:50:10 +01:00
function failwith() {
2019-01-25 11:39:31 +01:00
>&2 echo "$(basename $0): $@"
2020-02-25 10:50:10 +01:00
fail
2019-01-25 11:39:31 +01:00
}
2020-02-25 10:50:10 +01:00
2019-01-25 11:39:31 +01:00
function execute () {
local _command
echo "Executing:"
while read -r line; do
echo " " $line
_command+="${line} ;"
2020-02-26 15:58:14 +01:00
done
2019-01-25 11:39:31 +01:00
sleep 1
echo ""
printf "\e[0;94m"
( eval "set -x ; $_command set +x" ) || exit -1
printf "\e[m"
echo ""
}
2020-02-25 10:50:10 +01:00
function check_if_git_is_installed() {
if [[ $(find_exe git) == "no" ]] ; then
failwith "git command not found"
fi
2019-01-25 11:39:31 +01:00
}
2020-02-25 10:50:10 +01:00
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
2019-01-25 11:39:31 +01:00
}
2020-02-25 10:50:10 +01:00
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
2019-01-25 11:39:31 +01:00
}
2020-02-25 10:50:10 +01:00
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
2019-01-25 11:39:31 +01:00
}
2020-02-25 10:50:10 +01:00
function source_spack() {
source ${QP_ROOT}/external/spack/share/spack/setup-env.sh
}
2019-01-25 11:39:31 +01:00
2019-07-24 12:33:08 +02:00
2020-02-25 10:50:10 +01:00
function install_exe() {
NAME=$1
shift
if [[ $(find_exe $@) = $(not_found) ]] ; then
2020-02-27 11:47:30 +01:00
spack add $NAME
2020-02-25 10:50:10 +01:00
fi
}
2019-01-25 11:39:31 +01:00
2020-02-25 10:50:10 +01:00
function install_lib() {
NAME=$1
shift
if [[ $(find_lib $@) = $(not_found) ]] ; then
2020-02-27 11:47:30 +01:00
spack add $NAME
2020-02-25 10:50:10 +01:00
fi
}
2019-01-25 11:39:31 +01:00
2020-02-25 10:50:10 +01:00
function install_spack_packages() {
spack env deactivate
spack env create qp || :
spack env activate qp
2020-02-26 09:38:30 +01:00
spack add python@2.7:2.8
2020-02-27 11:47:30 +01:00
# 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
2020-02-26 09:38:30 +01:00
spack add bats
spack add ninja ^python@2.7:2.8
spack add f77-zmq ^libzmq~libsodium ^python@2.7:2.8
2020-02-27 11:47:30 +01:00
spack add opam@2.0: ^ocaml@4.09.0
if [[ $(find_exe ifort) = $(not_found) ]] ; then
spack add openblas threads=openmp
fi
2020-02-25 10:50:10 +01:00
spack concretize -f
spack install
}
2019-01-25 11:39:31 +01:00
2020-02-25 10:50:10 +01:00
function install_python_packages() {
2020-02-27 11:47:30 +01:00
PYTHON_PACKAGES="irpf90 docopt resultsFile" # basis-set-exchange"
2020-02-25 10:50:10 +01:00
pip install $PYTHON_PACKAGES
if [[ $? -ne 0 ]] ; then
pip install --user $PYTHON_PACKAGES
fi
}
2019-01-25 11:39:31 +01:00
2020-02-25 10:50:10 +01:00
function install_ocaml_packages() {
OCAML_PACKAGES="ocamlbuild cryptokit zmq sexplib ppx_sexp_conv ppx_deriving getopt"
2020-02-27 11:47:30 +01:00
export OPAMROOT=${OPAMROOT:-${QP_ROOT}/external/opam}
2020-02-25 10:50:10 +01:00
mkdir -p $OPAMROOT
opam init --disable-sandboxing --compiler=4.10.0 --no-setup --root=$OPAMROOT
eval $(opam env)
opam install -y ${OCAML_PACKAGES}
}
2019-01-25 11:39:31 +01:00
2020-02-25 10:50:10 +01:00
install_bse() {
if [[ $(find_exe pip) ]] ; then
pip install --user basis_set_exchange
fi
}
2019-01-25 11:39:31 +01:00
2020-02-25 10:50:10 +01:00
function configure_ninja_build() {
if [[ -n $CONFIG ]] ; then
"${QP_ROOT}"/scripts/compilation/qp_create_ninja create --development "${CONFIG}"
fi
}
2019-01-25 11:39:31 +01:00
2020-02-25 10:50:10 +01:00
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
}
2019-01-25 11:39:31 +01:00
2020-02-25 10:50:10 +01:00
# ------------------------------------------------------------------------------------
2019-01-25 11:39:31 +01:00
2019-02-04 13:14:57 +01:00
2020-02-25 10:50:10 +01:00
set_qp_root
parse_command_line
update_submodules
source_spack
install_spack_packages
install_ocaml_packages
2019-02-04 13:14:57 +01:00
source quantum_package.rc
2020-02-25 10:50:10 +01:00
if [[ -n $CONFIG ]] ; then
configure_ninja_build
2019-01-25 11:39:31 +01:00
fi
2020-02-27 11:47:30 +01:00
set_environment_variables
2019-01-25 11:39:31 +01:00
printf "\e[0;34m"
echo " ___________________________ "
echo "< All dependencies installed. >"
echo " --------------------------- "
echo " \ ^__^ "
echo " \ (oo)\_______ "
echo " (__)\ )\/\. "
echo " ||----w | "
echo " || || "
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
2020-02-25 10:50:10 +01:00
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
2020-02-04 19:04:36 +01:00
echo ""
2019-01-25 11:39:31 +01:00
printf "\e[m\n"
if [[ -f ${QP_ROOT}/build.ninja ]] ; then
2020-02-25 10:50:10 +01:00
[[ -z ${TRAVIS} ]] && echo "You can now run ${QP_ROOT}/bin/qpsh to enter in the QP shell mode :)"
2019-01-25 11:39:31 +01:00
echo ""
echo "${QP_ROOT}/build.ninja does not exist,"
echo "you need to specify the COMPILATION configuration file."
2020-02-27 10:19:40 +01:00
echo "See ./configure --help for more detail."
2019-01-25 11:39:31 +01:00
echo ""
fi
2019-01-25 11:39:31 +01:00
exit 0