Tutorials
qcr:2606.93170.1

Swap Networks for Limited Connectivity

Real quantum hardware rarely lets every qubit interact directly with every other; qubits are laid out with limited connectivity, so two-qubit gates between distant qubits must be routed by physically swapping qubit states until the operands are adjacent. This Cirq tutorial demonstrates swap networks, a structured and highly efficient way to perform such routing, using the acquaintance submodule. As a concrete application it implements a single round of QAOA for Maximum Cut on a linearly connected device, even when the underlying problem graph is arbitrary and dense. The key idea is that a carefully designed sequence of swaps brings every pair of qubits into adjacency exactly once, so all the required two-qubit interaction terms of the cost Hamiltonian can be applied along the way without any wasted movement. The example shows how to express the desired circuit (alternating mixing and phase-separation layers) abstractly in terms of logical qubits, then compile it onto a line of physical qubits using acquaintance strategies that interleave the interaction gates with the swaps. It is a practical, advanced look at the routing and compilation problem that every near-term algorithm must solve to run on connectivity-limited hardware.
Compilation
Qubit
Circuit-based
Uploaded 3 days ago
12
Views
GitHub4990
Citing this entry? Use this QCR ID
Uploaded by
QL
QCR Librarian

Overview

quantumlib/Cirq
49901228
README.md

Swap Networks for Limited Connectivity

Real quantum hardware rarely lets every qubit interact directly with every other; qubits are laid out with limited connectivity, so two-qubit gates between distant qubits must be routed by physically swapping qubit states until the operands are adjacent. This Cirq tutorial demonstrates swap networks, a structured and highly efficient way to perform such routing, using the acquaintance submodule. As a concrete application it implements a single round of QAOA for Maximum Cut on a linearly connected device, even when the underlying problem graph is arbitrary and dense. The key idea is that a carefully designed sequence of swaps brings every pair of qubits into adjacency exactly once, so all the required two-qubit interaction terms of the cost Hamiltonian can be applied along the way without any wasted movement. The example shows how to express the desired circuit (alternating mixing and phase-separation layers) abstractly in terms of logical qubits, then compile it onto a line of physical qubits using acquaintance strategies that interleave the interaction gates with the swaps. It is a practical, advanced look at the routing and compilation problem that every near-term algorithm must solve to run on connectivity-limited hardware.

Run it

pip install -r requirements.txt
python swap_networks.py

Source and license

Imported from examples/swap_networks.py in quantumlib/Cirq at v1.6.1, under the Apache License 2.0. Original authors: The Cirq Developers. The upstream LICENSE is included alongside this example.

Join the Discussion

Comments (0)

No comments yet. Be the first to share your thoughts!

Indexed by QCR Librarian

This entry was created automatically from publicly available records. QCR links to public sources and only stores repository content where the license permits redistribution.

Versions

v1 Latest
Jun 15, 2026
qcr:2606.93170.1

Cite all versions? Use the base QCR ID to always reference the latest version of this entry.

Tools used

Cirq

Keywords

swap-networks
connectivity
routing
qaoa
compilation

You may also like5