GPU4PySCF

repository·master·Indexed 43 days ago

https://github.com/pyscf/gpu4pyscf

A GPU plugin for the PySCF quantum chemistry library that provides hardware acceleration for SCF, DFT, and related calculations such as gradients and Hessians. It features a `to_gpu()` method for hybrid workflows, support for Periodic Boundary Condition (PBC) DFT, and integration with cuEST and cuTENSOR for accelerated ERI computations.

Tokens
7.2K
Snippets
21
Records
34
Agent score
57%

What's inside GPU4PySCF

  1. PBC DFT Benchmarks Overview

    master

    This document provides performance benchmarks for Periodic Boundary Condition (PBC) Density Functional Theory (DFT) calculations using gpu4pyscf. The benchmarks cover different functional types and integration methods across various crystal systems.

    Hardware Environment:

    • GPU: 1 NVIDIA A100 card
    • Host Memory: 200 GB
  2. Features and experimental capabilities of gpu4pyscf

    master

    Supported Features

    • Density fitting and direct SCF schemes.
    • SCF, analytical gradient, and analytical Hessian for Hartree-Fock and DFT.
    • Functionals: LDA, GGA, mGGA, hybrid, and range-separated (via libXC).
    • Excited states: Spin-conserved and spin-flip TDA and TDDFT.
    • Geometry optimization and transition state search (via geomeTRIC).
    • Interfaces: Atomic Simulation Environment (ASE).
    • Dispersion corrections: DFTD3 and DFTD4.
    • Nonlocal functional correction (vv10): Analytical gradient and Hessian.
    • GPU accelerated ECP.
    • Solvent models: PCM (with analytical gradients/Hessian) and SMD.
    • Unrestricted Hartree-Fock and DFT (gradient and Hessian).
    • Atomic charges: CHELPG, ESP, and RESP.

    Experimental Features

    • MP2/DF-MP2 and CCSD.
    • Polarizability, IR, and NMR shielding.
    • Raman spectrum.
    • QM/MM with PBC.
    • Multi-GPU for direct SCF and density fitting.
    • SCF and DFT with periodic boundary conditions.
    • Non-adiabatic coupling for TDDFT.
    • Energy decomposition analysis.
  3. Compare GPU4PySCF v1.0 performance with Q-Chem v6.1

    master

    GPU4PySCF v1.0 provides significant speedups for Density Fitting (DF) calculations compared to Q-Chem v6.1 across various functionals and basis sets.

    DF SCF Energy (B3LYP/*)

    • Accuracy: Differences from Q-Chem v6.1 are typically in the range of $10^{-4}$ to $10^{-7}$ depending on the basis set.
    • Speedup: Speedups range from ~0.8x (for small basis sets like sto-3g) up to ~24x for larger basis sets like def2-tzvpd.
    • Note: For the molecule 084_Sphingomyelin using the sto-3g basis set, the calculation does not converge.

    DF Gradient (B3LYP/*)

    • Accuracy: Differences are generally within $10^{-4}$ to $10^{-5}$.
    • Speedup: Significant speedups are observed, often exceeding 10x for medium basis sets and reaching up to ~27x for def2-tzvpp on certain molecules.

    DF Hessian (B3LYP/*)

    • Accuracy: Differences are typically in the $10^{-3}$ to $10^{-4}$ range.
    • Speedup: This category shows the highest performance gains, with speedups often exceeding 50x and reaching up to ~132x for large molecules and basis sets.

    DF SCF Energy and Gradient (*/def2-tzvpp)

    When using the def2-tzvpp basis set across different functionals:

    • Functionals tested: LDA, PBE, M06, B3LYP, and wB97m-v.
    • Speedup: Speedups are substantial across all functionals, typically ranging from ~3x to ~34x for SCF energy and ~3x to ~27x for gradients.
  4. Compare GPU4PySCF benchmarks with other software

    master

    When comparing GPU4PySCF performance benchmarks against other quantum chemistry packages (like Q-Chem or Psi4), ensure that all physical and numerical settings are identical. Differences in the following parameters will make performance comparisons invalid:

    • Integral thresholds: The precision required for calculating integrals.
    • Convergence tolerance: The threshold for SCF or other iterative convergence.
    • Basis set type: Whether using Cartesian or spherical basis sets.
    • Grids: The density and type of integration grids used.
  5. Compile gpu4pyscf from source

    master

    If you need to build the package from source, follow these steps:

    1. Clone the repository:
    git clone https://github.com/pyscf/gpu4pyscf.git
    cd gpu4pyscf
    1. Build using CMake:
    cmake -S gpu4pyscf/lib -B build/temp.gpu4pyscf
    cmake --build build/temp.gpu4pyscf -j 4
    1. Update your PYTHONPATH:
    CURRENT_PATH=`pwd`
    export PYTHONPATH="${PYTHONPATH}:${CURRENT_PATH}"
    1. Install acceleration dependencies (ensure versions match your CUDA environment):
    pip3 install cutensor-cu12 cupy-cuda12x

    Troubleshooting: If you see the following warning at the start of a job, it indicates a problem with your cupy or cutensor installation (likely a version mismatch or duplicate installations): <repo_path>/gpu4pyscf/lib/cutensor.py:<line_number>: UserWarning: using cupy as the tensor contraction engine.

    cmake -S gpu4pyscf/lib -B build/temp.gpu4pyscf
    cmake --build build/temp.gpu4pyscf -j 4
  6. Install gpu4pyscf via pip

    master

    Install the pre-compiled binary packages based on your CUDA version. Note that these packages support compute capability 7.0 and later (Volta, e.g., Tesla V100, RTX 20 series, and later).

    First, check your CUDA version:

    nvcc --version

    Then, install the corresponding package and the highly recommended cutensor package:

    CUDA Versiongpu4pyscf packagecutensor package
    11.xpip3 install gpu4pyscf-cuda11xpip3 install cutensor-cu11
    12.xpip3 install gpu4pyscf-cuda12xpip3 install cutensor-cu12
    13.xpip3 install gpu4pyscf-cuda13xpip3 install cutensor-cu13

    Important: CuPy and cuTENSOR versions are strongly interdependent. To avoid functionality failures, use these recommended combinations:

    1. CuPy 13.3.0 + cuTENSOR 2.0.2
    2. CuPy 13.4.1 + cuTENSOR 2.2.0

    To ensure compatibility and reproducibility, it is recommended to create a dedicated environment using the provided requirements file:

    pip3 install --no-cache-dir -r requirements.txt
    pip3 install gpu4pyscf-cuda12x
    pip3 install cutensor-cu12
  7. Handle data residence (NumPy vs CuPy) in hybrid workflows

    master

    When integrating GPU4PySCF into a PySCF codebase, be mindful of where tensors reside:

    • Input Arrays: CuPy arrays are preferred. NumPy arrays are accepted but will be handled by the library.
    • Calculation Results (Attributes):
      • Energies (energy, gradients, Hessians) $\rightarrow$ NumPy arrays.
      • Wavefunctions (coefficients, energies, occupancies, amplitudes) $\rightarrow$ CuPy arrays.

    Use cupy.asarray(x) to move to GPU and cupy.asnumpy(x) to move to CPU.

    import cupy as cp
    
    # Convert to a CuPy array for GPU processing
    x_gpu = cp.asarray(x_cpu)
    
    # Convert back to NumPy for CPU processing
    x_cpu = cp.asnumpy(x_gpu)
  8. Compare GPU4PySCF performance with Psi4

    master

    GPU4PySCF performance can be benchmarked against Psi4 v1.8. The benchmarks evaluate Direct SCF Energy across various functionals and basis sets.

    In the benchmark results:

    • Difference values represent the numerical difference in energy between GPU4PySCF and Psi4.
    • Speedup values represent the performance factor of GPU4PySCF relative to Psi4.
    • A value of -1 (or -1.00e+00) indicates that the computation was too expensive to complete in Psi4 for that specific configuration.

    Key benchmarked configurations include:

    • B3LYP/ with STO-3G or 6-31G basis sets*
    • Various functionals (HF, PBE, M06, B3LYP) with the def2-tzvpp basis set
  9. Export results for visualization (Cube and Molden formats)

    master

    To visualize electronic properties or orbitals, you can export data to standard formats:

    • Cube format: Use pyscf.tools.cubegen to export densities or potentials to .cube files, compatible with VMD or Jmol.
    • Molden format: Use pyscf.tools.molden to export orbital coefficients to .molden files.
    from pyscf.tools import cubegen, molden
    
    # Export electron density to cube
    cubegen.density(mol, 'density.cube', mf.make_rdm1())
    
    # Export orbitals to molden
    molden.from_scf(mf, 'scf_results.molden')
  10. Perform Geometry Optimization

    master

    Geometry optimization for molecules and crystals can be performed using the geomeTRIC or ASE packages via PySCF's wrapper interface.

    For methods implemented in both PySCF and GPU4PySCF, use the .optimizer() method of the Gradients class.

    # Optimize molecular geometry using GPU4PySCF
    mol.RKS(xc='wb97mv').to_gpu().Gradients().optimizer().run()
    
    # Optimize crystal lattice and atomic positions
    cell.KRKS(xc='pbe', kpts=cell.make_kpts([2,2,2])).to_gpu().Gradients().optimizer().run()
  11. Enable cuEST for accelerated ERI computations

    master

    cuEST (CUDA Electronic Structure Theory) accelerates ERI computations, specifically improving density-fitting J/K construction.

    Performance Gains:

    • Ampere: ~1.5x
    • Hopper: ~3x
    • Blackwell: ~5x
    • RTX PRO 6000: ~15x

    Limitations:

    • Does not support Volta GPUs.
    • Does not support Python 3.10 or earlier.
    • DFT XC integrals and density evaluation remain inefficient.

    Usage: Use the apply_cuest_wrapper from gpu4pyscf.lib.cuest_wrapper.

    from gpu4pyscf.lib.cuest_wrapper import apply_cuest_wrapper
    
    mf = mol.to_gpu().RKS(xc='pbe0').density_fit()
    mf = apply_cuest_wrapper(mf)
    
    # To turn off the cuEST DFT XC part specifically:
    mf._numint.turn_on_cuest_xc = False