class_docstr: Tests for bluefog/torch/mpi_ops.py on one-sided communication.
docstr: Test that the window accumulate operation.
code: def test_win_accumulate_with_varied_tensor_elements(self):
      """Test that the window accumulate operation."""
      size = bf.size()
      rank = bf.rank()
      if size <= 1:
          fname = inspect.currentframe().f_code.co_name
          warnings.warn("Skip {} due to size 1".format(fname))
          return
      dtypes = [torch.FloatTensor, torch.DoubleTensor]
      if TEST_ON_GPU:
          dtypes += [torch.cuda.FloatTensor, torch.cuda.DoubleTensor]
  
      # By default, we use exponential two ring topology.
      outdegree = int(np.ceil(np.log2(size)))
      neighbor_ranks = [
          (rank - 2**i) % size for i in range(outdegree)
      ]  # in-neighbor
      avg_value = rank + np.sum(neighbor_ranks) / float(outdegree + 1)
  
      dims = [1, 2, 3]
      for dtype, dim in itertools.product(dtypes, dims):
          tensor = (
              torch.FloatTensor(*([DIM_SIZE] * dim)).fill_(1).mul_(rank)
          )
          base_tensor = (
              torch.arange(DIM_SIZE**dim, dtype=torch.float32)
              .view_as(tensor)
              .div(1000)
          )
          tensor = self.cast_and_place(tensor, dtype)
          base_tensor = self.cast_and_place(base_tensor, dtype)
          tensor = tensor + base_tensor
          window_name = "win_accumulate_{}_{}".format(dim, dtype)
          bf.win_create(tensor, window_name)
          bf.win_accumulate(tensor, window_name)
  
          bf.barrier()
          sync_result = bf.win_update(window_name)
          sync_base_tensor = base_tensor * (
              1 + outdegree / (outdegree + 1)
          )
  
          assert (
              list(sync_result.shape) == [DIM_SIZE] * dim
          ), "bf.win_update after win_accmulate produces wrong shape tensor."
          assert (
              (sync_result - sync_base_tensor).data - avg_value
          ).abs().max() < EPSILON, (
              "bf.win_update after win_accmulate produces wrong tensor value "
              + "[{}-{}]!={} at rank {}.".format(
                  (sync_result - sync_base_tensor).min(),
                  (sync_result - sync_base_tensor).max(),
                  avg_value,
                  rank,
              )
          )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import inspect
  import itertools
  import time
  import warnings
  import unittest
  from bluefog.common import topology_util
  import bluefog.torch
  import torch
  import numpy
label_desc: Use image node_id 16 for calling the WinOpsTests obj's underlying member method code with example usage: obj.test_win_accumulate_with_varied_tensor_elements() without return types