find that the fraction of the time spent of each stage changes when using distance marginalisation. Without the marginalisation, on average, 8% of the total computa-tion time is spent on training and a further 40% on popu-lation. When using distance marginalisation this changes to 5% spent on training and 42% on population. We at-tribute the difference in population time to the efficiency of the rejection sampling, which is improved when includ-ing the reparameterisation for distance discussed in sec-tion III C. We find that without distance marginalisation the median run-time for Nessai is 2.32 times faster than dynesty. However when distance marginalisation is en-abled we observe that, on average, Nessai is only 1.40 times faster than dynesty. This further reinforces our recommendation to use Nessai with distance marginali-sation disabled.

We also show how our sampler can make use of paral-lelised likelihood functions by evaluating the likelihood of new live points during the population stage. We repeat the previous analysis for a single injection without dis-tance marginalisation and parallelise the likelihood com-putation with increasing number of threads up to 16. We observe that the reduction time evaluating the likelihood does not quite match the theoretical values, indicating that there is a small overhead associated with it. This also highlights how the limiting factor is the time spent training the normalising flow and populating the pool of new live point.

To aid in diagnosing potential biases during sampling, we include a series of diagnostics in our sampler which allow us to easily identify under and over-constraining. These diagnostics also help to tune the sampling settings and highlight how periodically re-training the normal-ising flow during sampling prevents the proposal from becoming inefficient during sampling.

We find that our algorithm is susceptible to under-sampling regions of the parameter space which are close to the prior bounds. We consequently introduce the previously described reparameterisations to mitigate this and a series of diagnostics to aid in diagnosing biases and correctly tuning the settings. We aim address this in fur-ther work with changes to the design of the normalising flows we have used.

It is natural to compare this work to [27–30] which use variational autoeconders and normalising flows to pro-duce posterior distributions. Our approach differs from these in that it requires no prior computation since train-ing occurs during sampling and we do not introduce any assumptions about the data other than those necessary to apply a nested sampling algorithm. Nessai is therefore a drop-in replacement for existing sampling algorithms that does not require changes to existing pipelines. In future work we aim to evaluate our sampler us-ing more expensive waveform models including those for longer duration signals, such as those from binary neu-tron star of neutron star-black hole system, and models which include higher-order modes. We will also investi-gate the suitability of other types of normalising flow transforms, such as the spline based transforms from[68] and flows which allow for specifying a manifold [69].These changes could improve the efficiency of the pop-ulation stage which is currently the slowest part of the algorithm. Another possible approach for reducing the cost of population is using alternative reparameterisa-tions for parameters such as the spins magnitudes, which we observe to be two of the most challenging parameters to sample.

In summary, we have proposed a novel variation of the standard nested sampling algorithm that incorpo-rates normalising flows specifically designed for inference with computationally expensive likelihood functions. We have applied our sampler to the problem of gravitational wave inference and shown that it consistently recovers the Bayesian posteriors distributions and evidences with 2.07 times fewer total likelihood evaluations than dynesty, another commonly used sampler, which translates to a 2.32 times reduction in computation time. Our sampler therefore serves as a more efficient drop-in replacement for existing samplers.

# ACKNOWLEDGMENTS

The authors gratefully acknowledge the Science and Technology Facilities Council of the United Kingdom. MJW is supported by the Science and Technology Fa-cilities Council [2285031]. JV and CM are supported by the Science and Technology Research Council [ST/L000946/1]. CM is also supported by the European Cooperation in Science and Technology (COST) action[CA17137]. The authors are grateful for computational resources provided by Cardiff University, and funded by an STFC grant supporting UK Involvement in the Oper-ation of Advanced LIGO.

Software: Nessai was initially developed using cp-nest [21] with permission from the authors and still shares a similar interface and other core codes. Nessai is implemented in Python and uses NumPy [70], SciPy[71], pandas [72, 73], nflows [47], PyTorch [46], mat-plotlib [74] and seaborn [75]. Gravitational wave in-jections were generated using Bilby and bilby pipe [25].Figures were prepared using matplotlib [74], seaborn[75], Bilby [25] and corner [76].