Tasks/Math & Scientific Computing/Quantum Computing

Plan the contraction order for exact decision-diagram circuit equivalence checking

Plan the contraction order for exact circuit equivalence checking

tddn_contraction_planning Math & Scientific Computing Quantum Computing
instruction.mdthis is what the agent is given

Two quantum circuits are checked for exact equivalence by contracting a network of Tensor Decision Diagrams (TDDs) down to a single tensor and testing it against the identity. Every contraction order reaches the same verdict, but the orders differ enormously in how large the intermediate diagrams grow and how long the whole check takes. Your job is the planner: at each step, pick which pair to contract next.

Hard Constraints

  • Edit only files under /app/methods/main/. That directory is what gets graded.
  • Keep the exact contract: select_edge(observation) -> int returns one enabled, stable edge_id. The exact TDD engine contracts that pair and hands you the next observation.
  • Return only an edge that action_mask marks as enabled. An invalid action forfeits the case.
  • Inference must be deterministic and independent of case IDs. Do not encode case IDs, fixed edge sequences, tensor IDs, or per-case tables — the sealed circuits have different hashes and sizes, and anything keyed on identity will simply miss.
  • Do not train a model and do not download artifacts. There is no network at run time; whatever you use has to be already installed or written here.
  • Do not attempt to read verifier or held-out files.
  • Your planner gets 30 seconds of total decision time per circuit, and no single select_edge call may take more than 5 seconds. Thinking longer per step is fine within that budget — the time you spend deciding is not part of your score.
  • Every circuit must finish and pass exact identity checking. Exceptions, invalid actions, incomplete contractions, failed identity checks, native resource failures and budget overruns all score zero for that case.

What You Have

  • /app/methods/main/solver.py — a crude planner that always takes the strongest shared bond. It is yours to rewrite or replace entirely.
  • python /app/selfcheck.py — free and unlimited. It always evaluates all 12 frozen visible cases (eight standard, four larger scalability cases) and reports the raw metrics. The visible set is fixed so successive planner revisions stay comparable.
  • /app/data/visible_cases.json — those 12 cases.

Each observation gives you:

key contents
nodes stable node IDs, current exact TDD sizes, rank, degree, and how many original gates each active tensor represents
edges stable edge_id, endpoints, shared-index count, bond dimension, normalized bond strength / local topology, endpoint sizes and degrees
action_mask which edge IDs are currently enabled
global_features active node/edge counts, step, qubits, latest size, peak size so far

Two things that bite: list positions are not stable IDs, and the scores you computed last step are stale — recompute after every contraction.

What You Submit

Leave your best planner in /app/methods/main/solver.py, exposing exactly:

def select_edge(observation: dict) -> int:
    """Return one edge_id enabled by observation["action_mask"]."""

There is no submit step and no per-attempt feedback. Work and self-check for as long as your run window allows, then leave your best solver.py in place.

How It Is Judged

The grader replays every contraction on 12 sealed cases you never see — four in-family standard sizes, four zero-shot Bernstein–Vazirani circuits, and four larger scalability cases, none of them overlapping the visible set. All contractions use the same 23-bit TDD normalization precision as your workbench.

A submission must first be correct: every circuit finishes and passes exact identity checking. Among correct planners, two numbers are measured per case and combined in log space:

  • peak intermediate TDD node count — 75% of the weight;
  • the time the native engine spends contracting — 25%. Your own decision time is not counted here; it only has to stay inside the budget above.

Both are lower-is-better. The grader runs the trusted starter and a frozen reference planner on the same hardware in the same pass, so the comparison is not affected by machine load. How the raw measurements map to the final reward is deliberately not disclosed — optimise the raw measurements themselves. The starter as shipped is the zero of that scale: submitted unchanged it scores 0.

Metric

combined log gain over the starter on 12 sealed circuits · higher is better

0.75*mean log(starter_peak/plan_peak) + 0.25*mean log(starter_ctime/plan_ctime); all 12 must verify

anchorheld-outreward
shipped starter (strongest shared bond)00.00
Rfrozen reference planner0.3751 (opus pass) / 0.3947 (codex pass)0.30
Usealed upper anchor (4.68x geomean)1.54281.00
normalisation
any case incorrect0
m <= 00
0 < m <= R0.3 * m / R
m > R0.3 + 0.7 * (m - R) / (U - R)

m = this run's held-out metric  ·  R = frozen reference planner  ·  U = sealed upper anchor (4.68x geomean)

m is one aggregate over the 12 cases, not per-case. R is the reference re-measured in the same pass, so it moves per run. Clamped to [0,1].

Rollouts

104 minwall clock
-spend
-tokens
5versions, 5 kept
40 50 60 70 80 0 25 50 75 100 agent step (this harness reports no tokens or timestamps) visible peak TDD nodes, geomean of 12, lower is better v0 v1 v2 v3 v4
keptrevertedno scoreturning point
  1. v0Shipped starter: strongest normalised shared bond80.6072
  2. v1Result rank ru+rv-2*shared, then merged degree, fill-in proxy, su*sv/bondRank an edge by the rank of the tensor it would produce, not by bond strength. Largest single gain, 80.6 to 43.1.43.0866
  3. v2Two-phase: v1 rule while active nodes > 3*qubits, then min su*sv/bond^2Switch predictor at a qubit-relative depth so it transfers to larger sealed circuits: rank early, predicted merged size late.37.6001
  4. v3Circuits with initial leaf fraction > 0.10 break ties by distance to path middleRead leafiness off step 0 and contract those circuits from the middle of a diameter path outwards; dense ones keep v2.35.8538
  5. v4Same policy, safer case reset on step 0 or a rising node count35.8538

Five snapshots, 104 min; this harness reports no token or cost data. Beam search, min-fill and nested dissection were rejected unsnapshotted.

On the hidden set

held-out metricreward
shipped starter (strongest shared bond)00.00
frozen reference planner0.3751 (opus pass) / 0.3947 (codex pass)0.30
sealed upper anchor (4.68x geomean)1.54281.00
this run0.59280.4355
128 minwall clock
$32.65spend
53.6Mtokens
14versions, 14 kept
30 40 50 60 70 80 $0 $7.5 $15 $22 cumulative spend on the run visible peak TDD nodes, geomean of 12, lower is better v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13
keptrevertedno scoreturning point
  1. v0Shipped starter: strongest normalised shared bond80.60721 min · $0.29
  2. v1Minimise projected merged log-size: log(su) + log(sv) - 2*log(bond)Score an edge by the size of the diagram it would produce, not by bond strength. Largest single gain, 80.6 to 44.3.44.32176 min · $0.78
  3. v2Add 0.75*merged degree to the width cost, chosen on a 75-point grid36.832616 min · $1.94
  4. v3Refine generic width weights, bond exponent 1 to 0.7536.540127 min · $3.40
  5. v4Dense endgame at <=3 nodes: subtract 2*log(represented gate sum)Recognise a dense endgame from shared-index structure and finish the more mature component, using no identity keys.34.425840 min · $5.51
  6. v5Depth-gated maturity weight 0.5 below 10 active nodes34.425849 min · $7.05
  7. v6Pre-maturity width as the secondary tie key34.425850 min · $7.38
  8. v7Drop the normalised-topology tie after exact merged degree34.165151 min · $7.77
  9. v8Deep endgames add 0.25*|log(su) - log(sv)| against unbalanced merges33.488263 min · $11.32
  10. v9Scale both endgame windows with qubits, capped at min(16, max(10, 2q))33.488283 min · $16.50
  11. v10Merged-degree weight 0.5 below 8 represented tensors/qubit, else 0.7533.4882103 min · $22.14
  12. v11Medium-depth band adds one label-invariant colour-refinement tieBreak ties by refined structural colour so the plan stops depending on how the hidden node ids happen to be numbered.33.3789113 min · $25.66
  13. v12Restrict medium-depth colour refinement to q <= 1033.3789116 min · $27.07
  14. v13Merged degrees and colours read from all active edges, candidates still masked33.3789119 min · $28.44

14 snapshots, 128 min, $32.65, none reverted: each was screened on offline grids and permutation tests first. Stopped at v13 with 592 min unused.

On the hidden set

held-out metricreward
shipped starter (strongest shared bond)00.00
frozen reference planner0.3751 (opus pass) / 0.3947 (codex pass)0.30
sealed upper anchor (4.68x geomean)1.54281.00
this run0.55530.4221
628 minwall clock
$36.12spend
51.9Mtokens
9versions, 8 kept
30 40 50 60 70 80 $0 $7.5 $15 $22 $30 cumulative spend on the run visible peak TDD nodes, geomean of 12, lower is better v0 v1 v2 v3 v4 v5 v6 v7 v8
keptrevertedno scoreturning point
  1. v0Shipped starter: always contract the strongest shared bond80.612 min · $0.39
  2. v1Greedy on estimated result size: min(l2u+l2v, 1.2*rank_new) - 1.5*sharedRank edges by the predicted size of the merged diagram, not by bond strength. Largest single gain, 80.6 to 36.9.36.932 min · $3.44
  3. v2Rollout planner: rank simulator plus a fitted apply-size law, 18 s/case38.6549 min · $6.15
  4. v3Add middle-out prior on gate-count-weighted normalised node positionContract from the middle of the circuit outwards. First prior taken from circuit structure, and it won on held-out synthetics.33.62202 min · $15.36
  5. v4Add contiguity prior: penalise the merged span not yet coveredKeep the merged qubit span contiguous, never half-covering a wide blob. It also made the score tie-free under 1e-9 jitter.31.61338 min · $19.98
  6. v5Normalise contiguity coverage per connected component30.78360 min · $21.68
  7. v6Wrap scoring in try/except with a valid-edge fallback30.78437 min · $27.14
  8. v7Switch both positional priors off when node ids are not circuit-ordered30.78440 min · $27.99
  9. v8Episode boundary also detected when the active-node count stops falling30.78587 min · $34.66

Nine snapshots, 628 min, $36.12. Most of the run never became a version: synthetic held-out sets, a jitter study, a surrogate study. Flat from v5.

On the hidden set

held-out metricreward
shipped starter (strongest shared bond)00.00
frozen reference planner0.3751 (opus pass) / 0.3947 (codex pass)0.30
sealed upper anchor (4.68x geomean)1.54281.00
this run0.52740.3913
39 minwall clock
$15.10spend
23.9Mtokens
59versions, 15 kept
40 50 60 70 80 $0 $3 $6 $9 $12 cumulative spend on the run visible peak TDD nodes, geomean of 12, lower is better v0 v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 v21 v22 v23 v24 v25 v26 v27 v28 v29 v30 v31 v32 v33 v34 v35 v36 v37 v38 v39 v40 v41 v42 v43 v44 v45 v46 v47 v48 v49 v50 v51 v52 v53 v54 v55 v56 v57 v58
keptrevertedno scoreturning point
  1. v0Shipped starter: strongest normalised shared bond80.60720 min · $0.09
  2. v1Local topology first, then operand-product cost, then bond strengthInvert the starter's priority: take the most tree-like neighbourhood first and use bond strength only to break ties.65.99231 min · $0.33
  3. v2Bond strength ahead of operand cost inside the topology-first order82.40852 min · $0.43
  4. v3Operand-product/bond cost first, topology only as tie-break11/12, QFT-5 abort2 min · $0.54
  5. v4Cost-first early, topology-first fill guard below 10 active nodes50.89333 min · $0.77
  6. v5Delay the topology-first guard from 10 to 5 active nodes11/12, QFT-5 abort4 min · $0.86
  7. v6Topology-first guard at 8 active nodes50.89334 min · $0.99
  8. v7Topology-first guard at 7 active nodes11/12, QFT-5 abort5 min · $1.11
  9. v8Late phase scored continuously: log(operand cost) + 3*topology44.98275 min · $1.25
  10. v9Late topology weight 3.0 to 2.544.81646 min · $1.39
  11. v10Late topology weight 2.5 to 2.044.81646 min · $1.52
  12. v11Late topology weight 2.0 to 1.544.81647 min · $1.66
  13. v12Late topology weight 1.5 to 1.011/12, QFT-5 abort7 min · $1.80
  14. v13Remove the bond-dimension discount from the operand cost10/12, both QFT abort8 min · $1.96
  15. v14Bond-dimension discount exponent 1 to 258.6748 min · $2.11
  16. v15Bond-dimension discount exponent 1 to 0.7546.36629 min · $2.27
  17. v16Bond-dimension discount exponent 1 to 1.2554.62559 min · $2.44
  18. v17Add 0.25*topology to the early log operand cost44.816410 min · $2.60
  19. v18Early topology penalty 0.25 to 0.547.043210 min · $2.76
  20. v19Add 0.1*estimated output rank to the log cost51.509511 min · $2.96
  21. v20Subtract 0.1*estimated output rank from the log cost54.074712 min · $3.15
  22. v21Divide cost by combined represented gate count^0.2544.530212 min · $3.35
  23. v22Represented-gate compression exponent 0.25 to 0.148.367213 min · $3.54
  24. v23Represented-gate compression exponent 0.2Favour edges whose endpoints already stand for many original gates, so compressed components absorb the rest, not each other.41.417613 min · $3.72
  25. v24Compression exponent 0.1843.051314 min · $3.91
  26. v25Compression exponent 0.2242.600314 min · $4.10
  27. v26Compression exponent 0.1941.727815 min · $4.29
  28. v27Compression exponent 0.19543.597415 min · $4.49
  29. v28Reward the product of endpoint gate counts^0.1 instead of the sum43.445716 min · $4.92
  30. v29Endpoint-product gate bonus exponent 0.1 to 0.0548.367217 min · $5.14
  31. v30Late topology weight 2.5 to 2.0, retried on v2641.727817 min · $5.35
  32. v31Smooth late guard from 8 to 7 active nodes43.051318 min · $5.58
  33. v32Smooth late guard starts at 9 active nodes41.42318 min · $5.79
  34. v33Smooth late guard starts at 10 active nodes41.42319 min · $6.01
  35. v34Smooth late guard starts at 12 active nodes43.523519 min · $6.24
  36. v35Early equal-cost tie-break by bond strength, not topology41.42320 min · $6.48
  37. v36Endpoint-size sum instead of product in the cost42.852220 min · $6.65
  38. v37Geometric blend sqrt(size-product * size-sum)60.112721 min · $6.89
  39. v38Add an endpoint-size imbalance^0.1 penalty44.452821 min · $7.14
  40. v39Imbalance penalty exponent 0.1 to 0.0245.285922 min · $7.39
  41. v40Disable the gate-count bonus inside the final 10-node guard41.42322 min · $7.66
  42. v41Disable the gate-count bonus after 70% of contractions50.452923 min · $7.92
  43. v42Add 0.7*topology to the early cost from first-divergence analysis56.465124 min · $8.29
  44. v43Raw cost then topology, gate bonus only for exact ties58.3724 min · $8.57
  45. v44Force leaf-chain edges with topology <= 0.25 ahead of adjusted cost41.838625 min · $8.85
  46. v45Infer a rank-2 rotation-dominated mode at step 0, drop the gate bonus thereRead the circuit family off anonymous step-0 rank and size fractions and switch rule set, instead of one score for every circuit.40.166126 min · $9.17
  47. v46Graph-like profile uses gate-count exponent 0.2239.452527 min · $9.49
  48. v47Graph-like mode uses late threshold 8, other modes stay at 1037.74628 min · $9.79
  49. v48Default gate-count exponent 0.19 to 0.18537.946328 min · $10.08
  50. v49Stateless density modes from sum(gate_count)/qubits replace step-0 state37.74629 min · $10.41
  51. v50Also divide the cost by normalised bond strength^0.2547.99633 min · $11.73
  52. v51Normalised bond-strength exponent 0.25 to 0.0544.030233 min · $12.04
  53. v52Dense networks use the max endpoint gate count for the bonus38.752734 min · $12.38
  54. v53Max-gate bonus only at 30-40 tensors/qubit, combined count above36.491935 min · $12.71
  55. v54Moderate-density max-gate exponent 0.19 to 0.2237.404135 min · $13.04
  56. v55Moderate-density max-gate exponent 0.19 to 0.1836.491936 min · $13.26
  57. v56Moderate-density max-gate exponent 0.19 to 0.1537.443836 min · $13.49
  58. v57Moderate-density late threshold 10 to 836.491937 min · $13.82
  59. v58Moderate-density gate bonus as max(gates) + 0.25*min(gates)38.186637 min · $14.16

59 snapshots, 39 min, $15.10 -- one every 38 s, each a single self-check. 39 were reverted, 5 failed correctness; it quit at v58 with 681 min unused.

On the hidden set

held-out metricreward
shipped starter (strongest shared bond)00.00
frozen reference planner0.3751 (opus pass) / 0.3947 (codex pass)0.30
sealed upper anchor (4.68x geomean)1.54281.00
this run0.51510.3734
145 minwall clock
$0.71spend
2.9Mtokens
4versions, 4 kept
45.0 52.5 60.0 67.5 75.0 82.5 $0 $0.2 $0.3 $0.5 $0.6 cumulative spend on the run visible peak TDD nodes, geomean of 12, lower is better v0 v1 v2 v3
keptrevertedno scoreturning point
  1. v0Shipped starter: strongest normalised shared bond80.607144 min · $0.60
  2. v1Min-width: take the edge minimising the resulting tensor rankCap the merged tensor's rank at every step instead of following bond strength, so TDD width stops exploding on QFT.53.251144 min · $0.62
  3. v2Lexicographic (res_rank, tdd_min, deg_sum), chosen from a 160-order sweep50.138144 min · $0.64
  4. v3Continuous nine-feature score, weights from a 200-step random searchReplace hard lexicographic ties with one smooth weighted score and tune the nine weights derivative-free.44.241144 min · $0.65

Four snapshots, 145 min, $0.71 -- all four written in the last minute; every gain came from offline search scripts, never versioned.

On the hidden set

held-out metricreward
shipped starter (strongest shared bond)00.00
frozen reference planner0.3751 (opus pass) / 0.3947 (codex pass)0.30
sealed upper anchor (4.68x geomean)1.54281.00
this run0.38740.3197