%load_ext autoreload
%autoreload 2
from IPython.display import clear_output

import matplotlib.pyplot as plt
import plotly.graph_objects as go
import numpy as np
import networkx as nx

# Design the graph for the  maxcut problem 

g = nx.Graph()
g.add_edge(0, 1)
g.add_edge(0, 2)
g.add_edge(1, 3)
g.add_edge(1, 4)
g.add_edge(2, 4)
g.add_edge(3, 4)

#import problem classes from OQ for easy problem creation
from openqaoa.problems.problem import MaximumCut

#import the QAOA workflow model
from openqaoa.workflows.optimizer import QAOA

#import method to specify the device
from openqaoa.devices import create_device

# Import the method to plot the graph 
from openqaoa.utilities import plot_graph

plot_graph(g)

#Use the MaximumCut class to instantiate the problem.
maxcut_prob = MaximumCut(g)

# The binary values can be access via the `asdict()` method.
maxcut_qubo = maxcut_prob.get_qubo_problem()
maxcut_qubo.asdict()

# init the object QAOA for default the backend is vectorised
q = QAOA()

q.local_simulators, q.cloud_provider

from openqaoa.devices import create_device
sim = create_device(location='local', name='vectorized')

q.set_device(sim)

q.compile(maxcut_qubo) 

q.optimize()

q.results.most_probable_states['solutions_bitstrings']

q.results.most_probable_states['bitstring_energy']

q.results.get_counts(q.results.optimized['optimized measurement outcomes'])

q.results.plot_cost()