Skip to content

Commit e0f5363

Browse files
committed
Refactor release workflow and update project metadata for improved build process and licensing clarity
1 parent 09c3935 commit e0f5363

3 files changed

Lines changed: 148 additions & 12 deletions

File tree

.github/workflows/release.yml

Lines changed: 141 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,164 @@
1-
name: publish-sdist
1+
name: release
22

33
on:
44
push:
55
tags:
66
- "v*"
7+
workflow_dispatch:
78

89
jobs:
9-
publish:
10+
sdist:
11+
name: Build sdist
1012
runs-on: ubuntu-latest
1113
permissions:
1214
contents: read
13-
id-token: write
1415
steps:
1516
- uses: actions/checkout@v4
1617

1718
- uses: actions/setup-python@v5
1819
with:
1920
python-version: "3.12"
2021

21-
- name: Install system deps
22+
- name: Build source distribution
2223
run: |
23-
sudo apt-get update
24-
sudo apt-get install -y libfftw3-dev cmake ninja-build pkg-config
24+
python -m pip install -U pip build
25+
python -m build -s
26+
27+
- name: Upload sdist
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: dist-sdist
31+
path: dist/*
32+
33+
wheels-linux:
34+
name: Build Linux wheels (x86_64, aarch64)
35+
runs-on: ubuntu-latest
36+
permissions:
37+
contents: read
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Build wheels with cibuildwheel
42+
uses: pypa/cibuildwheel@v2.21.3
43+
env:
44+
# CPython versions to build (match CI tests)
45+
CIBW_BUILD: cp310-* cp311-* cp312-*
46+
CIBW_SKIP: pp* *-musllinux_*
47+
CIBW_ARCHS_LINUX: x86_64 aarch64
48+
# Build FFTW from source and stage Boost headers for CMake
49+
CIBW_BEFORE_ALL_LINUX: |
50+
set -eux
51+
# Ensure pkg-config is present in the manylinux container
52+
if command -v yum >/dev/null 2>&1; then
53+
yum -y install pkgconfig || true
54+
fi
55+
FFTW_V=3.3.10
56+
curl -fsSL -o fftw.tar.gz http://www.fftw.org/fftw-${FFTW_V}.tar.gz
57+
tar -xzf fftw.tar.gz
58+
pushd fftw-${FFTW_V}
59+
./configure --prefix=/opt/fftw --enable-shared --enable-threads
60+
make -j"$(nproc)"
61+
make install
62+
popd
63+
64+
# Boost headers (header-only; no build needed)
65+
BOOST_V=1_84_0
66+
curl -fsSL -o boost.tar.bz2 https://boostorg.jfrog.io/artifactory/main/release/1.84.0/source/boost_${BOOST_V}.tar.bz2
67+
tar -xjf boost.tar.bz2
68+
mkdir -p /opt/boost/include
69+
cp -r boost_${BOOST_V}/boost /opt/boost/include/
70+
71+
# Help CMake find FFTW via pkg-config and Boost headers via define
72+
CIBW_ENVIRONMENT_LINUX: >
73+
PKG_CONFIG_PATH=/opt/fftw/lib/pkgconfig
74+
CMAKE_PREFIX_PATH=/opt/fftw
75+
CMAKE_ARGS="-DHF_USE_OPENMP=ON -DHF_USE_FFTW_THREADS=ON -DBOOST_INCLUDE_DIR=/opt/boost/include"
76+
77+
# Quick import + tiny run test inside the wheel env
78+
CIBW_TEST_COMMAND: >
79+
python - <<'PY'
80+
import numpy as np, cpp_hf
81+
nk,d=4,2
82+
w=np.ones((nk,nk))*((2/nk)*(2/nk)/(2*np.pi)**2)
83+
H=np.zeros((nk,nk,d,d),np.complex128)
84+
K=np.linspace(-1,1,nk)
85+
V=(1.0/np.sqrt((K[:,None]**2+K[None,:]**2)+0.2)).astype(np.complex128)[...,None,None]
86+
P0=np.zeros_like(H)
87+
ne=0.5*d*w.sum()
88+
P,F,E,mu,n=cpp_hf.hartreefock_iteration_cpp(w,H,V,P0,ne,0.2,1,1e-2,2,1.0)
89+
print("wheel ok", int(n), float(mu))
90+
PY
91+
92+
- name: Upload Linux wheels
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: dist-wheels-linux
96+
path: wheelhouse/*
97+
if-no-files-found: error
2598

26-
- name: Build distribution (sdist)
99+
wheels-macos:
100+
name: Build macOS wheels (Intel/Apple Silicon)
101+
strategy:
102+
fail-fast: false
103+
matrix:
104+
runner: [macos-13, macos-14]
105+
runs-on: ${{ matrix.runner }}
106+
permissions:
107+
contents: read
108+
steps:
109+
- uses: actions/checkout@v4
110+
111+
- name: Install Homebrew deps
27112
run: |
28-
python -m pip install -U pip build numpy scikit-build-core
29-
python -m build -s
113+
brew update
114+
brew install fftw libomp boost cmake ninja pkg-config || true
115+
116+
- name: Build wheels with cibuildwheel
117+
uses: pypa/cibuildwheel@v2.21.3
118+
env:
119+
CIBW_BUILD: cp310-* cp311-* cp312-*
120+
CIBW_SKIP: pp*
121+
# Let cibuildwheel build for the host arch on each runner
122+
CIBW_ARCHS_MACOS: native
123+
# Ensure pkg-config sees Homebrew's .pc files across both arch locations
124+
CIBW_ENVIRONMENT_MACOS: >
125+
PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig:/usr/local/lib/pkgconfig
126+
CMAKE_ARGS="-DHF_USE_OPENMP=ON -DHF_USE_FFTW_THREADS=ON"
127+
CIBW_TEST_COMMAND: >
128+
python - <<'PY'
129+
import numpy as np, cpp_hf
130+
nk,d=4,2
131+
w=np.ones((nk,nk))*((2/nk)*(2/nk)/(2*np.pi)**2)
132+
H=np.zeros((nk,nk,d,d),np.complex128)
133+
K=np.linspace(-1,1,nk)
134+
V=(1.0/np.sqrt((K[:,None]**2+K[None,:]**2)+0.2)).astype(np.complex128)[...,None,None]
135+
P0=np.zeros_like(H)
136+
ne=0.5*d*w.sum()
137+
P,F,E,mu,n=cpp_hf.hartreefock_iteration_cpp(w,H,V,P0,ne,0.2,1,1e-2,2,1.0)
138+
print("wheel ok", int(n), float(mu))
139+
PY
140+
141+
- name: Upload macOS wheels
142+
uses: actions/upload-artifact@v4
143+
with:
144+
name: dist-wheels-${{ matrix.runner }}
145+
path: wheelhouse/*
146+
if-no-files-found: error
147+
148+
publish:
149+
name: Publish to PyPI
150+
needs: [sdist, wheels-linux, wheels-macos]
151+
runs-on: ubuntu-latest
152+
permissions:
153+
contents: read
154+
id-token: write
155+
steps:
156+
- name: Download all artifacts
157+
uses: actions/download-artifact@v4
158+
with:
159+
pattern: dist-*
160+
merge-multiple: true
161+
path: dist
30162

31163
- name: Publish to PyPI via OIDC (Trusted Publisher)
32164
uses: pypa/gh-action-pypi-publish@release/v1

cpp_hf_module.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,16 @@ struct HFKernel {
521521

522522
if (v_is_scalar) {
523523
#ifdef _OPENMP
524-
#pragma omp parallel for collapse(3) schedule(static)
524+
// GCC requires strictly nested loops for collapse; use collapse(2) and SIMD on inner loop
525+
#pragma omp parallel for collapse(2) schedule(static)
525526
#endif
526527
for (long long k1=0;k1<(long long)nk1;++k1)
527528
for (long long k2=0;k2<(long long)nk2;++k2) {
528529
const cxd v = Vhat_scalar[(size_t)k1*nk2 + (size_t)k2];
529530
const size_t base = (((size_t)k1*nk2 + (size_t)k2) * d) * d;
531+
#ifdef _OPENMP
532+
#pragma omp simd
533+
#endif
530534
for (long long t=0; t<(long long)(d*d); ++t)
531535
scratch_fft[base + (size_t)t] *= v;
532536
}

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ description = "Hartree–Fock (k-grid) with FFTW + Eigen via pybind11"
99
readme = "Readme.md"
1010
requires-python = ">=3.8"
1111
authors = [{name = "ContiMod contributors"}]
12-
license = {text = "MIT License"}
12+
license = {file = "LICENSE"}
1313
keywords = ["hartree-fock", "fftw", "eigen", "pybind11", "condensed-matter", "physics"]
1414
classifiers = [
15-
"License :: OSI Approved :: MIT License",
15+
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
1616
"Programming Language :: Python",
1717
"Programming Language :: Python :: 3",
1818
"Programming Language :: C++",

0 commit comments

Comments
 (0)