code: def cache_subtree_features(tree, feature_names, parent=None):
      """Caches the features of the subtree on each of the tree nodes.
  
      :param tree: The current node in the tree to cache the features on.
      :type tree: dict
      :param feature_names: The set of feature names.
      :type feature_names: set[str]
      :param parent: The parent node of the current node.
      :type parent: Node or None
      :return: The features from the tree.
      :rtype: list[str]
      """
      if parent is not None:
          p_node_name_val = feature_names[parent[SPLIT_FEATURE]]
          features = {p_node_name_val}
      else:
          features = set()
      if LEAF_VALUE not in tree:
          left_child = tree[TreeSide.LEFT_CHILD]
          features = features.union(
              cache_subtree_features(left_child, feature_names, tree)
          )
          right_child = tree[TreeSide.RIGHT_CHILD]
          features = features.union(
              cache_subtree_features(right_child, feature_names, tree)
          )
      tree[CACHED_SUBTREE_FEATURES] = features
      return features
  
imports: import logging
  import numbers
  from enum import Enum
  import numpy
  import pandas
  from lightgbm import Booster, LGBMClassifier, LGBMRegressor
  from sklearn.metrics import mean_absolute_error, mean_squared_error, median_absolute_error, r2_score
  from erroranalysis._internal.cohort_filter import filter_from_cohort
  from erroranalysis._internal.constants import DIFF, LEAF_INDEX, METHOD, PRED_Y, ROW_INDEX, SPLIT_FEATURE, SPLIT_INDEX, TRUE_Y, CohortFilterMethods, Metrics, ModelTask, TreeNode, error_metrics, f1_metrics, metric_to_display_name, precision_metrics, recall_metrics, regression_metrics
  from erroranalysis._internal.metrics import get_ordered_classes, metric_to_func
  from erroranalysis._internal.process_categoricals import process_categoricals
  from erroranalysis._internal.utils import is_spark
  from raiutils.exceptions import UserConfigValidationException
label_desc: Use image node_id 12 for calling a global function with example usage: cache_subtree_features(tree, feature_names, parent) and returns: features