Skip to main content

No project description provided

Project description

This library contains direct translations of exchange correlation functionals in libxc to jax. The core calculations in libxc are implemented in maple. This gives us the opportunity to translate them directly into python with the help of CodeGeneration.

Usage

Installation

pip install jax-xc

Invoking the Functionals

jax_xc’s API is functional: it receives \(\rho\) a function of Callable type, and returns the \(\varepsilon_{xc}\) as a function of Callable type.

E_{xc} = \int \rho(r) \varepsilon_{xc}(r) dr

LDA and GGA

Unlike libxc which takes pre-computed densities and their derivative at certain coordinates. In jax_xc, the API is designed to directly take a density function.

import jax_xc

def rho(r):
  """Electron number density.

  A function that takes a real coordinate, and returns a scalar
  indicating the number density of electron at coordinate r.

  Args:
    r: a 3D coordinate.
  Returns:
    rho: If it is unpolarized, it is a scalar.
         If it is polarized, it is a array of shape (2,).
  """
  pass

exc = jax_xc.gga_xc_pbe1w(rho=rho, polarized=False)


# Numerical integral with grids and their corresponding weights
rho_times_exc = lambda w, r: w * rho(r) * exc(r)
Exc = jnp.sum(vmap(rho_times_exc)(weights, grids))

mGGA

Unlike LDA and GGA that only depends on the density function, mGGA functionals also depend on the molecular orbitals.

import jax_xc

def mo(r):
  """Molecular orbital.

  A function that takes a real coordinate, and returns the value of
  molecular orbital at this coordinate.

  Args:
    r: a 3D coordinate.
  Returns:
    mo: If it is unpolarized, it is a array of shape (N,).
        If it is polarized, it is a array of shape (N, 2).
  """
  pass

exc = jax_xc.mgga_xc_cc06(rho=rho, polarized=polarized, mo=mo)

# perform numerical integral like the example in LDA and GGA
rho_times_exc = lambda w, r: w * rho(r) * exc(r)
Exc = jnp.sum(vmap(rho_times_exc)(weights, grids))

Hybrid Functionals

Hybrid functionals expose the same API, with extra attributes for the users to access parameters needed outside of libxc/jax_xc (e.g. the fraction of exact exchange).

import jax_xc

def rho(r):
  """Electron number density.

  A function that takes a real coordinate, and returns a scalar
  indicating the number density of electron at coordinate r.

  Args:
    r: a 3D coordinate.
  Returns:
    rho: If it is unpolarized, it is a scalar.
         If it is polarized, it is a array of shape (2,).
  """
  pass

exc = jax_xc.hyb_gga_xc_pbeb0(rho=rho, polarized=polarized)
cam_alpha = exc.cam_alpha  # fraction of full Hartree-Fock exchange

The complete list of extra attributes can be found in the class below:

class HybridFunctional(Callable):
  cam_alpha: float
  cam_beta: float
  cam_omega: float
  nlc_b: float
  nlc_C: float

The meaning for each attribute is the same as libxc:

  • cam_alpha: fraction of full Hartree-Fock exchange, used both for usual hybrids as well as range-separated ones

  • cam_beta: fraction of short-range only(!) exchange in range-separated hybrids

  • cam_omega: range separation constant

  • nlc_b: non-local correlation, b parameter

  • nlc_C: non-local correlation, C parameter

Numerical Correctness

We test all the functionals that are auto-generated from maple files against the reference values in libxc. The test is performed by comparing the output of libxc and jax_xc and make sure they are within a certain tolerance, namely atol=2e-10 and rtol=2e-10.

Performance Benchmark

We report the performance benchmark of jax_xc against libxc on a 64-core machine with Intel(R) Xeon(R) Silver 4216 CPU @ 2.10GHz.

We sample the points to evaluate the functionals by varying the number of points from 1 to $10^7$. The benchmark is performed by evaluating the runtime of the functional. Note that the runtime of jax_xc is measured by excluding the time of just-in-time compilation.

We visualize the mean value (reduced for both polarized and unpolarized) of the runtime of jax_xc and libxc in the following figure. The y-axis is log-scale.

figures/jax_xc_speed.svg

We visualize the distribution of the runtime ratio of jax_xc and libxc in the following figure.

figures/jax_xc_ratio.svg

Note that, we exclude one datapoint mgga_x_2d_prhg07 from the runtime ratio visualization because it is an outlier due to Jax’s lack of support oflamberw function and we use tensorflow_probability.substrates.jax.math.lambertw.

Caveates

The following functionals from libxc are not available in jax_xc because some functions are not available in jax.

gga_x_fd_lb94          # Becke-Roussel not having an closed-form expression
gga_x_fd_revlb94       # Becke-Roussel not having an closed-form expression
gga_x_gg99             # Becke-Roussel not having an closed-form expression
gga_x_kgg99            # Becke-Roussel not having an closed-form expression
hyb_gga_xc_case21      # Becke-Roussel not having an closed-form expression
hyb_mgga_xc_b94_hyb    # Becke-Roussel not having an closed-form expression
hyb_mgga_xc_br3p86     # Becke-Roussel not having an closed-form expression
lda_x_1d_exponential   # Requires explicit 1D integration
lda_x_1d_soft          # Requires explicit 1D integration
mgga_c_b94             # Becke-Roussel not having an closed-form expression
mgga_x_b00             # Becke-Roussel not having an closed-form expression
mgga_x_bj06            # Becke-Roussel not having an closed-form expression
mgga_x_br89            # Becke-Roussel not having an closed-form expression
mgga_x_br89_1          # Becke-Roussel not having an closed-form expression
mgga_x_mbr             # Becke-Roussel not having an closed-form expression
mgga_x_mbrxc_bg        # Becke-Roussel not having an closed-form expression
mgga_x_mbrxh_bg        # Becke-Roussel not having an closed-form expression
mgga_x_mggac           # Becke-Roussel not having an closed-form expression
mgga_x_rpp09           # Becke-Roussel not having an closed-form expression
mgga_x_tb09            # Becke-Roussel not having an closed-form expression
gga_x_wpbeh            # jit too long for E1_scaled
gga_c_ft97             # jit too long for E1_scaled
lda_xc_tih             # vxc functional
gga_c_pbe_jrgx         # vxc functional
gga_x_lb               # vxc functional

Building from Source Code

Modify the .env.example to fill in your envrionment variables, then rename it to .env. Then run source .env to load them into your shell.

  • OUTPUT_USER_ROOT: The path to the bazel cache. This is where the bazel cache will be stored. This is useful if you are building on a shared filesystem.

  • MAPLE_PATH: The path to the maple binary.

  • TMP_INSTALL_PATH: The path to a temporary directory where the wheel will be installed. This is useful if you are building on a shared filesystem.

How to build.

bazel --output_user_root=$OUTPUT_USER_ROOT build --action_env=PATH=$PATH:$MAPLE_PATH @maple2jax//:jax_xc_wheel

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

jax_xc-0.0.2-cp310-cp310-manylinux_2_17_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

jax_xc-0.0.2-cp39-cp39-manylinux_2_17_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

jax_xc-0.0.2-cp38-cp38-manylinux_2_31_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.31+ x86-64

jax_xc-0.0.2-cp38-cp38-manylinux_2_17_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

jax_xc-0.0.2-cp37-cp37m-manylinux_2_17_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

File details

Details for the file jax_xc-0.0.2-cp310-cp310-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for jax_xc-0.0.2-cp310-cp310-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 6318ab306b476174b66a01d8b703a44ad876c554abb040b346bdceb1952c54b0
MD5 25e0feb86d52e8de919c3eb009a7961a
BLAKE2b-256 6ae1e8cce90b0d2287c85ccbcc3e836ebcb1ab9936b6b0c570db4c195111f62e

See more details on using hashes here.

File details

Details for the file jax_xc-0.0.2-cp39-cp39-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for jax_xc-0.0.2-cp39-cp39-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 8f6f64e595320bebbc768578f841758395895e894715ec3e31a270d555521f8e
MD5 59c8f17a0b40f6a82aacc82e907f5ea4
BLAKE2b-256 ef204a86ba510fd047a850f240b15a6d91c711c6c8ab9db2c91c95262d6c2f14

See more details on using hashes here.

File details

Details for the file jax_xc-0.0.2-cp38-cp38-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for jax_xc-0.0.2-cp38-cp38-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 f5a29557da915c55458d0097c2c8ce033443651d4ba251bb9d98cb12a06df9ad
MD5 e4e38cd08cc7708418b6e6eb85843625
BLAKE2b-256 0dc471e0f7920b37f4ff3784c2d5bd2c86f7b65b35774eb9781be08d0e624dd1

See more details on using hashes here.

File details

Details for the file jax_xc-0.0.2-cp38-cp38-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for jax_xc-0.0.2-cp38-cp38-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 c689c9a7b3c42fc30f9c50672f0089910ac0f5d16b42a4f992e291d0a8b0db9f
MD5 e16c76fce1eb6c6680c8606d8a424486
BLAKE2b-256 f1251a144948490715313ea37bce2df2af7ef672bc049bd50349913044fe0567

See more details on using hashes here.

File details

Details for the file jax_xc-0.0.2-cp37-cp37m-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for jax_xc-0.0.2-cp37-cp37m-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 b4fae0729faf82a751bd90a697a6ae40038f997e8e2c48017762e298b96cd993
MD5 c9459de07ca2de60b462d0a74a22c0f8
BLAKE2b-256 5283df69f032e77f2b0d29b3fe771acf33d6d0ac6c17d47be7bd4e1f26dd77e6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page