-
Notifications
You must be signed in to change notification settings - Fork 36
ENH: Free threading support #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
HaoZeke
wants to merge
14
commits into
bodono:master
Choose a base branch
from
HaoZeke:freethreading
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
19a486f
CI: Start testing freethreaded builds
HaoZeke f6c3713
TST: Add a few free threaded examples
HaoZeke 8d893bd
CI: Cleanup ft tests
HaoZeke a574662
MAINT: Start declaring FT support
HaoZeke 5896159
CI: Pass even without subrepo
HaoZeke 3d44153
TMP: Remove all non-ft CI for now
HaoZeke 4f16bfe
MAINT: Use pytest options for testpaths
HaoZeke f4b56de
MAINT: Add a baseline trove classifier
HaoZeke e58c2d9
MAINT: Lock self around warm starts and solve
HaoZeke 5643287
ENH: Lock before all calls into the scs library
HaoZeke f0432de
ENH: Hold per object locks
HaoZeke e1e84a4
CI: Stop doubling time taken
HaoZeke d37d114
TST: Drop precision for random cone problems
HaoZeke faaf870
MAINT: Refactor for clarity
HaoZeke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Free Threading Tests | ||
on: [push, pull_request] | ||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
- name: Grab pythoncapi-compat | ||
run: git clone --depth 1 https://github.com/python/pythoncapi-compat scs/pythoncapi-compat | ||
- name: Install uv and set the python version | ||
uses: astral-sh/setup-uv@v6 | ||
with: | ||
python-version: 3.13t | ||
activate-environment: true | ||
enable-cache: false | ||
- name: Set up Python | ||
run: uv python install | ||
- name: Install OpenBLAS | ||
run: | | ||
sudo apt update | ||
sudo apt install -y libopenblas-dev | ||
- name: Install Dependencies | ||
run: | | ||
uv pip install numpy scipy pytest-timeout pytest-durations pytest-run-parallel | ||
- name: Build | ||
run: | | ||
uv pip install -v . | ||
- name: Run Tests | ||
run: | | ||
set -xe | ||
uv run --no-project python -m pytest --parallel-threads=4 --iterations=1 -v -s --timeout=600 --durations=10 -m "not thread_unsafe" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ version = "3.2.7" | |
description = 'Splitting conic solver' | ||
readme = 'README.md' | ||
requires-python = '>=3.7' | ||
classifiers = [ | ||
'Programming Language :: Python :: Free Threading :: 1 - Unstable', | ||
] | ||
license = {file = 'LICENSE'} | ||
authors = [ | ||
{name = "Brendan O'Donoghue", email = "[email protected]"}] | ||
|
@@ -80,3 +83,8 @@ inherit.before-all = "append" | |
before-all = [ | ||
# "apk update", "apk search -v '*blas*'", | ||
"apk add openblas-dev"] | ||
|
||
[tool.pytest.ini_options] | ||
testpaths = [ | ||
"test", | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the GIL protect against the race you're worried about here? If not then you should lock on the GIL-enabled build too. It'd be nice to have an explicit test case for this fix if you don't already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general idea here was to lock before
Py_BEGIN_ALLOW_THREADS
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since its the initialization call, yes, it is covered by tests :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh oops, I completely missed that this is happening inside
SCS_init
. In that case locking probably isn't necessary, unless it's somehow possible for two threads to simultaneously see the sameSCS
object beforeSCS_init
returns an initialized object.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still a bit unclear about this. The guarantee with the lock is that there can be no two python threads trying to call
scs_init
(the external library) at the same time...This is the general pattern of locks around calls to
scs
.Under the free threading build without the lock isn't it possible for two threads to try to create
scs
objects at the same time thereby simultaneously calling into the external library? Or is the point that since the lock is on the object which hasn't been initialized yet it is meaningless anyway (or needs a global lock)?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we need to make a distinction between
scs_init
andSCS_init
. The latter is thetp_init
slot forSCS_Type
- it's the function that we're inside of in this comment thread.A Python object is effectively thread-local while it's under construction. Said another way, there's no way for another thread to have a handle on the
SCS
instance beforeSCS_init
completes.