Skip to content

[Rule] GraphPartitioning to QUBO #119

Closed

Description

@zazabap

Source: GraphPartitioning
Target: QUBO
Motivation: Enables solving graph bisection on quantum annealers (D-Wave); natural quadratic formulation with balance penalty.
Reference: Lucas, 2014, Ising formulations of many NP problems, Section 2.2

Reduction Algorithm

Notation:

  • Source: undirected graph $G = (V, E)$, $n = |V|$ (even), $m = |E|$
  • Target: QUBO with $n$ binary variables

Variable mapping: $x_i \in {0, 1}$ for each vertex $i$ ($x_i = 0$ if $i \in A$, $x_i = 1$ if $i \in B$).

Step 1 — Cut-counting term. For each edge $(u, v) \in E$, the expression $x_u + x_v - 2x_u x_v$ equals 1 iff $x_u \neq x_v$ (i.e., the edge is cut). Summing over all edges counts the cut size.

Step 2 — Balance penalty. The quadratic penalty $P(\sum_{i \in V} x_i - n/2)^2$ is zero iff exactly $n/2$ vertices are in $B$. Set $P > m$ to ensure any imbalanced partition has higher cost than any balanced one.

Step 3 — Construct the QUBO Q matrix. Initialize an $n \times n$ upper-triangular matrix $Q$ to zero. For each edge $(u,v) \in E$ with $u < v$:

  • $Q_{uu} \mathrel{+}= 1$, $Q_{vv} \mathrel{+}= 1$ (linear cut terms)
  • $Q_{uv} \mathrel{+}= -2$ (quadratic cut term)

Then add the expanded penalty $P(\sum x_i - n/2)^2 = P(1-n)\sum_i x_i + 2P\sum_{i<j} x_i x_j + Pn^2/4$:

  • For each $i$: $Q_{ii} \mathrel{+}= P(1-n)$
  • For each $i < j$: $Q_{ij} \mathrel{+}= 2P$

Resulting QUBO Q matrix entries:

$$Q_{ii} = \deg(i) + P(1 - n)$$

$$Q_{ij} = \begin{cases} -2 + 2P & \text{if } (i,j) \in E \\ 2P & \text{if } (i,j) \notin E \end{cases} \quad (i < j)$$

The QUBO objective is $\min_{x \in {0,1}^n} x^\top Q x$, equivalent to the original up to the constant offset $Pn^2/4$.

Solution extraction: $A = {i : x_i = 0}$, $B = {i : x_i = 1}$.

Size Overhead

Target metric (code name) Polynomial (using symbols above)
num_vars $n$

Validation Method

Closed-loop testing: solve GraphPartitioning by brute-force, solve the reduced QUBO, and verify both give the same optimal cut. Verify penalty $P$ is large enough.

Example

Source: 6 vertices, 9 edges: $(0,1), (0,2), (1,2), (1,3), (2,3), (2,4), (3,4), (3,5), (4,5)$.

QUBO: 6 variables, penalty $P = 10 &gt; m = 9$.

Degrees: $\deg(0)=2, \deg(1)=3, \deg(2)=4, \deg(3)=4, \deg(4)=3, \deg(5)=2$.

$Q_{ii} = \deg(i) + 10(1-6) = \deg(i) - 50$:

$$Q_{ii} = (-48,\ -47,\ -46,\ -46,\ -47,\ -48)$$

Off-diagonal ($i &lt; j$): $-2 + 2 \cdot 10 = 18$ for edges, $2 \cdot 10 = 20$ for non-edges:

$$Q = \begin{pmatrix} -48 & 18 & 18 & 20 & 20 & 20 \\ & -47 & 18 & 18 & 20 & 20 \\ & & -46 & 18 & 18 & 20 \\ & & & -46 & 18 & 18 \\ & & & & -47 & 18 \\ & & & & & -48 \end{pmatrix}$$

Optimal: $x = (0,0,0,1,1,1)$, cut edges: $(1,3), (2,3), (2,4)$, cut $= 3$, balance: $|B| = 3 = n/2$. Penalty $= 0$, $H = 3$.

Infeasible example: $x = (0,0,0,0,1,1)$ ($|B| = 2 \neq 3$), cut $= 3$ (edges $(2,4), (3,4), (3,5)$), penalty $= 10 \cdot (2 - 3)^2 = 10$, $H = 3 + 10 = 13$.

Activity

  1. added
    ruleA new reduction rule to be added.
    on Mar 5, 2026
  2. zazabap commented on Mar 8, 2026

    @zazabap
    CollaboratorAuthor

    Issue Quality Check — Rule

    Check Result Details
    Usefulness ⚠️ Warn Source "GraphPartitioning" not yet in codebase
    Non-trivial ✅ Pass Penalty-weighted QUBO construction
    Correctness ⚠️ Warn Reference is real but wrong section cited
    Well-written ❌ Fail Example contains arithmetic errors

    Overall: 1 passed, 1 failed, 2 warnings


    Usefulness

    GraphPartitioning does not exist in the codebase. Requires a [Model] issue first.

    Non-trivial

    Constructs a QUBO objective with cut-counting quadratic term and balance-enforcing penalty. Standard but non-trivial encoding.

    Correctness — WARN

    Lucas (2014) is a verified reference (already in bibliography as lucas2014). However, the issue cites "Section 5.2" — the graph partitioning formulation is actually in Section 2.2 of the paper.

    The QUBO formulation H = Σ(xᵤ + x_v − 2xᵤx_v) + P(Σxᵢ − n/2)² is mathematically correct. Setting P > m ensures balance.

    Well-written — FAIL

    Example arithmetic errors:

    The infeasible example x = (0,0,0,0,1,1) claims:

    • "cut = 2" — incorrect. Checking edges: (2,4), (3,4), (3,5) are all cut edges → cut = 3
    • "H = 12" — incorrect. With cut = 3 and penalty = 10·(2−3)² = 10: H = 3 + 10 = 13

    The optimal example (x = (0,0,0,1,1,1), cut = 3, H = 3) is correct.

    Required fixes

    1. Correct section reference from "Section 5.2" → Section 2.2
    2. Fix infeasible example: cut = 3 (not 2), H = 13 (not 12)
    3. File/link a [Model] issue for GraphPartitioning
  3. zazabap commented on Mar 11, 2026

    @zazabap
    CollaboratorAuthor

    Issue Quality Check — Rule

    Check Result Details
    Usefulness ✅ Pass Source problem GraphPartitioning does not yet exist in the reduction graph; novel reduction
    Non-trivial ✅ Pass Constructs quadratic penalty terms and cut-counting objective; genuine structural transformation
    Correctness ❌ Fail Section reference is wrong: the issue cites Section 5.2 of Lucas (2014), but that section covers "Knapsack with Integer Weights" — graph partitioning is in Section 2.2
    Well-written ⚠️ Warn Algorithm gives Hamiltonian formula but does not explicitly show how to populate the QUBO Q matrix entries; some implementability gaps

    Overall: 2 passed, 1 failed, 1 warning


    Usefulness

    The source problem GraphPartitioning does not exist in the codebase (pred show GraphPartitioning fails). Since neither the problem nor any reduction from it exists, this is a novel contribution. However, note that the source model must be implemented first before this rule can be added.

    Non-trivial

    The reduction constructs a QUBO objective with two distinct components:

    1. A cut-counting term $\sum_{(u,v) \in E}(x_u + x_v - 2x_u x_v)$ that counts edges between partitions
    2. A quadratic balance penalty $P(\sum x_i - n/2)^2$ that enforces equal partition sizes

    This involves genuine structural transformation — encoding graph structure and balance constraints into a single unconstrained quadratic objective with penalty terms. Pass.

    Correctness

    Reference verification:

    The issue cites: Lucas, 2014, "Ising formulations of many NP problems" (DOI: 10.3389/fphy.2014.00005), Section 5.2.

    • ✅ The paper exists and is correctly identified — published in Frontiers in Physics, February 2014, by Andrew Lucas. It is already in the project bibliography (references.bib entry lucas2014).
    • ❌ Wrong section number. Section 5.2 of Lucas (2014) covers "Knapsack with Integer Weights" (Equations 47–50). The graph partitioning formulation is in Section 2.2, "Graph Partitioning" (Equations 7–10).

    Formulation verification:

    Despite the wrong section citation, the QUBO formulation in the issue is mathematically correct. Lucas (2014) Section 2.2 uses Ising spins $s_v = \pm 1$ with:

    • $H_A = A(\sum s_i)^2$ (balance penalty)
    • $H_B = B \sum_{(uv) \in E} \frac{1 - s_u s_v}{2}$ (cut edges)

    The issue's formulation uses binary variables $x_i \in {0,1}$ (related by $x = (s+1)/2$), which is the standard QUBO conversion. The resulting Hamiltonian $H = \sum_{(u,v)}(x_u + x_v - 2x_u x_v) + P(\sum x_i - n/2)^2$ is equivalent after this change of variables.

    The penalty condition $P &gt; m$ is sufficient to enforce balance, consistent with the paper's analysis (Equation 10).

    Well-written

    Template completeness: All required sections are present (Source, Target, Motivation, Reference, Reduction Algorithm, Size Overhead, Validation Method, Example). ✅

    Symbol consistency: Symbols $n$, $m$, $G$, $V$, $E$, $P$ are all defined before use. ✅

    Overhead table: num_vars = n is correct — the QUBO has exactly $n$ binary variables (one per vertex). The target's size_fields confirms num_vars is the correct field name. ✅

    Algorithm completeness (⚠️ Warning):
    The Hamiltonian is clearly specified, but the issue does not explicitly describe how to construct the QUBO Q matrix entries ($Q_{ij}$) from the Hamiltonian. An implementer needs to:

    1. Expand the balance penalty $P(\sum x_i - n/2)^2$ into individual quadratic and linear terms
    2. Map all terms to the upper-triangular Q matrix: diagonal entries $Q_{ii}$ and off-diagonal entries $Q_{ij}$

    This step is non-trivial (the penalty expansion produces $O(n^2)$ off-diagonal terms) and should be spelled out for implementability.

    Example quality: The 6-vertex example is well-chosen — small enough to verify by hand, includes both a feasible optimal solution and an infeasible configuration showing the penalty in action. ✅

    Recommendations

    1. Fix the section reference: Change "Section 5.2" to "Section 2.2" in the Reference field.
    2. Add explicit Q matrix construction: Show how to expand the Hamiltonian into QUBO matrix entries. Specifically:
      • Diagonal: $Q_{ii} = \deg(i) + P(1 - n)$ (from cut term + penalty expansion, after collecting linear terms)
      • Off-diagonal for $(i,j) \in E$: $Q_{ij} = -2 + 2P$ (cut term + penalty)
      • Off-diagonal for $(i,j) \notin E$: $Q_{ij} = 2P$ (penalty only)
      • Constant offset: $Pn^2/4$ (can be dropped for optimization)
    3. Consider mentioning that the source model GraphPartitioning must be implemented first (no open issue found for it).
  4. moved this to Backlog in Good issueson Mar 15, 2026
  5. isPANN commented on Mar 20, 2026

    @isPANN
    Collaborator

    Issue Quality Check — Rule

    Check Result Details
    Usefulness ✅ Pass No existing path from GraphPartitioning to QUBO; novel reduction
    Non-trivial ✅ Pass Constructs quadratic penalty terms with cut-counting and balance enforcement
    Correctness ❌ Fail Wrong section citation; infeasible example has arithmetic errors
    Well-written ⚠️ Warn Algorithm omits explicit Q matrix construction; example search space slightly small

    Overall: 2 passed, 1 failed, 1 warning


    Usefulness

    pred path GraphPartitioning QUBO returns no path — this is a novel reduction. GraphPartitioning currently has no outgoing reductions at all, so this would be the first connection from the graph partitioning family to QUBO/quantum annealing problems. Pass.

    Non-trivial

    The reduction constructs a QUBO objective with two distinct components:

    1. A cut-counting term $\sum_{(u,v) \in E}(x_u + x_v - 2x_u x_v)$ that counts edges between partitions
    2. A quadratic balance penalty $P(\sum x_i - n/2)^2$ that enforces equal partition sizes

    This involves genuine structural transformation — encoding graph structure and a hard balance constraint into a single unconstrained quadratic objective with penalty terms. Pass.

    Correctness

    Reference verification:

    • ✅ Lucas (2014), "Ising formulations of many NP problems" (DOI: 10.3389/fphy.2014.00005) — exists, already in bibliography as lucas2014.
    • ❌ Wrong section citation. The issue cites Section 5.2, which is "Knapsack with Integer Weights" (page 14). The graph partitioning formulation is in Section 2.2 (page 6, Equations 7–9).

    Formulation verification:

    Lucas (2014) Section 2.2 uses Ising spins $s_v = \pm 1$ with $H_A = A(\sum s_i)^2$ (balance) and $H_B = B \sum_{(uv)} (1 - s_u s_v)/2$ (cut). Under the standard substitution $s_i = 1 - 2x_i$, this becomes exactly the issue's QUBO formula. ✅

    Penalty condition: $P &gt; m$ is sufficient to enforce balance. ✅

    Overhead verification: num_vars = n maps to num_vars = num_vertices in code. GraphPartitioning has num_vertices() getter; QUBO has num_vars as its size field. The QUBO has exactly $n$ binary variables (one per vertex). ✅

    Infeasible example errors:

    The infeasible example $x = (0,0,0,0,1,1)$ (partition B = {4,5}) claims "cut = 2, H = 12". Verified by enumeration:

    • Cut edges crossing the partition: $(2,4), (3,4), (3,5)$ → cut = 3 (not 2)
    • Balance penalty: $10 \cdot (2 - 3)^2 = 10$
    • H = 3 + 10 = 13 (not 12)

    The optimal example $x = (0,0,0,1,1,1)$ with $H = 3$ is correct (confirmed by brute-force enumeration of all 64 configurations; tied with complement $(1,1,1,0,0,0)$).

    Well-written

    Required sections: Source ✅, Target ✅, Motivation ✅, Reference ✅, Reduction Algorithm ✅, Size Overhead ✅, Validation Method ✅, Example ✅ — all present and substantive.

    Symbol consistency: Symbols $n$, $m$, $G$, $V$, $E$, $P$ are defined before use. Overhead metric num_vars matches QUBO's size field. ✅

    Algorithm completeness (⚠️ Warning): The Hamiltonian formula is clearly specified, but the issue does not show how to populate the QUBO Q matrix entries from the expanded Hamiltonian. An implementer needs to:

    1. Expand the penalty $P(\sum x_i - n/2)^2$ into individual quadratic and linear terms
    2. Map all terms to the upper-triangular Q matrix: diagonal $Q_{ii}$ and off-diagonal $Q_{ij}$

    This is non-trivial (the penalty expansion produces $O(n^2)$ off-diagonal terms).

    Example quality (⚠️ Warning): Search space = $2^6 = 64$, below the recommended 128. There are 20 feasible balanced partitions and 18 suboptimal ones, which is sufficient for testing diversity. Recommend using 7–8 vertices for a stronger example.

    Required fixes

    1. Correctness: Change section reference from "Section 5.2" → Section 2.2
    2. Correctness: Fix infeasible example: cut = 3 (not 2), H = 13 (not 12)

    Recommendations

    1. Add explicit Q matrix construction showing how to compute $Q_{ii}$ and $Q_{ij}$ entries
    2. Consider a slightly larger example (7–8 vertices) for search space ≥ 128
  6. isPANN commented on Mar 20, 2026

    @isPANN
    Collaborator

    Fix-issue changelog

    • Reference: Changed "Section 5.2" → "Section 2.2" (Section 5.2 is Knapsack with Integer Weights; graph partitioning is in Section 2.2)
    • Algorithm: Added Step 3 with explicit Q matrix construction procedure and closed-form Q matrix entries
    • Example: Fixed infeasible example arithmetic: cut = 3 (not 2), H = 13 (not 12)
    • Example: Added explicit Q matrix, degree table, and diagonal/off-diagonal computation for the 6-vertex instance
    • Example: Added cut edge enumeration for optimal solution

    Applied by /fix-issue.

  7. added
    GoodAn issue passed all checks.
    and removed on Mar 20, 2026
  8. moved this from Backlog to Ready in Good issueson Mar 20, 2026
  9. moved this from Ready to In progress in Good issueson Mar 20, 2026
  10. added a commit that references this issue on Mar 20, 2026
  11. moved this from In progress to Review pool in Good issueson Mar 20, 2026
  12. moved this from Review pool to Under review in Good issueson Mar 20, 2026
  13. moved this from Under review to Final review in Good issueson Mar 20, 2026
  14. moved this from Final review to OnHold in Good issueson Mar 21, 2026
  15. GiggleLiu commented on Mar 21, 2026

    @GiggleLiu
    Contributor

    Please kindly check the following items (PR #706):

    • Paper (PDF): check definition, proof sketch, and example figure
    • CLI demo (build from source: cargo install --path problemreductions-cli):
      pred show GraphPartitioning
      pred create --example GraphPartitioning -o instance.json
      pred reduce instance.json GraphPartitioning QUBO -o reduced.json
      pred solve reduced.json QUBO
    • Implementation (Optional): spot-check the source files changed in this PR for correctness

    💬 Join the discussion on Zulip — feel free to ask questions or leave feedback there.

  16. moved this from OnHold to Done in Good issueson Mar 21, 2026
  17. added a commit that references this issue on Mar 21, 2026
    d111c55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoodAn issue passed all checks.ruleA new reduction rule to be added.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions