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
cosmologiesand keepkeepat the scale factorsa.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 inkeepfrom the dense-output state and stores them, so the device holdsn_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 underjitor 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_STARTon. The solve integrates ina, and 1 is today for every cosmology. Traced values must start afterA_START. Every launch starts there, so a first value equal to it records the initial state. Keeptaufor the conformal time at eacha. Its value at 1 is the conformal age.extra – Components to append to the model for the hook: stateless
Componentsubclasses 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’stau,thermo_0,thermo_1,thermo_2,kappa,kappa_reio) or a quantity the model provides, such as the comoving curvature perturbationR, the shearalpha, the expansion rateaHor theopacity. 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 binspsi).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
Trueeach 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 inkeeporder, 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:
Notes
The hook compiles once per model and set of names. Before the launch
solve_ebcomputes only the parameter rows and the initial states, in JAX, so it traces underjit. Underjitthe 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.jvpandjax.jacfwd, with or withoutjit, 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 takejax.vmap(jax.jacfwd(f))of a function of one cosmology, sincejacfwdof 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_modewithindependent_rows). A gradient over a batch then costs whatjax.jacfwdof one cosmology costs, and needs no wrapper.jitmust 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, forkeepanderror_weights.
- discoeb.derived_parameters(cosmologies) dict[str, Array][source]#
Return the parameter-row columns the cosmologies imply,
(n_cosmologies,)each, by name.cosmologiesis 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 valuesreplace()set for those. Each is a namereplacetakes. JAX arrays, traceable underjit.
- discoeb.joint_model(model: type[Model], extra=()) Equations[source]#
Return the components of
modelwith 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’sx_H,x_HeandT_m) are the last columns of every history, atmodel.index["tau"]and so on.extralists component classes to append after them (the line-of-sight sources). The joint model integrates in the scale factor: its time isaand its clocka_prime = a', the rate ofain the conformal time the components write their rates in. Every cosmology then runs fromA_STARTto 1, and sinceagrows astauin the radiation era, the early solutions are the low-order polynomials they are intau.
Defaults#
Constant |
Value |
Meaning |
|---|---|---|
|
|
the scale factor at which every solve starts |
|
|
default |
|
|
default |
|
|
default first step, in the scale factor |
|
|
default |
|
100 km/s/Mpc in 1/Mpc |
converts a density \(\omega\) into a rate |