from openqaoa.problems.problem import NumberPartition
np = NumberPartition(numbers=[1,2,3])
np_qubo = np.get_qubo_problem()

# visualize the QUBO form on a graph
from openqaoa.utilities import plot_graph, graph_from_hamiltonian

#extract Hamiltonain
cost_hamil = np_qubo.hamiltonian

#convert Hamiltonian to graph
cost_gr = graph_from_hamiltonian(cost_hamil)

#plot the graph
plot_graph(cost_gr)

from openqaoa.workflows.optimizer import QAOA

# Initialise QAOA using the default values
q = QAOA()
# Complile the QAOA workflow
q.compile(np_qubo)
# Optimise the problem!
q.optimize()

q.results.plot_probabilities()

# Initialise QAOA
q = QAOA()
q.compile(np_qubo)

q.variate_params

# Initialise QAOA
q = QAOA()
q.set_circuit_properties(p=1, param_type='standard', init_type='rand')
q.compile(np_qubo)

q.variate_params

import numpy
def my_submission_function(p):
    """
    Note that the number of betas and gammas depend on the number of layers `p`!

    Also, in OpenQAOA there are several parametrisation techiques which will change the structure 
    of the return of `my_submission_function`
    For more details: https://el-openqaoa.readthedocs.io/en/latest/notebooks/05_advanced_parameterization.html
    """
    
    return { 'betas'  : [numpy.random.randn() for i in range(p)],
             'gammas' : [numpy.random.randn() for i in range(p)]}

p = 2
q_submission = QAOA()
q_submission.set_circuit_properties(p=p, 
                                    param_type='standard',
                                    init_type='custom',
                                    variational_params_dict=my_submission_function(2))

my_submission_function(2)

q_submission.compile(np_qubo)

q_submission.optimize()

q_submission.results.plot_cost()

q_submission.results.plot_probabilities()

np_input = [numpy.random.randint(30) for i in range(10)]
np_input