gpridge._observers

ASE-optimizer-style observers for the GP drivers.

GPNEB and GPDimer run their whole outer loop in C++, so there is no Python step at which an ASE Optimizer would call its observers. The one Python event the loop has is the oracle evaluation: every true energy and force call passes through the calculator bridge in gpridge.ase_bridge. The drivers therefore count one step per oracle call, and attach, logfile and trajectory act on those steps the way they act on optimizer steps in ASE:

  • attach(function, interval=1, *args, **kwargs) calls function(*args, **kwargs) after every interval-th oracle call;

  • logfile receives one line per oracle call ("-" is stdout);

  • trajectory receives the evaluated geometry with its energy and forces. A path is a readcon trajectory, one frame per oracle call, readable by readcon, eOn and the drivers. An object with write is used as is.

GP-predicted geometries are never reported: they cost no oracle call and are not ground truth.

Classes

ConTrajectoryWriter

Append evaluated geometries to a .con file through readcon.

OracleObservers

Observer list, log and trajectory driven by oracle evaluations.

ObservableDriver

attach / logfile / trajectory surface for a GP driver.

Module Contents

class gpridge._observers.ConTrajectoryWriter(path: str)

Append evaluated geometries to a .con file through readcon.

Each write adds one frame with the positions, the cell, the fixed flags, the energy and the forces of an Atoms whose calculator holds them, and flushes it, so the file is complete after every call.

path
write(atoms: Any) → None

Append atoms as one frame and flush it to the file.

close() → None

Do nothing; every write() has already flushed the file.

class gpridge._observers.OracleObservers(name: str, logfile: Any = None, trajectory: Any = None)

Observer list, log and trajectory driven by oracle evaluations.

Parameters:
  • name (str) – Label written at the start of each log line.

  • logfile (str, os.PathLike, file-like or None) – "-" writes to stdout, a string or path-like object opens that path for writing, an object with write is used as is, None disables logging.

  • trajectory (str or None) – A path opens a readcon trajectory. An object with write is used as is.

name = ''
nsteps = 0
observers: List[Tuple[Callable[Ellipsis, Any], int, tuple, dict, bool]] = []
last_atoms: Any = None
logfile = None
trajectory = None
attach(function: Callable[Ellipsis, Any], interval: int = 1, *args, **kwargs) → None

Call function(*args, **kwargs) every interval oracle calls.

As in ASE, an object with a write method may stand in for the function. Its write is called with the evaluated Atoms (energy and forces attached) followed by args, because the drivers do not move the caller’s Atoms during a run. Plain callables read the same geometry from last_atoms.

notify(atoms: Any, energy: float, forces: numpy.ndarray) → None

Record one oracle evaluation of atoms.

close() → None

Close the log and trajectory this object opened itself.

class gpridge._observers.ObservableDriver

attach / logfile / trajectory surface for a GP driver.

Subclasses call _init_observers in __init__ and pass observers to the calculator bridge.

observers: OracleObservers
property nsteps: int

Oracle evaluations recorded since construction.

property last_atoms

The most recent oracle-evaluated geometry, or None.

attach(function: Callable[Ellipsis, Any], interval: int = 1, *args, **kwargs) → None

Attach an observer; see OracleObservers.attach().

close() → None

Close a log or trajectory the driver opened from a path.