|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, ci-testing ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + lint: |
| 16 | + name: Code Formatting Check |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Python |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: "3.11" |
| 25 | + cache: 'pip' |
| 26 | + |
| 27 | + - name: Install yapf |
| 28 | + run: | |
| 29 | + python -m pip install --upgrade pip |
| 30 | + pip install yapf==0.32.0 |
| 31 | + pip install toml |
| 32 | + |
| 33 | + - name: Check format with YAPF |
| 34 | + run: | |
| 35 | + yapf --style=google -d -r . |
| 36 | +
|
| 37 | + test: |
| 38 | + name: Test Python ${{ matrix.python-version }} |
| 39 | + runs-on: ubuntu-latest |
| 40 | + strategy: |
| 41 | + fail-fast: false |
| 42 | + matrix: |
| 43 | + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] |
| 44 | + |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v4 |
| 47 | + |
| 48 | + - name: Set up Python ${{ matrix.python-version }} |
| 49 | + uses: actions/setup-python@v5 |
| 50 | + with: |
| 51 | + python-version: ${{ matrix.python-version }} |
| 52 | + cache: 'pip' |
| 53 | + |
| 54 | + - name: Install dependencies |
| 55 | + run: | |
| 56 | + python -m pip install --upgrade pip |
| 57 | + pip install -e . pytest pytest-cov pytest-xdist |
| 58 | + |
| 59 | + - name: Run tests |
| 60 | + run: | |
| 61 | + pytest -rA -n auto --cov=pysa --cov-report=xml --cov-report=term tests/ |
| 62 | + |
| 63 | + - name: Upload coverage to artifact |
| 64 | + if: matrix.python-version == '3.11' |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + with: |
| 67 | + name: coverage-report |
| 68 | + path: coverage.xml |
| 69 | + retention-days: 7 |
| 70 | + |
| 71 | + coverage: |
| 72 | + name: Upload Coverage |
| 73 | + needs: test |
| 74 | + runs-on: ubuntu-latest |
| 75 | + if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' |
| 76 | + steps: |
| 77 | + - uses: actions/checkout@v4 |
| 78 | + |
| 79 | + - name: Download coverage report |
| 80 | + uses: actions/download-artifact@v4 |
| 81 | + with: |
| 82 | + name: coverage-report |
| 83 | + |
| 84 | + - name: Upload coverage to Codecov |
| 85 | + uses: codecov/codecov-action@v4 |
| 86 | + with: |
| 87 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 88 | + file: ./coverage.xml |
| 89 | + flags: unittests |
| 90 | + name: codecov-umbrella |
| 91 | + fail_ci_if_error: false |
| 92 | + continue-on-error: true |
| 93 | + |
| 94 | + examples: |
| 95 | + name: Examples Python ${{ matrix.python-version }} |
| 96 | + runs-on: ubuntu-latest |
| 97 | + needs: test |
| 98 | + strategy: |
| 99 | + fail-fast: false |
| 100 | + matrix: |
| 101 | + python-version: ["3.9", "3.11"] |
| 102 | + |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + |
| 106 | + - name: Set up Python ${{ matrix.python-version }} |
| 107 | + uses: actions/setup-python@v5 |
| 108 | + with: |
| 109 | + python-version: ${{ matrix.python-version }} |
| 110 | + cache: 'pip' |
| 111 | + |
| 112 | + - name: Install dependencies |
| 113 | + run: | |
| 114 | + python -m pip install --upgrade pip |
| 115 | + pip install -e . termplotlib |
| 116 | + |
| 117 | + - name: Run examples |
| 118 | + run: | |
| 119 | + python examples/example_ising.py |
| 120 | + python examples/example_qubo.py |
| 121 | + python examples/example_ais.py |
| 122 | +
|
| 123 | + tutorials: |
| 124 | + name: Tutorials Python ${{ matrix.python-version }} |
| 125 | + runs-on: ubuntu-latest |
| 126 | + needs: test |
| 127 | + strategy: |
| 128 | + fail-fast: false |
| 129 | + matrix: |
| 130 | + python-version: ["3.9", "3.11"] |
| 131 | + |
| 132 | + steps: |
| 133 | + - uses: actions/checkout@v4 |
| 134 | + |
| 135 | + - name: Set up Python ${{ matrix.python-version }} |
| 136 | + uses: actions/setup-python@v5 |
| 137 | + with: |
| 138 | + python-version: ${{ matrix.python-version }} |
| 139 | + cache: 'pip' |
| 140 | + |
| 141 | + - name: Install dependencies |
| 142 | + run: | |
| 143 | + python -m pip install --upgrade pip |
| 144 | + pip install -e . papermill matplotlib plotly jupyter hyperopt torch torchvision |
| 145 | + |
| 146 | + - name: Run tutorials |
| 147 | + run: | |
| 148 | + cd tutorials/ |
| 149 | + papermill example_ising.ipynb output_example_ising.ipynb || true |
| 150 | + papermill hpo_demo.ipynb output_hpo_demo.ipynb || true |
| 151 | + papermill ising_tutorial.ipynb output_ising_tutorial.ipynb || true |
| 152 | + papermill RBM_tutorial.ipynb output_RBM_tutorial.ipynb || true |
| 153 | + |
| 154 | + - name: Upload tutorial outputs |
| 155 | + if: always() |
| 156 | + uses: actions/upload-artifact@v4 |
| 157 | + with: |
| 158 | + name: tutorial-outputs-py${{ matrix.python-version }} |
| 159 | + path: tutorials/output_*.ipynb |
| 160 | + retention-days: 7 |
| 161 | + continue-on-error: true |
| 162 | + |
| 163 | + all-checks-passed: |
| 164 | + name: All Checks Passed |
| 165 | + needs: [lint, test, examples, tutorials] |
| 166 | + runs-on: ubuntu-latest |
| 167 | + if: always() |
| 168 | + steps: |
| 169 | + - name: Check if all jobs passed |
| 170 | + run: | |
| 171 | + if [[ "${{ needs.lint.result }}" != "success" ]] || \ |
| 172 | + [[ "${{ needs.test.result }}" != "success" ]] || \ |
| 173 | + [[ "${{ needs.examples.result }}" != "success" ]] || \ |
| 174 | + [[ "${{ needs.tutorials.result }}" != "success" ]]; then |
| 175 | + echo "One or more jobs failed" |
| 176 | + exit 1 |
| 177 | + fi |
| 178 | + echo "All checks passed successfully!" |
0 commit comments