qml.qaoa.mixers.bit_flip_mixer

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 Hadfield et al. (2019).

Parameters
  • graph (nx.Graph or rx.PyGraph) – 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\).

Returns

Mixer Hamiltonian

Return type

Hamiltonian

Example

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)
>>> mixer_h
(
    0.5 * X(0)
  + 0.5 * (X(0) @ Z(1))
  + 0.25 * X(1)
  + 0.25 * (X(1) @ Z(2))
  + 0.25 * (X(1) @ Z(0))
  + 0.25 * (X(1) @ Z(0) @ Z(2))
  + 0.5 * X(2)
  + 0.5 * (X(2) @ Z(1))
)
>>> import rustworkx as rx
>>> graph = rx.PyGraph()
>>> graph.add_nodes_from([0, 1, 2])
>>> graph.add_edges_from([(0, 1, ""), (1, 2, "")])
>>> mixer_h = qaoa.bit_flip_mixer(graph, 0)
>>> print(mixer_h)
(
    0.5 * X(0)
  + 0.5 * (X(0) @ Z(1))
  + 0.25 * X(1)
  + 0.25 * (X(1) @ Z(2))
  + 0.25 * (X(1) @ Z(0))
  + 0.25 * (X(1) @ Z(0) @ Z(2))
  + 0.5 * X(2)
  + 0.5 * (X(2) @ Z(1))
)