Skip to content

FIX: Fix thread-safety for adaptive_minmax#52

Merged
derb12 merged 4 commits intodevelopmentfrom
test_threading
Oct 21, 2025
Merged

FIX: Fix thread-safety for adaptive_minmax#52
derb12 merged 4 commits intodevelopmentfrom
test_threading

Conversation

@derb12
Copy link
Copy Markdown
Owner

@derb12 derb12 commented Oct 21, 2025

Description

This PR fixes some issues with the testing framework when using threading, as found by using pytest-run-parallel. The majority of the identified test failures were just false-positives within the tests themselves since they were written without considering repeated, concurrent runs. The one true bug was that adaptive_minmax was found to not be thread-safe in both 1D and 2D, and pointed to a flaw with how the test_threading tests worked for optimizer-type algorithms, as detailed below.

Before this PR, the BaseTester class used the underlying private categorical algorithm classes (eg. _Whittaker, _Optimizer, etc.), rather than the Baseline class to test each method. This is fine for most algorithms, and the BaseTester.test_threading test added by PR #33 correctly identified most of the thread-unsafe behavior within the Baseline and Baseline2D classes. However, for optimizer-type methods, this will not find any issues with threading because when getting the baseline method to use, _Optimizers will always spawn a new object with the desired method (eg. _Polynomial if method is 'modpoly') since they do not have those methods, which will always be thread-safe. In actual use, the Baseline class will always have the desired method and will not spawn a new object. By changing the BaseTester[2D] test classes to use Baseline[2D] instead of the private classes, the test_threading test then correctly failed for adaptive_minmax in both the 1D and 2D cases, even without having to use pytest-run-parallel.

This oversight in the testing framework was fixed, as well as the underlying threading issues for adaptive_minmax for both 1D and 2D.

Note that linting is expected to fail, those fixes are already in the optimize_lam branch.

Type of Pull Request

  • Bug Fix
  • New Feature
  • Miscellaneous Changes (refactor, code improvements, etc.)
  • Documentation or Example Programs

Pull Request Checklist

  • New code and/or documentation is valid for use with the BSD 3-clause license.
  • New code is fully documented with docstrings that follow Numpy style,
    if applicable.
  • New code follows PEP 8 standards as closely as possible, if applicable.
  • Added/updated tests and ensured they pass locally, if applicable.
  • Verified that documentation builds locally, if applicable.

@derb12 derb12 merged commit f1c944e into development Oct 21, 2025
9 of 11 checks passed
@derb12 derb12 deleted the test_threading branch October 21, 2025 23:08
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.

1 participant