Refactor: Replace if-elif chain with optimizer config dict #6
Workflow file for this run
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
| name: Test Benchmark Refactoring | |
| on: | |
| push: | |
| branches: [ refactor-optimizer-selection ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test-refactoring: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: [3.8, 3.9, '3.10', 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 dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install numpy | |
| pip install -e . | |
| - name: Run syntax check | |
| run: | | |
| python -m py_compile tutorials/benchmarking_lsbbo_2.py | |
| - name: Test optimizer loading | |
| run: | | |
| python -c " | |
| import sys | |
| sys.path.append('tutorials') | |
| from benchmarking_lsbbo_2 import get_optimizer_class, OPTIMIZER_CONFIGS | |
| # Test a few optimizers | |
| test_optimizers = ['CMAES', 'PRS', 'JADE'] | |
| for opt in test_optimizers: | |
| try: | |
| cls = get_optimizer_class(opt) | |
| print(f'✓ {opt}: {cls.__name__}') | |
| except Exception as e: | |
| print(f'✗ {opt}: {e}') | |
| sys.exit(1) | |
| print(f'Total optimizers configured: {len(OPTIMIZER_CONFIGS)}') | |
| " | |
| - name: Test argument validation | |
| run: | | |
| python tutorials/benchmarking_lsbbo_2.py --help | |
| - name: Test invalid optimizer | |
| run: | | |
| python tutorials/benchmarking_lsbbo_2.py --start 0 --end 0 --optimizer INVALID --ndim_problem 10 || echo "Expected failure for invalid optimizer" | |
| - name: Quick integration test | |
| run: | | |
| timeout 60 python tutorials/benchmarking_lsbbo_2.py \ | |
| --start 0 --end 0 --optimizer CMAES --ndim_problem 2 || true | |
| code-quality: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install linting tools | |
| run: | | |
| pip install flake8 | |
| - name: Lint with flake8 | |
| run: flake8 tutorials/benchmarking_lsbbo_2.py --max-line-length=100 --ignore=E501,W503 |