Download graders/ae_p33_thomson/check.py from amphora/MathConstructOptimize-Envs: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/datasets/amphora/MathConstructOptimize-Envs/resolve/main/graders/ae_p33_thomson/check.py
- Command line
-
hf download hf://datasets/amphora/MathConstructOptimize-Envs/graders/ae_p33_thomson/check.py
-
curl -L -o check.py https://huggingface.co/datasets/amphora/MathConstructOptimize-Envs/resolve/main/graders/ae_p33_thomson/check.py
1.11 kB
| """Thomson problem (AlphaEvolve problem 33): minimize the Coulomb energy of n points on the unit sphere S^2. | |
| Same objective as the upstream get_score (thomson_problem.ipynb): vectors are projected onto the sphere and | |
| E = sum_{i<j} 1/|p_i - p_j|. Changes: zero / non-finite vectors are rejected instead of being normalized to | |
| NaN, and coincident points (distance < 1e-12) are rejected instead of being clamped to 1e-12. | |
| """ | |
| import numpy as np | |
| from run import Invalid, float_matrix | |
| def check(inst, ans): | |
| n = inst["n"] | |
| v = np.array(float_matrix(ans.get("vectors"), n, 3, "vectors")) | |
| nr = np.linalg.norm(v, axis=1, keepdims=True) | |
| if not np.all(np.isfinite(nr)) or np.any(nr < 1e-9) or np.any(nr > 1e9): | |
| raise Invalid("each vector must have norm in [1e-9, 1e9]") | |
| v = v / nr | |
| d = np.sqrt(((v[:, None, :] - v[None, :, :]) ** 2).sum(-1))[np.triu_indices(n, 1)] | |
| if d.min() < 1e-12: | |
| raise Invalid("two points coincide") | |
| e = float(np.sum(1.0 / d)) | |
| if not np.isfinite(e): | |
| raise Invalid("non-finite energy") | |
| return e, {"min_distance": float(d.min())} | |