From 66c08f151bf7cf7613735968d01a67a3ca841378 Mon Sep 17 00:00:00 2001 From: irvingcui <67258813+2018cx@users.noreply.github.com> Date: Fri, 4 Dec 2026 23:26:06 -0800 Subject: [PATCH 1/2] Add UOT v2 challenge statement Added README for Certified Asymmetric Unbalanced Transport II problem, detailing the optimization challenge and requirements. --- .../certified-asymmetric-uot-v2/README.md | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 problems/certified-asymmetric-uot-v2/README.md diff --git a/problems/certified-asymmetric-uot-v2/README.md b/problems/certified-asymmetric-uot-v2/README.md new file mode 100644 index 0000000..545e0c2 --- /dev/null +++ b/problems/certified-asymmetric-uot-v2/README.md @@ -0,0 +1,65 @@ +--- +proposer: "@2018cx" +harness: "dot" +model: "undisclosed" +field: numerical optimization +--- + +# Certified asymmetric unbalanced transport II: 10× over the accepted Newton solver + +The two histograms may have different total mass. For each generated dense cost +matrix `C` with shape 128 by 144 and strictly positive vectors `a,b`, solve +entropy-regularized unbalanced optimal transport on one CPU thread. The two +marginal penalties are distinct and relatively strong compared with the +entropy coefficient, so re-establishing agreement between weakly coupled +clusters can take many iterations. + +For a nonnegative matrix `P`, minimize + + + eps * sum_ij P_ij (log P_ij - 1) + + rho_a KL(P 1 || a) + rho_b KL(P^T 1 || b), + +where `KL(x||y)=sum_i x_i log(x_i/y_i)-x_i+y_i`. Use the usual +zero limits. There is no hard total-mass or marginal-equality constraint. + +Return a dictionary containing only `f` and `g`: finite float64 NumPy arrays +of shapes `(128,)` and `(144,)`, respectively. The verifier reconstructs +`P_ij = exp((f_i+g_j-C_ij)/eps)`, `q_a = a exp(-f/rho_a)`, and +`q_b = b exp(-g/rho_b)` and computes the primal–dual gap using the identity + + primal(P) - dual(f,g) = rho_a KL(P 1 || q_a) + rho_b KL(P^T 1 || q_b). + +The submitted code cannot provide the gap itself. Every timed case must +satisfy a gap at most `1e-12 + 1e-11*(rho_a*sum(a) + rho_b*sum(b))` +in the original cost units. Generated cases use heterogeneous cluster weights, +dense pair-specific cost jitter and unequal total mass. The baseline is the exact accepted `solve` from +[@xiaoxiaoxiaotao's PR #45](https://github.com/Halley-Lab/hee/pull/45), +[pinned to merge commit `89a7081fd2efef10651193436d74b395d3a99fe8`](https://github.com/Halley-Lab/hee/blob/89a7081fd2efef10651193436d74b395d3a99fe8/problems/certified-asymmetric-uot/solution.py) +under the repository's MIT license. It uses an in-place over-relaxed +Sinkhorn warm start followed by a reduced log-domain Schur-complement +chord-Newton iteration. The original generalized Sinkhorn baseline is not +the reference for this challenge. + +**Target: another 10× median speedup relative to that accepted solver on the +same machine and one CPU thread**, without relaxing the certificate. +The same instance family is used, stratified by entropy: the lower half +`[0.0117, 0.016425)` and the upper half `[0.016425, 0.02115)` of +the original uniform interval are sampled equally (24 cases per half in +each public/timed split). The referee requires 10× both overall and in +each half, so making only one regime fast does not suffice. + +For timing eligibility only, the generator draws from that distribution +until the pinned solver certifies the instance. A few raw draws are +numerically unstable for #45; these are excluded by the same certificate, +not by their timing. The retry order is deterministic and does not depend +on any candidate implementation. No reference computation or retry is +in the timed region, and the solver receives only the original `C, a, b, eps, rho_a, rho_b` +input dictionary. There is no slower timed +fallback. The reference implementation in `baseline.py` is byte-for-byte +identical to the pinned solution. + +The UOT objective and translation-invariant algorithms are existing techniques: +[Chizat et al.](https://doi.org/10.1090/MCOM/3303) and +[Séjourné et al.](https://proceedings.mlr.press/v151/sejourne22a.html). +The contribution here is the benchmark protocol, instance family, and +certificate, not a claim that this UOT formulation is new. From 5d2ab5f908bbb5670aea21ceb7246a2cb469f901 Mon Sep 17 00:00:00 2001 From: irvingcui <67258813+2018cx@users.noreply.github.com> Date: Sat, 5 Dec 2026 15:26:52 +0800 Subject: [PATCH 2/2] Add pinned PR 45 baseline and stratified 10x verifier --- .../certified-asymmetric-uot-v2/baseline.py | 210 ++++++++++++++++ problems/certified-asymmetric-uot-v2/task.py | 237 ++++++++++++++++++ 2 files changed, 447 insertions(+) create mode 100644 problems/certified-asymmetric-uot-v2/baseline.py create mode 100644 problems/certified-asymmetric-uot-v2/task.py diff --git a/problems/certified-asymmetric-uot-v2/baseline.py b/problems/certified-asymmetric-uot-v2/baseline.py new file mode 100644 index 0000000..162c719 --- /dev/null +++ b/problems/certified-asymmetric-uot-v2/baseline.py @@ -0,0 +1,210 @@ +import numpy as np +from scipy.linalg.blas import dsyrk +from scipy.linalg.lapack import dpotrf, dpotrs + +SOLVER = "@xiaoxiaoxiaotao" +HARNESS = "devin" +MODEL = "swe-2.1-max" +METHOD = "In-place SOR warm start with reduced log-domain Schur-complement chord Newton" + +def solve(inp): + c, a, b = inp["C"], inp["a"], inp["b"] + ra, rb, eps = inp["rho_a"], inp["rho_b"], inp["eps"] + n, m = c.shape + la, lb = np.log(a), np.log(b) + inv_ra, inv_rb, inv_eps = 1.0 / ra, 1.0 / rb, 1.0 / eps + kernel = np.empty_like(c) + np.multiply(c, -inv_eps * 1.4426950408889634, out=kernel) + kernel += 384.0 + np.exp2(kernel, out=kernel) + alpha_a, alpha_b = 1.0 + eps * inv_ra, 1.0 + eps * inv_rb + inv_alpha_a, inv_sum = 1.0 / alpha_a, 1.0 / (inv_ra + inv_rb) + log2e = 1.4426950408889634 + inv_ln2 = 0.6931471805599453 + la2 = la * log2e + lb2 = lb * log2e + om = 1.76 + pow_a = ra / (ra + eps) + pow_b = rb / (rb + eps) + u = np.ones(n, dtype=np.float64) + v = np.ones(m, dtype=np.float64) + kv = np.empty(n, dtype=np.float64) + ktu = np.empty(m, dtype=np.float64) + rat = np.empty(n, dtype=np.float64) + ratg = np.empty(m, dtype=np.float64) + eF2 = np.empty(m, dtype=np.float64) + D = np.empty(m, dtype=np.float64) + rhs = np.empty(m, dtype=np.float64) + om_pow_a = om * pow_a + om_pow_b = om * pow_b + one_minus_om = 1.0 - om + ka = kernel / a[:, None] + kbt = kernel.T.copy() + kbt /= b[:, None] + lx = np.empty(n, dtype=np.float64) + ly = np.empty(m, dtype=np.float64) + np.matmul(ka, v, out=kv) + np.log2(kv, out=lx) + lx -= 384.0 + lx *= -pow_a + np.exp2(lx, out=u) + np.matmul(kbt, u, out=ktu) + np.log2(ktu, out=ly) + ly -= 384.0 + ly *= -pow_b + lxp = np.empty(n, dtype=np.float64) + lyp = np.empty(m, dtype=np.float64) + first_err = np.inf + stab = eps < 0.0125 + mxv = float(np.max(ly)) + mxu = float(np.max(lx)) + for k in range(1, 250): + checkpoint = (k % 10 == 9) + if checkpoint: + mxv = float(np.max(ly)) + mxu = float(np.max(lx)) + lxp[:] = lx + if stab: + np.subtract(ly, mxv, out=v) + np.exp2(v, out=v) + else: + np.exp2(ly, out=v) + np.matmul(ka, v, out=kv) + np.log2(kv, out=kv) + kv += mxv - 384.0 if stab else -384.0 + kv *= -om_pow_a + lx *= one_minus_om + lx += kv + if checkpoint: + lyp[:] = ly + if stab: + np.subtract(lx, mxu, out=u) + np.exp2(u, out=u) + else: + np.exp2(lx, out=u) + np.matmul(kbt, u, out=ktu) + np.log2(ktu, out=ktu) + ktu += mxu - 384.0 if stab else -384.0 + ktu *= -om_pow_b + ly *= one_minus_om + ly += ktu + if checkpoint: + np.subtract(lx, lxp, out=rat) + np.abs(rat, out=rat) + np.subtract(ly, lyp, out=ratg) + np.abs(ratg, out=ratg) + er_chk = max(float(np.max(rat)), float(np.max(ratg))) * eps * inv_ln2 / om + np.multiply(lx, -eps * inv_ra, out=rat) + rat += la2 + np.exp2(rat, out=rat) + np.multiply(ly, -eps * inv_rb, out=ratg) + ratg += lb2 + np.exp2(ratg, out=ratg) + h = (np.log2(rat.sum()) - np.log2(ratg.sum())) * inv_sum + lx += h * inv_eps + ly -= h * inv_eps + if k == 9: + first_err = er_chk + elif k >= 19: + if er_chk > first_err * 1.05: + om = max(1.68, om - 0.03) + else: + om = min(1.92, om + 0.05) + om_pow_a = om * pow_a + om_pow_b = om * pow_b + one_minus_om = 1.0 - om + first_err = er_chk + if er_chk < 4.0e-3: + break + lx *= inv_ln2 + ly *= inv_ln2 + lym = float(np.max(ly)) + np.exp(ly - lym, out=v) + np.matmul(kernel, v, out=kv) + np.log(kv, out=kv) + kv += lym - 266.168517335019 + logkv = kv + np.subtract(la, logkv, out=lx) + lx *= pow_a + lxm = float(np.max(lx)) + np.exp(lx - lxm, out=u) + np.matmul(kernel.T, u, out=ktu) + np.log(ktu, out=ktu) + ktu += lxm - 266.168517335019 + logktu = ktu + np.multiply(ly, eps * inv_rb, out=eF2) + eF2 += ly + eF2 += logktu + eF2 -= lb + eF2 *= eps + np.subtract(ly, logktu, out=ratg) + ratg *= 0.5 + np.subtract(lx, logkv, out=rat) + rat *= 0.5 + np.exp(rat, out=rat) + np.exp(ratg, out=ratg) + B = ka + np.multiply(kernel, rat[:, None], out=B) + B *= ratg[None, :] + B[B < 1e-100] = 0.0 + S = dsyrk(-inv_alpha_a * 6.44114876959713331e-232, B, trans=1, lower=1) + S.flat[::m + 1] += alpha_b + np.add(ly, logktu, out=D) + D *= 0.5 + D -= np.mean(D) + np.exp(D, out=D) + lu_piv, lapack_info = dpotrf(S, lower=1, overwrite_a=True) + err0 = -1.0 + for sub in range(9): + err = float(np.max(np.abs(eF2))) + if sub == 0: + err0 = err + if err < 5.0e-7: + break + if sub in (1, 2) and err > max(1e-6, 0.1 * err0): + np.subtract(ly, logktu, out=ratg) + ratg *= 0.5 + np.subtract(lx, logkv, out=rat) + rat *= 0.5 + np.exp(rat, out=rat) + np.exp(ratg, out=ratg) + np.multiply(kernel, rat[:, None], out=B) + B *= ratg[None, :] + B[B < 1e-100] = 0.0 + S = dsyrk(-inv_alpha_a * 6.44114876959713331e-232, B, trans=1, lower=1) + S.flat[::m + 1] += alpha_b + np.add(ly, logktu, out=D) + D *= 0.5 + D -= np.mean(D) + np.exp(D, out=D) + lu_piv, lapack_info = dpotrf(S, lower=1, overwrite_a=True) + np.multiply(D, eF2, out=rhs) + rhs *= -1.0 + step = dpotrs(lu_piv, rhs, lower=1, overwrite_b=True)[0] + step /= D + step *= inv_eps + if sub == 0: + step *= 0.7 + ly += step + lym = float(np.max(ly)) + np.exp(ly - lym, out=v) + np.matmul(kernel, v, out=kv) + np.log(kv, out=kv) + kv += lym - 266.168517335019 + logkv = kv + np.subtract(la, logkv, out=lx) + lx *= pow_a + lxm = float(np.max(lx)) + np.exp(lx - lxm, out=u) + np.matmul(kernel.T, u, out=ktu) + np.log(ktu, out=ktu) + ktu += lxm - 266.168517335019 + logktu = ktu + np.multiply(ly, eps * inv_rb, out=eF2) + eF2 += ly + eF2 += logktu + eF2 -= lb + eF2 *= eps + f = eps * lx + g = eps * ly + return {"f": f, "g": g} diff --git a/problems/certified-asymmetric-uot-v2/task.py b/problems/certified-asymmetric-uot-v2/task.py new file mode 100644 index 0000000..38dc4f6 --- /dev/null +++ b/problems/certified-asymmetric-uot-v2/task.py @@ -0,0 +1,237 @@ +import numpy as np +from scipy.special import logsumexp +from scipy.linalg.blas import dsyrk +from scipy.linalg.lapack import dpotrf, dpotrs + +FORMALIZER = "@2018cx" +HARNESS = "dot" +MODEL = "undisclosed" +MODE = "speedup" +TARGET = 10.0 +CASES = 48 +ROUNDS = 9 +TIME_LIMIT_S = 20.0 +RUNTIME = "cpu" +TIMING_GROUPS = ("lower-eps", "upper-eps") + +ABS_TOL = 1e-12 +REL_TOL = 1e-11 + + +def _generate(seed, eps_lo, eps_hi): + rng = np.random.default_rng(seed) + n, m, dims, clusters = 128, 144, 4, 8 + a_ids = np.arange(n) % clusters + b_ids = np.arange(m) % clusters + rng.shuffle(a_ids) + rng.shuffle(b_ids) + centers = rng.normal(0.0, 0.73, (clusters, dims)) + x = centers[a_ids] + rng.normal(0.0, 0.16, (n, dims)) + y = centers[b_ids] + rng.normal(0.0, 0.19, (m, dims)) + penalty = rng.uniform(0.01, 0.18, (n, m)) + c = np.sum((x[:, None, :] - y[None, :, :]) ** 2, axis=2) + penalty + a, b = (rng.lognormal(0.0, 0.8, ids.size) * rng.lognormal(0.0, 0.9, clusters)[ids] + for ids in (a_ids, b_ids)) + a /= a.sum() + b *= rng.uniform(0.63, 1.37) / b.sum() + return {"C": c, "a": a, "b": b, "eps": rng.uniform(eps_lo, eps_hi), + "rho_a": rng.uniform(3.75, 8.0), "rho_b": rng.uniform(7.2, 12.0)} + + +def generate_group(seed, group, index): + lo, hi = ((0.0117, 0.016425) if group == "lower-eps" else (0.016425, 0.02115)) + for attempt in range(64): + x = _generate(seed + 2147483648 * attempt, lo, hi) + ref = _admission_reference(x) + if verify(x, ref, ref): + return x + raise ValueError("reference could not certify a generated instance") + + +def kl_from_logs(logp, logq): + z = logp - logq + # Stable near equality, with the regular p*(log p-log q)-p+q form otherwise. + p, q = np.exp(logp), np.exp(logq) + near = np.abs(z) < 0.1 + zn = np.clip(z, -0.1, 0.1) + small = q * (np.exp(zn) * zn - np.expm1(zn)) + regular = p * z - p + q + return float(np.sum(np.maximum(0.0, np.where(near, small, regular)))) + + +def certificate(inp, out, logp): + a, b, ea, eb = (inp[k] for k in ("a", "b", "rho_a", "rho_b")) + f, g = out["f"], out["g"] + logra = logsumexp(logp, axis=1) + logrbb = logsumexp(logp, axis=0) + logqa, logqb = np.log(a) - f / ea, np.log(b) - g / eb + return ea * kl_from_logs(logra, logqa) + eb * kl_from_logs(logrbb, logqb) + + +def verify(inp, out, ref_out): + if not isinstance(out, dict) or set(out) != {"f", "g"}: + return False + for name, key in (("f", "a"), ("g", "b")): + v = out[name] + if not isinstance(v, np.ndarray) or v.dtype != np.float64 or v.shape != inp[key].shape: + return False + if not bool(np.all(np.isfinite(v))) or np.max(np.abs(v)) > 32.0: + return False + logp = (out["f"][:, None] + out["g"][None, :] - inp["C"]) / inp["eps"] + if logp.max() > 80: + return False + gap = certificate(inp, out, logp) + scale = inp["rho_a"] * inp["a"].sum() + inp["rho_b"] * inp["b"].sum() + return bool(np.isfinite(gap) and 0 <= gap <= ABS_TOL + REL_TOL * scale) + + +# Untimed eligibility check; same algorithm as the pinned baseline, with repeated code factored. +def _admission_reference(inp): + c, a, b, ra, rb, eps = (inp[k] for k in ("C", "a", "b", "rho_a", "rho_b", "eps")) + n, m = c.shape + la, lb = np.log(a), np.log(b) + u, v = (np.ones(k) for k in (n, m)) + kv, rat, lx, lxp = (np.empty(n) for _ in range(4)) + ktu, ratg, eF2, D, rhs, ly, lyp = (np.empty(m) for _ in range(7)) + inv_ra, inv_rb, inv_eps = 1.0 / ra, 1.0 / rb, 1.0 / eps + kernel = np.empty_like(c) + np.multiply(c, -inv_eps * 1.4426950408889634, out=kernel) + kernel += 384.0 + np.exp2(kernel, out=kernel) + alpha_a, alpha_b = 1.0 + eps * inv_ra, 1.0 + eps * inv_rb + inv_alpha_a, inv_sum = 1.0 / alpha_a, 1.0 / (inv_ra + inv_rb) + log2e = 1.4426950408889634 + inv_ln2 = 0.6931471805599453 + la2, lb2 = la * log2e, lb * log2e + om = 1.76 + pow_a = ra / (ra + eps) + pow_b = rb / (rb + eps) + om_pow_a = om * pow_a + om_pow_b = om * pow_b + one_minus_om = 1.0 - om + ka = kernel / a[:, None] + kbt = kernel.T.copy() + kbt /= b[:, None] + def mv2(mat, z, tmp, out): + np.matmul(mat, z, out=tmp) + np.log2(tmp, out=out) + mv2(ka, v, kv, lx) + lx -= 384.0 + lx *= -pow_a + np.exp2(lx, out=u) + mv2(kbt, u, ktu, ly) + ly -= 384.0 + ly *= -pow_b + first_err = 0.0 + stab = eps < 0.0125 + mxv = ly.max() + mxu = lx.max() + def sor_logmv(mat, y, shift, work, out): + if stab: + np.subtract(y, shift, out=work) + np.exp2(work, out=work) + else: + np.exp2(y, out=work) + mv2(mat, work, out, out) + out += shift - 384.0 if stab else -384.0 + + for k in range(1, 250): + checkpoint = (k % 10 == 9) + if checkpoint: + mxv = ly.max() + mxu = lx.max() + lxp[:] = lx + sor_logmv(ka, ly, mxv, v, kv) + kv *= -om_pow_a + lx *= one_minus_om + lx += kv + if checkpoint: + lyp[:] = ly + sor_logmv(kbt, lx, mxu, u, ktu) + ktu *= -om_pow_b + ly *= one_minus_om + ly += ktu + if checkpoint: + er_chk = max(np.abs(lx-lxp).max(), np.abs(ly-lyp).max()) * eps * inv_ln2 / om + np.multiply(lx, -eps * inv_ra, out=rat) + rat += la2 + np.exp2(rat, out=rat) + np.multiply(ly, -eps * inv_rb, out=ratg) + ratg += lb2 + np.exp2(ratg, out=ratg) + h = (np.log2(rat.sum()) - np.log2(ratg.sum())) * inv_sum + lx += h * inv_eps + ly -= h * inv_eps + if k >= 19: + if er_chk > first_err * 1.05: + om = max(1.68, om - 0.03) + else: + om = min(1.92, om + 0.05) + om_pow_a = om * pow_a + om_pow_b = om * pow_b + one_minus_om = 1.0 - om + first_err = er_chk + if er_chk < 4.0e-3: + break + lx *= inv_ln2 + ly *= inv_ln2 + def shifted_logmv(mat, z, work, out): + shift = z.max() + np.exp(z - shift, out=work) + np.matmul(mat, work, out=out) + np.log(out, out=out) + out += shift - 266.168517335019 + + def residual(): + shifted_logmv(kernel, ly, v, kv) + np.subtract(la, kv, out=lx) + lx[:] *= pow_a + shifted_logmv(kernel.T, lx, u, ktu) + np.multiply(ly, eps * inv_rb, out=eF2) + eF2[:] += ly + eF2[:] += ktu + eF2[:] -= lb + eF2[:] *= eps + + residual() + B = ka + def factor(): + np.subtract(ly, ktu, out=ratg) + ratg[:] *= 0.5 + np.subtract(lx, kv, out=rat) + rat[:] *= 0.5 + np.exp(rat, out=rat) + np.exp(ratg, out=ratg) + np.multiply(kernel, rat[:, None], out=B) + B[:] *= ratg[None, :] + B[B < 1e-100] = 0.0 + S = dsyrk(-inv_alpha_a * 6.44114876959713331e-232, B, trans=1, lower=1) + S.flat[::m + 1] += alpha_b + np.add(ly, ktu, out=D) + D[:] *= 0.5 + D[:] -= np.mean(D) + np.exp(D, out=D) + return dpotrf(S, lower=1, overwrite_a=True)[0] + + lu_piv = factor() + err0 = -1.0 + for sub in range(9): + err = float(np.max(np.abs(eF2))) + if sub == 0: + err0 = err + if err < 5.0e-7: + break + if sub in (1, 2) and err > max(1e-6, 0.1 * err0): + lu_piv = factor() + np.multiply(D, eF2, out=rhs) + rhs *= -1.0 + step = dpotrs(lu_piv, rhs, lower=1, overwrite_b=True)[0] + step /= D + step *= inv_eps + if sub == 0: + step *= 0.7 + ly += step + residual() + f = eps * lx + g = eps * ly + return {"f": f, "g": g}