Skip to content

Keep Learner1D's loss infinite while a bound is still pending - #512

Merged
basnijholt merged 2 commits into
python-adaptive:mainfrom
r0c0y:learner1d-pending-bounds-loss
Dec 5, 2026
Merged

basnijholt merged 2 commits into
python-adaptive:mainfrom
r0c0y:learner1d-pending-bounds-loss

Conversation

@r0c0y

@r0c0y r0c0y commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Description

#271 made Learner1D.loss() infinite until the bounds are evaluated, so that a parallel run whose middle points come back first cannot reach its loss goal without the bounds. A later commit in that PR switched the check from self.__missing_bounds to self._missing_bounds(), which leaves out bounds that are pending (that list is what ask still has to hand out). In a runner both bounds are pending from the first ask, so in exactly that case the loss was finite again: with the data from #316 and the left bound in flight, loss() is 0.0015; with #271's own setup (ask(4), the two middle points told first) it is 0.59 while both bounds are still running.

loss() now treats a bound as missing until it is in data, so a pending bound counts too. Reading data directly also keeps clear of what the switch presumably fixed: __missing_bounds is only pruned inside _missing_bounds(), so it could still list bounds that had been told. loss(real=False) was already infinite in that state (the intervals next to a pending bound have an infinite combined loss), and ask still uses _missing_bounds(), so it does not ask for a pending bound twice.

What it changes for a run, with bounds that take 3 s and a middle that takes 20 ms, loss_goal=0.05 and 4 threads, 5 runs each:

main this branch
BlockingRunner: goal met when it returns 0 of 5 5 of 5
AsyncRunner: bounds evaluated at all 0 of 5 5 of 5

On main the goal is reached on the middle alone. BlockingRunner then waits for the running bounds while it cleans up, so they land, but the loss it returns with is above the goal and the edges are under-sampled. AsyncRunner cancels them, so the learner is left without its bounds.

New test test_inf_loss_while_bounds_are_pending in test_learner1d.py: after ask(4) and telling the two middle points, loss() and loss(real=False) are infinite, still infinite with one bound told, finite with both. On main it fails at the first check; checking only one bound fails it at the second.

This settles the part of #316 that still happens: the issue's own snippet, with the left bound never asked, already gives inf since #271.

Fixes #316

Checklist

  • Fixed style issues using pre-commit run --all (first install using pip install pre-commit)
  • pytest passed

Run here (macOS, on main at 262ffe9): 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_backend all pass (3.11 and 3.14 are not installed here), and pre-commit run --all-files passes, mypy included.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • (Code) style fix or documentation update
  • This change requires a documentation update

r0c0y and others added 2 commits December 5, 2026 21:25
python-adaptive#271 made loss() infinite until the bounds are evaluated, so that a
parallel run whose middle points come back first cannot reach its loss
goal without them. Checking _missing_bounds() left out pending bounds,
and in a runner both bounds are pending from the first ask, so the loss
was finite in exactly that case: BlockingRunner returned above its goal
and AsyncRunner cancelled the bounds. Treat a bound as missing until it
is in data.

Fixes python-adaptive#316
Keep real loss infinite until both bounds are evaluated. Use the original missing-bound check for expected loss so an in-flight bound does not starve sibling learners under loss-based balancing.

Assisted-by: MindRoom DevAgent:openai/gpt-6.2-sol <https://github.com/mindroom-ai/mindroom>

@basnijholt basnijholt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for tracking this down and putting together such a clear explanation and reproduction!

I pushed one small follow-up commit to restrict the self.data check to real=True and keep _missing_bounds() for real=False. While reviewing, I noticed that forcing loss(real=False) to inf for pending bounds changed BalancingLearner(strategy="loss") scheduling so a child with an in-flight bound took all newly asked points and starved siblings whose bounds had already finished. I also added tests covering both bound completion orders, expected loss, and BalancingLearner.

Merging now!

@basnijholt
basnijholt merged commit 2507701 into python-adaptive:main Dec 5, 2026
17 checks passed
basnijholt pushed a commit that referenced this pull request Dec 6, 2026
…513)

Learner1D and Learner2D report an infinite loss until their bounds are
evaluated, so a parallel run whose interior points come back first cannot
reach a loss goal without them. LearnerND.loss() was the largest simplex
loss of whatever had been told, so it was finite as soon as a few interior
points triangulated, with every corner still pending: BlockingRunner
returned above its goal and AsyncRunner returned without the corners and a
loss below the goal. Return inf until bounds_are_done, which LearnerND has
had all along without using it.

Follow-up commit restricts the bounds_are_done gate to real=True and keeps
_bounds_available for real=False (matching #512), with tests for real=False
and BalancingLearner with pending corners.

Assisted-by: MindRoom DevAgent (orchestrator: google/gemini-4-neon; implementer: openai/gpt-6.2-sol; reviewers: anthropic/claude-opus-5.5, openai/gpt-6.2-astra) <https://github.com/mindroom-ai/mindroom>
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.

Learner1D reports finite loss before bounds are done

2 participants