Skip to content

Commit

Permalink
add nanobound coupling kernel & build
Browse files Browse the repository at this point in the history
  • Loading branch information
Marmaduke Woodman committed Sep 3, 2024
1 parent aac0394 commit c0ec48c
Show file tree
Hide file tree
Showing 24 changed files with 497 additions and 563 deletions.
90 changes: 0 additions & 90 deletions .github/workflows.bak/build.yml

This file was deleted.

112 changes: 46 additions & 66 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: build kernel library
name: Test Py
on: [push]

jobs:
build:
name: build
name: Test and Inspect
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.10" ]
python-version: [ "3.10", "3.11" ]

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand All @@ -24,87 +24,67 @@ jobs:
- name: put ~/.local/bin on $PATH
run: echo "PATH=$HOME/.local/bin:$PATH" >> $GITHUB_ENV

# - name: cache ~/.local for pip deps
# id: cache-local
# uses: actions/cache@v3
# with:
# path: ~/.local
# key: pip-${{ steps.setPy.outputs.version }}-${{ hashFiles('tvb_framework/requirements.txt') }}

- name: install tools and dependencies
# if: steps.cache-local.outputs.cache-hit != 'true'
run: |
sudo apt-get update
sudo apt install libbz2-dev libhdf5-serial-dev liblzo2-dev cmake
sudo apt install libbz2-dev libhdf5-serial-dev liblzo2-dev
python3 -m pip install --upgrade setuptools==59.8.0 pip wheel
pip3 install --user --upgrade numpy
python3 -m pip install scikit-build
pip3 install --user -r tvb_framework/requirements.txt
pip3 install --user --no-build-isolation tvb-gdist
- name: install compilers and related
- name: setup tvb
run: |
pip3 install --user ctypesgen nanobind
# curl -LO https://github.com/ispc/ispc/releases/download/v1.24.0/ispc-v1.24.0-linux.tar.gz
# tar xzf ispc-v1.24.0-linux.tar.gz
# echo "PATH=$PWD/ispc-v1.24.0-linux/bin:$PATH" >> $GITHUB_ENV
cd tvb_build
bash install_full_tvb.sh
- name: setup ispc
uses: ScatteredRay/install-ispc-action@main
- name: cache data
id: cache-data
uses: actions/cache@v3
with:
version: 1.23.0
platform: linux
path: tvb_data
key: tvb-data

- name: check tools work
- name: download data
if: steps.cache-data.outputs.cache-hit != 'true'
run: |
ctypesgen --version
ispc --version
gcc -v
wget -q https://zenodo.org/record/10128131/files/tvb_data.zip?download=1 -O tvb_data.zip
mkdir tvb_data
unzip tvb_data.zip -d tvb_data
rm tvb_data.zip
- name: test first kernels
- name: setup data
run: |
cd tvb_kernels
./mkispc.sh nodes.ispc
cmake -S . -B build
cmake --build build
PYTHONPATH=build python test_nodes.py
# - name: setup tvb
# run: |
# cd tvb_build
# bash install_full_tvb.sh

# - name: cache data
# id: cache-data
# uses: actions/cache@v3
# with:
# path: tvb_data
# key: tvb-data
cd tvb_data
python3 setup.py develop
# - name: download data
# if: steps.cache-data.outputs.cache-hit != 'true'
# run: |
# wget -q https://zenodo.org/record/10128131/files/tvb_data.zip?download=1 -O tvb_data.zip
# mkdir tvb_data
# unzip tvb_data.zip -d tvb_data
# rm tvb_data.zip
- name: run library tests
run: pytest -v tvb_library --cov --cov-report=xml && mv coverage.xml coverage-library.xml

# - name: setup data
# run: |
# cd tvb_data
# python3 setup.py develop
- name: run framework tests
env:
KEYCLOAK_CLIENT_ID: ${{ secrets.KEYCLOAK_CLIENT_ID }} # KEYCLOAK_CLIENT_ID & SECRET have priority in tests
KEYCLOAK_CLIENT_SECRET: ${{ secrets.KEYCLOAK_CLIENT_SECRET }}
run: pytest -v tvb_framework --cov --cov-report=xml --ignore=tvb_framework/tvb/interfaces/rest/client/tests/rest_test.py && mv coverage.xml coverage-framework.xml

# - name: run library tests
# run: pytest -v tvb_library --cov --cov-report=xml && mv coverage.xml coverage-library.xml
- name: run storage tests
run: pytest -v tvb_storage --cov --cov-report=xml && mv coverage.xml coverage-storage.xml

# - name: run framework tests
# env:
# KEYCLOAK_CLIENT_ID: ${{ secrets.KEYCLOAK_CLIENT_ID }} # KEYCLOAK_CLIENT_ID & SECRET have priority in tests
# KEYCLOAK_CLIENT_SECRET: ${{ secrets.KEYCLOAK_CLIENT_SECRET }}
# run: pytest -v tvb_framework --cov --cov-report=xml --ignore=tvb_framework/tvb/interfaces/rest/client/tests/rest_test.py && mv coverage.xml coverage-framework.xml

# - name: run storage tests
# run: pytest -v tvb_storage --cov --cov-report=xml && mv coverage.xml coverage-storage.xml

# - name: Prepare PATH for Sonar
# run: |
# echo "PATH=$PATH:/opt/sonar-scanner/bin:/opt/nodejs/bin" >> $GITHUB_ENV
- name: Prepare PATH for Sonar
run: |
echo "PATH=$PATH:/opt/sonar-scanner/bin:/opt/nodejs/bin" >> $GITHUB_ENV
# - name: SonarCloud Scan
# uses: SonarSource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
File renamed without changes.
File renamed without changes.
74 changes: 74 additions & 0 deletions .github/workflows/kernels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: build & test kernel library
on: [push]

jobs:
pip-tvbk:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
python-version: [ "3.10", ]

steps:

- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
id: setPy
with:
python-version: ${{ matrix.python-version }}

- name: install tools and dependencies
run: python3 -m pip install -U setuptools pip wheel pytest scipy

- name: build
run: cd tvb_kernels; pip install .

- name: test
run: cd tvb_kernels; python -m pytest


spack-tvbk:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: setup spack
uses: spack/setup-spack@v2
with:
ref: develop
buildcache: true
color: true
path: spack

- name: install deps w/ spack
shell: spack-bash {0}
run: |
cd tvb_kernels
spack -e . concretize
spack -e . install
spack env activate .
spack env status
pip install pytest
- name: build nanobound library
shell: spack-bash {0}
run: |
cd tvb_kernels
spack env activate .
pip install .
pytest
# https://github.com/spack/setup-spack?tab=readme-ov-file#example-caching-your-own-binaries-for-public-repositories
- name: Push packages and update index
run: |
cd tvb_kernels
spack -e . mirror set --push --oci-username ${{ github.actor }} --oci-password "${{ secrets.GITHUB_TOKEN }}" local-buildcache
spack -e . buildcache push --base-image ubuntu:22.04 --update-index local-buildcache
if: ${{ !cancelled() }}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions tvb_kernels/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.cache
build
*.jpg
build
.spack-env
spack.lock
*.whl
57 changes: 57 additions & 0 deletions tvb_kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
cmake_minimum_required(VERSION 3.18...3.27)
project(tvb_kernels LANGUAGES C CXX)

if (NOT SKBUILD)
message(WARNING "\
This CMake file is meant to be executed using 'scikit-build-core'.
Running it directly will almost certainly not produce the desired
result. If you are a user trying to install this package, use the
command below, which will install all necessary build dependencies,
compile the package in an isolated environment, and then install it.
=====================================================================
$ pip install .
=====================================================================
If you are a software developer, and this is your own package, then
it is usually much more efficient to install the build dependencies
in your environment once and use the following command that avoids
a costly creation of a new virtual environment at every compilation:
=====================================================================
$ pip install nanobind scikit-build-core[pyproject]
$ pip install --no-build-isolation -ve .
=====================================================================
You may optionally add -Ceditable.rebuild=true to auto-rebuild when
the package is imported. Otherwise, you need to rerun the above
after editing C++ files.")
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_compile_options(-std=c++17 -fopenmp-simd -mavx2 -march=native -mtune=native)

find_package(Python 3.8
REQUIRED COMPONENTS Interpreter Development.Module
)

if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

# Detect the installed nanobind package and import it into CMake
execute_process(
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NB_DIR)
list(APPEND CMAKE_PREFIX_PATH "${NB_DIR}")
find_package(nanobind CONFIG REQUIRED)

nanobind_add_module(tvb_kernels tvb_kernels.cpp tvbk_conn.c)

nanobind_add_stub(
tvb_kernels_stub
MODULE tvb_kernels
OUTPUT tvb_kernels.pyi
PYTHON_PATH $<TARGET_FILE_DIR:tvb_kernels>
DEPENDS tvb_kernels
MARKER_FILE py.typed
)

install(TARGETS tvb_kernels LIBRARY DESTINATION tvb_kernels)
Loading

0 comments on commit c0ec48c

Please sign in to comment.