code: def _expand_param_grid(grid: dict) -> typing.Iterator[dict]:
      def expand_tuple(t):
          klass, params = t
  
          if not isinstance(klass, type):
              raise ValueError(
                  f"Expected first element to be a class, got {klass}"
              )
  
          if not isinstance(params, dict):
              raise ValueError(
                  f"Expected second element to be a dict, got {params}"
              )
  
          return (
              klass(**combo) for combo in _expand_param_grid(params)
          )
  
      def expand(k, v):
          if isinstance(v, tuple):
              return ((k, el) for el in expand_tuple(v))
  
          # Example:
          # k = 'lr'
          # v = [0.001, 0.01, 0.1]
          if (
              isinstance(v, list)
              or isinstance(v, set)
              or isinstance(v, np.ndarray)
          ):
              combos = []
  
              for el in v:
                  if isinstance(el, tuple):
                      for combo in expand_tuple(el):
                          combos.append((k, combo))
                  else:
                      combos.append((k, el))
  
              return combos
  
          if isinstance(v, dict):
              # Example:
              # k = 'LinearRegression'
              # v = {
              #     'intercept_lr': [0.001],
              #     'l2': [1],
              #     'optimizer': {
              #         optim.Adam: {
              #             'beta_1': [0.1, 0.01, 0.001],
              #             'lr': [0.1, 0.01, 0.001]
              #         },
              #      }
              # }
              return ((k, el) for el in _expand_param_grid(v))
  
          raise ValueError(f"unsupported type: {type(v)}")
  
      for key in grid:
          if not isinstance(key, str):
              raise ValueError(f"Expected a key of type str; got {key}")
  
      # Example:
      # grid = {
      #     'beta_1': [0.1, 0.01, 0.001],
      #     'lr': [0.1, 0.01, 0.001]
      # }
      return (
          dict(el) if isinstance(el[0], tuple) else el[0]
          for el in itertools.product(
              *(expand(k, v) for k, v in grid.items())
          )
      )
  
imports: from __future__ import annotations
  import itertools
  import typing
  import numpy
  from river import base
label_desc: Use image node_id 2 for calling a global function with example usage: _expand_param_grid(grid) and returns: unknown, unknown, unknown, combos, unknown