Non-linear models

class camb.nonlinear.NonLinearModel(*args, **kwargs)[source]

Abstract base class for non-linear correction models.

Variables:

Min_kh_nonlinear – (float64) minimum k/h at which to apply non-linear corrections

class camb.nonlinear.Halofit(*args, **kwargs)[source]

Bases: NonLinearModel

Various specific approximate non-linear correction models based on HaloFit.

Variables:
  • halofit_version – (integer/string, one of: original, bird, peacock, takahashi, mead, halomodel, casarini, mead2015, mead2016, mead2020, mead2020_feedback)

  • HMCode_A_baryon – (float64) HMcode parameter A_baryon

  • HMCode_eta_baryon – (float64) HMcode parameter eta_baryon

  • HMCode_logT_AGN – (float64) HMcode parameter log10(T_AGN/K)

set_params(halofit_version='mead2020', HMCode_A_baryon=3.13, HMCode_eta_baryon=0.603, HMCode_logT_AGN=7.8)[source]

Set the halofit model for non-linear corrections.

Parameters:
  • halofit_version

    One of

  • HMCode_A_baryon – HMcode parameter A_baryon. Default 3.13. Used only in models mead2015 and mead2016 (and its alias mead).

  • HMCode_eta_baryon – HMcode parameter eta_baryon. Default 0.603. Used only in mead2015 and mead2016 (and its alias mead).

  • HMCode_logT_AGN – HMcode parameter logT_AGN. Default 7.8. Used only in model mead2020_feedback.

class camb.nonlinear.ExternalNonLinearRatio(*args, **kwargs)[source]

Bases: NonLinearModel

Non-linear model that applies a user-supplied ratio sqrt(P_NL/P_L) from an external source, for example CCL or axionHMcode.

Use set_ratio() to provide the ratio grid, then assign the instance to params.NonLinearModel before calling camb.get_results(). This can also be used after computing time transfers, so lensed C_l values are generated with a consistent external non-linear prescription. Requested k_h or z values outside the supplied grid are clamped to the nearest grid boundary.

clear_ratio()[source]

Clear the stored ratio grid and release the interpolation data.

set_ratio(k_h, z, ratio)[source]

Set the non-linear ratio grid sqrt(P_NL/P_L).

Parameters:
  • k_h – 1D array of k values in h/Mpc units (ascending)

  • z – 1D array of redshift values (ascending)

  • ratio – 2D array of sqrt(P_NL/P_L), shape (len(z), len(k_h)), matching the convention of CAMB’s get_matter_power_spectrum. Values requested outside the supplied grid are clamped to the nearest tabulated boundary.

class camb.nonlinear.SecondOrderPK(*args, **kwargs)[source]

Bases: NonLinearModel

Third-order Newtonian perturbation theory results for the non-linear correction. Only intended for use at very high redshift (z>10) where corrections are perturbative, it will not give sensible results at low redshift.

See Appendix F of astro-ph/0702600 for equations and references.

Not intended for production use, it’s mainly to serve as an example alternative non-linear model implementation.

SP(k) model

The SPkNonLinear model wraps a base non-linear prescription (Halofit by default) and applies SP(k) baryon suppression multiplicatively.

See SP(k) baryon suppression model for calibrated validity domain, boundary behavior, and MCMC/Cobaya usage guidance.

class camb.nonlinear.SPkNonLinear(*args, **kwargs)[source]

Bases: NonLinearModel

SP(k) baryon suppression model applied on top of a base non-linear model.

Variables:
  • BaseModelcamb.nonlinear.NonLinearModel

  • SPk_feedback – (boolean) Enable SP(k) suppression

  • SPk_SO – (integer) SP(k) spherical overdensity (200 or 500)

  • SPk_relation_kind – (integer) SP(k) relation kind: 1=power_law, 2=cosmo_power_law, 3=double_power_law

  • SPk_fb_a – (float64) Power-law relation normalization

  • SPk_fb_pow – (float64) Power-law relation exponent

  • SPk_fb_pivot – (float64) Power-law relation pivot mass [M_sun]

  • SPk_alpha – (float64) Relation alpha parameter (kinds 2/3)

  • SPk_beta – (float64) Relation beta parameter (kinds 2/3)

  • SPk_gamma – (float64) Relation gamma parameter (kinds 2/3)

  • SPk_epsilon – (float64) Relation epsilon parameter (kind 3)

  • SPk_m_pivot – (float64) Relation pivot mass [M_sun] (kind 3)

set_params(SPk_feedback=False, SPk_SO=200, SPk_relation_kind=1, SPk_fb_a=1.0, SPk_fb_pow=0.0, SPk_fb_pivot=1.0, SPk_alpha=0.0, SPk_beta=0.0, SPk_gamma=0.0, SPk_epsilon=0.0, SPk_m_pivot=1.0, halofit_version='mead2020', HMCode_A_baryon=3.13, HMCode_eta_baryon=0.603, HMCode_logT_AGN=7.8)[source]

Configure the SP(k) baryon suppression model.

References:

The base model is evaluated first (Halofit by default), then SP(k) suppression is applied to CAMB’s non-linear ratio as:

sqrt(P_NL/P_L) -> sqrt(P_NL/P_L) * sqrt(SPk_suppression)

SP(k) relation kinds:

  • kind=1 (power_law): f_b / (Omega_b/Omega_m) = SPk_fb_a * (M / SPk_fb_pivot)^SPk_fb_pow

  • kind=2 (cosmo_power_law): f_b / (Omega_b/Omega_m) = (exp(SPk_alpha)/100) * (M_500c/1e14)^(SPk_beta - 1) * (E(z)/E(0.3))^SPk_gamma

  • kind=3 (double_power_law): f_b / (Omega_b/Omega_m) = 0.5 * SPk_epsilon * ((M/SPk_m_pivot)^SPk_alpha + (M/SPk_m_pivot)^SPk_beta) * (E(z)/E(0.3))^SPk_gamma

Parameters:
  • SPk_feedback – If True, apply SP(k) suppression on top of the base model.

  • SPk_SO – Spherical overdensity calibration (200 or 500).

  • SPk_relation_kind – Relation type: 1 (power_law), 2 (cosmo_power_law), 3 (double_power_law).

  • SPk_fb_a – Power-law normalization (kind=1).

  • SPk_fb_pow – Power-law exponent (kind=1).

  • SPk_fb_pivot – Power-law pivot mass in M_sun (kind=1).

  • SPk_alpha – Alpha parameter (kinds 2, 3).

  • SPk_beta – Beta parameter (kinds 2, 3).

  • SPk_gamma – Gamma parameter (kinds 2, 3).

  • SPk_epsilon – Epsilon parameter (kind=3).

  • SPk_m_pivot – Pivot mass in M_sun (kind=3).

  • halofit_version – Base Halofit version for the wrapped non-linear model.

  • HMCode_A_baryon – HMcode A_baryon parameter (mead2015/2016 only). Default 3.13.

  • HMCode_eta_baryon – HMcode eta_baryon parameter (mead2015/2016 only). Default 0.603.

  • HMCode_logT_AGN – HMcode log10(T_AGN/K) parameter (mead2020_feedback only). Default 7.8.

Returns:

Self, for fluent configuration.

Raises:

CAMBValueError – If parameters are invalid or incompatible with the base model.

Cobaya usage:

Cobaya passes keys from extra_args directly to set_params(). Parameters under the theory params: block are also forwarded and can be sampled.

  • extra_args (fixed): non_linear_model, halofit_version, SPk_feedback, SPk_SO, SPk_relation_kind, and pivot masses.

  • params (sampled): continuous relation parameters (e.g. SPk_fb_a, SPk_fb_pow).

Example YAML (kind=3, double_power_law):

params:
  SPk_epsilon:
    prior: {min: 0.24, max: 0.35}
    ref: {dist: norm, loc: 0.30, scale: 0.02}
  SPk_alpha:
    prior: {min: -0.12, max: 0.34}
  SPk_beta:
    prior: {min: -0.74, max: 0.77}
  SPk_gamma:
    prior: {min: -0.5, max: 1.20}
  log10_SPk_m_pivot:
    prior: {min: 13, max: 14}
    drop: true
  SPk_m_pivot:
    value: "lambda log10_SPk_m_pivot: 10**log10_SPk_m_pivot"

theory:
  camb:
    extra_args:
      non_linear_model: SPkNonLinear
      halofit_version: mead2020
      SPk_feedback: true
      SPk_SO: 200
      SPk_relation_kind: 3

Boundary behavior:

  • z outside [0, 3]: no suppression applied (identity).

  • k > 12 h/Mpc: suppression clamped to value at k = 12 (saturates).

  • f_b outside calibrated limits: nonlin_ratio set to NaN.

NaN propagates through get_matter_power_interpolator() (Cobaya rejects the sample). Set priors to keep f_b in range.

Warning

get_matter_power_spectrum() does not preserve NaN — use get_linear_matter_power_spectrum() with nonlinear=True to inspect which (z, k) cells are invalid.

Cannot be combined with halofit_version='mead2020_feedback'.