Skip to content

Fix Learner2D state rollback in BalancingLearner ask(tell_pending=False)#492

Merged
basnijholt merged 3 commits into
mainfrom
copilot/fix-failing-github-actions-job
Jun 10, 2026
Merged

Fix Learner2D state rollback in BalancingLearner ask(tell_pending=False)#492
basnijholt merged 3 commits into
mainfrom
copilot/fix-failing-github-actions-job

Conversation

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Description

This addresses the failing test (ubuntu-latest, 3.13) job caused by test_balancing_learner[Learner2D-ring_of_fire-learner_kwargs2]. The failure came from state leaking across restore(...) boundaries, eventually leaving Learner2D with too few points during stack fill.

  • Root cause

    • Learner2D.__getstate__ returned live mutable objects (_stack, data), so temporary mutations made during BalancingLearner.ask(..., tell_pending=False) were not fully isolated.
  • Code change

    • Learner2D.__getstate__ now snapshots _stack and data via deep copies to guarantee rollback correctness when used with restore(...).
  • Regression coverage

    • Added a focused test asserting that Learner2D stack/data are unchanged after BalancingLearner.ask(1, tell_pending=False).
def __getstate__(self):
    return (
        cloudpickle.dumps(self.function),
        self.bounds,
        self.loss_per_triangle,
        deepcopy(self._stack),
        deepcopy(self._get_data()),
    )

Checklist

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

Type of change

Check relevant option(s).

  • 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

Copilot AI changed the title [WIP] Fix the failing GitHub Actions job "test (ubuntu-latest, 3.13)" Fix Learner2D state rollback in BalancingLearner ask(tell_pending=False) Jun 10, 2026
Copilot AI requested a review from basnijholt June 10, 2026 16:05
Key-level mutations (stack pops/inserts) are all that restore() needs to
roll back; values are never mutated in place. A deepcopy of the full
data dict would add O(npoints) allocation to every
ask(tell_pending=False) call and to pickling.
@basnijholt basnijholt marked this pull request as ready for review June 10, 2026 22:45
@basnijholt basnijholt merged commit 5814aa0 into main Jun 10, 2026
17 of 18 checks passed
@basnijholt basnijholt deleted the copilot/fix-failing-github-actions-job branch June 10, 2026 22:45
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