hmf.helpers.functional.get_hmf

hmf.helpers.functional.get_hmf(req_qauntities: str | list[str] | None = None, get_label=True, framework=<class 'hmf.mass_function.hmf.MassFunction'>, fast_kwargs={'Mmax': 11.5, 'Mmin': 10, 'dlnk': 1, 'dlog10m': 0.5, 'lnk_max': 1, 'lnk_min': -1, 'transfer_model': 'BBKS'}, label_kind='display', label_kwargs=None, *, req_quantities: str | list[str] | None = None, **kwargs)[source]

Yield framework instances for all combinations of parameters supplied.

The underlying idea here is that typically modifying say the redshift has a smaller number of re-computations than modifying the base cosmological parameters. Thus, in a nested loop, the redshift should be the inner loop.

It is not always obvious which order the loops should be, but this function internally determines the order, and calculates the requisite quantities in a series of framework instances.

Parameters:
  • req_qauntities (str or list of str) – A string defining the quantities that should be pre-cached in the output instances. It is advisable that any required quantities for a given application be provided here, to ensure proper optimization. The name is misspelled for historical reasons: pass it positionally, or use the keyword req_quantities instead.

  • get_label (bool, optional) – Whether to return a list of string labels designating each combination of parameters.

  • framework (hmf._framework.Framework class, optional) – A framework for which to perform the optimization.

  • fast_kwargs (dict, optional) – Parameters to be used in the initial run to determine optimal order. These should be set to provide very quick calculation, and do not affect the final result. This will need to be over-ridden for frameworks other than hmf.MassFunction.

  • label_kind ({"display", "filename"}, optional) – The style of the yielded labels.

  • label_kwargs (dict, optional) – Extra keyword arguments controlling the label format.

  • req_quantities (str or list of str, optional) – Correctly-spelled, keyword-only alias of req_qauntities. Give one or the other, not both.

  • kwargs (unpacked-dict) – Any of the parameters to the initialiser of framework which should be calculated. These may be scalars, lists or tuples. The total number of calculations will be the total combination of all parameters.

Yields:
  • quantities (list) – A list of quantities, specified by the req_quantities arguments.

  • x (Framework instance) – An instance of framework, with the requisite quantities pre-cached. Each iteration yields a new, independent copy, so the yielded instances and quantities may safely be stored (e.g. with list(get_hmf(...))); they are not modified by subsequent iterations.

  • label (str, optional) – If get_label is True, also returns a string label uniquely specifying the current parameter combination.

Notes

Internally a single instance is updated in the optimal order, so that cached intermediate quantities are re-used. A deep copy of it is yielded at each iteration, which costs about as much as one cheap re-computation (e.g. changing only the redshift).

Examples

The following operation will run 12 iterations, yielding the desired quantities, an instance containing those and other quantities, and a unique label at every iteration.

>>> for quants, mf, label in get_hmf(
...     ["dndm", "ngtm"], z=[0, 1, 2], hmf_model=["ST", "PS"], sigma_8=[0.7, 0.8]
... ):
...     print(label)
sigma_8: 0.7, z: 0, ST
sigma_8: 0.7, z: 0, PS
sigma_8: 0.7, z: 1, ST
sigma_8: 0.7, z: 1, PS
sigma_8: 0.7, z: 2, ST
sigma_8: 0.7, z: 2, PS
sigma_8: 0.8, z: 0, ST
sigma_8: 0.8, z: 0, PS
sigma_8: 0.8, z: 1, ST
sigma_8: 0.8, z: 1, PS
sigma_8: 0.8, z: 2, ST
sigma_8: 0.8, z: 2, PS

To calculate all of them and keep the results as a list:

>>> big_list = list(get_hmf("mean_density", z=list(range(8))))
>>> print([float(round(x[0][0] / 1e10, 1)) for x in big_list])
[8.6, 68.8, 232.0, 550.0, 1074.3, 1856.3, 2947.8, 4400.2]
>>> print([x[1].z for x in big_list])
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]