Predict first, then obtain a state
Linear EdS predicts a power growth of roughly from to . Write that down before computing. It omits finite-mesh bias.
To make your own export, select A sheet folds, reduce amplitude to , wait for the new calculation, pause and export the current JSON. Use the full-precision saved scale factor in the file. This guide reads the current-state JSON, not the full native binary record.
The packaged example uses that setting at native frame , with . The example was generated by running the frozen Lab model and its current-state exporter in Node; you can also use a current-state JSON downloaded from the Lab. The full model takes steps from to . This frame is step ; the reference integrates only to the epoch in the file.
Reading: Original finite-mesh calculations and independent small-wave Python replay · Springel (2005), The cosmological simulation code GADGET-2, astro-ph/0505010v1
Run it in a fresh directory
Download and extract the independent replay package below. It contains the Python reference, example JSON, expected result and manifest. It includes no browser Engine, source papers or TNG snapshots. The accepted environment is Python 3.12.12, NumPy 2.3.5 and SciPy 1.17.1.
Install requirements.txt in your own virtual environment, then run the command below. Choose a new output directory to retain earlier results. Substitute your current-state JSON to use your own export. Strong nonlinear states may require many more force evaluations; this small-wave example does not establish their runtime.
The program writes result.json and double-precision independent final arrays. Check successful completion, the target epoch and environment before reading errors. A completed replay leaves both files with finite numerical results.
python replay.py small-wave-current.json --out my-new-resultReading: Original finite-mesh calculations and independent small-wave Python replay · Springel (2005), The cosmological simulation code GADGET-2, astro-ph/0505010v1
What makes the replay independent
The initial arrays come directly from the full-precision export. We neither infer them from rounded controls nor generate a new random starting point. This keeps different starting conditions out of the trajectory comparison.
The reference scatters CIC mass with NumPy repeated-index accumulation, applies the discrete four-point gradient in Fourier space and gathers force. The browser instead inverse-transforms the potential and takes the four-point derivative in real space. Both specify the same finite-mesh force through different implementation paths.
SciPy’s adaptive DOP853 replaces the time stepping. With as the independent variable, the chain rule multiplies the scale-factor equations by , giving the expressions below. Relative and absolute tolerances are and . This independently checks integration while retaining the same coarse force resolution.
Reading: Original finite-mesh calculations and independent small-wave Python replay · Springel (2005), The cosmological simulation code GADGET-2, astro-ph/0505010v1 · SciPy solve_ivp official reference and installed 1.17.1 documentation
Measure power directly from the positions
Apply the previous chapter’s definition to . The code below accepts position arrays shaped and returns . Retain full precision and do not subtract Poisson noise from the regular lattice.
The accepted fixture starts at . Native and independent final powers are and . Their relative difference is about . The RMS position difference is about box lengths.
That close agreement concerns this small wave under the same finite-mesh force. Late nonlinear knots need their own force-resolution and trajectory checks.
import numpy as np
def power(positions):
phase = positions @ np.array([1, 0, 0])
amplitude = np.mean(np.exp(-2j * np.pi * phase))
return 20.0**3 * abs(amplitude)**2Reading: Original finite-mesh calculations and independent small-wave Python replay · Springel (2005), The cosmological simulation code GADGET-2, astro-ph/0505010v1
Why both results fall below the prediction
The native growth ratio is about , the independent ratio and the EdS prediction . The reference is about below EdS. That comparison differs from the roughly native/reference difference.
The first includes the finite mesh, half-cell lattice response and small nonlinear corrections. The second mainly tests implementation and time integration of the same force. The earlier spatial calibration used and ; this example uses and ends near . Their numbers need not match digit for digit.
For the next experiment, change one question at a time. Hold mesh and initial state fixed while tightening integration error to check reference stability. To test continuous gravity, refine particles and mesh while preserving the continuous initial disturbance. Each comparison answers its own question about the calculation.
Reading: Original finite-mesh calculations and independent small-wave Python replay · Springel (2005), The cosmological simulation code GADGET-2, astro-ph/0505010v1
Check mass and periodicity too
The example’s maximum raw deposited mass error is about . It is checked before removing the background, without rescaling the answer to one. Translating initial positions by integer box lengths changes reference force by at most about ; initial mean force is also close to zero.
These tests ask whether mass was lost, periodic weights are consistent and internal gravity gives the whole box a net push. Together with growth and trajectories they support this small-wave replay. The package retains thresholds and environment information; preserve new results when trying your own state.
Reading: Original finite-mesh calculations and independent small-wave Python replay · Springel (2005), The cosmological simulation code GADGET-2, astro-ph/0505010v1