# Code imitating like max-cut(qaoa)

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
betas = params
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) @ qml.PauliZ(edge) ?

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) ?

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
betas = params
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 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 