import warnings


def _infer_max_treedepth(fit):
    """Extract max treedepth from a StanFit4Model instance."""
    try:
        return fit.stan_args[0]["ctrl"]["sampling"]["max_treedepth"]
    except:
        warnings.warn("Unable to determine max_treedepth. " + "Using value of 10.")
        return 10