Enable free threaded python support - #159
vlad-perevezentsev wants to merge 37 commits into
Conversation
…o enable-free-threaded-python
|
|
||
| def test_concurrent_sampling_per_instance(): | ||
| # Each thread owns a private MKLRandomState seeded identically, so the | ||
| # per-instance lock + `nogil` sampling must reproduce the single-threaded |
There was a problem hiding this comment.
Each thread builds its own MKLRandomState — no shared state, so it passes with or without the per-instance lock. Fine as an instance-independence smoke test, but the docstring's "exercises the per-instance lock" claim is misleading.
| k, rounds, seed = 32, 20, 777 | ||
| rs = mkl_random.MKLRandomState(seed) | ||
| rs.seed(seed) | ||
| ref = Counter(repr(call(rs)) for _ in range(k)) |
There was a problem hiding this comment.
For the multinomial and mvn_cholesky params repr truncates precision, weakening race detection for those two
| assert r.shape == (size,) | ||
| assert np.all(np.isfinite(r)) |
There was a problem hiding this comment.
Assertions are too weak. A data race that interleaves stream updates still produces finite floats in [0,1), so the corruption passes.
| np.testing.assert_array_equal(r, expected) | ||
|
|
||
|
|
||
| def test_concurrent_shared_singleton(): |
There was a problem hiding this comment.
Not FT-gated. On a GIL build it runs as a pure no-op smoke test (the GIL serializes it anyway), giving false confidence.
| np.testing.assert_array_equal(r, expected) | ||
|
|
||
|
|
||
| def test_concurrent_shared_singleton(): |
There was a problem hiding this comment.
No barrier — unlike _draw_concurrently, the threads aren't released together, so contention on the stream-touching region is minimal and the race window is barely exercised.
ndgrigorian
left a comment
There was a problem hiding this comment.
This LGTM, thank you @vlad-perevezentsev
This PR proposes enabling free-threaded Python support in
mkl_randomand makes the RNG safe for concurrent usemklrandwith# cython: freethreading_compatible=Trueso importing the package no longer re-enables the GIL.Cython>=3.1.0(pyproject.toml, conda recipes, README) and addFree Threading :: 2 - Beta classifierpython-gilpin from the conda recipes.free-threading testand3.14t / *_cp314tvariants to the GH workflow matricessize=Nonedraws,multinomial,multinormal_cholesky,shuffle,seed,randinthelpers), fix re-entrancy deadlocks and aget_stateheap overflow on concurrent BRNG changeAdditionally, fixed memory leaks in
set_state(4a0fb51) andlogseries(548d625)