uqfoundation / mystic

constrained nonlinear optimization for scientific machine learning, UQ, and AI
http://mystic.rtfd.io
Other
467 stars 50 forks source link

AssertionErrors in tests for python 3.12 due to sum #214

Closed mmckerns closed 1 year ago

mmckerns commented 1 year ago

Two assertions fail in the test suite with python 3.12.0rc3:

$ python test_moments.py 
Traceback (most recent call last):
  File "/Users/mmckerns/dev/git/uqfoundation/mystic/mystic/tests/test_moments.py", line 26, in <module>
    assert sum(isnan(mo.impose_moment(5.0, y, order=3, skew=False))) == 0 #XXX?
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

and

$ python test_solver_constraints.py 
Traceback (most recent call last):
  File "/Users/mmckerns/dev/git/uqfoundation/mystic/mystic/tests/test_solver_constraints.py", line 189, in <module>
    test_mapped_solver(nested, solver, map)
  File "/Users/mmckerns/dev/git/uqfoundation/mystic/mystic/tests/test_solver_constraints.py", line 157, in test_mapped_solver
    assert almostEqual(spread(y), 5.0, tol=1e-15)
AssertionError
mmckerns commented 1 year ago

Apparently this is due to a long-standing python issue...

Python 3.11.5 (main, Aug 25 2023, 01:35:05) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> [sum(i/float(j) for i in [1.0]*j) for j in range(1,10)]
[1.0, 1.0, 1.0, 1.0, 1.0, 0.9999999999999999, 0.9999999999999998, 1.0, 1.0000000000000002]

versus

Python 3.12.0rc3 (main, Sep 23 2023, 00:48:47) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> [sum(i/float(j) for i in [1.0]*j) for j in range(1,10)]
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

mystic should actually do the right thing. I expect this would mean adjusting the existing code when weights=None so that the sum of the weights equals 1.0.