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.tar.gz (36.4 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-cp312-cp312-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

cpp_hf-1.0-cp312-cp312-manylinux_2_28_aarch64.whl (749.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

cpp_hf-1.0-cp312-cp312-macosx_14_0_arm64.whl (486.0 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

cpp_hf-1.0-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-cp311-cp311-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

cpp_hf-1.0-cp311-cp311-manylinux_2_28_aarch64.whl (750.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

cpp_hf-1.0-cp311-cp311-macosx_14_0_arm64.whl (485.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

cpp_hf-1.0-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-cp310-cp310-manylinux_2_28_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

cpp_hf-1.0-cp310-cp310-manylinux_2_28_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

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

Uploaded CPython 3.10macOS 14.0+ ARM64

cpp_hf-1.0-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.tar.gz.

File metadata

  • Download URL: cpp_hf-1.0.tar.gz
  • Upload date:
  • Size: 36.4 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.tar.gz
Algorithm Hash digest
SHA256 a7d8567e55a9797bb46d7b1fbeb52465242c33ab4ec3c21f17c20116df8bb476
MD5 60db30a82dc71e888b15c44108265aa4
BLAKE2b-256 7408a3675c355cc3f185fe4d07f92f40672239050de3ddad3688febf7e4ddc75

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.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-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7e6fd6515e0e8187d76b276e7da4b98a0d12b1ebb116b2fb6996c13d0f883911
MD5 4d2ebf01ad00cbf855dac4e0c4fbce3b
BLAKE2b-256 7ad1d9a21669dc8e1f81e745a5580511e6f9ad09ddc68e6dcff18a78aa83a479

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0-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-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 98a0ec6b945b1f8040705f3443df0685273bf7d20e21d8d26d5840221a876782
MD5 fa35af7f953da46f7e2b0151d04ce3d1
BLAKE2b-256 9b76733a741a08ee3ee69f3f9b815084a81bafbf6ec4dc448c02a9f032916307

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0-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-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 249d1baf0f2755826a93369281213976009db1d4ba4f70fd12b65d7f2f32c841
MD5 fef0123cb29ef3e55e91e09909295ab6
BLAKE2b-256 e3e07ffbb47cdf24c47a8e62e841cdf17f5de746c31b9b3a352290186ec59c8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0-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-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 33bc0dcb2f3f3b465f77e60951e4122fc6633c2aba6df4a1d1f142c93c302b12
MD5 b4cb6451bc5ea08b70a5850f2261ddb9
BLAKE2b-256 d749d66ae9a4275bfa35b693a19b0151a988ea1c432c906796b6dbe92ff200c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0-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-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 700a9e419962ce91fccd1938aea145242b52f5176cb1328fb031fabd9479bd06
MD5 4569330667aee1369fe9eff0fec728d0
BLAKE2b-256 36d892dd550ed565bca78f62745dfa3640c6a8626eeacb5196135f59c54baf62

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0-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-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b83b48f45f294e7de7025abe2eed803b06f13227cf282248bc85cecdbf39f988
MD5 51e25aa85b17f2ef1b8f0ad440724b51
BLAKE2b-256 a6231c38a9c4eefbe81a10015ac0671df0a4087da7acc9d148a93e783284a916

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0-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-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 62d0b52f6713a6839b5021b997eba363d84f3377160d3cf3e346c01791d36561
MD5 8a363d4d9970fe8d1e78c196006bd6e9
BLAKE2b-256 d08b74e3255ae61a06a6ad3d0704e5a96278be844dc981c48a42561bfb97fa6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0-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-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 6837d2381d549cb16e0fe79f7715b4c434ec93055e53c70d74f3e3157d6e7d41
MD5 3cd0f8b8b79b62f1b7f727ecff51c8d0
BLAKE2b-256 c1084a43b7f8434124a7d086d63739f0b184b67bcdecec6beb728a3afd358fc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0-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-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 29cd2d1678700dae99f4c7d38eebeb061f0dad3d6dd887cf6e9ce220db723067
MD5 65fa231a51040315a7f0c7bb75b08b65
BLAKE2b-256 495cdfc35282a84a04c27884457f65a1903dac8b97e7280816c547db60a27e5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0-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-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 82fd5bd0ca36fb0fe38629a34528b9d6927f6c72c011c5ab4b15f6006b5fc186
MD5 6e4fbc5f308f485fe52724e0f5134882
BLAKE2b-256 28a9860d95afcb553bfac1159b49337e3da95bc4a87fdc8bbc2b9bcc3c78ab1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0-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-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a073fccf97ad2ea93fa1bda54a7babcea681efc35b07698f1b07254697d8a339
MD5 2b24f5f74e936769bcfce6a3e59069d2
BLAKE2b-256 6004645ad9f6fda19e35973ba8e4845d9ef28a4d3dcc4efe7431f680ee96e357

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0-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-cp310-cp310-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 d4953fbf44ed73dbee7365f68f443583bf94cfd60cd3cf4f1209920b6573f601
MD5 16a7a312e4fe4d76fb055670a884533b
BLAKE2b-256 4325cb7966729c9c106d034a3826b3465d62f5887644b9093fb4929d63a051a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0-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