Skip to content

Commit e9fa519

Browse files
extended CI example testing
Now, all standalone C and C++ files in the 'isolated' and 'automated' subdirectories of 'examples' will be executed by the compiler Github Action. The former is to just catch/log interface issues not reflected by the unit tests, while the latter empowers external contributors to include casual test code with their PRs which will be run cross-platform, cross-compiler and cross-precision. This is a much easier alternative to users attempting to include unit tests in their PRs, and has been setup in preparation for unitaryHACK 2025. Also documented each examples subdir
1 parent 835208e commit e9fa519

File tree

12 files changed

+151
-20
lines changed

12 files changed

+151
-20
lines changed

.github/workflows/compile.yml

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
# code with (attemptedly) all possible configurations
33
# of operating system, precision, multithreading,
44
# distribution, GPU-acceleration (via CUDA or HIP),
5-
# and cuQuantum (else custom kernels). Currently,
6-
# this wastefully downlaods and installs all needed
7-
# compilers (like libomp, CUDA, ROCm). Compilation
5+
# and cuQuantum (else custom kernels). Compilation
86
# includes the v4 unit and integration tests, the
97
# deprecated v3 tests (when possible), and all the
10-
# example programs. One example executable is then
11-
# run (both C and C++ versions) to ensure the build
12-
# was successful and does not cause link-time errors.
13-
# Note that ARM compilation is not yet tested here,
14-
# but in fact Linux ARM is used by a paid test runner.
8+
# example programs. All 'isolated' example executables
9+
# are then run (both C and C++ versions) to ensure the
10+
# build was successful and does not cause link-time
11+
# errors. Then, all 'automated' examples are run which
12+
# permits contributors to demo or test their changes
13+
# across all operation systems and compilers.
14+
#
15+
# Note:
16+
# - This workflow currently wastefully re-downloads and
17+
# installs all needed compilers (like libomp, CUDA, ROCm)
18+
# - ARM compilation is not tested here, though it is used
19+
# by the paid multithreaded CI tests.
1520
#
1621
# @author Tyson Jones
1722

@@ -142,12 +147,12 @@ jobs:
142147

143148
# constants
144149
env:
145-
build_dir: "build"
146150
cuda_arch: 70
147151
hip_arch: gfx801
148152
rocm_path: /opt/rocm/bin
149-
example_dir: build/examples/isolated
150-
example_fn_pref: reporting_quregs
153+
build_dir: build
154+
isolated_dir: build/examples/isolated
155+
automated_dir: build/examples/automated
151156

152157
# perform the job
153158
steps:
@@ -237,15 +242,43 @@ jobs:
237242
- name: Compile
238243
run: cmake --build ${{ env.build_dir }} --config Release --parallel
239244

240-
# attempt to run the compiled executable, testing for link-time errors,
241-
# logging stdout and stderr to file (to verify the executable actually ran)
242-
- name: Run (Windows)
245+
# run all compiled isolated examples to test for link-time errors,
246+
# continuing if any fail (since some deliberately fail)
247+
- name: Run isolated examples (Windows)
243248
if: ${{ matrix.os == 'windows-latest' }}
249+
working-directory: ${{ env.isolated_dir }}/Release/
250+
shell: pwsh
251+
run: |
252+
Get-ChildItem -Filter '*.exe' -File |
253+
ForEach-Object {
254+
Write-Host "`r`n[[[ $($_.Name) ]]]`r`n"
255+
& $_.FullName
256+
}
257+
- name: Run isolated examples (Unix)
258+
if: ${{ matrix.os != 'windows-latest' }}
259+
working-directory: ${{ env.isolated_dir }}
260+
run: |
261+
for fn in *_c *_cpp; do
262+
printf "\n[[[ $fn ]]]\n"
263+
./$fn || true
264+
done
265+
266+
# run all compiled 'automated' examples
267+
- name: Run automated examples (Windows)
268+
if: ${{ matrix.os == 'windows-latest' }}
269+
working-directory: ${{ env.automated_dir }}/Release/
270+
shell: pwsh
244271
run: |
245-
./${{ env.example_dir }}/Release/${{ env.example_fn_pref }}_c.exe
246-
./${{ env.example_dir }}/Release/${{ env.example_fn_pref }}_cpp.exe
247-
- name: Run (non-Windows)
272+
Get-ChildItem -Filter '*.exe' -File |
273+
ForEach-Object {
274+
Write-Host "`r`n[[[ $($_.Name) ]]]`r`n"
275+
& $_.FullName
276+
}
277+
- name: Run automated examples (Unix)
248278
if: ${{ matrix.os != 'windows-latest' }}
279+
working-directory: ${{ env.automated_dir }}
249280
run: |
250-
./${{ env.example_dir }}/${{ env.example_fn_pref }}_c
251-
./${{ env.example_dir }}/${{ env.example_fn_pref }}_cpp
281+
for fn in *_c *_cpp; do
282+
printf "\n[[[ $fn ]]]\n"
283+
./$fn || true
284+
done

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ endfunction()
5959

6060
add_subdirectory(isolated)
6161
add_subdirectory(extended)
62+
add_subdirectory(automated)

examples/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
@author Tyson Jones
88
-->
99

10-
The above folders contain example `C` and `C++` files which use QuEST's [API](https://quest-kit.github.io/QuEST/group__api.html), helping illustrate how to use specific functions. Instructions for compiling and running them are given in [`compile.md`](/docs/compile.md#tests) and [`launch.md`](/docs/launch.md#tests) respectively.
10+
These folders contain example `C` and `C++` files which use QuEST's [API](https://quest-kit.github.io/QuEST/group__api.html), helping illustrate how to use specific functions. Instructions for compiling and running them are given in [`compile.md`](/docs/compile.md#tests) and [`launch.md`](/docs/launch.md#tests) respectively, though some are automatically run by Github Actions.
1111
<!-- @todo the above links would fail Doxygen, which does not recognise the #section syntax.
1212
no problem here however because doxygen fails to render this page all together -->
13+
14+
A description of each folder is given within.

examples/automated/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @author Tyson Jones
2+
3+
add_all_local_examples()

examples/automated/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# 🔖🤖  Automated examples
2+
3+
<!--
4+
CI-triggered examples
5+
(this comment must be under the title for valid doxygen rendering)
6+
7+
@author Tyson Jones
8+
-->
9+
10+
This folder contains examples which are compiled and executed by QuEST's `compile` Github Action, on [free runners](https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners).
11+
Contributors can include rudimentary testing or demo code in this folder (as standalone `.c` or `.cpp` files)
12+
in their pull requests and preview its output on Github, where it is run with every combination of operating system, compiler and precision.
13+
This is intended for debugging and/or logging purposes, rather than for presenting example codes for users.
14+
15+
> [!IMPORTANT]
16+
> Beware that the configurations include use of multithreading, distribution and GPU-acceleration (as `OMP`, `MPI` and `CUDA` respectively) though this reflects only their _compilation_. All files are executed serially and locally on the CPU.
17+
18+
The output can be viewed at the `compile.yml`
19+
[workflow tab](https://github.com/QuEST-Kit/QuEST/actions/workflows/compile.yml), clicking on the PR name, selecting a configuration (such as `Windows [1] OMP`) and expanding the `run automated examples` section. All files within `automated/` will be run in-turn and their outputs sequentially presented.
20+
21+
> [!IMPORTANT]
22+
> Since these examples are executed at every invocation of the CI, they should _not_ perform intensive, long computations. Such examples are better suited for the [`extended/`](../extended/) folder.
23+
24+
> [!TIP]
25+
> Files with extensions `.c` or `.cpp` will be respectively compiled in `C11` and `C++17`. An example which uses a facility sensitive to the language can be duplicated as both `file.c` and `file.cpp` so that both versions are tested.

examples/automated/report_quest_env.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @file
2+
* Shows the output of reportQuESTEnv() on
3+
* Github Action runners
4+
*
5+
* @author Tyson Jones
6+
*/
7+
8+
#include "quest.h"
9+
10+
int main() {
11+
initQuESTEnv();
12+
reportQuESTEnv();
13+
finalizeQuESTEnv();
14+
}

examples/extended/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# 🔖📚  Extended examples
2+
3+
<!--
4+
Extended examples
5+
(this comment must be under the title for valid doxygen rendering)
6+
7+
@author Tyson Jones
8+
-->
9+
10+
This folder contains _extended_ examples which demonstrate the use of QuEST in standalone applications, such as the emulation of canonical quantum algorithms. We provide both `C` and `C++` versions (compiled against standards `C11` and `C++17`) of each example. All fines herein are _compiled_ (but not executed) by the [compile](https://github.com/QuEST-Kit/QuEST/actions/workflows/compile.yml) Github Action.
11+

examples/extended/dynamics.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/** @file
2+
* An example of using QuEST (primarily function
3+
* applyTrotterizedPauliStrSumGadget()) to perform
4+
* dynamical simulation via Trotterisation of the
5+
* unitary-time evolution operator.
6+
*
7+
* @author Tyson Jones
8+
*/
9+
110
#include "quest.h"
211
#include <stdio.h>
312
#include <stdlib.h>

examples/extended/dynamics.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/** @file
2+
* An example of using QuEST (primarily function
3+
* applyTrotterizedPauliStrSumGadget()) to perform
4+
* dynamical simulation via Trotterisation of the
5+
* unitary-time evolution operator.
6+
*
7+
* @author Tyson Jones
8+
*/
9+
110
#include "quest.h"
211
#include <vector>
312
#include <string>

examples/isolated/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# 🔖🔍  Isolated examples
2+
3+
<!--
4+
Isolated examples
5+
(this comment must be under the title for valid doxygen rendering)
6+
7+
@author Tyson Jones
8+
-->
9+
10+
This folder contains _isolated_ examples which demonstrate the possible uses of a specific QuEST function or facility. They mostly serve to illustrate the various ways that a single task (such as initialising a `KrausMap`) can be performed with the QuEST API. We provide both `C` and `C++` versions (compiled against standards `C11` and `C++17`) of each example to highlight the interfaces available to the respective languages.
11+
12+
Every `.c` and `.cpp` in this folder is compiled _and_ executed by the [compile](https://github.com/QuEST-Kit/QuEST/actions/workflows/compile.yml) Github Action, to automatically check for compilation and link-time issues.

0 commit comments

Comments
 (0)