bit_flip_mixer(graph, b)[source]

Creates a bit-flip mixer Hamiltonian.

This mixer is defined as:

\[H_M \ = \ \displaystyle\sum_{v \in V(G)} \frac{1}{2^{d(v)}} X_{v} \displaystyle\prod_{w \in N(v)} (\mathbb{I} \ + \ (-1)^b Z_w)\]

where \(V(G)\) is the set of vertices of some graph \(G\), \(d(v)\) is the degree of vertex \(v\), and \(N(v)\) is the neighbourhood of vertex \(v\). In addition, \(Z_v\) and \(X_v\) are the Pauli-Z and Pauli-X operators on vertex \(v\), respectively, and \(\mathbb{I}\) is the identity operator.

This mixer was introduced in [arXiv:1709.03489].

  • graph (nx.Graph) – A graph defining the collections of wires on which the Hamiltonian acts.

  • b (int) – Either \(0\) or \(1\). When \(b=0\), a bit flip is performed on vertex \(v\) only when all neighbouring nodes are in state \(|0\rangle\). Alternatively, for \(b=1\), a bit flip is performed only when all the neighbours of \(v\) are in the state \(|1\rangle\).


Mixer Hamiltonian

Return type



The mixer Hamiltonian can be called as follows:

>>> from pennylane import qaoa
>>> from networkx import Graph
>>> graph = Graph([(0, 1), (1, 2)])
>>> mixer_h = qaoa.bit_flip_mixer(graph, 0)
>>> print(mixer_h)
(0.5) [X0]
+ (0.5) [X0 Z1]
+ (0.25) [X1]
+ (0.25) [X1 Z2]
+ (0.25) [X1 Z0]
+ (0.25) [X1 Z0 Z2]
+ (0.5) [X2]
+ (0.5) [X2 Z1]