Skip to content

Commit

Permalink
CMake gcc workflows build and some unit tests (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
pprcht authored Mar 19, 2024
2 parents 598bb74 + f240551 commit 2719412
Show file tree
Hide file tree
Showing 26 changed files with 1,900 additions and 36 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ jobs:
tar xvf xtb-*.tar.xz
echo ${{ env.PWD }}/xtb-${{ env.XTB_VERSION }}/bin >> $GITHUB_PATH
# - name: Run example 0
# run: |
# bash run.sh
# working-directory: examples/expl-0

continuous-delivery:
if: github.event_name == 'push'
Expand All @@ -118,7 +113,7 @@ jobs:
OUTPUT_INTEL: crest-latest.tar.xz

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Install github-release
run: |
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/cmake-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CMake build and unit tests
on: [push, pull_request]

env:
BUILD_DIR: _build

jobs:
gcc-cmake-build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
fc: [gfortran-10]
cc: [gcc-10]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install CMake
run: pip3 install cmake

- name: Git Sumbodules Setup
run: |
git submodule update --init
- name: Configure build
run: cmake -B ${{ env.BUILD_DIR }}
env:
FC: ${{ matrix.fc }}
CC: ${{ matrix.cc }}

- name: Build project
run: cmake --build ${{ env.BUILD_DIR }}

- name: Run unit tests
run: make test
working-directory: ${{ env.BUILD_DIR }}
env:
OMP_NUM_THREADS: 2,1
13 changes: 7 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
path = subprojects/gfnff
url = https://github.com/pprcht/gfnff.git
branch = master
[submodule "subprojects/tblite"]
path = subprojects/tblite
# url = https://github.com/tblite/tblite.git
# branch = main
url = https://github.com/pprcht/tblite.git
branch = ompleak
[submodule "subprojects/lwoniom"]
path = subprojects/lwoniom
url = https://github.com/crest-lab/lwoniom
branch = main
[submodule "subprojects/test-drive"]
path = subprojects/test-drive
url = https://github.com/fortran-lang/test-drive.git
[submodule "subprojects/tblite"]
path = subprojects/tblite
url = https://github.com/tblite/tblite.git
branch = main
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ if(NOT TARGET "OpenMP::OpenMP_Fortran" AND WITH_OpenMP)
find_package("OpenMP" REQUIRED)
endif()

# Fortran unit test interface (also used by other subprojects)
if(NOT TARGET "test-drive::test-drive" AND WITH_TESTS)
find_package("test-drive" REQUIRED)
endif()

# TOML-F (needs to be imported before tblite)
if(NOT TARGET "toml-f::toml-f" AND WITH_TOMLF)
find_package("toml-f" REQUIRED)
Expand Down Expand Up @@ -334,6 +339,10 @@ install(
)

##############################################################################
################################ Testing #####################################
############################# Unit Tests #####################################
##############################################################################

if (WITH_TESTS)
enable_testing()
add_subdirectory("test")
endif()
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ Working and tested builds of CREST (mostly on Ubuntu 20.04 LTS):

| Build System | Compiler | Linear Algebra Backend | Build type | Status |
|--------------|----------|------------------------|:--------------:|:----------:|
| CMake | GNU (gcc 10.3.0) | [OpenBLAS](https://github.com/xianyi/OpenBLAS) (with OpenMP) | dynamic ||
| CMake | GNU (gcc 10.3.0) | [MKL shared (oneAPI 2023.1)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html) | dynamic ||
| CMake | GNU (gcc 9.5.0) | [MKL shared (oneAPI 2023.1)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html) | dynamic ||
| CMake | [Intel (`ifort`/`icc` 2021.9.0)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html) | [MKL static (oneAPI 2023.1)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html) | dynamic ||
| Meson | [Intel (`ifort`/`icc` 2021.9.0)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html) | [MKL static (oneAPI 2023.1)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html) | static ||
| Meson | [Intel (`ifort` 2021.9.0/`icx` 2023.1.0)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html) | [MKL static (oneAPI 2023.1)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html) | static ||
| CMake 3.28.3 | GNU (gcc 10.3.0) | [OpenBLAS](https://github.com/xianyi/OpenBLAS) (with OpenMP) | dynamic ||
| CMake 3.28.3 | GNU (gcc 10.3.0) | [MKL shared (oneAPI 2023.1)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html) | dynamic ||
| CMake 3.28.3 | GNU (gcc 9.5.0) | [MKL shared (oneAPI 2023.1)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html) | dynamic ||
| CMake 3.28.3 | [Intel (`ifort`/`icc` 2021.9.0)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html) | [MKL static (oneAPI 2023.1)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html) | dynamic ||
| Meson 1.2.0 | [Intel (`ifort`/`icc` 2021.9.0)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html) | [MKL static (oneAPI 2023.1)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html) | static ||
| Meson 1.2.0 | [Intel (`ifort` 2021.9.0/`icx` 2023.1.0)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/toolkits.html) | [MKL static (oneAPI 2023.1)](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html) | static ||



Expand Down
1 change: 1 addition & 0 deletions config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ option(WITH_GFN0 "Enable support for GFN0-xTB" TRUE)
option(WITH_GFNFF "Enable support for GFN-FF" TRUE)
option(WITH_XHCFF "Enable support for XHCFF" FALSE)
option(WITH_LWONIOM "Enable support for lwONIOM" TRUE)
option(WITH_TESTS "Enable unit tests" TRUE)

option(STATICBUILD "Attempt to link everything statically" FALSE) # doesn't work yet

Expand Down
5 changes: 5 additions & 0 deletions config/modules/Findtblite.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ endif()

include("${CMAKE_CURRENT_LIST_DIR}/crest-utils.cmake")

set(temp_with_tests ${WITH_TESTS}) # Save the current value of WITH_TESTS
set(WITH_TESTS FALSE CACHE BOOL "Temporarily disable tests for the tblite subproject" FORCE)
set(WITH_API FALSE)
crest_find_package("${_lib}" "${${_pkg}_FIND_METHOD}" "${_url}")

set(found FALSE)
Expand All @@ -32,6 +35,8 @@ if(TARGET "tblite::tblite")
endif()
message(STATUS "Found tblite: ${found}")

set(WITH_TESTS ${temp_with_tests} CACHE BOOL "Enable tests for the main project" FORCE)

unset(_lib)
unset(_pkg)
unset(_url)
38 changes: 38 additions & 0 deletions config/modules/Findtest-drive.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This file is part of crest.
# SPDX-Identifier: LGPL-3.0-or-later
#
# crest is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# crest is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with crest. If not, see <https://www.gnu.org/licenses/>.

set(_lib "test-drive")
set(_pkg "TEST-DRIVE")
set(_url "https://github.com/fortran-lang/test-drive")

if(NOT DEFINED "${_pkg}_FIND_METHOD")
set("${_pkg}_FIND_METHOD" "subproject" "cmake" "fetch" "pkgconf")
endif()

include("${CMAKE_CURRENT_LIST_DIR}/crest-utils.cmake")

crest_find_package("${_lib}" "${${_pkg}_FIND_METHOD}" "${_url}")

if(TARGET "${_lib}::${_lib}")
set (found TRUE)
else()
set (found FALSE)
endif()
message(STATUS "Found test-drive: ${found}")

unset(_lib)
unset(_pkg)
unset(_url)
16 changes: 16 additions & 0 deletions src/algos/optimization.f90
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ subroutine crest_ensemble_optimization(env,tim)
real(wp),allocatable :: eread(:)
real(wp),allocatable :: xyz(:,:,:)
integer,allocatable :: at(:)
character(len=10),allocatable :: comments(:)
character(len=80) :: atmp
real(wp) :: percent
character(len=52) :: bar
Expand Down Expand Up @@ -237,6 +238,21 @@ subroutine crest_ensemble_optimization(env,tim)
!>--- call the loop
call crest_oloop(env,nat,nall,at,xyz,eread,.true.)

!========================================================================================!
!>--- output
write(stdout,'(/,a,a,a)') 'Rewriting ',ensemblefile,' in the correct order'// &
& ' (failed optimizations are assigned an energy of +1.0)'
!>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<!
!>--- Back to Angstroem
xyz = xyz * bohr
!>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<!
allocate(comments(nall))
do i=1,nall
comments(i) = ''
if(eread(i) > 0.0_wp) comments(i) = '!failed'
enddo
call wrensemble(ensemblefile,nat,nall,at,xyz,eread,comments)

deallocate (eread,at,xyz)
write(stdout,'(/,a,a,a)') 'Optimized ensemble written to <',ensemblefile,'>'

Expand Down
2 changes: 1 addition & 1 deletion src/algos/parallel.f90
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ subroutine crest_oloop(env,nat,nall,at,xyz,eread,dump)
eread(zcopy) = energy
xyz(:,:,zcopy) = molsnew(job)%xyz(:,:)
else
eread(zcopy) = 0.0_wp
eread(zcopy) = 1.0_wp
end if
k = k+1
!>--- print progress
Expand Down
2 changes: 1 addition & 1 deletion src/algos/refine.f90
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ subroutine crest_refine(env,input,output)
else
outname = input !> overwrite
end if

!>--- presorting step, if necessary
if(env%refine_presort)then
call newcregen(env,0,input)
Expand Down
4 changes: 2 additions & 2 deletions src/optimize/gd.f90
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ subroutine gradientdescent(mol,calc,etot,grd,pr,wr,iostatus)

!>--- for too large energy rise, rewind step. otherwise go to next iteration
if (.not.lowered) then
write (*,'(" * ENERGY RISE detected. Rewind and try again with smaller step ...")')
if(pr) write (*,'(" * ENERGY RISE detected. Rewind and try again with smaller step ...")')
molopt%xyz = molopt%xyz-displ
write (*,*) jjj,maxmicro
!write (*,*) jjj,maxmicro
if (jjj == maxmicro) then
write (*,'(" * FAILED to perform gradient descent! Something is very wrong ...")')
converged = .false.
Expand Down
4 changes: 3 additions & 1 deletion src/parsing/parse_maindata.f90
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ subroutine parse_main_bool(env,key,val)
end if
case ('multilevelopt')
env%multilevelopt = val
case ('refine_presort')
env%refine_presort = val
end select
return
end subroutine parse_main_bool
Expand Down Expand Up @@ -282,7 +284,7 @@ subroutine parse_confsolv(env,blk)
integer :: i
!>--- add ConfSolv as refinement level to give a ΔΔGsoln
call env%addrefine(refine%ConfSolv)
env%refine_presort = .true.
!env%refine_presort = .true.
env%ewin = 100.0_wp

!>--- parse the arguments
Expand Down
2 changes: 1 addition & 1 deletion subprojects/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ dftd4.wrap
mstore.wrap
multicharge.wrap
s-dftd3.wrap
test-drive.wrap
mctc-lib.wrap
xhcff
lammps*
Expand All @@ -14,6 +13,7 @@ lammps*
!toml-f
!gfnff
!tblite
!test-drive

!packagefiles
!packagefiles/tblite
Expand Down
17 changes: 9 additions & 8 deletions subprojects/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

Newer versions of CREST use external projects:

| Library | Description | Build Option | git submodule |
| ------- | ----------- | ------------ | :-----------: |
| [`toml-f`](https://github.com/toml-f/toml-f) | A TOML parser for Fortran | `-DWITH_TOMLF=true` (default) ||
| [`gfn0`](https://github.com/pprcht/gfn0) | A GFN0-xTB standalone library | `-DWITH_GFN0=true` (default) ||
| [`gfnff`](https://github.com/pprcht/gfnff) | A GFN-FF standalone library | `-DWITH_GFNFF=true` (default) ||
| [`tblite`](https://github.com/tblite/tblite) | A lightweight implementation of the GFN1 and GFN2-xTB Hamiltonians | `-DWITH_TBLITE=true` (default) ||
| [`lwoniom`](https://github.com/crest-lab/lwoniom) | A lightweight ONIOM implementation | `-DWITH_LWONIOM=true` (default) ||
| Library | Description | Build Option | git submodule | CMake build | `meson` build |
| ------- | ----------- | ------------ | :-----------: | :---------: | :-----------: |
| [`toml-f`](https://github.com/toml-f/toml-f) | A TOML parser for Fortran | `-DWITH_TOMLF=true` (default) ||||
| [`gfn0`](https://github.com/pprcht/gfn0) | A GFN0-xTB standalone library | `-DWITH_GFN0=true` (default) ||||
| [`gfnff`](https://github.com/pprcht/gfnff) | A GFN-FF standalone library | `-DWITH_GFNFF=true` (default) ||||
| [`tblite`](https://github.com/tblite/tblite) | A lightweight implementation of the GFN1 and GFN2-xTB Hamiltonians | `-DWITH_TBLITE=true` (default) ||||
| [`lwoniom`](https://github.com/crest-lab/lwoniom) | A lightweight ONIOM implementation | `-DWITH_LWONIOM=true` (default) ||||
<!--
| [`xhcff`](https://github.com/zellerf/xhcff) | Implementation of the XHCFF force field | `-DWITH_XHCFF=true` | ✅ |
| [`xhcff`](https://github.com/zellerf/xhcff) | Implementation of the XHCFF force field | `-DWITH_XHCFF=true` | ✅ | ✅ | ✅ |
-->


Expand All @@ -30,3 +30,4 @@ git submodule update --remote
```
can be used.

Alternatively, a source directory of the respective project can be placed in the subprojects directory, or a symbolic link can be set.
2 changes: 1 addition & 1 deletion subprojects/tblite
Submodule tblite updated 87 files
+0 −1 README.md
+30 −4 app/cli.f90
+44 −38 app/cli_help.f90
+10 −9 app/driver_guess.f90
+44 −13 app/driver_run.f90
+5 −0 app/meson.build
+1,683 −0 app/test/gfn2-molmom.toml
+18 −0 app/test/input.xyz
+3 −0 app/test/molmom.toml
+0 −4 doc/index.rst
+1 −0 doc/tutorial/index.rst
+84 −0 doc/tutorial/parallel.rst
+2 −0 include/tblite.h
+18 −0 include/tblite/calculator.h
+112 −0 include/tblite/double_dictionary.h
+10 −0 include/tblite/result.h
+78 −0 man/tblite-guess.1.adoc
+3 −0 man/tblite-run.1.adoc
+3 −0 man/tblite.1.adoc
+1 −0 meson.build
+23 −15 python/tblite/ase.py
+17 −5 python/tblite/interface.py
+60 −20 python/tblite/library.py
+1 −1 python/tblite/test_ase.py
+23 −0 python/tblite/test_interface.py
+1 −0 src/tblite/CMakeLists.txt
+1 −0 src/tblite/api/CMakeLists.txt
+89 −11 src/tblite/api/calculator.f90
+307 −0 src/tblite/api/double_dictionary.f90
+1 −0 src/tblite/api/meson.build
+53 −14 src/tblite/api/result.f90
+1 −1 src/tblite/ceh/CMakeLists.txt
+0 −127 src/tblite/ceh/calculator.f90
+529 −688 src/tblite/ceh/ceh.f90
+281 −8 src/tblite/ceh/h0.f90
+1 −1 src/tblite/ceh/meson.build
+207 −0 src/tblite/ceh/singlepoint.f90
+8 −12 src/tblite/coulomb/charge/effective.f90
+0 −1 src/tblite/data/CMakeLists.txt
+0 −94 src/tblite/data/covrad_ceh.f90
+0 −1 src/tblite/data/meson.build
+9 −8 src/tblite/double_dictionary.f90
+15 −12 src/tblite/integral/diat_trafo.f90
+122 −12 src/tblite/integral/overlap.f90
+3 −0 src/tblite/integral/type.f90
+1 −0 src/tblite/meson.build
+16 −11 src/tblite/ncoord.f90
+2 −2 src/tblite/ncoord/CMakeLists.txt
+0 −216 src/tblite/ncoord/ceh_en.f90
+0 −191 src/tblite/ncoord/ceh_std.f90
+121 −0 src/tblite/ncoord/erf.f90
+141 −0 src/tblite/ncoord/erf_en.f90
+80 −47 src/tblite/ncoord/exp.f90
+47 −189 src/tblite/ncoord/gfn.f90
+2 −2 src/tblite/ncoord/meson.build
+216 −10 src/tblite/ncoord/type.f90
+18 −2 src/tblite/param.f90
+3 −0 src/tblite/param/CMakeLists.txt
+3 −0 src/tblite/param/meson.build
+159 −0 src/tblite/param/post_processing.f90
+24 −0 src/tblite/param/post_processing/CMakeLists.txt
+19 −0 src/tblite/param/post_processing/meson.build
+156 −0 src/tblite/param/post_processing/molmom.f90
+27 −0 src/tblite/post_processing/CMakeLists.txt
+281 −0 src/tblite/post_processing/list.f90
+24 −0 src/tblite/post_processing/meson.build
+123 −0 src/tblite/post_processing/molmom.f90
+118 −0 src/tblite/post_processing/type.f90
+138 −0 src/tblite/post_processing/wbo.f90
+3 −2 src/tblite/results.f90
+37 −1 src/tblite/wavefunction/mulliken.f90
+2 −0 src/tblite/xtb/calculator.f90
+16 −2 src/tblite/xtb/h0.f90
+30 −10 src/tblite/xtb/singlepoint.f90
+40 −0 src/tblite/xtb/spec.f90
+1,043 −169 test/api/main.c
+2 −1 test/unit/CMakeLists.txt
+4 −2 test/unit/main.f90
+2 −1 test/unit/meson.build
+976 −129 test/unit/test_ceh.f90
+76 −34 test/unit/test_double_dictionary.f90
+5 −2 test/unit/test_hamiltonian.f90
+233 −1 test/unit/test_integral_overlap.f90
+1,276 −0 test/unit/test_ncoord.f90
+0 −348 test/unit/test_ncoord_gfn.f90
+283 −0 test/unit/test_post_processing.f90
+12 −0 test/unit/test_xtb_param.f90
4 changes: 2 additions & 2 deletions subprojects/tblite.wrap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[wrap-git]
directory = tblite
url = https://github.com/pprcht/tblite
revision = ompleak
url = https://github.com/tblite/tblite
revision = main
1 change: 1 addition & 0 deletions subprojects/test-drive
Submodule test-drive added at a78870
33 changes: 33 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Unit testing
set(
tests
"tblite"
"gfnff"
"gfn0"
"gfn0occ"
"optimization"
)
set(
test-srcs
"testmol.f90"
"main.f90"
)
foreach(t IN LISTS tests)
string(MAKE_C_IDENTIFIER ${t} t)
list(APPEND test-srcs "test_${t}.F90")
endforeach()

add_executable(
"${PROJECT_NAME}-tester"
"${test-srcs}"
)
target_link_libraries(
"${PROJECT_NAME}-tester"
PRIVATE
"lib-${PROJECT_NAME}-static"
"test-drive::test-drive"
)

foreach(t IN LISTS tests)
add_test("${PROJECT_NAME}/${t}" "${PROJECT_NAME}-tester" "${t}")
endforeach()
Loading

0 comments on commit 2719412

Please sign in to comment.