Skip to content

Batched strategies - #53

Merged
Lance-Drane merged 39 commits into
developfrom
batched_strategies
Sep 9, 2026
Merged

Lance-Drane merged 39 commits into
developfrom
batched_strategies

Conversation

@vreshniak

@vreshniak vreshniak commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

This pull request introduces support of batch strategies.

Key changes include:

Strategy Handling

  • Supporting new batch strategies ('liar', 'believer'). The strategy argument types were also expanded to allow lists for more flexible parameterization.
  • Updated ServersideInputMultipleOtherStrategy and related data classes to accept and process the new strategy types and arguments, including batch strategies.

Core Logic

  • Extended core.py to support batch sampling. Now, get_next_points can handle the new strategies, delegating to the appropriate selection logic based on the strategy type.
  • Added new utility functions in strategies.py for batch_sampling supporting both liar and believer batch strategies.

Fixes and Minor Improvements

  • Fixed initialize_workflow to only train a model if both dataset_x and non-empty dataset_y are provided, preventing unnecessary or invalid model training.
  • Improved numerical stability in normalization by enforcing a minimum standard deviation (1e-12) in _transform_Y_params.

@vreshniak
vreshniak marked this pull request as draft August 6, 2026 14:42
@stvdwtt
stvdwtt requested a review from Lance-Drane August 20, 2026 14:31
@vreshniak
vreshniak marked this pull request as ready for review September 9, 2026 12:21
@vreshniak
vreshniak requested review from konstpieper and a lite review from Copilot September 9, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

There are correctness and test-coverage regressions (e.g., believer uses a stale model during batch selection, missing validation can raise UnboundLocalError, and a duplicated test name silently drops coverage).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This pull request adds support for batched point-selection strategies (constant liar and kriging believer) and introduces deterministic/indexed surrogate-free strategies (center/corners/grid/chebyshev/latin hypercube), alongside a few stability/correctness fixes in workflow initialization and preprocessing.

Changes:

  • Added indexed strategy implementations and selection logic, plus batch sampling via liar/believer.
  • Expanded request dataclasses to support batch_strategy and richer strategy_args types.
  • Improved serverside caching behavior and added extensive unit tests + a client script example.
File summaries
File Description
tests/unit/test_internals.py Adds helper utilities and new unit tests for indexed and batched strategies.
src/dial_service/utilities/strategies.py Implements indexed strategies and new batch_sampling for liar/believer.
src/dial_service/serverside_data.py Refactors y/yerr extraction into cached properties and adds cache clearing utility; updates multiple-input params handling.
src/dial_service/dial_service.py Prevents model training at workflow init unless both X and non-empty Y are provided.
src/dial_service/core.py Routes indexed single-point strategies and delegates batch requests to batch_sampling.
src/dial_dataclass/dial_dataclass.py Extends strategy typing and adds batch_strategy to multi-point requests.
scripts/2d_rosenbrock_client_with_strategies.py Adds an example client showcasing strategy scheduling and plotting.
Review details

Suppressed comments (1)

src/dial_service/core.py:107

  • get_next_points computes backend/module twice (once before the batch-strategy check and again after the match). This is redundant and makes it easier for the two blocks to drift if later edits change one but not the other.
    backend = data.backend.lower()
    module = get_backend_module(backend)

    if data.batch_strategy is not None:
        return batch_sampling(module, model, data)

    match data.strategy:
        case 'random':
            output_points = [
                random_in_bounds(data.bounds, data.numpy_rng) for _ in range(data.points)
            ]
            return output_points
        case 'hypercube':
            output_points = hypercube(data.bounds, data.points, data.numpy_rng)
            return output_points

    backend = data.backend.lower()
    module = get_backend_module(backend)
    output_points = module.samples(module, model, data)
  • Files reviewed: 7/7 changed files
  • Comments generated: 6
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +80 to +98
@cached_property
def yerr_train_raw(self) -> any:
"""
Return the raw training error values extracted from the dataset.
"""
yerr_label = self.statistics_y.scale
if isinstance(yerr_label, float):
self.yerr_train_raw = yerr_label
_yerr_train_raw = yerr_label
else:
# yerr_label is str
# this may trigger a ValueError, but should be handled by dataclass validation
pos_yerr = self.labels_y.index(yerr_label)
self.yerr_train_raw = self.dataset_y[:, pos_yerr]
_yerr_train_raw = self.dataset_y[:, pos_yerr]

if np.any(self.yerr_train_raw < 0):
idxs = np.where(np.yerr_train_raw < 0)
msg = f'yerr values in statistics_y.scale must be non-negative, found {np.yerr_train_raw[idxs[0]]} at {idxs[0]}.'
if np.any(_yerr_train_raw < 0):
idxs = np.where(_yerr_train_raw < 0)
msg = f'yerr values in statistics_y.scale must be non-negative, found {_yerr_train_raw[idxs[0]]} at {idxs[0]}.'
raise ValueError(msg)
return _yerr_train_raw

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

fixed in 40ffbb0

Comment thread src/dial_service/utilities/strategies.py Outdated
Comment thread src/dial_service/utilities/strategies.py
Comment thread tests/unit/test_internals.py Outdated
Comment thread src/dial_service/serverside_data.py
Comment thread tests/unit/test_internals.py Outdated
vreshniak and others added 9 commits September 9, 2026 08:31
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Lance-Drane <Lance-Drane@users.noreply.github.com>
Signed-off-by: Lance-Drane <Lance-Drane@users.noreply.github.com>

@Lance-Drane Lance-Drane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This LGTM, I went ahead and fixed the bug that CoPilot caught. Going to go ahead and merge this.

@Lance-Drane
Lance-Drane merged commit a2af370 into develop Sep 9, 2026
17 of 18 checks passed
@Lance-Drane
Lance-Drane deleted the batched_strategies branch September 9, 2026 18:39
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.

3 participants