code: def test_multi_learner_bmuf_correct_metrics_averaging(
      tmpdir, device_id, mb_source
  ):
      if platform.system() == "Linux":
          pytest.skip(
              "test only runs on Windows due to mpiexec -l option"
          )
  
      num_workers = 2
      # check whether trainer can be initialized or not
      bmuf = MultiLearnerTrainer()
      if not bmuf.trainer:
          pytest.skip("BMUF not available on this build")
  
      launch_args = []
      launch_args += ["--outputdir", str(tmpdir)]
      launch_args += ["--mb_source", mb_source]
      launch_args += ["--trainer_type", "multi"]
  
      ret_str = mpiexec_execute(
          __file__, ["-n", str(num_workers), "-l"], launch_args
      )
      print(ret_str)
      loss_perepoch_perworker = get_loss_perepoch_perworker(
          ret_str, num_workers
      )
  
      num_epochs_per_worker = list(
          map(len, loss_perepoch_perworker.values())
      )
  
      # assert that data exists
      assert len(num_epochs_per_worker) != 0
  
      # assert that number of epochs isn't zero for 1st worker.
      assert num_epochs_per_worker[0] != 0
  
      # assert all workers have same number of epochs
      assert min(num_epochs_per_worker) == max(num_epochs_per_worker)
  
      # assert all workers have same loss and metric values
      loss_per_worker = loss_perepoch_perworker.values()
      loss_per_worker_epochsort = []
      for epoch_losses in loss_per_worker:
          loss_per_worker_epochsort.append(
              [epoch_losses[i] for i in sorted(epoch_losses)]
          )
  
      assert all(
          [
              loss_per_worker_epochsort[0] == i
              for i in loss_per_worker_epochsort
          ]
      )
  
      # Do the same test with checkpoint and compare the results.
      launch_args += ["--checkpointdir", str(tmpdir.join("checkpoint"))]
  
      ret_str = mpiexec_execute(
          __file__, ["-n", str(num_workers), "-l"], launch_args
      )
      print(ret_str)
  
      loss_perepoch_perworker = get_loss_perepoch_perworker(
          ret_str, num_workers
      )
  
      num_epochs_per_worker = list(
          map(len, loss_perepoch_perworker.values())
      )
  
      # assert that data exists
      assert len(num_epochs_per_worker) != 0
  
      # assert that number of epochs isn't zero for 1st worker.
      assert num_epochs_per_worker[0] != 0
  
      # assert all workers have same number of epochs
      assert min(num_epochs_per_worker) == max(num_epochs_per_worker)
  
      # assert all workers have same loss and metric values
      loss_per_worker = loss_perepoch_perworker.values()
      multi_learner_loss_per_worker_epochsort = []
      for epoch_losses in loss_per_worker:
          multi_learner_loss_per_worker_epochsort.append(
              [epoch_losses[i] for i in sorted(epoch_losses)]
          )
  
      # Compare no checkpoint loss, matric, and num samples, to checkpoint loss values.
      for i in multi_learner_loss_per_worker_epochsort:
          for n in range(3):
              for m in range(3):
                  assert np.allclose(
                      float(loss_per_worker_epochsort[0][n][m]),
                      float(i[n][m]),
                  )
  
imports: import pytest
  import cntk
  import numpy
  import sys, os
  import argparse
  import re
  import platform
  from distributed_learner_test import mpiexec_execute
  from bmuf_metrics_aggregation_test import get_minibatch
label_desc: Use image node_id 4 for calling a global function with example usage: test_multi_learner_bmuf_correct_metrics_averaging(tmpdir, device_id, mb_source) without return types