code: def get_monitor_func(
      args, buffers, visualizer, window, title, progress_iter
  ):
      """
      Return closure that performs monitoring.
      """
  
      def monitor_func(
          idx, reward, total_reward, iter_time, finished=False
      ):
          def mean(vals):
              return torch.DoubleTensor(vals).mean().item()
  
          # flush buffers:
          if finished:
              for key, val in buffers.items():
                  buffers[key] = [
                      item for item in val if item is not None
                  ]
          if finished or (idx > 0 and idx % progress_iter == 0):
              logging.info(
                  "Sample %s; average reward = %2.5f, time %.3f (sec/iter) "
                  % (
                      idx,
                      mean(buffers["reward"]),
                      mean(buffers["iter_time"]),
                  )
              )
              if args.visualize:
                  window[0] = learning_curve(
                      visualizer,
                      torch.tensor(buffers["idx"], dtype=torch.long),
                      torch.DoubleTensor(buffers["cumulative_reward"]),
                      window=window[0],
                      title=title,
                  )
              for key in buffers.keys():
                  buffers[key] = [None] * progress_iter
  
          # fill buffers:
          if idx is not None:
              cur_idx = idx % progress_iter
              buffers["idx"][cur_idx] = idx
              buffers["reward"][cur_idx] = reward
              buffers["cumulative_reward"][cur_idx] = total_reward
              buffers["iter_time"][cur_idx] = iter_time
  
      return monitor_func
  
file_path: CrypTen/examples/bandits/launcher.py
imports: import argparse
  import logging
  import os
  import random
  import examples.util
  import torch
  import visdom
  from examples.multiprocess_launcher import MultiProcessLauncher
  from examples.util import NoopContextManager, process_mnist_files
  from torchvision.datasets.mnist import MNIST
label_desc: Use image node_id 6 for calling a global function with example usage: get_monitor_func(args, buffers, visualizer, window, title, progress_iter) and returns: monitor_func, torch