Skip to content

Batched evaluation¤

One vmapped solve over a stack of geometries. Orbital-sized outputs are opt-in; mesh= shards the batch axis across devices.

dftax.ks.batched.scf_batched(mol, coords_batch, xc, *, spin: int | None = None, grid: Becke | None = None, coulomb: ExactSpec | DFSpec | None = None, dispersion=None, forces: bool = False, return_orbitals: bool = False, mesh: MeshSpec | None = None, max_iter: int = 128, e_tol: float = 1e-08, d_tol: float = 1e-06, diis_space: int = 8, level_shift: float = 0.0, guess=None) -> BatchedResult ¤

SCF over many geometries of the same molecule in one compiled call.

Parameters:

Name Type Description Default
mol Molecule

the molecule; gives the atoms, basis, charge and spin.

required
coords_batch Array

nuclear coordinates (Bohr), (B, natom, 3).

required
xc XCFunctional

the exchange-correlation functional.

required
spin int | None

as for :class:~dftax.ks.energy.KS.

None
grid Becke | None

a :func:~dftax.grid.becke spec (rebuilt per geometry).

None
coulomb ExactSpec | DFSpec | None

:func:~dftax.ks.terms.df (the default) or plain :func:~dftax.ks.terms.exact; screen is not supported.

None
dispersion D3BJSpec | D4Spec | None

a :func:~dftax.energy.d3.d3bj or :func:~dftax.energy.d4.d4 spec.

None
forces bool

also compute the forces.

False
return_orbitals bool

also return the orbitals and densities (O(B·nao²) memory).

False
mesh MeshSpec | None

a :func:~dftax.ks.shard.mesh spec to divide the batch over devices.

None
max_iter int

as for :func:~dftax.ks.scf.scf.

128
e_tol float

as for :func:~dftax.ks.scf.scf.

1e-08
d_tol float

as for :func:~dftax.ks.scf.scf.

1e-06
diis_space int

as for :func:~dftax.ks.scf.scf.

8
level_shift float

as for :func:~dftax.ks.scf.scf.

0.0
guess GuessSpec | None

a guess spec from :mod:dftax.ks.guess; density arrays are not accepted.

None

Returns:

Name Type Description
A BatchedResult

class:BatchedResult.

Raises:

Type Description
ValueError

grid is not a :func:~dftax.grid.becke spec, exact with screen or stream, or forces=True with a hybrid on the streamed density-fitting backend.

TypeError

guess is not a spec.

dftax.ks.batched.BatchedResult ¤

Results of :func:scf_batched, one entry per geometry along the leading axis B.

Attributes:

Name Type Description
e_tot

total energies (Ha), (B,).

e_elec

electronic energies (Ha), (B,).

converged

whether each solve converged, (B,).

n_iter

iterations of each solve, (B,).

nocc

occupied orbitals per spin channel.

forces

forces (Ha/Bohr), (B, natom, 3), with forces=True.

mo_energy

orbital energies, (B, nspin, nmo), with return_orbitals=True.

mo_coeff

orbital coefficients, (B, nspin, nao, nmo), with return_orbitals=True.

P

density matrices, (B, nspin, nao, nao), with return_orbitals=True.

__annotations__ class-attribute ¤

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

__dataclass_fields__ class-attribute ¤

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

__dataclass_params__ class-attribute ¤
__dict__ class-attribute ¤

Read-only proxy of a mapping.

__doc__ class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.

__firstlineno__ class-attribute ¤

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer iteral.

int('0b100', base=0) 4

__match_args__ class-attribute ¤

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

__module__ class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.

__static_attributes__ class-attribute ¤

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

__weakref__ property ¤

list of weak references to the object

__eq__(other) ¤
__init__(e_tot: Float[Array, B], e_elec: Float[Array, B], converged: Array, n_iter: Array, nocc: tuple[int, ...], forces: Float[Array, 'B n_atom 3'] | None = None, mo_energy: Float[Array, 'B nspin nmo'] | None = None, mo_coeff: Float[Array, 'B nspin nao nmo'] | None = None, P: Float[Array, 'B nspin nao nao'] | None = None) -> None ¤
__repr__() ¤

Batched direct minimization¤

Different molecules padded to common sizes and minimized in one compiled program, closed and open shells, pure and hybrid. A system left unconverged or in a non-aufbau state is re-solved alone by gdm (BatchedGDMResult.fallback).

dftax.ks.batched_gdm.gdm_batched(kss: Sequence[KS], *, max_iter: int = 200, e_tol: float = 1e-08, d_tol: float = 1e-06, history: int = 20, max_step: float = 0.5, gap_floor: float = 0.05, guess: GuessSpec | jax.Array | None = None, bucket: Bucket | None = None, fallback: bool = True) -> BatchedGDMResult ¤

Direct minimization of many systems at once, padded to common sizes and solved in one compiled call.

The tolerances and step controls are those of :func:~dftax.ks.gdm.gdm.

Parameters:

Name Type Description Default
kss Sequence[KS]

the systems, each a :class:~dftax.ks.energy.KS built with coulomb=df(chunk=None) and grid=becke(chunk=None). Closed and open shells and different functionals may be mixed.

required
bucket Bucket | None

fixed padded sizes for a batch of one spin type and one functional, so batches of similar molecules reuse one compiled program; None uses the smallest sizes that fit.

None
guess GuessSpec | Array | None

a guess, as for :func:~dftax.ks.scf.scf.

None
fallback bool

re-solve alone, with :func:~dftax.ks.gdm.gdm, every system the batch leaves unconverged or in a state whose occupied orbitals are not the lowest ones.

True

Returns:

Name Type Description
A BatchedGDMResult

class:BatchedGDMResult.

Raises:

Type Description
NotImplementedError

a system with streamed density fitting or grid values, or with VV10.

ValueError

a bucket with mixed spin types or functionals.

dftax.ks.batched_gdm.BatchedGDMResult ¤

Results of :func:gdm_batched, in the order of the input systems.

Attributes:

Name Type Description
e_tot

total energies (Ha).

converged

whether each system converged.

n_iter

energy evaluations of each system.

P

density matrix of each system, (nspin, nao, nao).

fallback

whether each system was re-solved alone with :func:~dftax.ks.gdm.gdm.

__annotations__ class-attribute ¤

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

__dataclass_fields__ class-attribute ¤

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

__dataclass_params__ class-attribute ¤
__dict__ class-attribute ¤

Read-only proxy of a mapping.

__doc__ class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.

__firstlineno__ class-attribute ¤

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer iteral.

int('0b100', base=0) 4

__match_args__ class-attribute ¤

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

__module__ class-attribute ¤

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.

__static_attributes__ class-attribute ¤

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.

If the argument is a tuple, the return value is the same object.

__weakref__ property ¤

list of weak references to the object

__eq__(other) ¤
__init__(e_tot: np.ndarray, converged: np.ndarray, n_iter: np.ndarray, P: list, fallback: np.ndarray = None) -> None ¤
__repr__() ¤