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.1.0.tar.gz (18.4 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.1.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jax_hf-1.1.0.tar.gz
  • Upload date:
  • Size: 18.4 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.1.0.tar.gz
Algorithm Hash digest
SHA256 e4dc1d4aa47af4a0e5fa735de702d5d550b3a5e6073b3ac5135df5ae1f158571
MD5 2aefc3ca0355c031631753152826d273
BLAKE2b-256 a012445e92cfdad7ae1f30972de2096966fb7206172f245f5bdc83c93eb4f501

See more details on using hashes here.

Provenance

The following attestation bundles were made for jax_hf-1.1.0.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: jax_hf-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.8 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db8a5bbf6f49fe3afbd204cdd001374f300187699dd0d76ace666994ea8e5c49
MD5 5a0dd6478253a31d47020e5b9a19907d
BLAKE2b-256 10ec106dbfd1955ceb5929759dbc177cc36733232ffba00d717269e7f15207d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for jax_hf-1.1.0-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