I’ve got a bit of an elongated plea for aid here!
I’ve got some code that finds the optimum angles for QAOA on the Maximum Independent Set Problem. It does however seem about ~10x slower than related code that solves the Maxcut Problem.
The issue I think arises from the fact I use QAOAVarForm.construct_circuit()
to generate my circuit whereas the Maxcut program ‘manually’ places in the RX, RZ gates, etc. I’ve made two notebooks that compare the two approaches side by side in-depth:
https://www.dropbox.com/sh/xad0fcl49dbesqw/AABcNSBakS8r21Jh_3SOBaTNa?dl=0
(I’ve also included an image from snakeviz
which shows that the problem is coming from pauli_trotter_evolution
script. And for that matter the cProfile Data for this too, under the filename ‘Benchmarking_with_COBYLA’)
Here is the engine of my poorly performing code (this is certainly not all the functions required to make it work, those can be found in the notebooks!). Am I doing something incredibly inefficient? Is there a way that speeds up my code? Or would the best be to just manually create the circuit?
def quantum_operator_for_graph(Graph,model_name):
'''
Generates the quanutm object to be passed to the optimal angles function
'''
qp = QuadraticProgram()
qp.from_docplex(new_docplex_generator(Graph,model_name)) # Putting in Graph
quantum_operator, offset = qp.to_ising()
return quantum_operator
def get_qaoa_circuit_sv(var_form,p, theta):
'''
Supplies the circuit from var_form to be used in the optimisation stage of the program
'''
var_qc = var_form.construct_circuit(theta) # cost operator put in first, then after p the mixer p angles
return var_qc
def get_black_box_objective_sv(G,p,var_form,seed =10):
backend = Aer.get_backend('statevector_simulator')
def f(theta):
quantum_circuit = get_qaoa_circuit_sv(var_form,p,theta)
statevector = execute(quantum_circuit, backend, seed_simulator=seed).result().get_statevector()
# return the energy
return compute_mwis_energy_sv(get_adjusted_state(statevector), G)
return f
def get_optimal_angles(Graph,p, quantum_operator, initial_starting_points,seed):
'''
This performs the classical-quantum interchange, improving the values of beta and gamma by reducing the value of
< beta, gamma | - C | beta, gamma > (Note Negative Sign). Returns the best angles found and the objective value this refers to.
Starting points for the angles are randomly distributed across the interval specified.
'''
var_form = QAOAVarForm(quantum_operator, p)
objective_function= get_black_box_objective_sv(Graph,p,var_form,seed)
optimiser_function = minimize(objective_function, initial_starting_points, method='COBYLA', options={'maxiter':500})
best_angles = optimiser_function.x
objective_value = optimiser_function.fun
return best_angles,objective_value