Uploaded image for project: 'Beam'
  1. Beam
  2. BEAM-1251 Python 3 Support
  3. BEAM-6395

Opcounters sampling test fails for some random seeds on Python3

    XMLWordPrintableJSON

    Details

    • Type: Sub-task
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Not applicable
    • Component/s: sdk-py-core
    • Labels:
      None

      Description

      test_should_sample (apache_beam.runners.worker.opcounters_test.OperationCountersTest) fails on Python 3 for the specified random seed (1717), but succeeds for other random seeds (eg. 1718).

      It is not clear if this test fails due to Python 3, or because it is not stable for all random seeds.

      According to the random.seed docs, reproducing random sequences from older versions of Python should be possible by providing a 'version' argument. However, both with and without this argument, the results differ between python 2 and python 3.

      Using the following test:

      import random
      random.seed(1717)
      results = []
      for i in range(10):
          results.append(round(random.random(), 2))
          results.append(random.randint(1, 50))
      print(results)
      

      The obtained results are:
      Python 2:
      [0.78, 12, 0.94, 6, 0.54, 31, 0.53, 28, 0.44, 33, 0.36, 45, 0.47, 22, 0.71, 40, 0.45, 35, 0.0, 1] 
      Python 3:
      [0.78, 15, 0.94, 14, 0.12, 35, 0.22, 10, 0.53, 36, 0.45, 42, 0.65, 12, 0.9, 31, 0.78, 2, 0.71, 50]
      Python 3 with version=1: 
      [0.78, 15, 0.94, 14, 0.12, 35, 0.22, 10, 0.53, 36, 0.45, 42, 0.65, 12, 0.9, 31, 0.78, 2, 0.71, 50]

      The Python 3 result does not change due to the 'version' argument, since according to the docs, it only has effect on str or bytes type seeds.

       

      Relevant test output:

      ======================================================================
       FAIL: test_should_sample (apache_beam.runners.worker.opcounters_test.OperationCountersTest)
       ----------------------------------------------------------------------
       Traceback (most recent call last):
       File "/home/robbe/workspace/beam/sdks/python/apache_beam/runners/worker/opcounters_test.py", line 207, in test_should_sample
       buckets[i] / (10.0 * total_runs / i)))
       AssertionError: False is not true : i=256, buckets[i]=167, expected=117, ratio=1.425067

       

        Attachments

          Activity

            People

            • Assignee:
              RobbeSneyders Robbe
              Reporter:
              RobbeSneyders Robbe
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: