qml.qaoa.mixers.xy_mixer¶
- xy_mixer(graph)[source]¶
Creates a generalized SWAP/XY mixer Hamiltonian.
This mixer Hamiltonian is defined as:
HM = 12∑(i,j)∈E(G)XiXj + YiYj,for some graph G. Xi and Yi 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]