qcscine / sparrow

https://scine.ethz.ch
BSD 3-Clause "New" or "Revised" License
79 stars 15 forks source link

installation in github actions #18

Open stenczelt opened 2 years ago

stenczelt commented 2 years ago

Do you have a tried and tested github actions script for using sparrow within projects with CI/CD?

I am trying to install Sparrow in a github actions environment for testing some python code that is supposed to use it. I am trying to run the cmake installation, but for some reason it fails at the point of downloading the dependencies using your cmake tools. Oddly enough, if I am doing the same in Docker for example it just works, with the warning about cmake version settings not provided being shown as well and ignored (likely you are calling cmake from a non toplevel directory as well?)

The error is:

-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at cmake/ComponentSetup.cmake:56 (message):
  You are compiling Scine components with an architecture-specific ISA:
  -march=native.  Linking together libraries with mismatched architecture
  build flags can cause problems, in particular with Eigen.  Watch out!
Call Stack (most recent call first):
  CMakeLists.txt:16 (scine_setup_component)

CMake Error in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.23)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".

CMake Error at cmake/DownloadProject.cmake:167 (message):
  CMake step for googletest failed: 1
Call Stack (most recent call first):
  cmake/ImportGTest.cmake:16 (download_project)
  cmake/ComponentSetup.cmake:63 (import_gtest)
  CMakeLists.txt:16 (scine_setup_component)

-- Configuring incomplete, errors occurred!
See also "/opt/sparrow/build/CMakeFiles/CMakeOutput.log".
##[error]Process completed with exit code 1.

and the whole action file is as follows, that reproduces this:

name: Sparrow installation

on:
  push:

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v3
        with:
          python-version: '3.9'

      - name: Install dependencies / apt-get
        run: |
          sudo apt-get update -y
          sudo apt-get install -y \
            cmake \
            libeigen3-dev \
            libboost-all-dev \
            --

      - name: Download Sparrow
        working-directory: /opt
        run: |
          # clone Sparrow
          git clone https://github.com/qcscine/sparrow.git --branch=2.0.1 --single-branch --depth 1 --recursive

      - name: Setup Sparrow for Installation
        working-directory: /opt/sparrow
        run: |
          mkdir build install
          cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DSCINE_BUILD_PYTHON_BINDINGS=ON

      - name: Build & Install Sparrow
        working-directory: /opt/sparrow
        run: |
          cmake --build ./build
          cmake --install ./build

      - name: Sparrow path
        run: |
          export PATH="/opt/sparrow/install/bin:$PATH"
          export PYTHONPATH=$PYTHONPATH:/opt/sparrow/install/lib/python3.9/site-packages
          export SCINE_MODULE_PATH=/opt/sparrow/install/lib

I have taken this stripped-down version of the installation scripts and put them into a puclic repo as well for you to see: https://github.com/stenczelt/actions-test/runs/6746640491

stenczelt commented 2 years ago

PS. the project depends on sparrow 2.0.1... I am not sure if 3.0.0 would work, is there any compatibility issue or breaking changes for the python parts?

awvwgk commented 2 years ago

I wouldn't recommend building in CI since Sparrow is very expensive to compile. I packaged a version on conda-forge which can be installed using mamba-org/provision-with-micromamba in GHA:

    # Important to keep the conda environment active between steps
    defaults:
      run:
        shell: bash -l {0}
    # ...
    steps:
    # ...
    - name: Install dependencies
      uses: mamba-org/provision-with-micromamba@main
      with:
        environment-file: environment.yml

You can use this environment.yml to get scine-sparrow-python:

name: sparrow
channels:
  - conda-forge
dependencies:
  - scine-sparrow-python

You need at least the name and channels key in the environment.yml, the dependencies can also be passed directly to the action with the extra-specs option:

    - name: Install dependencies
      uses: mamba-org/provision-with-micromamba@main
      with:
        environment-file: environment.yml
        extra-specs: |
          scine-sparrow-python

If you rely on conda-forge for Python packages it is best to install all Python packages from conda-forge.

the project depends on sparrow 2.0.1... I am not sure if 3.0.0 would work, is there any compatibility issue or breaking changes for the python parts?

There are a lot of breaking changes, like change of the coordinate unit from Ångström to Bohr. I helped fixing a compatibility interface which makes Sparrow 3.0.0 look like Sparrow 2.0.1 a while ago, this can serve as reference for the required upgrade steps. See

https://github.com/gncs/molgym/blob/master/molgym/calculator.py