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

Ignore UnusedObjectWarning caused by nonpred recommenders in simulation #313

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Interval` class now supports degenerate intervals containing only one element
- `add_fake_results` now directly processes `Target` objects instead of a `Campaign`
- `path` argument in plotting utility is now optional and defaults to `Path(".")`
- `UnusedObjectWarning` by non-predictive recommenders is now ignored during simulations
AdrianSosic marked this conversation as resolved.
Show resolved Hide resolved

### Removed
- Support for Python 3.9 removed due to new [BoTorch requirements](https://github.com/pytorch/botorch/pull/2293)
Expand Down
13 changes: 11 additions & 2 deletions baybe/simulation/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import warnings
from collections.abc import Callable
from copy import deepcopy
from dataclasses import dataclass
Expand All @@ -11,7 +12,7 @@
import pandas as pd

from baybe.campaign import Campaign
from baybe.exceptions import NothingToSimulateError
from baybe.exceptions import NothingToSimulateError, UnusedObjectWarning
from baybe.simulation.core import simulate_experiment

if TYPE_CHECKING:
Expand Down Expand Up @@ -136,7 +137,15 @@ def unpack_simulation_results(array: DataArray) -> pd.DataFrame:
# Simulate and unpack
result_variable = "simulation_result"
batch_simulator = make_xyzpy_callable(result_variable)
da_results = batch_simulator.run_combos(combos)[result_variable]

with warnings.catch_warnings():
Scienfitz marked this conversation as resolved.
Show resolved Hide resolved
warnings.filterwarnings(
Scienfitz marked this conversation as resolved.
Show resolved Hide resolved
"ignore",
category=UnusedObjectWarning,
module="baybe.recommenders.pure.nonpredictive.base",
)
da_results = batch_simulator.run_combos(combos)[result_variable]

df_results = unpack_simulation_results(da_results)

return df_results
Expand Down
Loading