Skip to content

Commit 81316c6

Browse files
authored
Add Python nogil workflow (#2843)
* Use threads for nogil test * Check equality across parallel simulations * Update nogil workflow setup * Update nogil workflow dependencies * Install pkgconfig for nogil workflow * Add nogil warning test and set PYTHON_GIL * update test * move test * Update test_nogil.py * Update test_nogil.py * Update test_nogil.py
1 parent acd41fb commit 81316c6

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

.github/actions/install-apt-dependencies/action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ runs:
1111
libboost-chrono-dev \
1212
libboost-math-dev \
1313
libboost-serialization-dev \
14-
libhdf5-serial-dev
14+
libhdf5-serial-dev \
15+
pkg-config \
16+
libxml2-dev \
17+
libxslt1-dev
1518
shell: bash
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Python nogil Tests
2+
on:
3+
push:
4+
pull_request:
5+
branches:
6+
- main
7+
merge_group:
8+
workflow_dispatch:
9+
10+
jobs:
11+
nogil-tests:
12+
name: Python nogil
13+
runs-on: ubuntu-24.04
14+
env:
15+
AMICI_SKIP_CMAKE_TESTS: "TRUE"
16+
AMICI_PARALLEL_COMPILE: ""
17+
steps:
18+
- run: echo "AMICI_DIR=$(pwd)" >> $GITHUB_ENV
19+
- name: Set up Python 3.13 free-threaded
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.13'
23+
freethreaded: true
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 20
27+
- name: Install apt dependencies
28+
uses: ./.github/actions/install-apt-dependencies
29+
- name: Install python package
30+
run: |
31+
python3 -m venv venv --clear
32+
source venv/bin/activate
33+
pip install --upgrade pip wheel
34+
pip install numpy sympy cmake-build-extension==0.6.0 swig cython pkgconfig
35+
AMICI_BUILD_TEMP="python/sdist/build/temp" \
36+
pip install --verbose -e python/sdist[test] --no-build-isolation
37+
- run: source venv/bin/activate && pip3 install "sympy>1.12"
38+
- name: Python tests
39+
env:
40+
AMICI_NOGIL: "1"
41+
run: |
42+
source venv/bin/activate && \
43+
pytest tests/test_nogil.py -vv

tests/test_nogil.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
3+
import pytest
4+
5+
pytestmark = pytest.mark.skipif(
6+
not os.environ.get("AMICI_NOGIL"),
7+
reason="only run in nogil workflow",
8+
)
9+
10+
11+
def test_import_warns_without_python_gil(monkeypatch):
12+
with pytest.raises(
13+
RuntimeWarning,
14+
match=r"The global interpreter lock \(GIL\) has been enabled to load module",
15+
):
16+
import amici
17+
18+
print(amici.__version__)

0 commit comments

Comments
 (0)