code: def test_sweep_based_schedule(tmpdir, device_id):
      from cntk.io import (
          MinibatchSource,
          CTFDeserializer,
          StreamDef,
          StreamDefs,
      )
      from cntk import (
          cross_entropy_with_softmax,
          classification_error,
          plus,
          reduce_sum,
          sequence,
      )
      from cntk import Trainer
  
      input_dim = 69
  
      ctf_data = """\
  0   |S0 3:1   |S1 3:1 |# <s>
  0   |S0 4:1 |# A    |S1 32:1 |# ~AH
  0   |S0 5:1 |# B    |S1 36:1 |# ~B
  0   |S0 4:1 |# A    |S1 31:1 |# ~AE
  0   |S0 7:1 |# D    |S1 38:1 |# ~D
  0   |S0 12:1 |# I   |S1 47:1 |# ~IY
  0   |S0 1:1 |# </s> |S1 1:1 |# </s>
  2   |S0 60:1 |# <s> |S1 3:1 |# <s>
  2   |S0 61:1 |# A   |S1 32:1 |# ~AH
  """
      ctf_file = str(tmpdir / "2seqtest.txt")
      with open(ctf_file, "w") as f:
          f.write(ctf_data)
  
      mbs = MinibatchSource(
          CTFDeserializer(
              ctf_file,
              StreamDefs(
                  features=StreamDef(
                      field="S0", shape=input_dim, is_sparse=True
                  ),
                  labels=StreamDef(
                      field="S1", shape=input_dim, is_sparse=True
                  ),
              ),
          ),
          randomize=False,
      )
  
      in1 = sequence.input_variable(shape=(input_dim,))
      labels = sequence.input_variable(shape=(input_dim,))
      p = parameter(shape=(input_dim,), init=10)
      z = plus(in1, reduce_sum(p), name="z")
      ce = cross_entropy_with_softmax(z, labels)
      errs = classification_error(z, labels)
  
      lr_per_sample = C.learning_parameter_schedule_per_sample(
          [0.3, 0.2, 0.1, 0.0]
      )
      learner = sgd(z.parameters, lr_per_sample)
      trainer = Trainer(z, (ce, errs), [learner])
  
      input_map = {
          in1: mbs.streams.features,
          labels: mbs.streams.labels,
      }
  
      # fetch minibatch (first sequence)
      data = mbs.next_minibatch(1, input_map=input_map)
      trainer.train_minibatch(data)
      assert learner.learning_rate() == 0.3
  
      # fetch minibatch (second sequence, sweep ends at this point)
      data = mbs.next_minibatch(1, input_map=input_map)
      trainer.train_minibatch(data)
      assert learner.learning_rate() == 0.2
  
      # fetch minibatch (both sequences -- entire sweep in one go)
      data = mbs.next_minibatch(9, input_map=input_map)
      trainer.train_minibatch(data)
      assert learner.learning_rate() == 0.1
  
      # fetch minibatch (multiple sweeps)
      data = mbs.next_minibatch(30, input_map=input_map)
      trainer.train_minibatch(data, outputs=[z.output])
      assert learner.learning_rate() == 0.0
  
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 13 for calling a global function with example usage: test_sweep_based_schedule(tmpdir, device_id) without return types