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.

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

def circuit(alpha):

    for i in range(2):

    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:

>>> print(qml.draw(circuit)(0.5))
0: ──H─╭ApproxTimeEvolution(1.00,1.00,0.50)─┤  <Z>
1: ──H─╰ApproxTimeEvolution(1.00,1.00,0.50)─┤  <Z>
>>> print(qml.draw(circuit, expansion_strategy="device")(0.5))
0: ──H──RX(1.00)─╭RXX(1.00)─┤  <Z>
1: ──H───────────╰RXX(1.00)─┤  <Z>