Skip to content

Fix bounds indexing and candidate names for contextual BO with fixed features#426

Merged
roussel-ryan merged 3 commits into
contextual_bo_generatorfrom
copilot/fix-comments-in-review-thread
Jun 3, 2026
Merged

Fix bounds indexing and candidate names for contextual BO with fixed features#426
roussel-ryan merged 3 commits into
contextual_bo_generatorfrom
copilot/fix-comments-in-review-thread

Conversation

Copilot AI commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

When both fixed_features and contextual_variables are active, the generator double-sliced the bounds tensor using stale indices from the original variable list, causing out-of-range indexing and wrong column drops. Similarly, _candidate_names mutated vocs.variable_names in place and omitted contextual variables, causing column mismatches in _process_candidates.

Changes

  • _get_optimization_bounds: Replaced two sequential index+slice passes with a single exclusion set (fixed_features ∪ contextual_variables) computed against the original variable list, slicing bounds once.
  • _candidate_names: Copy the variable list before filtering (avoids mutating VOCS state), and exclude contextual variables alongside fixed features so the returned names always match the optimized tensor dimensions.
  • vocs.py error message: Clarified the validation error to say "non-contextual vocs variables" — the old message said "vocs variables", which was misleading since contextual variables are intentionally excluded from the expected column set.
  • Tests: Added three tests in xopt/tests/generators/bayesian/test_contextual_bo.py to validate the new behaviour:
    • test_candidate_names_excludes_contextual_and_fixed — verifies exclusion of both contextual and fixed-feature variables and no mutation of vocs.variable_names.
    • test_optimization_bounds_excludes_contextual_and_fixed — verifies correct bounds shape and values when both fixed_features and contextual variables are present.
    • test_convert_dataframe_to_inputs_error_message_contextual — verifies the updated error message references "non-contextual" variables.

- _candidate_names: copy variable list to avoid mutation, exclude contextual variables
- _get_optimization_bounds: compute keep-indices once from original list, slice bounds once
- vocs.py: update error message to mention non-contextual variables
Copilot AI changed the title [WIP] Fix code based on review comments Fix bounds indexing and candidate names for contextual BO with fixed features Jun 3, 2026
Copilot AI requested a review from roussel-ryan June 3, 2026 20:24
@roussel-ryan

Copy link
Copy Markdown
Collaborator

@copilot add tests to validate the new behavior

@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- test_candidate_names_excludes_contextual_and_fixed: verifies _candidate_names
  excludes both contextual variables and fixed features, and does not mutate vocs
- test_optimization_bounds_excludes_contextual_and_fixed: verifies _get_optimization_bounds
  correctly handles combined fixed_features + contextual_variables in a single pass
- test_convert_dataframe_to_inputs_error_message_contextual: verifies the updated
  error message mentions 'non-contextual' variables

Copilot AI commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add tests to validate the new behavior

Added three targeted tests in xopt/tests/generators/bayesian/test_contextual_bo.py (commit 0c23dbc):

  • test_candidate_names_excludes_contextual_and_fixed — verifies _candidate_names excludes both contextual variables and fixed features, and that calling it repeatedly does not mutate vocs.variable_names.
  • test_optimization_bounds_excludes_contextual_and_fixed — verifies _get_optimization_bounds produces correctly-shaped, correctly-valued bounds when both fixed_features and contextual variables are present.
  • test_convert_dataframe_to_inputs_error_message_contextual — verifies the updated error message references "non-contextual" variables so users aren't misled when contextual columns are absent from the input DataFrame.

@roussel-ryan roussel-ryan marked this pull request as ready for review June 3, 2026 21:09
@roussel-ryan roussel-ryan merged commit 22002d5 into contextual_bo_generator Jun 3, 2026
12 of 13 checks passed
@roussel-ryan roussel-ryan deleted the copilot/fix-comments-in-review-thread branch June 3, 2026 21:10
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.

2 participants