---
title: "Give an Exported Initial State to Another Integrator"
description: "Independently integrate a full-precision small-wave export in Python, measure particle power and separate time error from finite-grid growth bias."
canonical_url: "https://sandboxphysics.com/stories/cosmic-web/rerun-an-export-and-measure-growth/"
language: "en"
page_type: "story"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/stories/cosmic-web/rerun-an-export-and-measure-growth/"
last_modified: "2026-11-12"
---

[From ripples to the cosmic web](https://sandboxphysics.com/stories/cosmic-web/)

From ripples to the cosmic web · L3

# Give an Exported Initial State to Another Integrator

Sandbox Physics · 2026-11-12

An export can become a testable calculation. Keep its initial positions, momenta and epoch, let another force implementation and integrator reach the same frame, then compare trajectories and power. A small wave lets us complete that experiment.

## Before you begin

Read the coordinate, mesh and power chapters. You need to run Python commands; the package includes an example, so neither browser operation nor TNG data is required.

## Predict first, then obtain a state

Linear EdS predicts a power growth of roughly $475.6$ from $a_i=0.05$ to $a_f\simeq1.09046$. Write that down before computing. It omits finite-mesh bias.

To make your own export, select A sheet folds, reduce amplitude to $A=0.02$, 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 $116$, with $a_f=1.0904635200240378$. 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 $1024$ steps from $0.05$ to $1.5$. This frame is step $928$; 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-result
```

Reading: 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 $\ln a$ as the independent variable, the chain rule multiplies the scale-factor equations by $a$, giving the expressions below. Relative and absolute tolerances are $2\times10^{-10}$ and $2\times10^{-12}$. This independently checks integration while retaining the same coarse force resolution.

$$
\frac{d\boldsymbol y}{d\ln a}=a^{-1/2}\boldsymbol u,\qquad\frac{d\boldsymbol u}{d\ln a}=a^{1/2}\boldsymbol F(\boldsymbol y)
$$

Canonical momentum and the derived scale factors already account for background expansion; adding damping again would count it twice.

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 $\boldsymbol n=(1,0,0)$. The code below accepts position arrays shaped $(4096,3)$ and returns $\mathrm{Mpc}^3$. Retain full precision and do not subtract Poisson noise from the regular lattice.

The accepted fixture starts at $0.0019999995\,\mathrm{Mpc}^3$. Native and independent final powers are $0.9485598876$ and $0.9485655642\,\mathrm{Mpc}^3$. Their relative difference is about $5.98\times10^{-6}$. The RMS position difference is about $4.23\times10^{-9}$ 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)**2
```

Reading: 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 $474.2801$, the independent ratio $474.2829$ and the EdS prediction $475.6443$. The reference is about $0.2862\%$ below EdS. That comparison differs from the roughly $0.000598\%$ 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 $A=0.01$ and $a_f=1$; this example uses $A=0.02$ and ends near $1.09$. 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 $2.22\times10^{-16}$. 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 $8.21\times10^{-17}$; 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

## Exercises and explained answers

1. If you choose another native frame, how do you update the EdS power prediction?

   Read the explanation

   Read its actual $a_f$ and compute $(a_f/0.05)^2$. Do not reuse $475.6$ or say all 1024 native steps ended at that earlier frame.

2. Does exact agreement between integrators prove exact continuous Newtonian gravity?

   Read the explanation

   No. They can share systematic error from the finite mesh and cutoff. Independent time integration, spatial references and refinement check different layers of accuracy.

3. Why integrate from the initial state instead of evaluating force once at the final state?

   Read the explanation

   A final-force comparison checks one instantaneous operator. Repeating the whole interval also tests momentum conventions, expansion factors, stepping and accumulated error.

## Try the prediction

### [Save a prediction and a replay of your own](https://sandboxphysics.com/labs/cosmic-web-shell-crossing/)

1. Keep the minimum-amplitude plane wave, select another saved frame and export its current JSON.
2. Predict EdS growth before running the reference in a new directory. Record the actual epoch, both powers and the denominators of your error measures.
3. Explain which evidence concerns mass and periodicity, which compares integrators, and which still requires spatial refinement.

## Run an independent trajectory

[Download Python, the exact example and expected results](https://sandboxphysics.com/stories/cosmic-web/materials/cosmic-web-replay-v1.zip) (33189 B)

NumPy and SciPy integrate the exact exported small-wave initial state to its saved epoch. The ZIP contains no browser Engine or TNG data. Python 3.12.12, NumPy 2.3.5 and SciPy 1.17.1 were used for the fresh extracted replay.

SHA-256 and example origin

`9334aacf0036834af4e08d102f05e7fa096c71a1ce91b66b8f80b52f6db7c673`

The example came from actual Node execution of the frozen model and canonical current-state serializer; it is not a claimed browser download. The guide explains how to substitute your own current-state JSON.

[Previous: What a Power Spectrum Remembers](https://sandboxphysics.com/stories/cosmic-web/what-a-power-spectrum-remembers/) [Next: Choose What You Call a Halo, Then Read Feedback](https://sandboxphysics.com/stories/cosmic-web/choose-what-you-call-a-halo/)

## Sources and calculation scope

1. [Springel (2005), The cosmological simulation code GADGET-2, astro-ph/0505010v1](https://arxiv.org/abs/astro-ph/0505010v1)

   Focused reading: Section 2.1, equations 1–3; Section 3.2/3.2.1, equations 20–23; Section 4.1, equations 26–31, with original pages 3 and 11 viewed. Supplies cosmological momentum, PM windows and time-integration context. The teaching calculation specifies its own cutoff and finite gradient and adds no short-range tree force.

2. [SciPy solve\_ivp official reference and installed 1.17.1 documentation](https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html)

   DOP853, tolerances and returned success information checked. The live manual was 1.18.0 when read; the actual replay uses pinned 1.17.1, whose installed solve\_ivp documentation and source were separately read. The replay receipts report its real package versions.

3. [Original finite-mesh calculations and independent small-wave Python replay](https://sandboxphysics.com/stories/cosmic-web/materials/cosmic-web-replay-v1.zip)

   Original accepted kernel/linear, nonlinear and five-preset F64 calculations support the teaching figures and calibration. This small public ZIP contains only an exact current-state small-wave fixture, an independent NumPy/SciPy trajectory replay and expected output. The fixture was generated through the frozen model and canonical serializer in Node, not downloaded in a browser. Large raw preset archives remain separately retained; no Engine or source paper is included.
