Skip to content
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

Hopefully fixes builds on 3.12. #70

Merged
merged 56 commits into from
Nov 3, 2023
Merged

Hopefully fixes builds on 3.12. #70

merged 56 commits into from
Nov 3, 2023

Conversation

enzbus
Copy link
Contributor

@enzbus enzbus commented Oct 7, 2023

Turns out extra numpy.distutils.get_info args were superflous, at least for plain builds.

Turns out extra numpy.distutils.get_info args were superflous, at least for plain builds.
@enzbus enzbus mentioned this pull request Oct 7, 2023
@enzbus enzbus closed this Oct 7, 2023
@bodono
Copy link
Owner

bodono commented Oct 7, 2023

Thanks for doing this Enzo! Does this still pick up the right blas / lapack libraries to link against?

@bodono bodono reopened this Oct 7, 2023
@enzbus
Copy link
Contributor Author

enzbus commented Oct 7, 2023 via email

@enzbus
Copy link
Contributor Author

enzbus commented Oct 7, 2023

Confirmed, linking was broken already. On python 3.11, clean environment.

pip install scs
otool -L env/lib/python3.11/site-packages/_scs_indirect.cpython-311-darwin.so 

gives:

env/lib/python3.11/site-packages/_scs_indirect.cpython-311-darwin.so:
	@loader_path/scs/.dylibs/libopenblasp-r0.3.21.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)

While if I compile from source (inside scs-python)

pip install .
otool -L env/lib/python3.11/site-packages/_scs_indirect.cpython-311-darwin.so 

gives

env/lib/python3.11/site-packages/_scs_indirect.cpython-311-darwin.so:
	/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)

on Mac amd64.

Copy link
Contributor

@rgommers rgommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty close already

meson.build Outdated Show resolved Hide resolved
meson.build Outdated Show resolved Hide resolved
meson.build Outdated
'''
],
check: true
).stdout().strip()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the one annoying thing you have to do indeed - I will get around to replacing all this with a simple dependency('numpy') at some point.

For now, I'd recommend to include the relpath bit from SciPy: https://github.com/scipy/scipy/blob/166e1f2b1ea0a1a2c3d7b030bd829549f8a5844a/scipy/meson.build#L54-L57

That will ensure things work fine with an in-tree virtual environment (so numpy is inside your source tree from Meson's perspective).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I guess fixed (there are more try/except there that I don't understand).

@bodono
Copy link
Owner

bodono commented Oct 8, 2023

Confirmed, linking was broken already. On python 3.11, clean environment.

pip install scs
otool -L env/lib/python3.11/site-packages/_scs_indirect.cpython-311-darwin.so 

gives:

env/lib/python3.11/site-packages/_scs_indirect.cpython-311-darwin.so:
	@loader_path/scs/.dylibs/libopenblasp-r0.3.21.dylib (compatibility version 0.0.0, current version 0.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.100.1)

While if I compile from source (inside scs-python)

pip install .
otool -L env/lib/python3.11/site-packages/_scs_indirect.cpython-311-darwin.so 

gives

env/lib/python3.11/site-packages/_scs_indirect.cpython-311-darwin.so:
	/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate (compatibility version 1.0.0, current version 4.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)

on Mac amd64.

Yes I also noticed that SCS was much slower from pip than when compiling locally, but I haven't had the bandwidth to investigate it unfortunately!

@bodono
Copy link
Owner

bodono commented Oct 8, 2023

Thanks again for looking at this @enzbus and @rgommers ! Fingers crossed this works and can replace the very hacky code that was there before.

@enzbus
Copy link
Contributor Author

enzbus commented Oct 8, 2023

@bodono @rgommers, current status: Basic build works, but there's no linking to blas in the compiled, so I'm probably not giving the right argument to py.extension_module. Also, right now pip installs _scs_direct.so but not the scs/__init__.py that is required to use it. Any hint?

@rgommers
Copy link
Contributor

rgommers commented Oct 8, 2023

I'm just working on BLAS/LAPACK improvements in NumPy, so I can propose something. Rather than make it complicated now with 64-bit integer support (which seems incomplete?), the new Accelerate version for macOS >=13.3 (see note here), etc., maybe do only the basic setup first. Once NumPy has shipped the fancy version (auto-detect every option, full ILP64, switches for order of preference of known libraries, etc.) it can then be updated to mirror NumPy.

Sounds like you want regular 32-bit Accelerate on macOS preferably? And OpenBLAS or MKL elsewhere?

@rgommers
Copy link
Contributor

rgommers commented Oct 8, 2023

but not the scs/__init__.py that is required to use it

You are missing a py.install_sources() to specify what to install - see at the bottom of numpy/scipy's meson.build files for examples. Alternatively, if you have a subdir with no compiled code and you want to install everything in that subdir, you can use install_subdir().

@enzbus
Copy link
Contributor Author

enzbus commented Oct 8, 2023

I'm just working on BLAS/LAPACK improvements in NumPy, so I can propose something. Rather than make it complicated now with 64-bit integer support (which seems incomplete?), the new Accelerate version for macOS >=13.3 (see note here), etc., maybe do only the basic setup first. Once NumPy has shipped the fancy version (auto-detect every option, full ILP64, switches for order of preference of known libraries, etc.) it can then be updated to mirror NumPy.

Sounds like you want regular 32-bit Accelerate on macOS preferably? And OpenBLAS or MKL elsewhere?

That would be great, and I guess it can be done by if/else on dependency.found(). I'm just trying to get a basic build now, and it's not linking BLAS after giving this output to meson compile

Program python3 found: YES (/usr/local/opt/[email protected]/bin/python3.11)
Library openblas found: NO
Library blas found: YES
Library cblas found: YES

Thoughts? And thanks!!

@rgommers
Copy link
Contributor

rgommers commented Oct 8, 2023

I just tried meson setup build in my default SciPy dev env and got:

...
Program python3 found: YES (/home/rgommers/mambaforge/envs/scipy-dev/bin/python3.10)
Library openblas found: YES
Found pkg-config: /home/rgommers/mambaforge/envs/scipy-dev/bin/pkg-config (0.29.2)
Build targets in project: 2

You probably don't have pkg-config installed? What's happening is that for dependency('pkgname'), when Meson isn't aware of and has special handling for pkgname, it queries first pkg-config and then CMake to detect the dependency.

The better way to control this is via the `-Dbuildtype=` Meson build
option. The default for meson-python is `release`, which means
debug=False, optimization=3
@enzbus
Copy link
Contributor Author

enzbus commented Nov 2, 2023

@bodono : status. Blas is linked statically when building on github CI (via a meson option passed to the command line). Still no luck for windows, but I think we're super close. If someone has a windows development machine they can probably fix it easily, see lines 20-31 of meson.build. If I were you I would start shipping Linux/Mac packages (or at least the source distribution), for example by:

Here's how you do it. Install brew (or whatever, to get a python3.12 -> https://docs.brew.sh/Installation)

brew install [email protected]
git clone https://github.com/enzbus/scs-python
cd scs-python
git submodule update --init
python3.12 -m venv env
source env/bin/activate
pip install .
pip install pytest
pytest
pip install build
python -m build
pip install twine
twine check dist/*
twine upload --skip-existing dist/*

@enzbus
Copy link
Contributor Author

enzbus commented Nov 2, 2023

It builds and tests on windows!!! @rgommers have a look, we're using the same technique @bodono devised , with a few meson tweaks :)

@bodono
Copy link
Owner

bodono commented Nov 2, 2023

Amazing work @enzbus ! Thanks again for doing this, drinks on me next time you're in London!

Copy link
Contributor

@rgommers rgommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! This looks quite good to me - just one comment to help users a bit more when they are building from source and something goes wrong in BLAS detection.

meson.build Outdated
endif

# We find anaconda blas on windows for github CI
if not blas_deps[0].found()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is specific to the CI setup for building Windows wheels, and won't work in case users attempt to build from source on Windows for some reason. That may or may not matter to you, but it's probably appropriate to at least emit a warning with message("explain-that-blas-wasn't-found-and-this-is-for-CI-only") here?

Also, you may want to change this line to

if host_machine.system() == 'windows' and not blas_deps[0].found()
    ....

else
    error('OpenBLAS or Netlib BLAS/CBLAS is required on all platforms except Windows, and was not found.')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'm thinking of refactoring it: passing anaconda lib folder location as a meson option in the CI file, so the meson.build is not tailored for the compilation process on github.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense to me. You can do it as a CLI option, or you can craft an openblas.pc file which points to the right paths in a CI job and then add the directory of that .pc file to PKG_CONFIG_PATH. For the latter approach, see http://scipy.github.io/devdocs/building/blas_lapack.html#using-pkg-config-to-detect-libraries-in-a-nonstandard-location.

meson.build Outdated
error('Missing the `scs_source` submodule! Run `git submodule update --init` to fix this.')
endif

# This uses the path as is, and avoids running the interpreter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: this comment is a left-over and doesn't apply, so best to clean it up.

meson.build Outdated
c_args = cc.get_supported_arguments('-Wno-unused-result')

# meson doesn't support wildcards
# https://mesonbuild.com/FAQ.html#why-cant-i-specify-target-files-with-a-wildcard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably can be cleaned up as well now?

@bodono
Copy link
Owner

bodono commented Nov 2, 2023

It looks like the github runners are no longer able to schedule on macos-10.15, I think we can change that to macos-latest, which should schedule easier and hopefully run successfully now. I can do it in a PR that you can merge, or you can do it here if you prefer.

@enzbus
Copy link
Contributor Author

enzbus commented Nov 3, 2023

It looks like the github runners are no longer able to schedule on macos-10.15, I think we can change that to macos-latest, which should schedule easier and hopefully run successfully now. I can do it in a PR that you can merge, or you can do it here if you prefer.

OK, that explains why the MacOS jobs weren't running. As you prefer, I have limited time but would like to clean it a bit (it doesn't seem urgent, nobody replied on cvxpy/cvxpy#2269 ). Ideally we can also migrate the optional builds (openmp, cuda) to meson and reduce the size of the github yaml file. (We only need conda for installing openblas on windows, etc.) Just a note, meson doesn't support python <= 3.7, so if we eliminate the old setup.py we'll have to drop python 3.7 (but the wheels and source dists will remain on PyPI).

@rgommers
Copy link
Contributor

rgommers commented Nov 3, 2023

Just a note, meson doesn't support python <= 3.7, so if we eliminate the old setup.py we'll have to drop python 3.7 (but the wheels and source dists will remain on PyPI).

In practice that makes it harder to do Python 3.5-3.6, but not impossible. Meson by design does not depend on it being implemented in Python, it has its own DSL and you invoke it via a meson executable that's on PATH. So it is possible to install Meson in, say, a Python 3.11 env, prepend its bin directory to PATH, and then use it in a non-isolated build from an env with an older Python version.

That said, meson-python is tied to Python version too (and is at >=3.7), and avoiding that constraint is much harder. So in practice, yes, >=3.7 is the limit now.

@bodono
Copy link
Owner

bodono commented Nov 3, 2023

All checks have passed! I will merge as soon as you let me know it's ready @enzbus .

@enzbus
Copy link
Contributor Author

enzbus commented Nov 3, 2023

Ok, @bodono, I approve too. Please go on and merge, hopefully there won't be issues when the final build and upload is triggered.

@bodono bodono merged commit a72909b into bodono:master Nov 3, 2023
47 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.

3 participants