class_docstr: Implementation that contains the main Bayesian optimization loop.
  
  Parameters
  ----------
  scenario : Scenario
      The scenario object, holding all environmental information.
  runner : AbstractRunner
      The runner (containing the target function) is called internally to judge a trial's performance.
  runhistory : Runhistory
      The runhistory stores all trials.
  intensifier : AbstractIntensifier
      The intensifier decides which trial (combination of configuration, seed, budget and instance) should be run
      next.
  overwrite: bool, defaults to False
      When True, overwrites the run results if a previous run is found that is
      inconsistent in the meta data with the current setup. If ``overwrite`` is set to False, the user is asked
      for the exact behaviour (overwrite completely, save old run, or use old results).
  
  Warning
  -------
  This model should be initialized by a facade only.
class_docstr_tok: ["Implementation","that","contains","the","main","Bayesian","optimization","loop",".","Parameters","--","--","--","--","--","scenario",":","Scenario","The","scenario","object",",","holding","all","environmental","information",".","runner",":","AbstractRunner","The","runner","(","containing","the","target","function",")","is","called","internally","to","judge","a","trial","'s","performance",".","runhistory",":","Runhistory","The","runhistory","stores","all","trials",".","intensifier",":","AbstractIntensifier","The","intensifier","decides","which","trial","(","combination","of","configuration",",","seed",",","budget","and","instance",")","should","be","run","next",".","overwrite",":","bool",",","defaults","to","False","When","True",",","overwrites","the","run","results","if","a","previous","run","is","found","that","is","inconsistent","in","the","meta","data","with","the","current","setup",".","If","``","overwrite","``","is","set","to","False",",","the","user","is","asked","for","the","exact","behaviour","(","overwrite","completely",",","save","old","run",",","or","use","old","results",")",".","Warning","--","--","--","-","This","model","should","be","initialized","by","a","facade","only","."]
docstr: Detects whether the optimization is restored from a previous state.
code: def _initialize_state(self) -> None:
      """Detects whether the optimization is restored from a previous state."""
      # Here we actually check whether the run should be continued or not.
      # More precisely, we update our smbo/runhistory/intensifier object if all component arguments
      # and scenario object are the same. For doing so, we create a specific hash.
      # The SMBO object recognizes that stats (based on runhistory) is not empty and hence does not the run initial
      # design anymore.
      # Since the runhistory is already updated, the model uses previous data directly.
  
      if not self._overwrite:
          old_output_directory = self._scenario.output_directory
          if self.exists(old_output_directory):
              old_scenario = Scenario.load(old_output_directory)
  
              if self._scenario == old_scenario:
                  logger.info("Continuing from previous run.")
  
                  # First we reset everything and then we load the old states
                  self.reset()
                  self.load()
  
                  # If the last run was not successful, we reset everything again
                  if (
                      self._runhistory.submitted <= 1
                      and self._runhistory.finished == 0
                  ):
                      logger.info(
                          "Since the previous run was not successful, SMAC will start from scratch again."
                      )
                      self.reset()
              else:
                  # Here, we run into different scenarios
                  diff = recursively_compare_dicts(
                      Scenario.make_serializable(self._scenario),
                      Scenario.make_serializable(old_scenario),
                      level="scenario",
                  )
                  logger.info(
                      f"Found old run in `{self._scenario.output_directory}` but it is not the same as the current "
                      f"one:\n{diff}"
                  )
  
                  feedback = input(
                      "\nPress one of the following numbers to continue or any other key to abort:\n"
                      "(1) Overwrite old run completely and start a new run.\n"
                      "(2) Rename the old run (append an '-old') and start a new run.\n"
                  )
  
                  if feedback == "1":
                      # We don't have to do anything here, since we work with a clean runhistory and stats object
                      pass
                  elif feedback == "2":
                      # Rename old run
                      new_dir = str(
                          old_scenario.output_directory.parent
                      )
                      while True:
                          new_dir += "-old"
                          try:
                              old_scenario.output_directory.parent.rename(
                                  new_dir
                              )
                              break
                          except OSError:
                              pass
                  else:
                      raise RuntimeError(
                          "SMAC run was stopped by the user."
                      )
  
      # And now we save everything
      self._scenario.save()
      self.save()
  
imports: from __future__ import annotations
  from typing import Any
  import json
  import time
  from pathlib import Path
  import numpy
  from ConfigSpace import Configuration
  from numpy import ndarray
  from smac.acquisition.function.abstract_acquisition_function import AbstractAcquisitionFunction
  from smac.callback.callback import Callback
  from smac.intensifier.abstract_intensifier import AbstractIntensifier
  from smac.model.abstract_model import AbstractModel
  from smac.runhistory import StatusType, TrialInfo, TrialValue
  from smac.runhistory.runhistory import RunHistory
  from smac.runner import FirstRunCrashedException
  from smac.runner.abstract_runner import AbstractRunner
  from smac.runner.dask_runner import DaskParallelRunner
  from smac.scenario import Scenario
  from smac.utils.data_structures import recursively_compare_dicts
  from smac.utils.logging import get_logger
label_desc: Use image node_id 21 for calling the SMBO obj's underlying member method code with example usage: obj._initialize_state() without return types