Adaptive Low-Rank Methods

PyTC 0.3.0 adds basis-update and Galerkin (BUG) solvers for MP2, direct RPA, CCSD, and the perturbative triples correction (T). They work on closed-shell, density-fitted PySCF mean-field objects and do not use a Jastrow factor.

The representation

The doubles amplitudes are kept in the factorized form

\[T = U \,\mathrm{diag}(S)\, U^{\mathsf T}\]

in the occupied-virtual pair space, where U has one column per retained pair function and S holds the corresponding weights. Each iteration augments the pair basis with residual directions, solves the Galerkin problem in the augmented space, and truncates. The amplitudes are never stored in dense form. CCSD still builds one array of that size by default, the quadratic operator described under Memory options below.

The truncation threshold tau is the accuracy control. A smaller tau keeps a larger rank and brings the energy closer to the canonical density-fitted result. With the default truncation="relative", a mode is kept when the magnitude of its weight exceeds tau times the largest one; with truncation="absolute" it is kept when the magnitude exceeds tau. tau is not a residual tolerance.

Requirements

  • A closed-shell PySCF mean field built with density fitting, for example scf.RHF(mol).density_fit().

  • JAX in double precision. Set JAX_ENABLE_X64=1 in the environment or call jax.config.update("jax_enable_x64", True) before the calculation. The solvers raise Float64NotEnabled otherwise.

Quick start

import jax
jax.config.update("jax_enable_x64", True)
from pyscf import gto, scf

from pytc.solver.bug_ccsd import low_rank_ccsd
from pytc.solver.bug_t import low_rank_t

mol = gto.M(atom="O 0 0 0; H 0 0.757 0.587; H 0 -0.757 0.587", basis="6-31g")
mf = scf.RHF(mol).density_fit().run()

ccsd = low_rank_ccsd(mf, tau=1e-6)
e_t = low_rank_t(mf, ccsd)

print(f"CCSD correlation energy: {ccsd.energy:.10f} Eh")
print(f"(T) correction:          {e_t:.10f} Eh")
print(f"retained rank:           {ccsd.S.size}")

Solvers

Method

Entry point

Returns

MP2

pytc.solver.bug_mp2.low_rank_mp2(mf, tau=1e-4)

LowRankResult

Direct RPA (direct ring CCD)

pytc.solver.bug_rpa.low_rank_rpa(mf, tau=1e-4)

LowRankResult

CCSD

pytc.solver.bug_ccsd.low_rank_ccsd(mf, tau=1e-4)

LowRankResult

(T)

pytc.solver.bug_t.low_rank_t(mf, ccsd)

float

All four accept frozen=n to drop the n lowest orbitals. low_rank_t takes the result of low_rank_ccsd and must be called with the same frozen. It returns the (T) energy correction only; add it to ccsd.energy for the CCSD(T) correlation energy.

The result object

low_rank_mp2, low_rank_rpa, and low_rank_ccsd return a pytc.solver.bug_core.LowRankResult with these fields:

Field

Content

energy

Correlation energy in Hartree

U, S

The factors of the doubles amplitudes; S.size is the retained rank

t1

Singles amplitudes (CCSD only)

iterations

Number of iterations performed

converged

True when a stopping rule was met, False when the run ended at maxiter without one

stop_reason

"amplitude-step", "energy-plateau", or "maxiter"

rank_hist, e_hist

Rank and energy after each iteration

diagnostics

Solver-specific detail, such as augmentation widths and the memory plan

Smeared references in direct RPA

low_rank_rpa treats a Fermi- or Gaussian-smeared mean field with fractional occupations. Pass a mean field that is already smeared, or build the inputs with pytc.solver.bug_rpa.rpa_inputs(mf, sigma=..., method="fermi"), which reruns the SCF with PySCF’s smearing, and hand them to pytc.solver.bug_rpa.kernel.

Restarting CCSD

low_rank_ccsd calls callback once per iteration with a dictionary that includes the iteration number, the rank, the energy, and "state", the current (U, S, t1). Writing that tuple to disk in the callback and passing it back through init restarts an interrupted calculation from its last completed iteration.

import os
import numpy as np

def save(info):
    U, S, t1 = info["state"]
    # write to a temporary file first so an interrupted write cannot damage the checkpoint
    np.savez("bug_ccsd_checkpoint.tmp.npz", U=np.asarray(U), S=np.asarray(S), t1=np.asarray(t1))
    os.replace("bug_ccsd_checkpoint.tmp.npz", "bug_ccsd_checkpoint.npz")

result = low_rank_ccsd(mf, tau=1e-6, callback=save)

In a later run, load the file and continue:

saved = np.load("bug_ccsd_checkpoint.npz")
result = low_rank_ccsd(mf, tau=1e-6, init=(saved["U"], saved["S"], saved["t1"]),
                       callback=save)

Memory options

The density-fitting factors are always built in host memory, so budget host memory for them in every calculation. Where the solvers work from by default:

  • MP2 and direct RPA upload the occupied-virtual factor to the accelerator and keep the pair basis there.

  • CCSD keeps the factors in host memory for the whole calculation. The occupied-virtual factor is also held on the accelerator, and the solver raises MemoryError if it is larger than pytc.solver.bug_helper.RESIDENT_LIMIT_BYTES. The occupied-occupied and virtual-virtual factors are uploaded once per calculation when they are below that limit and streamed in chunks over the auxiliary index otherwise. The quadratic operator is on the accelerator. It holds \(n_{ov}^2\) double-precision numbers, where \(n_{ov}\) is the number of occupied-virtual pairs, which is the size of a dense doubles amplitude.

The following options move further arrays to host memory or to disk.

Option

Solvers

Effect

host_backed=True

MP2, direct RPA

Keeps the density-fitting factor and the pair basis in host memory and streams them to the device in row panels

PYTC_HOST_SCRATCH=<directory>

All

Places the host-side density-fitting factors and pair-height arrays in files in that directory instead of in RAM

quadratic_mode="host"

CCSD

Keeps only the upper triangle of the quadratic operator, \(n_{ov}^2/2\) double-precision numbers, in host memory and streams it to the device for each application

dense_core="host"

Direct RPA, CCSD

Runs the truncation eigendecomposition on the host CPU instead of on the device

Examples

Examples 07 to 10 run each solver on water in cc-pVDZ and compare with the corresponding PySCF result. See Examples. The snippets on this page use the default convergence settings of low_rank_ccsd; examples 08 and 10 set damp, aug_precond, aug_sel, aug_warmup, and aug_k explicitly. damp is the weight of the newly solved amplitudes when they are mixed with the previous ones (1.0 means no damping). The aug_ options control how many residual directions are added per iteration and how they are chosen; they are described in the low_rank_ccsd entry of the API reference.

API reference

The full signatures and remaining options are in the API reference under pytc.solver.bug_mp2, pytc.solver.bug_rpa, pytc.solver.bug_ccsd, pytc.solver.bug_t, and pytc.solver.bug_core.