From fb501cb2ec623192c47fd6bcdc467e3a1870ea89 Mon Sep 17 00:00:00 2001 From: Joe Zuntz Date: Mon, 13 Jan 2025 15:00:19 +0000 Subject: [PATCH] add output_block option to maxlike sampler --- cosmosis/samplers/maxlike/maxlike_sampler.py | 4 ++++ cosmosis/test/test_samplers.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cosmosis/samplers/maxlike/maxlike_sampler.py b/cosmosis/samplers/maxlike/maxlike_sampler.py index 5c7ee40e..e1d9710d 100755 --- a/cosmosis/samplers/maxlike/maxlike_sampler.py +++ b/cosmosis/samplers/maxlike/maxlike_sampler.py @@ -35,6 +35,7 @@ def config(self): self.maxiter = self.read_ini("maxiter", int, 1000) self.output_ini = self.read_ini("output_ini", str, "") self.output_cov = self.read_ini("output_covmat", str, "") + self.output_block = self.read_ini("output_block", str, "") self.method = self.read_ini("method",str,"Nelder-Mead") self.max_posterior = self.read_ini("max_posterior", bool, False) self.repeats = self.read_ini("repeats", int, 1) @@ -114,6 +115,9 @@ def save_final_outputs(self, best_fit_results, final=False): if self.output_ini: self.pipeline.create_ini(results.vector, self.output_ini) + + if self.output_block: + results.block.save_to_directory(self.output_block) # We only want to update the distribution hints at the very end diff --git a/cosmosis/test/test_samplers.py b/cosmosis/test/test_samplers.py index 46ce6e69..378a36b0 100644 --- a/cosmosis/test/test_samplers.py +++ b/cosmosis/test/test_samplers.py @@ -167,9 +167,11 @@ def test_maxlike(): with tempfile.TemporaryDirectory() as dirname: output_ini = os.path.join(dirname, "output.ini") output_cov = os.path.join(dirname, "output_cov.txt") - run('maxlike', True, can_postprocess=False, method="L-BFGS-B", max_posterior=True, output_ini=output_ini, output_covmat=output_cov) + output_block = os.path.join(dirname, "output_block") + run('maxlike', True, can_postprocess=False, method="L-BFGS-B", max_posterior=True, output_ini=output_ini, output_covmat=output_cov, output_block=output_block) assert os.path.exists(output_cov) assert os.path.exists(output_ini) + assert os.path.isdir(output_block)