SQWLib: Efficient Szegedy Walk Simulator
- SQWLib is a Python library that implements Szegedy quantum walk simulations and QPE protocols without constructing full N²×N² unitary matrices.
- It employs a matrix-based state representation with structured arrays to achieve O(N²) time for dense graphs and O(|E|) scaling for sparse graphs.
- The library supports multiple formulations—including single-step, double-step, and similarity-transformed walks—and integrates efficient QPE for advanced algorithm simulations.
Searching arXiv for the cited SQWLib/SQUWALS papers to ground the article. SQWLib is a Python library that implements the full simulation framework developed in “Efficient Simulation of Szegedy Quantum Walk Formulations and Algorithms.” It is a classical, NumPy/SciPy–based simulator specialized for Szegedy-type discrete-time quantum walks and for algorithms that couple these walks to quantum phase estimation (QPE). Its defining design goal is to avoid constructing the full unitary evolution operator of size for a graph with nodes, while supporting several different but spectrally equivalent walk formulations. For dense graphs it achieves time and memory, and for sparse graphs its cost scales as , where is the number of undirected edges (Ortega et al., 12 Jun 2026).
1. Formal setting and supported walk formulations
SQWLib is built around Szegedy’s quantization of a classical Markov chain. Given a graph with nodes and a column-stochastic transition matrix , the walk acts on the doubled Hilbert space
For each node , one defines
The projector onto the span of the 0 is
1
and the basic reflection and swap operators are
2
SQWLib supports the principal Szegedy walk formulations used in the literature.
| Formulation | Expression | Role |
|---|---|---|
| Single-step Szegedy operator | 3 | Common one-step evolution |
| Double-step Szegedy operator | 4 | Szegedy’s original two-reflection form |
| Similarity-transformed walk | 5 | Used in QSA and related algorithms |
For reversible Markov chains with stationary distribution 6, the walk admits the stationary eigenstate
7
Within the dynamical subspace
8
this is the unique eigenstate with eigenvalue 9 for 0, and measuring the first register of 1 yields a sample from the classical stationary distribution. SQWLib also supports the update-operator formulation based on 2 and
3
for which the stationary state takes the form
4
This state is independent of the Markov chain outside the amplitudes 5, a property used directly in quantum simulated annealing (Ortega et al., 12 Jun 2026).
2. State representation and primitive operators
The library’s efficiency derives from representing walk states as structured arrays rather than as flat vectors. Any state
6
is stored as an 7 matrix 8 with entries
9
Under this convention, the column index corresponds to the first register and the row index to the second register. This layout makes several basic operations immediate: the swap 0 becomes matrix transposition, 1, and the simple reflection 2 is implemented by multiplying all rows except the first by 3 (Ortega et al., 12 Jun 2026).
The nontrivial primitive is the reflection 4 about 5. SQWLib implements it through an expansion–recomposition scheme. For operators of the form
6
with
7
the expansion step computes coefficients
8
and the recomposition step forms 9. Numerically, expansion is an element-wise multiplication followed by summation along an axis, while recomposition is a broadcasting operation. For 0, one uses 1, with
2
SQWLib further introduces two concrete unitary implementations of the update operator 3. The first, 4, is defined on the update subspace
5
and acts as the identity on 6. The second, 7, is a block-diagonal Householder construction,
8
with 9 and 0. The paper states that 1 is more efficient than 2, since it requires fewer expansion/recomposition steps and has the self-inverse property (Ortega et al., 12 Jun 2026).
3. Dense and sparse simulation framework
The central algorithmic principle is to simulate the action of primitive operators rather than assemble full 3 unitary matrices. In dense settings, all major objects—4, 5, and the state matrices 6—are 7 dense arrays. Each basic operator touches each entry at most a constant number of times, so time and memory per walk step are 8. The paper characterizes this as optimal, because the minimal description of a dense Markov chain already requires 9 numbers (Ortega et al., 12 Jun 2026).
For sparse graphs, SQWLib exploits the fact that the walk is confined to a reduced subspace
0
where 1 is the adjacency matrix of the undirected backbone. Instead of storing an 2 matrix, the state is stored as a reduced vector of length 3. The implementation uses three auxiliary structures: STARTS, a list of offsets marking the start of each block; SIZES, the block sizes; and PERMUTATION, a permutation array that maps each reduced index to the index corresponding to the swapped edge.
Under this representation, swap 4 is implemented by applying PERMUTATION, while 5 multiplies all entries by 6 and then flips the sign back on the indices corresponding to 7. Expansion–recomposition becomes a blockwise computation using numpy.add.reduceat and blockwise broadcasting. Memory consumption is therefore 8, and time per operator is also 9. For bounded-degree graph families, where 0, the simulation becomes linear in the number of nodes. The paper also notes that even when the update operator 1 requires adding edges from node 2 to all nodes so that 3, this adds only 4 entries and preserves overall 5 scaling (Ortega et al., 12 Jun 2026).
4. Quantum phase estimation layer
A defining extension of SQWLib beyond earlier simulators is its integrated QPE framework. For a unitary 6, the library represents a joint QPE state as
7
where the phase index 8 occupies one tensor axis and each column contains an entire Szegedy walk state. This tensorized representation separates the two computational roles: QPE operations act along the phase axis, while walk operators act within each column or batch (Ortega et al., 12 Jun 2026).
Controlled powers of the walk are simulated without constructing controlled-unitary matrices. In the general implementation, one evolves a batch of walk states in parallel: after each step, the leftmost column is removed, so that after 9 iterations the column with index 0 has received exactly 1 applications of 2. For the common direct-QPE case with input 3, SQWLib uses a simpler method: it stores the successive states 4 across the phase axis and then applies inverse QFT numerically.
The Hadamard layer 5 and QFT/QFT6 are implemented via Walsh–Hadamard transforms and FFTs along the phase axis. The framework also supports multiple phase registers. With 7 phase registers of 8 qubits each, the total number of controlled-9 applications is 0, rather than 1. This construction is used in the approximate reflection operator that underlies the walk-based quantum search algorithm simulated in the package (Ortega et al., 12 Jun 2026).
5. Implemented algorithms and representative results
The paper presents SQWLib as a simulator not only for plain walk dynamics but for full algorithmic protocols built from Szegedy walks and QPE.
| Algorithm | Demonstration setup | Reported outcome |
|---|---|---|
| Marked-node detection | 2D lattice, 2, 3 or 4, 5 | For 6, phase outcome 7 has probability 8; for 9, outcomes concentrate on non-zero phases |
| Quantum simulated annealing | 1D Ising spin glass, 00, 01, 02, 5 temperature steps from 03 to 04 | Marginals match the classical stationary distribution; phase-0 probability at each step is 05; joint probability over all 5 steps is 06 |
| Quantum search on graphs | Same Ising system, 07, 08, varying number of phase registers 09 | Larger 10 makes the success-probability curve approach the theoretical amplitude-amplification behavior |
For marked-node detection, the underlying transition matrix is modified so that marked vertices become absorbing sinks,
11
The algorithm prepares a uniform superposition over unmarked 12 states. If there are no marked nodes, that state is an eigenstate with eigenvalue 13, so QPE returns phase 14. If marked nodes are present, the state has no support on the eigenspace with eigenvalue 15, and QPE yields non-zero phase with high probability given sufficient precision.
For quantum simulated annealing, SQWLib uses the similarity-transformed walk 16 built from a Metropolis–Hastings chain. The acceptance probabilities are
17
and the transition matrix is
18
The library simulates the standard QPE-with-postselection protocol across a temperature schedule. In the demonstrated 1D Ising spin-glass instance,
19
the measured marginals agree closely with the classical Boltzmann distributions at each intermediate temperature.
For quantum search on graphs, SQWLib implements approximate amplitude amplification using an oracle
20
together with an approximate reflection around the stationary state 21 obtained through QPE. The paper reports that as the number of phase registers increases, the success-probability curve approaches the theoretical one for perfect amplitude amplification; at the first maximum, the measured distribution over marked nodes matches the stationary distribution restricted to the marked subset (Ortega et al., 12 Jun 2026).
6. Relation to SQUWALS, implementation dependence, and limitations
SQWLib is the direct successor to the earlier simulator “SQUWALS: A Szegedy QUantum WALks Simulator,” which already provided a memory-saving classical simulator for the original Szegedy walk and showed 22 scaling in both time and memory for dense graphs (Ortega et al., 2023). SQUWALS supported the reflection 23, swap 24, simple oracles, mixed-state evolution, the semiclassical Szegedy walk, and high-level applications such as quantum PageRank. Its central contribution was the matrix-state representation that replaced 25 operator storage with 26 array operations (Ortega et al., 2023).
SQWLib extends that earlier framework in four explicit directions. First, it adds operator-level generality by introducing efficient simulation for the primitive operators 27, 28, and 29, which allows simulation of a broader class of Szegedy formulations. Second, it adds a NumPy-based sparse-state representation in the reduced subspace 30, bringing time and memory down to 31. Third, it integrates a QPE framework, including controlled-32 simulation, multiple phase registers, and approximate reflections. Fourth, it analyzes implementation dependence by providing both 33 and 34: the reported QSA results are independent of whether 35 or 36 is used when measurement is included at each step, whereas some heuristic multi-chain behaviors without measurement are implementation-dependent (Ortega et al., 12 Jun 2026).
The package is therefore not a framework for controlling quantum hardware; it is a classical simulator for numerical exploration of Szegedy-walk-based algorithms. The paper also states several limitations. Practical system size remains bounded by memory: 37 scaling for dense graphs limits 38 to a few thousands depending on the machine, and sparse simulations are limited by 39 and by the overhead of reduced-subspace tensors. The implementation assumes column-stochastic transition matrices and is tailored to Markov-chain-derived Szegedy walks. Alternative formulations that strongly exploit the second register may behave differently depending on how 40 is defined. Within those constraints, SQWLib is presented as a practical tool for studying Szegedy-walk-based algorithms numerically beyond purely analytical treatments; the code and scripts are available at https://github.com/qDNA-yonsei/SQWLib (Ortega et al., 12 Jun 2026).