code: def test_continue_when_walltime_stopped(rosenbrock, facade):
      class CustomCallbackWalltime(Callback):
          def __init__(self, limit: float):
              self._limit = limit
  
          def on_tell_end(
              self, smbo, info: TrialInfo, value: TrialValue
          ) -> bool | None:
              if smbo.used_walltime > self._limit:
                  return False
  
              return
  
      LIMIT = 1
      FINAL_LIMIT = 8
  
      # Same thing now but with walltime limit
      scenario = Scenario(
          rosenbrock.configspace,
          n_trials=99999,
          walltime_limit=FINAL_LIMIT,
          min_budget=1,
          max_budget=10,
      )
      smac = facade(
          scenario,
          rosenbrock.train,
          callbacks=[CustomCallbackWalltime(LIMIT)],
          overwrite=True,
      )
      smac.optimize()
      assert (
          smac._optimizer.used_walltime > LIMIT
          and smac._optimizer.used_walltime < FINAL_LIMIT
      )
  
      # Now we want to continue the run
      scenario = Scenario(
          rosenbrock.configspace,
          n_trials=99999,
          walltime_limit=FINAL_LIMIT,
          min_budget=1,
          max_budget=10,
      )
      smac2 = facade(scenario, rosenbrock.train, logging_level=0)
  
      # Let's see if we restored the runhistory correctly; used walltime should be roughly the same
      # However, since some more things happen in the background, it might be slightly different
      assert (
          pytest.approx(smac2._optimizer.used_walltime, 0.5)
          == smac._optimizer.used_walltime
      )
      assert smac2.runhistory.finished == smac.runhistory.finished
  
      smac2.optimize()
      assert smac2.runhistory.finished > smac.runhistory.finished
      assert smac2._optimizer.used_walltime > FINAL_LIMIT
  
file_path: SMAC3/tests/test_continue.py
imports: from __future__ import annotations
  import os
  import shutil
  from io import StringIO
  import pytest
  from smac import AlgorithmConfigurationFacade
  from smac import BlackBoxFacade
  from smac import HyperbandFacade
  from smac import HyperparameterOptimizationFacade
  from smac import MultiFidelityFacade
  from smac import RandomFacade
  from smac import Scenario
  from smac.callback.callback import Callback
  from smac.runhistory.dataclasses import TrialInfo, TrialValue
label_desc: Use image node_id 4 for calling a global function with example usage: test_continue_when_walltime_stopped(rosenbrock, facade) and returns: False