def check_initial_conditions(model):
    """
    Ensure initial conditions are well formed, and do not exceed population numbers.
    """

    def _check(field, value, error):
        try:
            is_pop_too_small = sum(value.values()) > model.starting_population
            if is_pop_too_small:
                error(field, "Initial condition population exceeds total starting population.")

            if not all([c in model.compartment_types for c in value.keys()]):
                error(
                    field,
                    "Initial condition compartment name is not one of the listed compartment types",
                )
        except TypeError:
            error(field, "Could not check initial conditions.")

    return _check