Пример #1
0
def core(cache: Path):
    return mcmc.CoreCoevalModule(
        redshift=9,
        user_params={
            "HII_DIM": 35,
            "DIM": 70
        },
        cache_mcmc=False,
        cache_dir=str(cache),
    )
Пример #2
0
def test_forest(lc_core_lowz, lc_core_lowz_ctx):

    lk = mcmc.LikelihoodForest(name="z5pt4")

    with pytest.raises(mcmc.NotAChain):
        assert lk._is_lightcone

    core = mcmc.CoreForest(
        redshift=5.4,
        name="z5pt4",
        user_params=lc_core_lowz.user_params,
        flag_options=lc_core_lowz.flag_options,
        n_realization=10,
    )

    with pytest.raises(NotImplementedError):
        coeval_core_lowz = mcmc.CoreCoevalModule(
            redshift=5.4,
            max_redshift=8.0,
            user_params=lc_core_lowz.user_params,
            flag_options=lc_core_lowz.flag_options,
        )
        chain = mcmc.build_computation_chain([coeval_core_lowz, core],
                                             lk,
                                             setup=True)
        lk.setup()

        model = lk.reduce_data(chain.build_model_data())

    with pytest.raises(ValueError):
        lk_wrongz = mcmc.LikelihoodForest(name="z5pt5")
        core_wrongz = mcmc.CoreForest(
            redshift=5.5,
            name="z5pt5",
            user_params=lc_core_lowz.user_params,
            flag_options=lc_core_lowz.flag_options,
            n_realization=10,
        )

        chain = mcmc.build_computation_chain([lc_core_lowz, core_wrongz],
                                             lk_wrongz,
                                             setup=True)
        lk_wrongz.setup()

        model = lk_wrongz.reduce_data(chain.build_model_data())

    mcmc.build_computation_chain([lc_core_lowz, core], lk, setup=True)
    lk.setup()

    model = lk.reduce_data(lc_core_lowz_ctx)
    assert not np.all(model == 0)
Пример #3
0
def test_wrong_ctx_variable():
    core = mcmc.CoreCoevalModule(
        redshift=6,
        user_params={
            "HII_DIM": 35,
            "BOX_LEN": 70
        },
        ctx_variables=("bad_key", "good key"),
    )
    lk = mcmc.Likelihood1DPowerCoeval(use_data=False)

    chain = mcmc.build_computation_chain(core, lk, setup=False)

    with pytest.raises(ValueError):
        chain.build_model_data()
Пример #4
0
def test_bad_continuation(core, likelihood_coeval, default_params, tmpdirec):
    "check if trying to continue a chain that isn't compatible with previous chain raises an error"

    mcmc.run_mcmc(
        core,
        likelihood_coeval,
        model_name="TESTBURNIN",
        continue_sampling=False,
        datadir=tmpdirec,
        params=default_params,
        walkersRatio=2,
        burninIterations=0,
        sampleIterations=1,
        threadCount=1,
    )

    with pytest.raises(RuntimeError):
        # core with different redshift
        core = mcmc.CoreCoevalModule(
            redshift=8,
            user_params={
                "HII_DIM": 35,
                "DIM": 70
            },
            cache_mcmc=False,
            cache_init=False,
        )
        mcmc.run_mcmc(
            core,
            likelihood_coeval,
            model_name="TESTBURNIN",
            continue_sampling=True,
            datadir=tmpdirec,
            params=default_params,
            walkersRatio=2,
            burninIterations=0,
            sampleIterations=2,
            threadCount=1,
        )
Пример #5
0
def test_core_coeval_not_setup():
    core = mcmc.CoreCoevalModule(redshift=9)

    with pytest.raises(mcmc.NotAChain):
        core.chain