Repository navigation
Count the workers as they change when computing the overhead - #517
Merged
basnijholt merged 2 commits intoDec 6, 2026
Merged
Conversation
overhead() divided each evaluation's time by the number of workers when it finished and the sum by the elapsed time, which only holds while that number stays the same. With a scaling cluster the evaluations that finish after a scale-down counted several times over and the overhead went negative (python-adaptive#187); after a scale-up it was too high. Divide the total function time by the worker-seconds offered instead, summed piece by piece as the number of workers or of pending points changes, with max(n_workers, n_pending) as the capacity, so the overhead stays between 0 and 100. With a fixed number of workers the result is the same, and the number of workers is now read once per iteration, not per finished point. Fixes python-adaptive#187
…ling-workers # Conflicts: # adaptive/tests/test_runner.py
basnijholt
approved these changes
Dec 6, 2026
basnijholt
left a comment
Member
There was a problem hiding this comment.
Looks great, thanks for fixing #187 and resolving the conflict with main so quickly! Merging now.
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.
Description
overhead()divided each evaluation's time by the number of workers at the moment it finished (t / self._get_max_tasks()), and divided the sum by the elapsed time. That is right only while the number of workers stays the same. With a cluster that scales (#187, dask'sadapt), the evaluations that finish after a scale-down are divided by the smaller number, so they count several times over, and the overhead goes negative. After a scale-up it is too high.The overhead is now
1 - t_function / t_workers:t_functionis the time of all evaluations together, each measured from submitting the point to processing its result, as before.t_workersis the worker-seconds the executor offered. The runner sums it piece by piece, and updates it whenever the number of workers or of pending points changes.Between updates the capacity is
max(n_workers, n_pending). When workers leave while points are still pending, those points count as well. Sincet_functionis at most the integral of the number of pending points (a failed evaluation is not counted), it can never exceedt_workers, so the overhead stays between 0 and 100.With a fixed number of workers the result is the same as before:
n_workers * elapsed. The number of workers is now read once per runner iteration, not once per finished point. Fordistributed,_get_ncoresasks the scheduler (client.ncores()), so that is one scheduler call per iteration instead of one per finished point.Measured with real threads, 0.05 s evaluations, 8 threads and
_get_ncoresreporting a schedule:mainTests in
test_runner.py:test_overhead_is_the_share_of_unused_worker_timeruns a fake clock and an executor whose futures the test completes, so the expected overhead is exact:mainpasses.maingives -157%.maingives 33%.Counting only the workers (not the pending points), skipping either update, or keeping the old division each fails at least one case.
test_overhead_with_a_changing_number_of_workerscovers the same three schedules with real threads, through a patched_get_ncores. The overhead must be at least 0 and below 50. Onmainthe scale-down case fails.The docstrings that gave the old formula now give the new one.
Fixes #187
Run here (macOS, on
mainat 2507701):nox -e pytest_min_deps-3.12 pytest_all_deps-3.12 pytest_min_deps-3.13 pytest_all_deps-3.13 pytest_typeguard pytest_rust_backendall pass, with all six new tests in every session (3.11 and 3.14 are not installed here), andpre-commitpasses on the changed files, mypy included.This touches
runner.pyin places #514 does not, and the two merge cleanly there. Intest_runner.pythey meet only in the import block at the top; whichever lands second, I will rebase it. With that resolved, this branch, currentmainand #514 (including d61bba6) together passtest_runner.py,test_learner1d.pyandtest_learnernd.py.Checklist
pre-commit run --all(first install usingpip install pre-commit)pytestpassedType of change