File size: 2,329 Bytes
1b70a0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Pre-generate sample data cache for rate_aware_gen.py debugging.

Generates and saves cache files for 2-user and 3-user configurations,
so subsequent runs of rate_aware_gen.py can load instantly instead of
regenerating data each time.

Usage:
    python pregen_cache.py                      # default: small scale, 15000 samples
    python pregen_cache.py --n-samples 2000     # smaller debug set
    python pregen_cache.py --scale small --n-samples 15000
"""

import argparse
import os
import time

from rate_aware_gen import make_config, generate_data
from updated_SIM_0413_multi_user import MultiUserDownlinkOptimizer


def pregen(scale, n_users, n_samples):
    cache_path = f"{scale}_{n_users}u_{n_samples}_cache.pt"
    print(f"\n{'='*60}")
    print(f"Pre-generating: scale={scale}, n_users={n_users}, "
          f"n_samples={n_samples}")
    print(f"Cache path: {cache_path}")
    print(f"{'='*60}")

    if os.path.exists(cache_path):
        print(f"  Cache already exists at {cache_path} — skipping.")
        print(f"  (Delete the file if you want to regenerate.)")
        return

    cfg = make_config(scale, n_users)
    optimizer = MultiUserDownlinkOptimizer(cfg, layout="LNLN")

    t0 = time.time()
    geos, configs, rates = generate_data(cfg, optimizer, n_samples, cache_path,
                                          require_cache=False)
    dt = time.time() - t0

    print(f"\n  Done in {dt:.1f}s")
    print(f"  geos:    {tuple(geos.shape)}")
    print(f"  configs: {tuple(configs.shape)}")
    print(f"  rates:   {tuple(rates.shape)}, mean={rates.mean():.3f}")
    print(f"  File size: {os.path.getsize(cache_path)/1e6:.1f} MB")


if __name__ == "__main__":
    pa = argparse.ArgumentParser(description="Pre-generate cache for rate_aware_gen")
    pa.add_argument("--scale", default="small", choices=["small", "large"])
    pa.add_argument("--n-samples", type=int, default=15000)
    pa.add_argument("--users", type=int, nargs="+", default=[2, 3],
                    help="Which n_users to generate (default: 2 3)")
    args = pa.parse_args()

    for n_u in args.users:
        pregen(args.scale, n_u, args.n_samples)

    print(f"\n{'='*60}")
    print("All caches ready. Subsequent rate_aware_gen.py runs will")
    print("load instantly instead of regenerating data.")
    print(f"{'='*60}")