def stop_early(ruleset, max_rules, max_total_conds):
    """Function to decide whether to halt training."""
    return (max_rules is not None and len(ruleset.rules) >= max_rules) or (
        max_total_conds is not None and ruleset.count_conds() >= max_total_conds
    )