Docs

QUBO & diagonal optimization

Optimization mode shines when your objective is a function of the measured output — a QUBO / Ising cost, a max-cut value, any cost you can read off the configuration. Here the substrate physically realizes the response landscape and the runtime drives it toward a low-cost state.

The one rule that makes it work

Send, as the measured statistic, the same object your score rates. For a QUBO you score a sampled bitstring — so pass that bitstring as p_hat, not a separate continuous reading. If the pool elite-weights one object while the score rates another, the target it builds will not correspond to low-cost configurations and the loop will not descend. This is the most common mistake.

copyfrom swc import SWCOptimizer
import numpy as np

opt = SWCOptimizer(license_key="EVAL-...", n=N)   # optimization mode (default)
phi = opt.start([1.5708]*N)
for _ in range(150):
    p   = read_power(phi)                # substrate response in [0,1]^N
    bits = (np.random.random(N) < p).astype(float)   # one sampled candidate
    score = -qubo_energy(bits, Q)        # MAXIMIZE -energy == minimize cost
    phi = opt.step(list(bits), score=score)   # send the SCORED bits as p_hat
opt.end()
# final solution = rounded readout at the final configuration
x_final = (read_power(phi) > 0.5).astype(float)

Choosing the estimator

Optimization mode builds its target from the scored samples in one of two ways. You select it with the estimator option; the default is unchanged from earlier builds.

  • estimator="elite" (default) — keeps a small cross-round pool of the best-scoring samples and drives toward their score-weighted mean. Robust, low-memory, and the right choice at small to moderate dimension or when each round contributes one sample.
  • estimator="smart" — score-weights a sliding window of recent samples (all of them, not just the best). In benchmarks this reaches usable solutions at ~n1.2 total measurements where the elite estimator scales near n2. Prefer it at larger dimension and when total measurement count is the binding cost.
copy# hosted endpoint: pass it in the session config
opt = SWCOptimizer(license_key="EVAL-...", n=N,
                   config={"estimator": "smart"})

# offline build: pass it to the constructor
from swc import SWCRuntime
rt = SWCRuntime(n=N, mode="optimization", estimator="smart")

Both estimators are exact across the hosted endpoint and the offline build. An unrecognized value falls back to "elite". See the baselines page for the measured scaling of each.

Where it wins — and where it does not

In benchmarks, this reaches usable QUBO solutions and beats equal-sample random search by an order of magnitude. A score-weighted measurement-feedback estimator reaches a usable solution at ~n1.2 total measurements within its envelope — sub-quadratic, holding on structured and coupled problems — where sequential search needs O(n²) for comparable quality. Against a strong classical solver (simulated annealing) given ample budget, SA remains competitive on solution quality — we say so plainly. The runtime’s edge is a different axis: performance under a starved budget and tight deadline. Because the substrate updates the whole configuration in parallel, the runtime’s cost per round is roughly constant in dimension, while a sequential solver pays per-evaluation cost that buys fewer and fewer useful steps as the problem grows. The consequence: under a starved budget where a classical solver has too few evaluations to search and stalls, the runtime keeps improving as dimension grows — it overtakes SA past a crossover and the margin widens with size. At a few thousand variables in a millisecond budget, sequential search is reduced to near-guesswork while the runtime still returns a usable answer. Tighten the budget or deadline and the crossover moves to smaller problems. This rests on one premise — that a configuration measurement is parallel and constant-cost in n — which is established in benchmarks here, with on-chip validation in progress.

Reproduce the crossover yourself

The full script behind the deadline-crossover figures. It runs on any CPU with the licensed wheel installed. The one assumption is made explicit in the cost model: a configuration measurement is treated as parallel and constant-cost in n (T_MEAS), while a classical flip pays sequential O(degree) cost. On a CPU both run on your processor, so we charge each its modelled cost to surface the crossover the hardware premise implies. Your crossover point will shift with the T_MEAS/T_OP ratio and your problem; the direction — the runtime overtaking sequential search as dimension grows under a fixed deadline — is the reproducible result.

copyimport math, random
from swc import SWCOptimizer   # pip-installed from your licensed wheel

# A QUBO with a per-bit field plus sparse pairwise coupling.
def make_qubo(n, density, coupling, seed):
    rng = random.Random(seed); Q = {}; adj = {i: [] for i in range(n)}
    for i in range(n):
        Q[(i, i)] = rng.uniform(-2, 2)
        for j in range(i + 1, n):
            if rng.random() < density:
                w = coupling * rng.uniform(-1, 1)
                Q[(i, j)] = w; adj[i].append((j, w)); adj[j].append((i, w))
    return Q, adj
def energy(x, Q):
    e = 0.0
    for (i, j), w in Q.items():
        e += w * x[i] * x[j] if i != j else w * x[i]
    return e

# Cost model. T_MEAS is CONSTANT in n: the premise is that the substrate measures the whole
# configuration in parallel. T_OP is one digital scalar op. On a CPU both methods run on your
# processor, so we charge each its modelled cost to expose the crossover the hardware implies.
T_MEAS = 0.05   # ms per parallel configuration measurement (constant in n)
T_OP   = 0.001  # ms per digital op

def swc_best(n, Q, deadline_ms, ns=8, seed=7):
    random.seed(seed)
    opt = SWCOptimizer(license_key="EVAL-...", n=n, mode="optimization")
    theta = opt.start([math.pi / 2] * n); best = 1e9; t = 0.0
    while t < deadline_ms:
        samp = [[1.0 if random.random() < 0.5 * (1 + math.cos(c)) else 0.0 for c in theta]
                for _ in range(ns)]
        es = [energy(b, Q) for b in samp]
        bi = min(range(ns), key=lambda k: es[k]); best = min(best, es[bi])
        t += ns * T_MEAS                                   # parallel, constant in n
        phat = [sum(b[i] for b in samp) / ns for i in range(n)]
        theta = opt.step(phat, score=-es[bi])
    opt.end(); return best

def sa_best(n, Q, adj, deadline_ms, seed=7):
    rng = random.Random(seed * 7 + 3)
    x = [1.0 if rng.random() < 0.5 else 0.0 for _ in range(n)]
    e = energy(x, Q); best = e; t = 0.0
    while t < deadline_ms:
        i = rng.randrange(n); xi = 1 - x[i]; d = Q.get((i, i), 0) * (xi - x[i])
        for j, w in adj[i]: d += w * (xi - x[i]) * x[j]
        if d < 0 or rng.random() < math.exp(-d / 1.001):
            x[i] = xi; e += d; best = min(best, e)
        t += (1 + len(adj[i])) * T_OP                      # sequential, O(degree) per flip
    return best

print(f"{'n':>6} {'SWC e/n':>9} {'SA e/n':>9} {'winner':>7}")
for n in [64, 256, 512, 1024, 2048]:
    deadline = 2.0   # fixed tight wall-clock, same for every n
    sw = []; sa = []
    for s in range(5):
        Q, adj = make_qubo(n, 0.05, 0.3, s)
        sw.append(swc_best(n, Q, deadline, seed=s) / n)
        sa.append(sa_best(n, Q, adj, deadline, seed=s) / n)
    swm = sum(sw) / 5; sam = sum(sa) / 5
    print(f"{n:>6} {swm:>9.4f} {sam:>9.4f} {('SWC' if swm < sam else 'SA'):>7}")

# Expected shape: SA wins at small n; the runtime overtakes it around n~512 and the gap
# widens with dimension. Tighten the deadline and the crossover moves to smaller n.
Scope: this is for diagonal objectives — cost that is a function of the measured bits. It is not for variational quantum energy (VQE / QAOA), where the objective lives in correlations the runtime cannot steer. See Quantum & photonic applications for the full boundary.