Skip to content

Datasets and bundles

Datasets

class-e generate writes an .npz plus a .npz.meta.json sidecar with the run settings. Format v2 holds plain arrays only and loads with allow_pickle=False.

Key Content
schema "class-e-dataset/2"
theta (N, D) sampled parameters
names (D,) parameter names
bounds (D, 2) prior box
obs/<name> (N, K) one observable (TT, TE, EE, PP, mPk, Tk, Hz in km/s/Mpc, chi in Mpc, (N, 1) scalars rs_drag, z_drag, rs_star, z_star, H0, theta_s_100, theta_star_100, ...)
grid/<axis> a grid: ell, k, z, tk_k, tk_z, z_bg (of Hz and chi)
deriv/<name> (N, D, K) finite-difference derivatives, if computed
axes JSON map of the grids each observable spans
from class_e.core.dataset import read_dataset

ds = read_dataset("data/data_train.npz")
ds.theta.shape, ds.observables["TT"].shape, ds.ell

read_dataset also reads the old pickled v1 format; class_e.generation.engine.upgrade_dataset rewrites a v1 file as v2.

Derivatives

Central finite-difference derivatives \(\partial Y/\partial\theta\) (stored as deriv/<name>) are computed from Python:

from dataclasses import replace
from class_e.generation.engine import parse_config, compute_dataset, save_dataset

conf = replace(parse_config("cfg.yaml", design="train"), compute_derivatives=True, derivative_epsilon=1e-4)
save_dataset(compute_dataset(conf), "data/with_derivs.npz")

This costs about \(2D\) extra CLASS runs per point. Train with JAXGPConfig(use_derivatives=True) and emulator.fit(X, Y, dY_dtheta=...).

Note

The YAML key samples.compute_derivatives is not currently read by parse_config, and class-e generate has no flag for it.

Emulator bundles

A .cemu bundle is a single file holding the trained emulators of several observables, the parameter names and prior box, the grids and metadata. It is hash-verified on load and contains no pickles.

from class_e import EmulatorBundle

bundle = EmulatorBundle.load("bundles/model.cemu")
pred = bundle.predict({"h": 0.674, "omega_b": 0.0224, "omega_cdm": 0.12})
pred["TT"]                         # (K,) spectrum

predict warns when a cosmology lies outside the prior box (out_of_bounds="warn" | "raise" | "ignore").

class-e info bundles/model.cemu

Parameter space and CLASS build

Datasets (sidecar meta["space"]) and bundles (meta["space"], copied from their training set) record what they emulate:

  • the parameters: names, prior box, CLASS names (alias) and drop flags;
  • the expressions sent to CLASS (derived with to_class) and the sampling constraints;
  • the fixed CLASS settings (extra_args), except those that only choose outputs and their range (output, l_max_scalars, P_k_max_h/Mpc, z_pk, z_max_pk, lensing, ...);
  • whether the CMB spectra are lensed;
  • the CLASS build: name, version and git commit. A wrapper built in a git checkout of CLASS or a fork (AxiCLASS, hi_class, ...) gives its repository name and commit; uncommitted changes add +dirty.<hash of the diff>. Set theory.classy.name in the YAML to name a build yourself.

Its fingerprint (sha256) is equal for two bundles when they emulate the same thing, whatever their backend, training-set size, observables or grids. lcdm@jax and lcdm@sklearn share one; bundles from AxiCLASS and from CLASS, or from one commit with different local edits, do not. Where the fingerprint is used:

  • merge refuses chunks with different fingerprints;
  • stitch refuses bundles of different spaces (the prior boxes may differ: their intersection is used);
  • a download whose fingerprint is not the registry's is refused (see Published emulators).
class-e diff lcdm@jax lcdm@sklearn   # space, inputs, outputs, training, software

class-e info shows the space and the build (space sha256:9f3c... computed with AxiCLASS v3.3.0 @ ac431c07) and the training-set size.

See the API.