# qml.qaoa.layers.mixer_layer¶

mixer_layer(alpha, hamiltonian)[source]

Applies the QAOA mixer layer corresponding to a mixer Hamiltonian.

For a mixer Hamiltonian $$H_M$$, this is defined as the following unitary:

$U_M \ = \ e^{-i \alpha H_M}$

where $$\alpha$$ is a variational parameter.

Parameters
• alpha (int or float) – The variational parameter passed into the mixer layer

• hamiltonian (Hamiltonian) – The mixer Hamiltonian

We first define a mixer Hamiltonian:

from pennylane import qaoa
import pennylane as qml

mixer_h = qml.Hamiltonian([1, 1], [qml.PauliX(0), qml.PauliX(0) @ qml.PauliX(1)])


We can then pass it into qaoa.mixer_layer, within a quantum circuit:

dev = qml.device('default.qubit', wires=2)

@qml.qnode(dev)
def circuit(alpha):

for i in range(2):
qml.Hadamard(wires=i)

qaoa.mixer_layer(alpha, mixer_h)

return [qml.expval(qml.PauliZ(wires=i)) for i in range(2)]


which gives us a circuit of the form:

>>> circuit(0.5)
>>> print(circuit.draw())
0: ──H──RZ(1)──H──H──╭RZ(1)──H──┤ ⟨Z⟩
1: ──H───────────────╰RZ(1)──H──┤ ⟨Z⟩