hmf.core (experimental)¶
Warning
hmf.core is an experimental preview of the hmf 4.0 API. It may change,
without deprecation, before 4.0. Importing it emits a
HMFCoreExperimentalWarning (a FutureWarning),
which you can silence with:
import warnings
from hmf.exceptions import HMFCoreExperimentalWarning
warnings.simplefilter("ignore", HMFCoreExperimentalWarning)
The v3 API is unaffected, and import hmf does not import hmf.core.
The v4 core is developed alongside the v3 API, as the subpackage hmf.core
(see #396). At 4.0 it becomes
hmf. So far it contains only the conventions the rest of the core will be
built on; no physics has been ported to it yet.
Conventions¶
- Units (
hmf.core.units) Every public input and output that has a dimension is an
astropy.units.Quantity; a bare number for a dimensional input raisesUnitBoundaryError. Outputs are in h-units, written explicitly withastropy.cosmology.units.littleh(e.g.Msun_h). Inputs may be in h-units or in physical units, which are converted with the object’s own H0. Dimensionless inputs (z, sigma, peak height, …) are plain numbers. Theunit_boundary()decorator implements this at a fixed cost of under 2 µs per call.- Kernels (
hmf.core._kernels) The numerics are pure functions on plain arrays, in the canonical unit of each physical kind (
CANONICAL_UNITS). They take no Quantities, do not loop over array elements in Python, never modify their inputs, and give results that do not depend on the batch size.- Models (
hmf.core.model) A model (a fitting function, a transfer function, …) is a frozen, keyword-only
attrsclass whose fields are its parameters. Each belongs to a kind with its own registry, and is registered under its qualified namepackage.module:Classand an optional unique alias. Lookup is per kind (Kind.get(name)), and also finds models by import path and through thehmf.modelsentry-point group.- Stages (
hmf.core.stage) A stage is one immutable step of a calculation. Parameters change through
evolve(), which returns a new stage; expensive results are cached withfunctools.cached_property().fields_info()describes the parameters without creating an instance.- Accuracy (
hmf.core.accuracy) The internal mass and wavenumber grids are set by
MassAccuracyandKAccuracy, each withfast()andhigh()presets.- Domains (
hmf.core.domain) Models will declare a valid domain (outside which they always raise) and a calibration domain (outside which a user-chosen
DomainPolicyapplies:"ignore","warn","mask"or"raise").
Logarithms always name their base: log10_... or ln_..., never log.
API¶
The modules are listed in the API reference, under “hmf.core (experimental)”.