[Python] I cant to seem make emcee blobs working correctly

Discussão em 'Python' iniciado por Stack, Setembro 5, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to include in my h5 file some parameters that are calculated inside my prob log function but after reading the docs and trying to implement it it always give me error.

    In the docs, https://emcee.readthedocs.io/en/stable/user/blobs/, in the function prob log they return the log prob and more two variables and I supose that they are written in the h5.

    In my case I have


    def Log_neutrino():
    ...
    return LTotal, variable1, variable2, variable3

    def run_MCMC(p0, lnprob, ndim, nwalkers, nburnin, nrun, h5name, scale, reset=True, pool_obj=None, burn_in=True):
    initial = [np.array(p0) + 1e-4 * np.random.randn(ndim) for i in range(nwalkers)]
    dtype = [("m1_tree", float), ("m2_tree", float), ("m3_tree", float)]
    backend = emcee.backends.HDFBackend(h5name)
    if reset:
    backend.reset(nwalkers, ndim)
    sampler = emcee.EnsembleSampler(nwalkers, ndim, lnprob, backend=backend, pool=pool_obj, a = scale, blobs_dtype=dtype)
    if burn_in:
    print("Running burn-in...")
    print(len(initial))
    initial, _ , _ = sampler.run_mcmc(initial, nburnin, progress=True)
    sampler.reset()
    print("Running production...")
    pos, prob, state = sampler.run_mcmc(initial, nrun, progress=True)
    return sampler


    But with this I am getting this: ValueError: could not assign tuple of length 1 to structure with 3 fields.

    I have tried to do

    return LTotal, (variable1, variable2, variable3)

    But it does not work either.

    It only worked if i only return one more variable besides LTotal, and even though the variable is not stored in the h5 file.

    Continue reading...

Compartilhe esta Página