Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 58 additions & 17 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ permissions:
contents: read

env:
# One thread per process: the suite is numerically heavy and runs serially.
# One thread per process: the suite is numerically heavy and runs on one pytest-xdist
# worker per core, so a worker must not start threads of its own.
OMP_NUM_THREADS: "1"
MKL_NUM_THREADS: "1"
OPENBLAS_NUM_THREADS: "1"
Expand Down Expand Up @@ -72,7 +73,7 @@ jobs:
- name: Install the package and test dependencies
run: python -m pip install --upgrade pip ".[dev,fast,contact]"
- name: Run the test suite
run: python -m pytest -q -p no:cacheprovider
run: python -m pytest -q -p no:cacheprovider -n auto --dist worksteal --durations=25

reference-path:
name: Tests without the compiled kernels
Expand All @@ -92,10 +93,12 @@ jobs:
- name: Install the package without numba
run: python -m pip install --upgrade pip ".[dev,contact]"
- name: Run the test suite on the NumPy reference path
run: python -m pytest -q -p no:cacheprovider
run: python -m pytest -q -p no:cacheprovider -n auto --dist worksteal --durations=25

coverage:
name: Coverage and validation report
coverage-suite:
# Not a required check itself: the required check "Coverage and validation report"
# passes only if this job and validation-report both pass.
name: Coverage of the whole suite
runs-on: ubuntu-latest
timeout-minutes: 150
steps:
Expand All @@ -109,28 +112,66 @@ jobs:
cache-dependency-path: pyproject.toml
- name: Install the package and test dependencies
run: python -m pip install --upgrade pip ".[dev,fast,contact]"
- name: The committed validation report is current
# The script exits non-zero while registered benchmark rows fail; the step
# fails only if the committed report differs from the live calculation. It runs
# before the coverage run (about 45 min), so a stale report fails within minutes.
shell: bash
run: |
set +e
python validation/scripts/run_validation.py --check 2>&1 | tee validation-check.txt
status=${PIPESTATUS[0]}
if grep -q "validation artefacts are stale" validation-check.txt; then exit 1; fi
echo "run_validation exit status ${status} (registered FAIL rows are expected)"
- name: Run the whole suite with line and branch coverage, kernels traced
# Functions compiled by numba run outside the coverage tracer, so the kernel
# tests run a second time with NUMBA_DISABLE_JIT=1 and are appended.
run: python release/check_coverage.py --fail-under 95
run: python release/check_coverage.py --fail-under 95 --numprocesses auto
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: always()
with:
name: cablexsec-coverage
path: coverage.xml
if-no-files-found: ignore

validation-report:
# Not a required check itself; see coverage-suite.
name: Validation report is current
runs-on: ubuntu-latest
timeout-minutes: 150
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: '3.11'
cache: pip
cache-dependency-path: pyproject.toml
- name: Install the package and test dependencies
run: python -m pip install --upgrade pip ".[dev,fast,contact]"
- name: The committed validation report is current
# The script exits non-zero while registered benchmark rows fail; the step
# fails only if the committed report differs from the live calculation.
# --jobs=auto evaluates the independent row groups and the taxonomy groups
# concurrently; the rows and the report are those of the serial run.
shell: bash
run: |
set +e
python validation/scripts/run_validation.py --check --jobs=auto 2>&1 | tee validation-check.txt
status=${PIPESTATUS[0]}
if grep -q "validation artefacts are stale" validation-check.txt; then exit 1; fi
echo "run_validation exit status ${status} (registered FAIL rows are expected)"

coverage:
# The required check. The coverage run and the validation report check run side by
# side in the two jobs above; this job fails unless both succeeded, and it also
# runs (and fails) when either of them failed, was cancelled or was skipped.
name: Coverage and validation report
needs: [coverage-suite, validation-report]
if: always()
runs-on: ubuntu-latest
steps:
- name: The coverage gate and the validation report check passed
shell: bash
env:
COVERAGE_RESULT: ${{ needs.coverage-suite.result }}
VALIDATION_RESULT: ${{ needs.validation-report.result }}
run: |
echo "Coverage of the whole suite: ${COVERAGE_RESULT}"
echo "Validation report is current: ${VALIDATION_RESULT}"
test "${COVERAGE_RESULT}" = success
test "${VALIDATION_RESULT}" = success

distribution:
name: Build Python distributions
runs-on: ubuntu-latest
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,15 @@ All notable changes to CableXSec are recorded in this file. The format follows

### Changed

- CI runs the tests in parallel: the test matrix, the NumPy reference path and both coverage
passes run on one pytest-xdist worker per core (`pytest-xdist` joins the `dev` extra), and
each worker keeps its own numba cache. `release/check_coverage.py --numprocesses N` and
`run_validation.py --jobs=N` take a worker count; `--jobs` evaluates the independent row
groups in worker processes and runs the three taxonomy groups concurrently. The coverage
run and the validation report check run side by side in two jobs, and the required check
"Coverage and validation report" passes only when both pass. The tests, the 95 % threshold,
the kernel coverage pass, the rows, the report and its staleness check are unchanged.

- The rows that compare with the measured loops of Ménard and Cartraud (2023), BM1-loop,
BM1-loop-uniform and BM1-ID, are stated, not gated (status INFO, the verdict against the
registered target kept): the test is an unreliable reference. The benchmark register states the
Expand Down
15 changes: 11 additions & 4 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ python -m pytest -q -m full_scale # published full-scale dat
python -m pytest -q --cov --cov-branch --cov-report=term-missing
```

The whole suite takes about 20 minutes on one core. Do not run it with several
workers on a shared machine without limiting the threads of each worker; set
`OMP_NUM_THREADS`, `MKL_NUM_THREADS`, `OPENBLAS_NUM_THREADS` and `NUMBA_NUM_THREADS`
to `1`. The tests import the reproduction scripts of `validation/scripts/` by name
The whole suite takes about 20 minutes on one core. `python -m pytest -q -n 4` runs it
on four pytest-xdist workers (CI uses `-n auto --dist worksteal`); each worker keeps its
own numba cache (`tests/conftest.py`). Do not run it with several workers without
limiting the threads of each worker; set `OMP_NUM_THREADS`, `MKL_NUM_THREADS`,
`OPENBLAS_NUM_THREADS` and `NUMBA_NUM_THREADS` to `1`. The coverage gate
`python release/check_coverage.py --fail-under 95` takes `--numprocesses 4` in the same
way. The tests import the reproduction scripts of `validation/scripts/` by name
(`tests/conftest.py` puts that folder on the import path).

| Marker | Tests |
Expand All @@ -59,6 +62,10 @@ python validation/scripts/run_validation.py # regenerate validation/val
python validation/scripts/run_validation.py --check # fail if the committed report is stale
```

`--jobs=N` (or `--jobs=auto`) evaluates the independent row groups in N processes and runs
the three marker groups concurrently, each on N pytest-xdist workers; the rows and the
report are those of the serial run.

The script recomputes every row from the live code, runs the three marker groups for
the test taxonomy, and exits non-zero while any row is `FAIL` or `REVIEW`; the failed
rows of the 0.1.0 report are registered, unresolved discrepancies (see
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ dev = [
"build>=1.2",
"pytest>=8.0",
"pytest-cov>=5",
"pytest-xdist>=3.6,<4",
"ruff>=0.15,<0.16",
"mypy>=1.11",
"twine>=5",
Expand Down
15 changes: 14 additions & 1 deletion release/check_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
``NUMBA_DISABLE_JIT=1`` so that the kernel bodies execute as Python, appends both to
one coverage record, and fails below the threshold.

Usage: ``python release/check_coverage.py [--fail-under 95]``
``--numprocesses`` (pytest-xdist) runs both passes on several workers; pytest-cov
combines the workers of each pass, and the second pass is appended to the first as in
a serial run.

Usage: ``python release/check_coverage.py [--fail-under 95] [--numprocesses auto]``
"""

from __future__ import annotations
Expand Down Expand Up @@ -50,9 +54,18 @@ def run(command: list[str], extra_env: dict[str, str] | None = None) -> int:
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("--fail-under", type=float, default=95.0)
parser.add_argument(
"-n",
"--numprocesses",
default=None,
help="pytest-xdist workers for both passes (a number, auto or logical); "
"serial when omitted",
)
args = parser.parse_args()
python = sys.executable
pytest = [python, "-m", "pytest", "-q", "-p", "no:cacheprovider"]
if args.numprocesses is not None:
pytest += ["-n", args.numprocesses]
status = run(
[*pytest, "--cov", "--cov-branch", "--cov-report=", "--cov-fail-under=0"]
)
Expand Down
23 changes: 22 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University
"""Test configuration: make the validation scripts importable by name."""
"""Test configuration: make the validation scripts importable by name.

Under pytest-xdist every worker gets its own numba cache directory before numba is
imported, so that concurrent workers (and the subprocesses they start) never write
the same on-disk kernel cache; a serial run keeps numba's default location.
"""

from __future__ import annotations

import os
import shutil
import sys
import tempfile
from pathlib import Path

_WORKER = os.environ.get("PYTEST_XDIST_WORKER")
_NUMBA_CACHE: Path | None = None
if _WORKER and "NUMBA_CACHE_DIR" not in os.environ:
_RUN = os.environ.get("PYTEST_XDIST_TESTRUNUID", "run")
_NUMBA_CACHE = Path(tempfile.gettempdir()) / f"cablexsec-numba-{_RUN}-{_WORKER}"
os.environ["NUMBA_CACHE_DIR"] = str(_NUMBA_CACHE)

_SCRIPTS = Path(__file__).resolve().parents[1] / "validation" / "scripts"
if str(_SCRIPTS) not in sys.path:
sys.path.insert(0, str(_SCRIPTS))


def pytest_unconfigure(config: object) -> None:
"""Remove the worker's own numba cache at the end of the run."""
if _NUMBA_CACHE is not None:
shutil.rmtree(_NUMBA_CACHE, ignore_errors=True)
Loading
Loading