|
Download scripts/validation/ns_derivative_lhs.md from santicas/cjfp-data: direct link, hf CLI and curl.
- Browser
- Download file 9.44 kB
-
https://huggingface.co/datasets/santicas/cjfp-data/resolve/main/scripts/validation/ns_derivative_lhs.md
- Command line
-
hf download hf://datasets/santicas/cjfp-data/scripts/validation/ns_derivative_lhs.md
-
curl -L -o ns_derivative_lhs.md https://huggingface.co/datasets/santicas/cjfp-data/resolve/main/scripts/validation/ns_derivative_lhs.md
9.44 kB
| # Latin-hypercube ns power-spectrum derivatives | |
| `compute_ns_derivative_lhs.py` compares total-matter **linear and nonlinear** power | |
| for CLASS × EuclidEmulator2 and SYREN-NEW, using CosmicFishPie's public cosmology | |
| interface and validated finite-difference engine. Each of 1,000 cosmologies has | |
| the same 10 redshifts and 240 logarithmically spaced wavenumbers. The ranges come | |
| from [the SYREN-NEW paper, Table 1](https://arxiv.org/html/2410.14623v1#S3). | |
| ## Run and resume | |
| Run these commands from **cjfp-data**. Reading/replotting downloaded arrays only | |
| requires NumPy and Matplotlib; see [the collaborator guide](../NS_RESPONSE_SHARING.md). | |
| For new solver runs, use an environment containing CLASS, EuclidEmulator2, | |
| symbolic_pofk and CosmicFishPie's dependencies. Keep a CosmicFishPie source | |
| checkout at `../cosmicfishpie`, or set `COSMICFISHPIE_REPO_ROOT` to its location. | |
| The script explicitly imports that checkout, so an editable install is unnecessary. | |
| The two YAML profiles are bundled under `scripts/validation/configs/`; no files | |
| need to be added to the CosmicFishPie repository. The original laptop run used | |
| `/home/santiago/miniforge3/envs/cloe-org-env/bin/python`. | |
| ```bash | |
| python scripts/validation/compute_ns_derivative_lhs.py \ | |
| --n-points 1000 --workers 8 --seed 241014623 \ | |
| --output-dir scripts/validation_results/ns_derivative_lhs | |
| # Same settings are required when resuming; completed failures remain recorded. | |
| python scripts/validation/compute_ns_derivative_lhs.py \ | |
| --n-points 1000 --workers 8 --seed 241014623 \ | |
| --output-dir scripts/validation_results/ns_derivative_lhs --resume | |
| python scripts/validation/plot_ns_derivative_lhs.py \ | |
| scripts/validation_results/ns_derivative_lhs | |
| ``` | |
| `--n-points 10 --workers 4 --output-dir <fresh-directory>` is a small smoke test. | |
| Existing campaign directories require `--resume`; the script checks settings | |
| and recorded source/profile hashes. Worker count may change on resume. | |
| The downloaded completed campaign is an archival result: its unchanged metadata | |
| records the original runner and paths, not the relocated convenience runner. | |
| Use a fresh output directory for a new run with the relocated runner. | |
| ## Sharing and provenance | |
| The numerical campaign is tracked independently by | |
| `scripts/validation_results/ns_derivative_lhs.dvc`. Download it without any chains: | |
| ```bash | |
| git pull --ff-only | |
| dvc pull scripts/validation_results/ns_derivative_lhs.dvc | |
| ``` | |
| The Git-tracked scripts, profiles, tests and this guide are small. The DVC target | |
| contains the arrays, figures, logs, original metadata and exact source snapshots. | |
| `provenance/manifest.json` maps each original source record to a snapshot filename | |
| and SHA-256 digest. Original absolute paths are historical provenance; they are | |
| not required to load or plot the data. All ten `.npy` files were verified | |
| byte-identical during relocation from the CosmicFishPie worktree. | |
| ## Sample and conventions | |
| The eight-dimensional scrambled SciPy Latin hypercube uses these column names | |
| and uniform ranges; z and k are evaluation axes, **not** additional LHS dimensions. | |
| | Column | Minimum | Maximum | | |
| | --- | ---: | ---: | | |
| | `10^9As` | 1.7 | 2.5 | | |
| | `Omegam` | 0.24 | 0.40 | | |
| | `Omegab` | 0.04 | 0.06 | | |
| | `h` | 0.61 | 0.73 | | |
| | `ns` | 0.92 | 1.00 | | |
| | `w0` | -1.3 | -0.7 | | |
| | `wa` | -0.7 | 0.5 | | |
| | `mnu` (summed eV, three degenerate species) | 0 | 0.15 | | |
| Redshifts are `linspace(0, 3, 10)`. The shared grid is | |
| `geomspace(0.009, 6.8, 240)` **h/Mpc**, interpolated through CFP's `Pmm`. | |
| The native CLASS and SYREN grids differ; every evaluation checks spline support | |
| and rejects extrapolation. Power is returned in **(Mpc/h)^3**: CFP receives `k*h` | |
| in 1/Mpc and its result in Mpc³ is multiplied by `h**3`. | |
| CLASS uses `class/ee2_ns_lhs.yaml`, matching the photometric EE2 physics, with | |
| `P_k_max_1/Mpc=7*h` set separately for each cosmology. This keeps the requested | |
| cutoff fixed at 7 h/Mpc and leaves padding room below EE2's native maximum of | |
| 9.40909 h/Mpc, while covering the output grid. CLASS's actual native k-grid can | |
| extend beyond the requested cutoff; the EE2 wrapper also checks it explicitly. | |
| SYREN uses `symbolic/syren_new_photo.yaml`. Both use `w0waCDM` and fixed primordial | |
| amplitude during the ns perturbation. Neutrino-density conversion and radiation | |
| conventions follow those existing profiles/providers; this is a comparison of | |
| the configured CFP backends, not an assertion that their background conventions | |
| are mathematically identical. | |
| The derivative engine receives a `plain` array observable holding both P and ln P. | |
| Interior points use **3PT**, with absolute half-step `0.01*ns`. If that stencil | |
| would leave [0.92, 1.00], it uses CFP's **4PT_FWD** inward, with the same step | |
| magnitude. At the upper edge a negative step makes it a backward stencil; | |
| the signed denominator preserves d/dns. Stencil choice is recoverable from ns | |
| in `params.npy` and the signed step (negative at the upper edge); plots mix both methods. | |
| `dlnP_dns` is the finite difference of ln P, not `dP_dns / power`; these agree | |
| only in the zero-step limit. No convergence claim is made for the chosen step. | |
| The scrambled LHS normally avoids mnu=0 exactly. A failed CLASS evaluation with | |
| input mnu <= 1e-6 eV gets one retry at 1e-6 eV, recorded in `effective_mnu.npy` | |
| and the event log; all other parameters and the original sample remain intact. | |
| ## Loading the arrays | |
| All `.npy` files use ordinary numeric dtypes (no pickle). Large arrays can be | |
| memory-mapped. Three spectrum arrays have shape **(1000, 2, 2, 10, 240)**: | |
| 1. LHS point; | |
| 2. backend: `[CLASS+EE2, SYREN-NEW]`; | |
| 3. spectrum: `[linear, nonlinear]`; | |
| 4. redshift; | |
| 5. wavenumber. | |
| | File | Contents | | |
| | --- | --- | | |
| | `params.npy` | (N,8) original sample, columns as above | | |
| | `power.npy` | Fiducial P, (Mpc/h)^3 | | |
| | `dP_dns.npy` | dP/dns at fixed As, (Mpc/h)^3 | | |
| | `dlnP_dns.npy` | d ln P/dns at fixed As, dimensionless | | |
| | `k_hmpc.npy`, `redshifts.npy` | Explicit evaluation axes | | |
| | `status.npy` | (N,2): 0 pending, 1 successful, -1 failed | | |
| | `signed_step.npy` | (N,2) actual absolute ns step with direction sign | | |
| | `effective_mnu.npy` | (N,2) summed neutrino mass supplied to each backend, in eV; see below | | |
| | `seconds.npy` | (N,2) wall time per backend in seconds | | |
| | `metadata.json` | Settings, labels, versions, source/profile hashes, final counts | | |
| | `events.jsonl`, `logs/` | Per-backend completion/error records and full diagnostics | | |
| ### What `effective_mnu.npy` means | |
| This is a **provenance array**, not another sampled cosmological parameter. | |
| Here, “effective” means the mass actually supplied to the backend, including | |
| any tiny-mass fallback. It is the **sum of the three neutrino masses in eV**, | |
| not the mass of one species and not the effective number of relativistic species. | |
| Its shape is `(N, 2)`, with columns `[CLASS+EE2, SYREN-NEW]`. Normally both | |
| columns equal the original `mnu` column in `params.npy`. If CLASS fails at an | |
| input mass <= 1e-6 eV, its column records the retry mass of 1e-6 eV; the SYREN | |
| column retains the original input. For failed entries, this records the mass | |
| attempted, not a successful calculation; check `status.npy` before using results. | |
| Pending entries are NaN. | |
| **In the completed 1000-point campaign no fallback was needed:** both columns | |
| equal the original sampled masses at every point. | |
| ### Loading the power responses | |
| ```python | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| root = Path('scripts/validation_results/ns_derivative_lhs') | |
| meta = json.loads((root / 'metadata.json').read_text()) | |
| params = np.load(root / 'params.npy') | |
| good = np.all(np.load(root / 'status.npy') == 1, axis=1) | |
| response = np.load(root / 'dlnP_dns.npy', mmap_mode='r') | |
| ee2_nonlinear_z0 = response[good, 0, 1, 0, :] | |
| syren_nonlinear_z0 = response[good, 1, 1, 0, :] | |
| delta = syren_nonlinear_z0 - ee2_nonlinear_z0 | |
| ``` | |
| To inspect the recorded masses after loading the sample: | |
| ```python | |
| effective_mnu = np.load(root / 'effective_mnu.npy') | |
| original_mnu = params[:, meta['parameter_names'].index('mnu')] | |
| mass_changed = effective_mnu != original_mnu[:, None] | |
| # For this completed campaign: mass_changed.any() is False. | |
| ``` | |
| Failed entries stay NaN, and the other backend is still attempted. Only the | |
| parent writes arrays, flushing data before committing each status entry. | |
| Interruptions leave pending entries resumable. Ordinary Python/solver exceptions | |
| are contained per backend; process-level native crashes or a killed runner can | |
| require restarting with `--resume`. No failure is replaced with a fabricated value. | |
| There are about 230 MB of spectrum arrays, plus logs. Outputs are local research | |
| artifacts; version the script and documentation separately from generated data. | |
| ## Figures | |
| The plotting command uses only paired successful points and writes four PNGs | |
| under `plots/`, plus `summary.json`: | |
| - `linear_response.png` and `nonlinear_response.png`: one panel per redshift, | |
| median and 68%/95% bands across the LHS, for each backend; | |
| - `paired_response_difference.png`: paired SYREN minus CLASS+EE2 response; | |
| - `parameter_dependence.png`: z=0 nonlinear RMS response difference over | |
| 0.2 <= k <= 1 h/Mpc against each cosmological parameter. | |
| Bands describe variation **across sampled cosmologies**, not statistical error | |
| bars or emulator accuracy estimates. Additive response differences are used | |
| because ratios become singular when d ln P/dns crosses zero. The same log-power | |
| derivative convention is used for both backends. | |