Skip to content

Commit 1c8c796

Browse files
[testing] [Python] Update test fixture (#3401)
Signed-off-by: Pradnya Khalate <[email protected]>
1 parent 0105f86 commit 1c8c796

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

python/tests/parallel/test_mqpu.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
# the terms of the Apache License 2.0 which accompanies this distribution. #
77
# ============================================================================ #
88

9-
import cudaq, os, pytest, random, timeit
10-
from cudaq import spin
9+
import os
10+
import random
11+
import time
12+
import timeit
13+
14+
import cudaq
1115
import numpy as np
16+
import pytest
17+
from cudaq import spin
1218

1319
skipIfNoMQPU = pytest.mark.skipif(
1420
not (cudaq.num_available_gpus() > 0 and cudaq.has_target('nvidia-mqpu')),
@@ -18,6 +24,11 @@
1824
@pytest.fixture(autouse=True)
1925
def do_something():
2026
cudaq.set_target('nvidia-mqpu')
27+
try:
28+
assert cudaq.get_target().num_qpus(
29+
) > 0, "No QPUs available after target set"
30+
except Exception as e:
31+
pytest.skip(f"MQPU setup failed: {str(e)}")
2132
yield
2233
cudaq.__clearKernelRegistries()
2334
cudaq.reset_target()
@@ -155,12 +166,6 @@ def parameterized_kernel(n: int, layers: int, params: list[float],
155166

156167

157168
def check_accuracy(entity):
158-
target = cudaq.get_target()
159-
numQpus = target.num_qpus()
160-
if numQpus == 0:
161-
pytest.skip("No QPUs available for target, skipping test")
162-
else:
163-
print(f"Target: {target}, NumQPUs: {numQpus}")
164169
# Define its spin Hamiltonian.
165170
hamiltonian = 5.907 - 2.1433 * spin.x(0) * spin.x(1) - 2.1433 * spin.y(
166171
0) * spin.y(1) + .21829 * spin.z(0) - 6.125 * spin.z(1)

0 commit comments

Comments
 (0)