Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions python/tests/kernel/test_run_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,19 @@ def test_simple_run_ghz_with_noise():
depol = cudaq.Depolarization2(.5)
noise = cudaq.NoiseModel()
noise.add_all_qubit_channel("cx", depol)
results = cudaq.run(simple,
qubitCount,
shots_count=shots,
noise_model=noise)
print(results)
assert len(results) == shots
noisy_count = 0
for result in results:
if result != 0 and result != qubitCount:
noisy_count += 1
assert noisy_count > 0
cudaq.reset_target()
try:
# Materialize results before resetting the simulation target.
results = list(
cudaq.run(simple, qubitCount, shots_count=shots, noise_model=noise))
print(results)
assert len(results) == shots
noisy_count = 0
for result in results:
if result != 0 and result != qubitCount:
noisy_count += 1
assert noisy_count > 0
finally:
cudaq.reset_target()


def test_return_bool():
Expand Down
42 changes: 37 additions & 5 deletions scripts/validate_pycudaq.sh
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,48 @@ fi

# Run core tests
echo "Running core tests."
python3 -m pytest -v -n auto "$root_folder/tests" \
--ignore "$root_folder/tests/backends" \
--ignore "$root_folder/tests/dynamics/integrators" \
--ignore "$root_folder/tests/parallel" \
--ignore "$root_folder/tests/domains"
core_test_args=(
-v
-n
auto
"$root_folder/tests"
--ignore
"$root_folder/tests/backends"
--ignore
"$root_folder/tests/dynamics/integrators"
--ignore
"$root_folder/tests/parallel"
--ignore
"$root_folder/tests/domains"
)

macos_serial_core_tests=()
if $is_macos; then
ghz_noise_test="test_simple_run_ghz_with_noise"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of hardcoding the test here.

I don't believe it always fails this test specifically - I started creating GH issues once I see them to try and paint a better picture. I think the failing test is random, and has something to do with the runner environment likely.

ghz_noise_nodeid="$root_folder/tests/kernel/test_run_kernel.py::${ghz_noise_test}"
core_test_args+=(
-k
"not ${ghz_noise_test}"
)
macos_serial_core_tests+=("$ghz_noise_nodeid")
echo "macOS xdist workaround: excluding ${ghz_noise_test} from parallel core run; it will run serially."
fi

python3 -m pytest "${core_test_args[@]}"
if [ ! $? -eq 0 ]; then
echo -e "\e[01;31mPython tests failed.\e[0m" >&2
status_sum=$((status_sum + 1))
fi

for serial_test in "${macos_serial_core_tests[@]}"; do
echo "Running serial core test: $serial_test"
python3 -m pytest -v --rootdir "$root_folder/tests" "$serial_test"
if [ ! $? -eq 0 ]; then
echo -e "\e[01;31mPython serial core test failed: $serial_test\e[0m" >&2
status_sum=$((status_sum + 1))
fi
done

# If this is a quick test, we return here.
if $quick_test; then
if [ ! $status_sum -eq 0 ]; then
Expand Down