code: def validate_fe_steps(
      candidate: Union[list, FeatureEngineer],
      template: Union[list, FeatureEngineer],
  ) -> list:
      """Check `candidate` "feature_engineer" `steps` compatibility with `template` and sanitize
      `candidate`
  
      Parameters
      ----------
      candidate: List, or FeatureEngineer
          Candidate "feature_engineer" `steps` to compare to `template`. If compatible with
          `template`, a sanitized version of `candidate` will be returned (described below)
      template: List, or FeatureEngineer
          Template "feature_engineer" `steps` to which `candidate` will be compared. `template` is
          also used to sanitize `candidate` (described below)
  
      Returns
      -------
      List
          If `candidate` is compatible with `template`, returns a list resembling `candidate`, with
          the following changes: 1) all step dicts in `candidate` are reinitialized to proper
          `EngineerStep` instances; and 2) wherever `candidate` was missing a step that was tagged as
          `optional` in `template`, `RejectedOptional` is added. In the end, if a list is returned, it
          is built from `candidate`, guaranteed to be the same length as `template` and guaranteed
          to contain only `EngineerStep` and `RejectedOptional` instances
  
      Raises
      ------
      IncompatibleCandidateError
          If `candidate` is incompatible with `template`. `candidate` may be incompatible with
          `template` for any of the following reasons:
  
          1. `candidate` has more steps than `template`
          2. `candidate` has a step that differs from a concrete (non-`Categorical`) `template` step
          2. `candidate` has a step that differs from a concrete (non-`Categorical`) `template` step
          3. `candidate` has a step that does not fit in a `Categorical` `template` step
          4. `candidate` is missing a concrete step in `template`
          5. `candidate` is missing a non-`optional` `Categorical` step in `template`
      """
      # Extract `steps` if given `FeatureEngineer`
      if isinstance(candidate, FeatureEngineer):
          candidate = candidate.steps
      if isinstance(template, FeatureEngineer):
          template = template.steps
  
      if len(template) == 0:
          if len(candidate) == 0:
              # All steps have been exhausted and passed, so `candidate` was a match
              return []
          # `candidate` steps remain while `template` is empty, so `candidate` is incompatible
          raise IncompatibleCandidateError(candidate, template)
  
      #################### Categorical Template Step ####################
      if isinstance(template[-1], Categorical):
          #################### Optional Categorical Template Step ####################
          if template[-1].optional is True:
              if len(candidate) == 0 or (
                  candidate[-1] not in template[-1]
              ):
                  # `candidate` is either empty or doesn't match an `optional` template step
                  candidate.append(RejectedOptional())
  
          #################### Non-Optional Categorical Template Step ####################
          elif len(candidate) == 0:
              # `candidate` is empty while non-`optional` `template` steps remain - Incompatible
              raise IncompatibleCandidateError(candidate, template)
          elif candidate[-1] not in template[-1]:
              raise IncompatibleCandidateError(candidate, template)
  
      elif len(candidate) == 0:
          raise IncompatibleCandidateError(candidate, template)
  
      #################### Concrete Template Step ####################
      elif candidate[-1] != template[-1]:
          raise IncompatibleCandidateError(candidate, template)
  
      #################### Reinitialize EngineerStep Dict ####################
      if isinstance(candidate[-1], dict):
          if isinstance(template[-1], Categorical):
              candidate[-1] = EngineerStep.honorary_step_from_dict(
                  candidate[-1], template[-1]
              )
          elif (
              isinstance(template[-1], EngineerStep)
              and template[-1] == candidate[-1]
          ):
              candidate[-1] = template[
                  -1
              ]  # Adopt template value if `EngineerStep` equivalent
  
      return validate_fe_steps(candidate[:-1], template[:-1]) + [
          candidate[-1]
      ]
  
imports: from hyperparameter_hunter.feature_engineering import EngineerStep, FeatureEngineer
  from hyperparameter_hunter.i_o.exceptions import IncompatibleCandidateError
  from hyperparameter_hunter.compat.keras_helper import keras_callback_to_dict, keras_initializer_to_dict
  from hyperparameter_hunter.settings import G
  from hyperparameter_hunter.space.dimensions import Categorical, RejectedOptional
  from hyperparameter_hunter.space.space_core import Space
  from hyperparameter_hunter.utils.boltons_utils import remap, get_path
  from hyperparameter_hunter.utils.general_utils import multi_visit
  from hyperparameter_hunter.utils.optimization_utils import does_fit_in_space, get_ids_by, get_scored_params
  from copy import deepcopy
  from numbers import Number
  from pathlib import Path
  from typing import Dict, List, Tuple, Union
  import wrapt
label_desc: Use image node_id 5 for calling a global function with example usage: validate_fe_steps(candidate, template) and returns: unknown, list