diff --git a/bilby/core/sampler/nestle.py b/bilby/core/sampler/nestle.py index 41318e9628d63e996f50113448b4db36488382f2..ebd955376050c80bcb43277ff95688c6fb572be8 100644 --- a/bilby/core/sampler/nestle.py +++ b/bilby/core/sampler/nestle.py @@ -1,4 +1,3 @@ -import numpy as np from pandas import DataFrame from .base_sampler import NestedSampler, signal_wrapper @@ -71,6 +70,11 @@ class Nestle(NestedSampler): """ import nestle + if nestle.__version__ == "0.2.0": + # This is a very ugly hack to support numpy>=1.24 + nestle.np.float = float + nestle.np.int = int + out = nestle.sample( loglikelihood=self.log_likelihood, prior_transform=self.prior_transform, @@ -107,21 +111,8 @@ class Nestle(NestedSampler): bilby.core.result.Result: Dummy container for sampling results. """ - import nestle - - kwargs = self.kwargs.copy() - kwargs["maxiter"] = 2 - nestle.sample( - loglikelihood=self.log_likelihood, - prior_transform=self.prior_transform, - ndim=self.ndim, - **kwargs - ) - self.result.samples = np.random.uniform(0, 1, (100, self.ndim)) - self.result.log_evidence = np.nan - self.result.log_evidence_err = np.nan - self.calc_likelihood_count() - return self.result + self.kwargs["maxiter"] = 2 + return self.run_sampler() def write_current_state(self): """ diff --git a/bilby/core/sampler/ptemcee.py b/bilby/core/sampler/ptemcee.py index e9da5371cf684fc9f61a310af49d72cf1fc48a55..8fce83996c37868c95708a8d227e69a2e0d1a4bc 100644 --- a/bilby/core/sampler/ptemcee.py +++ b/bilby/core/sampler/ptemcee.py @@ -408,6 +408,10 @@ class Ptemcee(MCMCSampler): """Either initialize the sampler or read in the resume file""" import ptemcee + if ptemcee.__version__ == "1.0.0": + # This is a very ugly hack to support numpy>=1.24 + ptemcee.sampler.np.float = float + if os.path.isfile(self.resume_file) and self.resume is True: import dill diff --git a/bilby/gw/prior.py b/bilby/gw/prior.py index 1f605f56f1a85509b09f0fc55e75e491aa7f3a63..0043395962753a54f7e047d25e89cd3e5ddc13b4 100644 --- a/bilby/gw/prior.py +++ b/bilby/gw/prior.py @@ -1325,11 +1325,11 @@ class HealPixMapPriorDist(BaseJointPriorDist): bounds.append([0, np.inf]) self.distance = True self.prob, self.distmu, self.distsigma, self.distnorm = self.hp.read_map( - hp_file, verbose=False, field=range(4) + hp_file, field=range(4) ) else: self.distance = False - self.prob = self.hp.read_map(hp_file, verbose=False) + self.prob = self.hp.read_map(hp_file) super(HealPixMapPriorDist, self).__init__(names=names, bounds=bounds) self.distname = "hpmap" @@ -1341,7 +1341,6 @@ class HealPixMapPriorDist(BaseJointPriorDist): self._all_interped = interp1d(x=self.pix_xx, y=self.prob, bounds_error=False, fill_value=0) self.inverse_cdf = None self.distance_pdf = None - self.distance_dist = None self.distance_icdf = None self._build_attributes() name = self.names[-1] @@ -1429,14 +1428,6 @@ class HealPixMapPriorDist(BaseJointPriorDist): ).pdf(r) pdfs = self.rs ** 2 * norm(loc=self.distmu[pix_idx], scale=self.distsigma[pix_idx]).pdf(self.rs) cdfs = np.cumsum(pdfs) / np.sum(pdfs) - - def sample_distance(n): - gaussian = norm(loc=self.distmu[pix_idx], scale=self.distsigma[pix_idx]).rvs(size=100 * n) - probs = self._check_norm(gaussian[gaussian > 0] ** 2) - ds = np.random.choice(gaussian[gaussian > 0], p=probs, size=n, replace=True) - return ds - - self.distance_dist = sample_distance self.distance_icdf = interp1d(cdfs, self.rs) @staticmethod @@ -1512,7 +1503,7 @@ class HealPixMapPriorDist(BaseJointPriorDist): """ if self.distmu[pix] == np.inf or self.distmu[pix] <= 0: return 0 - dist = self.distance_dist(1) + dist = self.distance_icdf(np.random.uniform(0, 1)) name = self.names[-1] if (dist > self.bounds[name][1]) | (dist < self.bounds[name][0]): self.draw_distance(pix) @@ -1605,7 +1596,7 @@ class HealPixMapPriorDist(BaseJointPriorDist): return lnprob def __eq__(self, other): - skip_keys = ["_all_interped", "inverse_cdf", "distance_pdf", "distance_dist", "distance_icdf"] + skip_keys = ["_all_interped", "inverse_cdf", "distance_pdf", "distance_icdf"] if self.__class__ != other.__class__: return False if sorted(self.__dict__.keys()) != sorted(other.__dict__.keys()):