gpridge.gp

GaussianProcess: the first-class GP surrogate object.

Everything in gpridge builds from GaussianProcess. It is:

  • an ASE Calculator – atoms.calc = gp works directly, returning GP-predicted energies and forces. Variance is exposed via gp.predict_with_uncertainty(atoms) or gp.uncertainty(atoms) for acquisition and trust logic.

  • a trainable model – gp.observe(atoms) appends one evaluated structure, and gp.fit(atoms_list) can accumulate a short list and refit theta in one call. NEB / Dimer drivers use the same appender between inner-loop iterations.

  • a handoff token – pass the same GaussianProcess instance to GPNEB and then to GPDimer to chain warm-started searches. The GP carries its accumulated observations + fitted theta + the layered-chain config; downstream drivers don’t re-train cold.

Example:

from metatomic.torch.ase_calculator import MetatomicCalculator
from gpridge.gp import GaussianProcess

petmad = MetatomicCalculator("model.pt")  # an exported model file
gp = GaussianProcess(
    uncertainty='laplace',
    psis=True,
    psis_deterministic=True,
    use_delta=True,
    rff_features=512,
    hyperparameters='inla',
)

# Use directly as an ASE Calculator (after at least one fit())
initial_atoms.calc = petmad
initial_atoms.get_potential_energy()        # oracle eval
gp.fit([initial_atoms])                     # seed the GP

test_atoms.calc = gp
e_pred = test_atoms.get_potential_energy()  # GP prediction
f_pred = test_atoms.get_forces()
pred = gp.predict_with_uncertainty(test_atoms)

# Drive with NEB. Omitting model_profile leaves the library profile.
# This example names extended to keep the chain above.
from gpridge.neb import GPNEB
neb = GPNEB(images, oracle=petmad, gp=gp, model_profile="extended")
neb.run(fmax=0.05)

# Pass SAME gp to Dimer for warm-started refinement
from gpridge.dimer import GPDimer
saddle = neb.images[neb.max_energy_image]
dimer = GPDimer(saddle, oracle=petmad, gp=gp, model_profile="extended")
dimer.run(fmax=0.01)

Classes

FitDiagnostics

Summary of the most recent hyperparameter fit.

GaussianProcess

First-class GP surrogate. Acts as an ASE Calculator + a trainable model.

NoiseReport

Likelihood floor and numerical regularization, in variance units.

Prediction

Energy/force prediction plus optional uncertainty moments.

TrainingSet

Owned arrays used to fit a GP surface.

Package Contents

class gpridge.gp.FitDiagnostics

Summary of the most recent hyperparameter fit.

iterations: int
stop_reason: str
optimizer_failed: bool
class gpridge.gp.GaussianProcess(*, chain=None, uncertainty: str | None = None, use_delta: bool = False, psis: bool | None = None, psis_deterministic: bool = True, rff_features: int | str = 0, rff_force_tol_fraction: float = 0.0, hyperparameters: str = 'scg', template_atoms=None, gpr_params: dict | None = None)

Bases: _CALC_BASE

First-class GP surrogate. Acts as an ASE Calculator + a trainable model.

Parameters:
  • chain (Surrogate, optional) – Layered-chain configuration. Defaults to Surrogate.map(). Direct uncertainty= options cover the common ASE workflow.

  • uncertainty ({"map", "laplace", "laplace-slice", "bma", "eb", "svgd"}, optional) – Posterior estimator for user-facing ASE workflows. "laplace" selects the production Laplace-slice path.

  • use_delta (bool, default False) – Enable the analytical INLA-Delta variance estimator. Requires uncertainty="laplace".

  • psis (bool, optional) – Enable or disable PSIS correction inside the Laplace-slice path. Defaults to enabled when uncertainty="laplace".

  • psis_deterministic (bool, default True) – Use the deterministic axial-grid PSIS sampler for reproducible Laplace-slice corrections.

  • rff_features (int or :py:class:``”auto”:py:class:``, default 0) – Number of Random Fourier Features for the mean prediction path. Zero disables RFF. A positive count requires uncertainty="laplace". "auto" doubles the count until a held-out random-feature posterior matches the exact GP.

  • rff_force_tol_fraction (float, default 0) – Share of the 0.0514221 eV/Å force tolerance that "auto" may spend on the force error. 0 derives the share from the deployed gradient noise, so the random-feature error cannot move a converged / not-converged decision outside the band already blurred by one gradient-noise standard deviation. The energy tolerance scales the energy-noise standard deviation by the same force-tolerance-to-gradient-noise ratio. Ignored for a fixed count.

  • hyperparameters ({"scg", "inla"}, default "scg") – Hyperparameter optimization mode.

  • template_atoms (ase.Atoms, optional) – Reference structure used to materialise the GP’s AtomsConfiguration. If omitted, the first call to add_observation / predict infers it from the supplied atoms. Periodic models use its fixed cell; observations and queries must retain its atomic numbers, periodicity, and the cell vectors of its periodic axes. A partly periodic template (a slab with pbc=(True, True, False)) takes the minimum image along its periodic axes only.

  • gpr_params (dict, optional) – Override for the underlying GPR parameter dict (rare; the defaults match the gprd binary).

implemented_properties: ClassVar[list[str]] = ['energy', 'forces']

Properties calculator can handle (energy, forces, …)

name: str = 'GaussianProcess'
chain
observe(atoms, *, energy=None, forces=None) → GaussianProcess

Append an ASE geometry to the training set.

If energy and forces are supplied, no calculator is queried. Otherwise the values are read from atoms using ASE’s standard get_potential_energy() and get_forces() calls.

add_observation(atoms) → None

Append (positions, energy, forces) from an ASE Atoms object.

atoms.get_potential_energy() and atoms.get_forces() are called; the caller is responsible for having the oracle Calculator attached. Subsequent fit() will pick up the new sample.

add_evaluated_observation(atoms, energy: float, forces) → None

Append a caller-supplied energy/forces sample.

Use this from drivers that have already evaluated the oracle. The core GP stores gradients, so ASE forces are negated on insert.

fit_from_atoms(atoms_list: collections.abc.Sequence) → GaussianProcess

Convenience: add_observation for each + fit.

Each Atoms in the iterable must already have been evaluated by the oracle Calculator (i.e. get_potential_energy returns).

fit(atoms_list: collections.abc.Sequence | None = None) → GaussianProcess

Refit hyperparameters on the accumulated observations.

Cache-free: re-creates the underlying GP each call so flipping layered-chain flags between runs has no hidden state.

save(path)

Write this fitted GP to a gp-state.npz file.

to_observation()

Materialise accumulated training rows as a core Observation.

train_marginal_likelihood() → dict

Refit the current observations with the marginal-likelihood path.

append_fixed(atoms_list: collections.abc.Sequence)

Append evaluated geometries without changing fitted hyperparameters.

Returns the combined core Observation used to refresh the posterior. HS-SVD fits must first call train_marginal_likelihood(), which materializes the Cholesky factor required for this update.

calibrate_forces(atoms_list: collections.abc.Sequence, nominal_probability: float = 0.95) → dict

Calibrate force uncertainty against evaluated held-out geometries.

calibrate_loo(nominal_probability: float = 0.95) → dict

Calibrate uncertainty by leave-one-out residuals.

predict(atoms) → tuple[float, numpy.ndarray]

Return (energy, forces) predicted by the GP at atoms.

energy(x) → float

Posterior-mean energy at an Atoms object or position array.

forces(x) → numpy.ndarray

Posterior-mean ASE forces at an Atoms object or position array.

energy_and_forces(x) → tuple[float, numpy.ndarray]

Posterior-mean energy and ASE forces from one prediction.

variance(x) → float

Posterior predictive energy variance.

predict_batch(atoms_list: collections.abc.Sequence, *, with_variance: bool = True) → tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray | None, numpy.ndarray | None]

Batch predict energies, forces, and optional variances.

predict_with_uncertainty(atoms) → Prediction

Return energy, forces, and predictive variance for atoms.

uncertainty(atoms) → float

Return the predictive energy variance for atoms.

get_variance(atoms) → float

Return predictive variance at atoms. Routes through the layered-chain variance arm (MAP within-sample, INLA-Delta when configured, etc.).

predict_hessian(atoms) → numpy.ndarray

Return the symmetric (3N, 3N) posterior-mean Hessian at atoms.

predict_hessian_action(atoms, direction) → numpy.ndarray

Return H(atoms) @ direction for the posterior mean.

predict_energy_variance_interval(atoms_list: collections.abc.Sequence) → tuple[numpy.ndarray, numpy.ndarray]

Return certified (lower, upper) energy-variance bounds per geometry.

Requires an exact-kernel HS-SVD MAP model; the noise is the one the trained factor inverts (see noise_floor_report()). A negative lower endpoint is clamped to zero when the upper endpoint is nonnegative.

noise_floor_report() → dict

Return the condition-floored noise and certificate gap of the fit.

hessian_action(x, direction) → numpy.ndarray

Posterior-mean Hessian action at an Atoms object or positions.

prediction_supported(atoms) → bool

Return True when the trained kernel supports atoms.

prediction_factors(atoms) → dict

Return the prediction factors (energy, scale, mean, kstar, weights).

property fit_iterations: int

Optimizer iterations of the last fit, or -1 if unfitted.

The count is rgmin’s SCG steps plus the L-BFGS fallback steps that finish a stalled rgmin SCG fit.

property fit_restarts: int

Restarts of the last fit, or -1 if unfitted.

Only train_marginal_likelihood restarts, at most once.

property fit_stop_reason: str

Stop reason of the last fit, or 'unset' if unfitted.

A fitted model reports budget, library, restored scg point, wall-clock limit, non-finite marginal likelihood, or unset.

property hyperparameters: dict

Fitted kernel and noise parameters as owned Python values.

property training_set: TrainingSet

Copy of positions, energies, and ASE forces used by the model.

property noise_report: NoiseReport

Likelihood floor, fitted noise, jitter, and their effective sum.

property fit_diagnostics: FitDiagnostics

Optimizer status for the most recent fit.

as_calculator()

Return this surface as an ASE Calculator.

as_rgpot()

Return the trained model through rgpot’s PotentialBase interface.

This is the supported construction path. The returned surface stays current when this model is refit and retains its fitted core model if this Python owner is deleted.

property rff_selection: dict

Stored automatic random-feature selection report.

calculate(atoms=None, properties=None, system_changes=None)

Store the GP prediction for atoms in self.results.

This is the ASE calculator hook behind get_potential_energy() and get_forces(). It returns the posterior mean (eV and eV/Angstrom); properties and system_changes are ignored. Raises RuntimeError when the GP is not fitted and ValueError when no atoms are available.

property n_observations: int

Number of stored observations (geometry, energy, forces).

property is_fit: bool

True once fit() has run. Observations added afterwards do not clear it, and predictions then ignore them until fit() is called again.

class gpridge.gp.NoiseReport

Likelihood floor and numerical regularization, in variance units.

configured_floor_variance: float
fitted_likelihood_variance: float
numerical_jitter_variance: float
effective_variance: float
class gpridge.gp.Prediction

Energy/force prediction plus optional uncertainty moments.

Forces follow ASE’s sign convention. Variance fields use the GP core’s predictive variance for energy and force components.

energy: float
forces: numpy.ndarray
energy_variance: float | None = None
force_variance: numpy.ndarray | None = None
property energy_std: float | None

Standard deviation of the energy in eV, the square root of energy_variance. None when no variance was computed.

class gpridge.gp.TrainingSet

Owned arrays used to fit a GP surface.

positions: numpy.ndarray
energies: numpy.ndarray
forces: numpy.ndarray