Example #1
0
def test_demo3():

    config_fn_ini = os.path.join(demo_dir, 'demo3.ini')
    config_fn_yaml = os.path.join(demo_dir, 'demo3.yaml')
    config = ConfigBlock(config_fn_ini)
    with open(config_fn_yaml, 'w') as file:
        yaml.dump(config.data, file)

    for config_fn in [config_fn_ini, config_fn_yaml]:

        graph_fn = os.path.join(demo_dir, 'pipe3.ps')

        mapping_proj = ['ell_0', 'ell_2', 'ell_4']
        make_data_covariance(data_fn=data_fn,
                             covariance_fn=covariance_fn,
                             mapping_proj=mapping_proj)
        pipeline = BasePipeline(config_block=config_fn)
        pipeline.plot_pipeline_graph(graph_fn)
        pipeline.setup()
        pipeline.execute_parameter_values(a=0.)
        loglkl = pipeline.data_block[section_names.likelihood, 'loglkl']
        pipeline.execute_parameter_values(a=4.)
        assert pipeline.data_block[section_names.likelihood,
                                   'loglkl'] != loglkl
        pipeline.cleanup()
Example #2
0
def test_demo4():

    config_fn = os.path.join(demo_dir, 'demo4.ini')
    graph_fn = os.path.join(demo_dir, 'pipe4.ps')

    mapping_proj = ['ell_0', 'ell_2', 'ell_4']
    make_data_covariance(data_fn=data_fn,
                         covariance_fn=covariance_fn,
                         mapping_proj=mapping_proj)
    pipeline = BasePipeline(config_block=config_fn)
    pipeline.plot_pipeline_graph(graph_fn)
    pipeline.setup()
    pipeline.data_block[section_names.parameters, 'a'] = 0.
    del pipeline.data_block[section_names.parameters, 'a_model1']
    del pipeline.data_block[section_names.parameters, 'b_model1']

    def test_error():
        ok = False
        try:
            pipeline.execute()
        except BlockError:
            ok = True
        assert ok

    test_error()
    pipeline.data_block[section_names.parameters, 'a_model1'] = 0.
    test_error()
    pipeline.data_block[section_names.parameters, 'b_model1'] = 0.
    assert (section_names.common, 'y_data1') in pipeline.data_block
    assert (section_names.common, 'y_data2') not in pipeline.data_block
    pipeline.cleanup()
Example #3
0
def test_internal():
    os.chdir(base_dir)
    mapping_proj = ['ell_0', 'ell_2', 'ell_4']
    make_data_covariance(data_fn=data_fn,
                         covariance_fn=covariance_fn,
                         mapping_proj=mapping_proj)
    try:  # not finished
        main(config='demo3.ini')
    except CosmosisConfigurationError:
        pass
Example #4
0
def test_external():

    os.chdir(base_dir)
    mapping_proj = ['ell_0', 'ell_2', 'ell_4']
    make_data_covariance(data_fn=data_fn,
                         covariance_fn=covariance_fn,
                         mapping_proj=mapping_proj)
    info = yaml_load_file('./test_cobaya.yaml')
    updated_info, sampler = run(info)
    assert 'a' in updated_info['params']
    assert 'sample' in sampler.products()
Example #5
0
def test_external():

    os.chdir(base_dir)
    mapping_proj = ['ell_0', 'ell_2', 'ell_4']
    make_data_covariance(data_fn=data_fn,
                         covariance_fn=covariance_fn,
                         mapping_proj=mapping_proj)
    ini = Inifile('test_cosmosis.ini')
    pipeline = LikelihoodPipeline(ini)
    data = pipeline.run_parameters([0.2])
    assert data['likelihoods', 'cosmopipe_like'] != 0.

    from cosmosis.samplers.emcee.emcee_sampler import EmceeSampler
    from cosmosis.output.in_memory_output import InMemoryOutput
    output = InMemoryOutput()
    sampler = EmceeSampler(ini, pipeline, output)
    sampler.config()

    while not sampler.is_converged():
        sampler.execute()
Example #6
0
def test_demo2():

    config_fn = os.path.join(demo_dir, 'demo2.ini')
    graph_fn = os.path.join(demo_dir, 'pipe2.ps')

    mapping_proj = ['ell_0', 'ell_2', 'ell_4']
    make_data_covariance(data_fn=data_fn,
                         covariance_fn=covariance_fn,
                         mapping_proj=mapping_proj)

    pipeline = BasePipeline(config_block=config_fn)
    pipeline.plot_pipeline_graph(graph_fn)
    pipeline.setup()
    pipeline.data_block[section_names.parameters, 'a'] = 0.
    pipeline.execute()
    loglkl = pipeline.data_block[section_names.likelihood, 'loglkl']
    pipeline.data_block[section_names.parameters, 'a'] = 4.
    pipeline.execute()
    assert pipeline.data_block[section_names.likelihood, 'loglkl'] != loglkl
    pipeline.cleanup()
Example #7
0
def test_demo3b():

    config_fn = os.path.join(demo_dir, 'demo3.ini')
    graph_fn = os.path.join(demo_dir, 'pipe3b.ps')

    mapping_proj = ['ell_0', 'ell_2', 'ell_4']
    make_data_covariance(data_fn=data_fn,
                         covariance_fn=covariance_fn,
                         mapping_proj=mapping_proj)
    config_block = ConfigBlock(config_fn)
    data1 = BaseModule.from_library(name='data1',
                                    options=SectionBlock(
                                        config_block, 'data1'))
    model1 = FlatModel(name='model1')
    data2 = BaseModule.from_library(name='data2',
                                    options=SectionBlock(
                                        config_block, 'data2'))
    model2 = BaseModule.from_library(name='model2',
                                     options=SectionBlock(
                                         config_block, 'model2'))
    cov = BaseModule.from_library(name='cov',
                                  options=SectionBlock(config_block, 'cov'))
    like1 = BaseLikelihood(name='like1', modules=[data1, model1])
    like2 = BaseLikelihood(name='like2', modules=[data2, model2])
    like = JointGaussianLikelihood(name='like',
                                   join=[like1, like2],
                                   modules=[cov])
    pipeline = BasePipeline(modules=[like])
    pipeline.plot_pipeline_graph(graph_fn)
    pipeline.setup()
    pipeline.data_block[section_names.parameters, 'a'] = 0.
    pipeline.execute()
    loglkl = pipeline.data_block[section_names.likelihood, 'loglkl']
    pipeline.data_block[section_names.parameters, 'a'] = 4.
    pipeline.execute()
    assert pipeline.data_block[section_names.likelihood, 'loglkl'] != loglkl
    pipeline.cleanup()
Example #8
0
def test_demo1():

    os.chdir(base_dir)
    config_fn = os.path.join(demo_dir, 'demo1.ini')
    graph_fn = os.path.join(demo_dir, 'pipe1.ps')

    mapping_proj = ['ell_0', 'ell_2', 'ell_4']
    make_data_covariance(data_fn=data_fn,
                         covariance_fn=covariance_fn,
                         mapping_proj=mapping_proj)

    pipeline = BasePipeline(config_block=config_fn)
    pipeline.plot_pipeline_graph(graph_fn)
    pipeline.setup()
    pipeline.data_block[section_names.parameters, 'a'] = 0.
    pipeline.execute()
    loglkl = pipeline.data_block[section_names.likelihood, 'loglkl']
    pipeline.data_block[section_names.parameters, 'a'] = 4.
    pipeline.execute()
    assert pipeline.data_block[section_names.likelihood, 'loglkl'] != loglkl
    pipeline.cleanup()

    graph_fn = os.path.join(demo_dir, 'inheritance.ps')
    BaseModule.plot_inheritance_graph(graph_fn, exclude=['AffineModel'])