Skip to content

Distinguish boolean and integer queued trial parameters - #6896

Open
kocaemre wants to merge 1 commit into
optuna:masterfrom
kocaemre:fix/6895-boolean-enqueue-dedup
Open

kocaemre wants to merge 1 commit into
optuna:masterfrom
kocaemre:fix/6895-boolean-enqueue-dedup

Conversation

@kocaemre

Copy link
Copy Markdown

Motivation

Study.enqueue_trial(..., skip_if_exists=True) currently skips True after 1 (and False after 0) because Python considers bool an int subclass. The reverse ordering is not skipped, so deduplication depends on insertion order. Boolean and integer fixed parameters should remain distinct.

Description of the changes

  • Exclude mixed boolean/non-boolean fixed parameters from the duplicate match, regardless of insertion order. Leave existing numeric and same-type comparisons unchanged.
  • Add regression cases for both boolean values, both insertion orders, and all seven existing storage modes; assert the two queued values retain their respective types.

RED: .venv/bin/python -m pytest tests/study_tests/test_study.py -q -k distinguishes_bool_from_int --tb=short -x -o addopts='' failed on the first case: expected 2 queued trials, got 1 ({'x': True} skipped).

GREEN:

  • .venv/bin/python -m pytest tests/study_tests/test_study.py -q -k enqueue_trial_skip_existing --tb=short -o addopts='' — 147 passed.
  • .venv/bin/python -m pytest tests/study_tests/test_study.py -q --tb=short -o addopts='' — 673 passed, 7 skipped (four multiprocessing fork deprecation warnings).
  • .venv/bin/ruff check optuna/study/study.py tests/study_tests/test_study.py — passed.
  • .venv/bin/ruff format --check optuna/study/study.py tests/study_tests/test_study.py — two files formatted.
  • git diff --check — passed.

Fixes #6895. I used an LLM to assist with this PR; I reproduced the failure, selected the bool/int boundary guard, and ran the stated local checks.

Checklist

  • I used an LLM while working on this PR.

Signed-off-by: Emre K <110906681+kocaemre@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

enqueue_trial(skip_if_exists=True) incorrectly treats bool parameters (True/False) as duplicates of integer parameters (1/0)

1 participant