From 762583b59f7d3a428ad90da75daf90d3c4b9a123 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Thu, 9 Nov 2023 14:37:39 +0000 Subject: [PATCH 1/2] Make list sampler operate in chunks of data --- cosmosis/samplers/list/list_sampler.py | 53 +++++++++++++++----------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/cosmosis/samplers/list/list_sampler.py b/cosmosis/samplers/list/list_sampler.py index 3d4337d4..c8f736d3 100755 --- a/cosmosis/samplers/list/list_sampler.py +++ b/cosmosis/samplers/list/list_sampler.py @@ -29,6 +29,7 @@ def config(self): self.burn = self.read_ini("burn", int, 0) self.thin = self.read_ini("thin", int, 1) limits = self.read_ini("limits", bool, False) + self.chunk_size = self.read_ini("chunk_size", int, 100) #overwrite the parameter limits if not limits: @@ -93,28 +94,36 @@ def execute(self): sample_index = list(range(len(sample_vectors))) jobs = list(zip(sample_index, sample_vectors)) - #Run all the parameters - #This only outputs them all at the end - #which is a bit problematic, though you - #can't use MPI and retain the output ordering. - #Have a few options depending on whether - #you care about this we should think about - #(also true for grid sampler). - if self.pool: - results = self.pool.map(task, jobs) - else: - results = list(map(task, jobs)) - - #Save the results of the sampling - #We now need to abuse the output code a little. - for sample, result in zip(sample_vectors, results): - #Optionally save all the results calculated by each - #pipeline run to files - (prob, (prior,extra)) = result - #always save the usual text output - self.output.parameters(sample, extra, prior, prob) - #We only ever run this once, though that could - #change if we decide to split up the runs + nsample = len(sample_index) + nchunk = nsample//self.chunk_size + if nsample%self.chunk_size!=0: + nchunk += 1 + + # Run on a chunk of parameters + for i in range(nchunk): + start = i*self.chunk_size + end = (i+1)*self.chunk_size + if end>nsample: + end = nsample + chunk = jobs[start:end] + + if self.pool: + results = self.pool.map(task, chunk) + else: + results = list(map(task, chunk)) + + + # Save the results of the sampling + # We now need to abuse the output code a little. + for sample, result in zip(sample_vectors[start:end], results): + # Optionally save all the results calculated by each + # pipeline run to files + (prob, (prior,extra)) = result + # always save the usual text output + self.output.parameters(sample, extra, prior, prob) + + # We only ever run this once, though that could + # change if we decide to split up the runs self.converged = True def is_converged(self): From 5d274ba2e1601e9d168bd120718a329b4a155f02 Mon Sep 17 00:00:00 2001 From: joezuntz Date: Thu, 9 Nov 2023 14:52:00 +0000 Subject: [PATCH 2/2] Update version.py --- cosmosis/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cosmosis/version.py b/cosmosis/version.py index 36f77735..daee014f 100644 --- a/cosmosis/version.py +++ b/cosmosis/version.py @@ -1 +1 @@ -__version__ = '3.4' +__version__ = '3.4.2'