Skip to main content

Hartree–Fock (k-grid) with FFTW + Eigen via pybind11

Project description

cpp_hf — Fast Hartree–Fock on k‑grids (FFTW + Eigen + pybind11)

PyPI Python Wheel License Release

cpp_hf provides a compiled extension module exposing a fast Hartree–Fock self‑consistent field (SCF) loop for uniform 2D k‑grids. It uses FFTW (batched 2D complex DFTs), Eigen (Hermitian eigendecompositions), and pybind11 to bind the C++ implementation to Python.

  • Batched 2D FFTs (FFTW guru interface)
  • Dense Hermitian diagonalization (Eigen)
  • EDIIS + Broyden mixing (robust convergence)
  • Simple, NumPy‑friendly API

This package is designed to interoperate with ContiMod, but it can be used on its own as a lightweight HF kernel.

Project links:

Installation

Quick install (prebuilt wheel if available):

pip install cpp-hf

Notes:

  • The import name is cpp_hf (underscore), even though the package name uses a hyphen.
  • Wheels may not be available for all platforms/Python versions yet; in that case pip will build from source.

Build from source (requirements):

  • Python 3.8+
  • A C++17 compiler
  • FFTW and headers (threads variant optional)
  • CMake ≥ 3.21

Build via pip (with optional CMake flags):

pip install . \
  -C cmake.define.HF_USE_OPENMP=ON \
  -C cmake.define.HF_USE_FFTW_THREADS=ON

macOS (Homebrew) dependencies:

brew install fftw eigen cmake

If FFTW is not found, set one of PKG_CONFIG_PATH, FFTW3_DIR, or CMAKE_PREFIX_PATH to point to your installation.

The repo includes a convenience script that activates a conda env and builds:

sh build_install.sh

Quick start

import numpy as np
import cpp_hf

# Grid and shapes
nk = 128; d = 2
weights = np.ones((nk, nk)) * ( (2/nk)*(2/nk) / (2*np.pi)**2 )  # scalar mesh measure
H = np.zeros((nk, nk, d, d), dtype=np.complex128)
Vq = (1.0/np.sqrt((np.linspace(-1,1,nk)[:,None]**2 + np.linspace(-1,1,nk)[None,:]**2) + 0.1)).astype(np.complex128)[...,None,None]
P0 = np.zeros_like(H)

# Target electron density (half‑filling)
ne_target = 0.5 * d * weights.sum()

P_fin, F_fin, E_fin, mu_fin, n_iter = cpp_hf.hartreefock_iteration_cpp(
    weights, H, Vq, P0,
    float(ne_target),  # electron density target
    0.5,               # temperature
    50,                # max_iter
    1e-3,              # commutator tolerance
    6,                 # mixing history (DIIS/EDIIS/Broyden)
    1.0,               # mixing alpha (kept for compatibility)
)
print("iters:", n_iter, "mu:", mu_fin, "E:", E_fin)

API

hartreefock_iteration_cpp(
    weights:      np.ndarray[(nk,nk), float64],
    hamiltonian:  np.ndarray[(nk,nk,d,d), complex128],
    v_coulomb:    np.ndarray[(nk,nk,1,1) or (nk,nk,d,d), complex128],
    p0:           np.ndarray[(nk,nk,d,d), complex128],
    electron_density0: float,
    T: float,
    max_iter: int,
    comm_tol: float,
    diis_size: int,
    mixing_alpha: float,
) -> tuple[P, F, E, mu, n_iter]
  • weights is the uniform k‑mesh measure (e.g., dkx*dky/(2π)^2).
  • v_coulomb can be scalar per‑k ([...,1,1]) or a full matrix per‑k ([...,d,d]).
  • Returns the converged density P, mean‑field F, total energy, chemical potential, and the iteration count.

License

GPLv2+ — see LICENSE.

Third‑party notices: see THIRD_PARTY_NOTICES.md.

Acknowledgments

  • FFTW — GPLv2+ (www.fftw.org)
  • Eigen — MPL2
  • pybind11 — BSD‑style

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpp_hf-1.0.1.tar.gz (35.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cpp_hf-1.0.1-cp312-cp312-manylinux_2_28_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

cpp_hf-1.0.1-cp312-cp312-manylinux_2_28_aarch64.whl (777.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

cpp_hf-1.0.1-cp312-cp312-macosx_14_0_arm64.whl (506.3 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

cpp_hf-1.0.1-cp312-cp312-macosx_13_0_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64

cpp_hf-1.0.1-cp311-cp311-manylinux_2_28_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

cpp_hf-1.0.1-cp311-cp311-manylinux_2_28_aarch64.whl (778.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

cpp_hf-1.0.1-cp311-cp311-macosx_14_0_arm64.whl (506.0 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

cpp_hf-1.0.1-cp311-cp311-macosx_13_0_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64

cpp_hf-1.0.1-cp310-cp310-manylinux_2_28_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

cpp_hf-1.0.1-cp310-cp310-manylinux_2_28_aarch64.whl (2.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

cpp_hf-1.0.1-cp310-cp310-macosx_14_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

cpp_hf-1.0.1-cp310-cp310-macosx_13_0_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.10macOS 13.0+ x86-64

File details

Details for the file cpp_hf-1.0.1.tar.gz.

File metadata

  • Download URL: cpp_hf-1.0.1.tar.gz
  • Upload date:
  • Size: 35.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cpp_hf-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3f422d863057abc6bddd831b04404283612a352283f4d275f557ec1801c957b8
MD5 9550dbdcecf95d23248b257e0973f0a6
BLAKE2b-256 389dba3858b39ba916b3027b7c11a26d7b7a4ec64e91e999bf5850df3435bb16

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1.tar.gz:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_hf-1.0.1-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c3b471f48ad4190f915d001486dab91416d49b134db24d760814e902c54b2417
MD5 6fde0f65ce1b302d7f1884c5dc5e338d
BLAKE2b-256 bc3aaba28ccb6774567b596bce91e6acbbeb1e5436b9856dd652bd99f6fd165c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_hf-1.0.1-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.1-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 569be9d60849932116b8c93c06a7b9e67226b9b6d43e1de9145b0e36d123c7fc
MD5 8e8baaeaf0b985526a3bcd7b2e264de5
BLAKE2b-256 e637f92428699be77f1b91c30e18b9f27d129df7a82e52011c918e12301a7162

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1-cp312-cp312-manylinux_2_28_aarch64.whl:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_hf-1.0.1-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.1-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 cd3709160ef123be04d72d90a603611a7288a2dc8537e49c25cab2ef044c6b96
MD5 2a76ba441d24d82d172b3b4ed66c4b91
BLAKE2b-256 1294d78cb2804970a77aff00f35cf3b39c25d63ca9a1fab4a9cca7e4a3a38c83

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_hf-1.0.1-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.1-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 c691f1526cb0a4b96dc8a72b089adba12e5ab20bc4f52b667c4dde810d81c843
MD5 bf269fb8ff51abcc17288cb4bf50e0a8
BLAKE2b-256 13cc5a15bfe9fae995ecd13d4600f0de112afd5097c6a0726f49ee8cee248d7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1-cp312-cp312-macosx_13_0_x86_64.whl:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_hf-1.0.1-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a07c869861ba2bfba6f3faaf69b0565ba5148bd34e86b638ec6b462681e61913
MD5 46557faa3ee61993e57e5e958df1a5ad
BLAKE2b-256 5bf6abcdfe8206b9d9bb6c20c84d95ea725ee5e5336558c13c3d80e7049de982

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_hf-1.0.1-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.1-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f5bbfbe3ca63de419c919e5cc8cf825e6f668165deb71967d2d872174efd2703
MD5 7eca915cbb435a2e8c0598b00d26f0b0
BLAKE2b-256 42a9ae7179a92c7a1eaa727a1f296fbc873d89a70517dd74cece8caef5fb461e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1-cp311-cp311-manylinux_2_28_aarch64.whl:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_hf-1.0.1-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.1-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 963e9d3a044e398a80e92d770a8cb8617897aafc3e94085a6516b636663df122
MD5 3ba6cf91678559768fe6f1aebe2b7af5
BLAKE2b-256 1dc3d062aba7cbea475f2d5025c399b9153288d1ab5bf855d7567516e5c5ee2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_hf-1.0.1-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.1-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 cbbad8dfa610c63cbdbcafdb6fd8a752881fde3b270f2d251199016eb7a18cbc
MD5 4a61fc72d9220771269a43f385aa6541
BLAKE2b-256 97760dffa5cd3c905d7fdc715cfe1e601606546d3f81db82278e46336c0ae695

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1-cp311-cp311-macosx_13_0_x86_64.whl:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_hf-1.0.1-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 967d03e7c64ec69104df6b5a5f7b8a9af91098d54b9b05f524d5b6f8469e35d5
MD5 39131c80f3d60356c7a9c96cda92cb78
BLAKE2b-256 623e0ef69644159117edbebb36f73dd3dd91dc20e2ff3d429d805a76836bd999

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_hf-1.0.1-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.1-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9b4e072a60b28456aaba20af26fc1fe3bf3d5ed215e17c300e3a2040e211651b
MD5 492b244456d49ca85572294d85c2a2a6
BLAKE2b-256 1d48ea8dbe9efdccf4f884feaf2d6d44515cf196a71bb995b5c6ba2023bf4092

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1-cp310-cp310-manylinux_2_28_aarch64.whl:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_hf-1.0.1-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.1-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 16440dfcf994123a40ad5d81e2d05d14716360d32534c068306e6a25be203ab8
MD5 68c860c66dad9cf8ceda6363d1ee428f
BLAKE2b-256 e54fd64d9b9b1277af6e41e8b4bf1ff89cb9bd488a89abb7343dfd24ab7d7986

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1-cp310-cp310-macosx_14_0_arm64.whl:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpp_hf-1.0.1-cp310-cp310-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.1-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 696e273b19929ec0cfbd89ac3a2c252c11d1212a04d0bf68385839fe71508f21
MD5 919737fb47ae3791027eb3d23400a872
BLAKE2b-256 301db3d66721a701dae705f090623311689bb19d109eacfa10cf64c5d19e8479

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.1-cp310-cp310-macosx_13_0_x86_64.whl:

Publisher: release.yml on skilledwolf/cpp_hf

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page