qml.qaoa.mixers.xy_mixer

xy_mixer(graph)[source]

Creates a generalized SWAP/XY mixer Hamiltonian.

This mixer Hamiltonian is defined as:

\[H_M \ = \ \frac{1}{2} \displaystyle\sum_{(i, j) \in E(G)} X_i X_j \ + \ Y_i Y_j,\]

for some graph \(G\). \(X_i\) and \(Y_i\) denote the Pauli-X and Pauli-Y operators on the \(i\)-th wire respectively.

This mixer was introduced in From the Quantum Approximate Optimization Algorithm to a Quantum Alternating Operator Ansatz by Stuart Hadfield, Zhihui Wang, Bryan O’Gorman, Eleanor G. Rieffel, Davide Venturelli, and Rupak Biswas Algorithms 12.2 (2019).

Parameters

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

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.xy_mixer(graph)
>>> print(mixer_h)
  (0.5) [X0 X1]
+ (0.5) [Y0 Y1]
+ (0.5) [X1 X2]
+ (0.5) [Y1 Y2]
>>> import rustworkx as rx
>>> graph = rx.PyGraph()
>>> graph.add_nodes_from([0, 1, 2])
>>> graph.add_edges_from([(0, 1, ""), (1, 2, "")])
>>> mixer_h = xy_mixer(graph)
>>> print(mixer_h)
  (0.5) [X0 X1]
+ (0.5) [Y0 Y1]
+ (0.5) [X1 X2]
+ (0.5) [Y1 Y2]