gpridge.session =============== .. py:module:: gpridge.session .. autoapi-nested-parse:: Step-level GP-NEB compute session (overlay entry for ASE / pyeonclient). Mirrors the pyeonclient composition pattern:: prepare (config + oracle + atoms_config) compute (run_ocineb / gp_neb) apply (write path back to images / Matter) without re-implementing path init in pure Python (that lives in nanobind). Example (ASE):: from gpridge.session import GPNEBSession from gpridge import GaussianProcess, production_baker_high_level_kwargs sess = GPNEBSession(images, oracle=calc, gp=gp, **production_baker_high_level_kwargs()) sess.interpolate("idpp") ok = sess.compute(fmax=0.05, steps=500) # images updated in place; sess.result holds GPNEBResult / OCINEB accounting Example (pyeonclient Matter endpoints):: from gpridge.session import GPNEBSession sess = GPNEBSession.from_matters(initial, final, n_intermediate=8, oracle=calc, gp=gp, path_method="idpp") sess.compute(fmax=0.05) Classes ------- .. autoapisummary:: gpridge.session.PreparedGPNEB gpridge.session.GPNEBSessionResult gpridge.session.GPNEBSession Functions --------- .. autoapisummary:: gpridge.session.map_acquisition Module Contents --------------- .. py:function:: map_acquisition(name: str) Map string acquisition name to :class:`AcquisitionType` enum. .. py:class:: PreparedGPNEB Immutable bundle of step inputs for one compute call. .. py:attribute:: oracle :type: Any .. py:attribute:: R_initial :type: numpy.ndarray .. py:attribute:: R_final :type: numpy.ndarray .. py:attribute:: n_intermediate :type: int .. py:attribute:: gpneb_config :type: Any .. py:attribute:: ocineb_config :type: Any .. py:attribute:: gp_params :type: dict .. py:attribute:: atoms_config :type: Any .. py:attribute:: use_ocineb :type: bool :value: True .. py:class:: GPNEBSessionResult Post-compute summary (high-level fields + raw C++ results). .. py:attribute:: converged :type: bool .. py:attribute:: barrier_eV :type: float .. py:attribute:: oracle_calls :type: int .. py:attribute:: outer_iterations :type: int .. py:attribute:: max_energy_image :type: int .. py:attribute:: max_force_history :type: List[float] :value: [] .. py:attribute:: oracle_calls_endpoints :type: int :value: 0 .. py:attribute:: oracle_calls_initial :type: int :value: 0 .. py:attribute:: oracle_calls_outer :type: int :value: 0 .. py:attribute:: oracle_calls_validation :type: int :value: 0 .. py:attribute:: oracle_calls_to_convergence :type: int :value: 0 .. py:attribute:: dimer_oracle_calls :type: int :value: 0 .. py:attribute:: mmf_bursts :type: int :value: 0 .. py:attribute:: certified :type: bool :value: False .. py:attribute:: index :type: int :value: 0 .. py:attribute:: n_certificate_calls :type: int :value: 0 .. py:attribute:: reverse_barrier_eV :type: float .. py:attribute:: stop_reason :type: str :value: 'unspecified' .. py:attribute:: elapsed_s :type: float .. py:attribute:: neb_result :type: Any :value: None .. py:attribute:: oci_result :type: Any :value: None .. py:class:: GPNEBSession(images: Sequence[Any], *, oracle, gp, climb: bool = True, spring_constant: float = 5.0, seed: int = 42, use_idpp: bool = False, verbose: bool = True, acquisition: str = 'tpe', model_profile: Any = None, geometric_spring: bool = False, use_sidpp: bool = True, sidpp_alpha: float = 0.33, use_mmf: bool = False, rg_minmode_dimer: bool = False, rgsaddle_library: str = '', dimer_max_rot_iter: int = 0, dimer_eval_image1: bool = True, dimer_variance_tau_rel: float = 0.0, dimer_variance_tau_abs: float = 0.0, dimer_imspe_soft_threshold: float = 0.0, theta_shift_skip_tol: float = 0.0, theta_shift_skip_auto: bool = False, vibrational_stencil: str = 'full', logfile: Any = None, trajectory: Any = None, init_data=None) Bases: :py:obj:`gpridge._observers.ObservableDriver` Step-level GP-NEB session: interpolate → prepare → compute → apply. Holds ASE images + oracle calculator + shared GaussianProcess. :param images: Reactant, intermediate images and product, at least three images with the same atoms in the same order. The search starts from the geometries in ``images``, so fill the intermediate images first with :meth:`interpolate` or build the list with :meth:`from_endpoints`. The relaxed band is written back into these objects. :type images: :py:class:`sequence` of :py:class:`ase.Atoms` :param oracle: Provider of the true energy (eV) and forces (eV/Angstrom). :type oracle: :py:class:`ase.calculators.calculator.Calculator` :param gp: Shared surrogate. It holds the observations after the run, so it can be passed on to a :class:`~gpridge.dimer.GPDimer`. :type gp: :py:class:`gpridge.gp.GaussianProcess` :param climb: Let the highest image climb to the saddle point (``GPNEBConfig.climbing_image``). :type climb: :py:class:`bool`, *default* :py:obj:`True` :param spring_constant: NEB spring constant in eV/Angstrom^2. :type spring_constant: :py:class:`float`, *default* ``5.0`` :param seed: Random seed of the search. :type seed: :py:class:`int`, *default* ``42`` :param use_idpp: Lets the session seed the band with an IDPP-family path. It applies where the session builds the interior images: :meth:`interpolate` and ``from_endpoints`` or ``from_matters`` without an explicit ``method`` or ``path_method`` use ``"idpp"`` when it is ``True`` and ``"linear"`` when it is ``False``. :meth:`interpolate` with an explicit method uses that method even when it disagrees with this flag. ``from_endpoints`` and ``from_matters`` still raise ``ValueError`` when an explicit ``path_method`` and this flag were both passed and they disagree: an IDPP-family name (``"idpp"``, ``"idpp_collective"``, ``"sidpp"`` or ``"sidpp_geodesic"``) with ``use_idpp=False``, or any other name with ``use_idpp=True``. The constructor takes ``images`` as given and searches that band, so ``prepare`` sets ``GPNEBConfig.use_idpp`` to ``False`` whatever this argument says. :type use_idpp: :py:class:`bool`, *default* :py:obj:`False` :param verbose: Write the C++ progress report to standard error. :type verbose: :py:class:`bool`, *default* :py:obj:`True` :param acquisition: Rule that picks the next image to measure: ``"ucb"``, ``"max_variance"``, ``"max_force"``, ``"thompson_sampling"``, ``"expected_improvement"``, ``"imspe"``, ``"tpe"`` or ``"psbax"``. Short forms such as ``"maxvar"``, ``"ts"`` and ``"ei"`` and the names of the ``AcquisitionType`` members (``"PriorityCascade"`` among them) are accepted, and an unknown name raises ``ValueError``. :type acquisition: :py:class:`str`, *default* ``"tpe"`` :param model_profile: GP model profile copied onto ``GPNEBConfig``. ``None`` keeps the library profile. Strings are ``"gprd_zbl"``, ``"chemgp"`` and ``"extended"``. :type model_profile: :py:class:`str` or :py:class:`~gpridge._core.GPModelProfile` or :py:obj:`None` :param vibrational_stencil: Coordinates the true-oracle Hessian stencil displaces. ``"full"`` measures every Cartesian coordinate and the resolution includes the rigid columns. ``"vibrational"`` displaces only the vibrational directions and can call a borderline mode resolved where ``"full"`` calls it unresolved. :type vibrational_stencil: ``{"full", "vibrational"}``, *default* ``"full"`` :param geometric_spring: Use the geometric (cubic-potential) spring, which keeps dense bands from developing a stiff-spring instability (``GPNEBConfig.use_geometric_spring``). :type geometric_spring: :py:class:`bool`, *default* :py:obj:`False` :param use_sidpp: Forwarded to ``GPNEBConfig.use_sidpp``, the sequential-IDPP flag of the C++ path initialisation. :type use_sidpp: :py:class:`bool`, *default* :py:obj:`True` :param sidpp_alpha: Blend parameter of the sequential-IDPP path. It is used by :meth:`interpolate` and :meth:`from_endpoints` for the ``"sidpp"`` path methods and forwarded to ``GPNEBConfig.sidpp_alpha``. :type sidpp_alpha: :py:class:`float`, *default* ``0.33`` :param use_mmf: Run a minimum-mode-following dimer burst on the climbing image (``OCINEBConfig.use_mmf``, the master switch of the ``dimer_*`` options below). :type use_mmf: :py:class:`bool`, *default* :py:obj:`False` :param rg_minmode_dimer: Use the RgMinMode dimer for the climbing-image burst instead of ``AtomicDimer`` (``OCINEBConfig.rg_minmode_dimer``). :type rg_minmode_dimer: :py:class:`bool`, *default* :py:obj:`False` :param rgsaddle_library: Selection for the index test after convergence (``GPNEBConfig.rgsaddle_library``). Non-empty text turns the test on. The linked librgsaddle runs it. The empty string leaves the test off. :type rgsaddle_library: :py:class:`str`, *default* ``""`` :param dimer_max_rot_iter: Passed to ``OCINEBConfig.dimer_max_rot_iter``, the number of surrogate rotations per dimer translation in a climbing-image burst. The C++ default is 10. :type dimer_max_rot_iter: :py:class:`int`, *default* ``0`` :param dimer_eval_image1: Evaluate the forward dimer image with the oracle at each dimer phase (``OCINEBConfig.dimer_eval_image1``). :type dimer_eval_image1: :py:class:`bool`, *default* :py:obj:`True` :param dimer_variance_tau_rel: Relative variance gate for dimer oracle calls. When positive, a dimer phase whose candidate has a posterior variance below this fraction of the GP signal variance uses the GP mean instead of an oracle call. Zero disables it. :type dimer_variance_tau_rel: :py:class:`float`, *default* ``0.0`` :param dimer_variance_tau_abs: Absolute variance gate in eV^2. It takes precedence over ``dimer_variance_tau_rel`` when positive. :type dimer_variance_tau_abs: :py:class:`float`, *default* ``0.0`` :param dimer_imspe_soft_threshold: Soft gate on the IMSPE score of a dimer candidate; a score below it suppresses the oracle call. Zero disables it. :type dimer_imspe_soft_threshold: :py:class:`float`, *default* ``0.0`` :param theta_shift_skip_tol: Skip the hyperparameter optimisation when the scale-free MAP stationarity measure at the current parameters is below this tolerance. Zero disables the gate. :type theta_shift_skip_tol: :py:class:`float`, *default* ``0.0`` :param theta_shift_skip_auto: Use the GP optimiser's displacement tolerance as the stationarity threshold. :type theta_shift_skip_auto: :py:class:`bool`, *default* :py:obj:`False` :param logfile: One line per oracle call. A string or path-like object is a file name and ``"-"`` is standard output. :type logfile: :py:class:`str`, :py:class:`os.PathLike`, :py:class:`file-like` or :py:obj:`None` :param trajectory: A file name opens a readcon trajectory with every oracle-evaluated geometry, its energy and its forces, which needs the ``readcon`` package. An object with ``write`` may be passed instead. :type trajectory: :py:class:`str`, :py:class:`os.PathLike`, :py:class:`file-like` or :py:obj:`None` .. rubric:: Notes ``model_profile`` is copied onto ``GPNEBConfig`` in :meth:`prepare`. The Baker-24 board configurations use ``"gprd_zbl"``. ``logfile``, ``trajectory`` and :meth:`~gpridge._observers.ObservableDriver.attach` follow ASE optimizers, with one step per oracle (true potential) call; see :mod:`gpridge._observers`. .. py:attribute:: images .. py:attribute:: oracle .. py:attribute:: gp .. py:attribute:: init_data :value: None .. py:attribute:: climb :value: True .. py:attribute:: spring_constant .. py:attribute:: seed :value: 42 .. py:attribute:: use_idpp :value: False .. py:attribute:: verbose :value: True .. py:attribute:: acquisition :value: '' .. py:attribute:: model_profile :value: None .. py:attribute:: geometric_spring :value: False .. py:attribute:: use_sidpp :value: True .. py:attribute:: sidpp_alpha .. py:attribute:: use_mmf :value: False .. py:attribute:: rg_minmode_dimer :value: False .. py:attribute:: rgsaddle_library :value: '' .. py:attribute:: dimer_max_rot_iter :value: 0 .. py:attribute:: dimer_eval_image1 :value: True .. py:attribute:: dimer_variance_tau_rel .. py:attribute:: dimer_variance_tau_abs .. py:attribute:: dimer_imspe_soft_threshold .. py:attribute:: theta_shift_skip_tol .. py:attribute:: theta_shift_skip_auto :value: False .. py:attribute:: vibrational_stencil :value: '' .. py:attribute:: prepared :type: Optional[PreparedGPNEB] :value: None .. py:attribute:: result :type: Optional[GPNEBSessionResult] :value: None .. py:method:: from_endpoints(reactant: Any, product: Any, n_intermediate: int, *, oracle, gp, path_method: Optional[str] = None, **kwargs) -> GPNEBSession :classmethod: ASE endpoints + C++ path init → session. ``path_method=None`` seeds with ``"idpp"`` when ``use_idpp=True`` is among *kwargs*, and with ``"linear"`` otherwise. An explicit ``path_method`` is the seed by itself. .. py:method:: from_matters(initial: Any, final: Any, n_intermediate: int, *, oracle=None, gp, path_method: Optional[str] = None, calculator=None, **kwargs) -> GPNEBSession :classmethod: pyeonclient Matter (or duck-type) endpoints → ASE session. ``path_method=None`` follows ``use_idpp`` as in :meth:`from_endpoints`. *oracle* or *calculator* must evaluate the PES. Prefer an ASE Calculator as *oracle*; Matter-bound pots are converted when possible. .. py:property:: n_images :type: int Number of images, endpoints included. .. py:property:: n_intermediate :type: int Number of images between the two endpoints. .. py:method:: interpolate(method: Optional[str] = None) -> None C++ path-init step into ``self.images`` (same as GPNEB.interpolate). ``method=None`` uses ``"idpp"``, or ``"linear"`` when ``use_idpp`` is ``False``. An explicit method is the seed even when it disagrees with ``use_idpp``. ``from_endpoints`` still rejects that pair when both were passed to the constructor. .. py:method:: path_matrix() -> numpy.ndarray Positions of all images, shape ``(n_images, 3 * n_atoms)``. .. py:method:: prepare(fmax: float = 0.05, steps: int = 200, *, max_inner_iter_gp: int = 0, inner_conv_tol: float = 0.001, lbfgs_max_move: float = 0.1, lbfgs_memory: int = 20, band_engine=None, lbfgs_inverse_curvature: float = 0.01, lbfgs_finite_difference: float = 1e-06, lbfgs_auto_scale: bool = True, lbfgs_angle_reset: bool = True, lbfgs_distance_reset: bool = True, oie_hook_reparam: bool = True, reparam_period: int = 0, reparam_tol: float = -1.0, use_ocineb: bool = True) -> PreparedGPNEB Step: build GPNEBConfig, OCINEBConfig, oracle, atoms_config. :param fmax: Force tolerance of the band in eV/Angstrom (``GPNEBConfig.conv_tol``). :type fmax: :py:class:`float`, *default* ``0.05`` :param steps: Outer-iteration budget (``GPNEBConfig.max_outer_iter``). :type steps: :py:class:`int`, *default* ``200`` :param max_inner_iter_gp: Cap on the inner relaxation on the surrogate. Zero or less stops on the inner tolerance only; a positive value adds an explicit iteration cap. :type max_inner_iter_gp: :py:class:`int`, *default* ``0`` :param inner_conv_tol: Force tolerance of the inner surrogate relaxation in eV/Angstrom. The C++ default is 0.05. :type inner_conv_tol: :py:class:`float`, *default* ``1e-3`` :param lbfgs_max_move: Largest Cartesian displacement of one atom in one band L-BFGS step, in Angstrom. Values above 0.2 trigger a one-time warning from the C++ side. :type lbfgs_max_move: :py:class:`float`, *default* ``0.1`` :param lbfgs_memory: Number of stored L-BFGS correction pairs. :type lbfgs_memory: :py:class:`int`, *default* ``20`` :param band_engine: Inner band stepper. ``None`` keeps the library default (``RgLbfgs``). ``InternalLbfgs`` is the parity harness. :type band_engine: :py:class:`BandEngineKind` or :py:obj:`None` :param lbfgs_inverse_curvature: Initial inverse-Hessian scale of the band L-BFGS. :type lbfgs_inverse_curvature: :py:class:`float`, *default* ``0.01`` :param lbfgs_finite_difference: Step of the curvature probe used by ``lbfgs_auto_scale``. :type lbfgs_finite_difference: :py:class:`float`, *default* ``1e-6`` :param lbfgs_auto_scale: Scale the initial inverse Hessian from a curvature probe. :type lbfgs_auto_scale: :py:class:`bool`, *default* :py:obj:`True` :param lbfgs_angle_reset: Discard the L-BFGS history and take a scaled force step when the quasi-Newton step points more than 90 degrees away from the force. :type lbfgs_angle_reset: :py:class:`bool`, *default* :py:obj:`True` :param lbfgs_distance_reset: Discard the L-BFGS history and take a scaled force step when the quasi-Newton step would move an atom by ``lbfgs_max_move`` or more. :type lbfgs_distance_reset: :py:class:`bool`, *default* :py:obj:`True` :param oie_hook_reparam: Redistribute the band after retained local path motions when the redistributed band already has oracle support. :type oie_hook_reparam: :py:class:`bool`, *default* :py:obj:`True` :param reparam_period: Legacy periodic reparametrisation control. The search reparametrises only after a retained hook motion changes the band. :type reparam_period: :py:class:`int`, *default* ``0`` :param reparam_tol: Legacy spacing trigger, kept for callers that set it. :type reparam_tol: :py:class:`float`, *default* ``-1.0`` :param use_ocineb: Run the search through ``run_ocineb``, which adds the optional climbing-image dimer burst. ``False`` calls ``gp_neb`` directly. :type use_ocineb: :py:class:`bool`, *default* :py:obj:`True` :returns: The oracle, endpoints and configurations that :meth:`compute` hands to the C++ search. The object is also stored as ``self.prepared``. :rtype: :py:class:`PreparedGPNEB` .. py:method:: compute(fmax: float = 0.05, steps: int = 200, *, prepared: Optional[PreparedGPNEB] = None, apply: bool = True, fit_gp: bool = True, **prepare_kw) -> bool Step: run_ocineb (or gp_neb) then optionally apply to images. :param fmax: As in :meth:`prepare`. :param steps: As in :meth:`prepare`. :param prepared: Result of an earlier :meth:`prepare`. When omitted, ``compute`` calls :meth:`prepare` with ``fmax``, ``steps`` and ``prepare_kw``. :type prepared: :py:class:`PreparedGPNEB`, *optional* :param apply: Write the relaxed band into ``images``. :type apply: :py:class:`bool`, *default* :py:obj:`True` :param fit_gp: Refit the shared GP on its observations after the search. :type fit_gp: :py:class:`bool`, *default* :py:obj:`True` :param \*\*prepare_kw: Further keyword arguments of :meth:`prepare`. :returns: Whether the C++ result reports convergence. The summary is stored as ``self.result``. :rtype: :py:class:`bool` .. py:method:: apply(neb_result: Any = None) -> None Step: write GPNEBResult into ``self.images``. .. py:method:: run(fmax: float = 0.05, steps: int = 200, **kw) -> bool Run :meth:`prepare`, :meth:`compute` and :meth:`apply` in one call. ``fmax`` and ``steps`` are the force tolerance in eV/Angstrom and the outer-iteration budget. ``**kw`` takes the keyword arguments of :meth:`prepare`. Returns whether the band converged. .. py:method:: to_gpneb() Materialize a high-level :class:`~gpridge.neb.GPNEB` sharing state.