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

Export NumericsWarning and UserInputWarning from botorch.exceptions #2761

Closed
wants to merge 2 commits into from

Conversation

chrisyeh96
Copy link
Contributor

@chrisyeh96 chrisyeh96 commented Mar 6, 2025

Motivation

Using botorch.acquisition.ExpectedImprovement (instead of LogEI) now triggers a botorch.exceptions.warnings.NumericsWarning. I'd like to be able to suppress this warning in cases that I actually intend to use EI instead of LogEI, such as when I am comparing the two.

I'd like to be able to write the following:

import warnings

import botorch

with warnings.catch_warnings():
    warnings.filterwarnings('ignore', category=botorch.exceptions.NumericsWarning)
    acqf = botorch.acquisition.ExpectedImprovement(...)

However, botorch.exceptions does not export NumericsWarning as a symbol, so code editors (e.g., Visual Studio Code) complain that the symbol botorch.exceptions.NumericsWarning is not found. This pull request updates botorch/exceptions/__init__.py to export NumericsWarning and UserInputWarning, the only two warnings from botorch/exceptions/warnings.py that were previously unexported.

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

N/A

Related PRs

I believe it may have been a simple oversight of commit 6892be9 (from pull request #2429) to add NumericsWarning to the list of exported symbols in botorch/exceptions/__init__.py.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Mar 6, 2025
@chrisyeh96
Copy link
Contributor Author

Tagging @SebastianAment

@Balandat
Copy link
Contributor

Balandat commented Mar 6, 2025

However, botorch.exceptions does not export NumericsWarning as a symbol

As an alternative, could you instead just write the following?

from botorch.exceptions.warnings import NumericsWarning

with warnings.catch_warnings():
    warnings.filterwarnings('ignore', category=botorch.exceptions.NumericsWarning)

Not saying we shouldn't land this PR (seems fine), just curious if the above would work.

@chrisyeh96
Copy link
Contributor Author

@Balandat: Yeah, what you suggested works. I just found it odd that all but two of the warnings could be used via botorch.exceptions.***Warning, whereas only NumericsWarning and UserInputWarning could only be imported as botorch.exceptions.warnings.***Warning

Copy link

codecov bot commented Mar 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.99%. Comparing base (290c0ba) to head (1619848).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2761   +/-   ##
=======================================
  Coverage   99.99%   99.99%           
=======================================
  Files         203      203           
  Lines       18705    18705           
=======================================
  Hits        18704    18704           
  Misses          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Co-authored-by: Max Balandat <[email protected]>
@facebook-github-bot
Copy link
Contributor

@SebastianAment has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@SebastianAment merged this pull request in bba835c.

@chrisyeh96 chrisyeh96 deleted the patch-1 branch March 8, 2025 00:56
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. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants