Download pregen_cache.py from lmb12306/SIM_ISAC: direct link, hf CLI and curl.
- Browser
- Download file 2.33 kB
-
https://huggingface.co/datasets/lmb12306/SIM_ISAC/resolve/main/pregen_cache.py
- Command line
-
hf download hf://datasets/lmb12306/SIM_ISAC/pregen_cache.py
-
curl -L -o pregen_cache.py https://huggingface.co/datasets/lmb12306/SIM_ISAC/resolve/main/pregen_cache.py
2.33 kB
| """ | |
| 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}") | |