code: def objective(trial, comm):
      # Sample an architecture.
      model = L.Classifier(create_model(trial))
  
      # Setup optimizer.
      optimizer = chainer.optimizers.MomentumSGD()
      optimizer.setup(model)
      optimizer = chainermn.create_multi_node_optimizer(optimizer, comm)
  
      # Setup dataset and iterator. Only worker 0 loads the whole dataset.
      # The dataset of worker 0 is evenly split and distributed to all workers.
      if comm.rank == 0:
          train, valid = chainer.datasets.get_mnist()
          rng = np.random.RandomState(0)
          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)),
          )
      else:
          train, valid = None, None
  
      train = chainermn.scatter_dataset(train, comm, shuffle=True)
      valid = chainermn.scatter_dataset(valid, comm)
  
      train_iter = chainer.iterators.SerialIterator(
          train, BATCHSIZE, shuffle=True
      )
      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"),
          )
      )
      evaluator = chainer.training.extensions.Evaluator(
          valid_iter, model
      )
      trainer.extend(
          chainermn.create_multi_node_evaluator(evaluator, comm)
      )
      log_report_extension = chainer.training.extensions.LogReport(
          log_name=None
      )
      trainer.extend(log_report_extension)
  
      if comm.rank == 0:
          trainer.extend(chainer.training.extensions.ProgressBar())
  
      # 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)
  
      # Evaluate.
      evaluator = chainer.training.extensions.Evaluator(
          valid_iter, model
      )
      evaluator = chainermn.create_multi_node_evaluator(evaluator, comm)
      report = evaluator()
  
      return report["main/accuracy"]
  
file_path: chainer/examples/optuna/chainermn_integration.py
imports: import sys
  import chainer
  import chainer.functions
  import chainer.links
  import chainermn
  import numpy
  import optuna
label_desc: Use image node_id 2 for calling a global function with example usage: objective(trial, comm) and returns: report