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.

QUBO Decomposition and Reconstruction

Maintained by the JuliaQUBO organization
SECQUOIA  ·  PSR Energy

Open In Colab

Use QUBODecomposition when a large QUBO can be solved through smaller conditional problems. This guide takes a JuMP model through compilation, separator selection, optimizer configuration and decoding. You should be comfortable with JuMP and QUBO objectives.

The model

Eight departments each choose one of six service alternatives. A shared platform changes their values and costs 60 annual net-value points to activate. The coefficients are synthetic; their structure lets us check the answer independently.

For departments g=1,…,8g=1,\ldots,8 and alternatives i=1,…,6i=1,\ldots,6:

max⁡x,yf(x,y)=∑g=18∑i=16(bgi+cgiy)xgi−Ky,subject to∑i=16xgi=1(g=1,…,8),xgi∈{0,1},y∈{0,1}.\begin{aligned} \max_{x,y}\quad & f(x,y)=\sum_{g=1}^{8}\sum_{i=1}^{6}(b_{gi}+c_{gi}y)x_{gi}-Ky,\\ \text{subject to}\quad & \sum_{i=1}^{6}x_{gi}=1\quad(g=1,\ldots,8),\\ &x_{gi}\in\{0,1\},\qquad y\in\{0,1\}. \end{aligned}

xgix_{gi} selects an alternative; yy activates the platform; bgib_{gi} is base value and cgic_{gi} its platform increment. K=60K=60 uses the same units. There are 49 original binary variables. We set max_variables=6, so each exhaustive child solve handles at most six logical variables, or 26=642^6=64 assignments.

Setup

Open this notebook in Julia 1.10.11 or 1.12.6 using the notebook environment, or use the Colab badge above. The setup cells activate that environment. The code examples use notebooks_jl/ as their working directory and these imports:

using JuMP, QUBODecomposition, QUBODrivers, QUBOTools, ToQUBO
using TOML
import MathOptInterface as MOI

The notebook runs the application implementation once. The excerpts below unpack its core API calls so you can adapt the same sequence to your own model.

Notebook Cell
Notebook Cell
Source
Source
(source_variables = 49, child_limit = 6, platform_branch_source_optima = [205, 259], source_optimum = 259)

Data and a reference answer

Each entry is base value / platform increment. With the platform off, every department prefers its first alternative; with it on, the sixth alternative becomes best.

For this model we can compute the source optimum without a QUBO solver:

F(y)=∑gmax⁡i(bgi+cgiy)−Ky,f∗=max⁡{F(0),F(1)}.F(y)=\sum_g\max_i(b_{gi}+c_{gi}y)-Ky,\qquad f^*=\max\{F(0),F(1)\}.

Evaluating the two platform choices requires 96 option scores and gives F(0)=205F(0)=205, F(1)=259F(1)=259. We will use 259 to check the decoded solution. Load the coefficients used in the table:

data = TOML.parsefile(joinpath("..", "notebooks_data", "decomposition_platform.toml"))
d = (b=data["base"], c=data["platform_increment"], cost=data["platform_cost"])
Source
Loading...

1. Identify a separator and choose the child capacity

The one-choice constraints create interactions within each department. All interactions between departments pass through yy. Fixing yy therefore separates the compiled QUBO into eight six-variable components.

The separator strategy enumerates y=0y=0 and y=1y=1. In each branch it solves those components, restores the fixed bit and compares the reconstructed full objectives. Conditioning includes the platform-to-department terms and the platform cost; simply deleting the platform variable would change the objective.

Here max_variables=6 matches the largest residual component. It limits child size, not the 49-variable parent. Two branches and eight components require 16 child solves, each enumerating at most 64 assignments. More generally, a kk-bit separator introduces up to 2k2^k branches, so a small residual problem can still be expensive if its separator is large.

Complete coverage with globally solved children gives a global QUBO certificate. Interrupted coverage gives a candidate rather than that certificate. This is the conditioning tradeoff described by Dechter (1999).

Source
Loading...

2. Formulate and compile the JuMP model

ToQUBO turns the one-choice constraints into automatic penalties. For this maximization problem, the compiled objective has the form

Q(x,y)=f(x,y)+∑gpg(∑ixgi−1)2,Q(x,y)=f(x,y)+\sum_g p_g\left(\sum_i x_{gi}-1\right)^2,

where ToQUBO chooses the negative coefficients pgp_g. Build the source model as usual:

compiler = ToQUBO.Optimizer()
model = Model(() -> compiler)
@variable(model, x[1:8, 1:6], Bin)
@variable(model, y, Bin)
@objective(model, Max,
    sum((d.b[g][i] + d.c[g][i] * y) * x[g, i]
        for g in 1:8, i in 1:6) - d.cost * y)
@constraint(model, [g=1:8], sum(x[g, i] for i in 1:6) == 1)

optimize!(model)
target = MOI.get(compiler, ToQUBO.Attributes.TargetModel())

With no child optimizer attached to compiler, this optimize! call compiles the model. We solve target separately in the next step; this call does not populate a solved JuMP source model.

Locate the platform in the compiled variables

Source JuMP indices, compiled indices and indices in a copied optimizer need not agree. Use the compiler’s reformulation metadata to locate the target bit for the source variable y:

metadata = ToQUBO.reformulation_metadata(compiler)
platform_entry = only(e for e in metadata["original_variables"]
                      if e["id"] == index(y).value)
platform_bit = MOI.VariableIndex(only(platform_entry["target_variables"]))

This example’s binary variables have one-to-one identity encodings: the compiled model still has 49 variables, and removing platform_bit leaves eight six-variable components. The implementation checks that structure before solving. For a model with integer encodings or auxiliary variables, inspect its target dimensions, expansion metadata and interaction graph instead of assuming the source partition survived compilation.

3. Configure, copy and solve

Pass a factory that creates a fresh ExactSampler for each child. Choose :separator and set limits for this model’s two branches:

optimizer = QUBODecomposition.Optimizer(
    child_optimizer = () -> QUBODrivers.ExactSampler.Optimizer(),
    strategy = :separator,
    max_variables = 6,
    max_separator_size = 1,
    max_child_calls = 16,
    max_candidate_evaluations = 1029,
)
index_map = MOI.copy_to(optimizer, target)

MOI.copy_to returns the map from target variables to optimizer variables. The separator attribute takes positions in the optimizer’s variable order, so apply both mappings:

labels = collect(QUBOTools.variables(optimizer))
position = Dict(v => i for (i, v) in enumerate(labels))
separator = [position[index_map[platform_bit]]]
MOI.set(optimizer, MOI.RawOptimizerAttribute("separator"), separator)

MOI.set(optimizer, MOI.TimeLimitSec(), 30.0)
MOI.optimize!(optimizer)
status = MOI.get(optimizer, MOI.TerminationStatus())

The 1029-candidate limit covers 1024 child rows, the initial parent assignment, and full-objective evaluations before and after each of the two branches. Time or work limits may stop branch coverage early; check status before claiming optimality.

4. Reconstruct and decode the solution

QUBODecomposition reconstructs a full target assignment. Read it through index_map, then give ToQUBO a dictionary keyed by the original target indices:

MOI.get(optimizer, MOI.ResultCount()) > 0 || error("No solution returned")
target_variables = MOI.get(target, MOI.ListOfVariableIndices())
target_state = Dict(v => MOI.get(optimizer, MOI.VariablePrimal(), index_map[v])
                    for v in target_variables)
decoded = ToQUBO.project_original_state(compiler, target_state)

x_value = [decoded[index(x[g, i])] for g in 1:8, i in 1:6]
y_value = decoded[index(y)]
feasible = all(v -> v in (0, 1), x_value) && y_value in (0, 1) &&
           all(g -> sum(x_value[g, :]) == 1, 1:8)
source_value = sum((d.b[g][i] + d.c[g][i] * y_value) * x_value[g, i]
                   for g in 1:8, i in 1:6) - d.cost * y_value

OPTIMAL certifies the compiled QUBO. Check the decoded domains, source constraints and source objective as well: a penalized objective value alone does not establish source feasibility.

The executed example below returns OPTIMAL, selects the sixth alternative for every department with y=1y=1, and gives source value 259, matching the reference. Both branches are certified; 16 child solves examine 1024 assignments. Expand its output for the complete result record.

Source
Output
Dict{String, Any}("attempted_child_calls" => 16, "method" => "separator_exact", "public_status" => "OPTIMAL", "completed_child_calls" => 16, "construction_compile_sec" => 12.750449738, "logical_global_proof" => true
, "compiled_dimension" => 49, "maximum_actual_child_dimension" => 6, "end_to_end_sec" => 18.71927812, "required_branches" => 2, "actual_exact_assignments" => 1024, "compiler_search_dispatches" => 0, "reported_compilation_sec" => 2.766385599, "child_public_statuses" => ["OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL", "OPTIMAL"], "source_objective" => 259.0, "backend_binary_upper_bound" => 6, "reserved_parent_evaluations" => 1029, "source_choices" => 
[[6], [6], [6], [6], [6], [6], [6], [6]], "automatic_penalties" => [-1492.0, -1492.0, -1492.0, -1492.0, -1492.0, -1492.0, -1492.0, -1492.0], "completed_branches" => 2, "reserved_child_calls" => 16, "copy_solve_sec" => 5.254032133, "mip_search_nodes" => "not reported by this public sampler path; not equated to exhaustive assignments", "iterative_penalty_refinements" => 0, "result_construction_sec" => 0.140434146, "reserved_exact_assignments" => 1024, "start_handling" => "Composite starts at zero; ExactSampler enumerates every child assignment", "source_feasible" => true, "outcome" => "complete", "source_platform" => 1.0, "source_dimension" => 49, "compiled_objective" => 259.0, "source_gap" => 0.0, "source_residuals" => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], "source_optimum" => 259, "parent_evaluations" => 1029, "decode_audit_sec" => 0.574355359, "child_limit" => 6)

5. Compare with partition sweeps

When no small separator fits your child solver, partition sweeps offer a heuristic alternative. They fix the variables outside each block to the incumbent, solve that block, and accept improving full assignments. The comparison uses one block per department followed by the platform singleton.

This model shows why exact children do not make that search globally exact. At the best y=0y=0 assignment, each department is already locally optimal. Flipping the platform alone loses 60 points; reaching 259 requires changing the platform and departmental choices together. The sweeps stop at 205 with LOCALLY_SOLVED.

The retained comparison has one warmup and three measured runs per method. For this maximization problem, gap = 259 − source value:

MethodLargest logical childSource value / gapStatusComplete attempt time, seconds
Direct HiGHS MIPSampler on the QUBO49259 / 0OPTIMAL1.133–1.175
Separator + HiGHS MIPSampler6259 / 0OPTIMAL0.332–0.383
Partition sweeps + HiGHS MIPSampler6205 / 54LOCALLY_SOLVED0.288–0.347
Separator + ExactSampler6259 / 0OPTIMAL0.027–0.028

Time ranges span the three measured runs and include model construction, automatic compilation, solving, decoding and source checks. All runs completed within their cooperative 30-second deadline. The HiGHS rows use the same backend settings, including one thread and zero MIP gaps. MIPSampler linearizes the QUBO exactly into a MILP; HiGHS does not directly solve the binary quadratic objective. The direct baseline therefore solves the penalized QUBO, not a separately formulated source MILP.

Both direct HiGHS and complete separator conditioning reach the same optimum; decomposition uses smaller children and was faster in these measured runs. These observations describe one synthetic instance with a cheap source oracle, measured on a shared development machine. The short separator timings do not rank the separator backends generally. Use the example to understand capacity and guarantees, then compare approaches on your own model. The retained comparison report contains all runs, timing details and provenance; the expandable output below holds the measured rows.

Source
Output
Loading...
Loading...
(julia_script_elapsed_sec = 40.975777625, timing_scope = "Per attempt: fresh construction, automatic compilation, solve, decode and source audit; Julia script elapsed includes imports/plan/attempt writes until final-summary construction; launcher process.log records full process elapsed including startup and final writes.")

Apply the pattern to your model

  • Check the compiled graph. Plan around the target QUBO, including encoding and auxiliary variables. A source-level grouping is a starting point, not a substitute for that check.

  • Choose a strategy that fits. Use components when they are independent, a separator when conditioning leaves manageable components, or sweeps when you can accept a heuristic. See the strategy guide.

  • Set work limits with child size. An exhaustive child costs up to 2n2^n assignments; separator branching adds another exponential factor. The budget guide explains shared limits and interruption.

  • Inspect the result before using it. Read status and coverage, then decode and check the source model. The result guide explains the returned metadata; the guarantee guide states when a global certificate follows.

Summary

Compile the model, find the separator in target coordinates, copy it with MOI.copy_to, and map the separator into optimizer positions before solving. Decode the reconstructed target assignment and check it against the source constraints and objective.

For this 49-variable model, complete conditioning on one bit lets six-variable exact children certify the optimum. Partition sweeps use the same capacity with a weaker guarantee: exactness of a block does not establish optimality of the coupled parent.

References

Acknowledgments

Maintained by JuliaQUBO with SECQUOIA and PSR Energy.

References
  1. Dechter, R. (1999). Bucket elimination: A unifying framework for reasoning. Artificial Intelligence, 113(1–2), 41–85. 10.1016/s0004-3702(99)00059-4