code: def get_weight_matrix(weights, n_forecasts, name, default_weights):
      """Returns a diagonal weight matrix with shape (``n_forecasts``, ``n_forecasts``)
      and Frobenius norm sqrt(`n_forecasts`).
  
      Parameters
      ----------
      weights : `list` [`float`] or `str` or None
          What weights to use.
  
              - If a list, returns a diagonal matrix with the list values on the diagonal.
                These values specify the weight for each timeseries.
                In ``ReconcileAdditiveForecasts``, weights are applied to the matrix
                whose rows are reordered to canonical form (transposed output of ``reorder_columns``)
              - If a string, determined by ``default_weights``.
              - If None, the identity matrix (equal weights).
  
          The specified weights are normalized in the output.
  
      n_forecasts : `int`
          The number of forecasts (shape of the output).
      name : `str`
          The name of the weight matrix.
      default_weights : `dict` [`str`, `numpy.array`]
          Default weights to use if ``weights`` is a string.
          Values should be square matrices with shape (``n_forecasts``, ``n_forecasts``).
  
      Returns
      -------
      weight_matrix : `numpy.array`
          Weights to apply to the errors.
          Diagonal matrix with shape (``n_forecasts``, ``n_forecasts``)
          and Frobenius norm sqrt(`n_forecasts`).
      """
      if weights is None:
          weight_matrix = np.eye(n_forecasts)
      elif isinstance(weights, str):
          if weights in default_weights:
              weight_matrix = default_weights[weights]
              logging.info(f"weight for {name} is {weight_matrix}")
          else:
              raise ValueError(
                  f"The requested weight '{weights}' for `{name}` is not found. "
                  f"Must be one of {list(default_weights.keys())}"
              )
      else:
          weight_matrix = np.diag(weights)
  
      if not isinstance(
          weight_matrix, np.ndarray
      ) or weight_matrix.shape != (n_forecasts, n_forecasts):
          raise ValueError(
              f"Expected square matrix with size {n_forecasts}, but `{name}` has "
              f"weight matrix with shape {weight_matrix.shape}"
          )
  
      target_norm = np.linalg.norm(np.eye(n_forecasts))
      weight_matrix = (
          weight_matrix * target_norm / np.linalg.norm(weight_matrix)
      )
  
      return weight_matrix
  
imports: import functools
  import logging
  import math
  import sys
  import warnings
  from dataclasses import dataclass
  from typing import Optional
  import cvxpy
  import numpy
  import pandas
  import plotly
  import plotly.express
  from plotly import graph_objects
  from plotly.subplots import make_subplots
  from scipy.linalg import sqrtm
  from sklearn.exceptions import NotFittedError
  from greykite.algo.reconcile.hierarchical_relationship import HierarchicalRelationship
  from greykite.common.python_utils import reorder_columns
label_desc: Use image node_id 1 for calling a global function with example usage: get_weight_matrix(weights, n_forecasts, name, default_weights) and returns: weight_matrix