Add user-suppliable batch_evaluator argument to minimize/maximize#684
Open
hmgaudecker wants to merge 2 commits into
Open
Add user-suppliable batch_evaluator argument to minimize/maximize#684hmgaudecker wants to merge 2 commits into
hmgaudecker wants to merge 2 commits into
Conversation
Threads a `batch_evaluator` keyword (a BatchEvaluatorLiteral string or a callable conforming to the BatchEvaluator protocol) from the public minimize/maximize API through create_optimization_problem and the OptimizationProblem container to InternalOptimizationProblem, replacing the hardcoded joblib evaluator in _optimize. This lets users plug in a custom evaluator (e.g. an MPI-backed pool) for the batched criterion evaluations that trust-region optimizers like tranquilo request. Removes the dead `batch_evaluator` Literal field from the Tranquilo and TranquiloLS dataclasses: it was never read (the evaluator lives on the problem, not the algorithm), so it silently no-op'd. Exports BatchEvaluator so users can type custom evaluators against the protocol. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Threads a
batch_evaluatorkeyword from the publicminimize/maximizeAPI throughcreate_optimization_problemand theOptimizationProblemcontainer toInternalOptimizationProblem, replacing the hardcodedprocess_batch_evaluator("joblib")in
_optimize. Users can now pass either a built-in name ("joblib","pathos","threading") or a callable conforming to theBatchEvaluatorprotocol.Also:
batch_evaluatorLiteralfield from theTranquilo/TranquiloLSdataclasses. It was never read — the evaluator lives on the optimization problem, not
the algorithm — so setting it silently no-op'd.
BatchEvaluatorfrom the top-level namespace so users can type their customevaluators against the protocol.
Why
The batched criterion evaluations a trust-region optimizer like
tranquilorequests werelocked to the in-process
joblibevaluator. Some workloads need a different executionbackend — e.g. a distributed, MPI-backed pool that fans each batch of candidate points
out across nodes/GPUs for an expensive simulation-based criterion. There was already a
process_batch_evaluatorresolver and aBatchEvaluatorprotocol; this just lets thecaller reach them.
This is also the foundation for a follow-up: a first-class executor-backed
(
concurrent.futures/mpi4py.futures) distributed evaluator, whereminimizeitselfparks non-root ranks in a worker pool so the optimizer runs on a single driver. That
addresses a real footgun — under MPI,
srunstarts N copies of the program, so a naive"run
minimizeon every rank with a collective evaluator" design ends up with Noptimizers kept in lockstep, which diverges under floating-point nondeterminism. This PR
is the minimal, backward-compatible plumbing that makes the safe design expressible.
Tests
Adds
test_minimize_uses_custom_batch_evaluator,test_maximize_uses_custom_batch_evaluator(a spy callable is the one optimagic actuallyinvokes), and
test_minimize_rejects_unknown_batch_evaluator(clear error on an unknownname).
Backward compatibility
Fully backward compatible —
batch_evaluatordefaults to"joblib", the prior behavior.Happy to add a
CHANGES.mdentry referencing this PR number under the appropriatenext-version heading (0.5.4 vs 0.6.0 — your call).
🤖 Generated with Claude Code