Skip to content

Commit

Permalink
Spack-solvable versions, add tests to Spack workflow (#2156)
Browse files Browse the repository at this point in the history
## Changes

1. Spack interprets version info consisting of 2-tuples as ranges,
leading to v0.8 being uninstallable if there has been a point release
(v0.8.1).
2. Change Spack CI to use latest release _and_ develop branch, because
the former is how Arbor is rolled out in various centers, and thus
should be verified to work, and the latter lets us know of upcoming
issues with dependencies.
3. Changed Spack CI to not use `build_spack_package.sh`. This script
does everything in `/tmp`, and Github Actions appear to be wiping `/tmp`
between steps, which means breaking up the run into steps is difficult.
Breaking up is desirable, because then one can see whether building or
testing breaks.
4. Run Python tests after building the Spack package.
5. Also use Spack-provided deps when Spack is instructed to build
master, not submodules.
6. Tiny fix for the `ciwheelbuild` failure.

## Future issues

Out of scope for now, but identified as problems:

1. Currently, Spack cannot execute the unit tests, because the
Google-Test package isn't built and Arbor doesn't look for it. @boeschf
is looking at the latter: making it possible to build with an external
Google Test.
    - Will be solved by #1731 
2. The former is another problem: Spack does not or not always (it's not
clear) concretize test dependencies. This is an open issue with low
priority: spack/spack#29447
This mean that despite oru `package.py` properly including
`depends_on("[email protected]", type="test", when="@0.7.1:")`, Spack
does not build it, at least not in the dev-build workflow as we
currently do. And it isn't clear what an always working workaround is,
see issue. (Spack can't display the deps for the `test` variant:
spack/spack#23586 `spack spec -I arbor`
doesn't show Google Test, and neither does `spack dependencies --deptype
test arbor`.)
    - Blocked by upstream.
  • Loading branch information
brenthuisman authored Aug 7, 2023
1 parent f9eae28 commit 7d36beb
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 54 deletions.
65 changes: 49 additions & 16 deletions .github/workflows/test-spack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04]
python-version: [3.8]
python-version: ['3.10']
spack-version: ['develop', 'latest_release']
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -27,18 +29,49 @@ jobs:
uses: actions/cache@v3
with:
path: ~/.spack-cache
key: spack-cache-${{ matrix.os }}-${{ github.run_id }}
restore-keys: spack-cache-${{ matrix.os }}-

- name: Build Arbor's Spack package against the develop branch
run: arbor/scripts/build_spack_package.sh arbor develop

# build_spack_package.sh only builds, does not install, therefore can't run Python code.
# - name: Run Python examples
# run: |
# cd arbor
# scripts/run_python_examples.sh
# - name: Test executables
# run: |
# cd arbor
# scripts/test_executables.sh
key: spack-cache-${{ matrix.os }}-${{ matrix.spack-version }}-${{ github.run_id }}
restore-keys: spack-cache-${{ matrix.os }}-${{ matrix.spack-version }}-
- name: Get Spack (develop)
if: ${{ matrix.spack-version == 'develop' }}
run: |
git clone -c feature.manyFiles=true --depth 1 https://github.com/spack/spack.git
- name: Get Spack (latest_release)
if: ${{ matrix.spack-version == 'latest_release' }}
run: |
wget "$(curl -sH "Accept: application/vnd.github.v3+json" https://api.github.com/repos/spack/spack/releases/latest | grep browser_download_url | cut -d '"' -f 4)"
tar xfz spack*.tar.gz
mv spack*/ spack
- name: Prep
run: |
mkdir ~/.spack
cp arbor/spack/config.yaml ~/.spack
source spack/share/spack/setup-env.sh
spack repo create custom_repo
mkdir -p custom_repo/packages/arbor
spack repo add custom_repo
spack reindex
cp arbor/spack/package.py custom_repo/packages/arbor
- name: Build Arbor
run: |
source spack/share/spack/setup-env.sh
cd arbor
spack dev-build arbor@develop +python
- name: Load Arbor and verify installation, Python Examples.
run: |
source spack/share/spack/setup-env.sh
spack load arbor
cd arbor
scripts/run_python_examples.sh
scripts/test_executables.sh
- name: Remove Arbor
run: |
source spack/share/spack/setup-env.sh
spack uninstall -yafR arbor
- name: Failure, upload logs
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: spack-log-${{ matrix.spack-version }}
path: |
arbor/*.txt
!arbor/CMakeLists.txt
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ include(ErrorTarget) # reguired for add_error_target

# Set release as the default build type (CMake default is debug.)

if (NOT CMAKE_BUILD_TYPE)
if (NOT CMAKE_BUILD_TYPE AND NOT BUILD_TESTING)
set(CMAKE_BUILD_TYPE release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "debug" "release")
Expand Down
6 changes: 3 additions & 3 deletions doc/contrib/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ Update tags/versions and test
- Double check that all examples/tutorials/etc are covered by CI
- Check Python/pip/PyPi metadata and scripts, e.g. ``setup.py``, ``pyproject.toml``

#. Create new temp-branch ending in ``-rc``. E.g. ``v0.6-rc``
#. Create new temp-branch ending in ``-rc``. E.g. ``v0.9.0-rc``
#. Bump the ``VERSION`` file:

- For as long as `scikit-build-core` does not support loading fields from external files, also bump in `pyproject.toml`
- See also :ref:`dev-version`
- Append ``-rc``. (Make sure there's no ``-dev``)

#. Create a draft PR. Tag and push with ``-rc``. E.g. ``v0.6-rc``
#. Create a draft PR. Tag and push with ``-rc``. E.g. ``v0.9.0-rc``

- on cmdline: ``git tag -a TAGNAME``
- ``git push upstream refs/tags/TAGNAME``
Expand Down Expand Up @@ -126,7 +126,7 @@ Post Release

#. Update Zenodo with authors and changelog created in previous step and submit.

#. Make a new PR setting ``VERSION`` to the next with a trailing ``-dev``. E.g. if you just release ``3.14``, change ``VERSION`` to ``3.15-dev``
#. Make a new PR setting ``VERSION`` to the next with a trailing ``-dev``. E.g. if you just released ``3.14.15``, change ``VERSION`` to ``3.15.16-dev``. Make sure the number portion always consists of a triple. Shorter versions are uninstallable by Spack (``spack install [email protected]`` will install v0.8.1, due to anything shorter than a triple being interpreted as a version range).

- Update ``spack/package.py``. The checksum of the targz is the sha256sum.
- Include changes such as to ``CITATIONS``, ``doc/index.rst`` in postrel PR. Copy Zenodo BibTex export to ``CITATIONS``.
Expand Down
29 changes: 13 additions & 16 deletions scripts/arbor-build-catalogue
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ config = A.config()
prefix = Path(config["prefix"])
CXX = Path(config["CXX"])
if not CXX.exists():
try:
# Example <>/lib/python3.10/site-packages/arbor
altern = "c++"
print(
f"Warning: prefix '{CXX}' does not exist, falling back to '{altern}'.",
file=sys.stderr,
)
CXX = altern
except:
# Example <>/lib/python3.10/site-packages/arbor
altern = "c++"
from shutil import which
if which(altern) == None:
print(
f"Error: Neither prefix '{CXX}' nor fallback '{altern}' exist. Please provide a path to a C++ compiler with --cxx",
file=sys.stderr,
)
exit(-1)
print(
f"Warning: prefix '{CXX}' does not exist, falling back to '{altern}'.",
file=sys.stderr,
)
CXX = altern


def parse_arguments():
Expand Down Expand Up @@ -312,13 +312,10 @@ with TemporaryDirectory() as tmp:
cmake_cmd = "cmake .."
make_cmd = "make"
if verbose:
out, err = (None, None)
make_cmd += " VERBOSE=1"
else:
out, err = (sp.PIPE, sp.PIPE)
try:
sp.run(cmake_cmd, shell=True, check=True, stdout=out, stderr=err)
sp.run(make_cmd, shell=True, check=True, stdout=out, stderr=err)
sp.run(cmake_cmd, shell=True, check=True, capture_output = True, text = True)
sp.run(make_cmd, shell=True, check=True, capture_output = True, text = True)
shutil.copy2(f"{name}-catalogue.so", pwd)
except sp.CalledProcessError as e:
import traceback as tb
Expand All @@ -327,9 +324,9 @@ with TemporaryDirectory() as tmp:
# Not in verbose mode, so we have captured the
# `stdout` and `stderr` and can print it to the user.
sys.stdout.write("Build log:\n")
sys.stdout.write(e.stdout.decode())
sys.stdout.write(e.stdout)
sys.stderr.write(tb.format_exc() + " Error:\n\n")
sys.stderr.write(e.stderr.decode())
sys.stderr.write(e.stderr)
else:
# In verbose mode the outputs weren't captured and
# have been streamed to `stdout` and `stderr` already.
Expand Down
4 changes: 2 additions & 2 deletions scripts/build_spack_package.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
# checks out Spack and Arbor and builds it with the package.py from Arbor's repo
# Spack can be the latest release or the develop branch
# Also runs unit tests.

set -Eeuo pipefail

Expand Down Expand Up @@ -61,5 +62,4 @@ spack reindex

cp $ARBOR_DIR/spack/package.py $SPACK_CUSTOM_REPO/packages/arbor
cd $ARBOR_DIR
ARBOR_VERSION=$(cat "$ARBOR_DIR/VERSION")
spack dev-build arbor@${ARBOR_VERSION} +python
spack dev-build --test root arbor@develop +python
1 change: 1 addition & 0 deletions scripts/run_python_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $PREFIX python3 -m pip install -r python/example/example_requirements.txt -U
runpyex () {
echo "=== Executing $1 ======================================"
$PREFIX python3 python/example/$*
echo "### Example $1: OK."
}

runpyex brunel.py -n 400 -m 100 -e 20 -p 0.1 -w 1.2 -d 1 -g 0.5 -l 5 -t 100 -s 1 -G 50 -S 123
Expand Down
4 changes: 3 additions & 1 deletion scripts/test_executables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ set -Eeuo pipefail
echo "=== Executing modcc test ======================================"
modcc python/example/cat/dummy.mod
test -f "dummy.hpp"
echo "executable modcc: OK."

echo "=== Executing a-b-c test ======================================"
arbor-build-catalogue -v cat python/example/cat
arbor-build-catalogue --cxx=c++ cat python/example/cat
./scripts/test-catalogue.py ./cat-catalogue.so
echo "executable a-b-c: OK."
28 changes: 13 additions & 15 deletions spack/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@

from spack.package import *

try:
with open("VERSION", "r") as file:
DEVVERSION = file.readline().strip()
except:
DEVVERSION = None


class Arbor(CMakePackage, CudaPackage):
"""Arbor is a high-performance library for computational neuroscience
Expand All @@ -21,26 +15,25 @@ class Arbor(CMakePackage, CudaPackage):
url = "https://github.com/arbor-sim/arbor/releases/download/v0.8.1/arbor-v0.8.1-full.tar.gz"
maintainers = ["thorstenhater", "brenthuisman", "haampie"]

version("master", branch="master", submodules=True)
if DEVVERSION:
version(DEVVERSION)
version("master", branch="master")
version("develop")
version(
"0.8.1",
sha256="caebf96676ace6a9c50436541c420ca4bb53f0639dcab825de6fa370aacf6baa",
url="https://github.com/arbor-sim/arbor/releases/download/v0.8.1/arbor-v0.8.1-full.tar.gz",
)
version(
"0.8",
"0.8.0",
sha256="18df5600308841616996a9de93b55a105be0f59692daa5febd3a65aae5bc2c5d",
url="https://github.com/arbor-sim/arbor/releases/download/v0.8/arbor-v0.8-full.tar.gz",
)
version(
"0.7",
"0.7.0",
sha256="c3a6b7193946aee882bb85f9c38beac74209842ee94e80840968997ba3b84543",
url="https://github.com/arbor-sim/arbor/releases/download/v0.7/arbor-v0.7-full.tar.gz",
)
version(
"0.6",
"0.6.0",
sha256="4cd333b18effc8833428ddc0b99e7dc976804771bc85da90034c272c7019e1e8",
url="https://github.com/arbor-sim/arbor/releases/download/v0.6/arbor-v0.6-full.tar.gz",
)
Expand Down Expand Up @@ -99,9 +92,9 @@ class Arbor(CMakePackage, CudaPackage):
depends_on("[email protected]:", when="+python", type=("build", "run"))
depends_on("py-numpy", when="+python", type=("build", "run"))
with when("+python"):
depends_on("[email protected]:", type=("build"))
depends_on("[email protected]:", when="@0.5.3:", type=("build"))
depends_on("[email protected]:", when="@0.7.1:", type=("build"))
depends_on("[email protected]:", type="build")
depends_on("[email protected]:", when="@0.5.3:", type="build")
depends_on("[email protected]:", when="@0.7.1:", type="build")

# sphinx based documentation
depends_on("[email protected]:", when="+doc", type="build")
Expand Down Expand Up @@ -132,3 +125,8 @@ def cmake_args(self):
args.append("-DARB_CXX_FLAGS_TARGET=" + opt_flags)

return args

@run_after("install", when="+python")
@on_package_attributes(run_tests=True)
def install_test(self):
python("-c", "import arbor")

0 comments on commit 7d36beb

Please sign in to comment.