diff --git a/cosmosis/runtime/pipeline.py b/cosmosis/runtime/pipeline.py index 01984a01..8b1d0696 100644 --- a/cosmosis/runtime/pipeline.py +++ b/cosmosis/runtime/pipeline.py @@ -896,7 +896,7 @@ def output_names(self): for section,name in self.extra_saves: if ('#' in name): n,l = name.split('#') - for i in range(l): + for i in range(int(l)): extra_names.append('{}--{}_{}'.format(section,n,i)) else: extra_names.append('%s--%s'%(section,name)) diff --git a/cosmosis/test/test_module4.py b/cosmosis/test/test_module4.py index eda50827..0f49d82a 100644 --- a/cosmosis/test/test_module4.py +++ b/cosmosis/test/test_module4.py @@ -5,5 +5,5 @@ def setup(options): def execute(block, config): p3 = block['parameters', 'p3'] - # do nothing execpt read + # do nothing except read return 0 diff --git a/cosmosis/test/test_pipeline.py b/cosmosis/test/test_pipeline.py index 49df335b..67a2166c 100644 --- a/cosmosis/test/test_pipeline.py +++ b/cosmosis/test/test_pipeline.py @@ -3,6 +3,7 @@ from cosmosis.samplers.sampler import Sampler from cosmosis.runtime.prior import TruncatedGaussianPrior, DeltaFunctionPrior from cosmosis.output.in_memory_output import InMemoryOutput +from cosmosis.main import run_cosmosis, parser import numpy as np import os import tempfile @@ -88,6 +89,44 @@ def test_unused_param_warning(capsys): out, _ = capsys.readouterr() assert "**** WARNING: Parameter 'unused'" in out +def test_vector_extra_outputs(): + with tempfile.TemporaryDirectory() as dirname: + values_file = f"{dirname}/values.ini" + params_file = f"{dirname}/params.ini" + output_file = f"{dirname}/output.txt" + with open(values_file, "w") as values: + values.write( + "[parameters]\n" + "p1=-3.0 0.0 3.0\n" + "p2=-3.0 0.0 3.0\n") + + params = { + ('runtime', 'root'): os.path.split(os.path.abspath(__file__))[0], + ('runtime', 'sampler'): "emcee", + ("pipeline", "debug"): "T", + ("pipeline", "quiet"): "F", + ("pipeline", "modules"): "test1", + ("pipeline", "extra_output"): "data_vector/test_theory#2", + ("pipeline", "values"): values_file, + ("test1", "file"): "test_module.py", + ("output", "filename"): output_file, + ("emcee", "walkers"): "8", + ("emcee", "samples"): "10", + } + + args = parser.parse_args(["not_a_real_file"]) + ini = Inifile(None, override=params) + status = run_cosmosis(args, ini=ini) + + with open(output_file) as f: + header = f.readline() + + assert "data_vector--test_theory_0" in header.lower() + assert "data_vector--test_theory_1" in header.lower() + + data = np.loadtxt(output_file) + # two parameters, two extra saves, prior, and posterior + assert data.shape[1] == 6 if __name__ == '__main__':