anhtld commited on
Commit
c86c41e
·
verified ·
1 Parent(s): 68d0545

test CTT proxy comparison artifact

Browse files
Files changed (1) hide show
  1. tests/test_ctt_proxy_comparison.py +108 -0
tests/test_ctt_proxy_comparison.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from pathlib import Path
5
+
6
+ from scripts import build_ctt_proxy_comparison as comparison
7
+
8
+
9
+ def _write_proxy_run(
10
+ run_dir: Path,
11
+ *,
12
+ pptc20: float,
13
+ pptc40: float,
14
+ neg20: float,
15
+ neg40: float,
16
+ pos_closer: float,
17
+ mean_pos: float,
18
+ mean_neg: float,
19
+ diversity: float,
20
+ collapse: float,
21
+ ) -> None:
22
+ run_dir.mkdir(parents=True)
23
+ row = {
24
+ "chart_id": "c0",
25
+ "task_id": "PickCube-v1",
26
+ "seed": "0",
27
+ "pptc_at_16_thr_0p20": pptc20,
28
+ "pptc_at_16_thr_0p40": pptc40,
29
+ "negative_near_at_16_thr_0p20": neg20,
30
+ "negative_near_at_16_thr_0p40": neg40,
31
+ "pos_closer_than_neg_at_16": pos_closer,
32
+ "mean_positive_distance_at_16": mean_pos,
33
+ "mean_negative_distance_at_16": mean_neg,
34
+ "candidate_diversity_at_16": diversity,
35
+ "collapse_rate_at_16": collapse,
36
+ "proxy_support_distance_at_16": mean_pos,
37
+ }
38
+ summary = {
39
+ key: {"micro": {"mean": value}}
40
+ for key, value in row.items()
41
+ if isinstance(value, float)
42
+ }
43
+ (run_dir / "metrics.json").write_text(
44
+ json.dumps(
45
+ {
46
+ "num_rows": 1,
47
+ "summary": summary,
48
+ "rows": [row],
49
+ "data_hash": "data",
50
+ "target_split_hash": "split",
51
+ },
52
+ indent=2,
53
+ )
54
+ + "\n"
55
+ )
56
+
57
+
58
+ def test_ctt_proxy_comparison_writes_full_proxy_gate_without_markdown(
59
+ tmp_path, monkeypatch
60
+ ) -> None:
61
+ local = tmp_path / "local_atlas"
62
+ ctt = tmp_path / "ctt_residual"
63
+ _write_proxy_run(
64
+ local,
65
+ pptc20=0.4,
66
+ pptc40=0.7,
67
+ neg20=0.03,
68
+ neg40=0.2,
69
+ pos_closer=0.6,
70
+ mean_pos=0.7,
71
+ mean_neg=0.8,
72
+ diversity=0.9,
73
+ collapse=0.05,
74
+ )
75
+ _write_proxy_run(
76
+ ctt,
77
+ pptc20=0.2,
78
+ pptc40=0.6,
79
+ neg20=0.035,
80
+ neg40=0.25,
81
+ pos_closer=0.8,
82
+ mean_pos=0.4,
83
+ mean_neg=0.5,
84
+ diversity=0.3,
85
+ collapse=0.06,
86
+ )
87
+ monkeypatch.setattr(
88
+ comparison,
89
+ "DEFAULT_RUNS",
90
+ [("local_atlas", [local]), ("ctt_residual", [ctt])],
91
+ )
92
+
93
+ out_dir = tmp_path / "comparison"
94
+ assert comparison.main(["--out-dir", str(out_dir), "--no-markdown-report"]) == 0
95
+
96
+ metrics = json.loads((out_dir / "metrics.json").read_text())
97
+ ctt_row = next(row for row in metrics["rows"] if row["method"] == "ctt_residual")
98
+ by_task = json.loads((out_dir / "metrics_by_task.json").read_text())
99
+ by_seed = json.loads((out_dir / "metrics_by_seed.json").read_text())
100
+
101
+ assert ctt_row["proxy_gate_pass"] is True
102
+ assert ctt_row["pos_closer_than_neg"] == 0.8
103
+ assert ctt_row["mean_negative_distance"] == 0.5
104
+ assert ctt_row["collapse_rate"] == 0.06
105
+ assert by_task["ctt_residual"]["PickCube-v1"]["pos_closer_than_neg"] == 0.8
106
+ assert by_seed["ctt_residual"]["0"]["mean_negative_distance"] == 0.5
107
+ assert "Pos<Neg" in (out_dir / "table.tex").read_text()
108
+ assert not (out_dir / "report.md").exists()