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

Fix tensor shapes in unit tests #1620

Closed
wants to merge 2 commits into from

Conversation

esantorella
Copy link
Member

Summary: As a result of switching from self.AssertTrue(torch.allclose(...)) to self.AssertAllClose in unit tests, we will now also have checks that tensors compared are the same shape and not just numerically equal. Some of our current tests were failing; this fixes that by changing the shapes of the compared tensors.

Differential Revision: D42402387

esantorella and others added 2 commits January 7, 2023 12:12
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
Summary: As a result of switching from `self.AssertTrue(torch.allclose(...))` to `self.AssertAllClose` in unit tests, we will now also have checks that tensors compared are the same shape and not just numerically equal. Some of our current tests were failing; this fixes that by changing the shapes of the compared tensors.

Differential Revision: D42402387

fbshipit-source-id: 15c42cb6d4c07b857092ece5d29b3a7fbd125661
@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: D42402387

@codecov
Copy link

codecov bot commented Jan 7, 2023

Codecov Report

Merging #1620 (2e5df41) into main (bb5fc4c) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main     #1620   +/-   ##
=========================================
  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

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in a0d6812.

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.

None yet

2 participants