ming
1
QAOA for MaxCut | PennyLane Demos
i want to write a piece of code by imitating the max-cut,i have some questions
in max-cut:
def objective(params):
gammas = params[0]
betas = params[1]
neg_obj = 0
for edge in graph:
# objective for the MaxCut problem
neg_obj -= 0.5 * (1 - circuit(gammas, betas, edge=edge, n_layers=n_layers))
return neg_obj
so 【circuit(gammas, betas, edge=edge, n_layers=n_layers) 】= qml.PauliZ(edge[0]) @ qml.PauliZ(edge[1]) ?
and if my cost fuction is Hc=const1 * qml.PauliZ(wire0) @ qml.PauliZ(wire1) + const2 * qml.PauliZ(wire0) how should i write here?
neg_obj -= circuit(gammas, betas, n_layers=n_layers) ?
thank you for your reply!
Hi @ming ! If your cost function does not depend on edges, and you simply want to minimize that hamitlonian, you could express the code like this:
def objective(params):
gammas = params[0]
betas = params[1]
return -circuit(gammas, betas, edge=edge, n_layers=n_layers)
In addition, you will have to update the line where you define the Hamiltonian in the circuit. Hope this solve your question
ming
3
Thank you for your reply!but If my cost function does not depend on edges,why can’t I just delete the “edge”?
Hey @ming! You can most certainly get rid of edge
if circuit
doesn’t depend on it whatsoever