Add challenge 74: N-body Gravitational Force (Medium) - #196
claude[bot] wants to merge 2 commits into
Conversation
Teaches the all-pairs O(N²) parallel computation pattern: each output depends on all N inputs, requiring shared-memory tiling to avoid the global-memory bandwidth bottleneck. Force uses the softened gravity formula with ε = 1e-3, tested on sizes up to N = 8,192. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Thanks for the PR! Challenge ID 74 is already taken on |
- Remove the `positions.device.type == "cuda"` assertion from reference_impl and route every tensor allocation through `self.device` so the reference runs on non-CUDA accelerators (XLA) - Add a `device` constructor argument (default "cuda") to supply `self.device`; keep the `super().__init__(...)` metadata call so `Challenge()` still loads under the current `ChallengeBase` - Add an N=3 functional test with mixed-sign coordinates (10 cases) - Add a dark-theme SVG showing pairwise contributions summing to the net force on a body, plus a position range bullet in Constraints Verified locally on CPU: reference_impl matches an independent O(N^2) float64 implementation of the documented formula on the example and all 10 functional tests, and a tiled CUDA solution (emulated in float32) agrees with the reference at N=8,192 with the worst deviation at 0.2% of the atol/rtol=1e-2 budget. `pre-commit run --all-files` passes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Review: challenge 74 — N-body Gravitational ForceReviewed against the Fixed in f1b15d3
VerificationThe platform runner is currently rejecting every submission, so I could not validate through
Two notes for maintainers1.
Minor, same theme: the guide's JAX comment template says 2. This is not specific to challenge 74 — a known-good 🤖 Generated with Claude Code |
Summary
Why this challenge?
Unlike the many element-wise challenges already in the repo, this is a genuine all-pairs computation where every output depends on all N inputs. The natural optimization (shared-memory tiling to amortize global loads across a block of particles) is the same conceptual leap as GEMM tiling but applied to a completely different physics problem — making it educational without being a duplicate.
Test plan
pre-commit run --all-filespasses (Black, isort, flake8, clang-format)run_challenge.py --action runpasses on NVIDIA TESLA T4 (example test)<p>, uses<h2>sections, first example matchesgenerate_example_test(), LaTeX bmatrix used consistently, performance bullet present🤖 Generated with Claude Code