Download code/_compute_within_arch_perm.py from physics-code-transfer-bench/cross-scenario-physics-code-transfer: direct link, hf CLI and curl.
- Browser
- Download file 3.43 kB
-
https://huggingface.co/datasets/physics-code-transfer-bench/cross-scenario-physics-code-transfer/resolve/main/code/_compute_within_arch_perm.py
- Command line
-
hf download hf://datasets/physics-code-transfer-bench/cross-scenario-physics-code-transfer/code/_compute_within_arch_perm.py
-
curl -L -o _compute_within_arch_perm.py https://huggingface.co/datasets/physics-code-transfer-bench/cross-scenario-physics-code-transfer/resolve/main/code/_compute_within_arch_perm.py
3.43 kB
| """Within-architecture permutation tests on the 24-config sweep — top-3 vs bot-3 | |
| PosDis within discrete-only and within continuous-only subsets. | |
| Addresses R2's flag that the pooled top-5 vs bot-5 comparison is partially confounded | |
| with discrete-vs-continuous (top-5 are all discrete; continuous tops at PosDis 0.40). | |
| """ | |
| import numpy as np | |
| # 24 configs from Table 6 (paper.tex) | |
| # (name, kind, posdis, cross192) | |
| configs = [ | |
| ("disc_L2_V5", "disc", 0.20, 43.9), | |
| ("disc_L2_V10", "disc", 0.25, 41.7), | |
| ("disc_L3_V5", "disc", 0.13, 42.8), | |
| ("disc_L3_V10", "disc", 0.12, 45.6), | |
| ("disc_L4_V5", "disc", 0.10, 42.2), | |
| ("disc_L4_V10", "disc", 0.08, 45.0), | |
| ("disc_L5_V5", "disc", 0.07, 43.9), | |
| ("cont_dim2", "cont", 0.15, 54.4), | |
| ("cont_dim3", "cont", 0.15, 41.1), | |
| ("cont_dim5", "cont", 0.06, 43.9), | |
| ("cont_dim10", "cont", 0.04, 48.3), | |
| ("cont_dim20", "cont", 0.02, 55.0), | |
| ("disc_multi_L3_V5", "disc", 0.51, 46.1), | |
| ("disc_multi_L4_V10", "disc", 0.48, 50.6), | |
| ("cont_multi_dim3", "cont", 0.40, 55.0), | |
| ("disc_multi5_L2_V5", "disc", 0.82, 52.2), | |
| ("disc_multi5_L3_V5", "disc", 0.83, 46.1), | |
| ("disc_multi5_L4_V5", "disc", 0.70, 47.8), | |
| ("disc_multi5_L2_V10_e250", "disc", 0.70, 55.6), | |
| ("disc_multi5_L3_V10_e250", "disc", 0.81, 43.3), | |
| ("disc_multi5_L4_V10_e250", "disc", 0.70, 41.7), | |
| ("disc_multi5_L2_V5_e200", "disc", 0.83, 51.1), | |
| ("disc_multi5_L4_V5_e250", "disc", 0.91, 46.7), | |
| ("disc_multi_L5_V5_3cls", "disc", 0.73, 42.2), | |
| ] | |
| posdis = np.array([c[2] for c in configs]) | |
| cross = np.array([c[3] for c in configs]) | |
| kind = np.array([c[1] for c in configs]) | |
| n_perm = 100_000 | |
| def run_perm(label, mask, k): | |
| p = posdis[mask]; c = cross[mask] | |
| n = len(p) | |
| if n < 2 * k: | |
| print(f" {label}: n={n} too small for top-{k}/bot-{k}") | |
| return | |
| order = np.argsort(p) | |
| top_idx = order[-k:] | |
| bot_idx = order[:k] | |
| obs_diff = c[top_idx].mean() - c[bot_idx].mean() | |
| obs_abs = abs(obs_diff) | |
| rng = np.random.default_rng(42) | |
| null_abs = [] | |
| for _ in range(n_perm): | |
| cp = rng.permutation(c) | |
| null_abs.append(abs(cp[top_idx].mean() - cp[bot_idx].mean())) | |
| null_abs = np.array(null_abs) | |
| p_two = float(np.mean(null_abs >= obs_abs)) | |
| print(f" {label} (n={n}, k={k}): obs |top-{k} - bot-{k}| = {obs_abs:.2f}pp, two-sided p = {p_two:.3f}") | |
| print(f" top-{k} PosDis range: {p[top_idx].min():.2f}-{p[top_idx].max():.2f}, cross: {sorted(c[top_idx].tolist())}") | |
| print(f" bot-{k} PosDis range: {p[bot_idx].min():.2f}-{p[bot_idx].max():.2f}, cross: {sorted(c[bot_idx].tolist())}") | |
| print("=" * 60) | |
| print("Within-architecture permutation tests (n_perm=10^5)") | |
| print("=" * 60) | |
| print("\n--- All 24 configs (pooled, for reference) ---") | |
| for k in [3, 5]: | |
| run_perm(f"All", np.ones(24, dtype=bool), k) | |
| print("\n--- Discrete-only (n=19) ---") | |
| disc_mask = (kind == "disc") | |
| print(f" Total disc configs: {disc_mask.sum()}, PosDis range: {posdis[disc_mask].min():.2f}-{posdis[disc_mask].max():.2f}") | |
| for k in [3, 4, 5]: | |
| run_perm(f"Disc top-{k}/bot-{k}", disc_mask, k) | |
| print("\n--- Continuous-only (n=6) ---") | |
| cont_mask = (kind == "cont") | |
| print(f" Total cont configs: {cont_mask.sum()}, PosDis range: {posdis[cont_mask].min():.2f}-{posdis[cont_mask].max():.2f}") | |
| for k in [2, 3]: | |
| run_perm(f"Cont top-{k}/bot-{k}", cont_mask, k) | |