|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# ============================================================================ # |
| 4 | +# Copyright (c) 2025 NVIDIA Corporation & Affiliates. # |
| 5 | +# All rights reserved. # |
| 6 | +# # |
| 7 | +# This source code and the accompanying materials are made available under # |
| 8 | +# the terms of the Apache License 2.0 which accompanies this distribution. # |
| 9 | +# ============================================================================ # |
| 10 | + |
| 11 | +# Set PATH |
| 12 | +export PATH="/cudaq-install/bin:$PATH" |
| 13 | +export PYTHONPATH="/cudaq-install:$HOME/.cudaqx" |
| 14 | +echo "Setting PYTHONPATH=$PYTHONPATH" |
| 15 | + |
| 16 | +# Set CUDA-QX paths for nvq++ |
| 17 | +CUDAQX_INCLUDE="$HOME/.cudaqx/include" |
| 18 | +CUDAQX_LIB="$HOME/.cudaqx/lib" |
| 19 | + |
| 20 | +LIB=$1 # Accepts "qec", "solvers", or "all" |
| 21 | + |
| 22 | +echo "Running example tests for $LIB..." |
| 23 | +echo "----------------------------------" |
| 24 | + |
| 25 | +# List to track failed tests |
| 26 | +FAILED_TESTS=() |
| 27 | + |
| 28 | +run_python_test() { |
| 29 | + local file=$1 |
| 30 | + echo "Running Python example: $file" |
| 31 | + echo "------------------------------" |
| 32 | + python3 "$file" |
| 33 | + if [ $? -ne 0 ]; then |
| 34 | + echo "Python test failed: $file" |
| 35 | + FAILED_TESTS+=("$file") |
| 36 | + fi |
| 37 | + echo "" |
| 38 | +} |
| 39 | + |
| 40 | +run_cpp_test() { |
| 41 | + local file=$1 |
| 42 | + local lib_flag=$2 |
| 43 | + echo "Compiling and running C++ example: $file" |
| 44 | + echo "-----------------------------------------" |
| 45 | + |
| 46 | + nvq++ --enable-mlir $lib_flag \ |
| 47 | + -I"$CUDAQX_INCLUDE" -L"$CUDAQX_LIB" -Wl,-rpath,"$CUDAQX_LIB" \ |
| 48 | + "$file" |
| 49 | + |
| 50 | + if [ $? -ne 0 ]; then |
| 51 | + echo "Compilation failed: $file" |
| 52 | + FAILED_TESTS+=("$file") |
| 53 | + return |
| 54 | + fi |
| 55 | + |
| 56 | + ./a.out |
| 57 | + if [ $? -ne 0 ]; then |
| 58 | + echo "Execution failed: $file" |
| 59 | + FAILED_TESTS+=("$file") |
| 60 | + fi |
| 61 | + echo "" |
| 62 | +} |
| 63 | + |
| 64 | +if [[ "$LIB" == "qec" || "$LIB" == "all" ]]; then |
| 65 | + echo "Running QEC examples..." |
| 66 | + echo "------------------------" |
| 67 | + |
| 68 | + for file in examples/qec/python/*.py; do |
| 69 | + run_python_test "$file" |
| 70 | + done |
| 71 | + |
| 72 | + for file in examples/qec/cpp/*.cpp; do |
| 73 | + run_cpp_test "$file" "--target=stim -lcudaq-qec" |
| 74 | + done |
| 75 | +fi |
| 76 | + |
| 77 | +if [[ "$LIB" == "solvers" || "$LIB" == "all" ]]; then |
| 78 | + echo "Running Solvers examples..." |
| 79 | + echo "---------------------------" |
| 80 | + |
| 81 | + for file in examples/solvers/python/*.py; do |
| 82 | + run_python_test "$file" |
| 83 | + done |
| 84 | + |
| 85 | + for file in examples/solvers/cpp/*.cpp; do |
| 86 | + run_cpp_test "$file" "-lcudaq-solvers" |
| 87 | + done |
| 88 | +fi |
| 89 | + |
| 90 | +# Final summary |
| 91 | +if [ ${#FAILED_TESTS[@]} -ne 0 ]; then |
| 92 | + echo "========================================" |
| 93 | + echo "Some tests failed:" |
| 94 | + for test in "${FAILED_TESTS[@]}"; do |
| 95 | + echo "- $test" |
| 96 | + done |
| 97 | + echo "========================================" |
| 98 | + exit 1 |
| 99 | +else |
| 100 | + echo "All tests passed successfully!" |
| 101 | + exit 0 |
| 102 | +fi |
0 commit comments