Skip to content

Commit 585d1fc

Browse files
Xrekiclaude
andcommitted
Improve build_db: auto-collect samples, loop over types, track stats
- Auto-collect sample paths by scanning for model.py when list file is missing - Use loop over sample_types instead of repeated code blocks - Track and print success/fail counts and order range per type Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent e1393bf commit 585d1fc

2 files changed

Lines changed: 53 additions & 54 deletions

File tree

sqlite/build_db.py

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,41 @@
77
from init_db import migrate
88

99

10+
def collect_sample_paths(model_path_prefix):
11+
"""Collect relative paths of directories containing model.py under model_path_prefix."""
12+
sample_paths = []
13+
for dirpath, _, filenames in os.walk(model_path_prefix):
14+
if "model.py" in filenames:
15+
rel = os.path.relpath(dirpath, model_path_prefix)
16+
sample_paths.append(rel)
17+
sample_paths.sort()
18+
return sample_paths
19+
20+
1021
def insert_from_list(
11-
list_file,
22+
list_file_path,
1223
model_path_prefix,
1324
sample_type,
1425
repo_uid,
1526
db_path,
1627
op_names_path_prefix,
1728
start_order=0,
1829
):
19-
if not os.path.isfile(list_file):
20-
print(f"List file not found: {list_file}, skipping")
21-
return start_order
22-
23-
with open(list_file) as f:
24-
paths = [line.strip() for line in f if line.strip()]
30+
if os.path.isfile(list_file_path):
31+
with open(list_file_path) as f:
32+
sample_paths = [line.strip() for line in f if line.strip()]
33+
sample_paths.sort()
34+
else:
35+
print(
36+
f"List file not found: {list_file_path}, collecting from {model_path_prefix}"
37+
)
38+
sample_paths = collect_sample_paths(model_path_prefix)
2539

40+
total = len(sample_paths)
2641
order_value = start_order
27-
for relative_model_path in paths:
42+
for relative_model_path in sample_paths:
2843
print(f"insert : {relative_model_path}")
29-
insert_one_sample(
44+
successed = insert_one_sample(
3045
model_path_prefix=model_path_prefix,
3146
relative_model_path=relative_model_path,
3247
repo_uid=repo_uid,
@@ -35,9 +50,10 @@ def insert_from_list(
3550
db_path=db_path,
3651
op_names_path_prefix=op_names_path_prefix,
3752
)
38-
order_value += 1
53+
if successed:
54+
order_value += 1
3955

40-
return order_value
56+
return order_value, total
4157

4258

4359
def main(args):
@@ -54,49 +70,28 @@ def main(args):
5470

5571
order_value = 0
5672

57-
# full_graph
58-
order_value = insert_from_list(
59-
list_file=os.path.join(dataset_root, "full_graph.txt"),
60-
model_path_prefix=os.path.join(dataset_root, "full_graph"),
61-
sample_type="full_graph",
62-
repo_uid=repo_uid,
63-
db_path=db_path,
64-
op_names_path_prefix="",
65-
start_order=order_value,
66-
)
67-
68-
# typical_graph
69-
order_value = insert_from_list(
70-
list_file=os.path.join(dataset_root, "typical_graph.txt"),
71-
model_path_prefix=os.path.join(dataset_root, "typical_graph"),
72-
sample_type="typical_graph",
73-
repo_uid=repo_uid,
74-
db_path=db_path,
75-
op_names_path_prefix=op_names_path_prefix,
76-
start_order=order_value,
77-
)
78-
79-
# fusible_graph
80-
order_value = insert_from_list(
81-
list_file=os.path.join(dataset_root, "fusible_graph.txt"),
82-
model_path_prefix=os.path.join(dataset_root, "fusible_graph"),
83-
sample_type="fusible_graph",
84-
repo_uid=repo_uid,
85-
db_path=db_path,
86-
op_names_path_prefix=op_names_path_prefix,
87-
start_order=order_value,
88-
)
89-
90-
# sole_op_graph
91-
order_value = insert_from_list(
92-
list_file=os.path.join(dataset_root, "sole_op_graph.txt"),
93-
model_path_prefix=os.path.join(dataset_root, "sole_op_graph"),
94-
sample_type="sole_op_graph",
95-
repo_uid=repo_uid,
96-
db_path=db_path,
97-
op_names_path_prefix=op_names_path_prefix,
98-
start_order=order_value,
99-
)
73+
sample_types = [
74+
("full_graph", ""),
75+
("typical_graph", op_names_path_prefix),
76+
("fusible_graph", op_names_path_prefix),
77+
("sole_op_graph", op_names_path_prefix),
78+
]
79+
for sample_type, op_prefix in sample_types:
80+
order_start = order_value
81+
order_value, total = insert_from_list(
82+
list_file_path=os.path.join(dataset_root, f"{sample_type}.txt"),
83+
model_path_prefix=os.path.join(dataset_root, sample_type),
84+
sample_type=sample_type,
85+
repo_uid=repo_uid,
86+
db_path=db_path,
87+
op_names_path_prefix=op_prefix,
88+
start_order=order_value,
89+
)
90+
num_success = order_value - order_start
91+
print(
92+
f"[{sample_type}] total={total}, success={num_success}, "
93+
f"fail={total - num_success}, order=[{order_start}, {order_value})"
94+
)
10095

10196
print("all done")
10297

sqlite/graphsample_insert.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,12 @@ def insert_one_sample(
507507
except sqlite3.IntegrityError as e:
508508
print("insert failed: integrity error (possible duplicate uuid or graph_hash)")
509509
print(f"error info: {e}")
510+
return False
510511
except Exception as e:
511512
print(f"insert failed: {e}")
513+
return False
514+
515+
return True
512516

513517

514518
def main(args):

0 commit comments

Comments
 (0)