Skip to content

Commit 3268cf9

Browse files
committed
Adding test comparing maxcut and warmstart.
1 parent ccd75a6 commit 3268cf9

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

tests/test_warm_start.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import qokit
44
from qokit.parameter_utils import get_fixed_gamma_beta
55
from qokit.warm_start import WSSolver, maxcut_qubo_from_G, WSSolverQUBO, get_terms_from_QUBO
6+
from qokit.maxcut import get_maxcut_terms
7+
import pytest
8+
import sys
69

710

811
def test_p0_objective():
@@ -68,6 +71,7 @@ def test_batch_obj_grad():
6871

6972

7073
############################
74+
@pytest.mark.skipif(sys.platform.startswith("darwin"), reason="Fast c/c++ simulator should be installed")
7175
def test_maxcut_qaoa():
7276
N = 10
7377
G = nx.random_regular_graph(3, N, seed=1)
@@ -82,6 +86,12 @@ def test_maxcut_qaoa():
8286
sim = simclass(N, terms=terms)
8387
cost = sim.get_cost_diagonal()
8488
best_cut = np.max(cost)
89+
90+
terms_maxcut = get_maxcut_terms(G)
91+
sim_maxcut = simclass(N, terms=terms_maxcut)
92+
cost_maxcut = sim_maxcut.get_cost_diagonal()
93+
best_cut_maxcut = np.max(cost_maxcut)
94+
8595
_result = sim.simulate_ws_qaoa(list(np.asarray(gamma)), list(np.asarray(beta)), np.ones(N) * np.pi / 2)
8696
qokit_energy = sim.get_expectation(_result)
8797

@@ -91,3 +101,4 @@ def test_maxcut_qaoa():
91101
ws_energy = ws_solver.run_standard_qaoa(p)
92102
assert np.isclose(qokit_energy, qubo_energy)
93103
assert np.isclose(ws_energy, qubo_energy)
104+
assert best_cut_maxcut < ws_energy

0 commit comments

Comments
 (0)