Skip to content

Commit 2f53b29

Browse files
author
Zichang He
committed
black check
1 parent 88b0d15 commit 2f53b29

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

tests/gpumpi_tests.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
SCRIPT_DIR = Path(__file__).resolve().parent
1515

16+
1617
def gpumpi_labs_test(N=10, p=4):
1718
df = pd.read_json(f"{SCRIPT_DIR.parent}/qokit/assets/QAOA_with_fixed_parameters_p_opt.json", orient="index")
1819
row = df[(df["N"] == N) & (df["p"] == p)]
@@ -30,26 +31,26 @@ def gpumpi_labs_test(N=10, p=4):
3031
elif objective == "expectation":
3132
assert np.isclose(f_gpumpi_labs(gamma, beta), f_c_labs(gamma, beta))
3233

34+
3335
def gpumpi_maxcut_test(N=12, p=3, seed=1):
3436
d = 3
3537
G = nx.random_regular_graph(d, N, seed=seed)
3638
gamma, beta = get_fixed_gamma_beta(d, p)
3739
obj_maxcut = partial(maxcut_obj, w=get_adjacency_matrix(G))
3840
precomputed_energies = precompute_energies(obj_maxcut, N)
3941
for objective in ["overlap", "expectation"]:
40-
o1_c_maxcut = get_qaoa_maxcut_objective(
41-
N, p, precomputed_cuts=precomputed_energies, simulator="c", parameterization="gamma beta", objective=objective
42-
)(gamma, beta)
42+
o1_c_maxcut = get_qaoa_maxcut_objective(N, p, precomputed_cuts=precomputed_energies, simulator="c", parameterization="gamma beta", objective=objective)(
43+
gamma, beta
44+
)
4345
o1_gpumpi_maxcut = get_qaoa_maxcut_objective(
4446
N, p, precomputed_cuts=precomputed_energies, simulator="gpumpi", parameterization="gamma beta", objective=objective
4547
)(gamma, beta)
46-
o2_gpumpi_maxcut = get_qaoa_maxcut_objective(
47-
N, p, G=G, simulator="gpumpi", parameterization="gamma beta", objective=objective
48-
)(gamma, beta)
48+
o2_gpumpi_maxcut = get_qaoa_maxcut_objective(N, p, G=G, simulator="gpumpi", parameterization="gamma beta", objective=objective)(gamma, beta)
4949

50-
assert np.isclose(o1_c_maxcut, o1_gpumpi_maxcut.real)
50+
assert np.isclose(o1_c_maxcut, o1_gpumpi_maxcut.real)
5151
assert np.isclose(o1_c_maxcut, o2_gpumpi_maxcut.real)
5252

53+
5354
def gpumpi_sk_test(N=10, p=3, seed=42):
5455

5556
J = get_random_J(N=N, seed=seed)
@@ -63,13 +64,12 @@ def gpumpi_sk_test(N=10, p=3, seed=42):
6364
o1_gpumpi_sk = get_qaoa_sk_objective(
6465
N, p, J=J, precomputed_energies=precomputed_energies, simulator="gpumpi", parameterization="gamma beta", objective="overlap"
6566
)(gamma, beta)
66-
o2_gpumpi_sk = get_qaoa_sk_objective(
67-
N, p, J=J, simulator="gpumpi", parameterization="gamma beta", objective="overlap"
68-
)(gamma, beta)
67+
o2_gpumpi_sk = get_qaoa_sk_objective(N, p, J=J, simulator="gpumpi", parameterization="gamma beta", objective="overlap")(gamma, beta)
6968

7069
assert np.isclose(o1_c_sk, o1_gpumpi_sk.real)
7170
assert np.isclose(o1_c_sk, o2_gpumpi_sk.real)
7271

72+
7373
if __name__ == "__main__":
7474

7575
gpumpi_labs_test()

tests/test_gpumpi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@
3333
is_gpu = "gpu" in simulators
3434
SCRIPT_DIR = Path(__file__).resolve().parent
3535

36+
3637
@pytest.mark.skipif(not is_nvlink, reason="NVLINK not available.")
3738
def test_gpumpi(n_procs=n_gpumpi):
3839
result = subprocess.run(["mpirun", "-np", str(n_procs), "python", f"{SCRIPT_DIR}/gpumpi_tests.py"], capture_output=True, text=True, check=True)
3940

41+
4042
@pytest.mark.skipif(not is_gpu, reason="GPU simulator not available.")
4143
def test_gpumpi_singleprocs():
4244
result = subprocess.run(["python", f"{SCRIPT_DIR}/gpumpi_tests.py"], capture_output=True, text=True, check=True)
4345

46+
4447
@pytest.mark.skipif(not is_gpu, reason="GPU simulator not available.")
4548
def test_gpu_labs(N=16, p=4, seed=1):
4649
df = pd.read_json(f"{SCRIPT_DIR.parent}/qokit/assets/QAOA_with_fixed_parameters_p_opt.json", orient="index")

0 commit comments

Comments
 (0)