From ba35e907bc7944a878f66f6f0aaa8961a88a43d8 Mon Sep 17 00:00:00 2001 From: Tomas Jira Date: Mon, 29 Jul 2024 14:31:35 +0200 Subject: [PATCH] edit the compilation process a little --- .github/workflows/test.yml | 6 +-- CMakeLists.txt | 10 ++-- example/qdyn-lz.sh | 97 +++++++++++++++++++++++++++++++++++ program/cdyn/CMakeLists.txt | 2 +- program/integral/src/main.cpp | 2 +- program/qdyn/CMakeLists.txt | 2 +- script/libfftw.sh | 7 +-- script/libint.sh | 7 +-- script/libtorch.sh | 2 +- 9 files changed, 113 insertions(+), 22 deletions(-) create mode 100755 example/qdyn-lz.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ff71626..1b9c495 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,12 +27,12 @@ jobs: - name: Build Libfftw run: ./script/libfftw.sh - - name: Build Libtorch - run: ./script/libtorch.sh - - name: Build Libint run: ./script/libint.sh + - name: Build Libtorch + run: ./script/libtorch.sh + - name: Configure Acorn run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} diff --git a/CMakeLists.txt b/CMakeLists.txt index f72f759..6bba999 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,11 +28,11 @@ find_package(Eigen3 REQUIRED) find_package(OpenMP REQUIRED) # find installed libraries -find_library(LIBTORCH_CPU NAMES torch_cpu PATHS external/lib) -find_library(LIBTORCH NAMES torch PATHS external/lib) -find_library(LIBFFTW NAMES fftw3 PATHS external/lib) -find_library(LIBINT NAMES int2 PATHS external/lib) -find_library(LIBC10 NAMES c10 PATHS external/lib) +find_library(LIBTORCH_CPU NAMES torch_cpu PATHS external/lib NO_DEFAULT_PATH) +find_library(LIBTORCH NAMES torch PATHS external/lib NO_DEFAULT_PATH) +find_library(LIBFFTW NAMES fftw3 PATHS external/lib NO_DEFAULT_PATH) +find_library(LIBINT NAMES int2 PATHS external/lib NO_DEFAULT_PATH) +find_library(LIBC10 NAMES c10 PATHS external/lib NO_DEFAULT_PATH) # add the base library add_library(acorn_base STATIC src/expression.cpp src/linalg.cpp src/timer.cpp) diff --git a/example/qdyn-lz.sh b/example/qdyn-lz.sh new file mode 100755 index 0000000..6272eb9 --- /dev/null +++ b/example/qdyn-lz.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +rm -rf result && mkdir result + +TULLY_1="if(x>0,0.01*(1-exp(-1.6*x)),-0.01*(1-exp(1.6*x))) 0.005*exp(-x^2) + 0.005*exp(-x^2) (-1)*if(x>0,0.01*(1-exp(-1.6*x)),-0.01*(1-exp(1.6*x)))" +TULLY_1_DIS=1; TULLY_1_AIS=1; TULLY_1_IX=-7; TULLY_1_IP=9 + +TULLY_2="0 0.015*exp(-0.06*x^2) + 0.015*exp(-0.06*x^2) (-0.1)*exp(-0.28*x^2)+0.05" +TULLY_2_DIS=1; TULLY_2_AIS=1; TULLY_2_IX=-10; TULLY_2_IP=12 + +DS_1="0.01*tanh(0.6*x) 0.001*exp(-x^2) + 0.001*exp(-x^2) (-0.01)*tanh(0.6*x)" +DS_1_DIS=1; DS_1_AIS=1; DS_1_IX=-7; DS_1_IP=9 + +DS_2="0.001*x 0.001*exp(-0.05*x^2) + 0.001*exp(-0.05*x^2) (-0.001)*x" +DS_2_DIS=1; DS_2_AIS=1; DS_2_IX=-8; DS_2_IP=9 + +TS_1="0.03*(tanh(1.6*x)+tanh(1.6*(x+7))) 0.005*exp(-x^2) 0.005*exp(-(x+7)^2) + 0.005*exp(-x^2) (-0.03)*(tanh(1.6*x)+tanh(1.6*(x-7))) 0.005*exp(-(x-7)^2) + 0.005*exp(-(x+7)^2) 0.005*exp(-(x-7)^2) (-0.03)*(tanh(1.6*(x+7))-tanh(1.6*(x-7)))" +TS_1_DIS=1; TS_1_AIS=2; TS_1_IX=-10; TS_1_IP=15 + +TS_2="0.001*x 0.001*exp(-0.01*x^2) 0.002*exp(-0.01*x^2) + 0.001*exp(-0.01*x^2) 0 0.001*exp(-0.01*x^2) + 0.002*exp(-0.01*x^2) 0.001*exp(-0.01*x^2) (-0.001)*x" +TS_2_DIS=2; TS_2_AIS=2; TS_2_IX=-15; TS_2_IP=15 + +TS_3="0.01*tanh(0.6*x) 0.001*exp(-x^2) 0.001*exp(-x^2) + 0.002*exp(-x^2) 0 0.002*exp(-x^2) + 0.001*exp(-x^2) 0.002*exp(-x^2) (-0.01)*tanh(0.6*x)" +TS_3_DIS=2; TS_3_AIS=2; TS_3_IX=-10; TS_3_IP=15 + +QS_1="0.03*(tanh(1.6*(x+7))-tanh(1.6*(x-7)))+0.03 0.005*exp(-(x-7)^2) 0.005*exp(-(x+7)^2) 0 + 0.005*exp(-(x-7)^2) 0.03*(tanh(1.6*(x-7))+tanh(1.6*x)+tanh(1.6*(x+7))) 0.005*exp(-x^2) 0.005*exp(-(x+7)^2) + 0.005*exp(-(x+7)^2) 0.005*exp(-x^2) (-0.03)*(tanh(1.6*x)+tanh(1.6*(x-7))+tanh(1.6*(x+7))) 0.005*exp(-(x-7)^2) + 0 0.005*exp(-(x+7)^2) 0.005*exp(-(x-7)^2) (-0.03)*(tanh(1.6*(x+7))-tanh(1.6*(x-7)))-0.03" +QS_1_DIS=2; QS_1_AIS=3; QS_1_IX=-10; QS_1_IP=15 + +QS_2="0.01*tanh(0.6*x) 0.001*exp(-x^2) 0.001*exp(-x^2) 0.001*exp(-x^2) + 0.001*exp(-x^2) 0.003*tanh(0.6*x) 0.001*exp(-x^2) 0.001*exp(-x^2) + 0.001*exp(-x^2) 0.001*exp(-x^2) (-0.003)*tanh(0.6*x) 0.001*exp(-x^2) + 0.001*exp(-x^2) 0.001*exp(-x^2) 0.001*exp(-x^2) (-0.01)*tanh(0.6*x)" +QS_2_DIS=3; QS_2_AIS=3; QS_2_IX=-10; QS_2_IP=15 + +A=0.05; C=tab:blue; I=3500; L=500; M=2000; R=1; T=100 + +for POT in TULLY_1 TULLY_2 DS_1 DS_2 TS_1 TS_2 TS_3 QS_1 QS_2; do +# for POT in QS_2; do + P=${POT}_IP; X=${POT}_IX; DIS=${POT}_DIS; AIS=${POT}_AIS; STATES=$(echo "sqrt($(echo ${!POT} | wc -w))" | bc) + + PSI=$(for i in $(seq 1 $((2*${!DIS}))); do echo " 0"; done)" exp(-(x-(${!X}))^2) 0"$(for i in $(seq 1 $((2*($STATES-${!DIS}-1)))); do echo " 0"; done) + + acorn_expression -g -24 40 -o U_DIA.mat -p 1025 -e ${!POT} + acorn_expression -g -24 40 -o PSI_DIA_GUESS.mat -p 1025 -e $PSI + acorn_qdyn -i 350 -m $M -p ${!P} -s 10 --adiabatic --savewfn --align --factor 0.01 + + for MODE in "" "--adiabatic"; do + acorn_cdyn -c ${!X} -e $([ -z $MODE ] && echo ${!DIS} || echo ${!AIS}) -i $I -l $L -m $M -p ${!P} -r $R -s 1 -t $T -u ${!POT} $MODE --savetraj + done + + plot.py PSI_ADIA_0.mat -c $(($STATES*2)) --png --title "Adiabatic Potential & Initial Wavefunction" && mv output.png U_PSI_ADIA_$POT.png + plot.py PSI_DIA_0.mat -c $(($STATES*2)) --png --title "Adiabatic Potential & Initial Wavefunction" && mv output.png U_PSI_DIA_$POT.png + plot.py P_ADIA_0.mat P_LZ-ADIA_ADIA.mat -c $(($STATES*$STATES)) -e $(seq 1 $(($STATES+1)) $(($STATES*$STATES))) --png --title "EXACT vs LZ-ADIA: Adiabatic Populations" && mv output.png P_EXACT_v_LZ-ADIA_ADIA_$POT.png + plot.py P_DIA_0.mat P_LZ-ADIA_DIA.mat -c $(($STATES*$STATES)) -e $(seq 1 $(($STATES+1)) $(($STATES*$STATES))) --png --title "EXACT vs LZ-ADIA: Diabatic Populations" && mv output.png P_EXACT_v_LZ-ADIA_DIA_$POT.png + plot.py P_ADIA_0.mat P_LZ-DIA_ADIA.mat -c $(($STATES*$STATES)) -e $(seq 1 $(($STATES+1)) $(($STATES*$STATES))) --png --title "EXACT vs LZ-DIA: Adiabatic Populations" && mv output.png P_EXACT_v_LZ-DIA_ADIA_$POT.png + plot.py P_DIA_0.mat P_LZ-DIA_DIA.mat -c $(($STATES*$STATES)) -e $(seq 1 $(($STATES+1)) $(($STATES*$STATES))) --png --title "EXACT vs LZ-DIA: Diabatic Populations" && mv output.png P_EXACT_v_LZ-DIA_DIA_$POT.png + plot.py P_LZ-ADIA_DIA.mat P_LZ-ADIA_ADIA.mat -c $(($STATES*$STATES)) -e $(seq 1 $(($STATES+1)) $(($STATES*$STATES))) --png --title "LZ-ADIA: Both Populations" && mv output.png P_LZ-ADIA_BOTH_$POT.png + plot.py P_LZ-DIA_DIA.mat P_LZ-DIA_ADIA.mat -c $(($STATES*$STATES)) -e $(seq 1 $(($STATES+1)) $(($STATES*$STATES))) --png --title "LZ-DIA: Both Populations" && mv output.png P_LZ-DIA_BOTH_$POT.png + montage -geometry "2400x1800" -title "Dynamics Summary (P=${!P}, TRAJS=$T)" U_PSI_DIA_$POT.png P_EXACT_v_LZ-DIA_DIA_$POT.png P_EXACT_v_LZ-DIA_ADIA_$POT.png P_LZ-DIA_BOTH_$POT.png U_PSI_ADIA_$POT.png P_EXACT_v_LZ-ADIA_DIA_$POT.png P_EXACT_v_LZ-ADIA_ADIA_$POT.png P_LZ-ADIA_BOTH_$POT.png 1_$POT.png + + # plot.py ETOT_LZ-ADIA_*.mat -p $C -a $A --png --title "Adiabatic Trajectory: Total Energy" && mv output.png ETOT_LZ-ADIA_$POT.png + # plot.py ETOT_LZ-DIA_*.mat -p $C -a $A --png --title "Diabatic Trajectory: Total Energy" && mv output.png ETOT_LZ-DIA_$POT.png + # plot.py R_LZ-ADIA_*.mat -p $C -a $A --png --title "Adiabatic Trajectory: Position" && mv output.png R_LZ-ADIA_$POT.png + # plot.py R_LZ-DIA_*.mat -p $C -a $A --png --title "Diabatic Trajectory: Position" && mv output.png R_LZ-DIA_$POT.png + # plot.py V_LZ-ADIA_*.mat -p $C -a $A --png --title "Adiabatic Trajectory: Velocity" && mv output.png V_LZ-ADIA_$POT.png + # plot.py V_LZ-DIA_*.mat -p $C -a $A --png --title "Diabatic Trajectory: Velocity" && mv output.png V_LZ-DIA_$POT.png + # plot.py A_LZ-ADIA_*.mat -p $C -a $A --png --title "Adiabatic Trajectory: Acceleration" && mv output.png A_LZ-ADIA_$POT.png + # plot.py A_LZ-DIA_*.mat -p $C -a $A --png --title "Diabatic Trajectory: Acceleration" && mv output.png A_LZ-DIA_$POT.png + # montage -geometry "2400x1800" ETOT_LZ-DIA_$POT.png R_LZ-DIA_$POT.png V_LZ-DIA_$POT.png A_LZ-DIA_$POT.png ETOT_LZ-ADIA_$POT.png R_LZ-ADIA_$POT.png V_LZ-ADIA_$POT.png A_LZ-ADIA_$POT.png 2_$POT.png + + # plot.py E_LZ-ADIA_*.mat -p $C -a $A --png --title "Adiabatic Simulation: TD Particle Energy" && mv output.png E_LZ-ADIA_$POT.png + # plot.py E_LZ-DIA_*.mat -p $C -a $A --png --title "Diabatic Simulation: TD Particle Energy" && mv output.png E_LZ-DIA_$POT.png + # plot.py ED_LZ-ADIA_*.mat -p $C -a $A -c 2 -e 1 --png --title "Adiabatic Simulation: TD Energy Differences" && mv output.png ED_LZ-ADIA_$POT.png + # plot.py ED_LZ-DIA_*.mat -p $C -a $A -c 2 -e 1 --png --title "Diabatic Simulation: TD Energy Differences" && mv output.png ED_LZ-DIA_$POT.png + # plot.py DED_LZ-ADIA_*.mat -p $C -a $A -c 2 -e 1 --png --title "Adiabatic Simulation: TD Energy Differences - 1st Derivative" && mv output.png DED_LZ-ADIA_$POT.png + # plot.py DED_LZ-DIA_*.mat -p $C -a $A -c 2 -e 1 --png --title "Diabatic Simulation: TD Energy Differences - 1st Derivative" && mv output.png DED_LZ-DIA_$POT.png + # plot.py DDED_LZ-ADIA_*.mat -p $C -a $A -c 2 -e 1 --png --title "Adiabatic Simulation: TD Energy Differences - 2nd Derivative" && mv output.png DDED_LZ-ADIA_$POT.png + # plot.py DDED_LZ-DIA_*.mat -p $C -a $A -c 2 -e 1 --png --title "Diabatic Simulation: TD Energy Differences - 2nd Derivative" && mv output.png DDED_LZ-DIA_$POT.png + # montage -geometry "2400x1800" E_LZ-DIA_$POT.png ED_LZ-DIA_$POT.png DED_LZ-DIA_$POT.png DDED_LZ-DIA_$POT.png E_LZ-ADIA_$POT.png ED_LZ-ADIA_$POT.png DED_LZ-ADIA_$POT.png DDED_LZ-ADIA_$POT.png 3_$POT.png + + convert -append [1-9]_$POT.png result/$POT.png && rm -rf *.mat +done + +rm -rf *.png diff --git a/program/cdyn/CMakeLists.txt b/program/cdyn/CMakeLists.txt index a7af438..736b136 100644 --- a/program/cdyn/CMakeLists.txt +++ b/program/cdyn/CMakeLists.txt @@ -8,6 +8,6 @@ target_include_directories(acorn_cdyn PRIVATE include) target_link_libraries(acorn_cdyn acorn_base) # link OpenMP -if(OpenMP_CXX_FOUND AND CMAKE_BUILD_TYPE STREQUAL "Release") +if(OpenMP_CXX_FOUND) target_link_libraries(acorn_cdyn OpenMP::OpenMP_CXX) endif() diff --git a/program/integral/src/main.cpp b/program/integral/src/main.cpp index 77e8c9b..656942e 100644 --- a/program/integral/src/main.cpp +++ b/program/integral/src/main.cpp @@ -4,7 +4,7 @@ #include int main(int argc, char** argv) { - argparse::ArgumentParser program("Acorn Integral Engine", "1.0", argparse::default_arguments::none); Timer::Timepoint start = Timer::Now(), tp; + argparse::ArgumentParser program("Acorn Integral Engine", "1.0", argparse::default_arguments::none); Timer::Timepoint start = Timer::Now(), tp = Timer::Now(); // add the command line arguments program.add_argument("-b", "--basis").help("-- Basis set used for integrals.").default_value("STO-3G"); diff --git a/program/qdyn/CMakeLists.txt b/program/qdyn/CMakeLists.txt index 9fd9dbf..dbf3431 100644 --- a/program/qdyn/CMakeLists.txt +++ b/program/qdyn/CMakeLists.txt @@ -5,4 +5,4 @@ add_executable(acorn_qdyn src/main.cpp src/fourier.cpp src/wavefunction.cpp) target_include_directories(acorn_qdyn PRIVATE include) # link libraries -target_link_libraries(acorn_qdyn acorn_base ${LIBFFTW}) +target_link_libraries(acorn_qdyn acorn_base "${LIBFFTW}") diff --git a/script/libfftw.sh b/script/libfftw.sh index 6e16a5c..e34ef10 100755 --- a/script/libfftw.sh +++ b/script/libfftw.sh @@ -7,7 +7,7 @@ mkdir -p external && wget -O external/libfftw.tar.gz https://www.fftw.org/fftw-3 cd external && rm -rf libfftw && tar -xzvf libfftw.tar.gz && mv fftw* libfftw && cd - # configure FFTW -cd external/libfftw && cmake -B build -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$PWD/install" && cd - +cd external/libfftw && cmake -B build -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$PWD/install" && cd - # compile and install FFTW cd external/libfftw && cmake --build build --parallel 2 && cmake --install build && cd - @@ -16,7 +16,4 @@ cd external/libfftw && cmake --build build --parallel 2 && cmake --install build cp -r external/libfftw/install/include external/libfftw/install/lib external/ # remove redundant files -rm -rf external/libfftw external/include/*.f external/include/*.f03 external/lib/cmake external/lib/pkgconfig external/lib/libfftw3.so.3.6.9 - -# move links -mv external/lib/libfftw3.so.3 external/lib/libfftw3.so +rm -rf external/libfftw external/include/*.f external/include/*.f03 external/lib/cmake external/lib/pkgconfig diff --git a/script/libint.sh b/script/libint.sh index e1c7be3..16cbaa4 100755 --- a/script/libint.sh +++ b/script/libint.sh @@ -7,7 +7,7 @@ mkdir -p external && wget -O external/libint.tgz https://github.com/evaleev/libi cd external && rm -rf libint && tar -xvf libint.tgz --warning=no-unknown-keyword && mv libint-* libint && cd - # configure libint -cd external/libint && cmake -B build -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$PWD/install" && cd - +cd external/libint && cmake -B build -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$PWD/install" && cd - # compile and install libint cd external/libint && cmake --build build --parallel 2 && cmake --install build && cd - @@ -16,7 +16,4 @@ cd external/libint && cmake --build build --parallel 2 && cmake --install build cp -r external/libint/install/include external/libint/install/lib external/ # remove redundant files -rm -rf external/libint external/lib/cmake external/lib/pkgconfig external/lib/libint2.so.2 - -# move links -mv external/lib/libint2.so.2.9.0 external/lib/libint2.so +rm -rf external/libint external/lib/cmake external/lib/pkgconfig diff --git a/script/libtorch.sh b/script/libtorch.sh index aef49ea..409e879 100755 --- a/script/libtorch.sh +++ b/script/libtorch.sh @@ -7,7 +7,7 @@ mkdir -p external && wget -O external/libtorch.tar.gz https://github.com/pytorch cd external && rm -rf libtorch && tar -xzvf libtorch* && mv pytorch* libtorch && cd - # configure libtorch -cd external/libtorch && cmake -B build -DBUILD_PYTHON=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$PWD/install" -DUSE_DISTRIBUTED=OFF -DUSE_FBGEMM=OFF -DUSE_OPENMP=OFF && cd - +cd external/libtorch && cmake -B build -DBUILD_PYTHON=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$PWD/install" -DUSE_CUDA=OFF -DUSE_DISTRIBUTED=OFF -DUSE_FBGEMM=OFF -DUSE_MAGMA=OFF -DUSE_MKLDNN=OFF -DUSE_NNPACK=OFF -DUSE_NUMPY=OFF -DUSE_OPENMP=OFF -DUSE_PYTORCH_QNNPACK=OFF -DUSE_ROCM=OFF -DUSE_XNNPACK=OFF -DUSE_XPU=OFF && cd - # compile and install libtorch cd external/libtorch && cmake --build build --parallel 2 && cmake --install build && cd -