code: def test_ratios_strategy(self):
      dataloaders = self._build_dataloaders()
      sampling_ratios = {}
  
      # Constant
      for idx in range(self.NUM_DATALOADERS):
          sampling_ratios[f"numbers_{idx}"] = 0
      sampling_ratios["numbers_0"] = 1
      strategy = (
          iteration_strategies.RatiosIterationStrategy.from_params(
              dataloaders, sampling_ratios=sampling_ratios
          )
      )
  
      counter = Counter()
      count = 10000
      for _ in range(count):
          counter[strategy()] += 1
  
      self.assertEqual(counter[0], count)
      for idx in range(1, self.NUM_DATALOADERS):
          self.assertEqual(counter[idx], 0)
  
      for idx in range(self.NUM_DATALOADERS):
          sampling_ratios[f"numbers_{idx}"] = 1.0 / self.NUM_DATALOADERS
  
      strategy = (
          iteration_strategies.RatiosIterationStrategy.from_params(
              dataloaders, sampling_ratios=sampling_ratios
          )
      )
  
      count = 10000
      counter = Counter()
      for _ in range(count):
          counter[strategy()] += 1
  
      for idx in range(0, self.NUM_DATALOADERS):
          self.assertTrue(counter[idx] <= 2100)
          self.assertTrue(counter[idx] >= 1900)
  
      lens = sum(len(loader.dataset) for loader in dataloaders.values())
      for idx in range(self.NUM_DATALOADERS):
          sampling_ratios[f"numbers_{idx}"] = (
              len(dataloaders[f"numbers_{idx}"].dataset) / lens
          )
  
      strategy = (
          iteration_strategies.RatiosIterationStrategy.from_params(
              dataloaders, sampling_ratios=sampling_ratios
          )
      )
  
      count = 10000
      counter = Counter()
      for _ in range(count):
          counter[strategy()] += 1
  
      for idx in range(0, self.NUM_DATALOADERS):
          self.assertTrue(counter[idx] <= 10**idx)
          lower_limit = 10 ** (idx - 1)
          if idx == 0:
              lower_limit = 0
          self.assertTrue(counter[idx] >= lower_limit)
  
file_path: mmf/tests/datasets/test_iteration_strategies.py
imports: import unittest
  from collections import Counter
  import numpy
  import torch
  from mmf.datasets import iteration_strategies
  from tests.test_utils import NumbersDataset
label_desc: Use image node_id 7 for calling the TestIterationStrategies obj's underlying member method code with example usage: obj.test_ratios_strategy() without return types