code: def test_parallel_sample_iter():
      batch_size = 2
      buckets = data_io.define_parallel_buckets(100, 100, 10, True, 1.0)
      # The first bucket is going to be empty:
      bucket_counts = [0] + [None] * (len(buckets) - 1)
      bucket_batch_sizes = data_io.define_bucket_batch_sizes(
          buckets,
          batch_size,
          batch_type=C.BATCH_TYPE_SENTENCE,
          data_target_average_len=[None] * len(buckets),
      )
  
      dataset = data_io.ParallelDataSet(
          *_get_random_bucketed_data(
              buckets,
              min_count=0,
              max_count=5,
              bucket_counts=bucket_counts,
          )
      )
      it = data_io.ParallelSampleIter(
          dataset, buckets, batch_size, bucket_batch_sizes
      )
  
      with TemporaryDirectory() as work_dir:
          # Test 1
          it.next()
          expected_batch = it.next()
  
          fname = os.path.join(work_dir, "saved_iter")
          it.save_state(fname)
  
          it_loaded = data_io.ParallelSampleIter(
              dataset, buckets, batch_size, bucket_batch_sizes
          )
          it_loaded.reset()
          it_loaded.load_state(fname)
          loaded_batch = it_loaded.next()
          assert _data_batches_equal(expected_batch, loaded_batch)
  
          # Test 2
          it.reset()
          expected_batch = it.next()
          it.save_state(fname)
  
          it_loaded = data_io.ParallelSampleIter(
              dataset, buckets, batch_size, bucket_batch_sizes
          )
          it_loaded.reset()
          it_loaded.load_state(fname)
  
          loaded_batch = it_loaded.next()
          assert _data_batches_equal(expected_batch, loaded_batch)
  
          # Test 3
          it.reset()
          expected_batch = it.next()
          it.save_state(fname)
          it_loaded = data_io.ParallelSampleIter(
              dataset, buckets, batch_size, bucket_batch_sizes
          )
          it_loaded.reset()
          it_loaded.load_state(fname)
  
          loaded_batch = it_loaded.next()
          assert _data_batches_equal(expected_batch, loaded_batch)
  
          while it.iter_next():
              it.next()
              it_loaded.next()
          assert not it_loaded.iter_next()
  
imports: import os
  import random
  from tempfile import TemporaryDirectory
  from typing import Optional, List, Tuple
  import numpy
  import pytest
  import torch
  from sockeye import constants
  from sockeye import data_io
  from sockeye import utils
  from sockeye import vocab
  from sockeye.test_utils import tmp_digits_dataset
  from sockeye.utils import SockeyeError, get_tokens, seed_rngs
label_desc: Use image node_id 25 for calling a global function with example usage: test_parallel_sample_iter() without return types