From 9a46735809894ed07c64227a547f3afa2e304f00 Mon Sep 17 00:00:00 2001 From: Guillaume Fraux Date: Tue, 22 Aug 2023 17:38:33 +0200 Subject: [PATCH] Run CI on windows --- .github/workflows/python-tests.yml | 10 +++--- .github/workflows/rust-tests.yml | 23 +++++++++++++ .github/workflows/torch-tests.yml | 5 +++ rascaline-c-api/CMakeLists.txt | 5 ++- rascaline-c-api/tests/CMakeLists.txt | 33 ++++++++++++------- rascaline-c-api/tests/cxx/CMakeLists.txt | 21 +++++++----- .../include/rascaline/torch/system.hpp | 4 +-- rascaline-torch/tests/system.cpp | 2 +- rascaline/src/calculators/radial_basis/gto.rs | 13 ++++---- 9 files changed, 79 insertions(+), 37 deletions(-) diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 717001255..7627b9508 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -19,13 +19,12 @@ jobs: matrix: include: - os: ubuntu-20.04 - rust-target: x86_64-unknown-linux-gnu python-version: "3.7" - os: ubuntu-20.04 - rust-target: x86_64-unknown-linux-gnu python-version: "3.11" - os: macos-11 - rust-target: x86_64-apple-darwin + python-version: "3.11" + - os: windows-2019 python-version: "3.11" steps: - uses: actions/checkout@v3 @@ -39,13 +38,12 @@ jobs: uses: dtolnay/rust-toolchain@master with: toolchain: stable - target: ${{ matrix.rust-target }} - name: install python dependencies run: | python -m pip install --upgrade pip python -m pip install tox - echo "tox_version=$(tox --version | awk '{split($0, s," "); print s[1]}')" >> $GITHUB_ENV + echo "tox_version=$(python -c 'import tox; print(tox.__version__)')" >> $GITHUB_ENV - name: Setup sccache uses: mozilla-actions/sccache-action@v0.0.3 @@ -95,7 +93,7 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install tox - echo "tox_version=$(tox --version | awk '{split($0, s," "); print s[1]}')" >> $GITHUB_ENV + echo "tox_version=$(python -c 'import tox; print(tox.__version__)')" >> $GITHUB_ENV - name: cache tox environments uses: actions/cache@v3 diff --git a/.github/workflows/rust-tests.yml b/.github/workflows/rust-tests.yml index 78f761910..73bd6113e 100644 --- a/.github/workflows/rust-tests.yml +++ b/.github/workflows/rust-tests.yml @@ -15,6 +15,9 @@ jobs: runs-on: ${{ matrix.os }} name: ${{ matrix.os }} / rust ${{ matrix.rust-version }} ${{ matrix.extra-name }} container: ${{ matrix.container }} + defaults: + run: + working-directory: ${{ matrix.working-directory }} strategy: matrix: include: @@ -24,6 +27,8 @@ jobs: build-type: debug test-static-lib: true extra-name: / static C library + working-directory: /home/runner/work/rascaline/rascaline/ + - os: ubuntu-20.04 rust-version: stable rust-target: x86_64-unknown-linux-gnu @@ -31,6 +36,8 @@ jobs: cargo-build-flags: --release do-valgrind: true extra-name: / release valgrind + working-directory: /home/runner/work/rascaline/rascaline/ + # check the build on a stock Ubuntu 20.04, including cmake 3.16 - os: ubuntu-20.04 rust-version: "1.64" @@ -38,10 +45,20 @@ jobs: rust-target: x86_64-unknown-linux-gnu build-type: debug extra-name: / cmake 3.16 + working-directory: /__w/rascaline/rascaline + - os: macos-11 rust-version: stable rust-target: x86_64-apple-darwin build-type: debug + working-directory: /Users/runner/work/rascaline/rascaline/ + + - os: windows-2019 + rust-version: stable + rust-target: x86_64-pc-windows-msvc + build-type: debug + working-directory: C:\\rascaline + steps: - name: install dependencies in container if: matrix.container == 'ubuntu:20.04' @@ -50,6 +67,7 @@ jobs: apt install -y software-properties-common apt install -y cmake make gcc g++ git curl python3-pip python3-venv ln -s /usr/bin/python3 /usr/bin/python + working-directory: / - name: free disk space if: matrix.os == 'ubuntu-20.04' @@ -57,6 +75,11 @@ jobs: - uses: actions/checkout@v3 + - name: "copy the code to C: drive" + if: matrix.os == 'windows-2019' + run: cp -r ${{ github.workspace }} ${{ matrix.working-directory }} + working-directory: / + - name: setup Python uses: actions/setup-python@v4 if: "!matrix.container" diff --git a/.github/workflows/torch-tests.yml b/.github/workflows/torch-tests.yml index 171b42205..e362acb83 100644 --- a/.github/workflows/torch-tests.yml +++ b/.github/workflows/torch-tests.yml @@ -33,6 +33,11 @@ jobs: python-version: "3.11" cargo-test-flags: --release + - os: windows-2019 + torch-version: 2.0.* + python-version: "3.11" + cargo-test-flags: --release + steps: - uses: actions/checkout@v3 diff --git a/rascaline-c-api/CMakeLists.txt b/rascaline-c-api/CMakeLists.txt index 5c9b7d85a..90dd8ee25 100644 --- a/rascaline-c-api/CMakeLists.txt +++ b/rascaline-c-api/CMakeLists.txt @@ -191,9 +191,12 @@ if (CARGO_VERSION_CHANGED) endforeach() # Special case `msvcrt` to link with the debug version in Debug mode. list(TRANSFORM stripped_lib_list REPLACE "^msvcrt$" "\$<\$:msvcrtd>") + list(REMOVE_DUPLICATES stripped_lib_list) set(CARGO_DEFAULT_LIBRARIES "${stripped_lib_list}" CACHE INTERNAL "list of implicitly linked libraries") - message(STATUS "Cargo default link libraries are: ${CARGO_DEFAULT_LIBRARIES}") + if (${RASCALINE_MAIN_PROJECT}) + message(STATUS "Cargo default link libraries are: ${CARGO_DEFAULT_LIBRARIES}") + endif() else() message(FATAL_ERROR "could not find default static libs: `native-static-libs` not found in: `${cargo_build_error_message}`") endif() diff --git a/rascaline-c-api/tests/CMakeLists.txt b/rascaline-c-api/tests/CMakeLists.txt index ea354ee02..ef81e4740 100644 --- a/rascaline-c-api/tests/CMakeLists.txt +++ b/rascaline-c-api/tests/CMakeLists.txt @@ -83,6 +83,11 @@ endif() file(GLOB ALL_TESTS *.cpp) list(REMOVE_ITEM ALL_TESTS "${CMAKE_CURRENT_SOURCE_DIR}/helpers.cpp") +# on windows, shared libraries are found in the PATH. This plays a similar role +# to `CMAKE_BUILD_RPATH` above +string(REPLACE ";" "\\;" PATH_STRING "$ENV{PATH}") +set(WINDOWS_TEST_PATH "${PATH_STRING}\;${METATENSOR_DIRECTORY}\;${RASCALINE_DIRECTORY}") + enable_testing() foreach(_file_ ${ALL_TESTS}) get_filename_component(_name_ ${_file_} NAME_WE) @@ -93,26 +98,30 @@ foreach(_file_ ${ALL_TESTS}) COMMAND ${TEST_COMMAND} $ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + + if(WIN32) + set_tests_properties(${_name_} PROPERTIES ENVIRONMENT "PATH=${WINDOWS_TEST_PATH}") + endif() endforeach() # make sure example compile and run +set(XYZ_EXAMPLE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../../rascaline/examples/data/water.xyz) + file(GLOB EXAMPLES ../examples/*.c) foreach(_file_ ${EXAMPLES}) get_filename_component(_name_ ${_file_} NAME_WE) - set(_name_ example-${_name_}) + set(_name_ example-c-${_name_}) add_executable(${_name_} ${_file_}) target_link_libraries(${_name_} rascaline::shared) -endforeach() -set(XYZ_EXAMPLE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../../rascaline/examples/data/water.xyz) -add_test( - NAME example-c-compute-soap - COMMAND ${TEST_COMMAND} $ ${XYZ_EXAMPLE_FILE} -) - -add_test( - NAME example-c-profiling - COMMAND ${TEST_COMMAND} $ ${XYZ_EXAMPLE_FILE} -) + add_test( + NAME ${_name_} + COMMAND ${TEST_COMMAND} $ ${XYZ_EXAMPLE_FILE} + ) + + if(WIN32) + set_tests_properties(${_name_} PROPERTIES ENVIRONMENT "PATH=${WINDOWS_TEST_PATH}") + endif() +endforeach() add_subdirectory(cxx) diff --git a/rascaline-c-api/tests/cxx/CMakeLists.txt b/rascaline-c-api/tests/cxx/CMakeLists.txt index 0ce315979..84ee2b52f 100644 --- a/rascaline-c-api/tests/cxx/CMakeLists.txt +++ b/rascaline-c-api/tests/cxx/CMakeLists.txt @@ -10,6 +10,10 @@ foreach(_file_ ${ALL_TESTS}) COMMAND ${TEST_COMMAND} $ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) + + if(WIN32) + set_tests_properties(${_name_} PROPERTIES ENVIRONMENT "PATH=${WINDOWS_TEST_PATH}") + endif() endforeach() file(GLOB EXAMPLES ../../examples/*.cpp) @@ -18,14 +22,13 @@ foreach(_file_ ${EXAMPLES}) set(_name_ example-cxx-${_name_}) add_executable(${_name_} ${_file_}) target_link_libraries(${_name_} rascaline::shared) -endforeach() -add_test( - NAME example-cxx-compute-soap - COMMAND ${TEST_COMMAND} $ ${XYZ_EXAMPLE_FILE} -) + add_test( + NAME ${_name_} + COMMAND ${TEST_COMMAND} $ ${XYZ_EXAMPLE_FILE} + ) -add_test( - NAME example-cxx-profiling - COMMAND ${TEST_COMMAND} $ ${XYZ_EXAMPLE_FILE} -) + if(WIN32) + set_tests_properties(${_name_} PROPERTIES ENVIRONMENT "PATH=${WINDOWS_TEST_PATH}") + endif() +endforeach() diff --git a/rascaline-torch/include/rascaline/torch/system.hpp b/rascaline-torch/include/rascaline/torch/system.hpp index 8f42122ae..fefc583ab 100644 --- a/rascaline-torch/include/rascaline/torch/system.hpp +++ b/rascaline-torch/include/rascaline/torch/system.hpp @@ -2,7 +2,7 @@ #define RASCALINE_TORCH_SYSTEM_HPP #include -#include +#include #include @@ -138,7 +138,7 @@ class RASCALINE_TORCH_EXPORT SystemHolder final: public rascaline::System, publi }; // all precomputed pairs we know about - std::unordered_map precomputed_pairs_; + std::map precomputed_pairs_; // last custom requested by `compute_neighbors` double last_cutoff_ = -1.0; }; diff --git a/rascaline-torch/tests/system.cpp b/rascaline-torch/tests/system.cpp index a42b784fb..ee594b4f6 100644 --- a/rascaline-torch/tests/system.cpp +++ b/rascaline-torch/tests/system.cpp @@ -26,7 +26,7 @@ TEST_CASE("Systems") { Catch::Matchers::StartsWith( "trying to get neighbor list with a cutoff (3.3) for which no " "pre-computed neighbor lists has been registered (we have lists " - "for cutoff=[4.5, 3.2])" + "for cutoff=[3.2, 4.5])" ) ); diff --git a/rascaline/src/calculators/radial_basis/gto.rs b/rascaline/src/calculators/radial_basis/gto.rs index a2a0025b1..2279fd90e 100644 --- a/rascaline/src/calculators/radial_basis/gto.rs +++ b/rascaline/src/calculators/radial_basis/gto.rs @@ -94,12 +94,13 @@ mod tests { let overlap = basis.overlap(); for i in 0..basis.max_radial { - assert_ulps_eq!(overlap[(i, i)], 1.0); - } - - for i in 0..basis.max_radial { - for j in i..basis.max_radial { - assert!(overlap[(j, i)] > 0.0); + for j in 0..basis.max_radial { + if i == j { + assert_ulps_eq!(overlap[(i, j)], 1.0, max_ulps=10); + } else { + assert!(overlap[(i, j)] > 0.0); + assert!(overlap[(i, j)] < 1.0); + } } } }