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-0.0.0-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-0.0.0-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-0.0.0-cp312-cp312-macosx_14_0_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.12macOS 14.0+ x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

cpp_hf-0.0.0-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-0.0.0-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-0.0.0-cp311-cp311-macosx_14_0_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.11macOS 14.0+ x86-64

cpp_hf-0.0.0-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-0.0.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cpp_hf-0.0.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0cafb88b6cf071c08445411834cfeeeb201ba60705a7ab0e4413fad699309454
MD5 625e6b745af9474d54485d464b1af14f
BLAKE2b-256 5b1c62065119c3f38c1db1e0bcdcf18478ed6d6c85bd35e59229dc6f6392dd67

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cpp_hf-0.0.0-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 08777bfe8fe5b9627c53c52c2a0a87d027a3a9a490ab4c667954cadaf2dcd9b2
MD5 23e85573a6a941f2ee380d918953b635
BLAKE2b-256 3f2b8af18e2b6ad3a6d12f5fa3cd1ce049900eaa969653e494134396e7d4dc8b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cpp_hf-0.0.0-cp312-cp312-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 32211ff083ef7b1555460a26565f3560c9bb2053607713d69d3a99e7717739a1
MD5 c725e7a66fc46287174e3bc1b38a8f6f
BLAKE2b-256 8796b2107f4ec8dfdeb1c89d91931848d9effbd060b946db4af7e610a46d6a59

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cpp_hf-0.0.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 abd00049a93790f863cc2ebaf062b0b45eed24ebdbd6458f0fa640bbe4d6d8d0
MD5 dbb0146eddbe5bbed598dea6b7aaa9c2
BLAKE2b-256 2d34582e2eca5de3695a0a87f0fa2fdf59d9dbd2dbbd49448148cbdab07ab061

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cpp_hf-0.0.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aac217b02b179609767fdcafd16df7c2fe96848b8f590f03b0b360181f30325f
MD5 4efde2b44b58050cb62c0228d5c7f6f7
BLAKE2b-256 f8865c62292c79476f7f9672ca5cebef5b982ee6c7d1e63a1130e25a13bfa354

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cpp_hf-0.0.0-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b8e71155bc1ec5b00931dad74050ce10cbd45c81dc606105ca90a805363f376e
MD5 c7897b91b419b42bf39c33071a37c609
BLAKE2b-256 1c93888f556afe7e8f9d0baba711fc93369d859b9bfe87d64516b49cfe0e17ed

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cpp_hf-0.0.0-cp311-cp311-macosx_14_0_x86_64.whl
Algorithm Hash digest
SHA256 98397d52f59f6fc4e5dec8965e23bc6fc4e808cd719d6bb39dc125decc215cac
MD5 8e9f79efc98c1b2e25cfcfb7d64398e7
BLAKE2b-256 31062d6edd14bb2e4983b0363a586a3f468dfac98dad7e2d5c6f23fe303b1228

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for cpp_hf-0.0.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 64c02875c00842d1a00f15a3e2267b1db8e375f4bb973737627bf4d8d2fffc3e
MD5 e1ce42a5ee053acfce0b94a54bc51940
BLAKE2b-256 a4b8c64ebdc4cdac2f72bdad8cfa73f7287a87fd62da3366dfb0dc6ef632e9ca

See more details on using hashes here.

Provenance

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