docstr: This is the forecast function which can be used to forecast.
  This function's predictions are constructed using simulations
  from the fitted series. This supports both ``predict_silverkite_via_sim``
  and ````predict_silverkite_via_sim_fast`` depending on value of the
  passed argument ``fast_simulation``.
  
  The ``past_df`` is set to be the training data which is available
  in ``trained_model``.
  It accepts extra regressors (``extra_pred_cols``) originally in
  ``df`` via ``new_external_regressor_df``.
  
  Parameters
  ----------
  fut_time_num : `int`
      number of needed future values
  trained_model : `dict`
      A fitted silverkite model which is the output of ``self.forecast``
  freq : `str`
      Frequency of future predictions.
      Accepts any valid frequency for ``pd.date_range``.
  new_external_regressor_df : `pandas.DataFrame` or None
      Contains the extra regressors if specified.
  simulation_num : `int`, optional, default 10
      The number of simulated series to be used in prediction.
  fast_simulation: `bool`, default False
      Deterimes if fast simulations are to be used. This only impacts models
      which include auto-regression. This method will only generate one simulation
      without any error being added and then add the error using the volatility
      model. The advantage is a major boost in speed during inference and the
      disadvantage is potentially less accurate prediction intervals.
  include_err : `bool`, optional, default None
      Boolean to determine if errors are to be incorporated in the simulations.
      If None, it will be set to True if uncertainty is passed to the model and
      otherwise will be set to False
  
  Returns
  -------
  result: `dict`
      A dictionary with following items
  
      - "fut_df": `pandas.DataFrame`
          The same as input dataframe with an added column for the response.
          If value_col already appears in ``fut_df``, it will be over-written.
          If ``uncertainty_dict`` is provided as input,
          it will also contain a ``QUANTILE_SUMMARY_COL`` column.
          Here are the expected columns:
  
          (1) A time column with the column name being ``trained_model["time_col"]``
          (2) The predicted response in ``value_col`` column.
          (3) Quantile summary response in ``QUANTILE_SUMMARY_COL`` column.
              This column only appears if the model includes uncertainty.
          (4) Error std in `ERR_STD_COL` column.
              This column only appears if the model includes uncertainty.
  
      - "x_mat": `pandas.DataFrame`
          Design matrix of the predictive machine-learning model
code: def predict_n_via_sim(
      self,
      fut_time_num,
      trained_model,
      freq,
      new_external_regressor_df=None,
      simulation_num=10,
      fast_simulation=False,
      include_err=None,
  ):
      """This is the forecast function which can be used to forecast.
      This function's predictions are constructed using simulations
      from the fitted series. This supports both ``predict_silverkite_via_sim``
      and ````predict_silverkite_via_sim_fast`` depending on value of the
      passed argument ``fast_simulation``.
  
      The ``past_df`` is set to be the training data which is available
      in ``trained_model``.
      It accepts extra regressors (``extra_pred_cols``) originally in
      ``df`` via ``new_external_regressor_df``.
  
      Parameters
      ----------
      fut_time_num : `int`
          number of needed future values
      trained_model : `dict`
          A fitted silverkite model which is the output of ``self.forecast``
      freq : `str`
          Frequency of future predictions.
          Accepts any valid frequency for ``pd.date_range``.
      new_external_regressor_df : `pandas.DataFrame` or None
          Contains the extra regressors if specified.
      simulation_num : `int`, optional, default 10
          The number of simulated series to be used in prediction.
      fast_simulation: `bool`, default False
          Deterimes if fast simulations are to be used. This only impacts models
          which include auto-regression. This method will only generate one simulation
          without any error being added and then add the error using the volatility
          model. The advantage is a major boost in speed during inference and the
          disadvantage is potentially less accurate prediction intervals.
      include_err : `bool`, optional, default None
          Boolean to determine if errors are to be incorporated in the simulations.
          If None, it will be set to True if uncertainty is passed to the model and
          otherwise will be set to False
  
      Returns
      -------
      result: `dict`
          A dictionary with following items
  
          - "fut_df": `pandas.DataFrame`
              The same as input dataframe with an added column for the response.
              If value_col already appears in ``fut_df``, it will be over-written.
              If ``uncertainty_dict`` is provided as input,
              it will also contain a ``QUANTILE_SUMMARY_COL`` column.
              Here are the expected columns:
  
              (1) A time column with the column name being ``trained_model["time_col"]``
              (2) The predicted response in ``value_col`` column.
              (3) Quantile summary response in ``QUANTILE_SUMMARY_COL`` column.
                  This column only appears if the model includes uncertainty.
              (4) Error std in `ERR_STD_COL` column.
                  This column only appears if the model includes uncertainty.
  
          - "x_mat": `pandas.DataFrame`
              Design matrix of the predictive machine-learning model
  
      """
      if include_err is None:
          include_err = trained_model["uncertainty_dict"] is not None
  
      if trained_model["uncertainty_dict"] is None and include_err:
          raise ValueError(
              "`include_err=True` was passed. "
              "However model does not support uncertainty. "
              "To support uncertainty pass `uncertainty_dict` to the model."
          )
  
      time_col = trained_model["time_col"]
      value_col = trained_model["value_col"]
      # creates the future time grid
      dates = pd.date_range(
          start=trained_model["last_date_for_fit"],
          periods=fut_time_num + 1,
          freq=freq,
      )
      dates = dates[
          dates > trained_model["last_date_for_fit"]
      ]  # drops values up to last_date_for_fit
      fut_df = pd.DataFrame({time_col: dates.tolist()})
  
      past_df = trained_model["df"][[value_col]].reset_index(drop=True)
  
      if fast_simulation:
          return self.predict_via_sim_fast(
              fut_df=fut_df,
              trained_model=trained_model,
              past_df=past_df,  # observed data used for training the model
              new_external_regressor_df=new_external_regressor_df,
          )
  
      return self.predict_via_sim(
          fut_df=fut_df,
          trained_model=trained_model,
          past_df=past_df,  # observed data used for training the model
          new_external_regressor_df=new_external_regressor_df,
          simulation_num=simulation_num,
          include_err=include_err,
      )
  
imports: import re
  import warnings
  from typing import Type
  import numpy
  import pandas
  from pandas.plotting import register_matplotlib_converters
  from pandas.tseries.frequencies import to_offset
  from greykite.algo.changepoint.adalasso.changepoint_detector import get_changepoints_dict
  from greykite.algo.changepoint.adalasso.changepoint_detector import get_seasonality_changepoints
  from greykite.algo.changepoint.adalasso.changepoints_utils import build_seasonality_feature_df_from_detection_result
  from greykite.algo.changepoint.adalasso.changepoints_utils import get_seasonality_changepoint_df_cols
  from greykite.algo.common.ml_models import fit_ml_model_with_evaluation
  from greykite.algo.common.ml_models import predict_ml
  from greykite.algo.common.ml_models import predict_ml_with_uncertainty
  from greykite.algo.forecast.silverkite.constants.silverkite_constant import default_silverkite_constant
  from greykite.algo.forecast.silverkite.constants.silverkite_seasonality import SilverkiteSeasonalityEnum
  from greykite.algo.forecast.silverkite.constants.silverkite_seasonality import SilverkiteSeasonalityEnumMixin
  from greykite.algo.forecast.silverkite.forecast_silverkite_helper import get_fourier_feature_col_names
  from greykite.algo.forecast.silverkite.forecast_silverkite_helper import get_similar_lag
  from greykite.common.constants import CHANGEPOINT_COL_PREFIX
  from greykite.common.constants import ERR_STD_COL
  from greykite.common.constants import QUANTILE_SUMMARY_COL
  from greykite.common.constants import SEASONALITY_REGEX
  from greykite.common.constants import TimeFeaturesEnum
  from greykite.common.enums import TimeEnum
  from greykite.common.features.timeseries_features import add_daily_events
  from greykite.common.features.timeseries_features import add_time_features_df
  from greykite.common.features.timeseries_features import fourier_series_multi_fcn
  from greykite.common.features.timeseries_features import get_changepoint_dates_from_changepoints_dict
  from greykite.common.features.timeseries_features import get_changepoint_features
  from greykite.common.features.timeseries_features import get_changepoint_features_and_values_from_config
  from greykite.common.features.timeseries_features import get_default_origin_for_time_vars
  from greykite.common.features.timeseries_lags import build_autoreg_df
  from greykite.common.features.timeseries_lags import build_autoreg_df_multi
  from greykite.common.logging import LoggingLevelEnum
  from greykite.common.logging import log_message
  from greykite.common.python_utils import get_pattern_cols
  from greykite.common.python_utils import unique_elements_in_list
  from greykite.common.time_properties import describe_timeseries
  from greykite.common.time_properties import fill_missing_dates
  from greykite.common.time_properties import min_gap_in_seconds
  from greykite.common.time_properties_forecast import get_default_horizon_from_period
label_desc: Use image node_id 9 for calling the SilverkiteForecast obj's underlying member method code with example usage: obj.predict_n_via_sim(fut_time_num, trained_model, freq, new_external_regressor_df, simulation_num, fast_simulation, include_err) and returns: self, self