Skip to content

I/O & Serialization

Functions for config serialization, result export, and reproducibility hashing.

Config Hashing

compute_config_hash(plan, market, policies, sim_config)

Compute a deterministic SHA-256 hash of all configs.

Uses canonical JSON (sorted keys, no whitespace) so the same logical config always produces the same hash.

Config Export/Import

dump_config(plan, market, policies, sim_config)

Serialize all configs to a JSON string.

load_config(json_str)

Deserialize configs from a JSON string.

Results Export

dump_time_series_csv(time_series, current_age, end_age, label='Value')

Export time series percentiles as CSV.

Parameters:

Name Type Description Default
time_series dict[str, list[float]]

Dict with keys p5, p25, p50, p75, p95, mean.

required
current_age int

Starting age.

required
end_age int

Ending age.

required
label str

Column label prefix (e.g. "Wealth" or "Spending").

'Value'

Returns:

Type Description
str

CSV string with Age, P5, P25, P50, P75, P95, Mean columns.

dump_results_summary(success_probability, terminal_wealth_percentiles, n_paths, n_steps, seed)

Serialize simulation results summary to JSON.