code: def test_with_tf_data_api(synthetic_dataset):
      """Verify that WeightedSamplingReader is compatible with make_petastorm_dataset"""
  
      np.random.seed(42)
  
      fields_to_read = ["id.*", "image_png"]
  
      # Use cur_shard=0, shard_count=2 to get only half samples from the second reader.
      readers = [
          make_reader(
              synthetic_dataset.url,
              schema_fields=fields_to_read,
              workers_count=1,
          ),
          make_reader(
              synthetic_dataset.url,
              schema_fields=fields_to_read,
              workers_count=1,
              cur_shard=0,
              shard_count=2,
          ),
      ]
  
      with WeightedSamplingReader(readers, [0.5, 0.5]) as mixer:
          dataset = make_petastorm_dataset(mixer)
          iterator = dataset.make_one_shot_iterator()
          tensor = iterator.get_next()
          rows_count = 0
          with tf.Session() as sess:
              while True:
                  try:
                      sess.run(tensor)
                      rows_count += 1
                  except tf.errors.OutOfRangeError:
                      break
  
          # We expect iterations to finish once the second read has exhausted its samples. For each sample in the
          # second reaader we read approximately 1 sample from the first.
          expected_rows_approx = len(synthetic_dataset.data)
          np.testing.assert_allclose(
              rows_count, expected_rows_approx, atol=20
          )
  
imports: from __future__ import division
  import numpy
  import pytest
  import six
  import tensorflow.compat.v1
  from petastorm import make_reader
  from petastorm.ngram import NGram
  from petastorm.predicates import in_lambda
  from petastorm.pytorch import DataLoader
  from petastorm.test_util.reader_mock import ReaderMock
  from petastorm.tf_utils import tf_tensors, make_petastorm_dataset
  from petastorm.unischema import Unischema, UnischemaField
  from petastorm.weighted_sampling_reader import WeightedSamplingReader
  from petastorm.tests.test_tf_utils import create_tf_graph
label_desc: Use image node_id 11 for calling a global function with example usage: test_with_tf_data_api(synthetic_dataset) without return types