-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_knowledge.py
More file actions
154 lines (130 loc) Β· 5.34 KB
/
Copy pathinit_knowledge.py
File metadata and controls
154 lines (130 loc) Β· 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
"""
One-time script: initialise knowledge/task_XXX/ for all 400 tasks.
Reads data/*.json + current scores + current ONNX cost breakdowns.
Run once: /Users/yeyang/miniconda3/envs/neurogolf/bin/python init_knowledge.py
"""
import json, math, os, sys
from pathlib import Path
ROOT = Path(__file__).parent
DATA = ROOT / "data"
ONNX_DIR = ROOT / "submissions" / "s_6256_03" / "onnx"
KNOWLEDGE = ROOT / "knowledge"
# Color representations (compact single char)
COLOR_CHARS = ".123456789" # 0=. 1-9=digit
def grid_to_str(grid):
lines = []
for row in grid:
lines.append("".join(COLOR_CHARS[c] if c < 10 else "?" for c in row))
return "\n".join(lines)
def grid_dims(grid):
h = len(grid)
w = len(grid[0]) if grid else 0
return h, w
# Load scores
with open("/tmp/task_scores.json") as f:
scores = json.load(f)
# Load ONNX sizes
onnx_sizes = {}
if ONNX_DIR.exists():
for f in ONNX_DIR.glob("task*.onnx"):
tid = int(f.stem.replace("task", ""))
onnx_sizes[tid] = f.stat().st_size
def cost_from_score(sc):
if sc <= 1.0: return None
return math.exp(25.0 - sc)
def difficulty_tag(sc):
if sc >= 22: return "EASY (top tier)"
if sc >= 18: return "MEDIUM-EASY"
if sc >= 15: return "MEDIUM"
if sc >= 12: return "HARD"
return "VERY HARD"
created, skipped = 0, 0
for tid in range(1, 401):
task_file = DATA / f"task{tid:03d}.json"
if not task_file.exists():
print(f" task{tid:03d}: no data file, skip")
skipped += 1
continue
with open(task_file) as f:
task = json.load(f)
task_dir = KNOWLEDGE / f"task_{tid:03d}"
task_dir.mkdir(parents=True, exist_ok=True)
sc = scores.get(str(tid), 0.0)
cost = cost_from_score(sc)
onnx_size = onnx_sizes.get(tid, 0)
n_train = len(task["train"])
n_test = len(task["test"])
n_arcgen = len(task.get("arc-gen", []))
# ββ description.md ββββββββββββββββββββββββββββββββββββββββββββ
desc_path = task_dir / "description.md"
if not desc_path.exists():
lines = [f"# Task {tid:03d}"]
lines.append(f"\n**Current score:** {sc:.4f} | **Difficulty:** {difficulty_tag(sc)}")
if cost:
lines.append(f"**Estimated cost:** {cost:,.0f} params+bytes | **ONNX size:** {onnx_size:,} B")
lines.append(f"**Examples:** {n_train} train, {n_test} test, {n_arcgen} arc-gen")
lines.append("")
lines.append("## Transformation Rule")
lines.append("")
lines.append("*(Fill in after understanding the task)*")
lines.append("")
lines.append("## Train Examples")
lines.append("")
lines.append("Color key: `.`=black `1`=blue `2`=red `3`=green `4`=yellow `5`=grey `6`=magenta `7`=orange `8`=cyan `9`=maroon")
lines.append("")
for i, ex in enumerate(task["train"]):
ih, iw = grid_dims(ex["input"])
oh, ow = grid_dims(ex["output"])
lines.append(f"### Train {i+1} ({ih}Γ{iw} β {oh}Γ{ow})")
lines.append("```")
lines.append("INPUT:")
lines.append(grid_to_str(ex["input"]))
lines.append("OUTPUT:")
lines.append(grid_to_str(ex["output"]))
lines.append("```")
lines.append("")
if task.get("test"):
ex = task["test"][0]
ih, iw = grid_dims(ex["input"])
oh, ow = grid_dims(ex["output"])
lines.append(f"## Test Example ({ih}Γ{iw} β {oh}Γ{ow})")
lines.append("```")
lines.append("INPUT:")
lines.append(grid_to_str(ex["input"]))
lines.append("OUTPUT:")
lines.append(grid_to_str(ex["output"]))
lines.append("```")
lines.append("")
lines.append("## Category Tags")
lines.append("")
lines.append("*(e.g., color_replace, spatial_shift, pattern_tile, object_detect, border_fill)*")
desc_path.write_text("\n".join(lines))
# ββ insights.md ββββββββββββββββββββββββββββββββββββββββββββββββ
ins_path = task_dir / "insights.md"
if not ins_path.exists():
ins_path.write_text(f"""# Task {tid:03d} β Iteration Log
## Current Best
- **Score:** {sc:.4f}
- **Cost:** {f"{cost:,.0f}" if cost else "0 (free!)"}
- **Source:** s_6256_03 (initial submission)
- **ONNX size:** {onnx_size:,} B
## Attempt History
| Version | Score | Delta | Description | Result |
|---------|-------|-------|-------------|--------|
| v0 (baseline) | {sc:.4f} | β | Initial submission | β
LB confirmed |
## Notes
*(Add insights as you iterate β what patterns work, what fails, hidden-test risks)*
## Score Target
To reach 18 pts β need cost < 5,958
To reach 20 pts β need cost < 799
To reach 22 pts β need cost < 107
""")
# ββ best_score.txt βββββββββββββββββββββββββββββββββββββββββββββ
score_path = task_dir / "best_score.txt"
if not score_path.exists():
score_path.write_text(f"{sc:.6f}\n")
created += 1
if created % 50 == 0:
print(f" {created}/400 created...")
print(f"\nDone. Created: {created}, Skipped: {skipped}")
print(f"Knowledge base at: {KNOWLEDGE}")