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 and alternatives :
selects an alternative; activates the platform; is base value and its platform increment. 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 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 MOIThe 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
function load_qubonotebooks_bootstrap()
candidates = (
joinpath(pwd(), "scripts", "notebook_bootstrap.jl"),
joinpath(pwd(), "..", "scripts", "notebook_bootstrap.jl"),
joinpath(pwd(), "QUBONotebooks", "scripts", "notebook_bootstrap.jl"),
joinpath("/content", "QUBONotebooks", "scripts", "notebook_bootstrap.jl"),
)
for candidate in candidates
if isfile(candidate)
include(candidate)
return nothing
end
end
in_colab = haskey(ENV, "COLAB_RELEASE_TAG") || haskey(ENV, "COLAB_JUPYTER_IP") || isdir(joinpath("/content", "sample_data"))
if in_colab
repo_dir = get(ENV, "QUBONOTEBOOKS_REPO_DIR", joinpath(pwd(), "QUBONotebooks"))
if !isdir(repo_dir)
println("[bootstrap] Cloning JuliaQUBO/QUBONotebooks into $repo_dir")
run(Cmd(["git", "clone", "--quiet", "--depth", "1", "https://github.com/JuliaQUBO/QUBONotebooks.git", repo_dir]))
end
include(joinpath(repo_dir, "scripts", "notebook_bootstrap.jl"))
return nothing
end
error("Could not locate scripts/notebook_bootstrap.jl from $(pwd()).")
end
load_qubonotebooks_bootstrap()
import TOML
tutorial_gate = TOML.parsefile(joinpath(
QUBONotebooksBootstrap.notebook_project_dir("12-Decomposition"), "RELEASE-GATES.toml"))
tutorial_gate["status"] == "ready" || error("Notebook 12 release/install gate is pending: " * tutorial_gate["reason"])
bootstrap_operation() = Base.invokelatest(QUBONotebooksBootstrap.bootstrap_notebook, "12-Decomposition")
BOOTSTRAP = if QUBONotebooksBootstrap.detect_colab()
bootstrap_operation()
else
# Keep transient paths/timings out of the committed local setup output.
QUBONotebooksBootstrap.with_suppressed_output(bootstrap_operation)
end
QUBONOTEBOOKS_REPO_DIR = BOOTSTRAP.repo_dir
JULIA_NOTEBOOKS_DIR = BOOTSTRAP.notebooks_dir
JULIA_PROJECT_DIR = BOOTSTRAP.project_dir
IN_COLAB = BOOTSTRAP.in_colab;Notebook Cell
import Pkg
if @isdefined(JULIA_PROJECT_DIR)
Pkg.activate(JULIA_PROJECT_DIR; io = devnull)
else
Pkg.activate(@__DIR__; io = devnull)
end
Pkg.instantiate(; io = devnull, allow_autoprecomp = false);Source
# QUBONOTEBOOKS_COLAB_IMPORT_CELL
Base.invokelatest(
QUBONotebooksBootstrap.warm_notebook_packages!,
"12-Decomposition",
);Source
include(joinpath(QUBONOTEBOOKS_REPO_DIR,"scripts","decomposition_application.jl"))
const DA=DecompositionApplication
DA.require_released_environment()
instance=DA.instance()
reference=DA.source_reference(instance)
@assert reference.values==[205,259] && reference.platform==1
println((; source_variables=49,child_limit=DA.CHILD_LIMIT,
platform_branch_source_optima=reference.values,source_optimum=reference.optimum))(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:
Evaluating the two platform choices requires 96 option scores and gives , . 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
table="| Department | "*join(instance.alternatives," | ")*" |\n| --- |"*repeat(" ---: |",6)*"\n"
for g in 1:8
table*="| $(instance.departments[g]) | "*join(["$(instance.b[g][i]) / $(instance.c[g][i])" for i in 1:6]," | ")*" |\n"
end
display(DA.ReportTable(table));1. Identify a separator and choose the child capacity¶
The one-choice constraints create interactions within each department. All interactions between departments pass through . Fixing therefore separates the compiled QUBO into eight six-variable components.
The separator strategy enumerates and . 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 -bit separator introduces up to 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
struct PlatformDiagram
svg::String
end
Base.show(io::IO,::MIME"image/svg+xml",figure::PlatformDiagram)=print(io,figure.svg)
svg="""<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="190" viewBox="0 0 1000 190"><rect width="1000" height="190" fill="white"/><text x="500" y="28" text-anchor="middle" font-size="18">Shared platform y: enumerate 0 and 1</text>"""
for g in 1:8
cx=65+(g-1)*124
svg*="""<line x1="500" y1="45" x2="$cx" y2="96" stroke="#63748a"/><rect x="$(cx-55)" y="96" width="110" height="55" rx="8" fill="#eaf1ff" stroke="#325a92"/><text x="$cx" y="119" text-anchor="middle" font-size="13">Department $g</text><text x="$cx" y="139" text-anchor="middle" font-size="12">6 logical binaries</text>"""
end
svg*="""<text x="500" y="178" text-anchor="middle" font-size="13">49-variable parent; eight independent residual groups after conditioning</text></svg>"""
display(PlatformDiagram(svg));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
where ToQUBO chooses the negative coefficients . 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_valueOPTIMAL 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 , 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
correctness=DA.correctness_demo() # exactly one top-level search solve in this notebook
println(correctness);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 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:
| Method | Largest logical child | Source value / gap | Status | Complete attempt time, seconds |
|---|---|---|---|---|
| Direct HiGHS MIPSampler on the QUBO | 49 | 259 / 0 | OPTIMAL | 1.133–1.175 |
| Separator + HiGHS MIPSampler | 6 | 259 / 0 | OPTIMAL | 0.332–0.383 |
| Partition sweeps + HiGHS MIPSampler | 6 | 205 / 54 | LOCALLY_SOLVED | 0.288–0.347 |
| Separator + ExactSampler | 6 | 259 / 0 | OPTIMAL | 0.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
comparison=DA.comparison_report()
if comparison===nothing
display(DA.ReportTable("**Comparison pending:** no authorized measured artifact exists for this rewritten source."))
else
quality_table,cost_table=DA.comparison_tables(comparison)
display(quality_table)
display(cost_table)
println((; julia_script_elapsed_sec=comparison["julia_script_elapsed_sec"],timing_scope=comparison["timing_scope"]))
endOutput
(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 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¶
R. Dechter (1999), Bucket elimination: A unifying framework for reasoning, Artificial Intelligence 113(1–2), 41–85. Dechter (1999).
F. Glover, G. Kochenberger and Y. Du, A Tutorial on Formulating and Using QUBO Models. arXiv:1811.11538.
ToQUBO 0.7.1: reformulation metadata and decoding.
Acknowledgments¶
Maintained by JuliaQUBO with SECQUOIA and PSR Energy.
- Dechter, R. (1999). Bucket elimination: A unifying framework for reasoning. Artificial Intelligence, 113(1–2), 41–85. 10.1016/s0004-3702(99)00059-4