Skip to content

Commit 6ad1c7c

Browse files
Add coverage for py-mpitests. (#522)
* Initial commit mpi tests * Remove label guards * Fix PL_DEVICE * Install lightning_qubit. * Fix ENABLE_MPI * print cuquantum * export cu_sdk * revert define * Debug cpp tests. * Debug cpp tests. * Fix cmake options. * Compile with mpicxx * Specify backend. * Specify backend. * Remove obsolete line. * Specify cov backend * Merge test/cov & try simplifying python * if-no-files-found: error and fix python tests. * Fix mpi find * Install real lightning. * Revert python tests. * Hardcode backend values in python tests * Install lightning_qubit with gpu in python tests * Remove explicit mpich mentions. * Parametrize mpilib name. * Add openmpi tests. * Build only openmpi python tests. * Add timeouts * test/test_apply.py * Revert pull triggers. * Clean gpu-mpi test workflows. * Revert to 804ed24. * Revert back. * Update tests_linux_x86_mpi.yml [ci skip] * Add jobs dep. * Remove module unload * Simplify mpi-gpu tests. * trigger CI * unset CFLAGS. * set CFLAGS * Revert triggers. * Fix pull_request: [skip ci] * trigger CI * Rename test_gpu_cu11.yml -> tests_gpu_cu11.yml [skip ci] * Add coverage for py-mpitests. * Upload mpi-gpu test coverage. * Try other paths. * trigger CI * Add mpi tests. * Fix couple tests. * Fixx test_apply tests? * Add MPI sparse measurements. * Fix format. * Add MPI_Init checks in MPIManager constructors. * Reformat mpitests and add cov for proc > dev error. * Refactor makefile. * Revert to full mpirun path. * Fix couple tests. * Name coverage after matrix.mpilib. * Remove oversubscribe MPI test. * Update changelog [skip ci]. --------- Co-authored-by: Shuli <[email protected]>
1 parent 34c3b9a commit 6ad1c7c

File tree

13 files changed

+862
-106
lines changed

13 files changed

+862
-106
lines changed

.github/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949

5050
### Improvements
5151

52+
* Improve Python testing for Lightning-GPU (+MPI) by adding jobs in Actions files and adding Python tests to increase code coverage.
53+
[(#522)](https://github.com/PennyLaneAI/pennylane-lightning/pull/522)
54+
5255
* Add support for `pip install pennylane-lightning[kokkos]` for the OpenMP backend.
5356
[(#515)](https://github.com/PennyLaneAI/pennylane-lightning/pull/515)
5457

.github/workflows/tests_linux_x86_mpi.yml

+69-13
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ jobs:
133133
for file in *runner_mpi ; do /opt/mpi/${{ matrix.mpilib }}/bin/mpirun -np 2 ./$file --order lex --reporter junit --out ./tests/results/report_$file.xml; done;
134134
lcov --directory . -b ../pennylane_lightning/src --capture --output-file coverage.info
135135
lcov --remove coverage.info '/usr/*' --output-file coverage.info
136-
mv coverage.info coverage-${{ github.job }}-lightning_gpu.info
136+
mv coverage.info coverage-${{ github.job }}-lightning_gpu_${{ matrix.mpilib }}.info
137137
138138
- name: Upload test results
139139
uses: actions/upload-artifact@v3
@@ -148,16 +148,13 @@ jobs:
148148
with:
149149
if-no-files-found: error
150150
name: ubuntu-codecov-results-cpp
151-
path: ./Build/coverage-${{ github.job }}-lightning_gpu.info
151+
path: ./Build/coverage-${{ github.job }}-lightning_gpu_${{ matrix.mpilib }}.info
152152

153153
- name: Cleanup
154154
if: always()
155155
run: |
156156
rm -rf ${{ steps.setup_venv.outputs.venv_name }}
157-
rm -rf *
158-
rm -rf .git
159-
rm -rf .gitignore
160-
rm -rf .github
157+
rm -rf * .git .gitignore .github
161158
pip cache purge
162159
163160
@@ -169,7 +166,6 @@ jobs:
169166
- x64
170167
- ubuntu-22.04
171168
- multi-gpu
172-
needs: ["cpp_tests"]
173169
strategy:
174170
max-parallel: 1
175171
matrix:
@@ -249,15 +245,75 @@ jobs:
249245
- name: Run PennyLane-Lightning-GPU unit tests
250246
run: |
251247
source /etc/profile.d/modules.sh && module use /opt/modules/ && module load ${{ matrix.mpilib }}
252-
PL_DEVICE=lightning.gpu python -m pytest ./tests/
253-
PL_DEVICE=lightning.gpu /opt/mpi/${{ matrix.mpilib }}/bin/mpirun -np 2 python -m pytest ./mpitests/test_adjoint_jacobian.py
248+
PL_DEVICE=lightning.gpu python -m pytest ./tests/ $COVERAGE_FLAGS
249+
PL_DEVICE=lightning.gpu /opt/mpi/${{ matrix.mpilib }}/bin/mpirun -np 2 python -m pytest ./mpitests $COVERAGE_FLAGS
250+
# PL_DEVICE=lightning.gpu /opt/mpi/${{ matrix.mpilib }}/bin/mpirun --oversubscribe -n 4 pytest -s -x mpitests/test_device.py -k test_create_device $COVERAGE_FLAGS
251+
mv coverage.xml coverage-${{ github.job }}-lightning_gpu_${{ matrix.mpilib }}.xml
252+
253+
- name: Upload code coverage results
254+
uses: actions/upload-artifact@v3
255+
with:
256+
name: ubuntu-codecov-results-python
257+
path: coverage-${{ github.job }}-lightning_gpu_${{ matrix.mpilib }}.xml
258+
if-no-files-found: error
259+
260+
- name: Cleanup
261+
if: always()
262+
run: |
263+
rm -rf ${{ steps.setup_venv.outputs.venv_name }}
264+
rm -rf * .git .gitignore .github
265+
pip cache purge
266+
267+
upload-to-codecov-linux-cpp:
268+
needs: ["cpp_tests"]
269+
name: Upload coverage data to codecov
270+
runs-on: ubuntu-latest
271+
steps:
272+
- name: Checkout
273+
uses: actions/checkout@v3
274+
275+
- name: Download coverage reports
276+
uses: actions/download-artifact@v3
277+
with:
278+
name: ubuntu-codecov-results-cpp
279+
280+
- name: Upload to Codecov
281+
uses: codecov/codecov-action@v3
282+
with:
283+
fail_ci_if_error: true
284+
verbose: true
285+
token: ${{ secrets.CODECOV_TOKEN }}
286+
287+
- name: Cleanup
288+
if: always()
289+
run: |
290+
rm -rf ${{ steps.setup_venv.outputs.venv_name }}
291+
rm -rf * .git .gitignore .github
292+
pip cache purge
293+
294+
upload-to-codecov-linux-python:
295+
needs: ["python_tests"]
296+
name: Upload coverage data to codecov
297+
runs-on: ubuntu-latest
298+
steps:
299+
- name: Checkout
300+
uses: actions/checkout@v3
301+
302+
- name: Download coverage reports
303+
uses: actions/download-artifact@v3
304+
with:
305+
name: ubuntu-codecov-results-python
306+
307+
- name: Upload to Codecov
308+
uses: codecov/codecov-action@v3
309+
with:
310+
fail_ci_if_error: true
311+
verbose: true
312+
token: ${{ secrets.CODECOV_TOKEN }}
254313

255314
- name: Cleanup
256315
if: always()
257316
run: |
258317
rm -rf ${{ steps.setup_venv.outputs.venv_name }}
259-
rm -rf *
260-
rm -rf .git
261-
rm -rf .gitignore
262-
rm -rf .github
318+
rm -rf * .git .gitignore .github
263319
pip cache purge

Makefile

+27-27
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@ TESTRUNNER := -m pytest tests --tb=short
66

77
PL_BACKEND?="$(if $(backend:-=),$(backend),lightning_qubit)"
88

9-
ifdef verbose
10-
VERBOSE := --verbose
11-
else
12-
VERBOSE :=
13-
endif
14-
159
ifdef check
1610
CHECK := --check
1711
else
1812
CHECK :=
1913
endif
2014

15+
ifdef build_options
16+
OPTIONS := $(build_options)
17+
else
18+
OPTIONS :=
19+
endif
20+
21+
ifdef verbose
22+
VERBOSE := --verbose
23+
else
24+
VERBOSE :=
25+
endif
26+
2127
.PHONY: help
2228
help:
2329
@echo "Please use \`make <target>' where <target> is one of"
@@ -56,16 +62,7 @@ clean:
5662
rm -rf .coverage coverage_html_report/
5763
rm -rf pennylane_lightning/*_ops*
5864

59-
.PHONY : test-builtin test-suite test-python coverage coverage-cpp test-cpp test-cpp-no-omp test-cpp-blas test-cpp-kokkos
60-
test-builtin:
61-
PL_DEVICE=$(if $(device:-=),$(device),lightning.qubit) $(PYTHON) -I $(TESTRUNNER)
62-
63-
test-suite:
64-
pl-device-test --device $(if $(device:-=),$(device),lightning.qubit) --skip-ops --shots=20000
65-
pl-device-test --device $(if $(device:-=),$(device),lightning.qubit) --shots=None --skip-ops
66-
67-
test-python: test-builtin test-suite
68-
65+
.PHONY : test-builtin test-suite test-python test-cpp coverage coverage-cpp
6966
coverage:
7067
@echo "Generating coverage report for $(if $(device:-=),$(device),lightning.qubit) device:"
7168
$(PYTHON) $(TESTRUNNER) $(COVERAGE)
@@ -75,20 +72,29 @@ coverage:
7572
coverage-cpp:
7673
@echo "Generating cpp coverage report in BuildCov/out for $(PL_BACKEND) backend"
7774
rm -rf ./BuildCov
78-
cmake -BBuildCov -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DENABLE_COVERAGE=ON -DPL_BACKEND=$(PL_BACKEND)
75+
cmake -BBuildCov -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DENABLE_COVERAGE=ON -DPL_BACKEND=$(PL_BACKEND) $(OPTIONS)
7976
cmake --build ./BuildCov
8077
cd ./BuildCov; for file in *runner ; do ./$file; done; \
8178
lcov --directory . -b ../pennylane_lightning/core/src --capture --output-file coverage.info; \
8279
genhtml coverage.info --output-directory out
8380

8481
build:
8582
rm -rf ./Build
86-
cmake -BBuild -G Ninja -DENABLE_BLAS=ON -DENABLE_WARNINGS=ON -DPL_BACKEND=$(PL_BACKEND)
83+
cmake -BBuild -G Ninja -DENABLE_WARNINGS=ON -DPL_BACKEND=$(PL_BACKEND) $(OPTIONS)
8784
cmake --build ./Build $(VERBOSE)
8885

86+
test-builtin:
87+
PL_DEVICE=$(if $(device:-=),$(device),lightning.qubit) $(PYTHON) -I $(TESTRUNNER)
88+
89+
test-suite:
90+
pl-device-test --device $(if $(device:-=),$(device),lightning.qubit) --skip-ops --shots=20000
91+
pl-device-test --device $(if $(device:-=),$(device),lightning.qubit) --shots=None --skip-ops
92+
93+
test-python: test-builtin test-suite
94+
8995
test-cpp:
9096
rm -rf ./BuildTests
91-
cmake -BBuildTests -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DENABLE_OPENMP=ON -DENABLE_WARNINGS=ON -DPL_BACKEND=$(PL_BACKEND)
97+
cmake -BBuildTests -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DENABLE_WARNINGS=ON -DPL_BACKEND=$(PL_BACKEND) $(OPTIONS)
9298
ifdef target
9399
cmake --build ./BuildTests $(VERBOSE) --target $(target)
94100
OMP_PROC_BIND=false ./BuildTests/$(target)
@@ -97,25 +103,19 @@ else
97103
OMP_PROC_BIND=false cmake --build ./BuildTests $(VERBOSE) --target test
98104
endif
99105

100-
test-cpp-blas:
101-
rm -rf ./BuildTests
102-
cmake -BBuildTests -G Ninja -DBUILD_TESTS=ON -DENABLE_BLAS=ON -DENABLE_WARNINGS=ON -DPL_BACKEND=$(PL_BACKEND)
103-
cmake --build ./BuildTests $(VERBOSE)
104-
cmake --build ./BuildTests $(VERBOSE) --target test
105-
106106
.PHONY: format format-cpp
107107
format: format-cpp format-python
108108

109109
format-cpp:
110110
./bin/format $(CHECK) --cfversion $(if $(version:-=),$(version),0) ./pennylane_lightning
111111

112112
format-python:
113-
black -l 100 ./pennylane_lightning/ ./tests $(CHECK)
113+
black -l 100 ./pennylane_lightning/ ./mpitests ./tests $(CHECK)
114114

115115
.PHONY: check-tidy
116116
check-tidy:
117117
rm -rf ./BuildTidy
118-
cmake -BBuildTidy -DENABLE_CLANG_TIDY=ON -DBUILD_TESTS=ON -DENABLE_WARNINGS=ON -DPL_BACKEND=$(PL_BACKEND)
118+
cmake -BBuildTidy -DENABLE_CLANG_TIDY=ON -DBUILD_TESTS=ON -DENABLE_WARNINGS=ON -DPL_BACKEND=$(PL_BACKEND) $(OPTIONS)
119119
ifdef target
120120
cmake --build ./BuildTidy $(VERBOSE) --target $(target)
121121
else

mpitests/conftest.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
PHI = np.linspace(0.32, 1, 3)
3939
VARPHI = np.linspace(0.02, 1, 3)
4040

41+
4142
@pytest.fixture(scope="session")
4243
def tol():
4344
"""Numerical tolerance for equality tests."""
@@ -49,6 +50,7 @@ def n_subsystems(request):
4950
"""Number of qubits or qumodes."""
5051
return request.param
5152

53+
5254
# Looking for the device for testing.
5355
default_device = "lightning.gpu"
5456
supported_devices = {"lightning.gpu"}
@@ -93,6 +95,12 @@ def get_device():
9395
)
9496
def qubit_device(request):
9597
def _device(wires):
96-
return qml.device(device_name, wires=wires, mpi=True, c_dtype=request.param[0], batch_obs=request.param[1])
98+
return qml.device(
99+
device_name,
100+
wires=wires,
101+
mpi=True,
102+
c_dtype=request.param[0],
103+
batch_obs=request.param[1],
104+
)
97105

98106
return _device

0 commit comments

Comments
 (0)