Skip to content

Commit

Permalink
TEST: fix workflow tests across OS and add test status badge
Browse files Browse the repository at this point in the history
  • Loading branch information
mh105 committed Jul 20, 2024
1 parent eba3a93 commit 65a843c
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 31 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/pr-pytest-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ jobs:
cache-environment: true

- name: Package install with pip
run: |
python --version
pip install .
run: pip install .

- name: "- Check python version"
run: python --version

- name: Lint with flake8
run: |
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/push-pytest-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ jobs:
cache-environment: true

- name: Package install with pip
run: |
python --version
pip install .
run: pip install .

- name: "- Check python version"
run: python --version

- name: Lint with flake8
run: |
Expand Down
62 changes: 44 additions & 18 deletions .github/workflows/release-install-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ on:

env:
PACKAGE_NAME: somata
RELEASE_JSON: https://api.github.com/repos/mh105/somata/releases/latest
RELEASE_HTTP: https://github.com/mh105/somata/releases/latest

jobs:
install-unix:
name: install-on-${{ matrix.os }}
pip-install:
name: pip-install-${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -26,12 +26,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: "Curl the latest release version"
run: |
latest_version=$(curl -s ${{ env.RELEASE_JSON }} | grep "tag_name" | cut -d '"' -f4 | cut -c2-)
echo "latest_version=$latest_version" >> $GITHUB_ENV
- name: "[Test 1] Create environment for 'pip install' on Unix"
- name: "Create environment for 'pip install' on Unix"
if: runner.os != 'Windows'
uses: mamba-org/setup-micromamba@v1
with:
Expand All @@ -40,27 +35,38 @@ jobs:
pip
cmdstanpy # avoids having to run 'install_cmdstan' after pip install

- name: "[Test 1] Create environment for 'pip install' on Windows"
- name: "Create environment for 'pip install' on Windows"
if: runner.os == 'Windows'
uses: mamba-org/setup-micromamba@v1
with:
environment-name: pip_env
create-args:
pip
cmdstanpy # avoids having to run 'install_cmdstan' after pip install
cmdstanpy
numpy<2
spectrum # avoids building 'spectrum' on Windows that requires VC++ v14+

- name: "- Pip install ${{ env.PACKAGE_NAME }}"
run: pip install ${{ env.PACKAGE_NAME }}

- name: "- Pip list"
run: pip list

- name: "- Get the latest release version"
run: |
python --version
pip list
latest_version=$(python -c "import requests; url = '${{ env.RELEASE_HTTP }}'; r = requests.get(url); print(r.url.split('/')[-1])" | awk '{print substr($0, 2)}')
if [ -n "$latest_version" ]; then
echo "latest_version extracted from GitHub releases: $latest_version"
echo "latest_version=$latest_version" >> $GITHUB_ENV
else
echo "failed to retrieve latest_version."
exit 1
fi
- name: "- Verify installed package version"
run: |
installed_version=$(pip show ${{ env.PACKAGE_NAME }} | grep Version | cut -d' ' -f2)
installed_version=$(pip show ${{ env.PACKAGE_NAME }} | grep Version | awk '{print $2}')
if [ "$installed_version" != "${{ env.latest_version }}" ]; then
echo "Installed version from PyPI ($installed_version) does not match the latest release version on GitHub (${{ env.latest_version }})."
exit 1
Expand All @@ -71,9 +77,22 @@ jobs:
- name: "- Run tests with pytest"
run: |
pip install pytest
pytest
pytest -vv
- name: "[Test 2] Install ${{ env.PACKAGE_NAME }} with 'conda create'"
conda-install:
name: conda-install-${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
defaults:
run:
shell: bash -el {0}

steps:
- uses: actions/checkout@v4

- name: "Install ${{ env.PACKAGE_NAME }} with 'conda create'"
uses: mamba-org/setup-micromamba@v1
with:
environment-name: conda_env
Expand All @@ -82,10 +101,17 @@ jobs:
-c conda-forge
${{ env.PACKAGE_NAME }}

- name: "- Micromamba list"
- name: "- Get the latest release version"
run: |
python --version
micromamba list
latest_version=$(python -c "import requests; url = '${{ env.RELEASE_HTTP }}'; r = requests.get(url); print(r.url.split('/')[-1])" | awk '{print substr($0, 2)}')
if [ -n "$latest_version" ]; then
echo "latest_version extracted from GitHub releases: $latest_version"
echo "latest_version=$latest_version" >> $GITHUB_ENV
else
echo "failed to retrieve latest_version."
exit 1
fi
- name: "- Verify installed package version"
run: |
Expand All @@ -100,4 +126,4 @@ jobs:
- name: "- Run tests with pytest"
run: |
micromamba install pytest
pytest
pytest -vv
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ Basic state-space models are introduced as class objects for flexible manipulati
Classical exact and approximate inference algorithms are implemented and interfaced as class methods.
Advanced neural oscillator modeling techniques are brought together to work synergistically.

[![Release install tests](https://github.com/mh105/somata/actions/workflows/release-install-tests.yml/badge.svg?kill_cache)](https://github.com/mh105/somata/actions/workflows/release-install-tests.yml)
[![Version](https://img.shields.io/badge/Version-0.5.5-green?kill_cache)](https://github.com/mh105/somata/releases)
[![Last-Update](https://anaconda.org/conda-forge/somata/badges/latest_release_date.svg?kill_cache)](https://anaconda.org/conda-forge/somata)
[![License: BSD 3-Clause Clear](https://img.shields.io/badge/License-BSD%203--Clause%20Clear-lightgrey.svg?kill_cache)](https://spdx.org/licenses/BSD-3-Clause-Clear.html)
[![DOI](https://zenodo.org/badge/556083594.svg?kill_cache)](https://zenodo.org/badge/latestdoi/556083594)
[![Release install tests](https://github.com/mh105/somata/actions/workflows/release-install-tests.yml/badge.svg)](https://github.com/mh105/somata/actions/workflows/release-install-tests.yml)
[![Version](https://img.shields.io/badge/Version-0.5.5-green)](https://github.com/mh105/somata/releases)
[![Last-Update](https://anaconda.org/conda-forge/somata/badges/latest_release_date.svg)](https://anaconda.org/conda-forge/somata)
[![License: BSD 3-Clause Clear](https://img.shields.io/badge/License-BSD%203--Clause%20Clear-lightgrey.svg)](https://spdx.org/licenses/BSD-3-Clause-Clear.html)
[![DOI](https://zenodo.org/badge/556083594.svg)](https://zenodo.org/badge/latestdoi/556083594)

---

Expand Down
38 changes: 38 additions & 0 deletions tests/test__import__numpy_torch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Author: Mingjian He <[email protected]>
Testing function for importing numpy and torch libraries
"""
import torch
import numpy as np


def test_import_numpy_torch(dim=2):
"""
Due to a strange dependency on sys lib5.dll between numpy and torch in
macOS(osx-arm64), one must import torch first then numpy to avoid the error:
>>> zsh: segmentation fault python
This is a very problematic issue because it fails silently without any
error message unless the offending function call is asked directly in a
python session because it is a system-level error that does not return an
error code to parent stacks, leading to all superordinate processes hanging.
This unit test checks that numpy and torch can be imported without error.
Note that we do not want to import within the function as it is executed
in runtime during test suite collection such as by pytest.
"""

np.random.seed(1)
A = np.random.rand(dim, dim)
A = A @ A.T + np.eye(dim)
_ = np.linalg.inv(A) # this call depends on lib5.dll
A = torch.as_tensor(data=A, dtype=torch.float32) # does not call lib5.dll
_ = torch.linalg.qr(A, mode='complete') # this call also invokes lib5.dll

return


if __name__ == "__main__":
test_import_numpy_torch()
print('numpy and torch import test finished without exception.')
3 changes: 1 addition & 2 deletions tests/test_dp_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Testing functions for exact inference signal processing methods in somata/exact_inferences/dp_func.py
"""

import torch
import numpy as np
from codetiming import Timer
from test_load_data import _load_data # type: ignore
Expand Down Expand Up @@ -195,7 +196,6 @@ def test_inverse(dim=128):

def test_inverse_torch(dim=128, atol=1e-3):
from somata.exact_inference import inverse_torch
import torch

np.random.seed(1)

Expand Down Expand Up @@ -263,7 +263,6 @@ def test_logdet():

def test_logdet_torch(rtol=1e-3, atol=1e-3):
from somata.exact_inference import logdet_torch
import torch

np.random.seed(1)

Expand Down

0 comments on commit 65a843c

Please sign in to comment.