code: def test_learner_init_legacy():
      i = C.input_variable(shape=(1,), needs_gradient=True, name="a")
      w = parameter(shape=(1,))
  
      res = i * w
  
      # for backcompatibility test
      # this will be deprecated in future version
      learner = sgd(
          res.parameters,
          lr=learning_rate_schedule(0.1, UnitType.sample),
      )
      assert (
          learner._learning_rate_schedule.minibatch_size == 1
      )  # the deprecated per sample schedule should not use compatible mode
      assert learner.learning_rate() == 0.1
  
      # for backcompatibility test
      # this will be deprecated in future version
      # The UnitType will provide per minibatch instruction for the learner
      # this will be deprecated in future version
      learner = sgd(
          res.parameters,
          lr=learning_rate_schedule(0.1, UnitType.minibatch),
      )
      assert learner.is_compatible_mode() == False
      assert learner.learning_rate() == 0.1
      assert learner.minibatch_size == C.learners.IGNORE
      assert learner._learning_rate_schedule.minibatch_size == 0
  
      # for backcompatibility test, in reset learning rate, the learner won't receive the reference minibatch size from the schedule
      # user will need to specify the reference minibatch size explicitly
      # this will be deprecated in future version
      learner = sgd(res.parameters, lr=0.1)
      learner.reset_learning_rate(
          learning_rate_schedule([1, 2, 3], UnitType.minibatch)
      )
      assert learner.learning_rate() == 1.0
      learner.minibatch_size = (
          C.learners.IGNORE
      )  # reset to be per minibatch
      assert learner.minibatch_size == C.learners.IGNORE
      assert (
          learner._learning_rate_schedule.minibatch_size
          == C.learners.IGNORE
      )
      assert learner.is_compatible_mode() == True
  
      # for backcompatibility test
      # this will be deprecated in future version
      learner = sgd(
          res.parameters,
          lr=learning_rate_schedule(0.1, UnitType.sample),
          minibatch_size=C.learners.IGNORE,
      )
      assert learner.is_compatible_mode() == True
      assert learner.learning_rate() == 0.1
      assert (
          learner.minibatch_size == C.learners.IGNORE
      )  # the learner's reference minibatch size is still 0
  
      # this will be deprecated in future version: This is logical invalid combination but it was the only way to use mean gradient and set learning rate in the past.
      learner = sgd(
          res.parameters,
          lr=learning_rate_schedule(0.1, UnitType.sample),
          use_mean_gradient=True,
      )
      assert learner.is_compatible_mode() == True
      assert learner.learning_rate() == 0.1
      # test the override in the new version
      assert (
          learner._learning_rate_schedule.minibatch_size
          == C.learners.IGNORE
      )
      assert (
          learner.minibatch_size == C.learners.IGNORE
      )  # the learner's reference minibatch size is still 0
  
      # for backcompatibility test
      # this will be deprecated in future version
      # The UnitType will provide per minibatch instruction for the learner
      # this will be deprecated in future version
      learner = sgd(
          res.parameters,
          lr=learning_rate_schedule(0.1, UnitType.minibatch),
          minibatch_size=C.learners.IGNORE,
      )
      assert learner.is_compatible_mode() == True
      assert learner.learning_rate() == 0.1
      assert learner.minibatch_size == C.learners.IGNORE
      assert (
          learner._learning_rate_schedule.minibatch_size
          == C.learners.IGNORE
      )
  
      # for backcompatibility test, in reset learning rate, the learner won't receive the reference minibatch size from the schedule
      # user will need to specify the reference minibatch size explicitly
      # this will be deprecated in future version
      learner = sgd(res.parameters, lr=0.1)
      learner.reset_learning_rate(
          learning_rate_schedule([1, 2, 3], UnitType.minibatch)
      )
      assert learner.learning_rate() == 1.0
      learner.minibatch_size = (
          C.learners.IGNORE
      )  # reset to be per minibatch
      assert learner.minibatch_size == C.learners.IGNORE
      assert (
          learner._learning_rate_schedule.minibatch_size
          == C.learners.IGNORE
      )
      assert learner.is_compatible_mode() == True
  
      learner_parameter = learner.parameters
      from cntk.variables import Parameter
  
      param = learner_parameter[0]
      assert isinstance(param, Parameter)
  
      unit_gain_value = C.default_unit_gain_value()
      assert unit_gain_value
  
      # back compatible API test
      momentum_time_constant = C.momentum_as_time_constant_schedule(
          1100
      )
      lr_per_sample = learning_parameter_schedule(0.1, minibatch_size=1)
      C.momentum_sgd(
          res.parameters, lr_per_sample, momentum_time_constant
      )
      C.momentum_sgd(
          res.parameters,
          lr_per_sample,
          momentum_time_constant,
          unit_gain_value,
      )
      C.momentum_sgd(
          res.parameters,
          lr_per_sample,
          momentum_time_constant,
          unit_gain=unit_gain_value,
      )
  
      C.set_default_unit_gain_value(False)
      unit_gain_value = C.default_unit_gain_value()
      assert not unit_gain_value
  
      C.set_default_unit_gain_value(True)
      unit_gain_value = C.default_unit_gain_value()
      assert unit_gain_value
  
      lr_per_sample = learning_rate_schedule(
          [(3, 0.1), (2, 0.2), (1, 0.3)], unit=UnitType.sample
      )
      C.fsadagrad(
          res.parameters,
          lr=lr_per_sample,
          momentum=momentum_time_constant,
      )
      C.fsadagrad(
          res.parameters,
          lr_per_sample,
          momentum_time_constant,
          unit_gain_value,
      )
      C.fsadagrad(
          res.parameters,
          lr=lr_per_sample,
          momentum=momentum_time_constant,
          unit_gain=unit_gain_value,
      )
  
      gamma, inc, dec, max, min = [0.5, 1.2, 0.7, 10, 1e-8]
      lr_per_sample = learning_rate_schedule(
          [0.1, 0.2], unit=UnitType.sample, epoch_size=100
      )
      C.rmsprop(
          res.parameters, lr_per_sample, gamma, inc, dec, max, min, True
      )
  
      C.adadelta(res.parameters, lr_per_sample, use_mean_gradient=True)
  
imports: from __future__ import division, print_function
  import numpy
  import cntk
  from cntk import parameter
  import pytest
  import sys
  import itertools
  from cntk.logging import ProgressPrinter
  from cntk.learners import sgd, learning_rate_schedule, learning_parameter_schedule, UnitType, universal
  from cntk.layers import Dense, Sequential
label_desc: Use image node_id 6 for calling a global function with example usage: test_learner_init_legacy() without return types