sigway.perturbations¶
The primordial curvature power spectrum \(\mathcal{P}_\zeta(k)\). Choose one of the implementations — or subclass the base — and hand it to OmegaGW.
Base class¶
sigway.perturbations.ScalarPerturbations ¶
Abstract base class for the primordial curvature power spectrum \(\mathcal{P}_\zeta(k)\).
Every spectrum model in SIGWAY inherits from this class and implements
__call__(k, *params) to return \(\mathcal{P}_\zeta\) evaluated at
wavenumber \(k\) for a given set of model parameters \(\theta\). The class
attributes below form the contract that
OmegaGW and the gravitational-wave integrator
rely on.
Attributes:
| Name | Type | Description |
|---|---|---|
param_names |
tuple of str
|
Ordered names of the free model parameters \(\theta\) passed as
|
jittable |
bool
|
Whether \(\mathcal{P}_\zeta(k,\theta)\) can be evaluated inside the
compiled, differentiable code path (JAX). Analytic spectra set this
to |
nonsmooth_params |
tuple of str
|
Subset of |
__call__ ¶
Evaluate \(\mathcal{P}_\zeta\) at wavenumber \(k\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
array_like
|
Comoving wavenumber(s) \(k\), in the units used throughout the model (\(\mathrm{s}^{-1}\)), at which to evaluate the primordial power spectrum. |
required |
*params
|
float
|
Model parameters \(\theta\) in the order given by |
()
|
Returns:
| Type | Description |
|---|---|
array_like
|
\(\mathcal{P}_\zeta(k,\theta)\) evaluated at the supplied \(k\). |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always — concrete subclasses must override this method. |
prepare ¶
Return a single-argument \(\mathcal{P}_\zeta(k)\) with parameters fixed.
The gravitational-wave integrator calls this once before evaluating
\(\mathcal{P}_\zeta\) on its dense \((k u,\, k v)\) grid. The default
implementation simply closes over __call__ with the given
params.
SingleFieldPerturbations
overrides this to solve the Mukhanov-Sasaki equation once on
kint and return a fast spline interpolant, avoiding a full ODE
solve at every grid point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kint
|
array_like
|
Wavenumber grid on which the integrator will sample \(\mathcal{P}_\zeta\). Forwarded to the Mukhanov-Sasaki solver when overridden; ignored by the default analytic implementation. |
required |
*params
|
float
|
Model parameters \(\theta\) in the order given by |
()
|
Returns:
| Type | Description |
|---|---|
callable
|
A single-argument function |
Implementations¶
sigway.perturbations.AnalyticPerturbations ¶
Bases: ScalarPerturbations
Closed-form primordial power spectrum \(\mathcal{P}_\zeta(k,\theta)\).
The lightest-weight way to define a spectrum model: supply any function
func(k, *params) that computes \(\mathcal{P}_\zeta\) analytically
together with the ordered names of its free parameters. The result is
a fully compliant
ScalarPerturbations object
that can be evaluated inside the compiled, differentiable code path,
provided func itself uses JAX-compatible operations
(e.g. jax.numpy).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
A function with signature |
required |
param_names
|
tuple of str
|
Ordered names of the free parameters expected by |
()
|
nonsmooth_params
|
tuple of str
|
Parameters in |
()
|
Attributes:
| Name | Type | Description |
|---|---|---|
func |
callable
|
The wrapped callable as supplied at construction time. |
param_names |
tuple of str
|
Ordered parameter names. |
nonsmooth_params |
tuple of str
|
Parameters requiring finite-difference derivatives. |
Examples:
Wrap a log-normal peak in \(\mathcal{P}_\zeta(k)\):
>>> import jax.numpy as jnp
>>> from sigway.perturbations import AnalyticPerturbations
>>> def pz(k, logAs, logks):
... return 10.0**logAs * jnp.exp(-0.5*(jnp.log(k/10**logks)/0.3)**2)
>>> perts = AnalyticPerturbations(pz, ("logAs", "logks"))
If the spectrum has a hard ultraviolet cutoff \(k_{\max}\) whose
derivative must be estimated by finite differences, declare it via
nonsmooth_params:
__call__ ¶
Evaluate the wrapped callable at wavenumber \(k\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
array_like
|
Comoving wavenumber(s) \(k\) at which to evaluate \(\mathcal{P}_\zeta\). |
required |
*params
|
float
|
Model parameters \(\theta\) in the order given by |
()
|
Returns:
| Type | Description |
|---|---|
array_like
|
\(\mathcal{P}_\zeta(k,\theta)\) as returned by |
sigway.perturbations.SingleFieldPerturbations ¶
Bases: ScalarPerturbations
Primordial power spectrum \(\mathcal{P}_\zeta(k)\) from single-field inflation.
For inflationary models where no analytic expression for
\(\mathcal{P}_\zeta(k)\) is available, this class solves the
Mukhanov-Sasaki equation numerically using
SingleFieldSolver. The result is
exposed through the same __call__ / prepare interface as every
other ScalarPerturbations
subclass, so the gravitational-wave integrator is unaware of whether
the spectrum is analytic or numerical.
Because the Mukhanov-Sasaki solver calls SciPy ODE routines internally,
it cannot be evaluated inside the compiled, differentiable code path.
jittable is therefore False, and the integrator runs this path
eagerly. Gradients with respect to inflationary potential parameters
must be obtained by finite differences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver
|
SingleFieldSolver
|
A configured
SingleFieldSolver instance
encoding the inflationary potential and integration settings.
Passing any other object raises |
required |
param_names
|
tuple of str
|
Ordered names of the free parameters forwarded to the solver (e.g. potential coefficients). Defaults to an empty tuple. |
()
|
Attributes:
| Name | Type | Description |
|---|---|---|
solver |
SingleFieldSolver
|
The wrapped SingleFieldSolver. |
param_names |
tuple of str
|
Ordered parameter names. |
jittable |
bool
|
Always |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
__call__ ¶
Evaluate \(\mathcal{P}_\zeta\) by solving the Mukhanov-Sasaki equation at \(k\).
Delegates directly to the wrapped solver. This is the
point-by-point evaluation path. For bulk evaluation on the
integrator grid — where solving the ODE at every point separately
would be prohibitively slow — use prepare instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
array_like
|
Comoving wavenumber(s) \(k\) at which to evaluate \(\mathcal{P}_\zeta\). |
required |
*params
|
float
|
Inflationary model parameters in the order given by
|
()
|
Returns:
| Type | Description |
|---|---|
array_like
|
\(\mathcal{P}_\zeta(k)\) at the requested wavenumbers. |
prepare ¶
Solve the Mukhanov-Sasaki equation once and return a fast interpolant.
Rather than re-running the full ODE for every point on the
integrator's dense \((k u,\, k v)\) grid, this method solves the
Mukhanov-Sasaki system once on the supplied wavenumber grid
kint and returns a SciPy spline interpolant. The integrator
then evaluates the cheap interpolant at each grid point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kint
|
array_like
|
Wavenumber grid \(k_{\mathrm{int}}\) on which to solve the Mukhanov-Sasaki equation. Should span the range of \(k\) values required by the subsequent integration. |
required |
*params
|
float
|
Inflationary model parameters forwarded to the solver. |
()
|
Returns:
| Type | Description |
|---|---|
callable
|
A single-argument spline interpolant |