def validateMCMCKwargs(ap, samplerKwargs, mcmcKwargs, verbose=False):
    """
    Validates emcee.EnsembleSampler parameters/kwargs.

    Parameters
    ----------
    ap : approxposterior.ApproxPosterior
            Initialized ApproxPosterior object
    samplerKwargs : dict
        dictionary containing parameters intended for emcee.EnsembleSampler
        object
    mcmcKwargs : dict
        dictionary containing parameters intended for
        emcee.EnsembleSampler.run_mcmc/.sample object
    verbose : bool (optional)
        verboisty level. Defaults to False (no output)

    Returns
    -------
    samplerKwargs : dict
        Sanitized dictionary containing parameters intended for
        emcee.EnsembleSampler object
    mcmcKwargs : dict
        Sanitized dictionary containing parameters intended for
        emcee.EnsembleSampler.run_mcmc/.sample object
    """
    if samplerKwargs is None:
        samplerKwargs = dict()
        samplerKwargs['ndim'] = ap.theta.shape[-1]
        samplerKwargs['nwalkers'] = 20 * samplerKwargs['dim']
        samplerKwargs['log_prob_fn'] = ap._gpll
    else:
        samplerKwargs.pop('ndim', None)
        samplerKwargs['ndim'] = ap.theta.shape[-1]
        try:
            nwalkers = samplerKwargs['nwalkers']
        except KeyError:
            print(
                'WARNING: samplerKwargs provided but nwalkers not in samplerKwargs'
                )
            print('Defaulting to nwalkers = 20 per dimension.')
            samplerKwargs['nwalkers'] = 20 * samplerKwargs['ndim']
        if 'backend' in samplerKwargs.keys():
            print(
                'WARNING: backend in samplerKwargs. approxposterior creates its own!'
                )
            print(
                'with filename = apRun.h5. Disregarding user-supplied backend.'
                )
        if 'log_prob_fn' in samplerKwargs.keys():
            samplerKwargs.pop('log_prob_fn', None)
        samplerKwargs.pop('backend', None)
        samplerKwargs['log_prob_fn'] = ap._gpll
    if mcmcKwargs is None:
        mcmcKwargs = dict()
        mcmcKwargs['iterations'] = 10000
        mcmcKwargs['initial_state'] = ap.priorSample(samplerKwargs['nwalkers'])
    else:
        try:
            nsteps = mcmcKwargs['iterations']
        except KeyError:
            mcmcKwargs['iterations'] = 10000
            if verbose:
                print(
                    'WARNING: mcmcKwargs provided, but iterations not in mcmcKwargs.'
                    )
                print('Defaulting to iterations = 10000.')
        try:
            p0 = mcmcKwargs['initial_state']
        except KeyError:
            mcmcKwargs['initial_state'] = ap.priorSample(samplerKwargs[
                'nwalkers'])
            if verbose:
                print(
                    'WARNING: mcmcKwargs provided, but initial_state not in mcmcKwargs.'
                    )
                print('Defaulting to nwalkers samples from priorSample.')
    return samplerKwargs, mcmcKwargs
