update docs req. #150
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Surfaces CI/CD Pipeline | |
| # Tests package with minimal and full dependencies across multiple Python versions and OSes | |
| name: tests | |
| on: | |
| push: | |
| branches: [main, dev] | |
| pull_request: | |
| branches: [main] | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| # =========================================================================== | |
| # Stage 1: Code Quality (Fast, runs first) | |
| # =========================================================================== | |
| code-quality: | |
| name: Code Quality | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install pre-commit | |
| run: pip install pre-commit | |
| - name: Run pre-commit | |
| run: pre-commit run --all-files | |
| # =========================================================================== | |
| # Stage 2: Test with Minimal Dependencies (Core functionality) | |
| # =========================================================================== | |
| test-minimal: | |
| name: Test Minimal (Py ${{ matrix.python-version }}, ${{ matrix.os }}) | |
| needs: code-quality | |
| runs-on: ${{ matrix.os }} | |
| defaults: | |
| run: | |
| shell: bash | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
| os: [ubuntu-latest] | |
| include: | |
| # Also test on macOS and Windows with one Python version | |
| - os: macos-latest | |
| python-version: "3.11" | |
| - os: windows-latest | |
| python-version: "3.11" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install minimal dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e ".[test-minimal]" | |
| - name: Verify minimal install (no sklearn, no viz) | |
| run: | | |
| python -c " | |
| import surfaces | |
| print(f'Surfaces version: {surfaces.__version__}') | |
| # These should work (numpy only) | |
| from surfaces.test_functions import SphereFunction, AckleyFunction | |
| from surfaces.test_functions import ThreeBarTrussFunction | |
| from surfaces.test_functions import algebraic_functions, engineering_functions | |
| print(f'Algebraic functions: {len(algebraic_functions)}') | |
| print(f'Engineering functions: {len(engineering_functions)}') | |
| # Verify math functions work | |
| sphere = SphereFunction(n_dim=2) | |
| result = sphere({'x0': 0, 'x1': 0}) | |
| assert result == 0, f'Expected 0, got {result}' | |
| print('Core functionality verified!') | |
| " | |
| - name: Test algebraic and engineering functions | |
| run: python -m pytest -x -p no:warnings tests/test_1d_functions.py tests/test_2d_functions.py tests/test_nd_functions.py tests/test_all_test_functions.py tests/test_api/test_input_type.py tests/test_api/test_metric.py tests/test_api/test_sleep.py | |
| # =========================================================================== | |
| # Stage 3: Test with Full Dependencies | |
| # =========================================================================== | |
| test-full: | |
| name: Test Full (Py ${{ matrix.python-version }}, ${{ matrix.os }}) | |
| needs: code-quality | |
| runs-on: ${{ matrix.os }} | |
| defaults: | |
| run: | |
| shell: bash | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
| os: [ubuntu-latest] | |
| include: | |
| - os: macos-latest | |
| python-version: "3.11" | |
| - os: windows-latest | |
| python-version: "3.11" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install full dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e ".[test]" | |
| - name: Verify full install | |
| run: | | |
| python -c " | |
| import surfaces | |
| from surfaces.test_functions import ( | |
| algebraic_functions, | |
| machine_learning_functions, | |
| engineering_functions, | |
| ) | |
| print(f'Algebraic: {len(algebraic_functions)}') | |
| print(f'ML: {len(machine_learning_functions)}') | |
| print(f'Engineering: {len(engineering_functions)}') | |
| assert len(machine_learning_functions) > 0, 'ML functions not available' | |
| print('Full installation verified!') | |
| " | |
| - name: Run all tests | |
| run: python -m pytest -x -p no:warnings tests/ | |
| # =========================================================================== | |
| # Stage 3b: Integration Tests with Optimization Libraries | |
| # =========================================================================== | |
| test-integrations: | |
| name: Integration Tests (Py ${{ matrix.python-version }}) | |
| needs: code-quality | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: ["3.10", "3.11", "3.12"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e ".[full]" | |
| pip install pytest pytest-cov | |
| pip install gradient-free-optimizers | |
| pip install optuna | |
| pip install scipy | |
| - name: Test with Gradient-Free-Optimizers | |
| run: | | |
| python -m pytest -x -p no:warnings \ | |
| tests/test_optimization.py \ | |
| tests/test_api/test_search_space.py | |
| - name: Test with Optuna | |
| run: | | |
| python -c " | |
| import optuna | |
| from surfaces.test_functions import SphereFunction, AckleyFunction | |
| # Test Sphere with Optuna | |
| sphere = SphereFunction(n_dim=2) | |
| def objective(trial): | |
| x0 = trial.suggest_float('x0', -5, 5) | |
| x1 = trial.suggest_float('x1', -5, 5) | |
| return sphere({'x0': x0, 'x1': x1}) | |
| study = optuna.create_study(direction='minimize') | |
| study.optimize(objective, n_trials=20, show_progress_bar=False) | |
| print(f'Optuna best value: {study.best_value:.6f}') | |
| assert study.best_value < 1.0, f'Optuna optimization failed: {study.best_value}' | |
| print('Optuna integration verified!') | |
| " | |
| - name: Test with Scipy | |
| run: | | |
| python -c " | |
| import numpy as np | |
| from scipy.optimize import minimize, differential_evolution | |
| from surfaces.test_functions import SphereFunction, RosenbrockFunction | |
| # Test Sphere with scipy.minimize | |
| sphere = SphereFunction(n_dim=2) | |
| def sphere_scipy(x): | |
| return sphere({'x0': x[0], 'x1': x[1]}) | |
| result = minimize(sphere_scipy, x0=[1.0, 1.0], method='Nelder-Mead') | |
| print(f'Scipy minimize result: {result.fun:.6f}') | |
| assert result.fun < 0.01, f'Scipy minimize failed: {result.fun}' | |
| # Test with differential evolution | |
| bounds = [(-5, 5), (-5, 5)] | |
| result_de = differential_evolution(sphere_scipy, bounds, maxiter=50, seed=42) | |
| print(f'Scipy DE result: {result_de.fun:.6f}') | |
| assert result_de.fun < 0.01, f'Scipy DE failed: {result_de.fun}' | |
| print('Scipy integration verified!') | |
| " | |
| # =========================================================================== | |
| # Stage 4: Coverage (only on Ubuntu, Python 3.11) | |
| # =========================================================================== | |
| coverage: | |
| name: Coverage | |
| needs: [test-minimal, test-full] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e ".[test]" | |
| - name: Run tests with coverage | |
| run: | | |
| python -m pytest tests/ \ | |
| --cov=surfaces \ | |
| --cov-report=term-missing \ | |
| --cov-report=xml \ | |
| -p no:warnings | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| files: ./coverage.xml | |
| fail_ci_if_error: false | |
| verbose: true |