44import networkx as nx
55from functools import partial
66import subprocess
7-
87from qokit .qaoa_objective_labs import get_qaoa_labs_objective
98from qokit .fur .mpi_nbcuda .qaoa_simulator import mpi_available
109from qokit .fur import get_available_simulator_names
1413from qokit .qaoa_objective_sk import get_qaoa_sk_objective
1514from qokit .utils import precompute_energies
1615from qokit .parameter_utils import get_sk_gamma_beta , get_fixed_gamma_beta
17-
16+ from pathlib import Path
1817
1918simulators = get_available_simulator_names ("x" )
2019
3231is_mpi_available = mpi_available ()
3332is_gpumpi = "gpumpi" in simulators
3433is_gpu = "gpu" in simulators
35-
34+ SCRIPT_DIR = Path ( __file__ ). resolve (). parent
3635
3736@pytest .mark .skipif (not is_nvlink , reason = "NVLINK not available." )
3837def test_gpumpi (n_procs = n_gpumpi ):
39- result = subprocess .run (["mpirun" , "-np" , str (n_procs ), "python" , "./tests/gpumpi_tests.py" ], capture_output = True , text = True , check = True )
40- output_lines = result .stdout .strip ().split ("\n " )
41- output = [item == "True" for item in output_lines ]
42- assert all (output )
43-
38+ result = subprocess .run (["mpirun" , "-np" , str (n_procs ), "python" , f"{ SCRIPT_DIR } /gpumpi_tests.py" ], capture_output = True , text = True , check = True )
4439
4540@pytest .mark .skipif (not is_gpu , reason = "GPU simulator not available." )
4641def test_gpumpi_singleprocs ():
47- result = subprocess .run (["python" , "./tests/gpumpi_tests.py" ], capture_output = True , text = True , check = True )
48- output_lines = result .stdout .strip ().split ("\n " )
49- output = [item == "True" for item in output_lines ]
50- assert all (output )
51-
42+ result = subprocess .run (["python" , f"{ SCRIPT_DIR } /gpumpi_tests.py" ], capture_output = True , text = True , check = True )
5243
5344@pytest .mark .skipif (not is_gpu , reason = "GPU simulator not available." )
5445def test_gpu_labs (N = 16 , p = 4 , seed = 1 ):
55- df = pd .read_json (". /qokit/assets/QAOA_with_fixed_parameters_p_opt.json" , orient = "index" )
46+ df = pd .read_json (f" { SCRIPT_DIR . parent } /qokit/assets/QAOA_with_fixed_parameters_p_opt.json" , orient = "index" )
5647 row = df [(df ["N" ] == N ) & (df ["p" ] == p )]
5748 beta = row ["beta" ].values [0 ]
5849 gamma = row ["gamma" ].values [0 ]
@@ -64,7 +55,7 @@ def test_gpu_labs(N=16, p=4, seed=1):
6455
6556
6657@pytest .mark .skipif (not is_gpu , reason = "GPU simulator not available." )
67- def test_gpu_maxcut (N = 16 , p = 4 , seed = 1 ):
58+ def test_gpu_maxcut (N = 12 , p = 3 , seed = 1 ):
6859 d = 3
6960 G = nx .random_regular_graph (d , N , seed = seed )
7061 obj_maxcut = partial (maxcut_obj , w = get_adjacency_matrix (G ))
@@ -82,8 +73,8 @@ def test_gpu_maxcut(N=16, p=4, seed=1):
8273
8374
8475@pytest .mark .skipif (not is_gpu , reason = "GPU simulator not available." )
85- def test_gpu_sk (N = 16 , p = 4 , seed = 1 ):
86- J = get_random_J (N = N )
76+ def test_gpu_sk (N = 10 , p = 3 , seed = 42 ):
77+ J = get_random_J (N = N , seed = seed )
8778 obj_sk = partial (sk_obj , J = J )
8879 precomputed_energies = precompute_energies (obj_sk , N )
8980 gamma , beta = get_sk_gamma_beta (p )
0 commit comments