Closed vivekkatial closed 6 months ago
Vivek,
Apologies for the confusion! brute_force
function is not meant to optimize the QAOA objective. Instead, it is meant to optimize the underlying cost function. In your example:
import networkx as nx
from functools import partial
from qokit.utils import brute_force
from qokit.maxcut import maxcut_obj, get_adjacency_matrix
# Generate a cycle graph
N = 6
G = nx.Graph()
G.add_edges_from([(i,(i+1)%N) for i in range(N)])
w = get_adjacency_matrix(G)
obj = partial(maxcut_obj, w=w)
optimal_cut, bitstring_encoding_cut = brute_force(obj, N, minimize=False, function_takes='bits')
print(f"Optimal cut: {optimal_cut}, encoded by bitstring {''.join(str(x) for x in bitstring_encoding_cut)}")
outputs
Optimal cut: 6.0, encoded by bitstring 101010
As your plot shows, this is indeed the optimal solution.
I have been trying to use the QOKit simulator for larger instances but before that I wanted to verify it works for some trivial small ones.
I'd love some insight into if I'm doing something wrong -- thank you in advance 😁
I have created a basic
2-regular
or ring graphThe solution for the two subsets are trivial:
However; when I run the code (see below) -- brute-force output is incorrect.
Pls let me know if I'm implementing this wrong?
Here is a plot:
I also validated with Gurobi and it can produce the correct solution: