def _process_historical_forecast_for_backtest(
    series: Union[TimeSeries, Sequence[TimeSeries]],
    historical_forecasts: Union[
        TimeSeries, Sequence[TimeSeries], Sequence[Sequence[TimeSeries]]
    ],
    last_points_only: bool,
):
    """Checks that the `historical_forecasts` have the correct format based on the input `series` and
    `last_points_only`. If all checks have passed, it converts `series` and `historical_forecasts` format into a
    multiple series case with `last_points_only=False`.
    """
    # remember input series type
    series_seq_type = get_series_seq_type(series)
    series = series2seq(series)

    # check that `historical_forecasts` have correct type
    expected_seq_type = None
    forecast_seq_type = get_series_seq_type(historical_forecasts)
    if last_points_only and not series_seq_type == forecast_seq_type:
        # lpo=True -> fc sequence type must be the same
        expected_seq_type = series_seq_type
    elif not last_points_only and forecast_seq_type != series_seq_type + 1:
        # lpo=False -> fc sequence type must be one order higher
        expected_seq_type = series_seq_type + 1

    if expected_seq_type is not None:
        raise_log(
            ValueError(
                f"Expected `historical_forecasts` of type {expected_seq_type} "
                f"with `last_points_only={last_points_only}` and `series` of type "
                f"{series_seq_type}. However, received `historical_forecasts` of type "
                f"{forecast_seq_type}. Make sure to pass the same `last_points_only` "
                f"value that was used to generate the historical forecasts."
            ),
            logger=logger,
        )

    # we must wrap each fc in a list if `last_points_only=True`
    nested = last_points_only and forecast_seq_type == SeriesType.SEQ
    historical_forecasts = series2seq(
        historical_forecasts, seq_type_out=SeriesType.SEQ_SEQ, nested=nested
    )

    # check that the number of series-specific forecasts corresponds to the
    # number of series in `series`
    if len(series) != len(historical_forecasts):
        error_msg = (
            f"Mismatch between the number of series-specific `historical_forecasts` "
            f"(n={len(historical_forecasts)}) and the number of  `TimeSeries` in `series` "
            f"(n={len(series)}). For `last_points_only={last_points_only}`, expected "
        )
        expected_seq_type = series_seq_type if last_points_only else series_seq_type + 1
        if expected_seq_type == SeriesType.SINGLE:
            error_msg += f"a single `historical_forecasts` of type {expected_seq_type}."
        else:
            error_msg += f"`historical_forecasts` of type {expected_seq_type} with length n={len(series)}."
        raise_log(
            ValueError(error_msg),
            logger=logger,
        )
    return series, historical_forecasts
Checks that the `historical_forecasts` have the correct format based on the input `series` and
    `last_points_only`. If all checks have passed, it converts `series` and `historical_forecasts` format into a
    multiple series case with `last_points_only=False`.
    
darts/utils/historical_forecasts/utils.py