Skip to main content

A package that provides a jax-based Hartree-Fock optimization solver for simple continuum models.

Project description

jax_hf — JAX Hartree–Fock on k‑grids

PyPI Python Wheel License Build Release

jax_hf provides a JAX implementation of a Hartree–Fock self‑consistent field (SCF) loop on uniform 2D k‑grids, with optional JIT compilation.

  • FFT‑based exchange in k‑space
  • Dense Hermitian diagonalization (JAX eigh)
  • DIIS/EDIIS‑style mixing (robust convergence)
  • NumPy/JAX‑friendly API, easy to integrate with other JAX code

Project links:

Installation

Users (PyPI):

pip install jax-hf

Note: jax_hf depends on JAX. For CPU‑only installs, pip will usually pull a working wheel automatically. For GPU, follow JAX’s official install guide to select the correct extras/wheels for your CUDA/cuDNN stack.

Developers (editable install):

git clone https://github.com/skilledwolf/jax_hf.git
cd jax_hf
pip install -e .

Quick start

import numpy as np
import jax.numpy as jnp
import jax_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)
K = np.linspace(-1.0, 1.0, nk)
Vq = (1.0 / np.sqrt((K[:, None]**2 + K[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()

# Build HF kernel (JAX arrays inside)
kernel = jax_hf.HartreeFockKernel(
    weights,                 # (nk, nk)
    H,                       # (nk, nk, d, d)
    Vq,                      # (nk, nk, 1, 1) or (nk, nk, d, d)
    T=0.5,                   # temperature
)

# JIT‑compile the SCF iteration function (optional but recommended)
hf_iter = jax_hf.jit_hartreefock_iteration(kernel)

P_fin, F_fin, E_fin, mu_fin, n_iter, history = hf_iter(
    P0, float(ne_target),
    max_iter=50, comm_tol=1e-3, diis_size=6, log_every=None,
)
print("iters:", int(n_iter), "mu:", float(mu_fin), "E:", float(E_fin))

API

class HartreeFockKernel:
    def __init__(self, weights, hamiltonian, coulomb_q, T: float):
        ...

def hartreefock_iteration(
    P0, electrondensity0, hf_step: HartreeFockKernel,
    *, max_iter=100, comm_tol=5e-3, diis_size=4, log_every: int | None = 1,
):
    """Runs SCF and returns (P_fin, F_fin, E_fin, mu_fin, n_iter, history)."""

def jit_hartreefock_iteration(hf_step: HartreeFockKernel):
    """Returns a jitted version of hartreefock_iteration with static args."""
  • shapes: weights is (nk, nk), hamiltonian is (nk, nk, d, d), coulomb_q is (nk, nk, 1, 1) or (nk, nk, d, d), P0 matches (nk, nk, d, d).
  • returns: converged density P_fin, mean‑field F_fin, total energy, chemical potential mu_fin, iteration count, and a small history dict with energy/commutator traces.

Versioning

Versions are derived from git tags using setuptools_scm. Tags like v1.2.3 produce version 1.2.3; non‑tag builds produce development versions.

License

BSD 2‑Clause — see LICENSE.

Third‑party notices: see THIRD_PARTY_NOTICES.md.

Author: Dr. Tobias Wolf

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

jax_hf-1.0.2.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

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

jax_hf-1.0.2-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file jax_hf-1.0.2.tar.gz.

File metadata

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

File hashes

Hashes for jax_hf-1.0.2.tar.gz
Algorithm Hash digest
SHA256 673ace3fa4ff8c4c10629114771f09a067bd3e4d9effce092c5d8ac196265659
MD5 efdc44072c930b7e1fcc99f99e24ab01
BLAKE2b-256 3a1a0dbb825c3793e944b7575bf4a8ec09d8747a1e255922dc54595d2e6dd871

See more details on using hashes here.

Provenance

The following attestation bundles were made for jax_hf-1.0.2.tar.gz:

Publisher: release.yml on skilledwolf/jax_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 jax_hf-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: jax_hf-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jax_hf-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3b9060413625e82dc37d7c6b5af6803e30f0637c5ea4a0eb6fdaa6e8337a8d0f
MD5 3783090fc25f79aa05d100bdf1c3a715
BLAKE2b-256 505fcb486aba7371ca2cca983085e0d4af56814488cb50c70f68d0f66c284b0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for jax_hf-1.0.2-py3-none-any.whl:

Publisher: release.yml on skilledwolf/jax_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