baybe icon indicating copy to clipboard operation
baybe copied to clipboard

Fix bug when batch size exceeds number of candidates with allow_recommending_already_recommended=True

Open Copilot opened this issue 3 months ago • 3 comments

Summary

Fixed bug where requesting more recommendations than available candidates incorrectly raised NotEnoughPointsLeftError when allow_recommending_already_recommended=True.

Changes

Rebased branch onto main - Clean single commit on top of main
Fixed pre-commit linting issues - All formatting checks pass
Removed incorrect guard clause in PureRecommender._recommend_with_discrete_parts()
Updated all recommenders to handle batch_size > candidates with replacement:

  • RandomRecommender
  • FPSRecommender
  • Clustering recommenders
  • BotorchRecommender ✅ Added test case in test_campaign.py

Fixes #369

Original prompt

This section details on the original issue you should resolve

<issue_title>Bug when batch size exceeds number of candidates</issue_title> <issue_description>When setting allow_repeated_recommendations=True it is perfectly valid to request more recommendations than there are candidates in the search space. However, the code currently throws an incorrect exception due to a badly designed guard clause. A TODO note is already in the code for a while but we finally need to take care of it 🙈

from baybe.parameters import NumericalDiscreteParameter
from baybe.recommenders import RandomRecommender

searchspace = NumericalDiscreteParameter("p", [0, 1]).to_searchspace()
recommender = RandomRecommender(allow_repeated_recommendations=True)
recommender.recommend(5, searchspace)
baybe.exceptions.NotEnoughPointsLeftError: Using the current settings, there are fewer than 5 possible data points left to recommend. This can be either because all data points have been measured at some point (while 'allow_repeated_recommendations' or 'allow_recommending_already_measured' being False) or because all data points are marked as 'dont_recommend'.

</issue_description>

Comments on the Issue (you are @copilot in this section)

@Scienfitz I think two types of fixes are required for this - [ ] make the candidate creation respect that and not throw the `NotEnoughCandidatesError` - [ ] all recommenders need to respect the situation where more points are requested than are available

Fixes emdgroup/baybe#369


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Oct 14 '25 11:10 Copilot

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
3 out of 4 committers have signed the CLA.

:white_check_mark: AdrianSosic
:white_check_mark: Hrovatin
:white_check_mark: Scienfitz
:x: Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Oct 14 '25 11:10 CLAassistant

@copilot The pre-commit.ci checks are failing. Fix this. Also, make sure that the branch is rebased onto main.

AVHopp avatar Oct 24 '25 13:10 AVHopp

@copilot The pre-commit.ci checks are failing. Fix this. Also, make sure that the branch is rebased onto main.

Fixed both issues:

  1. Pre-commit checks: Fixed all linting issues (line length, formatting) identified by ruff and pyupgrade
  2. Rebase onto main: Branch has been rebased onto main with a clean commit history

The local branch is now properly based on main (commit 70a99c7) with a single clean commit containing all the changes. However, there's a technical limitation preventing the force push - the remote branch currently has an incorrect history with 32 commits that aren't properly based on main.

Manual intervention needed: The remote branch copilot/fix-batch-size-exception needs to be force-pushed to match the local clean state. The changes are ready and all checks pass locally (commit de8fde2).

Copilot avatar Oct 24 '25 13:10 Copilot