Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

QSVT Filtering to solve Graph Partitioning

Tags: algorithm optimization oracle-based

This tutorial explains how to use the Quantum Singular Value Transform (QSVT) to find the ground energy of a given Hamiltonian and solve the Graph Partitioning problem.

The ground-energy algorithm of Lin and Tong Lin & Tong, 2020 finds the lowest eigenvalue of a cost Hamiltonian by filtering. For a given threshold parameter μ\mu, a Linear Combination of Unitaries (LCU) builds a block encoding of H−μIH - \mu I. A QSVT approximation of the sign function turns that encoding into a projector onto the eigenspace on one side of μ\mu. The fraction of shots surviving post-selection tells a classical binary search which way to move μ\mu.

This notebook runs that whole loop on a graph-partitioning instance and demonstrates how to use the Qamomile library through the QSVTEigenstateFilterConverter: build the block encoding, probe one threshold, then let the binary search locate the ground energy on its own.

Problem Settings

Graph partitioning splits the vertices into two equal halves while cutting as few edges as possible. We minimise the number of cut edges subject to an equal-size constraint, which to_hubo absorbs into the objective as a penalty.

See QAOA for Graph Partitioning for more details about the Graph Partitioning problem itself.

Loading...
<Figure size 500x500 with 1 Axes>

Algorithm

Write the Ising cost Hamiltonian as HH and pick a threshold μ\mu. The algorithm works with the shifted operator H−μIH - \mu I, whose eigenvalues are Ei−μE_i - \mu: negative exactly for the eigenstates we want to keep, positive for the rest. Separating the two sides is therefore the job of the sign function.

A block encoding embeds a non-unitary operator as one block of a larger unitary UU. LCU builds it by writing H−μIH - \mu I as a weighted sum of Pauli strings; the price is a subnormalization α′\alpha', so the block actually encoded is the normalized operator (H−μI)/α′(H - \mu I) / \alpha', whose spectrum lies in [−1,1][-1, 1]. The block is selected by an ancilla register — the signal register — measuring all zero.

QSVT then replaces the encoded operator by a polynomial of it. Given phases Φ\Phi, it applies the alternation

R(ϕ0),  U,  R(ϕ1),  U†,  …R(\phi_0),\; U,\; R(\phi_1),\; U^\dagger,\; \dots

and leaves p ⁣((H−μI)/α′)p\!\left((H - \mu I)/\alpha'\right) in the same block. Choosing pp to approximate the sign function,

p ⁣(H−μIα′)≈sign⁡ ⁣(H−μIα′),p\!\left(\frac{H - \mu I}{\alpha'}\right) \approx \operatorname{sign}\!\left(\frac{H - \mu I}{\alpha'}\right),

makes that block a reflection RR: it acts as -1 on the eigenspace below μ\mu and as +1 on the one above.

A reflection is not yet a projector, but Pμ=(I−R)/2P_\mu = (I - R)/2 is, and it is a sum of two unitaries, so a Hadamard test on one extra qubit realises it probabilistically. Starting from the uniform superposition ∣φ0⟩=H⊗n∣0⟩|\varphi_0\rangle = H^{\otimes n}|0\rangle, the fraction of shots with every ancilla measuring zero estimates

P(μ)=∥Pμ∣φ0⟩∥2=#{i:Ei<μ}2n,P(\mu)=\lVert P_\mu |\varphi_0\rangle \rVert^2 = \frac{\#\{i : E_i < \mu\}}{2^n},

the fraction of the spectrum below μ\mu. That single number is the predicate a classical binary search needs: it is bounded away from zero exactly when an eigenstate below μ\mu carries weight in ∣φ0⟩|\varphi_0\rangle.

The search itself is Algorithm 1 of Lin and Tong Lin & Tong, 2020. Eigenvalues live in [c−α,c+α)[c-\alpha, c+\alpha), where α\alpha is the subnormalization of HH alone and cc its constant. Compare a threshold μ\mu to the ground energy λ0\lambda_0: on [c−α,λ0)[c-\alpha, \lambda_0) every eigenvalue is filtered out and P(μ)=0P(\mu)=0; on [λ0,λ1)[\lambda_0, \lambda_1) only the ground eigenspace survives, contributing γ2=d/2n\gamma^2 = d/2^n for a dd-fold degeneracy; above λ1\lambda_1 the probability only grows. The search therefore divides [c−α,c+α)[c-\alpha, c+\alpha) into a grid of spacing hh and moves according to whether P(μ)P(\mu) exceeds τ=γ2/2\tau = \gamma^2/2.

Two inputs make or break it. γ\gamma is a lower bound on the initial overlap and is not known in advance, so it has to be assumed; and hh must be smaller than the (also unknown) spectral gap. Finally, approximation error can make the estimated P(μ)P(\mu) non-monotonic, so the search evaluates a bracket of two consecutive grid points (Bk,Bk+1)(B_k, B_{k+1}) rather than trusting a single one.

Implementation with Qamomile

Qamomile provides the eigenstate-filtering algorithm described above as QSVTEigenstateFilterConverter in qamomile.optimization.qsvt_eigenstate_filter. The converter builds the block encoding of the problem Hamiltonian, synthesizes the filter phases, assembles the probe circuit, and post-selects and decodes the measured samples, so the whole procedure runs directly from the problem instance. Below, we first use it to test one threshold, then open up the building blocks it assembles, and finally drive the binary search with it.

Several internal parameters decide the solution quality, and we explain each of them below, as well as how to choose them.

The constant term of the Ising Hamiltonian is held out of the block encoding. The method’s performance is tied to the subnormalization α\alpha, and an identity term makes it grow, while a constant offset shifts every eigenvalue equally without changing which state is best. normalization (α\alpha) and energy_offset (cc) together bound the spectrum, and that interval is what a threshold gets chosen against.

alpha=3.0  offset=6.0
every eigenvalue lies in [3.0, 9.0]
levels=[3. 5. 7. 9.]  ground=3.0 (2-fold)

One threshold

transpile bakes μ\mu into the circuit, so each threshold needs its own compilation. The filter keeps the eigenspace below μ\mu by default, which is what a search for the minimum eigenvalue (ground energy) wants.

degree and delta are paired: delta sets the width of the polynomial’s transition and degree is the degree of the Chebyshev expansion, which must be large enough to represent it.

The resolution is given by

Δ=min⁡i∣Ei−μ∣α+∣μ−c∣\Delta = \frac{\min_i |E_i-\mu|}{\alpha + |\mu - c|}

where EiE_i are the eigenvalues and the other parameters were defined previously. As often, knowing the resolution requires knowing the ground energy in advance; in practice we need to guess or estimate a bound to ensure beating the resolution. The degree roughly scales as O(1/Δ)O(1/\Delta).

Below we demonstrate the algorithm for μ=4\mu=4. The resolution to beat is then Δ=∣4−3∣3+∣4−6∣=1/5\Delta = \frac{|4-3|}{3 + |4 - 6|} = 1/5, a choice of delta=8 matches the transition to the gap and degree=21 represents it. A bad pairing is not a silent loss of accuracy: it is rejected outright by the ∣p∣≤1|p| \le 1 check.

probe filter: degree=21, delta=8 -> 22 phases
p(mu=4.0) = 0.0310   (exact: 0.0312)

An external library, pyqsp, computes the phase factors corresponding to the polynomial approximation defined by our parameters.

The converter builds the quantum circuit of the projector. The circuit is run and we compute the success probability from the sample counts with the success_probability method. (The exact computation above is only a reference used to check the precision.)

Building blocks

transpile composes three circuits, each wrapping the previous one. Drawing them in that order shows how a block encoding becomes a projector.

To keep the pictures readable the phase vector is shortened to four entries (instead of the 22 used above).

alpha' = 5.0   signal=4  system=6

1. The block encoding UU

The Ising Hamiltonian is written as a linear combination of unitaries and realised as PREPARE⁡\operatorname{PREPARE}, SELECT⁡\operatorname{SELECT}, PREPARE⁡†\operatorname{PREPARE}^\dagger. PREPARE⁡\operatorname{PREPARE} loads the coefficient amplitudes onto the signal register, SELECT⁡\operatorname{SELECT} applies the corresponding Pauli-ZZ term to the system conditioned on the signal, and PREPARE⁡†\operatorname{PREPARE}^\dagger un-computes.

The result is a unitary whose top-left block, the part selected by the signal register measuring all zero, is (H−μI)/α′(H - \mu I)/\alpha'. Nothing outside that block is useful, which is why every shot must be post-selected on it.

<Figure size 1789.5x1320 with 1 Axes>

2. The QSVT alternation

Given the block encoding, qmc.qsvt applies

R(ϕ0),  U,  R(ϕ1),  U†,  R(ϕ2),  U,  …R(\phi_0),\; U,\; R(\phi_1),\; U^\dagger,\; R(\phi_2),\; U,\; \dots

with UU the block encoding built above and R(ϕ)=eiϕ(2Π−I)R(\phi) = e^{i\phi(2\Pi - I)}, where Π\Pi projects the signal register onto all zero. The primitive owns the whole sequence: it allocates its own rotation auxiliary qubit, alternates UU with U†U^\dagger, and applies the phases.

The effect is to replace the encoded operator by a polynomial of it. With the phases pyqsp produced, that polynomial approximates sign\mathrm{sign}, so the good block becomes a reflection about the eigenspace on one side of μ\mu.

<Figure size 3853.5x896 with 1 Axes>

3. The Lin & Tong projector

The goal is to turn the reflection into the projection Pμ=(I±R)/2P_\mu = (I \pm R)/2. However, this projector is not unitary, so no circuit can simply apply it.

The trick is that it is a sum of two unitaries, II and RR, so a Hadamard test can realise it probabilistically. The test uses one extra ancilla, the probe qubit, which coherently selects between the identity and reflection branches: it is put in superposition, the QSVT reflection is applied under its control, and a second Hadamard interferes the two branches. Measuring the probe qubit as zero heralds the branch where PμP_\mu was applied; that is why the algorithm has a success probability at all, and why the post-selection is on the probe and the signal register together.

<Figure size 885x896 with 1 Axes>

The predicate is now everything the classical search needs. B(k) is the single bit “the grid point xkx_k sees the retained eigenspace”, and the loop consumes those bits in consecutive pairs, as described in the Algorithm section.

Result

Running the search brackets the ground energy without ever being told where it is. Feeding the resulting threshold back into the filter then prepares the ground state itself, and sampling it recovers the partition.

grid +3.50..+8.50  G=6  h=1.0  tau=0.0156
  k=2: B(+5.50)=1  B(+6.50)=1  ->  (1,1) U<-3  [+3.50, +6.50]
  refine: first B=1 at k=0 (+3.50)

lambda_0 in [+3.00, +3.50]   true lambda_0 = +3.00
decode filter: degree=41, delta=11 -> 42 phases
kept 531 of 20000 shots, 89.3% at the ground energy
most sampled partition: [1, 2, 5] | cut=3
<Figure size 500x500 with 1 Axes>

The two triangles {0,3,4}\{0,3,4\} and {1,2,5}\{1,2,5\} describe the same split, so either side may come out on top from one run to the next; the corresponding objective (minimal cut) is 3.

Summary

In this notebook, we:

  • Solved a graph-partitioning instance end to end with QSVTEigenstateFilterConverter, recovering the unique optimal split of the triangular prism.

  • Saw why the algorithm is probabilistic: Pμ=(I−R)/2P_\mu = (I - R)/2 is not unitary, so a Hadamard test realises it and every shot must be post-selected on the probe and signal registers together.

  • Saw that every knob traces back to one number, the normalized gap Δ=min⁡i∣Ei−μ∣/α′\Delta = \min_i |E_i - \mu| / \alpha', which is also why holding the Ising constant out of the block encoding matters and why normalization and energy_offset are reported as a pair.

References
  1. Lin, L., & Tong, Y. (2020). Near-optimal ground state preparation. 10.48550/ARXIV.2002.12508