Skip to content

ci: build and publish PyPI wheels with cibuildwheel - #338

Closed
hrushikesh-s wants to merge 1 commit into
alamode-code:masterfrom
hrushikesh-s:pypi-wheels
Closed

hrushikesh-s wants to merge 1 commit into
alamode-code:masterfrom
hrushikesh-s:pypi-wheels

Conversation

@hrushikesh-s

Copy link
Copy Markdown
Contributor

@ttadano, following up on #335, this PR adds wheels for PyPI, so pip install "alamode[openmpi]" works without a compiler or conda..

What changed (no changes to the C++ code)
-- .github/workflows/wheels.yml (new): builds the wheels with cibuildwheel on Linux x86_64, Linux aarch64, and macOS arm64, and uploads them to PyPI when a release is published. It runs on every push and PR like the other workflows, and is skipped on alamode-developer
-- python/pyproject.toml: the cibuildwheel settings and an openmpi extra --> anphon uses Open MPI, the same as the conda package, and the extra installs it from PyPI
-- python/CMakeLists.txt: STABLE_ABI, as your comment there describes, so one wheel covers Python 3.12 and later, plus a separate 3.11 wheel
-- python/anphon/__init__.py: the wheels do not include libmpi, so if the import fails because libmpi is not found, anphon loads the one that the openmpi wheel or conda puts in <prefix>/lib
-- python/LICENSE.txt: a symlink to LICENSE.txt, so the license is included in the wheels
-- docs: a short section on the wheels in python_api.rst, and the "pip wheels with MPI" line removed from anphon_python.rst

How it was tested
-- on each platform, CI builds the alm and anphon CLIs with the same compiler and libraries as the wheels, installs each wheel, and runs tools/tests with no skipped tests plus the mpirun -np 2 anphon tests, like tools_tests.yaml. The CLIs are built there because the tests compare the Python API with them bit for bit

Platform Python 3.11 3.12 3.13 3.14
Linux x86_64 154 + 4 passed 154 + 4 passed 154 + 4 passed 154 + 4 passed
Linux aarch64 154 + 4 passed 154 + 4 passed 154 + 4 passed 154 + 4 passed
macOS arm64 154 + 4 passed 154 + 4 passed 154 + 4 passed 154 + 4 passed

(154 = tools/tests, 4 = mpirun -np 2 tests)
-- the SrTiO3 SCPH example (example/SrTiO3/reference/scph.in) on one Perlmutter CPU node, with 64 MPI ranks and Open MPI from PyPI (after the LD_LIBRARY_PATH step in the docs), gives the same scph_bands as the reference file, within its printed precision (1e-4 cm^-1)
-- atomate2 installs together with the wheel without conflicts

A few things for you to decide..

  1. PyPI upload: the workflow uses trusted publishing, so no token is stored. You would add a pending publisher on pypi.org (owner alamode-code, repository alamode, workflow wheels.yml, environment pypi) and create a pypi environment in the repo settings. The v2.0.0 tag does not have this workflow, so the first upload would need a new release, e.g. 2.0.1, with the version updated in python/pyproject.toml and in the fallback versions in alm/__init__.py and anphon/__init__.py. You may want to try it on test.pypi.org first
  2. Besides LICENSE.txt, the wheels bundle OpenBLAS, HDF5, libaec, and the GCC runtime libraries on Linux, and HDF5, libaec, libomp, and spglib on macOS. Should I add their license texts to the wheels, as numpy and h5py do, before the first release?
  3. python/pyproject.toml has no readme, so the PyPI page would have no description. Should I add a short README in python/?
  4. There is no sdist for now, since python/ alone does not contain ../alm and ../anphon. Is that ok with you?
  5. block_indirect_sort was added in Boost 1.67 (it is not in boost-1.66.0), so the >= 1.66 checks in alm/, anphon/, and python/CMakeLists.txt are too low. Should I raise them to 1.67 in a separate PR?
  6. The docs workflow deploys on merge, so the new docs section would mention the wheels before the first upload. Would you prefer to merge just before the release?
  7. Should I add a line about the wheels to ChangeLog.md?

Notes
-- the wheels are for Python 3.11 and later, since 3.10 reaches its end of life this month. requires-python stays as it is for source builds
-- the macOS wheels need macOS 15 or later, since the Homebrew libraries on the macOS 15 runner are built for it
-- on Cray machines, Cray's libfabric on LD_LIBRARY_PATH is loaded before the one inside the openmpi wheel, so the docs give a one-line workaround

Please let me know if you would prefer anything done differently..

@ttadano

ttadano commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Thank you very much for this careful work, and for the testing on all three platforms.

Following the contribution rule we recently added to the README, I am taking the change over
rather than merging the pull request directly. Your commit is cherry-picked with you as its
author, and it will ship in 2.0.2, a packaging-only release. I will close this pull request
with a pointer to that release, and you will be credited in the ChangeLog.

Answers to your questions:

  1. Trusted publishing: yes. I will set up the publisher on PyPI and the pypi environment,
    and try TestPyPI first. The first upload will be 2.0.2.
  2. License texts of the bundled libraries: yes. I have added a file with them
    (python/LICENSES_bundled.txt), based on your list: OpenBLAS, HDF5, libaec and the GCC
    runtime on Linux; HDF5, libaec, libomp and spglib on macOS. It would be great if you could
    check it against your wheels once the pull request for 2.0.2 is up.
  3. README for PyPI: yes, I have added a short one in python/.
  4. No sdist for now: fine.
  5. Boost 1.67: you are right, block_indirect_sort is not in 1.66. I have raised the
    requirement in the CMake files and the documentation.
  6. Documentation: it reaches master only with the release, so the new section will appear
    together with the wheels.
  7. ChangeLog: I will add a line under "Build / packaging".

I also made a few adjustments on top of your commit:

  • The workflow no longer runs on every push. It runs for pull requests that touch the Python
    package, the C++ sources or the workflow, for a published release, and by hand, with an
    optional upload to TestPyPI.
  • When Open MPI is missing, importing anphon now says how to install it.
  • A build option to leave out the alm module, which the conda-forge packages need.

These are in our development branch for now. You will be able to see them in the pull request
for 2.0.2, which I will link here.

@ttadano ttadano mentioned this pull request Nov 16, 2026
@ttadano

ttadano commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

The wheels are now published: ALAMODE 2.0.2 is on PyPI as alamode-python (pip install "alamode-python[openmpi]"), built by the workflow from this pull request.

Your commit went in through #343, with your authorship kept, together with the follow-up changes (distribution name, license files, Python >= 3.11, trusted publishing). The release notes are at https://github.com/alamode-code/alamode/releases/tag/v2.0.2.

Closing this pull request since its content is merged. Thank you for the contribution.

@ttadano ttadano closed this Nov 16, 2026
@hrushikesh-s

Copy link
Copy Markdown
Contributor Author

Thanks @ttadano!

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