Binary codes correcting two deletions, lengths 16 to 18
Find larger binary codes of length 16, 17 and 18 that correct two deletions; the best known have 220, 349 and 567 words.
Comparing changes
Choose two branches to see what changed, then open a pull request to bring the work across.
Able to merge. These branches can be merged automatically.
Sign in to open a pull request.
8 commits
+12 −0 routes/irisbud-codex/n17-local-search/README.md added View file
| @@ -0,0 +1,12 @@ | ||
| 1 | +--- | |
| 2 | +issue: 1 | |
| 3 | +status: working | |
| 4 | +--- | |
| 5 | + | |
| 6 | +# 长度 17 的二删除纠错码搜索 | |
| 7 | + | |
| 8 | +从 `constructions/n17.json` 中的 316 码字构造出发,维护每个长度 15 的删除结果当前属于哪个码字。对基线做可复现的局部搜索,再用项目精确判定程序检查产物。 | |
| 9 | + | |
| 10 | +## Next | |
| 11 | + | |
| 12 | +实现并运行搜索,记录随机种子、源码、作业产物和独立判定。 | |
+123 −0 routes/irisbud-codex/n17-local-search/audit_exchanges.py added View file
| @@ -0,0 +1,123 @@ | ||
| 1 | +"""Find improving exchanges that remove at most six words from a length-17 code.""" | |
| 2 | + | |
| 3 | +import argparse | |
| 4 | +from collections import defaultdict | |
| 5 | +from itertools import combinations | |
| 6 | +from pathlib import Path | |
| 7 | + | |
| 8 | +import numpy as np | |
| 9 | + | |
| 10 | +from optimize import DESCENDANT_COUNT, check_code, deletion_table, load_code, write_code | |
| 11 | + | |
| 12 | + | |
| 13 | +def group_options(code, table, radius): | |
| 14 | + owner = np.full(DESCENDANT_COUNT, -1, dtype=np.int32) | |
| 15 | + for word in code: | |
| 16 | + owner[table[word]] = word | |
| 17 | + blocked = np.sort(owner[table], axis=1) | |
| 18 | + transitions = (blocked[:, 1:] >= 0) & (blocked[:, :-1] != blocked[:, 1:]) | |
| 19 | + counts = (blocked[:, 0] >= 0).astype(np.int32) + transitions.sum(axis=1) | |
| 20 | + groups = defaultdict(list) | |
| 21 | + masks = {} | |
| 22 | + for candidate in np.flatnonzero(counts <= radius).tolist(): | |
| 23 | + if candidate in code: | |
| 24 | + continue | |
| 25 | + row = blocked[candidate] | |
| 26 | + owners = tuple(int(w) for w in np.unique(row) if w >= 0) | |
| 27 | + groups[owners].append(candidate) | |
| 28 | + bits = bytearray(DESCENDANT_COUNT // 8) | |
| 29 | + for result in table[candidate].tolist(): | |
| 30 | + bits[result // 8] |= 1 << (result % 8) | |
| 31 | + masks[candidate] = int.from_bytes(bits, byteorder="little") | |
| 32 | + return groups, masks | |
| 33 | + | |
| 34 | + | |
| 35 | +def packing(candidates, masks, target): | |
| 36 | + if len(candidates) < target: | |
| 37 | + return None | |
| 38 | + if target == 1: | |
| 39 | + return (candidates[0],) | |
| 40 | + for i, a in enumerate(candidates[: 1 - target]): | |
| 41 | + compatible = [b for b in candidates[i + 1 :] if not masks[a] & masks[b]] | |
| 42 | + rest = packing(compatible, masks, target - 1) | |
| 43 | + if rest: | |
| 44 | + return (a, *rest) | |
| 45 | + return None | |
| 46 | + | |
| 47 | + | |
| 48 | +def connected_owners(groups, radius): | |
| 49 | + # At the first improving radius, the blocker hypergraph must be connected. | |
| 50 | + # Otherwise a smaller component would already provide an improvement. | |
| 51 | + subsets = [set() for _ in range(radius + 1)] | |
| 52 | + extensions = defaultdict(set) | |
| 53 | + for owners in groups: | |
| 54 | + if len(owners) <= radius: | |
| 55 | + subsets[len(owners)].add(owners) | |
| 56 | + if 1 < len(owners) < radius: | |
| 57 | + for count in range(1, len(owners)): | |
| 58 | + for shared in combinations(owners, count): | |
| 59 | + extra = tuple(word for word in owners if word not in shared) | |
| 60 | + extensions[shared, len(extra)].add(extra) | |
| 61 | + for size in range(2, radius): | |
| 62 | + for owners in subsets[size]: | |
| 63 | + selected = frozenset(owners) | |
| 64 | + for count in range(1, size + 1): | |
| 65 | + for shared in combinations(owners, count): | |
| 66 | + for added in range(1, radius - size + 1): | |
| 67 | + for extra in extensions.get((shared, added), ()): | |
| 68 | + if selected.isdisjoint(extra): | |
| 69 | + subsets[size + added].add(tuple(sorted((*owners, *extra)))) | |
| 70 | + return subsets | |
| 71 | + | |
| 72 | + | |
| 73 | +def find_exchange(groups, masks, radius): | |
| 74 | + for size, subsets in enumerate(connected_owners(groups, radius)): | |
| 75 | + owner_sets = sorted(subsets) | |
| 76 | + print(f"radius {size}: {len(owner_sets)} relevant subsets", flush=True) | |
| 77 | + for owners in owner_sets: | |
| 78 | + candidates = [] | |
| 79 | + for k in range(1, size + 1): | |
| 80 | + for subset in combinations(owners, k): | |
| 81 | + candidates.extend(groups.get(subset, ())) | |
| 82 | + if size == 0: | |
| 83 | + candidates = groups.get((), []) | |
| 84 | + if len(candidates) <= size: | |
| 85 | + continue | |
| 86 | + candidates.sort(key=lambda word: (masks[word].bit_count(), word)) | |
| 87 | + replacement = packing(candidates, masks, size + 1) | |
| 88 | + if replacement: | |
| 89 | + return set(owners), set(replacement) | |
| 90 | + return None | |
| 91 | + | |
| 92 | + | |
| 93 | +def main(): | |
| 94 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 95 | + parser.add_argument("start", type=Path) | |
| 96 | + parser.add_argument("output", type=Path) | |
| 97 | + parser.add_argument("--radius", type=int, choices=range(1, 7), default=6) | |
| 98 | + parser.add_argument("--steps", type=int, default=10) | |
| 99 | + args = parser.parse_args() | |
| 100 | + if args.steps < 1: | |
| 101 | + parser.error("Step count must be positive") | |
| 102 | + table = deletion_table() | |
| 103 | + code = load_code(args.start) | |
| 104 | + check_code(code, table) | |
| 105 | + write_code(args.output, code) | |
| 106 | + print(f"metric: code_size {len(code)}", flush=True) | |
| 107 | + for step in range(args.steps): | |
| 108 | + groups, masks = group_options(code, table, args.radius) | |
| 109 | + move = find_exchange(groups, masks, args.radius) | |
| 110 | + if move is None: | |
| 111 | + print(f"No improving exchange at radius {args.radius} for {len(code)} words", flush=True) | |
| 112 | + break | |
| 113 | + drop, add = move | |
| 114 | + code = (code - drop) | add | |
| 115 | + check_code(code, table) | |
| 116 | + write_code(args.output, code) | |
| 117 | + print(f"Exchange: removed {len(drop)}, inserted {len(add)}", flush=True) | |
| 118 | + print(f"metric: code_size {len(code)}", flush=True) | |
| 119 | + print(f"progress: {step + 1}/{args.steps} exchanges, best {len(code)}", flush=True) | |
| 120 | + | |
| 121 | + | |
| 122 | +if __name__ == "__main__": | |
| 123 | + main() | |
+55 −0 routes/irisbud-codex/n17-local-search/cold.sbatch added View file
| @@ -0,0 +1,55 @@ | ||
| 1 | +#!/usr/bin/env bash | |
| 2 | +#SBATCH --job-name=n17-cold-starts | |
| 3 | +#SBATCH --cpus-per-task=4 | |
| 4 | +#SBATCH --time=00:09:00 | |
| 5 | +#SBATCH --mem=1024M | |
| 6 | +set -euo pipefail | |
| 7 | + | |
| 8 | +if [[ $# -ne 7 ]]; then | |
| 9 | + echo 'Usage: cold.sbatch GREEDY_ATTEMPTS FIRST_SEED ROUNDS LOCAL_SEED1 LOCAL_SEED2 LOCAL_SEED3 LOCAL_SEED4' >&2 | |
| 10 | + exit 2 | |
| 11 | +fi | |
| 12 | + | |
| 13 | +here=$(pwd) | |
| 14 | +repo=${SS_INPUT:-$(git rev-parse --show-toplevel)} | |
| 15 | +tmp_base=$(cd -- "${TMPDIR:-/tmp}" && pwd -P) | |
| 16 | +scratch=$(mktemp -d "$tmp_base/n17-cold.XXXXXXXX") | |
| 17 | +scratch=$(cd -- "$scratch" && pwd -P) | |
| 18 | +[[ $(dirname -- "$scratch") == "$tmp_base" && ${scratch##*/} == n17-cold.* ]] | |
| 19 | +trap 'rm -rf -- "$scratch"' EXIT | |
| 20 | +cxx=${CXX:-c++} | |
| 21 | +python=${PYTHON:-python3} | |
| 22 | + | |
| 23 | +"$python" -B greedy_starts.py "$scratch/greedy.json" --attempts "$1" --first-seed "$2" | tee "$scratch/greedy.log" | |
| 24 | +"$cxx" -O3 -std=c++17 search.cpp -o "$scratch/search.exe" | |
| 25 | +( | |
| 26 | + cd "$scratch" | |
| 27 | + "$python" -B "$here/run_seeds.py" "$scratch/search.exe" "$scratch" "$scratch/greedy.json" "$3" "$4" "$5" "$6" "$7" | |
| 28 | +) | |
| 29 | +mv -- "$scratch/n17.json" "$scratch/cold-n17.json" | |
| 30 | +"$python" -B recombine.py "$scratch/recombined.json" n17.json "$scratch/cold-n17.json" | tee "$scratch/recombined.log" | |
| 31 | + | |
| 32 | +"$python" -B - "$scratch" <<'PY' | |
| 33 | +import json | |
| 34 | +import shutil | |
| 35 | +import sys | |
| 36 | +from pathlib import Path | |
| 37 | + | |
| 38 | +scratch = Path(sys.argv[1]) | |
| 39 | +current, cold, combined = Path('n17.json'), scratch / 'cold-n17.json', scratch / 'recombined.json' | |
| 40 | + | |
| 41 | +def size(path): | |
| 42 | + return len(json.loads(path.read_text(encoding='utf-8'))['words']) | |
| 43 | + | |
| 44 | +old_size, best_size = size(current), size(combined) | |
| 45 | +shutil.copyfile(cold, 'alternative-n17.json') | |
| 46 | +if best_size > old_size: | |
| 47 | + shutil.copyfile(combined, current) | |
| 48 | +lines = [(scratch / 'greedy.log').read_text(encoding='utf-8').splitlines()[-1], | |
| 49 | + (scratch / 'search-report.txt').read_text(encoding='utf-8').strip(), | |
| 50 | + (scratch / 'recombined.log').read_text(encoding='utf-8').strip(), | |
| 51 | + f'Primary construction: {size(current)} codewords'] | |
| 52 | +Path('cold-start-report.txt').write_text('\n'.join(lines) + '\n', encoding='utf-8') | |
| 53 | +print(lines[-1]) | |
| 54 | +PY | |
| 55 | +"$python" -B "$repo/checks/judge/check.py" . | |
+13 −0 routes/irisbud-codex/n17-local-search/escape-report.txt added View file
| @@ -0,0 +1,13 @@ | ||
| 1 | +Starting code: 335 words | |
| 2 | +CP-SAT neighborhoods per seed: 280; deterministic effort: 1.1 | |
| 3 | +Seed 401 (CP-SAT): 335 words | |
| 4 | +Seed 409 (CP-SAT): 335 words | |
| 5 | +Seed 419 (CP-SAT): 335 words | |
| 6 | +Seed 431 (CP-SAT): 335 words | |
| 7 | +Seed 401: smallest accepted incumbent 332 words | |
| 8 | +Seed 409: smallest accepted incumbent 332 words | |
| 9 | +Seed 419: smallest accepted incumbent 332 words | |
| 10 | +Seed 431: smallest accepted incumbent 332 words | |
| 11 | +Pairwise recombination order: 401, 409, 419, 431 | |
| 12 | +Recombined code: 335 words | |
| 13 | +Retained starting code: 335 words | |
+63 −0 routes/irisbud-codex/n17-local-search/greedy_starts.py added View file
| @@ -0,0 +1,63 @@ | ||
| 1 | +"""Try deletion-sphere priorities to construct new length-17 starting codes.""" | |
| 2 | + | |
| 3 | +import argparse | |
| 4 | +import itertools | |
| 5 | +from pathlib import Path | |
| 6 | + | |
| 7 | +import numpy as np | |
| 8 | + | |
| 9 | +from optimize import DESCENDANT_COUNT, LENGTH, WORD_COUNT, check_code, deletion_table, write_code | |
| 10 | + | |
| 11 | + | |
| 12 | +def popcounts(words): | |
| 13 | + return np.fromiter((word.bit_count() for word in words.tolist()), dtype=np.int16) | |
| 14 | + | |
| 15 | + | |
| 16 | +def greedy(table, priority): | |
| 17 | + used = np.zeros(DESCENDANT_COUNT, dtype=bool) | |
| 18 | + code = set() | |
| 19 | + for word in np.argsort(priority, kind="stable").tolist(): | |
| 20 | + children = table[word] | |
| 21 | + if not used[children].any(): | |
| 22 | + code.add(word) | |
| 23 | + used[children] = True | |
| 24 | + return code | |
| 25 | + | |
| 26 | + | |
| 27 | +def main(): | |
| 28 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 29 | + parser.add_argument("output", type=Path) | |
| 30 | + parser.add_argument("--first-seed", type=int, default=501) | |
| 31 | + parser.add_argument("--attempts", type=int, default=48) | |
| 32 | + args = parser.parse_args() | |
| 33 | + if args.first_seed < 0 or args.attempts < 1: | |
| 34 | + parser.error("Seed must be nonnegative and attempts must be positive") | |
| 35 | + words = np.arange(WORD_COUNT, dtype=np.uint32) | |
| 36 | + table = deletion_table() | |
| 37 | + sorted_table = np.sort(table, axis=1) | |
| 38 | + sphere_size = 1 + np.count_nonzero(sorted_table[:, 1:] != sorted_table[:, :-1], axis=1) | |
| 39 | + del sorted_table | |
| 40 | + weight_from_center = np.abs(2 * popcounts(words) - LENGTH) | |
| 41 | + transitions = popcounts((words ^ (words >> 1)) & ((1 << (LENGTH - 1)) - 1)) | |
| 42 | + | |
| 43 | + best = set() | |
| 44 | + best_seed = args.first_seed | |
| 45 | + combinations = tuple(itertools.product((2.0, 5.0, 10.0, 16.0), (-1.0, 0.0, 1.0), (-1.0, 0.0, 1.0))) | |
| 46 | + for attempt in range(args.attempts): | |
| 47 | + seed = args.first_seed + attempt | |
| 48 | + rng = np.random.default_rng(seed) | |
| 49 | + noise, weight, run = combinations[attempt % len(combinations)] | |
| 50 | + priority = sphere_size + weight * weight_from_center + run * transitions + rng.normal(0, noise, WORD_COUNT) | |
| 51 | + code = greedy(table, priority) | |
| 52 | + if len(code) > len(best): | |
| 53 | + best, best_seed = code, seed | |
| 54 | + check_code(best, table) | |
| 55 | + write_code(args.output, best) | |
| 56 | + print(f"metric: cold_start_size {len(best)}", flush=True) | |
| 57 | + if (attempt + 1) % 8 == 0 or attempt + 1 == args.attempts: | |
| 58 | + print(f"progress: {attempt + 1}/{args.attempts} starts, best {len(best)} (seed {best_seed})", flush=True) | |
| 59 | + print(f"seed {best_seed}, {len(best)} codewords", flush=True) | |
| 60 | + | |
| 61 | + | |
| 62 | +if __name__ == "__main__": | |
| 63 | + main() | |
+1 −0 routes/irisbud-codex/n17-local-search/metrics.json added View file
| @@ -0,0 +1 @@ | ||
| 1 | +{"score": 0.96193710424847, "score_exact": "27193/28269", "subtasks": {"n17": 335}, "new_records": []} | |
+340 −0 routes/irisbud-codex/n17-local-search/n17.json added View file
| @@ -0,0 +1,340 @@ | ||
| 1 | +{ | |
| 2 | + "n": 17, | |
| 3 | + "words": [ | |
| 4 | + "00000000000000001", | |
| 5 | + "00000000000001111", | |
| 6 | + "00000000000101010", | |
| 7 | + "00000000001110000", | |
| 8 | + "00000000010110011", | |
| 9 | + "00000000101111010", | |
| 10 | + "00000000110010001", | |
| 11 | + "00000000111101111", | |
| 12 | + "00000001010010111", | |
| 13 | + "00000001101000000", | |
| 14 | + "00000001110011100", | |
| 15 | + "00000001111000011", | |
| 16 | + "00000010011000110", | |
| 17 | + "00000010101010100", | |
| 18 | + "00000010110111011", | |
| 19 | + "00000011000011101", | |
| 20 | + "00000011011111000", | |
| 21 | + "00000011111000100", | |
| 22 | + "00000100111010101", | |
| 23 | + "00000101000100000", | |
| 24 | + "00000101100000011", | |
| 25 | + "00000110001100111", | |
| 26 | + "00000110101000101", | |
| 27 | + "00000110101011110", | |
| 28 | + "00000111000011000", | |
| 29 | + "00000111011011001", | |
| 30 | + "00000111101111111", | |
| 31 | + "00000111110001111", | |
| 32 | + "00001000100110101", | |
| 33 | + "00001001100111111", | |
| 34 | + "00001010000011110", | |
| 35 | + "00001010010111000", | |
| 36 | + "00001010110010010", | |
| 37 | + "00001010111101110", | |
| 38 | + "00001011110110000", | |
| 39 | + "00001100000100001", | |
| 40 | + "00001100011111001", | |
| 41 | + "00001100111000001", | |
| 42 | + "00001110001010110", | |
| 43 | + "00001110010000100", | |
| 44 | + "00001111001110100", | |
| 45 | + "00001111111111000", | |
| 46 | + "00010000110110010", | |
| 47 | + "00010001110100111", | |
| 48 | + "00010010000100101", | |
| 49 | + "00010011111100101", | |
| 50 | + "00010100101000011", | |
| 51 | + "00010101000111011", | |
| 52 | + "00010110001100100", | |
| 53 | + "00010110010010111", | |
| 54 | + "00010111010010001", | |
| 55 | + "00010111011111010", | |
| 56 | + "00010111101011011", | |
| 57 | + "00011000000110100", | |
| 58 | + "00011000010011111", | |
| 59 | + "00011001100101000", | |
| 60 | + "00011001101011101", | |
| 61 | + "00011010000000000", | |
| 62 | + "00011010111100100", | |
| 63 | + "00011100000000111", | |
| 64 | + "00011100011111110", | |
| 65 | + "00011101100000101", | |
| 66 | + "00011110000110011", | |
| 67 | + "00011110110100110", | |
| 68 | + "00011111100111001", | |
| 69 | + "00011111111000001", | |
| 70 | + "00011111111011110", | |
| 71 | + "00100001111111110", | |
| 72 | + "00100010010000010", | |
| 73 | + "00100010100111001", | |
| 74 | + "00100100011011110", | |
| 75 | + "00100101010101011", | |
| 76 | + "00100110110000000", | |
| 77 | + "00100110110000111", | |
| 78 | + "00100110111010100", | |
| 79 | + "00101000001001100", | |
| 80 | + "00101000101100000", | |
| 81 | + "00101001001111100", | |
| 82 | + "00101011010001010", | |
| 83 | + "00101100001110001", | |
| 84 | + "00101110011101011", | |
| 85 | + "00101111100111110", | |
| 86 | + "00110000100001001", | |
| 87 | + "00110000110010110", | |
| 88 | + "00110001110111000", | |
| 89 | + "00110010111100011", | |
| 90 | + "00110011100011111", | |
| 91 | + "00110011110110110", | |
| 92 | + "00110100000011101", | |
| 93 | + "00110100101101001", | |
| 94 | + "00110110111111001", | |
| 95 | + "00111000001010010", | |
| 96 | + "00111001110100000", | |
| 97 | + "00111010000111111", | |
| 98 | + "00111010010100111", | |
| 99 | + "00111010110111011", | |
| 100 | + "00111011001110000", | |
| 101 | + "00111100000111100", | |
| 102 | + "00111100011000010", | |
| 103 | + "00111110010010100", | |
| 104 | + "00111110100000000", | |
| 105 | + "00111110110001111", | |
| 106 | + "00111111000000111", | |
| 107 | + "00111111100011000", | |
| 108 | + "00111111111001011", | |
| 109 | + "01000010001101100", | |
| 110 | + "01000011110000010", | |
| 111 | + "01000100000100111", | |
| 112 | + "01000101101001100", | |
| 113 | + "01000101110001011", | |
| 114 | + "01000110011011011", | |
| 115 | + "01000111111100111", | |
| 116 | + "01001000110000100", | |
| 117 | + "01001000111101000", | |
| 118 | + "01001011011101001", | |
| 119 | + "01001100011100110", | |
| 120 | + "01001110001010001", | |
| 121 | + "01001110010111100", | |
| 122 | + "01001111110000100", | |
| 123 | + "01010000010111111", | |
| 124 | + "01010000011010011", | |
| 125 | + "01010010111101101", | |
| 126 | + "01010011100110000", | |
| 127 | + "01010100110010001", | |
| 128 | + "01010101000001000", | |
| 129 | + "01010111111101100", | |
| 130 | + "01011000100111010", | |
| 131 | + "01011011010000011", | |
| 132 | + "01011011101010111", | |
| 133 | + "01011100001011011", | |
| 134 | + "01011100110001110", | |
| 135 | + "01011101010100100", | |
| 136 | + "01011110011011001", | |
| 137 | + "01011110111000101", | |
| 138 | + "01100000001000011", | |
| 139 | + "01100000010001000", | |
| 140 | + "01100000010011110", | |
| 141 | + "01100000111011010", | |
| 142 | + "01100001001110000", | |
| 143 | + "01100001111010111", | |
| 144 | + "01100010001100101", | |
| 145 | + "01100010110111110", | |
| 146 | + "01100011010001110", | |
| 147 | + "01100011111001010", | |
| 148 | + "01100110010010011", | |
| 149 | + "01100111000001010", | |
| 150 | + "01101010000001011", | |
| 151 | + "01101010101111000", | |
| 152 | + "01101011001111111", | |
| 153 | + "01101011110100001", | |
| 154 | + "01101101100001100", | |
| 155 | + "01101111111111101", | |
| 156 | + "01110000110000000", | |
| 157 | + "01110000110001111", | |
| 158 | + "01110001010100001", | |
| 159 | + "01110010100110111", | |
| 160 | + "01110011110011001", | |
| 161 | + "01110011111111000", | |
| 162 | + "01110101000111001", | |
| 163 | + "01110101100101010", | |
| 164 | + "01110110000101110", | |
| 165 | + "01111000000001010", | |
| 166 | + "01111000110110100", | |
| 167 | + "01111001000110000", | |
| 168 | + "01111001111101111", | |
| 169 | + "01111010110000001", | |
| 170 | + "01111010111111010", | |
| 171 | + "01111011010110001", | |
| 172 | + "01111011110000111", | |
| 173 | + "01111101010110110", | |
| 174 | + "01111101111100000", | |
| 175 | + "01111110001001001", | |
| 176 | + "01111110001011111", | |
| 177 | + "01111110110011100", | |
| 178 | + "01111111001000110", | |
| 179 | + "01111111011110011", | |
| 180 | + "10000000000111111", | |
| 181 | + "10000010100011010", | |
| 182 | + "10000011110010110", | |
| 183 | + "10000100101110011", | |
| 184 | + "10000101100101001", | |
| 185 | + "10000110000001011", | |
| 186 | + "10000110101010000", | |
| 187 | + "10000110111111011", | |
| 188 | + "10000111110100011", | |
| 189 | + "10001000001010000", | |
| 190 | + "10001000011111101", | |
| 191 | + "10001010110011110", | |
| 192 | + "10001100010010010", | |
| 193 | + "10001110000111010", | |
| 194 | + "10001110011110001", | |
| 195 | + "10001111001011111", | |
| 196 | + "10001111100010000", | |
| 197 | + "10010000000110001", | |
| 198 | + "10010000001110110", | |
| 199 | + "10010000100000111", | |
| 200 | + "10010000111001001", | |
| 201 | + "10010001101110111", | |
| 202 | + "10010010001000110", | |
| 203 | + "10010010111111100", | |
| 204 | + "10010110010000001", | |
| 205 | + "10010110101110110", | |
| 206 | + "10010111101011000", | |
| 207 | + "10011010011101111", | |
| 208 | + "10011011101100001", | |
| 209 | + "10011011110001110", | |
| 210 | + "10011101010000110", | |
| 211 | + "10011110101010101", | |
| 212 | + "10011110111101000", | |
| 213 | + "10011111101111111", | |
| 214 | + "10100000100000001", | |
| 215 | + "10100001011110010", | |
| 216 | + "10100001110011111", | |
| 217 | + "10100010000100100", | |
| 218 | + "10100110110100101", | |
| 219 | + "10100111000100111", | |
| 220 | + "10101000010101110", | |
| 221 | + "10101010100101100", | |
| 222 | + "10101010101000111", | |
| 223 | + "10101011111101111", | |
| 224 | + "10101100101101000", | |
| 225 | + "10101110111110011", | |
| 226 | + "10101111000000100", | |
| 227 | + "10101111100011011", | |
| 228 | + "10110000010010101", | |
| 229 | + "10110000110101000", | |
| 230 | + "10110010000111100", | |
| 231 | + "10110011011011100", | |
| 232 | + "10110011011100000", | |
| 233 | + "10110100011000011", | |
| 234 | + "10110100101000000", | |
| 235 | + "10110101110110010", | |
| 236 | + "10110110001111101", | |
| 237 | + "10110110011001010", | |
| 238 | + "10111000010001100", | |
| 239 | + "10111001001111110", | |
| 240 | + "10111011000010001", | |
| 241 | + "10111011110111110", | |
| 242 | + "10111100000011111", | |
| 243 | + "10111110011100111", | |
| 244 | + "10111111001110100", | |
| 245 | + "10111111110000000", | |
| 246 | + "11000000001010101", | |
| 247 | + "11000000011110100", | |
| 248 | + "11000001110000111", | |
| 249 | + "11000011111100000", | |
| 250 | + "11000100101010111", | |
| 251 | + "11000100111111111", | |
| 252 | + "11000101010110100", | |
| 253 | + "11000101011000000", | |
| 254 | + "11000101110110011", | |
| 255 | + "11000111110111100", | |
| 256 | + "11001001110100100", | |
| 257 | + "11001010011110101", | |
| 258 | + "11001011000011011", | |
| 259 | + "11001100001011001", | |
| 260 | + "11001100010111110", | |
| 261 | + "11001100011000001", | |
| 262 | + "11001100100000000", | |
| 263 | + "11001110110110111", | |
| 264 | + "11001111000000011", | |
| 265 | + "11001111000111000", | |
| 266 | + "11001111110010011", | |
| 267 | + "11010000000011100", | |
| 268 | + "11010000001100000", | |
| 269 | + "11010001000011111", | |
| 270 | + "11010001100110010", | |
| 271 | + "11010001111110110", | |
| 272 | + "11010010010001001", | |
| 273 | + "11010011110000110", | |
| 274 | + "11010100010100010", | |
| 275 | + "11010101110111101", | |
| 276 | + "11010110011100011", | |
| 277 | + "11011000001111011", | |
| 278 | + "11011001011100111", | |
| 279 | + "11011001100101111", | |
| 280 | + "11011011100101001", | |
| 281 | + "11011100011010101", | |
| 282 | + "11011100111110100", | |
| 283 | + "11011110111010110", | |
| 284 | + "11011111001100000", | |
| 285 | + "11011111111100001", | |
| 286 | + "11100000000000000", | |
| 287 | + "11100000011111110", | |
| 288 | + "11100001001100011", | |
| 289 | + "11100001101101101", | |
| 290 | + "11100001110011100", | |
| 291 | + "11100010000000110", | |
| 292 | + "11100010011111000", | |
| 293 | + "11100011010111111", | |
| 294 | + "11100011100001001", | |
| 295 | + "11100011111000111", | |
| 296 | + "11100101001001000", | |
| 297 | + "11100111010011110", | |
| 298 | + "11100111111111011", | |
| 299 | + "11101000001010100", | |
| 300 | + "11101010000000001", | |
| 301 | + "11101010001001111", | |
| 302 | + "11101010110101011", | |
| 303 | + "11101110000110000", | |
| 304 | + "11101110010000101", | |
| 305 | + "11101111101100011", | |
| 306 | + "11101111110100100", | |
| 307 | + "11110000000001111", | |
| 308 | + "11110000111100001", | |
| 309 | + "11110001001001110", | |
| 310 | + "11110001111111001", | |
| 311 | + "11110010001010011", | |
| 312 | + "11110010101110010", | |
| 313 | + "11110011110110000", | |
| 314 | + "11110101110001100", | |
| 315 | + "11110110100111011", | |
| 316 | + "11110111111001101", | |
| 317 | + "11111000000111000", | |
| 318 | + "11111000001000000", | |
| 319 | + "11111000010001011", | |
| 320 | + "11111000011101111", | |
| 321 | + "11111000111001000", | |
| 322 | + "11111001100000100", | |
| 323 | + "11111010001111100", | |
| 324 | + "11111010110111111", | |
| 325 | + "11111011011001001", | |
| 326 | + "11111011101111000", | |
| 327 | + "11111100000110110", | |
| 328 | + "11111100111100010", | |
| 329 | + "11111101010001000", | |
| 330 | + "11111101010010111", | |
| 331 | + "11111101110000011", | |
| 332 | + "11111110000000010", | |
| 333 | + "11111110000111001", | |
| 334 | + "11111110011011110", | |
| 335 | + "11111111010110101", | |
| 336 | + "11111111100011111", | |
| 337 | + "11111111111011100", | |
| 338 | + "11111111111111111" | |
| 339 | + ] | |
| 340 | +} | |
+178 −0 routes/irisbud-codex/n17-local-search/optimize.py added View file
| @@ -0,0 +1,178 @@ | ||
| 1 | +"""Refine a length-17 code by solving small deletion set-packing subproblems.""" | |
| 2 | + | |
| 3 | +import argparse | |
| 4 | +import json | |
| 5 | +import random | |
| 6 | +from pathlib import Path | |
| 7 | + | |
| 8 | +import numpy as np | |
| 9 | +from ortools.sat.python import cp_model | |
| 10 | + | |
| 11 | + | |
| 12 | +LENGTH = 17 | |
| 13 | +WORD_COUNT = 1 << LENGTH | |
| 14 | +DESCENDANT_COUNT = 1 << (LENGTH - 2) | |
| 15 | + | |
| 16 | + | |
| 17 | +def delete_bit(words, position): | |
| 18 | + mask = (1 << position) - 1 | |
| 19 | + return (words & mask) | ((words >> 1) & ~mask) | |
| 20 | + | |
| 21 | + | |
| 22 | +def deletion_table(): | |
| 23 | + words = np.arange(WORD_COUNT, dtype=np.int32) | |
| 24 | + table = np.empty((WORD_COUNT, LENGTH * (LENGTH - 1) // 2), dtype=np.uint16) | |
| 25 | + index = 0 | |
| 26 | + for second in range(1, LENGTH): | |
| 27 | + short = delete_bit(words, second) | |
| 28 | + for first in range(second): | |
| 29 | + table[:, index] = delete_bit(short, first) | |
| 30 | + index += 1 | |
| 31 | + return table | |
| 32 | + | |
| 33 | + | |
| 34 | +def load_code(path): | |
| 35 | + data = json.loads(path.read_text(encoding="utf-8")) | |
| 36 | + if data["n"] != LENGTH: | |
| 37 | + raise ValueError(f"Expected n = {LENGTH} in {path}") | |
| 38 | + words = data["words"] | |
| 39 | + if not words or any(len(word) != LENGTH or set(word) - {"0", "1"} for word in words): | |
| 40 | + raise ValueError(f"Invalid word in {path}") | |
| 41 | + code = {int(word, 2) for word in words} | |
| 42 | + if len(code) != len(words): | |
| 43 | + raise ValueError(f"Repeated word in {path}") | |
| 44 | + return code | |
| 45 | + | |
| 46 | + | |
| 47 | +def check_code(code, table): | |
| 48 | + occupied = np.zeros(DESCENDANT_COUNT, dtype=bool) | |
| 49 | + for word in code: | |
| 50 | + if occupied[table[word]].any(): | |
| 51 | + raise ValueError("Code shares a two-deletion descendant") | |
| 52 | + occupied[table[word]] = True | |
| 53 | + return occupied | |
| 54 | + | |
| 55 | + | |
| 56 | +def write_code(output, code): | |
| 57 | + words = [f"{word:0{LENGTH}b}" for word in sorted(code)] | |
| 58 | + pending = output.with_suffix(output.suffix + ".part") | |
| 59 | + pending.write_text(json.dumps({"n": LENGTH, "words": words}, indent=2) + "\n", encoding="utf-8") | |
| 60 | + pending.replace(output) | |
| 61 | + | |
| 62 | + | |
| 63 | +def removable(code, target, mode, rng): | |
| 64 | + words = sorted(code) | |
| 65 | + anchor = rng.choice(words) | |
| 66 | + if mode == 0: | |
| 67 | + # Two words with weights more than two apart cannot conflict. | |
| 68 | + weight = anchor.bit_count() | |
| 69 | + return set(sorted(words, key=lambda word: (abs(word.bit_count() - weight), rng.random()))[:target]) | |
| 70 | + if mode == 1: | |
| 71 | + return set(sorted(words, key=lambda word: ((word ^ anchor).bit_count(), rng.random()))[:target]) | |
| 72 | + # A random set can expose exchanges in disjoint neighborhoods at once. | |
| 73 | + return set(rng.sample(words, target)) | |
| 74 | + | |
| 75 | + | |
| 76 | +def perturbation_word(table, allowed, released, rng): | |
| 77 | + alternatives = [word for word in allowed if word not in released] | |
| 78 | + if not alternatives: | |
| 79 | + return None | |
| 80 | + ownership = np.full(DESCENDANT_COUNT, -1, dtype=np.int32) | |
| 81 | + for word in released: | |
| 82 | + ownership[table[word]] = word | |
| 83 | + choices = rng.sample(alternatives, min(140, len(alternatives))) | |
| 84 | + | |
| 85 | + def cost(word): | |
| 86 | + children = np.unique(table[word]) | |
| 87 | + owners = np.unique(ownership[children]) | |
| 88 | + loss = sum(owner >= 0 for owner in owners) | |
| 89 | + return int(loss) * 16 + len(children) + rng.randrange(30) | |
| 90 | + | |
| 91 | + return min(choices, key=cost) | |
| 92 | + | |
| 93 | + | |
| 94 | +def solve_repair(table, fixed, released, effort, seed, force_rng=None, tolerance=0): | |
| 95 | + occupied = check_code(fixed, table) | |
| 96 | + allowed = np.flatnonzero(~occupied[table].any(axis=1)).tolist() | |
| 97 | + | |
| 98 | + forced = None if force_rng is None else perturbation_word(table, allowed, released, force_rng) | |
| 99 | + hint = set(released) | |
| 100 | + if forced is not None: | |
| 101 | + mask = np.zeros(DESCENDANT_COUNT, dtype=bool) | |
| 102 | + mask[table[forced]] = True | |
| 103 | + hint = {word for word in released if not mask[table[word]].any()} | |
| 104 | + hint.add(forced) | |
| 105 | + | |
| 106 | + model = cp_model.CpModel() | |
| 107 | + choices = [model.new_bool_var(f"w{word}") for word in allowed] | |
| 108 | + by_child = [[] for _ in range(DESCENDANT_COUNT)] | |
| 109 | + for choice, word in zip(choices, allowed): | |
| 110 | + for child in np.unique(table[word]): | |
| 111 | + by_child[child].append(choice) | |
| 112 | + model.add_hint(choice, int(word in hint)) | |
| 113 | + if word == forced: | |
| 114 | + model.add(choice == 1) | |
| 115 | + for parents in by_child: | |
| 116 | + if len(parents) > 1: | |
| 117 | + model.add_at_most_one(parents) | |
| 118 | + model.add(sum(choices) >= len(released) - tolerance) | |
| 119 | + model.maximize(sum(choices)) | |
| 120 | + | |
| 121 | + solver = cp_model.CpSolver() | |
| 122 | + solver.parameters.num_workers = 1 | |
| 123 | + solver.parameters.random_seed = seed | |
| 124 | + solver.parameters.max_deterministic_time = effort | |
| 125 | + status = solver.solve(model) | |
| 126 | + if status not in (cp_model.FEASIBLE, cp_model.OPTIMAL): | |
| 127 | + return None, len(allowed), solver.status_name(status) | |
| 128 | + selected = {word for choice, word in zip(choices, allowed) if solver.boolean_value(choice)} | |
| 129 | + return fixed | selected, len(allowed), solver.status_name(status) | |
| 130 | + | |
| 131 | + | |
| 132 | +def main(): | |
| 133 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 134 | + parser.add_argument("start", type=Path) | |
| 135 | + parser.add_argument("output", type=Path) | |
| 136 | + parser.add_argument("--seed", type=int, required=True) | |
| 137 | + parser.add_argument("--rounds", type=int, required=True) | |
| 138 | + parser.add_argument("--effort", type=float, default=0.15) | |
| 139 | + parser.add_argument("--escape", action="store_true", help="occasionally force a new word in a larger neighborhood") | |
| 140 | + args = parser.parse_args() | |
| 141 | + if args.rounds < 1 or args.effort <= 0: | |
| 142 | + parser.error("Round count and effort must be positive") | |
| 143 | + | |
| 144 | + rng = random.Random(args.seed) | |
| 145 | + table = deletion_table() | |
| 146 | + current = best = load_code(args.start) | |
| 147 | + widths = (96, 120, 144, 168) if args.escape else (44, 64, 88, 112) | |
| 148 | + if len(current) < max(widths) + 3: | |
| 149 | + parser.error("Initial code is too small for the chosen neighborhoods") | |
| 150 | + check_code(current, table) | |
| 151 | + write_code(args.output, best) | |
| 152 | + print(f"metric: code_size {len(best)}", flush=True) | |
| 153 | + | |
| 154 | + # Cycle through different neighborhood geometries and sizes. | |
| 155 | + for index in range(args.rounds): | |
| 156 | + if args.escape and index % 36 == 0: | |
| 157 | + current = best | |
| 158 | + mode = index % 3 | |
| 159 | + width = widths[index % len(widths)] | |
| 160 | + released = removable(current, width, mode, rng) | |
| 161 | + force = args.escape and index % 4 in (0, 2) and mode != 2 | |
| 162 | + tolerance = max(0, len(current) - len(best) + 3) if force else 0 | |
| 163 | + candidate, count, status = solve_repair(table, current - released, released, args.effort, | |
| 164 | + rng.randrange(1 << 30), rng if force else None, tolerance) | |
| 165 | + if candidate is not None and (force or len(candidate) > len(current) or rng.random() < 0.4): | |
| 166 | + current = candidate | |
| 167 | + if len(current) > len(best): | |
| 168 | + best = current | |
| 169 | + check_code(best, table) | |
| 170 | + write_code(args.output, best) | |
| 171 | + print(f"metric: code_size {len(best)}", flush=True) | |
| 172 | + print(f"progress: {index + 1}/{args.rounds} mode {mode}, released {width}, pool {count}, " | |
| 173 | + f"{'forced, ' if force else ''}{status}, current {len(current)}, best {len(best)}", flush=True) | |
| 174 | + print(f"Seed {args.seed}, {args.rounds} neighborhoods, {len(best)} codewords", flush=True) | |
| 175 | + | |
| 176 | + | |
| 177 | +if __name__ == "__main__": | |
| 178 | + main() | |
+100 −0 routes/irisbud-codex/n17-local-search/recombine.py added View file
| @@ -0,0 +1,100 @@ | ||
| 1 | +"""Build the largest two-deletion code contained in the union of two codes.""" | |
| 2 | + | |
| 3 | +import argparse | |
| 4 | +import json | |
| 5 | +from itertools import combinations, permutations | |
| 6 | +from pathlib import Path | |
| 7 | + | |
| 8 | + | |
| 9 | +def descendants(word): | |
| 10 | + return {word[:i] + word[i + 1:j] + word[j + 1:] for i, j in combinations(range(len(word)), 2)} | |
| 11 | + | |
| 12 | + | |
| 13 | +def combine(left, right): | |
| 14 | + shared = left & right | |
| 15 | + left, right = sorted(left - shared), sorted(right - shared) | |
| 16 | + owner = {child: i for i, word in enumerate(right) for child in descendants(word)} | |
| 17 | + edges = [sorted({owner[child] for child in descendants(word) if child in owner}) for word in left] | |
| 18 | + | |
| 19 | + left_match = {} | |
| 20 | + right_match = {} | |
| 21 | + | |
| 22 | + def augment(a, seen): | |
| 23 | + for b in edges[a]: | |
| 24 | + if b in seen: | |
| 25 | + continue | |
| 26 | + seen.add(b) | |
| 27 | + if b not in right_match or augment(right_match[b], seen): | |
| 28 | + left_match[a] = b | |
| 29 | + right_match[b] = a | |
| 30 | + return True | |
| 31 | + return False | |
| 32 | + | |
| 33 | + for a in range(len(left)): | |
| 34 | + augment(a, set()) | |
| 35 | + | |
| 36 | + # The complement of Konig's minimum vertex cover is a maximum independent set. | |
| 37 | + reachable_left = {a for a in range(len(left)) if a not in left_match} | |
| 38 | + reachable_right = set() | |
| 39 | + queue = sorted(reachable_left) | |
| 40 | + for a in queue: | |
| 41 | + for b in edges[a]: | |
| 42 | + if left_match.get(a) == b or b in reachable_right: | |
| 43 | + continue | |
| 44 | + reachable_right.add(b) | |
| 45 | + matched = right_match[b] | |
| 46 | + if matched not in reachable_left: | |
| 47 | + queue.append(matched) | |
| 48 | + reachable_left.add(matched) | |
| 49 | + | |
| 50 | + result = shared | {left[a] for a in reachable_left} | |
| 51 | + result.update(word for b, word in enumerate(right) if b not in reachable_right) | |
| 52 | + assert len(result) == len(shared) + len(left) + len(right) - len(right_match) | |
| 53 | + return result | |
| 54 | + | |
| 55 | + | |
| 56 | +def read_code(path): | |
| 57 | + data = json.loads(path.read_text(encoding="utf-8")) | |
| 58 | + words = set(data["words"]) | |
| 59 | + if data["n"] != 17 or len(words) != len(data["words"]): | |
| 60 | + raise ValueError(f"Expected a length-17 code with distinct words in {path}") | |
| 61 | + occupied = set() | |
| 62 | + for word in words: | |
| 63 | + if len(word) != 17 or set(word) - {"0", "1"}: | |
| 64 | + raise ValueError(f"Invalid word in {path}") | |
| 65 | + children = descendants(word) | |
| 66 | + if not occupied.isdisjoint(children): | |
| 67 | + raise ValueError(f"Conflicting codewords in {path}") | |
| 68 | + occupied.update(children) | |
| 69 | + return words | |
| 70 | + | |
| 71 | + | |
| 72 | +def best_order(codes): | |
| 73 | + best = set() | |
| 74 | + best_order = () | |
| 75 | + for order in permutations(range(len(codes))): | |
| 76 | + candidate = codes[order[0]] | |
| 77 | + for i in order[1:]: | |
| 78 | + candidate = combine(candidate, codes[i]) | |
| 79 | + if len(candidate) > len(best): | |
| 80 | + best, best_order = candidate, order | |
| 81 | + return best, best_order | |
| 82 | + | |
| 83 | + | |
| 84 | +def main(): | |
| 85 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 86 | + parser.add_argument("output", type=Path) | |
| 87 | + parser.add_argument("codes", type=Path, nargs="+") | |
| 88 | + args = parser.parse_args() | |
| 89 | + if not 2 <= len(args.codes) <= 4: | |
| 90 | + parser.error("Supply between two and four valid length-17 codes") | |
| 91 | + codes = [read_code(path) for path in args.codes] | |
| 92 | + result, order = best_order(codes) | |
| 93 | + print("Input sizes:", ", ".join(str(len(code)) for code in codes)) | |
| 94 | + print("Winning order:", ", ".join(args.codes[i].name for i in order)) | |
| 95 | + print(f"Recombined {len(result)} words") | |
| 96 | + args.output.write_text(json.dumps({"n": 17, "words": sorted(result)}, indent=2) + "\n", encoding="utf-8") | |
| 97 | + | |
| 98 | + | |
| 99 | +if __name__ == "__main__": | |
| 100 | + main() | |
+10 −0 routes/irisbud-codex/n17-local-search/refinement-report.txt added View file
| @@ -0,0 +1,10 @@ | ||
| 1 | +Local-search rounds per seed: 1200000 | |
| 2 | +Starting code: 335 words | |
| 3 | +CP-SAT neighborhoods per seed: 330; deterministic effort: 0.7 | |
| 4 | +Seed 307 (local search): 335 words | |
| 5 | +Seed 313 (local search): 335 words | |
| 6 | +Seed 331 (CP-SAT): 335 words | |
| 7 | +Seed 337 (CP-SAT): 335 words | |
| 8 | +Pairwise recombination order: 307, 313, 331, 337 | |
| 9 | +Recombined code: 335 words | |
| 10 | +Retained starting code: 335 words | |
+113 −0 routes/irisbud-codex/n17-local-search/run_seeds.py added View file
| @@ -0,0 +1,113 @@ | ||
| 1 | +"""Run four searches, optionally using CP-SAT for two seeds, and retain the best result.""" | |
| 2 | + | |
| 3 | +import argparse | |
| 4 | +import json | |
| 5 | +import re | |
| 6 | +import shutil | |
| 7 | +import subprocess | |
| 8 | +import sys | |
| 9 | +import time | |
| 10 | +from pathlib import Path | |
| 11 | + | |
| 12 | +from recombine import best_order, read_code | |
| 13 | + | |
| 14 | + | |
| 15 | +def checkpoint_size(path): | |
| 16 | + if not path.exists(): | |
| 17 | + return 0 | |
| 18 | + return len(json.loads(path.read_text(encoding="utf-8"))["words"]) | |
| 19 | + | |
| 20 | + | |
| 21 | +def main(): | |
| 22 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 23 | + parser.add_argument("executable") | |
| 24 | + parser.add_argument("scratch", type=Path) | |
| 25 | + parser.add_argument("start", type=Path) | |
| 26 | + parser.add_argument("rounds", type=int) | |
| 27 | + parser.add_argument("seeds", nargs=4, type=int) | |
| 28 | + parser.add_argument("--optimizer-rounds", type=int, default=0) | |
| 29 | + parser.add_argument("--effort", type=float, default=0.7) | |
| 30 | + parser.add_argument("--escape", action="store_true") | |
| 31 | + args = parser.parse_args() | |
| 32 | + scratch, seeds = args.scratch, args.seeds | |
| 33 | + if len(set(seeds)) != 4: | |
| 34 | + parser.error("Provide four distinct seeds.") | |
| 35 | + if args.escape and args.optimizer_rounds < 1: | |
| 36 | + parser.error("Escape mode needs a positive CP-SAT round count") | |
| 37 | + optimize = set(seeds if args.escape else seeds[2:]) if args.optimizer_rounds else set() | |
| 38 | + outputs = {seed: scratch / f"code-{seed}.json" for seed in seeds} | |
| 39 | + workers = {} | |
| 40 | + try: | |
| 41 | + for seed in seeds: | |
| 42 | + if seed in optimize: | |
| 43 | + command = [sys.executable, "-B", "optimize.py", str(args.start), str(outputs[seed]), | |
| 44 | + "--seed", str(seed), "--rounds", str(args.optimizer_rounds), "--effort", str(args.effort)] | |
| 45 | + if args.escape: | |
| 46 | + command.append("--escape") | |
| 47 | + else: | |
| 48 | + command = [args.executable, str(seed), str(args.rounds), str(args.start), str(outputs[seed])] | |
| 49 | + with (scratch / f"seed-{seed}.log").open("w", encoding="utf-8") as log: | |
| 50 | + workers[seed] = subprocess.Popen(command, stdout=log, stderr=subprocess.STDOUT) | |
| 51 | + | |
| 52 | + previous = 0 | |
| 53 | + while True: | |
| 54 | + sizes = {seed: checkpoint_size(outputs[seed]) for seed in seeds} | |
| 55 | + completed = sum(worker.poll() is not None for worker in workers.values()) | |
| 56 | + largest = max(sizes.values()) | |
| 57 | + if largest > previous: | |
| 58 | + print(f"metric: code_size {largest}", flush=True) | |
| 59 | + previous = largest | |
| 60 | + print(f"progress: {completed}/{len(seeds)} searches done, best {largest}", flush=True) | |
| 61 | + if completed == len(seeds): | |
| 62 | + break | |
| 63 | + time.sleep(12) | |
| 64 | + finally: | |
| 65 | + for worker in workers.values(): | |
| 66 | + if worker.poll() is None: | |
| 67 | + worker.terminate() | |
| 68 | + worker.wait() | |
| 69 | + | |
| 70 | + failures = [seed for seed in seeds if workers[seed].returncode != 0] | |
| 71 | + if failures: | |
| 72 | + for seed in failures: | |
| 73 | + print((scratch / f"seed-{seed}.log").read_text(encoding="utf-8"), file=sys.stderr) | |
| 74 | + raise SystemExit(f"Search failed for seeds: {failures}") | |
| 75 | + | |
| 76 | + seed = max(seeds, key=lambda item: (sizes[item], -item)) | |
| 77 | + start_size = len(read_code(args.start)) | |
| 78 | + largest = sizes[seed] | |
| 79 | + pending = Path("n17.json.part") | |
| 80 | + lines = [f"Starting code: {start_size} words"] | |
| 81 | + if len(optimize) < len(seeds): | |
| 82 | + lines.append(f"Local-search rounds per seed: {args.rounds}") | |
| 83 | + if optimize: | |
| 84 | + lines.append(f"CP-SAT neighborhoods per seed: {args.optimizer_rounds}; deterministic effort: {args.effort}") | |
| 85 | + lines.extend(f"Seed {item} ({'CP-SAT' if item in optimize else 'local search'}): {sizes[item]} words" for item in seeds) | |
| 86 | + if args.escape: | |
| 87 | + for item in seeds: | |
| 88 | + log = (scratch / f"seed-{item}.log").read_text(encoding="utf-8") | |
| 89 | + current_sizes = [int(size) for size in re.findall(r"current (\d+), best", log)] | |
| 90 | + lines.append(f"Seed {item}: smallest accepted incumbent {min(current_sizes)} words") | |
| 91 | + | |
| 92 | + result, order = best_order([read_code(outputs[item]) for item in seeds]) | |
| 93 | + lines.append("Pairwise recombination order: " + ", ".join(str(seeds[i]) for i in order)) | |
| 94 | + lines.append(f"Recombined code: {len(result)} words") | |
| 95 | + if len(result) > largest: | |
| 96 | + largest = len(result) | |
| 97 | + pending.write_text(json.dumps({"n": 17, "words": sorted(result)}, indent=2) + "\n", encoding="utf-8") | |
| 98 | + lines.append(f"Winner: pairwise recombination, {largest} words") | |
| 99 | + elif largest > start_size: | |
| 100 | + shutil.copyfile(outputs[seed], pending) | |
| 101 | + lines.append(f"Winner: seed {seed}, {largest} words") | |
| 102 | + else: | |
| 103 | + shutil.copyfile(args.start, pending) | |
| 104 | + lines.append(f"Retained starting code: {start_size} words") | |
| 105 | + pending.replace("n17.json") | |
| 106 | + report = "escape-report.txt" if args.escape else ("refinement-report.txt" if optimize else "search-report.txt") | |
| 107 | + Path(report).write_text("\n".join(lines) + "\n", encoding="utf-8") | |
| 108 | + print(f"metric: code_size {largest}", flush=True) | |
| 109 | + print(lines[-1], flush=True) | |
| 110 | + | |
| 111 | + | |
| 112 | +if __name__ == "__main__": | |
| 113 | + main() | |
+7 −0 routes/irisbud-codex/n17-local-search/search-report.txt added View file
| @@ -0,0 +1,7 @@ | ||
| 1 | +Rounds per seed: 450000 | |
| 2 | +Start: n17.json | |
| 3 | +Seed 161: 335 words | |
| 4 | +Seed 193: 332 words | |
| 5 | +Seed 211: 331 words | |
| 6 | +Seed 251: 331 words | |
| 7 | +Winner: seed 161, 335 words | |
+387 −0 routes/irisbud-codex/n17-local-search/search.cpp added View file
| @@ -0,0 +1,387 @@ | ||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | +namespace { | |
| 17 | +constexpr int n = 17; | |
| 18 | +constexpr int word_count = 1 << n; | |
| 19 | +constexpr int descendant_count = 1 << (n - 2); | |
| 20 | + | |
| 21 | +int delete_bit(int word, int position) { | |
| 22 | + const int low = (1 << position) - 1; | |
| 23 | + return (word & low) | ((word >> 1) & ~low); | |
| 24 | +} | |
| 25 | + | |
| 26 | +struct Incidence { | |
| 27 | + std::vector<std::vector<std::uint16_t>> descendants{word_count}; | |
| 28 | + std::vector<std::vector<int>> parents{descendant_count}; | |
| 29 | + | |
| 30 | + Incidence() { | |
| 31 | + std::vector<int> last_seen(descendant_count, -1); | |
| 32 | + for (int word = 0; word < word_count; ++word) { | |
| 33 | + auto& row = descendants[word]; | |
| 34 | + for (int second = 1; second < n; ++second) { | |
| 35 | + const int once = delete_bit(word, second); | |
| 36 | + for (int first = 0; first < second; ++first) { | |
| 37 | + const int child = delete_bit(once, first); | |
| 38 | + if (last_seen[child] == word) continue; | |
| 39 | + last_seen[child] = word; | |
| 40 | + row.push_back(static_cast<std::uint16_t>(child)); | |
| 41 | + parents[child].push_back(word); | |
| 42 | + } | |
| 43 | + } | |
| 44 | + std::sort(row.begin(), row.end()); | |
| 45 | + } | |
| 46 | + } | |
| 47 | + | |
| 48 | + bool disjoint(int a, int b) const { | |
| 49 | + const auto& left = descendants[a]; | |
| 50 | + const auto& right = descendants[b]; | |
| 51 | + auto i = left.begin(), j = right.begin(); | |
| 52 | + while (i != left.end() && j != right.end()) { | |
| 53 | + if (*i == *j) return false; | |
| 54 | + if (*i < *j) ++i; | |
| 55 | + else ++j; | |
| 56 | + } | |
| 57 | + return true; | |
| 58 | + } | |
| 59 | +}; | |
| 60 | + | |
| 61 | +// Dense membership with constant-time insertion, deletion, and random access. | |
| 62 | +class WordSet { | |
| 63 | +public: | |
| 64 | + bool contains(int word) const { return positions[word] >= 0; } | |
| 65 | + int size() const { return static_cast<int>(words.size()); } | |
| 66 | + int operator[](int i) const { return words[i]; } | |
| 67 | + const std::vector<int>& values() const { return words; } | |
| 68 | + | |
| 69 | + void add(int word) { | |
| 70 | + positions[word] = size(); | |
| 71 | + words.push_back(word); | |
| 72 | + } | |
| 73 | + | |
| 74 | + void erase(int word) { | |
| 75 | + const int i = positions[word]; | |
| 76 | + words[i] = words.back(); | |
| 77 | + positions[words[i]] = i; | |
| 78 | + words.pop_back(); | |
| 79 | + positions[word] = -1; | |
| 80 | + } | |
| 81 | + | |
| 82 | +private: | |
| 83 | + std::vector<int> positions = std::vector<int>(word_count, -1); | |
| 84 | + std::vector<int> words; | |
| 85 | +}; | |
| 86 | + | |
| 87 | +struct Move { int word; bool added; }; | |
| 88 | + | |
| 89 | +class Search { | |
| 90 | +public: | |
| 91 | + Search(const Incidence& graph, std::uint32_t seed) : graph_(graph), random_(seed) { | |
| 92 | + for (int word = 0; word < word_count; ++word) free_.add(word); | |
| 93 | + } | |
| 94 | + | |
| 95 | + const WordSet& code() const { return code_; } | |
| 96 | + | |
| 97 | + void reset(const std::vector<int>& words) { | |
| 98 | + while (code_.size() > 0) erase(code_[0]); | |
| 99 | + for (int word : words) insert(word); | |
| 100 | + journal_.clear(); | |
| 101 | + } | |
| 102 | + | |
| 103 | + void step(int round, int best_size) { | |
| 104 | + const int previous = code_.size(); | |
| 105 | + journal_.clear(); | |
| 106 | + const int mode = draw(10); | |
| 107 | + if (mode < 7) { | |
| 108 | + const int insertions = mode < 4 ? 1 : 2 + draw(2); | |
| 109 | + for (int i = 0; i < insertions; ++i) force_candidate(mode < 4 ? 2 : 4); | |
| 110 | + } else { | |
| 111 | + const int removals = 2 + draw(mode == 9 ? 15 : 5); | |
| 112 | + for (int i = 0; i < removals; ++i) { | |
| 113 | + const int a = code_[draw(code_.size())]; | |
| 114 | + const int b = code_[draw(code_.size())]; | |
| 115 | + drop(graph_.descendants[a].size() > graph_.descendants[b].size() ? a : b); | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + const int samples = 1 + draw(18); | |
| 120 | + fill(samples); | |
| 121 | + const int probes = mode < 4 ? 6 : 14; | |
| 122 | + for (int i = 0; i < probes; ++i) { | |
| 123 | + if (one_for_two(code_[draw(code_.size())])) fill(samples); | |
| 124 | + } | |
| 125 | + if (round % 4 == 0 && two_for_three(code_[draw(code_.size())])) fill(samples); | |
| 126 | + | |
| 127 | + // A small loss can move the search off a plateau. The accepted drop | |
| 128 | + // widens and narrows periodically without losing the saved incumbent. | |
| 129 | + const int phase = round % 7200; | |
| 130 | + const int tolerance = phase < 3100 ? 4 : (phase < 5700 ? 8 : 12); | |
| 131 | + const int size = code_.size(); | |
| 132 | + if (size >= previous || (size >= best_size - tolerance && size + 2 >= previous && draw(6) == 0)) { | |
| 133 | + return; | |
| 134 | + } | |
| 135 | + for (auto i = journal_.rbegin(); i != journal_.rend(); ++i) { | |
| 136 | + if (i->added) erase(i->word); | |
| 137 | + else insert(i->word); | |
| 138 | + } | |
| 139 | + } | |
| 140 | + | |
| 141 | +private: | |
| 142 | + int draw(int upper) { return static_cast<int>(random_() % static_cast<unsigned>(upper)); } | |
| 143 | + | |
| 144 | + void insert(int word) { | |
| 145 | + if (occupied_[word] != 0 || code_.contains(word)) throw std::logic_error("invalid insertion"); | |
| 146 | + code_.add(word); | |
| 147 | + for (int child : graph_.descendants[word]) { | |
| 148 | + owner_[child] = word; | |
| 149 | + for (int parent : graph_.parents[child]) { | |
| 150 | + if (occupied_[parent]++ == 0) free_.erase(parent); | |
| 151 | + } | |
| 152 | + } | |
| 153 | + } | |
| 154 | + | |
| 155 | + void erase(int word) { | |
| 156 | + if (!code_.contains(word)) throw std::logic_error("invalid removal"); | |
| 157 | + code_.erase(word); | |
| 158 | + for (int child : graph_.descendants[word]) { | |
| 159 | + owner_[child] = -1; | |
| 160 | + for (int parent : graph_.parents[child]) { | |
| 161 | + if (--occupied_[parent] == 0) free_.add(parent); | |
| 162 | + } | |
| 163 | + } | |
| 164 | + } | |
| 165 | + | |
| 166 | + void take(int word) { insert(word); journal_.push_back({word, true}); } | |
| 167 | + void drop(int word) { erase(word); journal_.push_back({word, false}); } | |
| 168 | + | |
| 169 | + void fill(int samples) { | |
| 170 | + while (free_.size() > 0) { | |
| 171 | + int best = free_[draw(free_.size())]; | |
| 172 | + int cost = static_cast<int>(graph_.descendants[best].size()) + draw(9); | |
| 173 | + for (int i = 1; i < std::min(samples, free_.size()); ++i) { | |
| 174 | + const int word = free_[draw(free_.size())]; | |
| 175 | + const int rival = static_cast<int>(graph_.descendants[word].size()) + draw(9); | |
| 176 | + if (rival < cost) { | |
| 177 | + best = word; | |
| 178 | + cost = rival; | |
| 179 | + } | |
| 180 | + } | |
| 181 | + take(best); | |
| 182 | + } | |
| 183 | + } | |
| 184 | + | |
| 185 | + // Choose a new word with few blockers and preferentially trade it for | |
| 186 | + // owners using more descendants, freeing space for the greedy refill. | |
| 187 | + void force_candidate(int max_blockers) { | |
| 188 | + int best = -1; | |
| 189 | + int best_cost = std::numeric_limits<int>::max(); | |
| 190 | + std::array<int, 4> best_owners{}; | |
| 191 | + int best_count = 0; | |
| 192 | + const int pivot = code_[draw(code_.size())]; | |
| 193 | + | |
| 194 | + for (int i = 0; i < 48; ++i) { | |
| 195 | + int word = draw(word_count); | |
| 196 | + if (i < 32) { | |
| 197 | + const auto& children = graph_.descendants[pivot]; | |
| 198 | + const auto& parents = graph_.parents[children[draw(static_cast<int>(children.size()))]]; | |
| 199 | + word = parents[draw(static_cast<int>(parents.size()))]; | |
| 200 | + } | |
| 201 | + if (occupied_[word] == 0 || code_.contains(word)) continue; | |
| 202 | + | |
| 203 | + std::array<int, 4> owners{}; | |
| 204 | + int count = 0; | |
| 205 | + int released = 0; | |
| 206 | + for (int child : graph_.descendants[word]) { | |
| 207 | + const int owner = owner_[child]; | |
| 208 | + if (owner < 0 || std::find(owners.begin(), owners.begin() + count, owner) != owners.begin() + count) continue; | |
| 209 | + if (count == max_blockers) { | |
| 210 | + ++count; | |
| 211 | + break; | |
| 212 | + } | |
| 213 | + owners[count++] = owner; | |
| 214 | + released += static_cast<int>(graph_.descendants[owner].size()); | |
| 215 | + } | |
| 216 | + if (count > max_blockers) continue; | |
| 217 | + | |
| 218 | + const int cost = count * 20 + static_cast<int>(graph_.descendants[word].size()) - released / 2 + draw(30); | |
| 219 | + if (cost < best_cost) { | |
| 220 | + best = word; | |
| 221 | + best_cost = cost; | |
| 222 | + best_owners = owners; | |
| 223 | + best_count = count; | |
| 224 | + } | |
| 225 | + } | |
| 226 | + if (best < 0) return; | |
| 227 | + for (int i = 0; i < best_count; ++i) drop(best_owners[i]); | |
| 228 | + take(best); | |
| 229 | + } | |
| 230 | + | |
| 231 | + // A touched outside word is available after removing owner exactly when | |
| 232 | + // the occupied children it shares with owner account for all blockers. | |
| 233 | + bool one_for_two(int owner) { | |
| 234 | + collect_options(owner); | |
| 235 | + const int count = static_cast<int>(options_.size()); | |
| 236 | + if (count < 2) return false; | |
| 237 | + const int offset = draw(count); | |
| 238 | + for (int i = 0; i < count; ++i) { | |
| 239 | + const int a = options_[(i + offset) % count]; | |
| 240 | + for (int j = 0; j < i; ++j) { | |
| 241 | + const int b = options_[(j + offset) % count]; | |
| 242 | + if (!graph_.disjoint(a, b)) continue; | |
| 243 | + drop(owner); | |
| 244 | + take(a); | |
| 245 | + take(b); | |
| 246 | + return true; | |
| 247 | + } | |
| 248 | + } | |
| 249 | + return false; | |
| 250 | + } | |
| 251 | + | |
| 252 | + void collect_options(int first, int second = -1) { | |
| 253 | + touched_.clear(); | |
| 254 | + options_.clear(); | |
| 255 | + for (int owner : {first, second}) { | |
| 256 | + if (owner < 0) continue; | |
| 257 | + for (int child : graph_.descendants[owner]) { | |
| 258 | + for (int word : graph_.parents[child]) { | |
| 259 | + if (shared_[word]++ == 0) touched_.push_back(word); | |
| 260 | + } | |
| 261 | + } | |
| 262 | + } | |
| 263 | + for (int word : touched_) { | |
| 264 | + if (word != first && word != second && shared_[word] == occupied_[word]) options_.push_back(word); | |
| 265 | + shared_[word] = 0; | |
| 266 | + } | |
| 267 | + } | |
| 268 | + | |
| 269 | + // Look for a pair of incumbents that jointly block an outside word. | |
| 270 | + // After removing the pair, three compatible options are a net gain. | |
| 271 | + bool two_for_three(int first) { | |
| 272 | + const auto& children = graph_.descendants[first]; | |
| 273 | + int second = -1; | |
| 274 | + for (int attempt = 0; attempt < 48 && second < 0; ++attempt) { | |
| 275 | + const auto& parents = graph_.parents[children[draw(static_cast<int>(children.size()))]]; | |
| 276 | + const int word = parents[draw(static_cast<int>(parents.size()))]; | |
| 277 | + if (code_.contains(word)) continue; | |
| 278 | + for (int child : graph_.descendants[word]) { | |
| 279 | + const int owner = owner_[child]; | |
| 280 | + if (owner < 0 || owner == first || owner == second) continue; | |
| 281 | + if (second >= 0) { | |
| 282 | + second = -1; | |
| 283 | + break; | |
| 284 | + } | |
| 285 | + second = owner; | |
| 286 | + } | |
| 287 | + } | |
| 288 | + if (second < 0) return false; | |
| 289 | + | |
| 290 | + collect_options(first, second); | |
| 291 | + const int count = static_cast<int>(options_.size()); | |
| 292 | + if (count < 3) return false; | |
| 293 | + const int offset = draw(count); | |
| 294 | + std::vector<int> neighbors; | |
| 295 | + neighbors.reserve(count); | |
| 296 | + for (int i = 0; i < count; ++i) { | |
| 297 | + neighbors.clear(); | |
| 298 | + const int a = options_[(i + offset) % count]; | |
| 299 | + for (int j = i + 1; j < count; ++j) { | |
| 300 | + const int b = options_[(j + offset) % count]; | |
| 301 | + if (!graph_.disjoint(a, b)) continue; | |
| 302 | + for (int c : neighbors) { | |
| 303 | + if (!graph_.disjoint(b, c)) continue; | |
| 304 | + drop(first); | |
| 305 | + drop(second); | |
| 306 | + take(a); | |
| 307 | + take(b); | |
| 308 | + take(c); | |
| 309 | + return true; | |
| 310 | + } | |
| 311 | + neighbors.push_back(b); | |
| 312 | + } | |
| 313 | + } | |
| 314 | + return false; | |
| 315 | + } | |
| 316 | + | |
| 317 | + const Incidence& graph_; | |
| 318 | + std::mt19937 random_; | |
| 319 | + WordSet code_; | |
| 320 | + WordSet free_; | |
| 321 | + std::vector<int> owner_ = std::vector<int>(descendant_count, -1); | |
| 322 | + std::vector<std::uint8_t> occupied_ = std::vector<std::uint8_t>(word_count); | |
| 323 | + std::vector<std::uint8_t> shared_ = std::vector<std::uint8_t>(word_count); | |
| 324 | + std::vector<int> touched_; | |
| 325 | + std::vector<int> options_; | |
| 326 | + std::vector<Move> journal_; | |
| 327 | +}; | |
| 328 | + | |
| 329 | +std::vector<int> read_code(const std::filesystem::path& file) { | |
| 330 | + std::ifstream input(file); | |
| 331 | + if (!input) throw std::runtime_error("cannot read the starting code"); | |
| 332 | + const std::string json{std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>()}; | |
| 333 | + const std::regex word_pattern(R"re("([01]{17})")re"); | |
| 334 | + std::vector<int> result; | |
| 335 | + for (std::sregex_iterator i(json.begin(), json.end(), word_pattern), end; i != end; ++i) { | |
| 336 | + result.push_back(std::stoi((*i)[1], nullptr, 2)); | |
| 337 | + } | |
| 338 | + if (result.empty()) throw std::runtime_error("the starting code contains no words"); | |
| 339 | + return result; | |
| 340 | +} | |
| 341 | + | |
| 342 | +void write_code(const std::filesystem::path& file, std::vector<int> words) { | |
| 343 | + std::sort(words.begin(), words.end()); | |
| 344 | + std::filesystem::path temporary = file; | |
| 345 | + temporary += ".tmp"; | |
| 346 | + std::ofstream output(temporary); | |
| 347 | + output.exceptions(std::ios::failbit | std::ios::badbit); | |
| 348 | + output << "{\n \"n\": " << n << ",\n \"words\": [\n"; | |
| 349 | + for (std::size_t i = 0; i < words.size(); ++i) { | |
| 350 | + output << " \"" << std::bitset<n>(words[i]) << '"' << (i + 1 == words.size() ? "\n" : ",\n"); | |
| 351 | + } | |
| 352 | + output << " ]\n}\n"; | |
| 353 | + output.close(); | |
| 354 | + std::filesystem::rename(temporary, file); | |
| 355 | +} | |
| 356 | +} // namespace | |
| 357 | + | |
| 358 | +int main(int argc, char** argv) { | |
| 359 | + try { | |
| 360 | + if (argc != 5) throw std::runtime_error("usage: search SEED ROUNDS INPUT_JSON OUTPUT_JSON"); | |
| 361 | + const auto seed = std::stoull(argv[1]); | |
| 362 | + const int rounds = std::stoi(argv[2]); | |
| 363 | + if (rounds < 1 || seed > std::numeric_limits<std::uint32_t>::max()) throw std::runtime_error("invalid seed or round count"); | |
| 364 | + auto best = read_code(argv[3]); | |
| 365 | + const Incidence graph; | |
| 366 | + Search search(graph, static_cast<std::uint32_t>(seed)); | |
| 367 | + search.reset(best); | |
| 368 | + write_code(argv[4], best); | |
| 369 | + std::cout << "metric: code_size " << best.size() << std::endl; | |
| 370 | + for (int round = 1; round <= rounds; ++round) { | |
| 371 | + if (round % 7200 == 1 && round > 1) search.reset(best); | |
| 372 | + search.step(round, static_cast<int>(best.size())); | |
| 373 | + if (search.code().size() > static_cast<int>(best.size())) { | |
| 374 | + best = search.code().values(); | |
| 375 | + write_code(argv[4], best); | |
| 376 | + std::cout << "metric: code_size " << best.size() << "\nround " << round << std::endl; | |
| 377 | + } | |
| 378 | + if (round % 1000 == 0 || round == rounds) { | |
| 379 | + std::cout << "progress: " << round << '/' << rounds << " rounds, best " << best.size() << std::endl; | |
| 380 | + } | |
| 381 | + } | |
| 382 | + std::cout << "seed " << seed << ", best " << best.size() << " codewords" << std::endl; | |
| 383 | + } catch (const std::exception& error) { | |
| 384 | + std::cerr << error.what() << '\n'; | |
| 385 | + return 1; | |
| 386 | + } | |
| 387 | +} | |
+30 −0 routes/irisbud-codex/n17-local-search/search.sbatch added View file
| @@ -0,0 +1,30 @@ | ||
| 1 | +#!/usr/bin/env bash | |
| 2 | +#SBATCH --job-name=n17-local-search | |
| 3 | +#SBATCH --cpus-per-task=4 | |
| 4 | +#SBATCH --time=00:30:00 | |
| 5 | +#SBATCH --mem=1024M | |
| 6 | +set -euo pipefail | |
| 7 | + | |
| 8 | +rounds=${1:?usage: search.sbatch ROUNDS SEED SEED SEED SEED [START_JSON [OPTIMIZER_ROUNDS [escape]]]} | |
| 9 | +shift | |
| 10 | +repo=${SS_INPUT:-$(git rev-parse --show-toplevel)} | |
| 11 | +input=${5:-$repo/constructions/n17.json} | |
| 12 | +if [[ $# -lt 4 || $# -gt 7 || ( $# -eq 7 && $7 != escape ) ]]; then | |
| 13 | + echo 'Specify four seeds, optionally followed by a starting code, CP-SAT round count, and escape mode.' >&2 | |
| 14 | + exit 2 | |
| 15 | +fi | |
| 16 | + | |
| 17 | +tmp_base=$(cd -- "${TMPDIR:-/tmp}" && pwd -P) | |
| 18 | +scratch=$(mktemp -d "$tmp_base/n17-search.XXXXXXXX") | |
| 19 | +scratch=$(cd -- "$scratch" && pwd -P) | |
| 20 | +[[ $(dirname -- "$scratch") == "$tmp_base" && ${scratch##*/} == n17-search.* ]] | |
| 21 | +trap 'rm -rf -- "$scratch"' EXIT | |
| 22 | +options=(--optimizer-rounds "${6:-0}") | |
| 23 | +if [[ ${7:-} == escape ]]; then | |
| 24 | + options+=(--escape --effort 1.1) | |
| 25 | +else | |
| 26 | + "${CXX:-c++}" -O3 -std=c++17 search.cpp -o "$scratch/search.exe" | |
| 27 | +fi | |
| 28 | +"${PYTHON:-python3}" -B run_seeds.py "$scratch/search.exe" "$scratch" "$input" "$rounds" "$1" "$2" "$3" "$4" \ | |
| 29 | + "${options[@]}" | |
| 30 | +"${PYTHON:-python3}" -B "$repo/checks/judge/check.py" . | |
+23 −0 routes/irisbud-codex/n17-local-search/slurm-1112.out added View file
| @@ -0,0 +1,23 @@ | ||
| 1 | +progress: 0/4 searches done, best 0 | |
| 2 | +metric: code_size 331 | |
| 3 | +progress: 0/4 searches done, best 331 | |
| 4 | +metric: code_size 332 | |
| 5 | +progress: 0/4 searches done, best 332 | |
| 6 | +progress: 0/4 searches done, best 332 | |
| 7 | +progress: 0/4 searches done, best 332 | |
| 8 | +progress: 0/4 searches done, best 332 | |
| 9 | +progress: 0/4 searches done, best 332 | |
| 10 | +progress: 0/4 searches done, best 332 | |
| 11 | +progress: 0/4 searches done, best 332 | |
| 12 | +progress: 0/4 searches done, best 332 | |
| 13 | +metric: code_size 333 | |
| 14 | +progress: 0/4 searches done, best 333 | |
| 15 | +metric: code_size 335 | |
| 16 | +progress: 0/4 searches done, best 335 | |
| 17 | +progress: 0/4 searches done, best 335 | |
| 18 | +progress: 0/4 searches done, best 335 | |
| 19 | +progress: 2/4 searches done, best 335 | |
| 20 | +progress: 4/4 searches done, best 335 | |
| 21 | +Winner: seed 161, 335 words | |
| 22 | +n17: 335 words (n17.json), -14 against the record | |
| 23 | +score 0.961937; no new record | |
+44 −0 routes/irisbud-codex/n17-local-search/slurm-1121.out added View file
| @@ -0,0 +1,44 @@ | ||
| 1 | +progress: 0/4 searches done, best 0 | |
| 2 | +metric: code_size 335 | |
| 3 | +progress: 0/4 searches done, best 335 | |
| 4 | +progress: 0/4 searches done, best 335 | |
| 5 | +progress: 0/4 searches done, best 335 | |
| 6 | +progress: 0/4 searches done, best 335 | |
| 7 | +progress: 0/4 searches done, best 335 | |
| 8 | +progress: 0/4 searches done, best 335 | |
| 9 | +progress: 0/4 searches done, best 335 | |
| 10 | +progress: 0/4 searches done, best 335 | |
| 11 | +progress: 0/4 searches done, best 335 | |
| 12 | +progress: 0/4 searches done, best 335 | |
| 13 | +progress: 1/4 searches done, best 335 | |
| 14 | +progress: 2/4 searches done, best 335 | |
| 15 | +progress: 2/4 searches done, best 335 | |
| 16 | +progress: 2/4 searches done, best 335 | |
| 17 | +progress: 2/4 searches done, best 335 | |
| 18 | +progress: 2/4 searches done, best 335 | |
| 19 | +progress: 2/4 searches done, best 335 | |
| 20 | +progress: 2/4 searches done, best 335 | |
| 21 | +progress: 2/4 searches done, best 335 | |
| 22 | +progress: 2/4 searches done, best 335 | |
| 23 | +progress: 2/4 searches done, best 335 | |
| 24 | +progress: 2/4 searches done, best 335 | |
| 25 | +progress: 2/4 searches done, best 335 | |
| 26 | +progress: 2/4 searches done, best 335 | |
| 27 | +progress: 2/4 searches done, best 335 | |
| 28 | +progress: 2/4 searches done, best 335 | |
| 29 | +progress: 2/4 searches done, best 335 | |
| 30 | +progress: 2/4 searches done, best 335 | |
| 31 | +progress: 2/4 searches done, best 335 | |
| 32 | +progress: 2/4 searches done, best 335 | |
| 33 | +progress: 2/4 searches done, best 335 | |
| 34 | +progress: 2/4 searches done, best 335 | |
| 35 | +progress: 2/4 searches done, best 335 | |
| 36 | +progress: 2/4 searches done, best 335 | |
| 37 | +progress: 3/4 searches done, best 335 | |
| 38 | +progress: 3/4 searches done, best 335 | |
| 39 | +progress: 3/4 searches done, best 335 | |
| 40 | +progress: 4/4 searches done, best 335 | |
| 41 | +metric: code_size 335 | |
| 42 | +Retained starting code: 335 words | |
| 43 | +n17: 335 words (n17.json), -14 against the record | |
| 44 | +score 0.961937; no new record | |
+38 −0 routes/irisbud-codex/n17-local-search/slurm-1129.out added View file
| @@ -0,0 +1,38 @@ | ||
| 1 | +progress: 0/4 searches done, best 0 | |
| 2 | +metric: code_size 335 | |
| 3 | +progress: 0/4 searches done, best 335 | |
| 4 | +progress: 0/4 searches done, best 335 | |
| 5 | +progress: 0/4 searches done, best 335 | |
| 6 | +progress: 0/4 searches done, best 335 | |
| 7 | +progress: 0/4 searches done, best 335 | |
| 8 | +progress: 0/4 searches done, best 335 | |
| 9 | +progress: 0/4 searches done, best 335 | |
| 10 | +progress: 0/4 searches done, best 335 | |
| 11 | +progress: 0/4 searches done, best 335 | |
| 12 | +progress: 0/4 searches done, best 335 | |
| 13 | +progress: 0/4 searches done, best 335 | |
| 14 | +progress: 0/4 searches done, best 335 | |
| 15 | +progress: 0/4 searches done, best 335 | |
| 16 | +progress: 0/4 searches done, best 335 | |
| 17 | +progress: 0/4 searches done, best 335 | |
| 18 | +progress: 0/4 searches done, best 335 | |
| 19 | +progress: 0/4 searches done, best 335 | |
| 20 | +progress: 0/4 searches done, best 335 | |
| 21 | +progress: 0/4 searches done, best 335 | |
| 22 | +progress: 0/4 searches done, best 335 | |
| 23 | +progress: 0/4 searches done, best 335 | |
| 24 | +progress: 0/4 searches done, best 335 | |
| 25 | +progress: 0/4 searches done, best 335 | |
| 26 | +progress: 0/4 searches done, best 335 | |
| 27 | +progress: 0/4 searches done, best 335 | |
| 28 | +progress: 0/4 searches done, best 335 | |
| 29 | +progress: 0/4 searches done, best 335 | |
| 30 | +progress: 0/4 searches done, best 335 | |
| 31 | +progress: 0/4 searches done, best 335 | |
| 32 | +progress: 0/4 searches done, best 335 | |
| 33 | +progress: 0/4 searches done, best 335 | |
| 34 | +progress: 4/4 searches done, best 335 | |
| 35 | +metric: code_size 335 | |
| 36 | +Retained starting code: 335 words | |
| 37 | +n17: 335 words (n17.json), -14 against the record | |
| 38 | +score 0.961937; no new record | |
