import os
os.chdir("..")

from classes import Qaoa as Q
from classes import Problems as P
from functions import qaoa_utilities as qaoa_utils
from functions import maxcut_utilities as mcut_utils
from functions import qaoa_optimizers as optims

import numpy as np
import pickle
import sys

from config import *

# Graphs

graphs = []
for i in range(num_graphs):
    sys.path.append("classes/")
    path = "data/graph_"+str(i)+".nx"
    with open(path, 'rb') as f:
        g = pickle.load(f)
    graphs.append(g)

# Select a graph 
G = graphs[idx]

G.get_draw()

# Generate initial random angles
betas = qaoa_utils.generate_parameters(n=p, k=1, seed=seed)
gammas = qaoa_utils.generate_parameters(n=p, k=2, seed=seed)

# Instantiate QAOA 
qaoa = Q.Qaoa(p=p, G=G, betas=betas, gammas=gammas, mixer=mixer, seed=seed, verbose=verbose)

qaoa.get_circuit().draw()

# QAOA execution (simple optimization)
_, f = optims.simple_optimization(qaoa, method=method, seed=seed, shots=shots, verbose=verbose)
_,f 