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

Note: the Python import name is cpp_hf (underscore).

Advanced installation, source builds, platform tips, and troubleshooting: see Installation.md.

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

cpp_hf-1.0.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

cpp_hf-1.0.3-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

cpp_hf-1.0.3-cp312-cp312-macosx_14_0_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.12macOS 14.0+ x86-64

cpp_hf-1.0.3-cp312-cp312-macosx_14_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

cpp_hf-1.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

cpp_hf-1.0.3-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

cpp_hf-1.0.3-cp311-cp311-macosx_14_0_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.11macOS 14.0+ x86-64

cpp_hf-1.0.3-cp311-cp311-macosx_14_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

File details

Details for the file cpp_hf-1.0.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f2546714219eeb68119ce49ae609aff491ce97d44fd9487b843941abf8805255
MD5 d079186db8ee92718803c4d0233b9031
BLAKE2b-256 3e5e9f671226b90662bab1a12b376bc99b21d6f8345737fe53997efc8606660f

See more details on using hashes here.

Provenance

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

Publisher: wheels.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.3-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.3-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 60d095b7ee7289c71c28b36fc2fb37f9234c56ae4c5da2b2d76280203180428e
MD5 76756e41c5e5a4bdf026e5642c94fb3f
BLAKE2b-256 fc26870c95a7a8bb2b639fc9967b093799284d3154c23ae7181e80bf25a1c922

See more details on using hashes here.

Provenance

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

Publisher: wheels.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.3-cp312-cp312-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.3-cp312-cp312-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 bf17ac1fc3dabb1e6fb5544ccae6184e425de6d6125ecf71bf38001eabd63063
MD5 5b7aeff9c9859f72e6fa81a7e241d623
BLAKE2b-256 b6e7598206807a6eac154289f110063f94160239a9196715164421c02993ebe6

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.3-cp312-cp312-macosx_14_0_x86_64.whl:

Publisher: wheels.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.3-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.3-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 832631c65154ea70946f80dfbe58c1503103db01ff7d046aded2c875ddb93a61
MD5 d8d6b21754334428973e76ff323b26ea
BLAKE2b-256 98e77d20e1643dd15e79b6cc8ee1682fca81bdde25bd7cc4da22ae10f946f9a5

See more details on using hashes here.

Provenance

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

Publisher: wheels.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.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8fd26a5a995b83c5f350ddeb73174837c7301334e33c45bb092288d5e8b86a35
MD5 ae63f2fbae3e1188f4d32674914e6461
BLAKE2b-256 8ddf5f81919dbe106f17dc7c99101bc00e3f5e507e4a6a6206932881d14376a0

See more details on using hashes here.

Provenance

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

Publisher: wheels.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.3-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.3-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 98007f7b17d3de602f0457af9566f05475ac62cbde13fd872a39aca9af624cac
MD5 3383fdb6888580ec96950cb284e85363
BLAKE2b-256 96ee084a74d2326ef60f7d5e597c2df0c2af15d53490d83f1bf909021f699f1a

See more details on using hashes here.

Provenance

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

Publisher: wheels.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.3-cp311-cp311-macosx_14_0_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.3-cp311-cp311-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 51590deb00ad23bcd1c19af2e7220a3d38eadd661641582eb4db4d58a25480be
MD5 4d881714935d44007ce9e3ea0f1d1e88
BLAKE2b-256 d23b85e23f74dfa06d1d65fac6b48764b5d7885583f60e8b1815ef5fc201816c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpp_hf-1.0.3-cp311-cp311-macosx_14_0_x86_64.whl:

Publisher: wheels.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.3-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for cpp_hf-1.0.3-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a20cc95f06394e2b0a148852f2e1856cea22bf6e1c4ccba65b6bc034c83ef2a0
MD5 9685e2f248102f4771bd54df71208932
BLAKE2b-256 ba1bb615da1ba6dee07d088f2cfe91a630975ddcbb66b9be6b3a317cd28ac3cd

See more details on using hashes here.

Provenance

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

Publisher: wheels.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