Max-Cut
Source: examples/maxcut/README.md
Find a 2-colour partition of a weighted graph that maximises the total weight of edges crossing the partition.
QUBO formulation
- Input:
num_nodes(int),edges(Vec of flat(i, j, w)triples,3*|E|entries) - Model:
nbinary variables, one per node.x[v] in {0, 1}selects the side of the cut. - Objective: for each edge
(i, j, w), add-w*(x_i + x_j)and+2w*x_i*x_j. Minimising this minimises-sum w*[x_i != x_j], i.e. maximises the cut.
DSL methods used
problem.input()– declare typed calldata inputsproblem.define_model()– allocate binary XQMX modelproblem.stow()– bind intermediate computations to named registersproblem.range()– emit RANGE loopsmodel.linear[i].add()– accumulate linear bias on variable imodel.quadratic[i, j].add()– accumulate quadratic coupling between variables i and jproblem.output()– declare typed output slotsproblem.sample.getline()– read a row from the sample bitstring
Pipeline overview
- CP (
xqcp) – build a random weighted complete graph, declare binary variables (one per node), and add linear/quadratic QUBO terms per edge. - Assemble –
.xqasmtext to bytecode viaxquad.asm - Encode – run encoder on chosen XQVM to produce the XQMX model
- Sample – solver runs SA/QPU/GPU over the model
- Verify – verifier checks constraints and computes energy
- Decode – decoder extracts the 2-colour partition
Usage
uv run python examples/maxcut/runner.py --seed 42
uv run python examples/maxcut/runner.py --n 6 --seed 7 -o /tmp/mc.json
| Flag | Default | Description |
|---|---|---|
--n | 5 | Number of nodes in the complete graph |
--solver | dwave-cpu | Solver backend (see Choosing a solver) |
--interpreter | python | XQVM backend: python or rust |
--seed | 42 | Random seed |
-o | stdout | Write JSON result to file |
Choosing a solver
| Name | Hardware | Install |
|---|---|---|
dwave-cpu | CPU (default) | pip install xquad |
dwave-qpu | D-Wave Leap account | pip install xquad[dwave] |
cuda-gpu | NVIDIA CUDA GPU | pip install xquad[cuda] |
metal-gpu | Apple Silicon (macOS) | pip install xquad[metal] |
See GPU/QPU installation for driver prerequisites and xqsa solver quick-starts for per-solver parameter tuning.
Non-default solvers will not reproduce the canonical output (different
RNG/hardware). example-smoke always runs dwave-cpu.
The canonical output and its invariants are defined in the source README.