Skip to content

Commit

Permalink
Add pypy to test matrix (#142)
Browse files Browse the repository at this point in the history
* Add pypy to test matrix
* catch -> doctest
* tweak CI setup
  • Loading branch information
bjodah authored Apr 21, 2024
1 parent 6c6e6c4 commit f00c8ea
Show file tree
Hide file tree
Showing 24 changed files with 130 additions and 97 deletions.
1 change: 1 addition & 0 deletions .ci/run-matrix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export PATH=/opt-2/gcc-13/bin:$PATH
export CC=gcc
export CXX=g++
# .ci/test-case.sh --asan --python /opt-3/cpython-v3.11.9-asan/bin/python3 /opt-3/sundials-6.7.0-asan
.ci/test-case.sh --python /opt-3/pypy3.10-v7.3.15-linux64/bin/python3 /opt-3/sundials-6.7.0-debug
.ci/test-case.sh --python /opt-3/cpython-v3.11.?-debug/bin/python3 /opt-3/sundials-6.7.0-debug
.ci/test-case.sh --python /opt-3/cpython-v3.12.2-debug/bin/python3 /opt-3/sundials-6.7.0-debug
PYCVODES_NO_LAPACK=1 PYCVODES_NO_KLU=1 .ci/test-case.sh --python /opt-3/cpython-v3.11-apt-deb/bin/python3 /opt-3/sundials-6.7.0-extended
Expand Down
16 changes: 14 additions & 2 deletions .ci/test-case.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ show_help() {
echo "--native"
echo "--python <python-exe-path>"
}

NATIVE=0
TEST_ASAN=0
MAKE_TMP_DIR=0
while [ $# -gt 1 ]; do
case $1 in
--native)
Expand All @@ -22,12 +24,21 @@ while [ $# -gt 1 ]; do
TEST_ASAN=1
shift
;;
--tmp)
MAKE_TMP_DIR=1
shift
;;
*)
>&2 echo "Unrecognized parameter: $1"
exit 1
esac
done

if [ "$MAKE_TMP_DIR" = 1 ]; then
REPO_TMP_DIR=$(mktemp -d)
trap 'rm -rf -- "$REPO_TMP_DIR"' EXIT
cp -ra . "$REPO_TMP_DIR/."
cd "$REPO_TMP_DIR"
fi
SUNDBASE=$1
if [ ! -d "$SUNDBASE/include/sundials" ]; then >&2 echo "No such directory: $SUNDBASE"; exit 1; fi
if [[ $SUNDBASE =~ *-extended || $SUNDBASE =~ *-single ]]; then
Expand All @@ -40,6 +51,7 @@ export LDFLAGS="$LINKLIBS -Wl,--disable-new-dtags -Wl,-rpath,$SUNDBASE/lib -L$SU
export LD_LIBRARY_PATH=$(compgen -G "/opt-2/llvm-*/lib")

if [ $TEST_ASAN -eq 1 ]; then
export CC=clang
export CXX=clang++
LIBCXX_ASAN_ROOT=$(compgen -G "/opt-2/libcxx*-asan")
LIBCXX_ASAN_INCLUDE=${LIBCXX_ASAN_ROOT}/include/c++/v1
Expand All @@ -53,7 +65,7 @@ if [ $TEST_ASAN -eq 1 ]; then
# LD_PRELOAD=$(clang++ --print-file-name=libclang_rt.asan.so)
export PYTHON="env ASAN_OPTIONS=abort_on_error=1,detect_leaks=0 ${PYTHON:-python3}"
else
export PATH=/opt-2/gcc-13/bin:$PATH
export CC=gcc
export CXX=g++
if $CXX --version | head -n 1 | grep -E 'g++\.*13\.[0-9]\.[0-9]$'; then exit 1; fi
export CXXFLAGS="$CXXFLAGS -D_GLIBCXX_DEBUG -D_GLIBCXX_PEDANTIC"
Expand Down
15 changes: 10 additions & 5 deletions .ci/test-sdist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ env \
CFLAGS="-isystem $SUNDBASE/include -isystem /usr/include/suitesparse" \
LDFLAGS="-Wl,--disable-new-dtags -Wl,-rpath,$SUNDBASE/lib -L$SUNDBASE/lib" \
CC=gcc CXX=g++ pip install ${CI_REPO_NAME}-*.tar.gz
pip install pytest-flakes pytest-cov matplotlib sphinx numpydoc sphinx-rtd-theme
../scripts/run_tests.sh --cov ${CI_REPO_NAME} --cov-report html
../scripts/coverage_badge.py htmlcov/ htmlcov/coverage.svg

python3 -m pytest --pyargs pycvodes
cd -
source ./scripts/generate_docs.sh
env \
CFLAGS="-isystem $SUNDBASE/include -isystem /usr/include/suitesparse" \
LDFLAGS="-Wl,--disable-new-dtags -Wl,-rpath,$SUNDBASE/lib -L$SUNDBASE/lib" \
CC=gcc CXX=g++ python3 setup.py build_ext -i

pip install pytest-flakes pytest-cov matplotlib sphinx numpydoc sphinx-rtd-theme
./scripts/run_tests.sh --cov ${CI_REPO_NAME} --cov-report html
./scripts/coverage_badge.py htmlcov/ htmlcov/coverage.svg
./scripts/generate_docs.sh
58 changes: 46 additions & 12 deletions .woodpecker.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,64 @@
when:
- event: [pull_request, tag, cron, push]
- event: [push] # pull_request, tag, cron,

steps:
- name: build-and-test-asan
image: cont-reg.bjodah.se:443/bjodah/triceratops-3:14
- name: pypy
image: cont-reg.bjodah.se:443/bjodah/triceratops-3:16
commands:
- .ci/test-case.sh --tmp --python /opt-3/pypy3.10-v7.3.15-linux64/bin/python3 /opt-3/sundials-6.7.0-debug

- name: py3.11-dbg
image: cont-reg.bjodah.se:443/bjodah/triceratops-3:16
commands:
- .ci/test-case.sh --tmp --python /opt-3/cpython-v3.11.?-debug/bin/python3 /opt-3/sundials-6.7.0-debug

- name: py3.12-dbg
image: cont-reg.bjodah.se:443/bjodah/triceratops-3:16
commands:
- .ci/test-case.sh --tmp --python /opt-3/cpython-v3.12.2-debug/bin/python3 /opt-3/sundials-6.7.0-debug

- name: py3.11-extended
image: cont-reg.bjodah.se:443/bjodah/triceratops-3:16
environment:
- PYCVODES_NO_LAPACK=1
- PYCVODES_NO_KLU=1
commands:
- .ci/test-case.sh --tmp --python /opt-3/cpython-v3.11-apt-deb/bin/python3 /opt-3/sundials-6.7.0-extended

- name: py3.12-single
image: cont-reg.bjodah.se:443/bjodah/triceratops-3:16
environment:
- PYCVODES_NO_LAPACK=1
- PYCVODES_NO_KLU=1
commands:
- .ci/test-case.sh --tmp --python /opt-3/cpython-v3.12.2-release/bin/python3 /opt-3/sundials-6.7.0-single

- name: sdist-and-docs
image: cont-reg.bjodah.se:443/bjodah/triceratops-3:16
environment:
- PYCVODES_STRICT=1
- LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
- LLVM_ROOT=/opt-2/llvm-18
commands:
#- git fetch -tq
# - bash -c '[[ $(python3 setup.py --version 2>/dev/null) =~ ^[0-9]+.* ]]'
- .ci/run-matrix.sh
- .ci/test-sdist.sh
- ./scripts/prepare_deploy.sh
- if grep "DO-NOT-MERGE!" -R . --exclude ".woodpecker.yml"; then exit 1; fi

- if grep "DO-NOT-MERGE!" -R . --exclude ".woodpecker.yaml"; then exit 1; fi
depends_on:
- pypy
- py3.11-dbg
- py3.12-dbg
- py3.11-extended
- py3.12-single

- name: deploy-public-html
image: cont-reg.bjodah.se:443/bjodah/triceratops-3:14
image: cont-reg.bjodah.se:443/bjodah/triceratops-3:16
commands:
- tar -C ./deploy/public_html czf pycovdes-${CI_COMMIT_BRANCH}.tar.gz .
- curl -T pycovdes-${CI_COMMIT_BRANCH}.tar.gz ftp://pycovdes:$${ARTIFACTS_PASS}@$${FTP_SERVER}/public_html/
- tar -C ./deploy/public_html -czf pycvodes-${CI_COMMIT_BRANCH}.tar.gz .
- curl -T pycvodes-${CI_COMMIT_BRANCH}.tar.gz ftp://pycvodes:$${ARTIFACTS_PASS}@$${FTP_SERVER}/public_html/
secrets: [ ARTIFACTS_PASS, FTP_SERVER ]
when:
- event: push
repo: github.com/bjodah/pycovdes
repo: bjodah/pycvodes
depends_on:
- build-and-test
- sdist-and-docs
29 changes: 0 additions & 29 deletions appveyor.yml

This file was deleted.

2 changes: 1 addition & 1 deletion external/anyode
5 changes: 4 additions & 1 deletion pycvodes/include/sundials_cxx.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#pragma once
#include <cstring> // std::memcpy
#include <nvector/nvector_serial.h> /* serial N_Vector types, fcts., macros */
#include <sundials/sundials_config.h>
#include <stdexcept>
#include <cstring> // std::memcpy
#include <vector>

namespace sundials_cxx {
#if SUNDIALS_VERSION_MAJOR >= 3
const int version_major = SUNDIALS_VERSION_MAJOR;
Expand Down
18 changes: 12 additions & 6 deletions pycvodes/tests/test_cvodes_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
)


def _get_refcount_None():
if hasattr(sys, 'getrefcount'):
gc.collect()
gc.collect()
return sys.getrefcount(None)
else: # e.g. pypy
return 0


def test_config_env():
# This test is useful for e.g. out-of-tree conda-recipes (e.g. conda-forge) where variables
# are set manually (and could otherwise be forgotten unless tests fail).
Expand Down Expand Up @@ -822,10 +831,7 @@ def j(t, y, Jmat, dfdt=None, fy=None):
k = 0
for jiter in range(nIter):
if jiter == 1:
gc.collect()
gc.collect()
nNone1 = sys.getrefcount(None)

nNone1 = _get_refcount_None()
t0 = k
tend = k + 1 # so let the step to be 1 second
k+=1
Expand All @@ -840,5 +846,5 @@ def j(t, y, Jmat, dfdt=None, fy=None):
y_prev2 = yout.T[1][-1]
gc.collect()
gc.collect()
nNone2 = sys.getrefcount(None)
assert -10 < nNone1 - nNone2 < 10
nNone2 = _get_refcount_None()
assert -nIter//10 < nNone1 - nNone2 < nIter//10
4 changes: 2 additions & 2 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
catch.hpp
doctest.h
doctest.o
test_cvodes_anyode
test_cvodes_cxx
test_sundials_cxx
Expand All @@ -8,6 +9,5 @@ test_cvodes_anyode_autorestart
test_cvodes_anyode_svd
test_tough_case
test_cvodes_anyode_quad
catch.o
test_cvodes_anyode_jtimes
test_cvodes_anyode_sparse
14 changes: 7 additions & 7 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ else
endif

clean:
$(RM) catch.o
$(RM) doctest.o
$(RM) $(TARGETS)
if [ -f test_cvodes_anyode_parallel ] ; then rm test_cvodes_anyode_parallel ; fi;

test_%: test_%.cpp ../pycvodes/include/cvodes_cxx.hpp catch.o
$(CXX) $(CXXFLAGS) $(INCLUDE) $(DEFINES) -o $@ $< catch.o $(LDFLAGS)
test_%: test_%.cpp ../pycvodes/include/cvodes_cxx.hpp doctest.o
$(CXX) $(CXXFLAGS) $(INCLUDE) $(DEFINES) -o $@ $< doctest.o $(LDFLAGS)

test_cvodes_anyode_parallel: test_cvodes_anyode_parallel.cpp ../pycvodes/include/cvodes_*.hpp catch.o
test_cvodes_anyode_parallel: test_cvodes_anyode_parallel.cpp ../pycvodes/include/cvodes_*.hpp doctest.o
ifeq ($(CXX),clang++-6.0)
@echo "skipping openmp when using clang"
else
$(CXX) $(CXXFLAGS) $(OPENMP_FLAG) $(INCLUDE) $(DEFINES) -o $@ $< catch.o $(LDFLAGS) $(OPENMP_LIB)
$(CXX) $(CXXFLAGS) $(OPENMP_FLAG) $(INCLUDE) $(DEFINES) -o $@ $< doctest.o $(LDFLAGS) $(OPENMP_LIB)
endif

catch.hpp: catch.hpp.bz2
doctest.h: doctest.h.bz2
bzcat $< >$@

catch.o: catch.cpp catch.hpp
doctest.o: doctest.cpp doctest.h

2 changes: 0 additions & 2 deletions tests/catch.cpp

This file was deleted.

2 changes: 2 additions & 0 deletions tests/doctest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
Binary file added tests/doctest.h.bz2
Binary file not shown.
1 change: 1 addition & 0 deletions tests/doctest.h.url
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/doctest/doctest/releases/download/v2.4.11/doctest.h
12 changes: 6 additions & 6 deletions tests/test_cvodes_anyode.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// C++11 source code.
#include "catch.hpp"
#include "doctest.h"
#include "cvodes_anyode.hpp"
#include "testing_utils.hpp"

TEST_CASE( "decay_adaptive", "[simple_adaptive]" ) {
TEST_CASE( "decay_adaptive" ) {
Decay odesys(1.0);
std::vector<int> root_indices;
int td = 1;
Expand All @@ -24,7 +24,7 @@ TEST_CASE( "decay_adaptive", "[simple_adaptive]" ) {
free(xyout);
}

TEST_CASE( "decay_adaptive_ew_ele", "[simple_adaptive]" ) {
TEST_CASE( "decay_adaptive_ew_ele" ) {
Decay odesys(1.0);
std::vector<int> root_indices;
int td = 1;
Expand Down Expand Up @@ -65,7 +65,7 @@ TEST_CASE( "decay_adaptive_ew_ele", "[simple_adaptive]" ) {
free(ew_ele);
}

TEST_CASE( "decay_predefined_ew_ele", "[simple_predefined]" ) {
TEST_CASE( "decay_predefined_ew_ele" ) {
Decay odesys(1.0);
int nt = 37;
realtype t0=0, tend=4.0;
Expand Down Expand Up @@ -108,7 +108,7 @@ TEST_CASE( "decay_predefined_ew_ele", "[simple_predefined]" ) {
REQUIRE( odesys.current_info.nfo_int["n_steps"] < 997 );
}

TEST_CASE( "decay_adaptive_get_dx_max", "[simple_adaptive]" ) {
TEST_CASE( "decay_adaptive_get_dx_max" ) {
Decay odesys(1.0);
realtype y0 = 1.0;
std::vector<int> root_indices;
Expand All @@ -130,7 +130,7 @@ TEST_CASE( "decay_adaptive_get_dx_max", "[simple_adaptive]" ) {
}


TEST_CASE( "decay_adaptive_dx_max", "[simple_adaptive]" ) {
TEST_CASE( "decay_adaptive_dx_max" ) {
Decay odesys(1.0);
realtype y0 = 1.0;
std::vector<int> root_indices;
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cvodes_anyode_autorestart.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "catch.hpp"
#include "doctest.h"
#include <math.h>
#include <vector>
#include "anyode/anyode.hpp"
Expand All @@ -7,7 +7,7 @@
#include "cetsa_case.hpp"


TEST_CASE( "adaptive_autorestart", "[simple_adaptive]" ) {
TEST_CASE( "adaptive_autorestart" ) {
std::vector<realtype> p = {{298.15, 39390, -135.3, 18010, 44960, 48.2, 65919.5, -93.8304, 1780, 3790, 57.44, 19700, -157.4}};
OdeSys odesys(&p[0]);
int td = 1;
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cvodes_anyode_jtimes.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "catch.hpp"
#include "doctest.h"
#include <math.h>
#include <vector>
#include "anyode/anyode.hpp"
#include "cvodes_anyode.hpp"
#include "cetsa_case_iterative.hpp"

TEST_CASE( "adaptive_tricky_svd_no_jac_no_prec", "[simple_adaptive]" ) {
TEST_CASE( "adaptive_tricky_svd_no_jac_no_prec" ) {
std::vector<realtype> p = {{321.14999999999998, 39390, -135.30000000000001, 18010, 44960, 48.200000000000003,
49320, -114.59999999999999, 1780, -34400.547966379738, -2.865040967667511,
93065.338440593958, 5.7581184659305222}};
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cvodes_anyode_parallel.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// C++11 source code.
#include "catch.hpp"
#include "doctest.h"
#include "cvodes_anyode_parallel.hpp"
#include "testing_utils.hpp"

TEST_CASE( "decay_adaptive", "[multi_adaptive]" ) {
TEST_CASE( "decay_adaptive" ) {
std::vector<realtype> k {{ 2.0, 3.0}};
Decay odesys1(k[0]);
Decay odesys2(k[1]);
Expand Down Expand Up @@ -44,7 +44,7 @@ TEST_CASE( "decay_adaptive", "[multi_adaptive]" ) {
free(xyout_arr);
}

TEST_CASE( "decay_predefined", "[multi_predefined]" ) {
TEST_CASE( "decay_predefined" ) {
std::vector<realtype> k {{ 2.0, 3.0}};
Decay odesys1(k[0]);
Decay odesys2(k[1]);
Expand Down
Loading

0 comments on commit f00c8ea

Please sign in to comment.