Solver#

The solver. It holds the joint kernel and solve_eb.

discoeb.solve_eb(cosmologies: Model | Sequence[Model], k_values, a, *, extra=(), keep: Sequence[str | Sequence[str]] | None = None, rtol: float = 0.0001, atol: float = 0.0001, first_step: float = 2e-07, max_steps: int = 20000, error_weights=None, thermo_weight: float = 1.0, split_derivatives: bool = False) → Annotated[Array, 'cosmology', 'name', 'k', 'a'][source]#

Solve the Einstein-Boltzmann system of cosmologies and keep keep at the scale factors a.

One modax solve integrates the background of every cosmology and, against it, the perturbations of every (wave mode, cosmology) pair (_launch()). At each save the kernel evaluates the quantities named in keep from the dense-output state and stores them, so the device holds n_k * n_cosmologies * len(a) * len(keep) values and never the history.

Parameters:
  • cosmologies – A cosmology, LCDM(omega_b=..., ...), or a sequence of cosmologies of one model. The model sets the species and interactions the solve evolves, and each model compiles one kernel. A parameter may be a JAX array, traced under jit or not, and differentiated.

  • k_values – Wave numbers in 1/Mpc, in any order. They must be concrete numbers, since they set the launch’s shape.

  • a – Strictly increasing scale factors at which to record, from A_START on. The solve integrates in a, and 1 is today for every cosmology. Traced values must start after A_START. Every launch starts there, so a first value equal to it records the initial state. Keep tau for the conformal time at each a. Its value at 1 is the conformal age.

  • extra – Components to append to the model for the hook: stateless Component subclasses whose providers read the model’s quantities and add their own (DISCO-CMB’s line-of-sight sources). The hook cache tells them apart by class.

  • keep – Names of the quantities to record, or sequences of names, which are flattened in order: [LineOfSightSources.keep, "delta_c"] keeps a component’s list and one more name. A name is a state element (state_names(), or the recombination block’s tau, thermo_0, thermo_1, thermo_2, kappa, kappa_reio) or a quantity the model provides, such as the comoving curvature perturbation R, the shear alpha, the expansion rate aH or the opacity. Default: every element of the perturbation state. A quantity of the background alone, one the perturbations read of it (tau, opacity, cs2, the recombination block’s states), comes from the background’s own saves, once per cosmology, unless nothing else is kept.

  • rtol – Settings of the Rodas5P step controller.

  • atol – Settings of the Rodas5P step controller.

  • first_step – Settings of the Rodas5P step controller.

  • max_steps – Settings of the Rodas5P step controller.

  • error_weights – Either {state name: weight} or modax’s array (n_k * n_cosmologies, nvar) in launch order (wave modes ascending, cosmologies within). In the dictionary each weight is a number or a function of the trajectories’ wave numbers that returns one per trajectory, and unnamed states keep their declared weight (one, and zero for the massive-neutrino bins psi).

  • thermo_weight – Weight of the background states in the error norm of their solve.

  • split_derivatives – How a derivative uses the device’s threads. By default a trajectory and its sensitivity columns share one thread, which costs the least work and suits a batch that fills the device. With True each direction gets a copy of every trajectory in a thread of its own, holding the state and one column. The copies repeat the primal but run side by side, so one cosmology finishes sooner, and a thread’s memory does not grow with the number of parameters.

Returns:

The kept quantities, (n_cosmologies, len(keep), n_k, n_a): cosmologies in the order given, quantities in keep order, wave modes and scale factors in the caller’s order. jnp.unstack(values, axis=1) splits it into one (n_cosmologies, n_k, n_a) array per name.

Return type:

jax.Array

Notes

The hook compiles once per model and set of names. Before the launch solve_eb computes only the parameter rows and the initial states, in JAX, so it traces under jit. Under jit the model cannot check the cosmologies, since their values are not known.

The returned values are differentiable in every parameter of the cosmologies and every input, in forward and reverse mode. Under jax.jvp and jax.jacfwd, with or without jit, modax integrates one sensitivity column per tangent direction in both blocks, the background’s derivatives reach the perturbations through the nodes it publishes, and each kept quantity’s derivative is stored beside it. Over a batch in forward mode take jax.vmap(jax.jacfwd(f)) of a function of one cosmology, since jacfwd of the batch would ask every cosmology for every other’s directions. Reverse mode (jax.grad, jax.vjp, jax.jacrev) integrates one forward column per moving parameter, seeded in every cosmology at once, since a cosmology’s values depend on its own parameters alone, and JAX transposes the result (modax.by_forward_mode with independent_rows). A gradient over a batch then costs what jax.jacfwd of one cosmology costs, and needs no wrapper. jit must sit outside the reverse-mode transform. The derivative holds the scale factor fixed, so it is the derivative at fixed redshift. A parameter the solve never reads (A_s, n_s, k_p) has a zero derivative.

discoeb.state_names(model: type[Model]) → tuple[str, ...][source]#

Return the perturbation state names of model, for keep and error_weights.

discoeb.derived_parameters(cosmologies) → dict[str, Array][source]#

Return the parameter-row columns the cosmologies imply, (n_cosmologies,) each, by name.

cosmologies is a cosmology or a sequence of cosmologies of one model. The kernel reads these columns: the parameters its methods name (omega_c, omega_b, Y_He, T_cmb, …) and the quantities the host computes from parameters for them (omega_g, omega_ur, amnu, …), or the values replace() set for those. Each is a name replace takes. JAX arrays, traceable under jit.

discoeb.joint_model(model: type[Model], extra=()) → Equations[source]#

Return the components of model with the recombination code (RECOMBINATION) appended.

The recombination states come after the perturbations’, so the perturbation state keeps the indices of Model.state_names. The thermal states (the conformal time, the optical depth and RECFAST’s x_H, x_He and T_m) are the last columns of every history, at model.index["tau"] and so on. extra lists component classes to append after them (the line-of-sight sources). The joint model integrates in the scale factor: its time is a and its clock a_prime = a', the rate of a in the conformal time the components write their rates in. Every cosmology then runs from A_START to 1, and since a grows as tau in the radiation era, the early solutions are the low-order polynomials they are in tau.

Defaults#

Constant

Value

Meaning

discoeb.A_START

2e-7

the scale factor at which every solve starts

discoeb.PERTURB_RTOL

1e-4

default rtol

discoeb.PERTURB_ATOL

1e-4

default atol

discoeb.PERTURB_FIRST_STEP

A_START

default first step, in the scale factor

discoeb.PERTURB_MAX_STEPS

20000

default max_steps

discoeb.H100

100 km/s/Mpc in 1/Mpc

converts a density \(\omega\) into a rate