pytensor icon indicating copy to clipboard operation
pytensor copied to clipboard

Remove reimplementation of np.testing.assert_allclose

Open jaharvey8 opened this issue 1 year ago • 8 comments

Description

I think I got all the unittest_tools.assert_allclose instances

The following files no longer used functions from unittest_tools so I removed the import tests/link/test_vm.py tests/tensor/test_variable.py tests/scalar/test_basic.py tests/sparse/test_rewriting.py tests/link/c/test_params_type.py tests/tensor/rewriting/test_elemwise.py

There was a mention of utt.assert_all close in the creating_an_op document file so I changed that as well.

Related Issue

  • [x] Closes #551

Checklist

  • [X] Checked that the pre-commit linting/style checks pass
  • [X] Included tests that prove the fix is effective or that the new feature works
  • [X] Added necessary documentation (docstrings and/or example notebooks)
  • [ ] If you are a pro: each commit corresponds to a [relevant logical changes

Type of change

  • [ ] New feature / enhancement
  • [ ] Bug fix
  • [ ] Documentation
  • [X] Maintenance
  • [ ] Other (please specify):

jaharvey8 avatar Dec 19 '23 14:12 jaharvey8

Seems like the rtol/atol values may need to be tweaked slightly, as some tests are now failing

ricardoV94 avatar Dec 29 '23 16:12 ricardoV94

Seems like the rtol/atol values may need to be tweaked slightly, as some tests are now failing

Potentially dumb question, is that something I need to do?

jaharvey8 avatar Dec 29 '23 17:12 jaharvey8

Yes, we can only merge the changes if all tests pass. You can see which tests failed here on GitHub

ricardoV94 avatar Dec 29 '23 18:12 ricardoV94

Oh ok yeah I just wasn't sure what the atol and rtol values were and if that was something I was supposed to modify. But I'll look and see which tests failed and why. Thanks!

jaharvey8 avatar Dec 29 '23 19:12 jaharvey8

Ok I fixed up some remaining calls to the old unittest_tools assert_allclose function and fixed some typos I had introduced.

On the rtol and atol issues, in the current unittest_tools assert_allclose function, the default values for those are set to 'None'. That is

def assert_allclose(expected, value, rtol=None, atol=None):
    if not _allclose(expected, value, rtol, atol):
        raise WrongValue(expected, value, rtol, atol)

Should I also pass 'None' to the np.testing.assert_allclose function calls (assuming that's allowed)?

jaharvey8 avatar Jan 04 '24 04:01 jaharvey8

Instead of none, we should not specify them at all (unless the test fails, then we need to tweak them)

ricardoV94 avatar Jan 07 '24 22:01 ricardoV94

If things get out of hand, the default atol and rtol were being defined here: https://github.com/pymc-devs/pytensor/blob/0ebc83b393b7a3c310cdb451baee35b56b0dcc2f/pytensor/tensor/math.py#L102

And used here: https://github.com/pymc-devs/pytensor/blob/0ebc83b393b7a3c310cdb451baee35b56b0dcc2f/pytensor/tensor/math.py#L117

ricardoV94 avatar Jan 07 '24 22:01 ricardoV94

Hi @jaharvey8 Are you still working on this PR? I'd like to take it up if you are not.

Dhruvanshu-Joshi avatar Apr 08 '24 13:04 Dhruvanshu-Joshi