arraybridge 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arraybridge-0.2.0/.github/workflows/ci.yml +153 -0
- arraybridge-0.2.0/.github/workflows/gpu-tests.yml +69 -0
- arraybridge-0.2.0/.github/workflows/publish.yml +51 -0
- arraybridge-0.2.0/.gitignore +48 -0
- arraybridge-0.2.0/.readthedocs.yml +33 -0
- arraybridge-0.2.0/CI_IMPROVEMENTS.md +193 -0
- arraybridge-0.2.0/CONFLICT_VISUALIZATION.md +283 -0
- arraybridge-0.2.0/CONTRIBUTING.md +417 -0
- arraybridge-0.2.0/LICENSE +21 -0
- arraybridge-0.2.0/MERGE_CONFLICT_RESOLUTION.md +241 -0
- arraybridge-0.2.0/PKG-INFO +228 -0
- arraybridge-0.2.0/QUICK_FIX_GUIDE.txt +141 -0
- arraybridge-0.2.0/README.md +173 -0
- arraybridge-0.2.0/RESOLVED_FILES.md +196 -0
- arraybridge-0.2.0/TESTING.md +175 -0
- arraybridge-0.2.0/docs/Makefile +20 -0
- arraybridge-0.2.0/docs/ci-cd.md +352 -0
- arraybridge-0.2.0/docs/source/.gitignore +3 -0
- arraybridge-0.2.0/docs/source/Makefile +20 -0
- arraybridge-0.2.0/docs/source/README.md +145 -0
- arraybridge-0.2.0/docs/source/advanced_topics.rst +637 -0
- arraybridge-0.2.0/docs/source/api/converters.rst +46 -0
- arraybridge-0.2.0/docs/source/api/decorators.rst +72 -0
- arraybridge-0.2.0/docs/source/api/exceptions.rst +39 -0
- arraybridge-0.2.0/docs/source/api/index.rst +24 -0
- arraybridge-0.2.0/docs/source/api/types.rst +54 -0
- arraybridge-0.2.0/docs/source/api/utils.rst +70 -0
- arraybridge-0.2.0/docs/source/api_reference.rst +629 -0
- arraybridge-0.2.0/docs/source/ci-cd.rst +32 -0
- arraybridge-0.2.0/docs/source/conf.py +133 -0
- arraybridge-0.2.0/docs/source/contributing.rst +24 -0
- arraybridge-0.2.0/docs/source/converters.rst +474 -0
- arraybridge-0.2.0/docs/source/decorators.rst +638 -0
- arraybridge-0.2.0/docs/source/examples/basic_conversion.rst +98 -0
- arraybridge-0.2.0/docs/source/examples/decorators.rst +124 -0
- arraybridge-0.2.0/docs/source/examples/index.rst +18 -0
- arraybridge-0.2.0/docs/source/examples/multi_framework.rst +132 -0
- arraybridge-0.2.0/docs/source/gpu_features.rst +624 -0
- arraybridge-0.2.0/docs/source/index.rst +96 -0
- arraybridge-0.2.0/docs/source/installation.rst +229 -0
- arraybridge-0.2.0/docs/source/quickstart.rst +281 -0
- arraybridge-0.2.0/docs/source/stack_utils.rst +600 -0
- arraybridge-0.2.0/docs/source/user_guide.rst +568 -0
- arraybridge-0.2.0/pyproject.toml +95 -0
- arraybridge-0.2.0/src/arraybridge/__init__.py +37 -0
- arraybridge-0.2.0/src/arraybridge/conversion_helpers.py +150 -0
- arraybridge-0.2.0/src/arraybridge/converters.py +61 -0
- arraybridge-0.2.0/src/arraybridge/decorators.py +396 -0
- arraybridge-0.2.0/src/arraybridge/dtype_scaling.py +157 -0
- arraybridge-0.2.0/src/arraybridge/exceptions.py +26 -0
- arraybridge-0.2.0/src/arraybridge/framework_config.py +459 -0
- arraybridge-0.2.0/src/arraybridge/framework_ops.py +15 -0
- arraybridge-0.2.0/src/arraybridge/gpu_cleanup.py +149 -0
- arraybridge-0.2.0/src/arraybridge/oom_recovery.py +148 -0
- arraybridge-0.2.0/src/arraybridge/slice_processing.py +73 -0
- arraybridge-0.2.0/src/arraybridge/stack_utils.py +317 -0
- arraybridge-0.2.0/src/arraybridge/types.py +70 -0
- arraybridge-0.2.0/src/arraybridge/utils.py +352 -0
- arraybridge-0.2.0/tests/__init__.py +1 -0
- arraybridge-0.2.0/tests/conftest.py +119 -0
- arraybridge-0.2.0/tests/test_converters.py +170 -0
- arraybridge-0.2.0/tests/test_exceptions.py +62 -0
- arraybridge-0.2.0/tests/test_integration.py +193 -0
- arraybridge-0.2.0/tests/test_types.py +80 -0
- arraybridge-0.2.0/tests/test_utils.py +151 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main, master]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main, master]
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
# Test across Python versions with CPU-compatible frameworks
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ${{ matrix.os }}
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
python-version: ["3.10", "3.11", "3.12"]
|
|
18
|
+
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
19
|
+
framework: [none, torch]
|
|
20
|
+
exclude:
|
|
21
|
+
# Reduce matrix size - test torch mainly on ubuntu
|
|
22
|
+
- os: windows-latest
|
|
23
|
+
framework: torch
|
|
24
|
+
- os: macos-latest
|
|
25
|
+
framework: torch
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- name: Checkout
|
|
29
|
+
uses: actions/checkout@v4
|
|
30
|
+
|
|
31
|
+
- name: Setup Python ${{ matrix.python-version }}
|
|
32
|
+
uses: actions/setup-python@v5
|
|
33
|
+
with:
|
|
34
|
+
python-version: ${{ matrix.python-version }}
|
|
35
|
+
|
|
36
|
+
- name: Install base dependencies
|
|
37
|
+
run: |
|
|
38
|
+
python -m pip install --upgrade pip
|
|
39
|
+
pip install -e ".[dev]"
|
|
40
|
+
|
|
41
|
+
- name: Install PyTorch (CPU-only)
|
|
42
|
+
if: matrix.framework == 'torch'
|
|
43
|
+
run: |
|
|
44
|
+
pip install torch --index-url https://download.pytorch.org/whl/cpu
|
|
45
|
+
|
|
46
|
+
- name: Run tests with coverage
|
|
47
|
+
run: |
|
|
48
|
+
pytest --cov=arraybridge --cov-report=xml --cov-report=html --cov-report=term-missing -v
|
|
49
|
+
|
|
50
|
+
- name: Upload coverage to Codecov
|
|
51
|
+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' && matrix.framework == 'torch'
|
|
52
|
+
uses: codecov/codecov-action@v3
|
|
53
|
+
with:
|
|
54
|
+
file: ./coverage.xml
|
|
55
|
+
fail_ci_if_error: false
|
|
56
|
+
|
|
57
|
+
# GPU tests with GitHub Actions GPU runners (optional, non-blocking)
|
|
58
|
+
# Note: GPU runners may have long queue times, so this job is allowed to fail
|
|
59
|
+
gpu-test:
|
|
60
|
+
runs-on: ubuntu-latest-gpu-t4
|
|
61
|
+
continue-on-error: true # Don't block PR merges if GPU tests fail or timeout
|
|
62
|
+
|
|
63
|
+
steps:
|
|
64
|
+
- name: Checkout
|
|
65
|
+
uses: actions/checkout@v4
|
|
66
|
+
|
|
67
|
+
- name: Setup Python
|
|
68
|
+
uses: actions/setup-python@v5
|
|
69
|
+
with:
|
|
70
|
+
python-version: "3.12"
|
|
71
|
+
|
|
72
|
+
- name: Check CUDA availability
|
|
73
|
+
run: |
|
|
74
|
+
nvidia-smi
|
|
75
|
+
nvcc --version || echo "NVCC not available"
|
|
76
|
+
|
|
77
|
+
- name: Install base dependencies
|
|
78
|
+
run: |
|
|
79
|
+
python -m pip install --upgrade pip
|
|
80
|
+
pip install -e ".[dev]"
|
|
81
|
+
|
|
82
|
+
- name: Install GPU frameworks
|
|
83
|
+
run: |
|
|
84
|
+
# Install PyTorch with CUDA support
|
|
85
|
+
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
|
|
86
|
+
|
|
87
|
+
# Install CuPy with CUDA 12.x support
|
|
88
|
+
pip install cupy-cuda12x
|
|
89
|
+
|
|
90
|
+
# Verify installations
|
|
91
|
+
python -c "import torch; print(f'PyTorch version: {torch.__version__}'); print(f'CUDA available: {torch.cuda.is_available()}'); print(f'CUDA device: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"N/A\"}')"
|
|
92
|
+
python -c "import cupy as cp; print(f'CuPy version: {cp.__version__}'); print(f'CUDA device: {cp.cuda.Device()}')"
|
|
93
|
+
|
|
94
|
+
- name: Run GPU tests
|
|
95
|
+
run: |
|
|
96
|
+
# Run all tests - GPU frameworks will be used when available
|
|
97
|
+
pytest -v --tb=short
|
|
98
|
+
|
|
99
|
+
- name: Test GPU memory conversions
|
|
100
|
+
run: |
|
|
101
|
+
# Quick sanity check for GPU conversions
|
|
102
|
+
python -c "
|
|
103
|
+
import numpy as np
|
|
104
|
+
import torch
|
|
105
|
+
import cupy as cp
|
|
106
|
+
from arraybridge import convert_memory, detect_memory_type
|
|
107
|
+
|
|
108
|
+
# Test NumPy -> CuPy
|
|
109
|
+
np_arr = np.array([1, 2, 3], dtype=np.float32)
|
|
110
|
+
cp_arr = convert_memory(np_arr, 'numpy', 'cupy', gpu_id=0)
|
|
111
|
+
print(f'NumPy -> CuPy: {type(cp_arr)}, device: {cp_arr.device}')
|
|
112
|
+
|
|
113
|
+
# Test NumPy -> PyTorch GPU
|
|
114
|
+
torch_arr = convert_memory(np_arr, 'numpy', 'torch', gpu_id=0)
|
|
115
|
+
print(f'NumPy -> PyTorch: {type(torch_arr)}, device: {torch_arr.device}')
|
|
116
|
+
|
|
117
|
+
# Test CuPy -> PyTorch
|
|
118
|
+
torch_from_cp = convert_memory(cp_arr, 'cupy', 'torch', gpu_id=0)
|
|
119
|
+
print(f'CuPy -> PyTorch: {type(torch_from_cp)}, device: {torch_from_cp.device}')
|
|
120
|
+
|
|
121
|
+
print('✓ All GPU conversions successful!')
|
|
122
|
+
"
|
|
123
|
+
|
|
124
|
+
# Code quality checks
|
|
125
|
+
code-quality:
|
|
126
|
+
runs-on: ubuntu-latest
|
|
127
|
+
|
|
128
|
+
steps:
|
|
129
|
+
- name: Checkout
|
|
130
|
+
uses: actions/checkout@v4
|
|
131
|
+
|
|
132
|
+
- name: Setup Python
|
|
133
|
+
uses: actions/setup-python@v5
|
|
134
|
+
with:
|
|
135
|
+
python-version: "3.12"
|
|
136
|
+
|
|
137
|
+
- name: Install dependencies
|
|
138
|
+
run: |
|
|
139
|
+
python -m pip install --upgrade pip
|
|
140
|
+
pip install ruff black mypy
|
|
141
|
+
|
|
142
|
+
- name: Run ruff (linting)
|
|
143
|
+
run: |
|
|
144
|
+
ruff check src/ --output-format=github
|
|
145
|
+
|
|
146
|
+
- name: Run black (formatting check)
|
|
147
|
+
run: |
|
|
148
|
+
black --check src/
|
|
149
|
+
|
|
150
|
+
- name: Run mypy (type checking)
|
|
151
|
+
continue-on-error: true # Scientific code often has complex types
|
|
152
|
+
run: |
|
|
153
|
+
mypy src/ --ignore-missing-imports
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
name: GPU Tests (Optional)
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch: # Manual trigger only
|
|
5
|
+
schedule:
|
|
6
|
+
# Run weekly on Sunday at 2am UTC (optional, can be removed)
|
|
7
|
+
- cron: '0 2 * * 0'
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
gpu-test:
|
|
11
|
+
runs-on: [self-hosted, gpu] # Requires GPU runner
|
|
12
|
+
# Alternative: use GitHub's beta GPU runners when available
|
|
13
|
+
# runs-on: ubuntu-latest-gpu
|
|
14
|
+
|
|
15
|
+
strategy:
|
|
16
|
+
fail-fast: false
|
|
17
|
+
matrix:
|
|
18
|
+
framework: [cupy, torch-gpu]
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- name: Checkout
|
|
22
|
+
uses: actions/checkout@v4
|
|
23
|
+
|
|
24
|
+
- name: Setup Python
|
|
25
|
+
uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.11"
|
|
28
|
+
|
|
29
|
+
- name: Check CUDA availability
|
|
30
|
+
run: |
|
|
31
|
+
nvidia-smi || echo "No NVIDIA GPU detected"
|
|
32
|
+
nvcc --version || echo "No CUDA compiler detected"
|
|
33
|
+
|
|
34
|
+
- name: Install base dependencies
|
|
35
|
+
run: |
|
|
36
|
+
python -m pip install --upgrade pip
|
|
37
|
+
pip install -e ".[dev]"
|
|
38
|
+
|
|
39
|
+
- name: Install CuPy
|
|
40
|
+
if: matrix.framework == 'cupy'
|
|
41
|
+
run: |
|
|
42
|
+
pip install cupy-cuda12x # Adjust CUDA version as needed
|
|
43
|
+
|
|
44
|
+
- name: Install PyTorch (GPU)
|
|
45
|
+
if: matrix.framework == 'torch-gpu'
|
|
46
|
+
run: |
|
|
47
|
+
pip install torch --index-url https://download.pytorch.org/whl/cu121
|
|
48
|
+
|
|
49
|
+
- name: Run GPU-specific tests
|
|
50
|
+
run: |
|
|
51
|
+
# Run only tests marked with @pytest.mark.gpu
|
|
52
|
+
pytest -v -m "gpu" --cov=arraybridge --cov-report=term-missing
|
|
53
|
+
continue-on-error: true # Don't fail the workflow if GPU tests fail
|
|
54
|
+
|
|
55
|
+
- name: Run framework-specific tests
|
|
56
|
+
run: |
|
|
57
|
+
# Run tests for the specific framework
|
|
58
|
+
pytest -v -m "${{ matrix.framework }}" --cov=arraybridge --cov-report=term-missing
|
|
59
|
+
continue-on-error: true
|
|
60
|
+
|
|
61
|
+
- name: Upload test results
|
|
62
|
+
if: always()
|
|
63
|
+
uses: actions/upload-artifact@v3
|
|
64
|
+
with:
|
|
65
|
+
name: gpu-test-results-${{ matrix.framework }}
|
|
66
|
+
path: |
|
|
67
|
+
htmlcov/
|
|
68
|
+
.coverage
|
|
69
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: write
|
|
10
|
+
id-token: write # Required for trusted publishing
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build-and-publish:
|
|
14
|
+
name: Build and publish to PyPI
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
environment:
|
|
17
|
+
name: pypi
|
|
18
|
+
url: https://pypi.org/p/arraybridge
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- name: Checkout code
|
|
22
|
+
uses: actions/checkout@v4
|
|
23
|
+
|
|
24
|
+
- name: Set up Python
|
|
25
|
+
uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.12"
|
|
28
|
+
|
|
29
|
+
- name: Install build dependencies
|
|
30
|
+
run: |
|
|
31
|
+
python -m pip install --upgrade pip
|
|
32
|
+
pip install build
|
|
33
|
+
|
|
34
|
+
- name: Build package
|
|
35
|
+
run: python -m build
|
|
36
|
+
|
|
37
|
+
- name: Check distribution
|
|
38
|
+
run: |
|
|
39
|
+
pip install twine
|
|
40
|
+
twine check dist/*
|
|
41
|
+
|
|
42
|
+
- name: Create GitHub Release
|
|
43
|
+
uses: softprops/action-gh-release@v2
|
|
44
|
+
with:
|
|
45
|
+
files: dist/*
|
|
46
|
+
generate_release_notes: true
|
|
47
|
+
env:
|
|
48
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
49
|
+
|
|
50
|
+
- name: Publish to PyPI
|
|
51
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
|
|
23
|
+
# Virtual environments
|
|
24
|
+
venv/
|
|
25
|
+
ENV/
|
|
26
|
+
env/
|
|
27
|
+
.venv
|
|
28
|
+
|
|
29
|
+
# Testing
|
|
30
|
+
.pytest_cache/
|
|
31
|
+
.coverage
|
|
32
|
+
htmlcov/
|
|
33
|
+
.tox/
|
|
34
|
+
|
|
35
|
+
# IDEs
|
|
36
|
+
.vscode/
|
|
37
|
+
.idea/
|
|
38
|
+
*.swp
|
|
39
|
+
*.swo
|
|
40
|
+
*~
|
|
41
|
+
|
|
42
|
+
# Documentation
|
|
43
|
+
docs/_build/
|
|
44
|
+
site/
|
|
45
|
+
|
|
46
|
+
# OS
|
|
47
|
+
.DS_Store
|
|
48
|
+
Thumbs.db
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Read the Docs configuration file for arraybridge
|
|
2
|
+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
|
3
|
+
|
|
4
|
+
# Required
|
|
5
|
+
version: 2
|
|
6
|
+
|
|
7
|
+
# Set the version of Python and other tools you might need
|
|
8
|
+
build:
|
|
9
|
+
os: ubuntu-22.04
|
|
10
|
+
tools:
|
|
11
|
+
python: "3.11"
|
|
12
|
+
jobs:
|
|
13
|
+
post_install:
|
|
14
|
+
# Install the package in editable mode
|
|
15
|
+
- pip install -e .
|
|
16
|
+
|
|
17
|
+
# Build documentation in the docs/source directory with Sphinx
|
|
18
|
+
sphinx:
|
|
19
|
+
configuration: docs/source/conf.py
|
|
20
|
+
fail_on_warning: false
|
|
21
|
+
|
|
22
|
+
# Optionally build your docs in additional formats such as PDF and ePub
|
|
23
|
+
formats:
|
|
24
|
+
- pdf
|
|
25
|
+
- epub
|
|
26
|
+
|
|
27
|
+
# Python configuration
|
|
28
|
+
python:
|
|
29
|
+
install:
|
|
30
|
+
- method: pip
|
|
31
|
+
path: .
|
|
32
|
+
extra_requirements:
|
|
33
|
+
- docs
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# CI Testing Improvements
|
|
2
|
+
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
This update restructures the CI testing strategy to eliminate GPU runner queue issues while maintaining comprehensive test coverage.
|
|
6
|
+
|
|
7
|
+
## Problems Solved
|
|
8
|
+
|
|
9
|
+
1. **CuPy Installation Failures**: CuPy requires CUDA drivers and cannot be installed on standard CI runners
|
|
10
|
+
2. **GPU Runner Queue Times**: Beta GPU runners have long queue times, blocking PR feedback
|
|
11
|
+
3. **Inefficient Test Matrix**: Too many redundant test combinations
|
|
12
|
+
4. **Unclear Test Organization**: No markers to distinguish CPU vs GPU tests
|
|
13
|
+
|
|
14
|
+
## Changes Made
|
|
15
|
+
|
|
16
|
+
### 1. Updated CI Workflow (`.github/workflows/ci.yml`)
|
|
17
|
+
|
|
18
|
+
**Before:**
|
|
19
|
+
- Matrix included `cupy` framework option
|
|
20
|
+
- Tried to install CuPy on standard runners (always failed)
|
|
21
|
+
- Tested on Python 3.9-3.12 across all OS combinations
|
|
22
|
+
- 36+ job combinations
|
|
23
|
+
|
|
24
|
+
**After:**
|
|
25
|
+
- Removed `cupy` from standard CI matrix
|
|
26
|
+
- Reduced Python versions to 3.10-3.12 (dropped 3.9)
|
|
27
|
+
- Simplified matrix: torch tests only on Ubuntu
|
|
28
|
+
- GPU tests marked as `continue-on-error: true` (non-blocking)
|
|
29
|
+
- **Result**: ~12 fast jobs on standard runners + 1 optional GPU job
|
|
30
|
+
|
|
31
|
+
### 2. Added Pytest Markers (`pyproject.toml`)
|
|
32
|
+
|
|
33
|
+
New markers for test organization:
|
|
34
|
+
- `@pytest.mark.gpu` - Requires actual GPU hardware
|
|
35
|
+
- `@pytest.mark.cupy` - Requires CuPy framework
|
|
36
|
+
- `@pytest.mark.torch` - Requires PyTorch framework
|
|
37
|
+
- `@pytest.mark.tensorflow` - Requires TensorFlow
|
|
38
|
+
- `@pytest.mark.jax` - Requires JAX
|
|
39
|
+
- `@pytest.mark.pyclesperanto` - Requires pyclesperanto
|
|
40
|
+
- `@pytest.mark.slow` - Long-running tests
|
|
41
|
+
|
|
42
|
+
### 3. Enhanced Test Fixtures (`tests/conftest.py`)
|
|
43
|
+
|
|
44
|
+
- Added `pytest_configure()` to register markers
|
|
45
|
+
- Improved `cupy_available` fixture to verify GPU access
|
|
46
|
+
- Added `gpu_available` fixture for general GPU detection
|
|
47
|
+
- Better error handling for framework imports
|
|
48
|
+
|
|
49
|
+
### 4. Marked Framework-Specific Tests
|
|
50
|
+
|
|
51
|
+
Added `@pytest.mark.torch` to PyTorch tests in `test_converters.py`:
|
|
52
|
+
- `test_detect_torch_tensor`
|
|
53
|
+
- `test_convert_numpy_to_torch`
|
|
54
|
+
- `test_convert_torch_to_numpy`
|
|
55
|
+
- `test_round_trip_conversion_numpy_torch`
|
|
56
|
+
|
|
57
|
+
### 5. Created Optional GPU Workflow (`.github/workflows/gpu-tests.yml`)
|
|
58
|
+
|
|
59
|
+
Separate workflow for GPU testing:
|
|
60
|
+
- Manual trigger only (`workflow_dispatch`)
|
|
61
|
+
- Optional weekly schedule
|
|
62
|
+
- Runs on self-hosted or beta GPU runners
|
|
63
|
+
- Tests CuPy and PyTorch GPU functionality
|
|
64
|
+
- Non-blocking (failures don't block PRs)
|
|
65
|
+
|
|
66
|
+
### 6. Documentation (`TESTING.md`)
|
|
67
|
+
|
|
68
|
+
Comprehensive testing guide covering:
|
|
69
|
+
- Test categories (CPU vs GPU)
|
|
70
|
+
- Running tests locally
|
|
71
|
+
- Using pytest markers
|
|
72
|
+
- CI workflow explanation
|
|
73
|
+
- Adding new tests
|
|
74
|
+
- Coverage goals
|
|
75
|
+
|
|
76
|
+
## Test Results
|
|
77
|
+
|
|
78
|
+
### Without PyTorch (NumPy only)
|
|
79
|
+
```
|
|
80
|
+
61 passed, 4 deselected
|
|
81
|
+
Coverage: 33%
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### With PyTorch CPU
|
|
85
|
+
```
|
|
86
|
+
65 passed
|
|
87
|
+
Coverage: ~35%
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Test Breakdown
|
|
91
|
+
- **CPU-compatible tests**: 61 tests (run on every PR)
|
|
92
|
+
- **PyTorch tests**: 4 tests (run on Ubuntu with torch-cpu)
|
|
93
|
+
- **GPU tests**: 0 currently (would run on GPU runners when available)
|
|
94
|
+
|
|
95
|
+
## Benefits
|
|
96
|
+
|
|
97
|
+
### ✅ Fast CI Feedback
|
|
98
|
+
- Standard tests complete in ~2-3 minutes
|
|
99
|
+
- No waiting in GPU runner queues
|
|
100
|
+
- Immediate feedback on PRs
|
|
101
|
+
|
|
102
|
+
### ✅ Cost Efficiency
|
|
103
|
+
- Uses free standard runners for 99% of tests
|
|
104
|
+
- GPU runners only used when needed
|
|
105
|
+
- Reduced total CI minutes
|
|
106
|
+
|
|
107
|
+
### ✅ Better Test Organization
|
|
108
|
+
- Clear markers for test categories
|
|
109
|
+
- Easy to run specific test subsets
|
|
110
|
+
- Better documentation
|
|
111
|
+
|
|
112
|
+
### ✅ Comprehensive Coverage
|
|
113
|
+
- Core conversion logic tested on CPU
|
|
114
|
+
- PyTorch CPU tests validate API
|
|
115
|
+
- Optional GPU tests for real hardware validation
|
|
116
|
+
|
|
117
|
+
### ✅ Non-Blocking GPU Tests
|
|
118
|
+
- GPU test failures don't block PRs
|
|
119
|
+
- Can investigate GPU issues separately
|
|
120
|
+
- Flexibility for GPU runner availability
|
|
121
|
+
|
|
122
|
+
## Migration Guide
|
|
123
|
+
|
|
124
|
+
### For Developers
|
|
125
|
+
|
|
126
|
+
**Running tests locally:**
|
|
127
|
+
```bash
|
|
128
|
+
# CPU tests only (fast)
|
|
129
|
+
pytest -m "not gpu"
|
|
130
|
+
|
|
131
|
+
# With PyTorch CPU
|
|
132
|
+
pip install torch --index-url https://download.pytorch.org/whl/cpu
|
|
133
|
+
pytest
|
|
134
|
+
|
|
135
|
+
# With GPU frameworks (requires CUDA)
|
|
136
|
+
pip install cupy-cuda12x
|
|
137
|
+
pytest -m gpu
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Adding new tests:**
|
|
141
|
+
```python
|
|
142
|
+
# CPU-compatible test (no marker needed)
|
|
143
|
+
def test_my_feature():
|
|
144
|
+
pass
|
|
145
|
+
|
|
146
|
+
# Framework-specific test
|
|
147
|
+
@pytest.mark.torch
|
|
148
|
+
def test_torch_feature(torch_available):
|
|
149
|
+
if not torch_available:
|
|
150
|
+
pytest.skip("PyTorch not available")
|
|
151
|
+
# test code
|
|
152
|
+
|
|
153
|
+
# GPU-only test
|
|
154
|
+
@pytest.mark.gpu
|
|
155
|
+
@pytest.mark.cupy
|
|
156
|
+
def test_gpu_feature(cupy_available, gpu_available):
|
|
157
|
+
if not cupy_available or not gpu_available:
|
|
158
|
+
pytest.skip("GPU not available")
|
|
159
|
+
# test code
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### For CI/CD
|
|
163
|
+
|
|
164
|
+
**Standard CI (automatic):**
|
|
165
|
+
- Runs on every PR and push to main
|
|
166
|
+
- Tests NumPy + PyTorch CPU
|
|
167
|
+
- Fast feedback (~2-3 minutes)
|
|
168
|
+
- Must pass for PR merge
|
|
169
|
+
|
|
170
|
+
**GPU CI (optional):**
|
|
171
|
+
- Manual trigger via Actions tab
|
|
172
|
+
- Or weekly schedule
|
|
173
|
+
- Non-blocking (can fail without blocking PRs)
|
|
174
|
+
- Use for validating GPU-specific features
|
|
175
|
+
|
|
176
|
+
## Future Improvements
|
|
177
|
+
|
|
178
|
+
1. **Mock GPU Frameworks**: Add mocking for GPU frameworks to test API without hardware
|
|
179
|
+
2. **Performance Benchmarks**: Add benchmarks for conversion operations
|
|
180
|
+
3. **Integration Tests**: Real-world scientific workflow tests
|
|
181
|
+
4. **Coverage Goals**: Increase coverage to 80%+ for core modules
|
|
182
|
+
|
|
183
|
+
## Rollback Plan
|
|
184
|
+
|
|
185
|
+
If issues arise, revert to previous CI by:
|
|
186
|
+
1. Restore original `.github/workflows/ci.yml`
|
|
187
|
+
2. Remove pytest markers (optional, won't break anything)
|
|
188
|
+
3. Tests will still work, just with less organization
|
|
189
|
+
|
|
190
|
+
## Questions?
|
|
191
|
+
|
|
192
|
+
See `TESTING.md` for detailed testing documentation.
|
|
193
|
+
|