opencr.backends.jax_backend
The optional JAX backend: jitted rates, vmapped scans, automatic-differentiation Jacobians.
Nothing in the core imports JAX; this module does, and it is only usable
with the jax extra installed. It reuses the reference’s prepared rate
evaluators with jax.numpy as the array namespace and the structure of a
PopulationSystem, so that
JaxModel.ratesevaluates every reaction’s Maxwellian rate coefficient at one or many electron temperatures in one jitted call;JaxModel.rhsandJaxModel.jacobiangiveR(n)anddR/dnof the population equations by forward-mode automatic differentiation, for the general (nonlinear, quasi-neutral) equations;JaxModel.reductionis the quasi-static reduction of a batch of(T_e, n_e)withjax.vmap, the counterpart ofopencr.backends.batched;JaxModel.effective_rateis differentiable:jax.gradof it gives the sensitivity of an effective coefficient toT_eandn_e.
Two things differ from the reference: a Function
rate (Python code) is tabulated on its file_temperatures and interpolated
in log-log (the same as when it is written to a file), and a non-Maxwellian
EEDF is refused. The first call of each jitted function compiles it; the
benchmarks separate that from the warm time. Computations are in float64
(jax_enable_x64).
Classes
| Name | Description |
|---|---|
JaxModel | A model on JAX, at fixed heavy-particle temperatures and escape factors. |
JaxModelclass#
class JaxModel(model: Model, conditions: Conditions)A model on JAX, at fixed heavy-particle temperatures and escape factors.
Parameters
| Name | Type | Description |
|---|---|---|
model | Model | The model. |
conditions | Conditions | The conditions whose heavy temperatures, escape factors
and prescribed densities are baked in; T_e and n_e are
the arguments of the methods. A non-Maxwellian EEDF is refused. |
conditionsattributeinstance attribute#
conditions = conditionsmodelattributeinstance attribute#
model = modelsystemattributeinstance attribute#
system = systemeffective_ratemethod#
def effective_rate(source: str, target: str, electron_temperature: Any, electron_density: Any) -> AnyReturn M_eff[target, source] / n_e (m^3/s) as a differentiable JAX scalar.
jax.grad(jax_model.effective_rate, argnums=2)(src, tgt, T_e, n_e) is
the sensitivity to T_e.
Numerics
gradient
Assumptions:
- the reduction of
quasi_staticwritten injax.numpy, vmapped over ; float64
Built from:
opencr.kinetics.effective.QuasiStatic.effective_rate
jacobianmethod#
def jacobian(n: Any, electron_temperature: float, electron_density: float | None = None) -> AnyReturn dR/dn as a dense array by forward-mode automatic differentiation.
Numerics
jacobian
Assumptions:
- dense; the general equations (nonlinear, quasi-neutral) with Maxwellian rates
- a
Functionrate is tabulated on itsfile_temperaturesand interpolated in log-log
Built from:
opencr.kinetics.system.PopulationSystem.jacobian
ratesmethod#
def rates(electron_temperature: Any) -> AnyReturn k of shape (..., n_reactions) for Maxwellian electrons at T_e (eV).
reductionmethod#
def reduction(electron_temperatures: Any, electron_densities: Any) -> BatchedReductionReturn the quasi-static reduction of every (T_e, n_e) pair (vmapped).
The drivers are the prescribed states of the conditions, else the model’s. The result holds NumPy arrays.
rhsmethod#
def rhs(n: Any, electron_temperature: float, electron_density: float | None = None) -> AnyReturn R(n) = dn/dt of the evolving states (m^-3 s^-1).
electron_density=None means quasi-neutrality, as in the conditions.