Skip to content

Compare integer parameters exactly in enqueue_trial - #6889

Merged
gen740 merged 2 commits into
optuna:masterfrom
aalquwayfili:fix-enqueued-integer-identity
Oct 10, 2026
Merged

gen740 merged 2 commits into
optuna:masterfrom
aalquwayfili:fix-enqueued-integer-identity

Conversation

@aalquwayfili

Copy link
Copy Markdown
Contributor

Motivation

enqueue_trial(skip_if_exists=True) treats 100000 and 100001 as duplicates because it converts integers to float and applies np.isclose. This silently removes a requested discrete configuration from the queue.

Discovered through code inspection and reproduced with the public API:

import optuna

study = optuna.create_study()
for value in (100000, 100001, 100000):
    study.enqueue_trial({"vocab_size": value}, skip_if_exists=True)
print(len(study.trials))  # Before: 1. Expected and fixed: 2.

Description of the changes

Use exact equality for integral values. Preserve the existing approximate comparison for other real values, including its NaN handling. The original review introduced tolerance for floating-point representation errors.

Extend the existing parameterized test with positive/negative neighboring integers, float-conversion precision boundaries, an exact duplicate and a close-float control. The large integer cases test queue identity, not arbitrary-width integer sampling.

Validation:

  • Unchanged base: 15 failures and 85 passing controls across five storage backends.
  • pytest tests/study_tests/test_study.py -q -k 'enqueue and not grpc': 136 passed.
  • Repository-wide Ruff check/format check and mypy pass; mypy checks 324 source files.
  • git diff --check passes.

The storage tests cover in-memory, SQLite, cached SQLite, journal files and the repository's fake-Redis backend. gRPC, live Redis and the full package suite were not run.

Checklist

  • I used an LLM while working on this PR.

@c-bata

c-bata commented Oct 9, 2026

Copy link
Copy Markdown
Member

@yen-0 @gen740 Could you review this PR?

Comment thread tests/study_tests/test_study.py Resolved
Comment thread tests/study_tests/test_study.py Resolved

@yen-0 yen-0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except the same points as @gen740 .

@aalquwayfili

Copy link
Copy Markdown
Contributor Author

Removed those test cases. Thanks!

@aalquwayfili
aalquwayfili requested a review from gen740 October 9, 2026 10:16

@gen740 gen740 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@gen740
gen740 merged commit 13a3ff1 into optuna:master Oct 10, 2026
14 checks passed
@yen-0 yen-0 added the bug Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself. label Oct 14, 2026
@yen-0 yen-0 added this to the v5.1.0 milestone Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants