def _update_state(affected_rules, search_state, config):
  """Sparsely update the state for rules that may be affected."""
  for idx, affected_rule in enumerate(affected_rules):
    # Debug logging every Nth rule.
    if idx % 10 == 0:
      print("Updating rule %s of %s." % (idx + 1, len(affected_rules)))

    # Check if rule can now be generated. Ideally, this should have been
    # determined upstream when determining which rules could be removed,
    # but some cases are not caught until here, such as when source
    # sequences contain repeated substrings and are therefore not considered
    # by `get_candidates`.
    # Regardless, it is still important to run this for the side-effect of
    # updating the set of derivable rules.
    if derivation_utils.can_derive(affected_rule, search_state.current_rules,
                                   search_state.derivable_rules):
      print("Can now generate: %s." % str(affected_rule))
      search_state.current_rules.remove(affected_rule)
    else:
      candidates = split_utils.find_possible_splits(
          affected_rule,
          search_state.derivable_rules,
          allow_repeated_target_nts=config.allow_repeated_target_nts,
      )
      if config.balance_parens:
        candidates = _filter_unbalanced_paren_candidates(candidates)
      for candidate in candidates:
        search_state.rules_to_candidates[affected_rule].add(candidate)
  print("Updates complete.")
Sparsely update the state for rules that may be affected.
language/compgen/nqg/model/induction/induction_utils.py