File size: 8,212 Bytes
ceac1e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/usr/bin/env python3
"""Scaffold a canonical ICML 2026 reproduction Trackio logbook."""

from __future__ import annotations

import argparse
import json
import re
import sys


def repro_slug_from_title(title: str, *, max_len: int = 96) -> str:
    clean = re.sub(r"^Reproduction:\s*", "", title.strip(), flags=re.I).strip()
    slug = re.sub(r"[^a-zA-Z0-9]+", "-", clean.lower()).strip("-") or "page"
    base = f"repro-{slug}"
    if len(base) <= max_len:
        return base
    return base[:max_len].rstrip("-")


def main() -> int:
    parser = argparse.ArgumentParser(
        description="Create the canonical ICML reproduction logbook template."
    )
    parser.add_argument("--title", required=True, help="Paper title")
    parser.add_argument("--orid", required=True, help="OpenReview forum id")
    parser.add_argument("--arxiv", help="arXiv id (for HF paper link)")
    parser.add_argument("--openreview-url", help="Full OpenReview paper URL")
    parser.add_argument(
        "--hf-indexed",
        action="store_true",
        help="Paper is indexed on huggingface.co/papers",
    )
    parser.add_argument(
        "--claims-json",
        help='JSON array of claim strings, e.g. \'["headline accuracy"]\'',
    )
    parser.add_argument(
        "--username",
        help="HF username for metadata.space_id (username/repro-<slug>)",
    )
    args = parser.parse_args()

    try:
        from trackio import logbook as lb
    except ImportError:
        print(
            "trackio is required. Install with: uv pip install --upgrade trackio",
            file=sys.stderr,
        )
        return 1

    if hasattr(lb, "scaffold_icml_logbook"):
        claims = None
        if args.claims_json:
            try:
                claims = json.loads(args.claims_json)
            except json.JSONDecodeError as exc:
                print(f"Invalid --claims-json: {exc}", file=sys.stderr)
                return 1
            if not isinstance(claims, list):
                print("--claims-json must be a JSON array.", file=sys.stderr)
                return 1
        try:
            info = lb.scaffold_icml_logbook(
                title=args.title,
                orid=args.orid,
                claims=claims,
                arxiv_id=args.arxiv,
                openreview_url=args.openreview_url,
                hf_indexed=args.hf_indexed,
                username=args.username,
            )
        except lb.LogbookError as exc:
            print(str(exc), file=sys.stderr)
            return 1
        _print_next_steps(info)
        return 0

    claims = None
    if args.claims_json:
        try:
            claims = json.loads(args.claims_json)
        except json.JSONDecodeError as exc:
            print(f"Invalid --claims-json: {exc}", file=sys.stderr)
            return 1
        if not isinstance(claims, list):
            print("--claims-json must be a JSON array.", file=sys.stderr)
            return 1

    paper_title = re.sub(r"^Reproduction:\s*", "", args.title.strip(), flags=re.I).strip()
    logbook_title = f"Reproduction: {paper_title}"
    slug = repro_slug_from_title(paper_title)
    space_id = f"{args.username}/{slug}" if args.username else None
    orid = args.orid.strip()
    if not orid:
        print("OpenReview id (--orid) is required.", file=sys.stderr)
        return 1

    if lb.find_project_dir() and (
        lb.logbook_root(lb.find_project_dir()) / "pages" / "index.md"
    ).exists():
        print("A logbook already exists in this directory.", file=sys.stderr)
        return 1

    try:
        proj = lb.create_logbook(title=logbook_title, space_id=space_id)
        paper_link = (
            f"[HF paper page](https://huggingface.co/papers/{args.arxiv.strip()})"
            if args.hf_indexed and args.arxiv
            else f"[OpenReview paper]({(args.openreview_url or f'https://openreview.net/forum?id={orid}').strip()})"
        )
        claim_specs = []
        for i, claim in enumerate(claims or [], start=1):
            claim_text = str(claim).strip()
            if not claim_text:
                continue
            if not re.match(r"^Claim\s+\d+\s*:", claim_text, re.I):
                claim_text = f"Claim {i}: {claim_text}"
            claim_specs.append((claim_text, lb.ensure_page(proj, claim_text)))

        exec_slug = lb.ensure_page(proj, "Executive summary")
        concl_slug = lb.ensure_page(proj, "Conclusion")
        index_lines = [
            f"# {logbook_title}",
            "",
            paper_link,
            "",
            lb.TOC_HEADING,
            "",
            lb.TOC_HEADER,
            lb.TOC_SEP,
            f"| [Executive summary](#/{exec_slug}) |",
        ]
        for claim_title, claim_slug in claim_specs:
            index_lines.append(f"| [{claim_title}](#/{claim_slug}) |")
        index_lines += [f"| [Conclusion](#/{concl_slug}) |", ""]
        (lb._pages_dir(proj) / "index.md").write_text(
            "\n".join(index_lines), encoding="utf-8"
        )

        metadata = lb.read_metadata(proj)
        metadata["tags"] = ["icml2026-repro", f"paper-{orid}"]
        if args.arxiv:
            metadata["paper"] = {"arxiv_id": args.arxiv.strip()}
        if space_id:
            metadata["space_id"] = space_id
        lb.write_metadata(proj, metadata)

        summary_body = (
            "Write a 3–5 sentence outcome-first summary here.\n\n"
            "## Scope & cost\n\n"
            "| Item | Value |\n"
            "| --- | --- |\n"
            "| GPU / compute | |\n"
            "| Wall time | |\n"
            "| Feasibility | |\n"
        )
        lb.add_markdown_cell(proj, exec_slug, summary_body, title="Executive summary")
        summary_id = lb.last_cell_id(proj, page=exec_slug)
        if summary_id:
            lb.set_cell_pinned(proj, summary_id, pinned=True, page=exec_slug)

        lb.add_figure_cell(
            proj,
            exec_slug,
            html=(
                "<p>Build a reproduction poster with "
                '<a href="https://github.com/Chenruishuo/posterly">Chenruishuo/posterly</a> '
                "and replace this cell with <code>poster_embed.html</code>.</p>"
            ),
            title="Reproduction poster (poster_embed.html)",
        )
        poster_id = lb.last_cell_id(proj, page=exec_slug)
        if poster_id:
            lb.set_cell_pinned(proj, poster_id, pinned=True, page=exec_slug)

        lb.add_markdown_cell(
            proj,
            concl_slug,
            (
                "Add a reproduction bundle artifact cell here after running:\n\n"
                "```bash\n"
                f'trackio.log_artifact("./repro_{slug[6:]}/", name="repro-bundle", type="dataset")\n'
                f"trackio logbook cell artifact {slug}/repro-bundle:v0 "
                '--page "Conclusion" --title "Reproduction bundle" --type dataset\n'
                "```"
            ),
            title="Reproduction bundle",
        )
        for claim_title, claim_slug in claim_specs:
            lb.add_markdown_cell(
                proj,
                claim_slug,
                f"Document setup, runs, and results for **{claim_title}**.",
                title=claim_title,
            )
        lb.write_site_files(proj)
    except lb.LogbookError as exc:
        print(str(exc), file=sys.stderr)
        return 1

    _print_next_steps(
        {
            "title": logbook_title,
            "slug": slug,
            "space_id": space_id or f"<username>/{slug}",
        }
    )
    return 0


def _print_next_steps(info: dict) -> None:
    print(f"Scaffolded logbook: {info['title']}")
    print(f"Publish slug: {info['slug']}")
    print(f"Publish target: {info['space_id']}")
    print(
        "\nNext steps:\n"
        "  1. Reproduce each claim (log commands, Hub assets, results)\n"
        "  2. Fill Executive summary + poster_embed.html (Chenruishuo/posterly)\n"
        "  3. Add reproduction bundle artifact on Conclusion\n"
        "  4. curl -sL …/validate_icml_logbook.py | python3 - --space "
        f"{info['space_id']}\n"
        f"  5. trackio logbook publish {info['space_id']}"
    )


if __name__ == "__main__":
    raise SystemExit(main())