============================================== GP-OIE controller invariants and design record ============================================== **Status:** partially implemented. The invariants listed here hold in ``gpr/neb/GPNEB.cpp``, which runs the GP-OIE outer loop for ``NEBMode::GP_OIE`` (``gprn --nebmode gp_oie``, the default, and the Python ``gpridge.neb`` driver). The object model that an earlier draft of this page proposed (``OIEController``, ``BandTransaction``, ``SurrogateRelaxer``, ``TrustPolicy``, a Cap'n Proto ``GpOieConfig``, Python snapshot types) was not built. The section "Proposed types that do not exist" lists each of them with the symbol that does the same job in the code. This page is developer reference. How the loop behaves for a user is in :doc:`The surrogate loop and derivative observations <../../explanation/surrogate_loop>`. The default oracle-target ranking inside the variance tier is in :doc:`TPE acquisition for GP-OIE `. Purpose ------- GP-OIE (optimal image evaluation) is a nudged elastic band search in which a Gaussian-process surrogate relaxes the whole band and the potential is called only for the images chosen by an acquisition rule. The controller has to keep three kinds of geometry apart: - the accepted band, the last band whose images are certified against measured data; - the trial band, which the surrogate relaxation proposes and the trust checks may reject; - the acquisition candidate, the one image whose energy and gradient the potential is asked for next. A rejected trial must not change the accepted band. It only names the geometry to measure. Final convergence is certified from the accepted band and from forces returned by the potential, never from a trial. What the code guarantees ------------------------ Each rule below is stated by a comment or a test next to the symbol named in the right column. .. table:: +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+ | Rule | Where it is enforced | +==================================================================================================================================================================================+====================================================================================================+ | A trial band that leaves the GP trust set is rejected, and every interior image returns to its accepted position. | ``rejectUntrustedStep`` (``gpr/neb/TrustGuard.h``), tested in ``tests/gpr/neb/TrustGuardTest.cpp`` | +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+ | A joint-posterior deficit rejects the trial band and turns its selected image into an off-path energy-and-gradient acquisition. Only a resolved trial becomes the accepted band. | ``decideOieInnerProposal`` and ``OieInnerProposalDecision`` (``gpr/neb/GPNEB.h``) | +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+ | A whole-band action that the controller stages for later measurement keeps its source band and trial positions together. | ``OiePendingBandAction`` (``gpr/neb/GPNEB.h``) | +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+ | The next oracle target comes from one planner with a fixed priority order. | ``OieOracleTargetPlanner::selectPriorityTarget`` (``gpr/neb/GPNEB.cpp``) | +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+ | A posterior-based policy may replace only the replaceable arms of that order. | ``OieOracleTargetPlanner::selectPosteriorAcquisitionTarget`` | +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+ | Every point of an oracle step is evaluated once. A refusal on one rank reaches all ranks before values are exchanged. | ``parallelEvaluate`` and ``evaluateTrialPoints`` (``gpr/neb/GPNEB.cpp``) | +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+ | A refused trial point stays unmeasured and the points that returned are kept. | ``evaluateTrialPoints``, test ``GPNEBTest.OneRefusedGeometryKeepsItsBatchMates`` | +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------+ Target selection order ---------------------- ``OieOracleTargetPlanner::selectPriorityTarget`` returns an ``OieOracleTargetDecision`` (image index plus an ``OieOracleSelectionArm``). The first rule that applies wins: 1. Accepted drift of kind ``PredictionKernelBoundary`` at an interior image: the held image itself (arm ``PredictionKernelDrift``), or the rejected proposal at that image (arm ``RejectedProposal``). 2. The climbing image is not yet active and the variance gate is exceeded: the highest-variance image (arm ``Variance``). 3. The climbing image is not yet active and the current-chain image has no oracle data: that image (arm ``ActivationPriority``). 4. The convergence certificate needs current-chain data and the image clears the noise floor: arm ``CurrentChainPriority``, or ``CurrentClimbingImage`` when the image is the climbing image under convergence-only checking. 5. A pending whole-band action, unless the sweep is frozen (arm ``PSBAX``). 6. A rejected proposal at an interior image (arm ``RejectedProposal``). 7. Frozen sweep: the climbing image if it lacks data, then the image with the largest variance, then the first unmeasured interior image (arm ``FrozenSweep``). 8. A confident local recovery owns the replaceable work: no target (arm ``None``). 9. Geometric trust-boundary drift under convergence-only checking (arm ``AcceptedDrift``). 10. Convergence-only checking with an active climbing image: the climbing image if it lacks current data, then the current-chain image (arm ``CertificateDeficit``). 11. The variance gate is exceeded (arm ``Variance``). 12. Any other accepted drift that clears the noise floor, and a geometric trust-boundary drift without the floor test (arm ``AcceptedDrift``). 13. A current-chain image without data that clears the noise floor (arm ``CertificateDeficit``). 14. The climbing image without current data (arm ``CurrentClimbingImage``). 15. The highest-variance image, then the first unmeasured interior image (arms ``Variance`` and ``FirstUnobserved``). The noise-floor test (``clearsNoiseFloor``) skips a target whose predictive variance already sits at the likelihood floor, because a new measurement there cannot change a certificate. The activation arm and the geometric trust-boundary arm are exempt, as the comments in ``selectPriorityTarget`` explain. The arms that a posterior policy may replace are ``Variance``, ``FirstUnobserved`` and ``CertificateDeficit``; see :doc:`TPE acquisition for GP-OIE `. The names ``eval_next_i`` and ``eval_next_CI`` belong to the Koistinen OIE algorithm. In the code only a comment in ``GPNEB.cpp`` mentions ``eval_next_CI``. The roles of the two latches are played by the ``RejectedProposal`` and ``CurrentClimbingImage`` arms. Formal model ------------ ``docs/verification/gp_oie_state_machine.tla`` and its ``.cfg`` model the control plane as a transition system. Geometry is reduced to an integer accepted-band level. The phases are ``select``, ``oracle``, ``append``, ``predict``, ``relax``, ``check`` and ``done``, and the model includes a four-rank MPI control plane. The configuration uses ``MaxBand`` 2, ``MaxInner`` 2, ``MaxOracle`` 4 and ``NumRanks`` 4. The ``.cfg`` checks these invariants and the ``Termination`` property: .. table:: +--------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ | Obligation | TLA+ invariant | +============================================================================================+===========================================================================================+ | A failed-step target dominates the climbing-image and variance targets. | ``TargetPriority`` | +--------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ | Oracle and refit phases do not mutate the accepted band. | ``OracleDoesNotMutateAccepted`` | +--------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ | A rejected trial rolls back to the pre-trial accepted band. | ``RejectedTrialRollback`` | +--------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ | Final convergence is certified only from the accepted band. | ``ConvergenceUsesAcceptedBand`` | +--------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ | A rejection cannot certify final convergence. | ``RejectedTrialDoesNotConverge`` | +--------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ | All ranks have the same control phase, accepted band and training count after collectives. | ``SynchronizedControlState``, ``SynchronizedAcceptedBand``, ``SynchronizedTrainingState`` | +--------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ | Each evaluated oracle slot has exactly one owner rank. | ``OracleWorkPartitioned``, ``OracleWorkComplete`` | +--------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ The model is an abstraction of the code, not a proof about it. Its ``TargetPriority`` has three tiers (failed step, climbing image, variance); the planner above has more. The model does not cover kernel algebra, floating-point behaviour, L-BFGS convergence or posterior variance formulas. Nothing in ``.github/workflows`` runs it. The Pixi task ``apalache-gp-oie-state-machine`` calls ``${JAVA_HOME}/bin/java`` and the fixed Apalache jar ``/usr/share/java/apalache/apalache.jar``, so ``JAVA_HOME`` must name the selected JDK and Apalache must be installed at that system-wide path. MPI contract ------------ The code follows the contract that the model states: - Every rank runs the same control flow. Decisions made on one rank, such as the chosen oracle image, the band vector or a no-oracle decision, are broadcast from the root so that all ranks agree (``gpr/neb/OieOracleConsensus.h``). - Oracle work is partitioned. Image :math:`i` belongs to rank :math:`i \bmod P` for :math:`P` ranks (``ownerRankForImage``), and ``pot::OracleBatchLayout`` (``gpr/potentials/OracleBatch.h``) shares the points of an oracle step among the ranks. - After an oracle step every rank holds the owners' energies and gradients bit for bit, at every rank count. - An oracle refusal on any rank is shared before the value exchange, so no rank waits in a collective for a rank that has left through an exception. The consensus tests are in ``tests/gpr/neb/OieOracleConsensusTest.cpp``. Meson runs them through ``mpiexec -np 4`` as ``test_gpneb_oie_consensus_np4``, which needs an MPI build. ``tests/gpr/neb/GPNEBOieTest.cpp`` covers the GP-OIE loop itself. Traces ------ Two opt-in records describe what the loop did. Neither is a controller state snapshot. - ``OuterIterCompositionTrace`` (``gpr/neb/OuterIterCompositionTrace.h``) records the decision state of each outer iteration: oracle target, hyperparameters, barrier estimate, convergence certificates, climbing-image index and the largest oracle force. Set ``GPNEBConfig::record_composition_trace`` and read ``GPNEBResult::composition_trace``. - ``OieBandTraceRecord`` (``gpr/neb/BandTrace.h``) records the band energies, posterior energy variances and NEB force norms at each recorded outer iteration. Proposed types that do not exist -------------------------------- The earlier draft of this page proposed a type graph under ``gpr::neb::oie``. None of these types exists in the repository. The code reaches the same goals with free functions and local state inside ``gpNEB``. The only files in ``gpr/neb/oie/`` are ``AcquisitionPolicy.h`` and ``AcquisitionPolicy.cpp``. .. table:: +----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Proposed | What the code has instead | +==============================================================================================+==============================================================================================================================================================================================================+ | ``OIEController`` with one ``step`` per phase | The outer loop inside ``gpNEB`` (``gpr/neb/GPNEB.cpp``). ``OCINEBController`` (``gpr/neb/OCINEBController.h``) is a different object: it hands a converged climbing image to a minimum-mode-following burst. | +----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``OIEState`` (accepted band, ``eval_next_i``, ``eval_next_ci``, latest climbing-image index) | Local variables of ``gpNEB``. ``OiePendingBandAction`` holds a staged whole-band action. | +----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``CandidateSource`` and ``AcquisitionCandidate`` | ``OieOracleSelectionArm`` and ``OieOracleTargetDecision``. | +----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``AcquisitionPolicy::select`` for all targets | ``oie::AcquisitionPolicy`` covers only the TPE choice among replaceable arms; ``OieOracleTargetPlanner`` owns the full order. | +----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``BandTransaction`` (commit and rollback of a trial) | ``decideOieInnerProposal`` and ``rejectUntrustedStep``. | +----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``SurrogateRelaxer`` for L-BFGS bursts | The inner relaxation inside ``gpNEB``, run through the engines in ``gpr/neb/``. | +----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``TrustPolicy::certify`` | ``gpr::TrustRadius`` (``gpr/ml/TrustRadius.h``) and the guard in ``TrustGuard.h``. | +----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``PerImageModelBank`` | ``ActiveLearningSession`` (``gpr/neb/Session.h``) and ``LocalCartesianGP`` (``gpr/neb/LocalGP.h``). | +----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``CollectiveOracle`` and a distributed surrogate model | ``parallelEvaluate`` and ``OieOracleConsensus.h``. | +----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``GpOieConfig`` in ``schema/params.capnp`` | Not in the schema. GP-OIE keys live with the other NEB settings; see :doc:`the configuration reference <../../reference/configuration>` . | +----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ``OIEStateSnapshot`` and ``oie_trace`` events in ``gpridge.neb`` | Not in the Python package. The traces above are available from C++. | +----------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ If a future change builds the controller object model, this table is the list of what has to move out of ``GPNEB.cpp``. The invariants in the section "What the code guarantees" and the TLA+ obligations are the acceptance criteria for that move. Open items ---------- - The TLA+ model is not run in CI. - The planner's priority order has no TLA+ counterpart. - No test asserts the planner order as a whole. Single arms are covered inside ``tests/gpr/neb/GPNEBOieTest.cpp`` and ``tests/gpr/neb/AcquisitionPolicyTest.cpp``.