"""Generate the article's illustrative rank map, not a scheduler configuration."""
import csv
from pathlib import Path

DP, TP, PP, GPUS_PER_NODE = 8, 4, 32, 8


def make_rows():
    for d in range(DP):
        for p in range(PP):
            for t in range(TP):
                rank = (d * PP + p) * TP + t
                yield {
                    "rank": rank,
                    "dp_coordinate": d,
                    "pp_coordinate": p,
                    "tp_coordinate": t,
                    "logical_node": rank // GPUS_PER_NODE,
                    "local_rank": rank % GPUS_PER_NODE,
                    "tp_group": d * PP + p,
                    "pp_group": d * TP + t,
                    "dp_group": p * TP + t,
                }


if __name__ == "__main__":
    rows = list(make_rows())
    output = Path(__file__).with_name("rank-map.csv")
    with output.open("w", encoding="utf-8", newline="") as handle:
        writer = csv.DictWriter(handle, fieldnames=list(rows[0]))
        writer.writeheader()
        writer.writerows(rows)
    print(f"Generated {len(rows)} illustrative ranks: {output}")
