code: def objective(trial):
      model = L.Classifier(create_model(trial))
      optimizer = chainer.optimizers.Adam()
      optimizer.setup(model)
  
      rng = np.random.RandomState(0)
      train, valid = chainer.datasets.get_mnist()
      train = chainer.datasets.SubDataset(
          train, 0, N_TRAIN_EXAMPLES, order=rng.permutation(len(train))
      )
      valid = chainer.datasets.SubDataset(
          valid, 0, N_VALID_EXAMPLES, order=rng.permutation(len(valid))
      )
      train_iter = chainer.iterators.SerialIterator(train, BATCHSIZE)
      valid_iter = chainer.iterators.SerialIterator(
          valid, BATCHSIZE, repeat=False, shuffle=False
      )
  
      # Setup trainer.
      updater = chainer.training.StandardUpdater(train_iter, optimizer)
      trainer = chainer.training.Trainer(updater, (EPOCH, "epoch"))
  
      # Add Chainer extension for pruners.
      trainer.extend(
          optuna.integration.ChainerPruningExtension(
              trial,
              "validation/main/accuracy",
              (PRUNER_INTERVAL, "epoch"),
          )
      )
  
      trainer.extend(
          chainer.training.extensions.Evaluator(valid_iter, model)
      )
      trainer.extend(
          chainer.training.extensions.PrintReport(
              [
                  "epoch",
                  "main/loss",
                  "validation/main/loss",
                  "main/accuracy",
                  "validation/main/accuracy",
              ]
          )
      )
      log_report_extension = chainer.training.extensions.LogReport(
          log_name=None
      )
      trainer.extend(log_report_extension)
  
      # Run training.
      # Please set show_loop_exception_msg False to inhibit messages about
      # TrialPruned exception. ChainerPruningExtension raises TrialPruned
      # exception to stop training, and trainer shows some messages every time
      # it receives TrialPruned.
      trainer.run(show_loop_exception_msg=False)
  
      # Save loss and accuracy to user attributes.
      log_last = log_report_extension.log[-1]
      for key, value in log_last.items():
          trial.set_user_attr(key, value)
  
      return log_report_extension.log[-1]["validation/main/accuracy"]
  
file_path: chainer/examples/optuna/chainer_integration.py
imports: import chainer
  import chainer.functions
  import chainer.links
  import numpy
  from packaging import version
  import optuna
label_desc: Use image node_id 2 for calling a global function with example usage: objective(trial) and returns: log_report_extension