gpridge.gp¶
GaussianProcess: the first-class GP surrogate object.
Everything in gpridge builds from GaussianProcess. It is:
an ASE Calculator –
atoms.calc = gpworks directly, returning GP-predicted energies and forces. Variance is exposed viagp.predict_with_uncertainty(atoms)orgp.uncertainty(atoms)for acquisition and trust logic.a trainable model –
gp.observe(atoms)appends one evaluated structure, andgp.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
GaussianProcessinstance toGPNEBand then toGPDimerto 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¶
Summary of the most recent hyperparameter fit. |
|
First-class GP surrogate. Acts as an ASE Calculator + a trainable model. |
|
Likelihood floor and numerical regularization, in variance units. |
|
Energy/force prediction plus optional uncertainty moments. |
|
Owned arrays used to fit a GP surface. |
Package Contents¶
- class gpridge.gp.FitDiagnostics¶
Summary of the most recent hyperparameter fit.
- 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_BASEFirst-class GP surrogate. Acts as an ASE Calculator + a trainable model.
- Parameters:
chain (
Surrogate, optional) – Layered-chain configuration. Defaults toSurrogate.map(). Directuncertainty=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, defaultFalse) – Enable the analytical INLA-Delta variance estimator. Requiresuncertainty="laplace".psis (
bool, optional) – Enable or disable PSIS correction inside the Laplace-slice path. Defaults to enabled whenuncertainty="laplace".psis_deterministic (
bool, defaultTrue) – Use the deterministic axial-grid PSIS sampler for reproducible Laplace-slice corrections.rff_features (
intor :py:class:``”auto”:py:class:``, default0) – Number of Random Fourier Features for the mean prediction path. Zero disables RFF. A positive count requiresuncertainty="laplace"."auto"doubles the count until a held-out random-feature posterior matches the exact GP.rff_force_tol_fraction (
float, default0) – 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 toadd_observation/predictinfers 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 withpbc=(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, …)
- 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
atomsusing ASE’s standardget_potential_energy()andget_forces()calls.
- add_observation(atoms) None¶
Append (positions, energy, forces) from an ASE Atoms object.
atoms.get_potential_energy()andatoms.get_forces()are called; the caller is responsible for having the oracle Calculator attached. Subsequentfit()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_observationfor each +fit.Each Atoms in the iterable must already have been evaluated by the oracle Calculator (i.e.
get_potential_energyreturns).
- 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.npzfile.
- to_observation()¶
Materialise accumulated training rows as a core Observation.
- append_fixed(atoms_list: collections.abc.Sequence)¶
Append evaluated geometries without changing fitted hyperparameters.
Returns the combined core
Observationused to refresh the posterior. HS-SVD fits must first calltrain_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.
- 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.
- 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.
- 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.
- hessian_action(x, direction) numpy.ndarray¶
Posterior-mean Hessian action at an Atoms object or positions.
- 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_likelihoodrestarts, 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, orunset.
- 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.
- calculate(atoms=None, properties=None, system_changes=None)¶
Store the GP prediction for
atomsinself.results.This is the ASE calculator hook behind
get_potential_energy()andget_forces(). It returns the posterior mean (eV and eV/Angstrom);propertiesandsystem_changesare ignored. RaisesRuntimeErrorwhen the GP is not fitted andValueErrorwhen no atoms are available.
- class gpridge.gp.NoiseReport¶
Likelihood floor and numerical regularization, in variance units.
- 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.
- forces: numpy.ndarray¶
- force_variance: numpy.ndarray | None = None¶
- class gpridge.gp.TrainingSet¶
Owned arrays used to fit a GP surface.
- positions: numpy.ndarray¶
- energies: numpy.ndarray¶
- forces: numpy.ndarray¶