code: def _optimize(
      study: "optuna.Study",
      func: "optuna.study.study.ObjectiveFuncType",
      n_trials: Optional[int] = None,
      timeout: Optional[float] = None,
      n_jobs: int = 1,
      catch: Tuple[Type[Exception], ...] = (),
      callbacks: Optional[
          List[Callable[["optuna.Study", FrozenTrial], None]]
      ] = None,
      gc_after_trial: bool = False,
      show_progress_bar: bool = False,
  ) -> None:
      if not isinstance(catch, tuple):
          raise TypeError(
              "The catch argument is of type '{}' but must be a tuple.".format(
                  type(catch).__name__
              )
          )
  
      if study._thread_local.in_optimize_loop:
          raise RuntimeError(
              "Nested invocation of `Study.optimize` method isn't allowed."
          )
  
      if (
          show_progress_bar
          and n_trials is None
          and timeout is not None
          and n_jobs != 1
      ):
          warnings.warn(
              "The timeout-based progress bar is not supported with n_jobs != 1."
          )
          show_progress_bar = False
  
      progress_bar = pbar_module._ProgressBar(
          show_progress_bar, n_trials, timeout
      )
  
      study._stop_flag = False
  
      try:
          if n_jobs == 1:
              _optimize_sequential(
                  study,
                  func,
                  n_trials,
                  timeout,
                  catch,
                  callbacks,
                  gc_after_trial,
                  reseed_sampler_rng=False,
                  time_start=None,
                  progress_bar=progress_bar,
              )
          else:
              if n_jobs == -1:
                  n_jobs = os.cpu_count() or 1
  
              time_start = datetime.datetime.now()
              futures: Set[Future] = set()
  
              with ThreadPoolExecutor(max_workers=n_jobs) as executor:
                  for n_submitted_trials in itertools.count():
                      if study._stop_flag:
                          break
  
                      if (
                          timeout is not None
                          and (
                              datetime.datetime.now() - time_start
                          ).total_seconds()
                          > timeout
                      ):
                          break
  
                      if (
                          n_trials is not None
                          and n_submitted_trials >= n_trials
                      ):
                          break
  
                      if len(futures) >= n_jobs:
                          completed, futures = wait(
                              futures, return_when=FIRST_COMPLETED
                          )
                          # Raise if exception occurred in executing the completed futures.
                          for f in completed:
                              f.result()
  
                      futures.add(
                          executor.submit(
                              _optimize_sequential,
                              study,
                              func,
                              1,
                              timeout,
                              catch,
                              callbacks,
                              gc_after_trial,
                              True,
                              time_start,
                              progress_bar,
                          )
                      )
      finally:
          study._thread_local.in_optimize_loop = False
          progress_bar.close()
  
imports: from concurrent.futures import FIRST_COMPLETED
  from concurrent.futures import Future
  from concurrent.futures import ThreadPoolExecutor
  from concurrent.futures import wait
  import datetime
  import gc
  import itertools
  import os
  import sys
  from typing import Any
  from typing import Callable
  from typing import List
  from typing import Optional
  from typing import Sequence
  from typing import Set
  from typing import Tuple
  from typing import Type
  from typing import Union
  import warnings
  import optuna
  from optuna import exceptions
  from optuna import logging
  from optuna import progress_bar
  from optuna import trial
  from optuna.storages._heartbeat import get_heartbeat_thread
  from optuna.storages._heartbeat import is_heartbeat_enabled
  from optuna.study._tell import _tell_with_warning
  from optuna.study._tell import STUDY_TELL_WARNING_KEY
  from optuna.trial import FrozenTrial
  from optuna.trial import TrialState
label_desc: Use image node_id 1 for calling a global function with example usage: _optimize(study, func, n_trials, timeout, n_jobs, catch, callbacks, gc_after_trial, show_progress_bar) without return types