code: def test_get_weight_matrix():
      """Tests get_weight_matrix"""
      # weights is None
      wmat = get_weight_matrix(
          weights=None,
          n_forecasts=3,
          name="weight_bias",
          default_weights={},
      )
      assert_equal(np.eye(3), wmat)
  
      # weights is string
      default_weights = {
          "identity": np.ones((3, 3)),
          "custom": np.random.rand(3, 3),
      }
      wmat = get_weight_matrix(
          weights="custom",
          n_forecasts=3,
          name="weight_bias",
          default_weights=default_weights,
      )
      target_norm = math.sqrt(3)
      expected_wmat = (
          default_weights["custom"]
          * target_norm
          / np.linalg.norm(default_weights["custom"])
      )
      assert_equal(expected_wmat, wmat)
  
      # weights is a list
      wmat = get_weight_matrix(
          weights=[1, 2, 3],
          n_forecasts=3,
          name="weight_bias",
          default_weights={},
      )
      expected_wmat = (
          np.diag([1, 2, 3])
          * target_norm
          / np.linalg.norm(np.diag([1, 2, 3]))
      )
      assert_equal(expected_wmat, wmat)
  
      # weights is an array
      wmat = get_weight_matrix(
          weights=np.array([1, 2, 3]),
          n_forecasts=3,
          name="weight_bias",
          default_weights={},
      )
      assert_equal(expected_wmat, wmat)
  
      # exception
      with pytest.raises(
          ValueError,
          match="Expected square matrix with size 10, but `weight_bias` "
          "has weight matrix with shape \\(3, 3\\)",
      ):
          get_weight_matrix(
              weights=np.array([1, 2, 3]),
              n_forecasts=10,  # doesn't match len(weights)
              name="weight_bias",
              default_weights={},
          )
  
      # weights is string, no default
      with pytest.raises(
          ValueError,
          match="The requested weight 'dummy' for `weight_bias` is not found. "
          "Must be one of \['custom'\]",
      ):  # noqa: W605
          wmat = get_weight_matrix(
              weights="dummy",
              n_forecasts=3,
              name="weight_bias",
              default_weights={"custom": np.ones((3, 3))},
          )
          assert_equal(np.eye(3), wmat)
  
imports: import math
  import os
  import warnings
  import cvxpy
  import numpy
  import pandas
  import pytest
  from scipy.linalg import sqrtm
  from sklearn.exceptions import NotFittedError
  from greykite.algo.reconcile.convex.reconcile_forecasts import ReconcileAdditiveForecasts
  from greykite.algo.reconcile.convex.reconcile_forecasts import TraceInfo
  from greykite.algo.reconcile.convex.reconcile_forecasts import apply_method_defaults
  from greykite.algo.reconcile.convex.reconcile_forecasts import evaluation_plot
  from greykite.algo.reconcile.convex.reconcile_forecasts import get_fit_params
  from greykite.algo.reconcile.convex.reconcile_forecasts import get_weight_matrix
  from greykite.algo.reconcile.hierarchical_relationship import HierarchicalRelationship
  from greykite.common.constants import TIME_COL
  from greykite.common.data_loader import DataLoader
  from greykite.common.evaluation import mean_absolute_percent_error
  from greykite.common.evaluation import median_absolute_percent_error
  from greykite.common.evaluation import root_mean_squared_error
  from greykite.common.python_utils import assert_equal
  from greykite.common.python_utils import reorder_columns
label_desc: Use image node_id 2 for calling a global function with example usage: test_get_weight_matrix() without return types