n_wires = 1
dev = qml.device("default.qubit", wires=n_wires)
p=3
cost_h=qml.Hamiltonian([1], [qml.PauliZ(0)])
mixer_h=qml.Hamiltonian([1], [qml.PauliX(0)])
params=np.ones((p, 2),requires_grad=True) * 0.5
def qaoa_layer(params,cost_h):
"""Implement one QAOA layer alternating H_C and H_M.
Args:
params (np.array): An array with the trainable parameters of the QAOA ansatz.
cost_h (qml.Hamiltonian): The cost Hamiltonian
"""
##################
# YOUR CODE HERE #
##################
def qaoa_circuit(params,p,cost_h):
"""Implement the initial state and p layers of the QAOA ansatz.
Args:
params (np.array): An array with the trainable parameters of the QAOA ansatz.
p (int): Number of layers of the QAOA ansatz.
cost_h (qml.Hamiltonian): The cost Hamiltonian
"""
##################
# YOUR CODE HERE #
##################
@qml.qnode(dev)
def probability_circuit(params,p,cost_h):
"""QAOA circuit which returns the probabilities.
Args:
params (np.array): An array with the trainable parameters of the QAOA ansatz.
p (int): Number of layers of the QAOA ansatz.
cost_h (qml.Hamiltonian): The cost Hamiltonian
Returns: