Add mixers and utility functions for DIIS, EDIIS, and Broyden mixing … #16
Workflow file for this run
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
| name: release | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| jobs: | |
| sdist: | |
| name: Build sdist | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Build source distribution | |
| run: | | |
| python -m pip install -U pip build | |
| python -m build -s | |
| - name: Upload sdist | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-sdist | |
| path: dist/* | |
| if-no-files-found: error | |
| # ----- Linux (native x86_64 + native aarch64) ----- | |
| wheels-linux: | |
| name: Build Linux wheels (${{ matrix.arch }}) | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - arch: x86_64 | |
| runner: ubuntu-latest | |
| image_var: CIBW_MANYLINUX_X86_64_IMAGE | |
| - arch: aarch64 | |
| runner: ubuntu-24.04-arm | |
| image_var: CIBW_MANYLINUX_AARCH64_IMAGE | |
| runs-on: ${{ matrix.runner }} | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Restore ccache | |
| uses: actions/cache@v4 | |
| with: | |
| path: .ccache | |
| key: ccache-linux-${{ matrix.arch }}-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake', '**/*.cpp', '**/*.h', 'pyproject.toml') }} | |
| - name: Build wheels with cibuildwheel (${{ matrix.arch }}) | |
| uses: pypa/cibuildwheel@v2.21.3 | |
| env: | |
| CIBW_BUILD: cp310-* cp311-* cp312-* | |
| CIBW_SKIP: pp* *-musllinux_* | |
| CIBW_ARCHS_LINUX: ${{ matrix.arch }} | |
| ${{ matrix.image_var }}: manylinux_2_28 | |
| # Install build tools + FFTW + Boost headers; robust ccache fallback (pkg -> prebuilt -> source) | |
| CIBW_BEFORE_ALL_LINUX: | | |
| set -eux | |
| pm_install() { | |
| if command -v dnf >/dev/null 2>&1; then | |
| dnf -y install pkgconfig ninja-build unzip make which curl ca-certificates xz tar gzip cmake gcc-c++ fftw fftw-devel boost-devel libzstd libzstd-devel || true | |
| elif command -v yum >/dev/null 2>&1; then | |
| yum -y install pkgconfig ninja-build unzip make which curl ca-certificates xz tar gzip cmake gcc-c++ fftw fftw-devel boost-devel libzstd libzstd-devel || true | |
| elif command -v microdnf >/dev/null 2>&1; then | |
| microdnf -y install pkgconfig ninja-build unzip make which curl ca-certificates xz tar gzip cmake gcc-c++ fftw fftw-devel boost-devel libzstd libzstd-devel || true | |
| elif command -v apt-get >/dev/null 2>&1; then | |
| apt-get update -y | |
| apt-get install -y --no-install-recommends \ | |
| pkg-config ninja-build unzip make curl ca-certificates xz-utils tar gzip cmake g++ \ | |
| libfftw3-3 libfftw3-dev libboost-all-dev zstd libzstd-dev | |
| else | |
| echo "No supported package manager found" >&2 | |
| exit 1 | |
| fi | |
| } | |
| install_ccache() { | |
| # 1) Try package manager | |
| if command -v dnf >/devnull 2>&1; then dnf -y install ccache || true; fi | |
| if command -v yum >/devnull 2>&1; then yum -y install ccache || true; fi | |
| if command -v microdnf >/devnull 2>&1; then microdnf -y install ccache || true; fi | |
| if command -v apt-get >/devnull 2>&1; then apt-get install -y --no-install-recommends ccache || true; fi | |
| if command -v ccache >/dev/null 2>&1; then return 0; fi | |
| # 2) Try official prebuilt tarball | |
| ver="4.11.3" | |
| arch="$(uname -m)" | |
| url="https://github.com/ccache/ccache/releases/download/v${ver}/ccache-${ver}-linux-${arch}.tar.xz" | |
| if curl -fsSL "$url" -o /tmp/ccache.tar.xz; then | |
| mkdir -p /usr/local/ccache | |
| tar -xJf /tmp/ccache.tar.xz -C /usr/local/ccache --strip-components=1 | |
| ln -sf /usr/local/ccache/bin/ccache /usr/local/bin/ccache | |
| fi | |
| if command -v ccache >/dev/null 2>&1; then return 0; fi | |
| # 3) Build from source with CMake (last resort) | |
| src="4.11.3" | |
| tmpd="$(mktemp -d)" | |
| curl -fsSL "https://github.com/ccache/ccache/releases/download/v${src}/ccache-${src}.tar.gz" -o "${tmpd}/ccache.tar.gz" | |
| tar -xzf "${tmpd}/ccache.tar.gz" -C "${tmpd}" | |
| cmake -S "${tmpd}/ccache-${src}" -B "${tmpd}/build" -DCMAKE_BUILD_TYPE=Release | |
| cmake --build "${tmpd}/build" -j"$(nproc)" | |
| cmake --install "${tmpd}/build" | |
| ln -sf /usr/local/bin/ccache /usr/local/ccache/bin/ccache || true | |
| } | |
| pm_install | |
| install_ccache | |
| command -v ccache >/dev/null || { echo "ccache still missing"; exit 1; } | |
| CIBW_ENVIRONMENT_LINUX: > | |
| CC=gcc | |
| CXX=g++ | |
| CCACHE_DIR=/project/.ccache | |
| CMAKE_ARGS="-G Ninja -DHF_USE_OPENMP=ON -DHF_USE_FFTW_THREADS=ON -DBOOST_INCLUDEDIR=/usr/include -DCMAKE_CXX_COMPILER_LAUNCHER=ccache" | |
| CMAKE_BUILD_PARALLEL_LEVEL=$(nproc) | |
| CIBW_REPAIR_WHEEL_COMMAND_LINUX: > | |
| bash -lc 'auditwheel repair -w {dest_dir} {wheel}' | |
| CIBW_TEST_REQUIRES: numpy | |
| CIBW_TEST_COMMAND: | | |
| python - <<'PY' | |
| import numpy as np, cpp_hf | |
| nk,d=4,2 | |
| w=np.ones((nk,nk))*((2/nk)*(2/nk)/(2*np.pi)**2) | |
| H=np.zeros((nk,nk,d,d),np.complex128) | |
| K=np.linspace(-1,1,nk) | |
| V=(1.0/np.sqrt((K[:,None]**2+K[None,:]**2)+0.2)).astype(np.complex128)[...,None,None] | |
| P0=np.zeros_like(H) | |
| ne=0.5*d*w.sum() | |
| P,F,E,mu,n=cpp_hf.hartreefock_iteration_cpp(w,H,V,P0,ne,0.2,1,1e-2,2,1.0) | |
| print("wheel ok", int(n), float(mu)) | |
| PY | |
| - name: Upload Linux ${{ matrix.arch }} wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-wheels-linux-${{ matrix.arch }} | |
| path: wheelhouse/* | |
| if-no-files-found: error | |
| # ----- macOS (Intel/Apple Silicon) ----- | |
| wheels-macos: | |
| name: Build macOS wheels (Intel/Apple Silicon) | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| runner: [macos-13, macos-14] | |
| runs-on: ${{ matrix.runner }} | |
| env: | |
| MACOSX_DEPLOYMENT_TARGET: ${{ matrix.runner == 'macos-14' && '14.0' || '13.0' }} | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install Homebrew deps | |
| env: | |
| HOMEBREW_NO_AUTO_UPDATE: "1" | |
| run: | | |
| rm -f "$HOME/Library/Caches/Homebrew/downloads/"*libomp* || true | |
| brew install fftw libomp boost cmake ninja || true | |
| - name: Build wheels with cibuildwheel | |
| uses: pypa/cibuildwheel@v2.21.3 | |
| env: | |
| CIBW_BUILD: cp310-* cp311-* cp312-* | |
| CIBW_SKIP: pp* | |
| CIBW_ARCHS_MACOS: native | |
| CIBW_ENVIRONMENT_MACOS: > | |
| PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig:/usr/local/lib/pkgconfig | |
| CMAKE_ARGS="-DHF_USE_OPENMP=ON -DHF_USE_FFTW_THREADS=ON -DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}" | |
| CIBW_REPAIR_WHEEL_COMMAND_MACOS: > | |
| bash -lc 'delocate-listdeps -d {wheel} || true; MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET} delocate-wheel -L /opt/homebrew/lib -L /usr/local/lib --require-archs {delocate_archs} -w {dest_dir} -v {wheel}' | |
| CIBW_TEST_REQUIRES: numpy | |
| CIBW_TEST_COMMAND: | | |
| python - <<'PY' | |
| import numpy as np, cpp_hf | |
| nk,d=4,2 | |
| w=np.ones((nk,nk))*((2/nk)*(2/nk)/(2*np.pi)**2) | |
| H=np.zeros((nk,nk,d,d),np.complex128) | |
| K=np.linspace(-1,1,nk) | |
| V=(1.0/np.sqrt((K[:,None]**2+K[None,:]**2)+0.2)).astype(np.complex128)[...,None,None] | |
| P0=np.zeros_like(H) | |
| ne=0.5*d*w.sum() | |
| P,F,E,mu,n=cpp_hf.hartreefock_iteration_cpp(w,H,V,P0,ne,0.2,1,1e-2,2,1.0) | |
| print("wheel ok", int(n), float(mu)) | |
| PY | |
| - name: Upload macOS wheels | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-wheels-${{ matrix.runner }} | |
| path: wheelhouse/* | |
| if-no-files-found: error | |
| # ----- Publish to PyPI ----- | |
| publish: | |
| name: Publish to PyPI | |
| needs: [sdist, wheels-linux, wheels-macos] | |
| runs-on: ubuntu-latest | |
| environment: cpp_hf_env | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: dist-* | |
| merge-multiple: true | |
| path: dist | |
| - name: Publish to PyPI via OIDC (Trusted Publisher) | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| packages-dir: dist/ |