Skip to content

Commit

Permalink
Merge: Ignore UnusedObjectWarning caused by nonpred recommenders in…
Browse files Browse the repository at this point in the history
… simulation (#313)

- ignore `UnusedObjectWarning` caused by recommenders in simulations
- this was caused for isntance by using the `RandomRecommender`, a
common use case because its a baseline
- I tried to use warning action modes `once` and `module` but that didnt
work at all
  • Loading branch information
Scienfitz authored Jul 23, 2024
2 parents 9a09f1e + 9bbe6cf commit afb0eb6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
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

### 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():
warnings.filterwarnings(
"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

0 comments on commit afb0eb6

Please sign in to comment.