nessai.utils.multiprocessing
============================

.. py:module:: nessai.utils.multiprocessing

.. autoapi-nested-parse::

   Utilities related to multiprocessing.

   ..
       !! processed by numpydoc !!


Functions
---------

.. autoapisummary::

   nessai.utils.multiprocessing.get_n_pool
   nessai.utils.multiprocessing.check_multiprocessing_start_method
   nessai.utils.multiprocessing.initialise_pool_variables
   nessai.utils.multiprocessing.log_likelihood_wrapper
   nessai.utils.multiprocessing.log_prior_wrapper
   nessai.utils.multiprocessing.log_prior_unit_hypercube_wrapper
   nessai.utils.multiprocessing.batch_evaluate_function
   nessai.utils.multiprocessing.check_vectorised_function


Module Contents
---------------

.. py:function:: get_n_pool(pool)

   
   Determine the number of processes in a multiprocessing pool.


   :Parameters:

       **pool** : object
           Multiprocessing pool or similar.



   :Returns:

       int or None
           Number of processes. Returns None if number could not be determined.











   ..
       !! processed by numpydoc !!

.. py:function:: check_multiprocessing_start_method()

   
   Check the multiprocessing start method.

   Print a warning if the start method is not `fork`.















   ..
       !! processed by numpydoc !!

.. py:function:: initialise_pool_variables(model)

   
   Prepare the model for use with a multiprocessing pool.

   Makes a global copy of the model. Should be called before initialising
   a pool or passed to the :code:`initializer` argument with the model as one
   of the :code:`initargs`.

   :Parameters:

       **model** : :obj:`nessai.model.Model`
           Model to be copied to a global variable.














   ..
       !! processed by numpydoc !!

.. py:function:: log_likelihood_wrapper(x)

   
   Wrapper for the log-likelihood for use with multiprocessing.

   Should be used alongside
   :py:func:`nessai.utils.multiprocessing.initialise_pool_variables`

   :Parameters:

       **x** : :obj:`numpy.ndarray`
           Array of samples.



   :Returns:

       :obj:`numpy.ndarray`
           Array of log-likelihoods.











   ..
       !! processed by numpydoc !!

.. py:function:: log_prior_wrapper(x)

   
   Wrapper for the log-prior for use with multiprocessing.

   Should be used alongside
   :py:func:`nessai.utils.multiprocessing.initialise_pool_variables`

   :Parameters:

       **x** : :obj:`numpy.ndarray`
           Array of samples.



   :Returns:

       :obj:`numpy.ndarray`
           Array of log-prior values.











   ..
       !! processed by numpydoc !!

.. py:function:: log_prior_unit_hypercube_wrapper(x)

   
   Wrapper for the log-prior in the unit-hypercube for use with
   multiprocessing.

   Should be used alongside
   :py:func:`nessai.utils.multiprocessing.initialise_pool_variables`

   :Parameters:

       **x** : :obj:`numpy.ndarray`
           Array of samples.



   :Returns:

       :obj:`numpy.ndarray`
           Array of log-prior values in the unit-hypercube.











   ..
       !! processed by numpydoc !!

.. py:function:: batch_evaluate_function(func, x, vectorised, chunksize=None, pool=None, n_pool=None, func_wrapper=None)

   
   Evaluate a function over a batch of inputs.


   :Parameters:

       **func** : Callable
           The function to evaluate.

       **x** : numpy.ndarray
           The values over which to evaluate the function.

       **vectorised** : bool
           Boolean to indicate if the function is vectorised or not.

       **chunksize** : Optional[int]
           Maximum number of inputs that will be passed to the function at once.
           Only applies if the function is vectorised.

       **pool** : Optional[multiprocessing.Pool]
           Multiprocessing pool used to evaluate the function.

       **n_pool** : Optional[int]
           Number of cores in the multiprocessing. Determines how values are split
           when calling :code:`Pool.map`.

       **func_wrapper** : Optional[Callable]
           Wrapper to the function to use instead of the function when using the
           pool.



   :Returns:

       numpy.ndarray
           Array of outputs











   ..
       !! processed by numpydoc !!

.. py:function:: check_vectorised_function(func, x, dtype=None, atol=1e-15, rtol=1e-15)

   
   Check if a function is vectorised given a set of inputs.


   :Parameters:

       **func** : Callable
           Function to test

       **x** : numpy.ndarray
           Inputs over which to evaluate the function

       **dtype** :  Optional[Union[str, numpy.dtype]]
           Dtype to cast the results to. If not specified, the default dtype
           for livepoints is used.

       **rtol** : float
           Relative tolerance, see numpy documentation for :code:`allclose`.

       **atol** : float
           Abosoulte tolerance, see numpy documentation for :code:`allclose`.



   :Returns:

       numpy.ndarray
           Array of outputs











   ..
       !! processed by numpydoc !!

