Debian Codegraph @

.github/workflows/tests.yml

raw symbols SCIP
1 # The name is short because we mostly care how it appears in the pull request
2 # "checks" dialogue box - it looks like
3 # Tests / ubuntu-latest, python-3.9, defaults
4 # or similar.
5 name: Tests
6
7 on:
8 [push, pull_request]
9 concurrency:
10 group: test_${{ github.ref }}
11 cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
12
13 defaults:
14 run:
15 # The slightly odd shell call is to force bash to read .bashrc, which is
16 # necessary for having conda behave sensibly. We use bash as the shell even
17 # on Windows, since we don't run anything much complicated, and it makes
18 # things much simpler.
19 shell: bash -l -e {0}
20
21 jobs:
22 cases:
23 name: ${{ matrix.os }}, python${{ matrix.python-version }}, ${{ matrix.case-name }}
24 runs-on: ${{ matrix.os }}
25 env:
26 MPLBACKEND: Agg # Explicitly define matplotlib backend for Windows tests
27 strategy:
28 fail-fast: false
29 matrix:
30 os: [ubuntu-latest]
31 # Test other versions of Python in special cases to avoid exploding the
32 # matrix size; make sure to test all supported versions in some form.
33 python-version: ["3.14"]
34 case-name: ["python 3.14 - Latest"]
35 condaforge: [1]
36 numpy-build: [""]
37 numpy-requirement: [""]
38 scipy-requirement: [">=1.9"]
39 coverage-requirement: ["==6.5"]
40 pytest-extra-options: ["-W ignore:Matrix:scipy.linalg._misc.LinAlgWarning"]
41 # Extra special cases. In these, the new variable defined should always
42 # be a truth-y value (hence 'nomkl: 1' rather than 'mkl: 0'), because
43 # the lack of a variable is _always_ false-y, and the defaults lack all
44 # the special cases.
45 include:
46 - case-name: p313 numpy 2
47 os: ubuntu-latest
48 python-version: "3.13"
49 numpy-build: ">=2.2.0,<2.3.0"
50 numpy-requirement: ">=2.2.0,<2.3.0"
51 scipy-requirement: ">=1.15,<1.16"
52 pypi: 1
53 # Install mpi4py to test mpi_pmap
54 # Should be enough to include this in one of the runs
55 includempi: 1
56
57 - case-name: p314 ubuntu arm
58 os: ubuntu-24.04-arm
59 python-version: "3.14"
60 numpy-build: ">=2.2.0"
61 numpy-requirement: ">=2.2.0"
62 pypi: 1
63 # Install mpi4py to test mpi_pmap
64 # Should be enough to include this in one of the runs
65 includempi: 1
66
67 - case-name: p312, numpy fallback
68 os: ubuntu-latest
69 python-version: "3.12"
70 numpy-build: ">=2.1.0,<2.2.0"
71 numpy-requirement: ">=1.26,<1.27"
72 scipy-requirement: ">=1.11,<1.12"
73 pypi: 1
74 oldmpl: 1
75 coveralls: 1
76 nomkl: 1
77
78 - case-name: Oldest officially supported
79 os: ubuntu-latest
80 python-version: "3.11"
81 numpy-build: ">=1.22.0,<1.23.0"
82 numpy-requirement: ">=1.22.0,<1.23.0"
83 scipy-requirement: ">=1.9,<1.10"
84 semidefinite: 1
85 oldcython: 1
86 oldmpl: 1
87 pypi: 1
88 coveralls: 1
89 pytest-extra-options: "-W ignore:dep_util:DeprecationWarning -W \"ignore:The 'renderer' parameter of do_3d_projection\""
90
91 # Mac
92 # Mac has issues with MKL since september 2022.
93 - case-name: macos
94 os: macos-latest
95 python-version: "3.14"
96 numpy-build: ">=2.0.0"
97 numpy-requirement: ">=2.0.0"
98 condaforge: 1
99 nomkl: 1
100 pytest-extra-options: "-W ignore:Matrix:scipy.linalg._misc.LinAlgWarning"
101
102 - case-name: macos - numpy fallback
103 os: macos-15-intel # Test on intel cpus
104 python-version: "3.11"
105 numpy-build: ">=2.0.0"
106 numpy-requirement: ">=1.25,<1.26"
107 scipy-requirement: "==1.16.*"
108 condaforge: 1
109 nomkl: 1
110 coveralls: 1
111 pytest-extra-options: "-W ignore:Matrix:scipy.linalg._misc.LinAlgWarning"
112
113 - case-name: Windows
114 os: windows-11-arm
115 python-version: "3.14"
116 numpy-build: ">=2.0.0"
117 numpy-requirement: ">=2.0.0"
118 pypi: 1
119 pytest-extra-options: "-W ignore:Matrix:scipy.linalg._misc.LinAlgWarning"
120
121 - case-name: Windows - numpy fallback
122 os: windows-latest
123 python-version: "3.11"
124 numpy-build: ">=2.0.0"
125 numpy-requirement: ">=1.24,<1.25"
126 semidefinite: 1
127 oldmpl: 1
128 nocython: 1
129 condaforge: 1
130 nomkl: 1
131 coveralls: 1
132 pytest-extra-options: "-W ignore:dep_util:DeprecationWarning -W \"ignore:The 'renderer' parameter of do_3d_projection\""
133
134 steps:
135 - uses: actions/checkout@v6
136 - uses: conda-incubator/setup-miniconda@v4
137 if: matrix.os != 'windows-11-arm'
138 # Currently miniconda doesn't support window-11 arms
139 with:
140 auto-update-conda: true
141 python-version: ${{ matrix.python-version }}
142 channels: ${{ matrix.condaforge == 1 && 'conda-forge' || 'defaults' }}
143
144 - name: Install pip
145 if: matrix.os != 'windows-11-arm'
146 shell: bash -l {0}
147 run: conda install pip -y -n test
148
149 # TODO remove this once conda supports windows arm
150 - uses: actions/setup-python@v6
151 if: matrix.os == 'windows-11-arm'
152 with:
153 python-version: ${{ matrix.python-version }}
154
155 - name: Install QuTiP and dependencies
156 # In the run, first we handle any special cases. We do this in bash
157 # rather than in the GitHub Actions file directly, because bash gives us
158 # a proper programming language to use.
159 # We install without build isolation so qutip is compiled with the
160 # version of cython, scipy, numpy in the test matrix, not a temporary
161 # version use in the installation virtual environment.
162 run: |
163 # Install the extra requirement
164 python -m pip install pytest>=5.2 pytest-rerunfailures # tests
165 python -m pip install ipython # ipython
166 python -m pip install loky!=3.5.0 tqdm mpmath # extras
167 python -m pip install "coverage${{ matrix.coverage-requirement }}" chardet
168 python -m pip install pytest-cov coveralls pytest-fail-slow
169 python -m pip install setuptools
170
171 if [[ "${{ matrix.pypi }}" ]]; then
172 pip install "numpy${{ matrix.numpy-build }}"
173 pip install "scipy${{ matrix.scipy-requirement }}"
174 elif [[ -z "${{ matrix.nomkl }}" ]]; then
175 conda install blas=*=mkl "numpy${{ matrix.numpy-build }}" "scipy${{ matrix.scipy-requirement }}"
176 elif [[ "${{ matrix.os }}" =~ ^windows.*$ ]]; then
177 # Conda doesn't supply forced nomkl builds on Windows, so we rely on
178 # pip not automatically linking to MKL.
179 pip install "numpy${{ matrix.numpy-build }}" "scipy${{ matrix.scipy-requirement }}"
180 else
181 conda install nomkl "numpy${{ matrix.numpy-build }}" "scipy${{ matrix.scipy-requirement }}"
182 fi
183 if [[ -n "${{ matrix.conda-extra-pkgs }}" ]]; then
184 conda install "${{ matrix.conda-extra-pkgs }}"
185 fi
186 if [[ "${{ matrix.includempi }}" ]]; then
187 # Both mpich and openmpi version 4 have caused problems in the past
188 # so we use openmpi version 5. Openmpi 5 and python 3.13-compatible
189 # version of mpi4py are currently only available on conda-forge:
190 conda install --channel conda-forge "openmpi>=5.0" mpi4py
191 fi
192 if [[ "${{ matrix.oldcython }}" ]]; then
193 python -m pip install cython==0.29.36 filelock matplotlib==3.6
194 else
195 python -m pip install cython filelock
196 fi
197
198 python -m pip install -e . -v --no-build-isolation
199
200 if [[ "${{ matrix.nocython }}" ]]; then
201 python -m pip uninstall cython -y
202 fi
203
204 if [[ "${{ matrix.pypi }}" ]]; then
205 python -m pip install "numpy${{ matrix.numpy-requirement }}"
206 elif [[ -z "${{ matrix.nomkl }}" ]]; then
207 conda install "numpy${{ matrix.numpy-requirement }}"
208 elif [[ "${{ matrix.os }}" =~ ^windows.*$ ]]; then
209 python -m pip install "numpy${{ matrix.numpy-requirement }}"
210 else
211 conda install nomkl "numpy${{ matrix.numpy-requirement }}"
212 fi
213 if [[ -n "${{ matrix.semidefinite }}" ]]; then
214 python -m pip install cvxpy>=1.0 cvxopt
215 fi
216 if [[ "${{ matrix.oldmpl }}" ]]; then
217 python -m pip install matplotlib==3.7.* "pyparsing<=3.2.0" # graphics
218 else
219 python -m pip install matplotlib # graphics
220 fi
221
222 - name: Package information
223 run: |
224 if [[ "${{ matrix.os }}" == "windows-11-arm" ]]; then
225 pip list
226 else
227 conda list
228 fi
229 python -c "import qutip; qutip.about()"
230 python -c "import qutip; print(qutip.settings)"
231
232 - name: Environment information
233 run: |
234 uname -a
235 if [[ "ubuntu-latest" == "${{ matrix.os }}" ]]; then
236 hostnamectl
237 lscpu
238 free -h
239 fi
240
241 - name: Run tests
242 # If our tests are running for longer than an hour, _something_ is wrong
243 # somewhere. The GitHub default is 6 hours, which is a bit long to wait
244 # to see if something hung.
245 timeout-minutes: 60
246 run: |
247 if [[ -n "${{ matrix.openmp }}" ]]; then
248 # Force OpenMP runs to use more threads, even if there aren't
249 # actually that many CPUs. We have to check any dispatch code is
250 # truly being executed.
251 export QUTIP_NUM_PROCESSES=2
252 fi
253 if [[ "${{ matrix.includempi }}" ]]; then
254 # By default, the max. number of allowed worker processes in openmpi is
255 # (number of physical cpu cores) - 1.
256 # We only have 2 physical cores, but we want to test mpi_pmap with 2 workers.
257 # For OpenMPI <= 4:
258 # export OMPI_MCA_rmaps_base_oversubscribe=true
259 # For OpenMPI >= 5:
260 export PRTE_MCA_rmaps_default_mapping_policy=:oversubscribe
261 fi
262 pytest -Werror --strict-config --strict-markers --fail-slow=300 --durations=0 --durations-min=1.0 --verbosity=1 --cov=qutip --cov-report= --color=yes ${{ matrix.pytest-extra-options }} qutip/tests
263 # Above flags are:
264 # -Werror
265 # treat warnings as errors
266 # --strict-config
267 # error out if the configuration file is not parseable
268 # --strict-markers
269 # error out if a marker is used but not defined in the
270 # configuration file
271 # --timeout=300
272 # error any individual test that goes longer than the given time
273 # --durations=0 --durations-min=1.0
274 # at the end, show a list of all the tests that took longer than a
275 # second to run
276 # --verbosity=1
277 # turn the verbosity up so pytest prints the names of the tests
278 # it's currently working on
279 # --cov=qutip
280 # limit coverage reporting to code that's within the qutip package
281 # --cov-report=
282 # don't print the coverage report to the terminal---it just adds
283 # cruft, and we're going to upload the .coverage file to Coveralls
284 # --color=yes
285 # force coloured output in the terminal
286
287 - name: Upload to Coveralls
288 if: ${{ matrix.coveralls }}
289 env:
290 GITHUB_TOKEN: ${{ secrets.github_token }}
291 COVERALLS_FLAG_NAME: ${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.case-name }}
292 COVERALLS_PARALLEL: true
293 run: coveralls --service=github
294
295 towncrier-check:
296 name: Verify Towncrier entry added
297 runs-on: ubuntu-latest
298 steps:
299 - uses: actions/checkout@v6
300 with:
301 fetch-depth: 0
302
303 - name: Install Towncrier
304 run: |
305 python -m venv towncrier_check
306 source towncrier_check/bin/activate
307 python -m pip install towncrier
308
309 - name: Verify Towncrier entry added
310 if: github.event_name == 'pull_request'
311 env:
312 BASE_BRANCH: ${{ github.base_ref }}
313 run: |
314 # Fetch the pull request' base branch so towncrier will be able to
315 # compare the current branch with the base branch.
316 # Source: https://github.com/actions/checkout/#fetch-all-branches.
317 git fetch --no-tags origin +refs/heads/${BASE_BRANCH}:refs/remotes/origin/${BASE_BRANCH}
318 source towncrier_check/bin/activate
319 towncrier check --compare-with origin/${BASE_BRANCH}
320 towncrier build --version "$(cat VERSION)" --draft
321
322 finalise:
323 name: Finalise coverage reporting
324 needs: cases
325 runs-on: ubuntu-latest
326 container: python:3-slim
327 steps:
328 - name: Finalise coverage reporting
329 env:
330 GITHUB_TOKEN: ${{ secrets.github_token }}
331 run: |
332 python -m pip install coveralls
333 coveralls --service=github --finish