|
93 | 93 | tests/test_1d_functions.py \ |
94 | 94 | tests/test_2d_functions.py \ |
95 | 95 | tests/test_nd_functions.py \ |
96 | | - tests/test_api/ |
| 96 | + tests/test_all_test_functions.py \ |
| 97 | + tests/test_api/test_input_type.py \ |
| 98 | + tests/test_api/test_metric.py \ |
| 99 | + tests/test_api/test_sleep.py |
97 | 100 |
|
98 | 101 | # =========================================================================== |
99 | 102 | # Stage 3: Test with Full Dependencies |
@@ -145,6 +148,89 @@ jobs: |
145 | 148 | - name: Run all tests |
146 | 149 | run: python -m pytest -x -p no:warnings tests/ |
147 | 150 |
|
| 151 | + # =========================================================================== |
| 152 | + # Stage 3b: Integration Tests with Optimization Libraries |
| 153 | + # =========================================================================== |
| 154 | + test-integrations: |
| 155 | + name: Integration Tests (Py ${{ matrix.python-version }}) |
| 156 | + needs: code-quality |
| 157 | + runs-on: ubuntu-latest |
| 158 | + strategy: |
| 159 | + fail-fast: false |
| 160 | + matrix: |
| 161 | + python-version: ["3.10", "3.11", "3.12"] |
| 162 | + |
| 163 | + steps: |
| 164 | + - uses: actions/checkout@v4 |
| 165 | + |
| 166 | + - name: Set up Python ${{ matrix.python-version }} |
| 167 | + uses: actions/setup-python@v5 |
| 168 | + with: |
| 169 | + python-version: ${{ matrix.python-version }} |
| 170 | + |
| 171 | + - name: Install dependencies |
| 172 | + run: | |
| 173 | + python -m pip install --upgrade pip |
| 174 | + pip install -e ".[full]" |
| 175 | + pip install pytest pytest-cov |
| 176 | + pip install gradient-free-optimizers |
| 177 | + pip install optuna |
| 178 | + pip install scipy |
| 179 | +
|
| 180 | + - name: Test with Gradient-Free-Optimizers |
| 181 | + run: | |
| 182 | + python -m pytest -x -p no:warnings \ |
| 183 | + tests/test_optimization.py \ |
| 184 | + tests/test_api/test_search_space.py |
| 185 | +
|
| 186 | + - name: Test with Optuna |
| 187 | + run: | |
| 188 | + python -c " |
| 189 | + import optuna |
| 190 | + from surfaces.test_functions import SphereFunction, AckleyFunction |
| 191 | +
|
| 192 | + # Test Sphere with Optuna |
| 193 | + sphere = SphereFunction(n_dim=2) |
| 194 | +
|
| 195 | + def objective(trial): |
| 196 | + x0 = trial.suggest_float('x0', -5, 5) |
| 197 | + x1 = trial.suggest_float('x1', -5, 5) |
| 198 | + return sphere({'x0': x0, 'x1': x1}) |
| 199 | +
|
| 200 | + study = optuna.create_study(direction='minimize') |
| 201 | + study.optimize(objective, n_trials=20, show_progress_bar=False) |
| 202 | +
|
| 203 | + print(f'Optuna best value: {study.best_value:.6f}') |
| 204 | + assert study.best_value < 1.0, f'Optuna optimization failed: {study.best_value}' |
| 205 | + print('Optuna integration verified!') |
| 206 | + " |
| 207 | +
|
| 208 | + - name: Test with Scipy |
| 209 | + run: | |
| 210 | + python -c " |
| 211 | + import numpy as np |
| 212 | + from scipy.optimize import minimize, differential_evolution |
| 213 | + from surfaces.test_functions import SphereFunction, RosenbrockFunction |
| 214 | +
|
| 215 | + # Test Sphere with scipy.minimize |
| 216 | + sphere = SphereFunction(n_dim=2) |
| 217 | +
|
| 218 | + def sphere_scipy(x): |
| 219 | + return sphere({'x0': x[0], 'x1': x[1]}) |
| 220 | +
|
| 221 | + result = minimize(sphere_scipy, x0=[1.0, 1.0], method='Nelder-Mead') |
| 222 | + print(f'Scipy minimize result: {result.fun:.6f}') |
| 223 | + assert result.fun < 0.01, f'Scipy minimize failed: {result.fun}' |
| 224 | +
|
| 225 | + # Test with differential evolution |
| 226 | + bounds = [(-5, 5), (-5, 5)] |
| 227 | + result_de = differential_evolution(sphere_scipy, bounds, maxiter=50, seed=42) |
| 228 | + print(f'Scipy DE result: {result_de.fun:.6f}') |
| 229 | + assert result_de.fun < 0.01, f'Scipy DE failed: {result_de.fun}' |
| 230 | +
|
| 231 | + print('Scipy integration verified!') |
| 232 | + " |
| 233 | +
|
148 | 234 | # =========================================================================== |
149 | 235 | # Stage 4: Coverage (only on Ubuntu, Python 3.11) |
150 | 236 | # =========================================================================== |
|
0 commit comments