Skip to content

Keep LearnerND's loss infinite until its bound points are evaluated - #513

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

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

Conversation

@r0c0y

@r0c0y r0c0y commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Description

The LearnerND counterpart of #512. Learner1D (since #271 and #512) and Learner2D (bounds_are_done) report an infinite loss until their bound points are evaluated, so a parallel run whose interior points come back first cannot reach a loss goal without the bounds. LearnerND.loss() had no such check: it is the largest simplex loss of whatever has been told, so as soon as a few interior points triangulate, the loss is finite while every corner is still pending. With bounds [(-1, 1), (-1, 1)], the four corners asked and four interior points told, loss() is 0.0075; Learner2D in the same state gives inf.

loss() now returns inf until bounds_are_done. That property has been on LearnerND since it was added, but nothing used it. It checks data for every bound point, the corners of a box or the vertices of a ConvexHull, so pending ones count as missing. ask already hands the bound points out first, so a run asks for nothing new.

What it changes for a run, with corners that take 3 s, an interior that takes 20 ms, loss_goal=0.01 and 6 threads, 5 runs each:

main this branch
BlockingRunner: goal met when it returns 0 of 5 5 of 5
AsyncRunner: corners evaluated 0 of 5 5 of 5
AsyncRunner: loss below the goal with no corner evaluated 5 of 5 0 of 5

On main, BlockingRunner waits for the running corners while it cleans up, so they land, but it returns above its goal (0.22 against 0.01 in one run). AsyncRunner cancels them and returns a learner whose loss still says it met the goal.

New test test_inf_loss_while_bound_points_are_pending in test_learnernd.py, for a box and for a triangular ConvexHull: with the bound points asked and four interior points told, loss() and loss(real=False) are infinite, still infinite with all but one bound point told, finite with all of them. On main both cases fail at the first check.

Run here (macOS, on main at 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_backend all pass (3.11 and 3.14 are not installed here), and pre-commit run --all-files passes, mypy included. The slowest LearnerND tests (test_anisotropic_3d and the LearnerND cases of test_balancing_learner) take the same time as on main.

Checklist

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

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 6, 2026 06:07
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.

@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 catching this and adding clean regression tests! I pushed a small follow-up commit to restrict the bounds_are_done check to real=True and keep _bounds_available for real=False so LearnerND matches #512, along with tests covering real=False and BalancingLearner with pending corners. Looks good to merge.

@basnijholt
basnijholt merged commit 4296c74 into python-adaptive:main Dec 6, 2026
17 checks passed
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