class_docstr: The model template for Multistage Forecast Estimator.
class_docstr_tok: ["The","model","template","for","Multistage","Forecast","Estimator","."]
docstr: Flattens the ``estimator_params_list``.
  
  The ``estimator_params_list`` is from ``self.__get_estimators_and_params_from_template_configs``,
  and may contain nested grids within each parameter.
  This function flattens it into the format of list of lists of ``estimator_params``.
  
  For example, the original ``estimator_params_list`` is
  
      [{"a": [1], "b": [2, 3]}, {"c": [4, 5]}]
  
  It consists of 2 stages of models. Each stage of model's parameters are in a dictionary.
  The parameter values are in lists and could have multiple possible values.
  
  After flattening the ``estimator_params_list``, it becomes
  
      [[{"a": 1, "b": 2}, {"c": 4}], [{"a": 1, "b": 3}, {"c": 4}],
       [{"a": 1, "b": 2}, {"c": 5}], [{"a": 1, "b": 3}, {"c": 5}]]
  
  There are 2 x 2 = 4 sets of parameters, i.e., 4 sets of ``estimator_params``,
  each of which includes two dictionaries which correspond to the two stages of models.
  
  Parameters
  ----------
  estimator_params_list : `list` [`dict` [`str`, any]]
      The estimator parameter list in hyperparameter grids.
  
  Returns
  -------
  flattened_estimator_params : `list` [`list` [`dict` [`str`, any]]]
      The flattened list of lists of estimator parameter dictionaries.
docstr_tok: ["Flattens","the","``","estimator_params_list","``",".","The","``","estimator_params_list","``","is","from","``","self.__get_estimators_and_params_from_template_configs","``",",","and","may","contain","nested","grids","within","each","parameter",".","This","function","flattens","it","into","the","format","of","list","of","lists","of","``","estimator_params","``",".","For","example",",","the","original","``","estimator_params_list","``","is","[","{","``","a","''",":","[","1","]",",","``","b","''",":","[","2",",","3","]","}",",","{","``","c","''",":","[","4",",","5","]","}","]","It","consists","of","2","stages","of","models",".","Each","stage","of","model","'s","parameters","are","in","a","dictionary",".","The","parameter","values","are","in","lists","and","could","have","multiple","possible","values",".","After","flattening","the","``","estimator_params_list","``",",","it","becomes","[","[","{","``","a","''",":","1",",","``","b","''",":","2","}",",","{","``","c","''",":","4","}","]",",","[","{","``","a","''",":","1",",","``","b","''",":","3","}",",","{","``","c","''",":","4","}","]",",","[","{","``","a","''",":","1",",","``","b","''",":","2","}",",","{","``","c","''",":","5","}","]",",","[","{","``","a","''",":","1",",","``","b","''",":","3","}",",","{","``","c","''",":","5","}","]","]","There","are","2","x","2","=","4","sets","of","parameters",",","i.e.",",","4","sets","of","``","estimator_params","``",",","each","of","which","includes","two","dictionaries","which","correspond","to","the","two","stages","of","models",".","Parameters","--","--","--","--","--","estimator_params_list",":","`","list","`","[","`","dict","`","[","`","str","`",",","any","]","]","The","estimator","parameter","list","in","hyperparameter","grids",".","Returns","--","--","--","-","flattened_estimator_params",":","`","list","`","[","`","list","`","[","`","dict","`","[","`","str","`",",","any","]","]","]","The","flattened","list","of","lists","of","estimator","parameter","dictionaries","."]
code: def __flatten_estimator_params_list(
      estimator_params_list: List[Dict[str, any]]
  ):
      """Flattens the ``estimator_params_list``.
  
      The ``estimator_params_list`` is from ``self.__get_estimators_and_params_from_template_configs``,
      and may contain nested grids within each parameter.
      This function flattens it into the format of list of lists of ``estimator_params``.
  
      For example, the original ``estimator_params_list`` is
  
          [{"a": [1], "b": [2, 3]}, {"c": [4, 5]}]
  
      It consists of 2 stages of models. Each stage of model's parameters are in a dictionary.
      The parameter values are in lists and could have multiple possible values.
  
      After flattening the ``estimator_params_list``, it becomes
  
          [[{"a": 1, "b": 2}, {"c": 4}], [{"a": 1, "b": 3}, {"c": 4}],
           [{"a": 1, "b": 2}, {"c": 5}], [{"a": 1, "b": 3}, {"c": 5}]]
  
      There are 2 x 2 = 4 sets of parameters, i.e., 4 sets of ``estimator_params``,
      each of which includes two dictionaries which correspond to the two stages of models.
  
      Parameters
      ----------
      estimator_params_list : `list` [`dict` [`str`, any]]
          The estimator parameter list in hyperparameter grids.
  
      Returns
      -------
      flattened_estimator_params : `list` [`list` [`dict` [`str`, any]]]
          The flattened list of lists of estimator parameter dictionaries.
      """
      # Although Python 3.7 keeps the order in dictionary from insertion,
      # to be more compatible, we use lists to ensure the keys and values are matched.
      # For example, we have
      # [{"a": [1], "b": [2, 3]}, {"c": [4, 5]}]
      keys = []
      params = []
      for index, dictionary in enumerate(estimator_params_list):
          keys.append([])
          params.append([])
          for key, value in dictionary.items():
              # ``time_properties`` are automatically inferred from the other parameters.
              if (
                  "estimator__" in key
                  and key != "estimator__time_properties"
              ):
                  keys[index].append(key.split("__")[1])
                  params[index].append(value)
      # Here we get a list of flattened values.
      # [((1, 2), (4)), ((1, 3), (4)), ((1, 2), (5)), ((1, 3), (5))]
      # The inner product gets all cross products for the value combinations within a stage.
      # The outer product gets all cross products for the value combinations across stages.
      flattened_params = list(
          product(*[list(product(*param)) for param in params])
      )
      # Then we map the flattened parameters with their keys and flatten them.
      # [[{"a": 1, "b": 2}, {"c": 4}], [{"a": 1, "b": 3}, {"c": 4}],
      #  [{"a": 1, "b": 2}, {"c": 5}], [{"a": 1, "b": 3}, {"c": 5}]]
      flattened_dictionaries = [
          [
              {key: value for (key, value) in zip(subkeys, subvalues)}
              for subkeys, subvalues in zip(keys, single_value)
          ]
          for single_value in flattened_params
      ]
      return flattened_dictionaries
  
imports: from itertools import product
  from typing import Dict
  from typing import List
  from typing import Type
  import pandas
  from greykite.common import constants
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.python_utils import unique_in_list
  from greykite.common.python_utils import update_dictionaries
  from greykite.framework.templates.autogen.forecast_config import ForecastConfig
  from greykite.framework.templates.autogen.forecast_config import MetadataParam
  from greykite.framework.templates.base_template import BaseTemplate
  from greykite.framework.templates.multistage_forecast_template_config import MultistageForecastTemplateConfig
  from greykite.framework.templates.multistage_forecast_template_config import MultistageForecastTemplateConstants
  from greykite.sklearn.estimator.base_forecast_estimator import BaseForecastEstimator
  from greykite.sklearn.estimator.multistage_forecast_estimator import MultistageForecastEstimator
  from greykite.sklearn.estimator.multistage_forecast_estimator import MultistageForecastModelConfig
label_desc: Use image node_id 9 for calling the MultistageForecastTemplate obj's underlying member method code with example usage: obj.__flatten_estimator_params_list(estimator_params_list) and returns: flattened_dictionaries