cctbx / cctbx_project

Computational Crystallography Toolbox
https://cci.lbl.gov/docs/cctbx
Other
214 stars 111 forks source link

smtbx/refinement/restraints/tests/tst_restraints.py broken on Python 3 #363

Open Anthchirp opened 5 years ago

Anthchirp commented 5 years ago

loads of tests still failing on python 3. This one is run by azure: https://dev.azure.com/cctbx/cctbx_project/_build/results?buildId=184

libtbx.python smtbx/refinement/restraints/tests/tst_restraints.py --verbose --scatterers=5 --resolution=0.2

  Standard error:
    Traceback (most recent call last):
      File "/__w/1/modules/cctbx_project/smtbx/refinement/restraints/tests/tst_restraints.py", line 454, in <module>
        run()
      File "/__w/1/modules/cctbx_project/smtbx/refinement/restraints/tests/tst_restraints.py", line 451, in run
        exercise_ls_restraints(command_line.options)
      File "/__w/1/modules/cctbx_project/smtbx/refinement/restraints/tests/tst_restraints.py", line 424, in exercise_ls_restraints
        exercise_restrained_refinement(options)
      File "/__w/1/modules/cctbx_project/smtbx/refinement/restraints/tests/tst_restraints.py", line 378, in exercise_restrained_refinement
        assert approx_equal(d, p.distance_ideal, eps)
    AssertionError
rjgildea commented 5 years ago

@luc-j-bourhis you added this particular test here: https://github.com/cctbx/cctbx_project/commit/511e6d9a59574e914ef36b254152b0d8f4571d4c

The cause of the failure is that random.sample returns different values on Python 3 compared to Python 2, so the test sets up a different set of restraints to refine against: https://github.com/cctbx/cctbx_project/blob/301522a972fac1f75d5c333540974bd9148434f8/smtbx/refinement/restraints/tests/tst_restraints.py#L318

On Python 2:

i, j, k, l: 3 0 2 1

Bond restraints: 5
Sorted by residual:
bond O1
     Mg3
  ideal  model  delta    sigma   weight residual
  6.496  7.643 -1.146 3.16e-05 1.00e+09 1.31e+09
bond O4
     O1
  ideal  model  delta    sigma   weight residual
  2.311  2.889 -0.578 3.16e-05 1.00e+09 3.34e+08
bond Mg3
     O4
  ideal  model  delta    sigma   weight residual
  4.869  5.410 -0.541 3.16e-05 1.00e+09 2.93e+08
bond O1
     Ca2
  ideal  model  delta    sigma   weight residual
  3.988  4.431 -0.443 3.16e-05 1.00e+09 1.96e+08
bond Ca2
     Mg3
  ideal  model  delta    sigma   weight residual
  3.988  4.082 -0.095 3.16e-05 1.00e+09 8.98e+06

On Python 3:

i, j, k, l: 1 0 4 3

Bond restraints: 5
Sorted by residual:
bond O4
     Si5
  ideal  model  delta    sigma   weight residual
  2.600  8.824 -6.223 3.16e-05 1.00e+09 3.87e+10
bond O1
     Si5
  ideal  model  delta    sigma   weight residual
  8.076  9.502 -1.425 3.16e-05 1.00e+09 2.03e+09
bond Ca2
     O1
  ideal  model  delta    sigma   weight residual
  3.545  4.431 -0.886 3.16e-05 1.00e+09 7.85e+08
bond Si5
     Ca2
  ideal  model  delta    sigma   weight residual
  5.027  5.585 -0.559 3.16e-05 1.00e+09 3.12e+08
bond O1
     O4
  ideal  model  delta    sigma   weight residual
  2.600  2.889 -0.289 3.16e-05 1.00e+09 8.35e+07

Should this test be expected to pass regardless of the values of i, j, k, l, or should they be hardcoded to the working Python 2 values?

See also https://docs.python.org/3/library/random.html#random.seed.