You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reject incompatible parameter keys when loading optimizer state - #629
load_state() replays saved observation arrays using the receiving optimizer's parameter order without checking the saved keys. Saving x=1, y=2, target=21 and loading into pbounds={"y": ..., "x": ...} silently associates that target with y=1, x=2. Replacing the parameter names is also accepted when the dimensions match.
Validate the saved names and their order at the start of _load_state_dict() and raise a clear ValueError on a mismatch, before registering observations or changing the receiver's random state. Add eight regression cases covering reversed and renamed keys, empty/populated saved states, and empty/populated receiving optimizers. Same-order round trips retain the existing behavior.
Validation on Windows, Python 3.12.14, NumPy 2.5.3, SciPy 1.18.1, and scikit-learn 1.9.1:
Public save_state() / load_state() reproduction: four incompatible-key cases fail on untouched master, while two same-order controls pass; all six cases pass after the fix.
Complete pytest suite, including all eight example notebooks: 184 passed. With the new tests and untouched production code: eight failures and 176 passes, with no skips.
Full configured Ruff 0.12.3 pre-commit lint and format hooks and git diff --check pass.
The key-order mismatch was previously identified in the CodeRabbit review on #609. The state persistence API was introduced by @adrianmolzon in #547. This change addresses parameter names and order; it does not introduce state migration or validation of the other saved configuration fields. Documentation builds and the other platform/Python-version combinations were not run locally.
Summary by CodeRabbit
Bug Fixes
Loading saved optimizer state rejects parameter keys that differ or appear in a different order, preventing incompatible state from being restored.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 5ed4af42-cb9d-4c67-a8c0-9d12e4af72d0
📥 Commits
Reviewing files that changed from the base of the PR and between 3660dc9 and e47d1a3.
📒 Files selected for processing (1)
tests/test_bayesian_optimization.py
🚧 Files skipped from review as they are similar to previous changes (1)
tests/test_bayesian_optimization.py
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
📝 Walkthrough
Walkthrough
State loading checks that saved parameter keys match the optimizer’s keys in membership and order. It raises ValueError before restoring state when they do not match. Tests verify that rejection leaves optimizer results and subsequent random samples unchanged.
Changes
State Loading
Layer / File(s)
Summary
Validate parameter keys before restoration bayes_opt/bayesian_optimization.py, tests/test_bayesian_optimization.py
_load_state_dict rejects saved parameter keys that differ or appear in a different order. Tests cover observation variants and verify that rejection leaves results and subsequent random samples unchanged.
Loading saved state into an optimizer with different or reordered parameters now fails early with a clear error instead of silently misassociating observations. Same-order loads keep their existing behavior. No merge-blocking risk is identified.
Pre-merge checks | 5
✅ Passed checks (5 passed)
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main change: rejecting incompatible parameter keys when loading optimizer state.
Docstring Coverage
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
load_state()replays saved observation arrays using the receiving optimizer's parameter order without checking the savedkeys. Savingx=1, y=2, target=21and loading intopbounds={"y": ..., "x": ...}silently associates that target withy=1, x=2. Replacing the parameter names is also accepted when the dimensions match.Validate the saved names and their order at the start of
_load_state_dict()and raise a clearValueErroron a mismatch, before registering observations or changing the receiver's random state. Add eight regression cases covering reversed and renamed keys, empty/populated saved states, and empty/populated receiving optimizers. Same-order round trips retain the existing behavior.Validation on Windows, Python 3.12.14, NumPy 2.5.3, SciPy 1.18.1, and scikit-learn 1.9.1:
save_state()/load_state()reproduction: four incompatible-key cases fail on untouched master, while two same-order controls pass; all six cases pass after the fix.git diff --checkpass.The key-order mismatch was previously identified in the CodeRabbit review on #609. The state persistence API was introduced by @adrianmolzon in #547. This change addresses parameter names and order; it does not introduce state migration or validation of the other saved configuration fields. Documentation builds and the other platform/Python-version combinations were not run locally.
Summary by CodeRabbit