Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BotorchTestCase.assertAllClose #1618

Closed
wants to merge 1 commit into from

Conversation

esantorella
Copy link
Member

Summary:
BotorchTestCase.assertAllClose will print more informative error messages on failure than TestCase.assertTrue(torch.allclose(...)). It uses torch.testing.assert_close.

Old test output:
AssertionError: False is not true

New test output:

1) AssertionError: Scalars are not close!

Absolute difference: 1.0000034868717194 (up to 0.0001 allowed)
Relative difference: 0.8348668001940709 (up to 1e-05 allowed)

This currently replicates the behavior of torch.allclose so that tests remain exactly as strict as they used to be, but in the future we might want to use the behavior of assert_close instead since it uses higher tolerances for single-precision inputs by default and is more configurable.

Differential Revision: D42402142

@facebook-github-bot facebook-github-bot added CLA Signed Do not delete this pull request or issue due to inactivity. fb-exported labels Jan 7, 2023
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D42402142

@codecov
Copy link

codecov bot commented Jan 7, 2023

Codecov Report

Merging #1618 (19ec6e1) into main (bb5fc4c) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main     #1618   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          154       154           
  Lines        13774     13776    +2     
=========================================
+ Hits         13774     13776    +2     
Impacted Files Coverage Δ
botorch/utils/testing.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Summary:
Pull Request resolved: pytorch#1618

`BotorchTestCase.assertAllClose` will print more informative error messages on failure than `TestCase.assertTrue(torch.allclose(...))`. It uses `torch.testing.assert_close`.

Old test output:
```AssertionError: False is not true```

New test output:
```
1) AssertionError: Scalars are not close!

Absolute difference: 1.0000034868717194 (up to 0.0001 allowed)
Relative difference: 0.8348668001940709 (up to 1e-05 allowed)
```

This currently replicates the behavior of `torch.allclose` so that tests remain exactly as strict as they used to be, but in the future we might want to use the behavior of `assert_close` instead since it uses higher tolerances for single-precision inputs by default and is more configurable.

Differential Revision: D42402142

fbshipit-source-id: 62dc6df5e786a72a758a4d9a08ca92f88ab2c149
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D42402142

esantorella added a commit to esantorella/botorch that referenced this pull request Jan 7, 2023
Summary:
Pull Request resolved: pytorch#1618

`BotorchTestCase.assertAllClose` is a thin wrapper around `torch.testing.assert_close`, designed to replace usages of
`self.assertTrue(torch.allclose(...))`.

Using  has several advantages over `torch.allclose`:
* Checks that shapes are equal, not just values
* More configurability and better defaults, such as higher tolerances for single precision, if we choose to use them in the future. for the time being, I've set up this wrapper so that numerical checks remain exactly the same as they used to be.
* More informative test output, showing what was put in and why the test failed:

Old test output:
```AssertionError: False is not true```

New test output:
```
1) AssertionError: Scalars are not close!

Absolute difference: 1.0000034868717194 (up to 0.0001 allowed)
Relative difference: 0.8348668001940709 (up to 1e-05 allowed)
```

Differential Revision: https://internalfb.com/D42402142

fbshipit-source-id: c729ed6ea7c0e16487e3bc7e174b6e4c675cc19a
esantorella added a commit to esantorella/botorch that referenced this pull request Jan 7, 2023
Summary:
Pull Request resolved: pytorch#1618

`BotorchTestCase.assertAllClose` is a thin wrapper around `torch.testing.assert_close`, designed to replace usages of
`self.assertTrue(torch.allclose(...))`.

Using  has several advantages over `torch.allclose`:
* Checks that shapes are equal, not just values
* More configurability and better defaults, such as higher tolerances for single precision, if we choose to use them in the future. for the time being, I've set up this wrapper so that numerical checks remain exactly the same as they used to be.
* More informative test output, showing what was put in and why the test failed:

Old test output:
```AssertionError: False is not true```

New test output:
```
1) AssertionError: Scalars are not close!

Absolute difference: 1.0000034868717194 (up to 0.0001 allowed)
Relative difference: 0.8348668001940709 (up to 1e-05 allowed)
```

Differential Revision: https://internalfb.com/D42402142

fbshipit-source-id: 1bec649658ea698a7f54330d20837efa0d2aaa11
esantorella added a commit to esantorella/botorch that referenced this pull request Jan 7, 2023
Summary:
Pull Request resolved: pytorch#1618

`BotorchTestCase.assertAllClose` is a thin wrapper around `torch.testing.assert_close`, designed to replace usages of
`self.assertTrue(torch.allclose(...))`.

Using  has several advantages over `torch.allclose`:
* Checks that shapes are equal, not just values
* More configurability and better defaults, such as higher tolerances for single precision, if we choose to use them in the future. for the time being, I've set up this wrapper so that numerical checks remain exactly the same as they used to be.
* More informative test output, showing what was put in and why the test failed:

Old test output:
```AssertionError: False is not true```

New test output:
```
1) AssertionError: Scalars are not close!

Absolute difference: 1.0000034868717194 (up to 0.0001 allowed)
Relative difference: 0.8348668001940709 (up to 1e-05 allowed)
```

Differential Revision: https://internalfb.com/D42402142

fbshipit-source-id: 24df18d1e748f4b4e9192f3781dee75259bbb80c
esantorella added a commit to esantorella/botorch that referenced this pull request Jan 7, 2023
Summary:
Pull Request resolved: pytorch#1618

`BotorchTestCase.assertAllClose` is a thin wrapper around `torch.testing.assert_close`, designed to replace usages of
`self.assertTrue(torch.allclose(...))`.

Using  has several advantages over `torch.allclose`:
* Checks that shapes are equal, not just values
* More configurability and better defaults, such as higher tolerances for single precision, if we choose to use them in the future. for the time being, I've set up this wrapper so that numerical checks remain exactly the same as they used to be.
* More informative test output, showing what was put in and why the test failed:

Old test output:
```AssertionError: False is not true```

New test output:
```
1) AssertionError: Scalars are not close!

Absolute difference: 1.0000034868717194 (up to 0.0001 allowed)
Relative difference: 0.8348668001940709 (up to 1e-05 allowed)
```

Differential Revision: https://internalfb.com/D42402142

fbshipit-source-id: e10063d1b3401168e6e7bfd1fc605b2331a63a3d
esantorella added a commit to esantorella/botorch that referenced this pull request Jan 7, 2023
Summary:
Pull Request resolved: pytorch#1618

`BotorchTestCase.assertAllClose` is a thin wrapper around `torch.testing.assert_close`, designed to replace usages of
`self.assertTrue(torch.allclose(...))`.

Using  has several advantages over `torch.allclose`:
* Checks that shapes are equal, not just values
* More configurability and better defaults, such as higher tolerances for single precision, if we choose to use them in the future. for the time being, I've set up this wrapper so that numerical checks remain exactly the same as they used to be.
* More informative test output, showing what was put in and why the test failed:

Old test output:
```AssertionError: False is not true```

New test output:
```
1) AssertionError: Scalars are not close!

Absolute difference: 1.0000034868717194 (up to 0.0001 allowed)
Relative difference: 0.8348668001940709 (up to 1e-05 allowed)
```

Differential Revision: https://internalfb.com/D42402142

fbshipit-source-id: 3ceb5a02ee6704da4a49cc48f5bb7adf7b2e9c9a
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 05d93e6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants