42double& helpedModeCurvatureSlot()
44 static double value = std::numeric_limits<double>::quiet_NaN();
51 return helpedModeCurvatureSlot();
56struct OracleNoiseUpdatePause {
57 explicit OracleNoiseUpdatePause(
bool* enabled_in)
58 : enabled(enabled_in), previous(enabled_in ? *enabled_in : true)
60 if (enabled) *enabled =
false;
63 ~OracleNoiseUpdatePause()
65 if (enabled) *enabled = previous;
68 bool* enabled =
nullptr;
72bool isLowerValidSaddleEnergy(
double reference_saddle_energy,
73 double candidate_saddle_energy,
74 double reactant_energy,
double product_energy)
76 return std::isfinite(reference_saddle_energy) &&
77 std::isfinite(candidate_saddle_energy) &&
78 candidate_saddle_energy < reference_saddle_energy &&
79 isTruePesSaddleEnergyCandidate(candidate_saddle_energy,
80 reactant_energy, product_energy);
83MmfRecoveryPhaseEvidence recordedMmfRecoveryPhaseEvidence(
84 const atmd::AtomicDimer::DimerPhaseRecord& phase,
double energy_zero,
85 Eigen::Index expected_dimension)
87 MmfRecoveryPhaseEvidence evidence;
89 phase.
gradient.cols() != expected_dimension ||
91 !std::isfinite(energy_zero)) {
94 evidence.energy = phase.
energy + energy_zero;
95 if (!std::isfinite(evidence.energy))
return evidence;
96 evidence.gradient = phase.
gradient.row(0).transpose();
97 evidence.oracle_certified =
true;
101void appendAcceptedMmfRecoveryObservation(ActiveLearningSession& session,
102 int image_idx,
const Image& accepted)
104 if (image_idx < 0 || !accepted.evaluated ||
105 accepted.positions.size() == 0 || accepted.gradient.size() == 0 ||
106 accepted.positions.size() != accepted.gradient.size() ||
107 !accepted.positions.allFinite() || !accepted.gradient.allFinite() ||
108 !std::isfinite(accepted.energy)) {
111 session.appendCurrentChainObservation(
112 image_idx, accepted.positions, accepted.energy, accepted.gradient,
117MmfRecoveryAcceptanceDecision classifyMmfRecovery(
118 double pre_force,
double recovery_force,
double recovery_displacement,
119 double max_displacement,
double acceptance_force_threshold,
120 bool keep_force_improving_burst,
double reference_saddle_energy,
121 double candidate_saddle_energy,
double reactant_energy,
122 double product_energy,
bool candidate_saddle_certified,
123 bool candidate_path_mode_certified,
124 bool candidate_measured_descent_certified)
126 MmfRecoveryAcceptanceDecision decision;
127 if (!std::isfinite(pre_force) || !std::isfinite(recovery_force)) {
130 decision.finite_input =
true;
131 decision.force_improves = recovery_force < pre_force;
132 decision.threshold_limited = acceptance_force_threshold > 0.0 &&
133 std::isfinite(acceptance_force_threshold);
134 decision.threshold_passed = decision.threshold_limited &&
135 recovery_force < acceptance_force_threshold;
138 decision.has_displacement_trust =
139 std::isfinite(max_displacement) && max_displacement > 0.0;
140 if (decision.has_displacement_trust) {
141 decision.within_displacement_trust =
142 std::isfinite(recovery_displacement) &&
143 recovery_displacement <= max_displacement;
145 decision.uncertified_energy_descent =
146 !candidate_saddle_certified && std::isfinite(reference_saddle_energy) &&
147 std::isfinite(candidate_saddle_energy) &&
148 candidate_saddle_energy < reference_saddle_energy;
149 decision.measured_path_continuation = decision.force_improves &&
150 candidate_path_mode_certified &&
151 candidate_measured_descent_certified;
152 decision.measured_trust_bounded_progress =
153 decision.force_improves && candidate_measured_descent_certified &&
154 decision.has_displacement_trust && decision.within_displacement_trust;
160 const bool trusted_path_aligned_progress =
161 decision.force_improves && candidate_path_mode_certified &&
162 ((decision.has_displacement_trust &&
163 decision.within_displacement_trust) ||
164 decision.measured_path_continuation);
165 if (decision.uncertified_energy_descent && !trusted_path_aligned_progress &&
166 !decision.measured_trust_bounded_progress) {
169 if (decision.has_displacement_trust) {
170 if (!decision.within_displacement_trust &&
171 !decision.measured_path_continuation) {
174 decision.lower_valid_saddle_energy =
175 candidate_saddle_certified &&
176 isLowerValidSaddleEnergy(reference_saddle_energy,
177 candidate_saddle_energy, reactant_energy,
179 if (!decision.force_improves) {
184 const bool on_ridge_min_mode =
185 !decision.uncertified_energy_descent &&
186 isTruePesSaddleEnergyCandidate(candidate_saddle_energy,
187 reactant_energy, product_energy);
189 decision.lower_valid_saddle_energy || on_ridge_min_mode;
192 if (!keep_force_improving_burst && decision.threshold_limited &&
193 !decision.threshold_passed) {
194 decision.accepted = decision.lower_valid_saddle_energy;
207 if (std::isfinite(candidate_saddle_energy) &&
208 std::isfinite(reactant_energy) && std::isfinite(product_energy) &&
209 !isTruePesSaddleEnergyCandidate(candidate_saddle_energy,
210 reactant_energy, product_energy)) {
211 decision.accepted =
false;
214 decision.accepted =
true;
221 (void)keep_force_improving_burst;
222 if (!decision.force_improves) {
225 if (!decision.threshold_limited) {
230 if (std::isfinite(candidate_saddle_energy) &&
231 std::isfinite(reactant_energy) && std::isfinite(product_energy) &&
232 !isTruePesSaddleEnergyCandidate(candidate_saddle_energy,
233 reactant_energy, product_energy)) {
236 decision.accepted = decision.threshold_passed;
240bool shouldAcceptMmfRecovery(
241 double pre_force,
double recovery_force,
double recovery_displacement,
242 double max_displacement,
double acceptance_force_threshold,
243 bool keep_force_improving_burst,
double reference_saddle_energy,
244 double candidate_saddle_energy,
double reactant_energy,
245 double product_energy,
bool candidate_saddle_certified,
246 bool candidate_path_mode_certified,
247 bool candidate_measured_descent_certified)
249 return classifyMmfRecovery(
250 pre_force, recovery_force, recovery_displacement,
251 max_displacement, acceptance_force_threshold,
252 keep_force_improving_burst, reference_saddle_energy,
253 candidate_saddle_energy, reactant_energy, product_energy,
254 candidate_saddle_certified, candidate_path_mode_certified,
255 candidate_measured_descent_certified)
259bool shouldRejectUncertifiedMmfRecoveryHandback(
double recovery_force,
260 double recovery_displacement,
261 double max_displacement,
262 double force_tolerance)
264 if (!std::isfinite(recovery_force) || recovery_force <= 0.0) {
267 if (!std::isfinite(force_tolerance) || force_tolerance <= 0.0) {
270 if (!std::isfinite(max_displacement) || max_displacement <= 0.0) {
273 if (!std::isfinite(recovery_displacement) ||
274 recovery_displacement <= max_displacement) {
280 return (recovery_force - force_tolerance) <= force_tolerance;
283bool isConvergenceScaleForce(
double force,
double force_tolerance)
285 if (!std::isfinite(force) || force <= 0.0)
return false;
286 if (!std::isfinite(force_tolerance) || force_tolerance <= 0.0) {
289 return (force - force_tolerance) <= force_tolerance;
292double effectiveMmfRecoveryDisplacementCap(
double configured_cap,
294 double right_spacing)
296 if (std::isfinite(configured_cap) && configured_cap > 0.0) {
297 return configured_cap;
300 double cap = std::numeric_limits<double>::infinity();
301 if (std::isfinite(left_spacing) && left_spacing > 0.0) {
302 cap = std::min(cap, left_spacing);
304 if (std::isfinite(right_spacing) && right_spacing > 0.0) {
305 cap = std::min(cap, right_spacing);
307 return std::isfinite(cap) ? cap : configured_cap;
310bool shouldRejectUncertifiedHelpedDisplacement(
bool dimer_converged,
311 bool helped_angle_certified,
312 double helped_displacement,
313 double max_displacement)
315 if (!dimer_converged || helped_angle_certified)
return false;
316 if (!std::isfinite(max_displacement) || max_displacement <= 0.0) {
319 return !std::isfinite(helped_displacement) ||
320 helped_displacement > max_displacement;
323bool shouldRejectForceOnlyHelpedBelowEndpoints(
bool dimer_converged,
324 bool helped_angle_certified,
325 double dimer_final_energy,
326 double reactant_energy,
327 double product_energy)
332 if (!dimer_converged || helped_angle_certified)
return false;
333 return !isTruePesSaddleEnergyCandidate(dimer_final_energy, reactant_energy,
337std::string forceOnlyHelpedBelowEndpointDiagnostic(
double dimer_final_energy,
338 double reactant_energy,
339 double product_energy)
341 std::ostringstream os;
342 const double endpoint_floor = std::max(reactant_energy, product_energy);
343 os <<
"force-only below path endpoints: E=" << dimer_final_energy
344 <<
", reactant=" << reactant_energy <<
", product=" << product_energy
345 <<
", endpoint_floor=" << endpoint_floor
346 <<
", forward_barrier=" << (dimer_final_energy - reactant_energy)
347 <<
", reverse_barrier=" << (dimer_final_energy - product_energy);
351std::string trustedRecoveryAdvanceDiagnostic(
353 int recovery_phase, std::size_t phase_count,
double curvature,
354 double recovery_baseline,
double recovery_force,
double raw_pre_force,
355 double raw_force,
double reference_energy,
double candidate_energy,
356 double reactant_energy,
double product_energy,
bool saddle_certified)
358 const bool lower_valid_energy =
359 std::isfinite(reference_energy) && std::isfinite(candidate_energy) &&
360 candidate_energy < reference_energy &&
361 isTruePesSaddleEnergyCandidate(candidate_energy, reactant_energy,
363 const char* termination =
"relaxation handback";
364 switch (termination_reason) {
366 termination =
"force-converged termination";
369 termination =
"true-PES non-descent handback";
372 termination =
"degenerate-probe handback";
375 termination =
"measured index-zero handback";
378 termination =
"uninformative-rotation handback";
381 termination =
"alignment termination";
384 termination =
"interatomic-collapse termination";
387 termination =
"invalid-atoms-configuration termination";
390 termination =
"oracle-budget termination";
393 termination =
"wall-clock limit termination";
396 termination =
"invalid-parameters termination";
399 termination =
"step-budget termination";
402 termination =
"uncertified-force termination";
407 std::ostringstream os;
408 os << termination <<
", advanced CI to trusted negative-curvature phase "
409 << recovery_phase <<
"/" << phase_count <<
" (curv = " << curvature
410 <<
", recovery force " << recovery_baseline <<
" -> " << recovery_force
411 <<
", raw force " << raw_pre_force <<
" -> " << raw_force <<
", "
412 << (saddle_certified ?
"saddle energy " :
"candidate energy ")
413 << reference_energy <<
" -> " << candidate_energy
414 <<
", lower_valid_energy=" << (lower_valid_energy ? 1 : 0)
415 <<
", saddle_certified=" << (saddle_certified ? 1 : 0) <<
")";
423double mmfRecoveryForceBaseline(
double pre_neb_force,
double pre_raw_force)
425 double baseline = 0.0;
427 if (std::isfinite(pre_neb_force) && pre_neb_force > 0.0) {
428 baseline = pre_neb_force;
431 if (std::isfinite(pre_raw_force) && pre_raw_force > 0.0) {
432 baseline = any ? std::max(baseline, pre_raw_force) : pre_raw_force;
435 return any ? baseline : std::numeric_limits<double>::infinity();
438int chooseMmfRecoveryPhase(
const std::vector<MmfRecoveryCandidate>& candidates,
439 double pre_force,
double max_displacement,
440 double acceptance_force_threshold,
441 bool keep_force_improving_burst,
442 double reference_saddle_energy,
443 double reactant_energy,
double product_energy,
444 MmfRecoverySelectionStats* stats,
445 bool allow_directional_out_of_trust_recovery)
448 int best_acceptance_rank = std::numeric_limits<int>::max();
449 int best_certificate_rank = std::numeric_limits<int>::max();
450 double best_energy = std::numeric_limits<double>::infinity();
451 double best_force = std::numeric_limits<double>::infinity();
452 double best_curvature = std::numeric_limits<double>::infinity();
453 for (
const MmfRecoveryCandidate& candidate: candidates) {
454 if (!std::isfinite(candidate.curvature) ||
455 !(candidate.curvature < 0.0)) {
458 const MmfRecoveryAcceptanceDecision decision = classifyMmfRecovery(
459 pre_force, candidate.recovery_force, candidate.displacement,
460 max_displacement, acceptance_force_threshold,
461 keep_force_improving_burst, reference_saddle_energy,
462 candidate.saddle_energy, reactant_energy, product_energy,
463 candidate.saddle_certified, candidate.path_mode_certified,
464 candidate.measured_descent_certified);
466 ++stats->negative_curvature_candidates;
467 if (!decision.finite_input) {
468 ++stats->invalid_candidates;
470 if (decision.force_improves) {
471 ++stats->force_improving_candidates;
473 if (isLowerValidSaddleEnergy(reference_saddle_energy,
474 candidate.saddle_energy,
475 reactant_energy, product_energy)) {
476 if (candidate.saddle_certified) {
477 ++stats->certified_lower_energy_candidates;
479 ++stats->uncertified_lower_energy_candidates;
482 if (decision.uncertified_energy_descent) {
483 ++stats->uncertified_energy_descent_candidates;
485 if (decision.has_displacement_trust &&
486 !decision.within_displacement_trust) {
487 ++stats->out_of_trust_candidates;
490 const bool directional_out_of_trust =
491 allow_directional_out_of_trust_recovery && !decision.accepted &&
492 decision.force_improves && !decision.uncertified_energy_descent &&
493 decision.has_displacement_trust &&
494 !decision.within_displacement_trust;
495 if (stats && directional_out_of_trust) {
496 ++stats->directional_out_of_trust_candidates;
498 const int acceptance_rank =
499 decision.accepted ? 0 : (directional_out_of_trust ? 1 : -1);
501 if (decision.force_improves && !decision.accepted) {
502 if (decision.has_displacement_trust &&
503 decision.within_displacement_trust &&
504 decision.threshold_limited && !decision.threshold_passed) {
505 ++stats->threshold_rejected_candidates;
506 }
else if (!decision.has_displacement_trust) {
507 ++stats->no_trust_threshold_rejected_candidates;
511 if (acceptance_rank < 0) {
514 if (stats) ++stats->accepted_candidates;
515 const int certificate_rank = candidate.saddle_certified ? 0 : 1;
516 const bool candidate_has_energy =
517 std::isfinite(candidate.saddle_energy);
518 const bool best_has_energy = std::isfinite(best_energy);
519 bool prefer_candidate =
false;
520 if (acceptance_rank != best_acceptance_rank) {
521 prefer_candidate = acceptance_rank < best_acceptance_rank;
522 }
else if (certificate_rank != best_certificate_rank) {
523 prefer_candidate = certificate_rank < best_certificate_rank;
524 }
else if (candidate.saddle_certified) {
525 if (candidate_has_energy != best_has_energy) {
526 prefer_candidate = candidate_has_energy;
527 }
else if (candidate_has_energy &&
528 candidate.saddle_energy != best_energy) {
529 prefer_candidate = candidate.saddle_energy < best_energy;
530 }
else if (candidate.recovery_force != best_force) {
531 prefer_candidate = candidate.recovery_force < best_force;
533 prefer_candidate = candidate.curvature < best_curvature;
535 }
else if (candidate.recovery_force != best_force) {
536 prefer_candidate = candidate.recovery_force < best_force;
537 }
else if (candidate_has_energy != best_has_energy) {
538 prefer_candidate = candidate_has_energy;
539 }
else if (candidate_has_energy &&
540 candidate.saddle_energy != best_energy) {
541 prefer_candidate = candidate.saddle_energy < best_energy;
543 prefer_candidate = candidate.curvature < best_curvature;
549 if (prefer_candidate) {
550 best_acceptance_rank = acceptance_rank;
551 best_certificate_rank = certificate_rank;
552 best_phase = candidate.phase;
553 best_energy = candidate.saddle_energy;
554 best_force = candidate.recovery_force;
555 best_curvature = candidate.curvature;
561double successThresholdAfterMmf(
double handoff_force,
double mmf_force,
562 double baseline_threshold)
564 if (!std::isfinite(handoff_force) || handoff_force <= 0.0)
565 return baseline_threshold;
566 if (!std::isfinite(mmf_force) || mmf_force <= 0.0 ||
567 mmf_force >= handoff_force)
568 return baseline_threshold;
570 double threshold = handoff_force;
571 if (std::isfinite(baseline_threshold) && baseline_threshold > 0.0)
572 threshold = std::min(threshold, baseline_threshold);
576double rejectedMmfBackoffThreshold(
double current_force,
double force_tolerance,
577 double baseline_threshold)
579 if (!std::isfinite(current_force) || current_force <= 0.0)
580 return baseline_threshold;
581 if (!std::isfinite(force_tolerance) || force_tolerance <= 0.0 ||
582 current_force <= force_tolerance)
583 return baseline_threshold;
588 const double geo = std::sqrt(current_force * force_tolerance);
589 double threshold = std::max(geo, 0.5 * current_force);
590 if (std::isfinite(baseline_threshold) && baseline_threshold > 0.0)
591 threshold = std::min(threshold, baseline_threshold);
595MmfInformationGate advanceMmfInformationGateOnSurrogateChange(
596 MmfInformationGate gate,
const MmfSurrogateFingerprint& surrogate_now,
597 const MmfSurrogateFingerprint& surrogate_at_last_reject,
598 bool* refresh_snapshot)
600 if (refresh_snapshot) *refresh_snapshot =
false;
601 if (gate == MmfInformationGate::Open)
return gate;
602 if (gate == MmfInformationGate::AwaitingActionChange)
return gate;
603 if (!mmfSurrogateChanged(surrogate_now, surrogate_at_last_reject)) {
607 if (gate == MmfInformationGate::AwaitingFirstTrainingGrowth) {
608 return MmfInformationGate::Open;
613bool mmfSurrogateChanged(
614 const MmfSurrogateFingerprint& surrogate_now,
615 const MmfSurrogateFingerprint& surrogate_at_last_reject)
617 return surrogate_now != surrogate_at_last_reject;
620bool mmfPosteriorActionChanged(
621 const MmfPosteriorActionFingerprint& action_now,
622 const MmfPosteriorActionFingerprint& action_at_last_reject)
624 if (action_now.surrogate.owner != action_at_last_reject.surrogate.owner) {
627 const auto& current = action_now.action;
628 const auto& rejected = action_at_last_reject.action;
629 if (!current.valid || !rejected.valid)
return false;
630 const auto valid_geometry = [](
const gpr::Coord& positions) {
631 return positions.rows() == 1 && positions.cols() > 0 &&
632 positions.allFinite();
634 if ((current.trial_positions.size() > 0 &&
635 !valid_geometry(current.trial_positions)) ||
636 (rejected.trial_positions.size() > 0 &&
637 !valid_geometry(rejected.trial_positions)))
641 if (valid_geometry(current.trial_positions) &&
642 valid_geometry(rejected.trial_positions) &&
643 !positionsCoincide(current.trial_positions.row(0).transpose(),
644 rejected.trial_positions.row(0).transpose()))
647 if (current.termination != rejected.termination ||
648 current.proposal_action != rejected.proposal_action ||
649 current.residual_action != rejected.residual_action ||
650 current.force_norm != rejected.force_norm) {
654 if (std::isfinite(current.curvature) && std::isfinite(rejected.curvature) &&
655 std::signbit(current.curvature) != std::signbit(rejected.curvature)) {
658 if (current.termination ==
663 if (current.mode.size() == 0 ||
664 current.mode.size() != rejected.mode.size() ||
665 !current.mode.allFinite() || !rejected.mode.allFinite()) {
668 const double current_norm = current.mode.norm();
669 const double rejected_norm = rejected.mode.norm();
670 if (!(std::isfinite(current_norm) && current_norm > 0.0 &&
671 std::isfinite(rejected_norm) && rejected_norm > 0.0 &&
672 std::isfinite(current.rotation_tolerance) &&
673 current.rotation_tolerance > 0.0 &&
674 std::isfinite(rejected.rotation_tolerance) &&
675 rejected.rotation_tolerance > 0.0)) {
678 const double alignment =
680 (current_norm * rejected_norm)),
682 const double angle = std::acos(alignment);
683 const double rotation_tolerance =
684 std::min(current.rotation_tolerance, rejected.rotation_tolerance);
685 return angle > rotation_tolerance;
688bool shouldSuppressMmfUntilTrainingGrows(MmfInformationGate gate)
690 return gate != MmfInformationGate::Open;
693double mmfThresholdForce(
double neb_force,
double raw_force)
695 if (std::isfinite(neb_force) && neb_force > 0.0)
return neb_force;
696 if (std::isfinite(raw_force) && raw_force > 0.0)
return raw_force;
700bool ciPosteriorConfident(
const NEBPath& path,
int ci_idx,
double kappa)
710 if (ci_idx <= 0 || ci_idx >= path.numImages() - 1)
return false;
711 const auto posterior_risk = [&](
int idx) ->
double {
712 if (idx <= 0 || idx >= path.numImages() - 1) {
713 return std::numeric_limits<double>::infinity();
715 const auto& image_i = path.image(idx);
716 const double e_i = image_i.energy;
717 const double v_i = image_i.posterior_variance;
718 if (!std::isfinite(e_i) || !std::isfinite(v_i) || v_i < 0.0) {
719 return std::numeric_limits<double>::infinity();
722 for (
int j = 1; j < path.numImages() - 1; ++j) {
723 if (j == idx)
continue;
724 const auto& image_j = path.image(j);
726 e_i, v_i, image_j.energy, image_j.posterior_variance);
727 if (!std::isfinite(p))
return p;
732 const double ci_risk = posterior_risk(ci_idx);
733 if (!std::isfinite(ci_risk))
return false;
734 constexpr double binary_bayes_decision_boundary = 0.5;
735 if (!(ci_risk < binary_bayes_decision_boundary))
return false;
736 double best_risk = ci_risk;
737 for (
int i = 1; i < path.numImages() - 1; ++i) {
738 if (i == ci_idx)
continue;
739 best_risk = std::min(best_risk, posterior_risk(i));
742 std::nextafter(best_risk, std::numeric_limits<double>::infinity());
745bool isPrematureForceOnlyHelped(
bool is_helped_status,
bool force_certified,
746 bool helped_angle_certified,
747 int ci_stable_outer_count,
748 bool helped_negative_curvature)
750 if (!is_helped_status || !force_certified)
return false;
751 if (helped_angle_certified)
return false;
755 if (!helped_negative_curvature)
return true;
759 return ci_stable_outer_count < 1;
762bool forceOnlyHelpedPathCertified(
bool helped_angle_certified,
double alignment,
763 double alignment_cos_tol)
765 if (helped_angle_certified)
return true;
766 if (!std::isfinite(alignment) || !std::isfinite(alignment_cos_tol)) {
769 const double a = std::abs(alignment);
770 if (a > 1.0 || alignment_cos_tol < 0.0 || alignment_cos_tol > 1.0) {
777 return a >= alignment_cos_tol;
780bool shouldSearchMmfRecoveryPortfolio(
bool dimer_converged,
781 bool helped_ran_away,
782 bool helped_path_certified,
783 bool found_saddle_mode)
785 if (!found_saddle_mode)
return false;
786 if (!dimer_converged)
return true;
787 return !helped_ran_away && !helped_path_certified;
790bool mmfForceCertifiedForConvergence(
double dimer_force,
double band_force,
791 double force_tolerance)
793 if (!std::isfinite(force_tolerance) || force_tolerance <= 0.0) {
796 const double achieved_force =
797 (std::isfinite(dimer_force) && dimer_force > 0.0) ? dimer_force
799 return std::isfinite(achieved_force) && achieved_force < force_tolerance;
802bool mmfBurstConvergedAfterAcceptance(
MMFStatus status,
bool force_certified,
803 bool helped_angle_certified,
804 double final_mode_curvature,
805 bool helped_path_certified)
808 if (helped_angle_certified)
return true;
813 const bool negative_mode_curvature =
814 std::isfinite(final_mode_curvature) && final_mode_curvature < 0.0;
815 return force_certified && negative_mode_curvature;
818bool applyDimerSaddleSummary(GPNEBResult& result,
int dimer_saddle_image_idx)
820 if (!result.path)
return false;
821 if (dimer_saddle_image_idx <= 0 ||
822 dimer_saddle_image_idx >= result.path->numImages() - 1) {
825 const auto& saddle = result.path->image(dimer_saddle_image_idx);
826 const auto& reactant = result.path->image(0);
827 const auto& product = result.path->image(result.path->numImages() - 1);
828 if (!saddle.evaluated || !std::isfinite(saddle.energy) ||
829 !std::isfinite(reactant.energy) || !std::isfinite(product.energy)) {
835 if (!std::isfinite(result.ci_barrier_energy)) {
836 result.ci_barrier_energy = result.barrier_energy;
837 result.ci_reverse_barrier_energy = result.reverse_barrier_energy;
839 result.max_energy_image = dimer_saddle_image_idx;
840 result.barrier_energy = saddle.energy - reactant.energy;
841 result.reverse_barrier_energy = saddle.energy - product.energy;
845bool shouldPureLockAfterMmfReject(
MMFStatus status,
bool force_improved,
846 bool adaptive_threshold_seeded,
849 return shouldPureLockAfterMmfReject(
status, force_improved,
851 adaptive_threshold_seeded, reject_kind);
854bool shouldPureLockAfterMmfReject(
MMFStatus status,
bool force_improved,
855 bool trusted_recovery_advanced,
856 bool adaptive_threshold_seeded,
859 if (!adaptive_threshold_seeded)
return false;
861 if (trusted_recovery_advanced)
return false;
873 return !force_improved;
876bool isRecoveryPortfolioExhaustedReject(
bool recovery_selection_exhausted,
877 int accepted_candidates)
879 return recovery_selection_exhausted && accepted_candidates == 0;
882bool isMmfRecoveryPortfolioExhausted(
bool found_saddle_mode,
int selected_phase,
883 int accepted_candidates)
885 return !found_saddle_mode ||
886 (selected_phase < 0 && accepted_candidates == 0);
889bool shouldAcquireMmfMinModeProbe(
bool found_saddle_mode,
int selected_phase,
890 int accepted_candidates,
891 int negative_curvature_candidates,
892 int force_improving_candidates,
893 int out_of_trust_candidates)
895 if (out_of_trust_candidates > 0 && force_improving_candidates == 0) {
898 return found_saddle_mode && selected_phase < 0 &&
899 accepted_candidates == 0 && negative_curvature_candidates > 0 &&
900 force_improving_candidates == 0;
903bool shouldHoldMmfForExpectedImprovement(
bool wait_for_true_sample,
905 Eigen::Index ntrain_at_hold)
907 return wait_for_true_sample && ntrain <= ntrain_at_hold;
910double mmfMinModeProbeStep(
double recovery_disp_cap,
double seed_kick,
911 double max_burst_displacement)
913 double step = std::numeric_limits<double>::quiet_NaN();
914 if (std::isfinite(recovery_disp_cap) && recovery_disp_cap > 0.0) {
915 step = 0.5 * recovery_disp_cap;
917 if (std::isfinite(seed_kick) && seed_kick > 0.0) {
918 const double floor = 2.0 * seed_kick;
919 step = std::isfinite(step) ? std::max(step, floor) : floor;
921 if (std::isfinite(max_burst_displacement) && max_burst_displacement > 0.0) {
922 step = std::isfinite(step) ? std::min(step, max_burst_displacement)
923 : max_burst_displacement;
925 return (std::isfinite(step) && step > 0.0) ? step : 0.1;
928Eigen::VectorXd minModeProbePosition(
const Eigen::VectorXd& seed,
929 const Eigen::VectorXd& mode,
double step)
931 if (seed.size() == 0 || mode.size() != seed.size() || !seed.allFinite() ||
932 !mode.allFinite() || !std::isfinite(step) || !(step > 0.0)) {
935 const double norm = mode.norm();
936 if (!(norm > 0.0) || !std::isfinite(norm)) {
939 return seed + (step / norm) * mode;
942bool isTruePesRecoverySaddleEnergyCertified(
double true_energy,
943 double reactant_energy,
944 double product_energy)
946 return isTruePesSaddleEnergyCandidate(true_energy, reactant_energy,
950bool isTruePesRecoverySaddleCertified(
double true_energy,
double recovery_force,
951 double force_tolerance,
952 double reactant_energy,
953 double product_energy)
955 return std::isfinite(recovery_force) && recovery_force >= 0.0 &&
956 std::isfinite(force_tolerance) && force_tolerance > 0.0 &&
957 recovery_force < force_tolerance &&
958 isTruePesRecoverySaddleEnergyCertified(true_energy, reactant_energy,
962bool isMmfAdaptiveThresholdSeeded(
double current_threshold)
964 return std::isfinite(current_threshold) && current_threshold > 0.0;
967bool shouldLeaseAfterPureRejectProgress(
bool pure_reject_lock,
968 bool improved_under_backoff,
969 bool improved_since_pure_reject)
975 return pure_reject_lock &&
976 (improved_under_backoff || improved_since_pure_reject);
979bool shouldLeaseAfterExhaustedQuietStall(
980 bool pure_reject_lock,
bool exhausted_recovery_reject_applies,
981 bool oie_quiet_handoff_stalled,
bool oie_acquisition_quiet,
982 bool current_chain_certificate,
bool current_saddle_stencil_certificate,
983 bool ci_posterior_confident,
bool ci_is_energy_maximum)
991 (void)pure_reject_lock;
992 return exhausted_recovery_reject_applies && oie_quiet_handoff_stalled &&
993 oie_acquisition_quiet && current_chain_certificate &&
994 current_saddle_stencil_certificate && ci_posterior_confident &&
995 ci_is_energy_maximum;
998bool shouldBlockRejectedSeedReplay(
bool rejected_seed_replay,
1000 bool improved_since_pure_reject,
1001 bool exhausted_quiet_stall_lease)
1003 return rejected_seed_replay && !trap_detected &&
1004 !improved_since_pure_reject && !exhausted_quiet_stall_lease;
1007bool shouldSkipMmfAfterSpentMinModeProbe(
bool min_mode_probe_spent,
1008 bool rejected_seed_replay,
1009 bool rejected_seed_position_matches)
1011 return min_mode_probe_spent &&
1012 (rejected_seed_replay || rejected_seed_position_matches);
1015PureLockHopState pureLockStateAfterCiHop(PureLockHopState state)
1017 if (!state.force_improving_recovery_active) {
1023 state.pure_reject_lock =
false;
1024 state.pure_reject_force = std::numeric_limits<double>::quiet_NaN();
1025 state.force_improving_recovery_active =
false;
1029double resolveMmfSeedDisplacement(
double configured_displacement,
1030 bool force_improving_recovery_active,
1031 bool trusted_recovery_active)
1033 if (!std::isfinite(configured_displacement) ||
1034 force_improving_recovery_active || trusted_recovery_active) {
1037 return configured_displacement;
1040bool shouldImmediateRereleaseAfterFi(
bool force_improving_recovery_active,
1042 double current_threshold,
1043 double force_tolerance)
1045 if (!force_improving_recovery_active)
return false;
1046 if (!isMmfAdaptiveThresholdSeeded(current_threshold))
return false;
1047 if (!std::isfinite(post_force) || !(post_force > 0.0))
return false;
1048 if (!std::isfinite(force_tolerance) || !(force_tolerance > 0.0)) {
1052 return post_force > force_tolerance && post_force <= current_threshold;
1055bool shouldImmediateRereleaseAfterOciRecovery(
1056 bool force_improving_recovery_active,
bool trusted_recovery_active,
1057 double post_force,
double current_threshold,
double force_tolerance,
1058 bool current_saddle_stencil_certificate)
1064 if (force_improving_recovery_active && trusted_recovery_active &&
1065 current_saddle_stencil_certificate && std::isfinite(post_force) &&
1066 std::isfinite(force_tolerance) && force_tolerance > 0.0) {
1067 return post_force > force_tolerance;
1069 if (!shouldImmediateRereleaseAfterFi(force_improving_recovery_active,
1070 post_force, current_threshold,
1074 if (!trusted_recovery_active)
return true;
1075 return current_saddle_stencil_certificate ||
1076 isConvergenceScaleForce(post_force, force_tolerance);
1079bool shouldImmediateRereleaseAfterOciRecovery(
1080 const MMFRunResult& burst,
double current_threshold,
double force_tolerance,
1081 bool current_saddle_stencil_certificate)
1083 if (burst.requires_outer_path_refresh)
return false;
1087 return shouldImmediateRereleaseAfterOciRecovery(
1088 burst.force_improving_recovery_advanced,
1089 burst.trusted_recovery_advanced, burst.newForce, current_threshold,
1091 current_saddle_stencil_certificate || burst.recovery_saddle_certified);
1094bool mmfAttemptConsumedAfterRecovery(
bool mmf_attempted,
1095 bool trusted_recovery_advanced,
1096 bool requires_outer_path_refresh)
1098 return mmf_attempted &&
1099 !(trusted_recovery_advanced && requires_outer_path_refresh);
1102bool shouldPreserveFiRecoveryGateAfterRetry(
1103 bool force_improving_recovery_active,
double pre_force,
1104 double current_threshold,
double force_tolerance,
1105 bool recovery_selection_exhausted)
1107 if (!force_improving_recovery_active)
return false;
1110 if (recovery_selection_exhausted)
return false;
1111 if (!isMmfAdaptiveThresholdSeeded(current_threshold))
return false;
1112 if (!std::isfinite(pre_force) || !(pre_force > 0.0))
return false;
1113 if (!std::isfinite(force_tolerance) || !(force_tolerance > 0.0)) {
1116 return pre_force > force_tolerance && pre_force <= current_threshold;
1119bool shouldPreserveTrustedRecoveryGateAfterRetry(
1121 bool trusted_recovery_advanced,
bool rejected_helped_handback,
1122 MMFRejectKind reject_kind,
bool recovery_selection_exhausted)
1124 if (!trusted_recovery_active)
return false;
1126 if (recovery_selection_exhausted)
return false;
1127 if (rejected_helped_handback &&
1131 if (force_improved || trusted_recovery_advanced)
return false;
1135bool shouldRecordRejectedSeedForRecoveryGate(
1136 bool preserve_fi_recovery_gate,
bool preserve_trusted_recovery_gate)
1138 return preserve_trusted_recovery_gate && !preserve_fi_recovery_gate;
1141double trustedRetryRejectForceAfterRetry(
1142 bool preserve_trusted_recovery_gate,
1143 double existing_trusted_retry_reject_force,
double retry_reject_force)
1145 if (!preserve_trusted_recovery_gate) {
1146 return std::numeric_limits<double>::quiet_NaN();
1148 if (std::isfinite(existing_trusted_retry_reject_force) &&
1149 existing_trusted_retry_reject_force > 0.0) {
1150 return existing_trusted_retry_reject_force;
1152 return retry_reject_force;
1155bool shouldHarvestAcceptedRecoveryObservation(
bool trusted_recovery_advanced)
1157 return trusted_recovery_advanced;
1160bool shouldKeepTrustedRecoveryGateAfterAdvance(
bool trusted_recovery_advanced,
1161 bool force_improved)
1163 return trusted_recovery_advanced && force_improved;
1166bool shouldPromoteCurrentCiHandoffMismatchToTrap(
int handoff_outer_iter,
1167 int hook_outer_iter,
1169 double oracle_force,
1170 double handoff_threshold)
1172 if (handoff_outer_iter < 0 || hook_outer_iter < 0)
return false;
1173 if (!(handoff_outer_iter < hook_outer_iter))
return false;
1174 return shouldFlagMmfHandoffTrap(gp_force, oracle_force, handoff_threshold);
1177bool shouldRefreshCurrentCiHandoffPrediction(
bool pending_request,
1179 bool current_request,
1180 int current_ci)
noexcept
1182 return !current_request || !pending_request || pending_ci != current_ci;
1185bool isBandInformationExhaustedForMmf(
double max_chain_energy_variance,
1186 double likelihood_noise_variance,
1187 double posterior_variance_threshold,
1188 double inner_unc_relative)
1190 (void)posterior_variance_threshold;
1191 (void)inner_unc_relative;
1192 if (!std::isfinite(max_chain_energy_variance) ||
1193 max_chain_energy_variance < 0.0) {
1197 return std::isfinite(likelihood_noise_variance) &&
1198 likelihood_noise_variance > 0.0 &&
1199 max_chain_energy_variance <= likelihood_noise_variance;
1202bool isOieAcquisitionQuietForMmf(
double max_chain_energy_variance,
1203 double posterior_variance_threshold)
1205 if (!std::isfinite(max_chain_energy_variance) ||
1206 max_chain_energy_variance < 0.0) {
1209 return std::isfinite(posterior_variance_threshold) &&
1210 posterior_variance_threshold > 0.0 &&
1211 max_chain_energy_variance <= posterior_variance_threshold;
1214bool hasCurrentOciSaddleStencilCertificate(
const ActiveLearningSession& session,
1215 const NEBPath& path,
int ci_idx)
1217 return ci_idx > 0 && ci_idx < path.numImages() - 1 &&
1218 selectOciHandoffCertificateOracleTargets(ci_idx, path, session)
1222bool isOracleTransitionFocalHandoff(
int configured_focal_image,
1224 bool current_chain_certificate,
1225 bool current_saddle_stencil_certificate)
1227 return configured_focal_image > 0 &&
1228 configured_focal_image == ci_image_idx &&
1229 current_chain_certificate && current_saddle_stencil_certificate;
1232bool isOciMmfHandoffDataReady(
bool band_acquisition_quiet,
1233 bool current_saddle_stencil_certificate,
1234 bool ci_posterior_confident,
1235 bool ci_is_energy_maximum)
1244 return (band_acquisition_quiet && current_saddle_stencil_certificate) ||
1245 (ci_posterior_confident && ci_is_energy_maximum);
1248bool isForceImprovingRecoveryStalledHandoff(
1249 bool force_improving_recovery_active,
bool ci_posterior_confident,
1250 bool current_chain_certificate,
bool oie_acquisition_quiet,
1251 bool oie_quiet_handoff_stalled)
1253 (void)ci_posterior_confident;
1254 return force_improving_recovery_active && current_chain_certificate &&
1255 oie_acquisition_quiet && oie_quiet_handoff_stalled;
1258bool isTrustedRecoveryStalledHandoff(
bool trusted_recovery_active,
1259 bool ci_posterior_confident,
1260 bool current_chain_certificate,
1261 bool ci_is_energy_maximum,
1262 bool oie_acquisition_quiet,
1263 bool oie_quiet_handoff_stalled)
1265 (void)ci_posterior_confident;
1266 return trusted_recovery_active && current_chain_certificate &&
1267 ci_is_energy_maximum && oie_acquisition_quiet &&
1268 oie_quiet_handoff_stalled;
1271bool shouldUseTrustedRecoveryStalledHandoff(
1272 bool trusted_retry_progress_pending,
bool trusted_recovery_stalled_handoff)
1274 (void)trusted_retry_progress_pending;
1275 return trusted_recovery_stalled_handoff;
1278bool isTrustedRecoveryProgressHandoff(
1279 bool trusted_recovery_active,
double trusted_retry_reject_force,
1280 double conv_force,
double current_threshold,
bool ci_posterior_confident,
1281 bool ci_is_energy_maximum,
bool rejected_seed_replay,
1282 bool current_chain_certificate,
bool oie_quiet_handoff_stalled,
1283 bool oie_acquisition_quiet)
1285 (void)current_threshold;
1286 (void)ci_posterior_confident;
1287 (void)oie_quiet_handoff_stalled;
1288 return trusted_recovery_active && ci_is_energy_maximum &&
1289 !rejected_seed_replay && current_chain_certificate &&
1290 oie_acquisition_quiet && std::isfinite(trusted_retry_reject_force) &&
1291 trusted_retry_reject_force > 0.0 && std::isfinite(conv_force) &&
1292 conv_force > 0.0 && conv_force < trusted_retry_reject_force;
1295bool isCurrentChainCertifiedHandoff(
bool trusted_retry_progress_pending,
1296 bool current_chain_certificate,
1297 bool rejected_seed_replay,
1298 bool ci_posterior_confident,
1299 bool ci_is_energy_maximum,
1300 bool oie_acquisition_quiet,
1301 bool exhausted_recovery_reject_active)
1303 if (exhausted_recovery_reject_active)
return false;
1304 return !trusted_retry_progress_pending && current_chain_certificate &&
1305 !rejected_seed_replay && ci_posterior_confident &&
1306 ci_is_energy_maximum && oie_acquisition_quiet;
1309bool exhaustedRecoveryRejectAppliesToCi(
bool exhausted_recovery_reject_active,
1310 long reject_climbing_image,
1311 long climbing_image)
1313 if (!exhausted_recovery_reject_active)
return false;
1314 return reject_climbing_image < 0 || climbing_image < 0 ||
1315 reject_climbing_image == climbing_image;
1318bool shouldRequestCurrentCiOracleForExhaustedRecovery(
1319 bool exhausted_recovery_reject_active,
long reject_climbing_image,
1320 long climbing_image)
1322 return exhaustedRecoveryRejectAppliesToCi(exhausted_recovery_reject_active,
1323 reject_climbing_image,
1327bool isRefreshedExhaustedRecoveryHandoff(
1328 bool exhausted_recovery_reject_applies,
bool current_chain_certificate,
1329 bool current_saddle_stencil_certificate,
bool rejected_seed_replay,
1330 bool rejected_seed_position_matches,
bool ci_posterior_confident,
1331 bool ci_is_energy_maximum)
1333 return exhausted_recovery_reject_applies && current_chain_certificate &&
1334 current_saddle_stencil_certificate && !rejected_seed_replay &&
1335 !rejected_seed_position_matches && ci_posterior_confident &&
1336 ci_is_energy_maximum;
1339bool activeMmfRecoveryOwnsClimbingImage(
bool force_improving_recovery_active,
1340 bool trusted_recovery_active)
1342 return force_improving_recovery_active || trusted_recovery_active;
1345int activeOieRecoveryOwnerImage(
int recorded_owner_image,
int current_ci_image,
1346 bool force_improving_recovery_active,
1347 bool trusted_recovery_active)
1349 if (!activeMmfRecoveryOwnsClimbingImage(force_improving_recovery_active,
1350 trusted_recovery_active)) {
1353 if (recorded_owner_image > 0)
return recorded_owner_image;
1354 return current_ci_image > 0 ? current_ci_image : -1;
1357bool shouldHoldOieFixedImage(
bool force_improving_recovery_active,
1358 bool trusted_recovery_active)
1360 return shouldHoldOieFixedImage(force_improving_recovery_active,
1361 trusted_recovery_active,
1365bool shouldHoldOieFixedImage(
bool force_improving_recovery_active,
1366 bool trusted_recovery_active,
1367 bool rejected_recovery_seed)
1369 return force_improving_recovery_active ||
1370 (trusted_recovery_active && !rejected_recovery_seed);
1373bool shouldRequestOieRecoveryModelGrowth(
bool force_improving_recovery_active,
1374 bool trusted_recovery_active,
1375 bool rejected_recovery_seed,
1376 MmfInformationGate info_gate)
1378 const bool action_uncertifiable =
1379 info_gate == MmfInformationGate::AwaitingFirstTrainingGrowth;
1380 return shouldHoldOieFixedImage(force_improving_recovery_active,
1381 trusted_recovery_active,
1382 rejected_recovery_seed) &&
1383 action_uncertifiable;
1386bool shouldSuppressMmfRecoveryRetry(
bool force_improving_recovery_active,
1387 bool trusted_recovery_active,
1388 MmfInformationGate info_gate)
1390 return activeMmfRecoveryOwnsClimbingImage(force_improving_recovery_active,
1391 trusted_recovery_active) &&
1392 shouldSuppressMmfUntilTrainingGrows(info_gate);
1395bool shouldReleaseOieRecoveryForCertifiedHandover(
1396 bool active_recovery,
int recovery_owner_image,
int candidate_image,
1397 bool candidate_posterior_confident,
bool candidate_chain_certificate,
1398 bool candidate_saddle_stencil_certificate)
1400 return active_recovery && recovery_owner_image > 0 && candidate_image > 0 &&
1401 candidate_image != recovery_owner_image &&
1402 candidate_posterior_confident && candidate_chain_certificate &&
1403 candidate_saddle_stencil_certificate;
1406bool shouldReleaseOieExhaustedRecoveryForCertifiedHandover(
1407 bool exhausted_recovery_reject_active,
int rejected_image,
1408 int candidate_image,
bool candidate_posterior_confident,
1409 bool candidate_chain_certificate,
bool candidate_saddle_stencil_certificate)
1411 return exhausted_recovery_reject_active && rejected_image > 0 &&
1412 candidate_image > 0 && candidate_image != rejected_image &&
1413 candidate_posterior_confident && candidate_chain_certificate &&
1414 candidate_saddle_stencil_certificate;
1417bool shouldReleaseOieRecoveryForInvalidatedOwner(
1418 bool active_recovery,
int recovery_owner_image,
int retry_image,
1419 bool recovery_model_growth_ready,
bool band_force_converged,
1420 bool owner_chain_certificate,
bool owner_saddle_stencil_certificate,
1421 bool owner_posterior_confident,
bool owner_is_energy_maximum)
1423 const bool owner_identity_matches =
1424 recovery_owner_image > 0 && recovery_owner_image == retry_image;
1425 const bool owner_certificate =
1426 owner_chain_certificate && owner_saddle_stencil_certificate &&
1427 owner_posterior_confident && owner_is_energy_maximum;
1428 return active_recovery && owner_identity_matches &&
1429 recovery_model_growth_ready && band_force_converged &&
1433bool shouldAdvanceOieRecoveryInformationGate(
bool active_recovery,
1434 int recovery_owner_image,
1437 return !active_recovery ||
1438 (recovery_owner_image > 0 && recovery_owner_image == retry_image);
1441OieFixedImageLease makeOieRecoveryFixedImageLease(
1442 int ci_image_idx,
bool force_improving_recovery_active,
1443 bool trusted_recovery_active,
bool rejected_recovery_seed,
1444 MmfInformationGate info_gate,
bool recovery_retry_blocked)
1446 if (ci_image_idx <= 0 ||
1447 !shouldHoldOieFixedImage(force_improving_recovery_active,
1448 trusted_recovery_active,
1449 rejected_recovery_seed)) {
1452 const bool model_growth_required = shouldRequestOieRecoveryModelGrowth(
1453 force_improving_recovery_active, trusted_recovery_active,
1454 rejected_recovery_seed, info_gate);
1455 const bool allow_replaceable_acquisition =
1456 !model_growth_required &&
1457 (info_gate == MmfInformationGate::AwaitingActionChange ||
1458 recovery_retry_blocked);
1459 return {ci_image_idx, model_growth_required, model_growth_required,
1460 allow_replaceable_acquisition};
1463OieFixedImageLease makeOieExhaustedRecoveryFixedImageLease(
1464 int ci_image_idx,
bool exhausted_recovery_reject_active,
1465 long reject_climbing_image)
1467 if (ci_image_idx <= 0 || !exhaustedRecoveryRejectAppliesToCi(
1468 exhausted_recovery_reject_active,
1469 reject_climbing_image, ci_image_idx)) {
1472 return {ci_image_idx,
1478OieFixedImageLease makeOieExhaustedRecoveryEvidenceLease(
1479 int ci_image_idx,
bool exhausted_recovery_reject_active,
1480 long reject_climbing_image,
int candidate_image)
1482 OieFixedImageLease lease = makeOieExhaustedRecoveryFixedImageLease(
1483 ci_image_idx, exhausted_recovery_reject_active, reject_climbing_image);
1484 if (lease.image_index > 0 && candidate_image == lease.image_index) {
1485 lease.model_growth_required =
true;
1486 lease.allow_replaceable_acquisition =
false;
1491bool isOieRecoveryOwnerModelGrowthReady(
1492 bool model_growth_requested,
const MmfSurrogateFingerprint& surrogate_now,
1493 const MmfSurrogateFingerprint& surrogate_at_request)
1495 return model_growth_requested &&
1496 mmfSurrogateChanged(surrogate_now, surrogate_at_request);
1499bool isOieRecoveryModelGrowthCertified(
int recovery_owner_image,
1501 bool recovery_model_growth_ready,
1502 bool current_chain_certificate,
1503 bool current_saddle_stencil_certificate,
1504 bool recovery_owner_is_energy_maximum)
1506 return recovery_owner_image > 0 && recovery_owner_image == retry_image &&
1507 recovery_model_growth_ready && current_chain_certificate &&
1508 current_saddle_stencil_certificate &&
1509 recovery_owner_is_energy_maximum;
1512bool isOieExhaustedRecoveryModelGrowthCertified(
1513 int recovery_owner_image,
int retry_image,
bool recovery_model_growth_ready,
1514 bool current_chain_certificate,
bool current_saddle_stencil_certificate,
1515 bool recovery_owner_is_energy_maximum,
bool rejected_seed_replay)
1517 return !rejected_seed_replay &&
1518 isOieRecoveryModelGrowthCertified(
1519 recovery_owner_image, retry_image, recovery_model_growth_ready,
1520 current_chain_certificate, current_saddle_stencil_certificate,
1521 recovery_owner_is_energy_maximum);
1524bool shouldUseSurfaceUpdatedTrapRetryForCurrentCiOracle(
1525 bool trap_surface_updated,
bool trusted_recovery_active,
1526 double trusted_retry_reject_force,
double conv_force,
1527 double current_threshold)
1529 if (!trap_surface_updated)
return false;
1530 if (!trusted_recovery_active)
return true;
1531 const bool trusted_retry_progress_pending =
1532 std::isfinite(trusted_retry_reject_force) &&
1533 trusted_retry_reject_force > 0.0;
1534 if (!trusted_retry_progress_pending)
return false;
1535 return std::isfinite(conv_force) && conv_force > 0.0 &&
1536 std::isfinite(current_threshold) && current_threshold > 0.0 &&
1537 conv_force <= current_threshold;
1540bool shouldRetireTrustedRetryAfterProgress(
bool trusted_recovery_active,
1541 double trusted_retry_reject_force,
1543 double current_threshold)
1545 return trusted_recovery_active &&
1546 std::isfinite(trusted_retry_reject_force) &&
1547 trusted_retry_reject_force > 0.0 && std::isfinite(conv_force) &&
1548 conv_force > 0.0 && conv_force < trusted_retry_reject_force &&
1549 std::isfinite(current_threshold) && current_threshold > 0.0 &&
1550 conv_force <= current_threshold;
1553bool shouldTriggerMmf(
const OCINEBConfig& cfg,
double convForce,
bool ci_active,
1554 long climbingImage,
long numImages,
1555 bool ci_posterior_confident,
double current_threshold,
1556 bool trap_detected,
bool trap_backoff_active,
1557 bool trap_surface_updated, MmfInformationGate info_gate,
1558 bool ci_is_energy_maximum,
1559 bool band_information_exhausted,
1560 bool oie_acquisition_quiet,
bool oie_acquisition_stalled,
1561 bool certified_recovery_stalled_handoff,
1562 bool certified_handoff)
1564 if (!cfg.use_mmf || !ci_active)
return false;
1565 if (climbingImage <= 0 || climbingImage > numImages)
return false;
1566 if (!std::isfinite(convForce))
return false;
1573 const double force_tolerance = mmfLeaseForceTolerance(cfg);
1574 if (!(std::isfinite(force_tolerance) && force_tolerance > 0.0 &&
1575 convForce > force_tolerance)) {
1581 if (trap_detected && (!trap_backoff_active || trap_surface_updated)) {
1587 if (certified_handoff)
return true;
1590 if (shouldSuppressMmfUntilTrainingGrows(info_gate)) {
1595 if (band_information_exhausted)
return true;
1596 if (certified_recovery_stalled_handoff)
return true;
1599 if (!(std::isfinite(current_threshold) && current_threshold > 0.0)) {
1602 if (convForce > current_threshold) {
1607 if (ci_posterior_confident)
return true;
1610 (void)ci_is_energy_maximum;
1611 (void)trap_backoff_active;
1612 (void)oie_acquisition_quiet;
1613 (void)oie_acquisition_stalled;
1617double resolveDimerVarianceTauRelative(
const GPNEBConfig& neb_config,
1618 const OCINEBConfig& oci_config)
1621 if (std::isfinite(oci_config.dimer_variance_tau_rel)) {
1622 return std::max(0.0, oci_config.dimer_variance_tau_rel);
1627bool shouldInstallOciMmfHook(
const GPNEBConfig& neb_config,
1628 const OCINEBConfig& oci_config)
1637 if (!oci_config.use_mmf)
return false;
1651bool shouldUseHssvdAnalyticDimerCurvature(
const GPNEBConfig& neb_config)
1653 return shouldUseHssvdAnalyticDimerCurvature(neb_config,
true);
1656bool shouldUseHssvdAnalyticDimerCurvature(
const GPNEBConfig& neb_config,
1657 bool has_spectral_posterior)
1659 return neb_config.dimer_analytic_curvature.value_or(
1660 has_spectral_posterior && (neb_config.use_hssvd_solver ||
1661 neb_config.hyperparameter_objective ==
1665double resolveOciForceTolerance(
const OCINEBConfig& oci_config)
1667 const bool has_base = std::isfinite(oci_config.force_tolerance) &&
1668 oci_config.force_tolerance > 0.0;
1669 double tol = oci_config.force_tolerance;
1670 if (oci_config.effective_force_tolerance) {
1671 const double live_tol = oci_config.effective_force_tolerance();
1672 if (std::isfinite(live_tol) && live_tol > 0.0 &&
1673 (!has_base || live_tol > tol)) {
1680double mmfLeaseForceTolerance(
const OCINEBConfig& oci_config)
1684 if (std::isfinite(oci_config.force_tolerance) &&
1685 oci_config.force_tolerance > 0.0) {
1686 return oci_config.force_tolerance;
1688 return resolveOciForceTolerance(oci_config);
1691class ScopedImageState {
1693 ScopedImageState(NEBPath& path,
int image_idx)
1695 image_idx_(image_idx),
1696 positions_(path.image(image_idx).positions),
1697 energy_(path.image(image_idx).energy),
1698 gradient_(path.image(image_idx).gradient),
1699 evaluated_(path.image(image_idx).evaluated)
1703 ScopedImageState(
const ScopedImageState&) =
delete;
1704 ScopedImageState& operator=(
const ScopedImageState&) =
delete;
1705 ScopedImageState(ScopedImageState&&) =
delete;
1706 ScopedImageState& operator=(ScopedImageState&&) =
delete;
1710 path_.image(image_idx_).positions = positions_;
1711 path_.image(image_idx_).energy = energy_;
1712 path_.image(image_idx_).gradient = gradient_;
1713 path_.image(image_idx_).evaluated = evaluated_;
1714 path_.computeNEBForces();
1720 Eigen::VectorXd positions_;
1722 Eigen::VectorXd gradient_;
1731gpr::Coord flatToCoord1xD(
const Eigen::VectorXd& v)
1734 for (Eigen::Index j = 0; j < v.size(); ++j)
1739Eigen::VectorXd coordToFlat(
const gpr::Coord& c)
1741 Eigen::VectorXd v(c.cols());
1742 for (Eigen::Index j = 0; j < c.cols(); ++j)
1747struct OciMmfHandoffTrapState {
1748 int outer_iter = -1;
1749 int ci_image_idx = -1;
1750 double gp_force = std::numeric_limits<double>::infinity();
1751 double threshold = std::numeric_limits<double>::quiet_NaN();
1752 bool requested_current_ci =
false;
1759double emdDistance(
const Eigen::VectorXd& a,
const Eigen::VectorXd& b,
1760 const gpr::AtomsConfiguration& atoms_config)
1762 if (a.size() != b.size() || a.size() == 0) {
1763 return std::numeric_limits<double>::infinity();
1768 aux::Distance distance;
1769 distance.
dist_emd(ca, cb, atoms_config, dist);
1770 if (dist.size() == 0)
return std::numeric_limits<double>::infinity();
1781gpr::InputParameters buildDimerParameters(
const GPNEBConfig& neb_config,
1782 const OCINEBConfig& oci_config,
1783 gpr::AtomsConfiguration& tmp,
1784 bool use_analytic_hssvd)
1786 gpr::InputParameters parameters;
1787 if (neb_config.gp_setup) {
1788 neb_config.gp_setup(parameters, tmp);
1796 gpr::CanonicalDimerDefaultOptions dd;
1820 gpr::InputParameters canonical;
1821 gpr::CanonicalDimerDefaultOptions dd;
1855 parameters.
T_dimer.
value = resolveOciForceTolerance(oci_config);
1856 if (neb_config.n_atoms > 0) {
1862 parameters.
num_iter.
value = oci_config.dimer_max_inner_iter;
1864 if (use_analytic_hssvd) {
1877gpr::InputParameters buildDimerParameters(
const GPNEBConfig& neb_config,
1878 const OCINEBConfig& oci_config,
1879 gpr::AtomsConfiguration& tmp)
1881 return buildDimerParameters(
1882 neb_config, oci_config, tmp,
1883 shouldUseHssvdAnalyticDimerCurvature(neb_config));
1886MmfPosteriorActionFingerprint probeMmfPosteriorAction(
1887 ActiveLearningSession& session,
int image_idx,
bool dimer_use_global_gp,
1888 const Eigen::VectorXd& seed,
const Eigen::VectorXd& seed_gradient,
1889 const Eigen::VectorXd& initial_mode,
const GPNEBConfig& neb_config,
1890 const OCINEBConfig& oci_config)
1892 MmfPosteriorActionFingerprint result;
1893 const int owner = session.mmfModelOwner(image_idx, dimer_use_global_gp);
1894 result.surrogate = session.surrogateFingerprint(owner);
1895 if (seed.size() == 0 || seed.size() != seed_gradient.size() ||
1896 seed.size() != initial_mode.size() || !seed.allFinite() ||
1897 !seed_gradient.allFinite() || !initial_mode.allFinite() ||
1898 !(initial_mode.norm() > 0.0)) {
1902 ActiveLearningSession::ModelLease model =
1903 owner >= 0 ? session.acquireImageModel(owner)
1904 : session.acquireGlobalModel();
1905 gpr::Observation middle_point;
1906 middle_point.
R = flatToCoord1xD(seed);
1907 middle_point.
G = flatToCoord1xD(seed_gradient);
1908 gpr::Coord orientation = flatToCoord1xD(initial_mode.normalized());
1910 gpr::AtomsConfiguration parameter_atoms;
1911 const bool use_analytic_hssvd = shouldUseHssvdAnalyticDimerCurvature(
1912 neb_config, model.gp().hasReusableHssvdPosterior());
1913 gpr::InputParameters parameters = buildDimerParameters(
1914 neb_config, oci_config, parameter_atoms, use_analytic_hssvd);
1915 atmd::AtomicDimer dimer;
1916 if (neb_config.training_policy !=
nullptr)
1922 dimer.
initialize(parameters, model.observations(), middle_point,
1923 orientation, session.atoms_config);
1931 atmd::AtomicDimer::VarianceGateConfig variance_gate =
1933 variance_gate.
accept_tau = oci_config.dimer_variance_tau_abs;
1935 resolveDimerVarianceTauRelative(neb_config, oci_config);
1938 std::max(1, oci_config.dimer_imspe_history_size);
1943 result.surrogate = session.surrogateFingerprint(owner);
1955 MPI_Initialized(&mpi_up);
1958 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
1965const char* mmfInformationGateName(detail::MmfInformationGate gate)
1968 case detail::MmfInformationGate::Open:
1970 case detail::MmfInformationGate::AwaitingFirstTrainingGrowth:
1971 return "awaiting_first_growth";
1972 case detail::MmfInformationGate::AwaitingActionChange:
1973 return "awaiting_action_change";
1978const char* mmfSurrogateOwnerName(
1979 const detail::MmfSurrogateFingerprint& surrogate)
1981 return surrogate.owner >= 0 ?
"image" :
"global";
1988bool shouldRetainMmfObservation(
const Eigen::VectorXd& positions,
1989 const Eigen::VectorXd& anchor,
1990 const gpr::AtomsConfiguration& atoms_config,
1991 double max_displacement)
1993 if (positions.size() != anchor.size() || positions.size() == 0) {
1996 if (!(max_displacement > 0.0))
return true;
1997 const double displacement = emdDistance(positions, anchor, atoms_config);
1998 return std::isfinite(displacement) && displacement <= max_displacement;
2001bool shouldCommitMmfObservation(
const Eigen::VectorXd& positions,
2002 const Eigen::VectorXd& anchor,
2003 const gpr::AtomsConfiguration& atoms_config,
2004 double max_displacement)
2006 return shouldRetainMmfObservation(positions, anchor, atoms_config,
2010bool shouldHarvestRejectedMmfObservation(
2011 bool helped,
bool trusted_recovery_advanced,
2012 const Eigen::VectorXd& positions,
const Eigen::VectorXd& anchor,
2013 const gpr::AtomsConfiguration& atoms_config,
double max_displacement)
2015 return !helped && !trusted_recovery_advanced &&
2016 shouldCommitMmfObservation(positions, anchor, atoms_config,
2024double OCINEBController::forceTolerance()
const
2026 return detail::resolveOciForceTolerance(cfg_);
2029std::optional<Eigen::VectorXd> OCINEBController::initialModeForPath(
2030 const NEBPath& path,
int ci_image_idx)
const
2032 if (ci_image_idx <= 0 || ci_image_idx >= path.numImages() - 1) {
2033 return std::nullopt;
2035 Eigen::VectorXd mode;
2038 }
else if (has_cached_mode_ && cached_mode_.size() > 0) {
2039 mode = cached_mode_;
2041 mode = path.tangentAt(ci_image_idx);
2043 const double norm = mode.norm();
2044 if (mode.size() != path.image(ci_image_idx).positions.size() ||
2045 !mode.allFinite() || !(std::isfinite(norm) && norm >= 1e-8)) {
2046 return std::nullopt;
2053 const Eigen::VectorXd& ci_position,
2056 if (mmf_reject_ci_position_.size() == 0 ||
2057 mmf_reject_ci_position_.size() != ci_position.size()) {
2060 if ((mmf_reject_ci_position_.array() == ci_position.array()).all()) {
2063 const bool same_reject_marker = climbingImage < 0 ||
2064 mmf_reject_climbing_image_ < 0 ||
2065 climbingImage == mmf_reject_climbing_image_;
2066 if (!same_reject_marker) {
2069 if (atoms_config ==
nullptr || !(cfg_.max_burst_displacement > 0.0)) {
2074 return detail::shouldRetainMmfObservation(
2075 ci_position, mmf_reject_ci_position_, *atoms_config,
2076 cfg_.max_burst_displacement);
2080 const Eigen::VectorXd& ci_position,
2081 detail::MmfSurrogateFingerprint surrogate,
long climbingImage,
2088 return !detail::mmfSurrogateChanged(surrogate,
2089 mmf_surrogate_at_last_reject_);
2093 const Eigen::VectorXd& ci_position,
2094 const detail::MmfPosteriorActionFingerprint& action,
long climbingImage,
2101 return !detail::mmfPosteriorActionChanged(action,
2102 mmf_action_at_last_reject_);
2105void OCINEBController::saveAdaptiveState(
long climbingImage)
2107 if (climbingImage < 0)
return;
2108 CiAdaptiveState& state = ci_adaptive_state_[climbingImage];
2109 state.current_threshold = current_threshold_;
2110 state.baseline_force = baseline_force_;
2111 state.trap_backoff_active = trap_backoff_active_;
2112 state.trap_surface_updated = trap_surface_updated_;
2113 state.has_cached_mode = has_cached_mode_;
2114 state.mmf_attempted = mmf_attempted_;
2115 state.soft_quiet_blocked_after_reject = soft_quiet_blocked_after_reject_;
2116 state.uncertified_hook_reject_active = uncertified_hook_reject_active_;
2117 state.oie_quiet_handoff_stalled = oie_quiet_handoff_stalled_;
2118 state.exhausted_recovery_reject_active = exhausted_recovery_reject_active_;
2119 state.best_oie_quiet_handoff_force = best_oie_quiet_handoff_force_;
2120 state.trusted_retry_reject_force = trusted_retry_reject_force_;
2121 state.cached_mode = cached_mode_;
2124void OCINEBController::loadAdaptiveState(
long climbingImage)
2126 const auto it = ci_adaptive_state_.find(climbingImage);
2127 if (it == ci_adaptive_state_.end()) {
2128 current_threshold_ = -1.0;
2129 baseline_force_ = -1.0;
2130 trap_backoff_active_ =
false;
2131 trap_surface_updated_ =
false;
2132 soft_quiet_blocked_after_reject_ =
false;
2133 uncertified_hook_reject_active_ =
false;
2134 oie_quiet_handoff_stalled_ =
false;
2135 exhausted_recovery_reject_active_ =
false;
2136 best_oie_quiet_handoff_force_ =
2137 std::numeric_limits<double>::quiet_NaN();
2138 trusted_retry_reject_force_ = std::numeric_limits<double>::quiet_NaN();
2139 has_cached_mode_ =
false;
2140 mmf_attempted_ =
false;
2141 cached_mode_.resize(0);
2144 current_threshold_ = it->second.current_threshold;
2145 baseline_force_ = it->second.baseline_force;
2146 trap_backoff_active_ = it->second.trap_backoff_active;
2147 trap_surface_updated_ = it->second.trap_surface_updated;
2148 soft_quiet_blocked_after_reject_ =
2149 it->second.soft_quiet_blocked_after_reject;
2150 uncertified_hook_reject_active_ = it->second.uncertified_hook_reject_active;
2151 oie_quiet_handoff_stalled_ = it->second.oie_quiet_handoff_stalled;
2152 exhausted_recovery_reject_active_ =
2153 it->second.exhausted_recovery_reject_active;
2154 best_oie_quiet_handoff_force_ = it->second.best_oie_quiet_handoff_force;
2155 trusted_retry_reject_force_ = it->second.trusted_retry_reject_force;
2156 has_cached_mode_ = it->second.has_cached_mode;
2157 mmf_attempted_ = it->second.mmf_attempted;
2158 cached_mode_ = it->second.cached_mode;
2163 baseline_force_ = baseline_force;
2165 current_threshold_ = baseline_force_ * cfg_.trigger_factor;
2169 bool handoff_data_ready)
2171 if (!std::isfinite(handoff_force) || handoff_force <= 0.0) {
2172 oie_quiet_handoff_stalled_ =
false;
2175 if (handoff_data_ready) {
2176 oie_quiet_handoff_stalled_ =
2177 std::isfinite(best_oie_quiet_handoff_force_) &&
2178 handoff_force >= best_oie_quiet_handoff_force_;
2179 if (!std::isfinite(best_oie_quiet_handoff_force_) ||
2180 handoff_force < best_oie_quiet_handoff_force_) {
2181 best_oie_quiet_handoff_force_ = handoff_force;
2184 oie_quiet_handoff_stalled_ =
false;
2185 best_oie_quiet_handoff_force_ =
2186 std::numeric_limits<double>::quiet_NaN();
2188 retireTrustedRetryIfProgressed(handoff_force);
2197 if (!handoff_data_ready) {
2202 if (!std::isfinite(cfg_.trigger_factor) || cfg_.trigger_factor <= 0.0) {
2205 const double force_tolerance = forceTolerance();
2206 if (std::isfinite(force_tolerance) && force_tolerance > 0.0) {
2207 const double minimum_seed_force = force_tolerance / cfg_.trigger_factor;
2208 if (handoff_force <= minimum_seed_force) {
2215void OCINEBController::retireTrustedRetryIfProgressed(
double handoff_force)
2217 if (!detail::shouldRetireTrustedRetryAfterProgress(
2218 trusted_recovery_active_, trusted_retry_reject_force_,
2219 handoff_force, current_threshold_)) {
2222 trusted_retry_reject_force_ = std::numeric_limits<double>::quiet_NaN();
2223 trap_surface_updated_ =
false;
2227 bool trap_detected,
bool band_information_exhausted,
2228 bool current_chain_certificate)
const
2230 const bool trap_retry_ready =
2231 trap_detected && (!trap_backoff_active_ || trap_surface_updated_);
2232 const bool certified_band_information_exhausted =
2233 band_information_exhausted && current_chain_certificate;
2235 mmf_attempted_ || trap_retry_ready ||
2236 certified_band_information_exhausted;
2240 double convForce,
bool ci_active,
long climbingImage,
long numImages,
2241 bool ci_posterior_confident,
bool trap_detected, std::size_t ntrain_now,
2242 bool ci_is_energy_maximum,
bool band_information_exhausted,
2243 bool oie_acquisition_quiet,
bool rejected_seed_replay,
2244 bool current_chain_certificate,
bool current_saddle_stencil_certificate,
2245 bool rejected_seed_position_matches,
bool stagnation_handoff)
const
2250 if (stagnation_handoff) {
2251 return detail::shouldTriggerMmf(
2252 cfg_, convForce, ci_active, climbingImage, numImages,
2255 false, mmf_info_gate_,
2262 if (detail::shouldHoldMmfForExpectedImprovement(
2263 mmf_wait_for_true_sample_,
static_cast<Eigen::Index
>(ntrain_now),
2264 mmf_wait_ntrain_)) {
2267 if (detail::shouldSuppressMmfRecoveryRetry(force_improving_recovery_active_,
2268 trusted_recovery_active_,
2272 const bool certified_band_information_exhausted =
2273 band_information_exhausted && current_chain_certificate;
2274 const bool reject_gate_applies_to_ci =
2275 mmf_reject_climbing_image_ < 0 ||
2276 climbingImage == mmf_reject_climbing_image_;
2277 const bool exhausted_recovery_reject_applies =
2278 detail::exhaustedRecoveryRejectAppliesToCi(
2279 exhausted_recovery_reject_active_, mmf_reject_climbing_image_,
2281 const bool improved_under_backoff =
2282 std::isfinite(current_threshold_) && current_threshold_ > 0.0 &&
2283 std::isfinite(convForce) && convForce <= current_threshold_;
2287 const bool improved_since_pure_reject =
2288 pure_reject_lock_ && std::isfinite(pure_reject_force_) &&
2289 pure_reject_force_ > 0.0 && std::isfinite(convForce) &&
2290 convForce < pure_reject_force_;
2291 const bool pure_reject_residual_progress =
2292 detail::shouldLeaseAfterPureRejectProgress(pure_reject_lock_,
2293 improved_under_backoff,
2294 improved_since_pure_reject);
2295 const bool exhausted_quiet_stall_lease =
2296 detail::shouldLeaseAfterExhaustedQuietStall(
2297 pure_reject_lock_, exhausted_recovery_reject_applies,
2298 oie_quiet_handoff_stalled_, oie_acquisition_quiet,
2299 current_chain_certificate, current_saddle_stencil_certificate,
2300 ci_posterior_confident, ci_is_energy_maximum);
2305 const bool rejected_seed_geometry_replay =
2306 rejected_seed_replay || rejected_seed_position_matches;
2307 if (detail::shouldSkipMmfAfterSpentMinModeProbe(
2308 min_mode_probe_spent_, rejected_seed_replay,
2309 rejected_seed_position_matches)) {
2312 if (detail::shouldBlockRejectedSeedReplay(
2313 rejected_seed_geometry_replay, trap_detected,
2314 improved_since_pure_reject, exhausted_quiet_stall_lease)) {
2317 const bool trusted_retry_progress_pending =
2318 trusted_recovery_active_ &&
2319 std::isfinite(trusted_retry_reject_force_) &&
2320 trusted_retry_reject_force_ > 0.0;
2321 const bool force_recovery_stalled_handoff =
2322 detail::isForceImprovingRecoveryStalledHandoff(
2323 force_improving_recovery_active_, ci_posterior_confident,
2324 current_chain_certificate, oie_acquisition_quiet,
2325 oie_quiet_handoff_stalled_);
2326 const bool trusted_recovery_stalled_signal =
2327 detail::isTrustedRecoveryStalledHandoff(
2328 trusted_recovery_active_, ci_posterior_confident,
2329 current_chain_certificate, ci_is_energy_maximum,
2330 oie_acquisition_quiet, oie_quiet_handoff_stalled_);
2331 const bool trusted_recovery_stalled_handoff =
2332 detail::shouldUseTrustedRecoveryStalledHandoff(
2333 trusted_retry_progress_pending, trusted_recovery_stalled_signal);
2334 const bool recovery_stalled_handoff =
2335 force_recovery_stalled_handoff || trusted_recovery_stalled_handoff;
2336 const bool trusted_recovery_progress_handoff =
2337 detail::isTrustedRecoveryProgressHandoff(
2338 trusted_recovery_active_, trusted_retry_reject_force_, convForce,
2339 current_threshold_, ci_posterior_confident, ci_is_energy_maximum,
2340 rejected_seed_replay, current_chain_certificate,
2341 oie_quiet_handoff_stalled_, oie_acquisition_quiet);
2342 const bool refreshed_exhausted_recovery_handoff =
2343 detail::isRefreshedExhaustedRecoveryHandoff(
2344 exhausted_recovery_reject_applies, current_chain_certificate,
2345 current_saddle_stencil_certificate, rejected_seed_replay,
2346 rejected_seed_replay || rejected_seed_position_matches,
2347 ci_posterior_confident, ci_is_energy_maximum);
2348 const bool stale_rejected_seed_handoff =
2349 !exhausted_recovery_reject_applies && !trusted_retry_progress_pending &&
2350 soft_quiet_blocked_after_reject_ && !rejected_seed_replay &&
2351 current_chain_certificate && ci_posterior_confident &&
2352 ci_is_energy_maximum && oie_acquisition_quiet &&
2353 oie_quiet_handoff_stalled_;
2357 const bool certificate_bar_bypass_state =
2358 oie_quiet_handoff_stalled_ || pure_reject_lock_ ||
2359 soft_quiet_blocked_after_reject_ || force_improving_recovery_active_ ||
2360 trusted_recovery_active_;
2361 const bool current_chain_certified_handoff =
2362 certificate_bar_bypass_state &&
2363 detail::isCurrentChainCertifiedHandoff(
2364 trusted_retry_progress_pending, current_chain_certificate,
2365 rejected_seed_replay, ci_posterior_confident, ci_is_energy_maximum,
2366 oie_acquisition_quiet, exhausted_recovery_reject_applies);
2367 const bool current_chain_under_threshold_handoff =
2368 !trusted_retry_progress_pending && current_chain_certificate &&
2369 !rejected_seed_replay && oie_acquisition_quiet &&
2370 std::isfinite(convForce) && convForce > 0.0 &&
2371 std::isfinite(current_threshold_) && current_threshold_ > 0.0 &&
2372 convForce <= current_threshold_;
2377 const bool exact_saddle_stencil_handoff =
2378 !mmf_attempted_ && current_saddle_stencil_certificate &&
2379 current_chain_certificate && !rejected_seed_replay &&
2380 ci_posterior_confident && ci_is_energy_maximum;
2381 const bool certified_handoff =
2382 stale_rejected_seed_handoff || current_chain_certified_handoff ||
2383 current_chain_under_threshold_handoff || exact_saddle_stencil_handoff ||
2384 refreshed_exhausted_recovery_handoff || recovery_stalled_handoff ||
2385 trusted_recovery_progress_handoff;
2386 bool soft_quiet = oie_acquisition_quiet;
2387 if (soft_quiet && soft_quiet_blocked_after_reject_ &&
2388 reject_gate_applies_to_ci) {
2389 soft_quiet = improved_under_backoff || recovery_stalled_handoff ||
2392 const bool soft_quiet_stalled = soft_quiet && oie_quiet_handoff_stalled_;
2393 const bool trap_retry_ready =
2394 trap_detected && (!trap_backoff_active_ || trap_surface_updated_);
2402 current_chain_certificate)) {
2411 if (pure_reject_lock_ && !pure_reject_residual_progress &&
2412 !certified_band_information_exhausted && !recovery_stalled_handoff &&
2413 !certified_handoff && !exhausted_quiet_stall_lease &&
2414 !trap_retry_ready) {
2420 if (soft_quiet_blocked_after_reject_ && reject_gate_applies_to_ci &&
2421 !improved_under_backoff && !trap_detected &&
2422 !certified_band_information_exhausted && !recovery_stalled_handoff &&
2423 !certified_handoff && !exhausted_quiet_stall_lease &&
2424 !pure_reject_residual_progress) {
2432 const double trigger_threshold =
2433 (!
baselineSet() && ci_posterior_confident) ? 0.0 : current_threshold_;
2434 const bool pure_reject_residual_handoff =
2435 pure_reject_residual_progress && ci_posterior_confident;
2439 const bool lease_after_information_gate =
2440 recovery_stalled_handoff || exhausted_quiet_stall_lease ||
2441 pure_reject_residual_handoff || pending_min_mode_probe_lease_;
2442 const bool certified_handoff_beats_gate =
2443 stale_rejected_seed_handoff || current_chain_certified_handoff ||
2444 current_chain_under_threshold_handoff || exact_saddle_stencil_handoff ||
2445 refreshed_exhausted_recovery_handoff ||
2446 trusted_recovery_progress_handoff;
2447 return detail::shouldTriggerMmf(
2448 cfg_, convForce, ci_active, climbingImage, numImages,
2449 ci_posterior_confident, trigger_threshold, trap_detected,
2450 trap_backoff_active_, trap_surface_updated_, mmf_info_gate_,
2451 ci_is_energy_maximum, certified_band_information_exhausted, soft_quiet,
2452 soft_quiet_stalled, lease_after_information_gate,
2453 certified_handoff_beats_gate);
2458 trap_surface_updated_ =
true;
2462 detail::MmfSurrogateFingerprint surrogate)
2464 detail::MmfPosteriorActionFingerprint action;
2465 action.surrogate = surrogate;
2470 detail::MmfPosteriorActionFingerprint action)
2472 using Gate = detail::MmfInformationGate;
2473 mmf_info_gate_ = action.action.valid ? Gate::AwaitingActionChange
2474 : Gate::AwaitingFirstTrainingGrowth;
2475 mmf_surrogate_at_last_reject_ = action.surrogate;
2476 mmf_action_at_last_reject_ = std::move(action);
2480 detail::MmfSurrogateFingerprint surrogate)
2482 const bool changed_since_reject =
2483 detail::mmfSurrogateChanged(surrogate, mmf_surrogate_at_last_reject_);
2484 const bool was_waiting = mmf_info_gate_ != detail::MmfInformationGate::Open;
2485 if (was_waiting && changed_since_reject) {
2486 mmf_info_gate_ = detail::MmfInformationGate::Open;
2487 uncertified_hook_reject_active_ =
false;
2488 trap_surface_updated_ =
true;
2489 for (
auto& [_, state]: ci_adaptive_state_) {
2490 if (state.trap_backoff_active) {
2491 state.trap_surface_updated =
true;
2498 detail::MmfPosteriorActionFingerprint action)
2500 const bool changed_since_reject =
2501 detail::mmfPosteriorActionChanged(action, mmf_action_at_last_reject_);
2502 if (changed_since_reject) {
2503 min_mode_probe_spent_ =
false;
2505 const bool was_waiting = mmf_info_gate_ != detail::MmfInformationGate::Open;
2506 if (was_waiting && changed_since_reject) {
2507 mmf_info_gate_ = detail::MmfInformationGate::Open;
2509 if (mmf_info_gate_ == detail::MmfInformationGate::Open) {
2510 uncertified_hook_reject_active_ =
false;
2512 if (was_waiting && changed_since_reject &&
2513 mmf_info_gate_ == detail::MmfInformationGate::Open) {
2514 trap_surface_updated_ =
true;
2515 for (
auto& [_, state]: ci_adaptive_state_) {
2516 if (state.trap_backoff_active) {
2517 state.trap_surface_updated =
true;
2527 detail::MmfPosteriorActionFingerprint result;
2531 if (!neb_config.
gp_setup)
return result;
2533 const std::optional<Eigen::VectorXd> initial_mode =
2534 initialModeForPath(path, ci_image_idx);
2535 if (!initial_mode)
return result;
2537 const double seed_displacement = detail::resolveMmfSeedDisplacement(
2538 cfg_.perturb_along_tangent, force_improving_recovery_active_,
2539 trusted_recovery_active_);
2540 if (seed_displacement != 0.0) {
2541 seed += seed_displacement * *initial_mode;
2544 Eigen::VectorXd seed_gradient;
2545 const int observation_index =
2547 if (observation_index >= 0 &&
2550 session.
training_obs.
G.row(observation_index).allFinite()) {
2553 }
else if (detail::positionsCoincide(seed,
2563 predicted.
R = flatToCoord1xD(seed);
2565 if (predicted.
G.rows() != 1 || predicted.
G.cols() != seed.size() ||
2566 !predicted.
G.allFinite()) {
2570 seed_gradient = predicted.
G.row(0).transpose();
2573 return detail::probeMmfPosteriorAction(
2575 seed_gradient, *initial_mode, neb_config, cfg_);
2579 const Eigen::VectorXd& owner_position,
long owner_image)
2581 if (!detail::activeMmfRecoveryOwnsClimbingImage(
2582 force_improving_recovery_active_, trusted_recovery_active_)) {
2585 if (force_improving_recovery_active_) {
2586 pure_reject_lock_ =
false;
2587 pure_reject_force_ = std::numeric_limits<double>::quiet_NaN();
2589 force_improving_recovery_active_ =
false;
2590 trusted_recovery_active_ =
false;
2591 recovery_owner_image_ = -1;
2592 trusted_retry_reject_force_ = std::numeric_limits<double>::quiet_NaN();
2593 trap_surface_updated_ =
false;
2594 mmf_info_gate_ = detail::MmfInformationGate::Open;
2595 mmf_surrogate_at_last_reject_ = {};
2596 mmf_action_at_last_reject_ = {};
2597 exhausted_recovery_reject_active_ =
true;
2603 if (!exhausted_recovery_reject_active_)
return;
2604 exhausted_recovery_reject_active_ =
false;
2605 soft_quiet_blocked_after_reject_ =
false;
2606 pure_reject_lock_ =
false;
2607 pure_reject_force_ = std::numeric_limits<double>::quiet_NaN();
2608 trap_backoff_active_ =
false;
2609 trap_surface_updated_ =
false;
2610 uncertified_hook_reject_active_ =
false;
2611 oie_quiet_handoff_stalled_ =
false;
2612 best_oie_quiet_handoff_force_ = std::numeric_limits<double>::quiet_NaN();
2613 mmf_info_gate_ = detail::MmfInformationGate::Open;
2614 mmf_surrogate_at_last_reject_ = {};
2615 mmf_action_at_last_reject_ = {};
2616 mmf_reject_ci_position_.resize(0);
2617 mmf_reject_climbing_image_ = -1;
2621 double convForce,
const Eigen::VectorXd& ci_position,
2622 detail::MmfSurrogateFingerprint surrogate,
long climbingImage)
2624 detail::MmfPosteriorActionFingerprint action;
2625 action.surrogate = surrogate;
2631 double convForce,
const Eigen::VectorXd& ci_position,
2632 detail::MmfPosteriorActionFingerprint action,
long climbingImage)
2635 updateThresholdBackoff(convForce);
2637 trap_backoff_active_ =
true;
2638 trap_surface_updated_ =
false;
2639 soft_quiet_blocked_after_reject_ =
true;
2641 force_improving_recovery_active_ =
false;
2642 trusted_recovery_active_ =
false;
2643 recovery_owner_image_ = -1;
2646 uncertified_hook_reject_active_ =
true;
2650 if (detail::isMmfAdaptiveThresholdSeeded(current_threshold_) &&
2651 std::isfinite(convForce) && convForce > 0.0) {
2652 pure_reject_lock_ =
true;
2653 pure_reject_force_ = convForce;
2658 double convForce,
bool ci_active,
long climbingImage,
long numImages,
2659 int outerIter,
bool ci_posterior_confident,
bool trap_detected,
2660 std::size_t ntrain_now,
bool ci_is_energy_maximum)
2662 if (!cfg_.use_mmf || !ci_active)
return false;
2664 const bool valid_climbing_image =
2665 climbingImage > 0 && climbingImage <= numImages;
2666 const bool active_recovery_needs_oracle =
2667 detail::activeMmfRecoveryOwnsClimbingImage(
2668 force_improving_recovery_active_, trusted_recovery_active_);
2669 const bool exhausted_recovery_needs_oracle =
2670 detail::shouldRequestCurrentCiOracleForExhaustedRecovery(
2671 exhausted_recovery_reject_active_, mmf_reject_climbing_image_,
2673 if (valid_climbing_image &&
2674 (active_recovery_needs_oracle || exhausted_recovery_needs_oracle)) {
2677 const bool trap_retry_needs_oracle =
2678 detail::shouldUseSurfaceUpdatedTrapRetryForCurrentCiOracle(
2679 trap_surface_updated_, trusted_recovery_active_,
2680 trusted_retry_reject_force_, convForce, current_threshold_);
2681 const bool effective_trap = trap_detected || trap_retry_needs_oracle;
2687 const double force_tolerance = forceTolerance();
2688 return climbingImage > 0 && climbingImage <= numImages &&
2689 ci_posterior_confident && ci_is_energy_maximum &&
2690 std::isfinite(convForce) && std::isfinite(force_tolerance) &&
2691 force_tolerance > 0.0 && convForce > force_tolerance;
2693 return shouldTrigger(convForce, ci_active, climbingImage, numImages,
2694 ci_posterior_confident, effective_trap, ntrain_now,
2695 ci_is_energy_maximum);
2700 if (climbingImage == previousClimbingImage_)
return;
2701 if (previousClimbingImage_ < 0) {
2702 previousClimbingImage_ = climbingImage;
2703 saveAdaptiveState(climbingImage);
2708 saveAdaptiveState(previousClimbingImage_);
2709 previousClimbingImage_ = climbingImage;
2710 loadAdaptiveState(climbingImage);
2712 const detail::PureLockHopState hop = detail::pureLockStateAfterCiHop(
2713 {pure_reject_lock_, pure_reject_force_,
2714 force_improving_recovery_active_, trusted_recovery_active_});
2715 pure_reject_lock_ = hop.pure_reject_lock;
2716 pure_reject_force_ = hop.pure_reject_force;
2717 force_improving_recovery_active_ = hop.force_improving_recovery_active;
2718 trusted_recovery_active_ = hop.trusted_recovery_active;
2719 if (!detail::activeMmfRecoveryOwnsClimbingImage(
2720 force_improving_recovery_active_, trusted_recovery_active_)) {
2721 recovery_owner_image_ = -1;
2728 if (outerIter == lastStabilityOuter_ &&
2729 climbingImage == lastStabilityClimbingImage_) {
2733 lastStabilityOuter_ = outerIter;
2734 lastStabilityClimbingImage_ = climbingImage;
2737void OCINEBController::updateThresholdSuccess(
double convForce,
double newForce)
2739 const double max_threshold = baseline_force_ * cfg_.
trigger_factor;
2740 current_threshold_ =
2741 detail::successThresholdAfterMmf(convForce, newForce, max_threshold);
2742 trap_backoff_active_ =
false;
2743 trap_surface_updated_ =
false;
2744 uncertified_hook_reject_active_ =
false;
2745 soft_quiet_blocked_after_reject_ =
false;
2746 pure_reject_lock_ =
false;
2747 force_improving_recovery_active_ =
false;
2748 trusted_recovery_active_ =
false;
2749 recovery_owner_image_ = -1;
2750 exhausted_recovery_reject_active_ =
false;
2751 oie_quiet_handoff_stalled_ =
false;
2752 best_oie_quiet_handoff_force_ = std::numeric_limits<double>::quiet_NaN();
2753 mmf_info_gate_ = detail::MmfInformationGate::Open;
2754 mmf_surrogate_at_last_reject_ = {};
2755 mmf_action_at_last_reject_ = {};
2758void OCINEBController::updateThresholdBackoff(
double convForce)
2760 const double max_threshold = baseline_force_ * cfg_.trigger_factor;
2762 current_threshold_ = detail::rejectedMmfBackoffThreshold(
2763 convForce, forceTolerance(), max_threshold);
2764 trap_backoff_active_ =
true;
2765 trap_surface_updated_ =
false;
2766 uncertified_hook_reject_active_ =
false;
2767 soft_quiet_blocked_after_reject_ =
true;
2768 force_improving_recovery_active_ =
false;
2769 recovery_owner_image_ = -1;
2770 exhausted_recovery_reject_active_ =
false;
2771 oie_quiet_handoff_stalled_ =
false;
2772 best_oie_quiet_handoff_force_ = std::numeric_limits<double>::quiet_NaN();
2777void detail::configureBurstDimerSecant(atmd::AtomicDimer& dimer,
2778 const optim::SecantHessianConfig&
band)
2780 auto dimer_secant =
band;
2781 dimer_secant.quadratic_prior_mean =
false;
2786std::vector<StagedDimerObservation> detail::stageDimerObservationUpdates(
2787 const gpr::Observation& initial,
const gpr::Coord& positions,
2789 double energy_origin)
2791 std::vector<StagedDimerObservation> staged;
2792 for (Eigen::Index row = 0; row < positions.rows(); ++row) {
2796 const bool unchanged =
2797 row < initial.
R.rows() &&
2798 (initial.
R.row(row).array() == positions.row(row).array()).all() &&
2799 initial.
E(row, 0) - energy_origin == energies(row, 0) &&
2800 (initial.
G.row(row).array() == gradients.row(row).array()).all();
2801 if (unchanged)
continue;
2802 staged.push_back({positions.row(row).transpose(),
2803 energies(row, 0) + energy_origin,
2804 gradients.row(row).transpose()});
2809void OCINEBController::runBurstUnderSessionModelLease(
2812 const gpr::Observation& middle_point, atmd::AtomicDimer& dimer,
2814 std::vector<StagedDimerObservation>& staged_dimer_observations)
2816 ActiveLearningSession::ModelLease model = [&]() {
2817 if (per_image_ready) {
2818 return session.acquireImageModel(ci_image_idx);
2820 return session.acquireGlobalModel();
2822 auto restore_model = model.scopedParameterRestore();
2824 gpr::Observation init_observations = model.observations();
2825 gpr::Coord init_orient_coord = flatToCoord1xD(initialMode);
2827 gpr::AtomsConfiguration tmp;
2828 const bool use_analytic_hssvd =
2829 detail::shouldUseHssvdAnalyticDimerCurvature(
2830 neb_config, model.gp().hasReusableHssvdPosterior());
2831 gpr::InputParameters parameters =
2832 detail::buildDimerParameters(neb_config, cfg_, tmp, use_analytic_hssvd);
2839 dimer.
initialize(parameters, init_observations, middle_point,
2840 init_orient_coord, session.atoms_config);
2845 ++mmf_bursts_fired_;
2846 mmf_attempted_ =
true;
2864 atmd::AtomicDimer::VarianceGateConfig vg =
2868 detail::resolveDimerVarianceTauRelative(neb_config, cfg_);
2873#ifdef USE_READCON_DB
2874 dimer.setObservationArchive(session.observationArchive());
2877 detail::configureBurstDimerSecant(dimer, neb_config.secant_hessian);
2878 const gpr::optim::SecantCurvatureCounts replayed_secants =
2881 gpr::optim::SecantCurvatureCounts fresh_secants = dimer.
secantLedger();
2887 session.addSecantCounts(fresh_secants);
2890 mmf_iterations_used_ +=
static_cast<long>(dimer.
getIterations());
2903 const double e0 = (e_zero.size() > 0) ? e_zero(0, 0) : 0.0;
2904 staged_dimer_observations = detail::stageDimerObservationUpdates(
2905 init_observations, dimer_R, dimer_E, dimer_G, e0);
2908 restore_model.restore();
2911void OCINEBController::runBurstOnTruePotential(
2914 const Eigen::VectorXd& initialMode,
const gpr::Observation& middle_point,
2915 atmd::AtomicDimer& dimer,
double pre_neb_force,
bool has_gp,
2917 std::vector<StagedDimerObservation>& staged_dimer_observations)
2925 gpr::Observation empty_obs;
2926 gpr::Coord init_orient_coord = flatToCoord1xD(initialMode);
2927 gpr::AtomsConfiguration tmp;
2928 gpr::InputParameters parameters =
2929 detail::buildDimerParameters(neb_config, cfg_, tmp);
2937 const double* energy_noise_rms =
2938 detail::oracleEnergyNoiseRmsPtr(neb_config);
2939 if (energy_noise_rms !=
nullptr) {
2940 const double rms = *energy_noise_rms;
2941 if (std::isfinite(rms) && rms > 0.0) {
2950 dimer.
initialize(parameters, empty_obs, middle_point, init_orient_coord,
2951 session.atoms_config);
2952 if (energy_noise_rms !=
nullptr) {
2953 const double rms = *energy_noise_rms;
2954 if (std::isfinite(rms) && rms > 0.0) {
2959 detail::shouldUseHssvdAnalyticDimerCurvature(neb_config));
2962 ++mmf_bursts_fired_;
2963 mmf_attempted_ =
true;
2973 const bool near_threshold =
2974 std::isfinite(current_threshold_) && current_threshold_ > 0.0 &&
2975 pre_neb_force > 0.0 && pre_neb_force <= current_threshold_;
2978 atmd::AtomicDimer::VarianceGateConfig vg =
2982 detail::resolveDimerVarianceTauRelative(neb_config, cfg_);
2987#ifdef USE_READCON_DB
2988 dimer.setObservationArchive(session.observationArchive());
2991 detail::configureBurstDimerSecant(dimer, neb_config.secant_hessian);
2995 mmf_iterations_used_ +=
static_cast<long>(dimer.
getIterations());
3010 const double e0 = (e_zero.size() > 0) ? e_zero(0, 0) : 0.0;
3011 staged_dimer_observations = detail::stageDimerObservationUpdates(
3012 empty_obs, dimer_R, dimer_E, dimer_G, e0);
3016void OCINEBController::recordBurstOutcome(
3019 bool adaptive_threshold_seeded,
bool force_improved,
3020 double threshold_pre_force,
double threshold_post_force,
3024 updateThresholdSuccess(threshold_pre_force, threshold_post_force);
3025 pure_reject_force_ = std::numeric_limits<double>::quiet_NaN();
3026 trusted_retry_reject_force_ = std::numeric_limits<double>::quiet_NaN();
3027 }
else if (force_improved || result.trusted_recovery_advanced) {
3031 result.force_improving_recovery_advanced = force_improved;
3032 mmf_reject_ci_position_.resize(0);
3033 mmf_reject_climbing_image_ = -1;
3034 exhausted_recovery_reject_active_ =
false;
3035 trusted_retry_reject_force_ = std::numeric_limits<double>::quiet_NaN();
3036 const double problem_force_tol = forceTolerance();
3037 const bool residual_at_problem_tol =
3038 std::isfinite(threshold_post_force) && threshold_post_force > 0.0 &&
3039 std::isfinite(problem_force_tol) && problem_force_tol > 0.0 &&
3040 threshold_post_force <= problem_force_tol;
3046 if (residual_at_problem_tol) {
3047 soft_quiet_blocked_after_reject_ =
true;
3048 force_improving_recovery_active_ = force_improved;
3049 trusted_recovery_active_ =
3050 detail::shouldKeepTrustedRecoveryGateAfterAdvance(
3051 result.trusted_recovery_advanced, force_improved);
3052 recovery_owner_image_ =
3053 detail::activeMmfRecoveryOwnsClimbingImage(
3054 force_improving_recovery_active_, trusted_recovery_active_)
3057 if (force_improved && adaptive_threshold_seeded) {
3058 pure_reject_lock_ =
true;
3059 pure_reject_force_ = threshold_post_force;
3061 pure_reject_lock_ =
false;
3062 pure_reject_force_ = std::numeric_limits<double>::quiet_NaN();
3065 soft_quiet_blocked_after_reject_ =
false;
3066 force_improving_recovery_active_ =
false;
3067 trusted_recovery_active_ =
false;
3068 recovery_owner_image_ = -1;
3069 pure_reject_lock_ =
false;
3070 pure_reject_force_ = std::numeric_limits<double>::quiet_NaN();
3071 mmf_info_gate_ = detail::MmfInformationGate::Open;
3076 const bool preserve_fi_recovery_gate =
3077 detail::shouldPreserveFiRecoveryGateAfterRetry(
3078 force_improving_recovery_active_, threshold_pre_force,
3079 current_threshold_, forceTolerance(),
3080 result.recovery_selection_exhausted);
3081 const bool preserve_trusted_recovery_gate =
3082 detail::shouldPreserveTrustedRecoveryGateAfterRetry(
3083 trusted_recovery_active_, result.status, force_improved,
3084 result.trusted_recovery_advanced,
3085 result.rejected_helped_handback, result.reject_kind,
3086 result.recovery_selection_exhausted);
3087 if (!preserve_fi_recovery_gate && !preserve_trusted_recovery_gate) {
3088 updateThresholdBackoff(threshold_pre_force);
3089 exhausted_recovery_reject_active_ =
3090 result.recovery_selection_exhausted;
3092 if (preserve_fi_recovery_gate || preserve_trusted_recovery_gate) {
3093 if (detail::shouldRecordRejectedSeedForRecoveryGate(
3094 preserve_fi_recovery_gate,
3095 preserve_trusted_recovery_gate)) {
3098 mmf_reject_ci_position_.resize(0);
3099 mmf_reject_climbing_image_ = -1;
3101 soft_quiet_blocked_after_reject_ =
true;
3102 force_improving_recovery_active_ = preserve_fi_recovery_gate;
3103 trusted_recovery_active_ = preserve_trusted_recovery_gate;
3104 if (recovery_owner_image_ < 1) {
3105 recovery_owner_image_ = ci_image_idx;
3107 exhausted_recovery_reject_active_ =
false;
3108 pure_reject_lock_ = preserve_fi_recovery_gate;
3109 trusted_retry_reject_force_ =
3110 detail::trustedRetryRejectForceAfterRetry(
3111 preserve_trusted_recovery_gate, trusted_retry_reject_force_,
3112 threshold_pre_force);
3115 trusted_recovery_active_ =
false;
3116 recovery_owner_image_ = -1;
3117 exhausted_recovery_reject_active_ =
3118 result.recovery_selection_exhausted;
3119 trusted_retry_reject_force_ =
3120 std::numeric_limits<double>::quiet_NaN();
3121 pure_reject_lock_ = detail::shouldPureLockAfterMmfReject(
3122 result.status, force_improved, result.trusted_recovery_advanced,
3123 adaptive_threshold_seeded, result.reject_kind);
3125 if (pure_reject_lock_) {
3131 if (std::isfinite(threshold_pre_force) &&
3132 threshold_pre_force > 0.0 &&
3133 (!std::isfinite(pure_reject_force_) ||
3134 threshold_pre_force < pure_reject_force_)) {
3135 pure_reject_force_ = threshold_pre_force;
3138 pure_reject_force_ = std::numeric_limits<double>::quiet_NaN();
3144 if (result.mode_probe_acquired) {
3159 pending_min_mode_probe_lease_ =
false;
3160 const Eigen::Index ntrain_now = session.
training_obs.
R.rows();
3161 if (mmf_wait_for_true_sample_ && ntrain_now > mmf_wait_ntrain_) {
3162 mmf_wait_for_true_sample_ =
false;
3166 static_cast<long>(ci_image_idx))) {
3167 min_mode_probe_spent_ =
false;
3169 trap_surface_updated_ =
false;
3170 std::vector<StagedDimerObservation> staged_dimer_observations;
3173 Eigen::VectorXd savedPositions = path.
image(ci_image_idx).
positions;
3182 const bool savedCiEnergyValid =
3185 const double savedCiEnergy = path.
image(ci_image_idx).
energy;
3192 const double burst_disp_cap = cfg_.max_burst_displacement;
3194 const auto local_spacing_to = [&](
int image_idx) ->
double {
3195 if (image_idx < 0 || image_idx >= path.
numImages()) {
3196 return std::numeric_limits<double>::infinity();
3198 const Eigen::VectorXd& neighbor_positions =
3200 if (neighbor_positions.size() != savedPositions.size() ||
3201 neighbor_positions.size() == 0) {
3202 return std::numeric_limits<double>::infinity();
3204 return emdDistance(savedPositions, neighbor_positions,
3207 const double recovery_disp_cap =
3208 detail::effectiveMmfRecoveryDisplacementCap(
3209 burst_disp_cap, local_spacing_to(ci_image_idx - 1),
3210 local_spacing_to(ci_image_idx + 1));
3213 const double pre_neb_force = path.
nebForce(ci_image_idx).norm();
3214 const double pre_force = path.
saddleForce(ci_image_idx);
3218 const std::optional<Eigen::VectorXd> initial_mode =
3219 initialModeForPath(path, ci_image_idx);
3220 if (!initial_mode) {
3226 const Eigen::VectorXd initialMode = *initial_mode;
3230 if (cfg_.rg_minmode_dimer) {
3233 const Eigen::Index dof = savedPositions.size();
3234 const int64_t n_atoms = dof / 3;
3236 if (n_atoms >= 1 && dof == 3 * n_atoms &&
3237 minmode.
bind(dest, n_atoms, savedPositions.data(),
3238 initialMode.data(), cfg_.force_tolerance,
3240 std::max(1, cfg_.dimer_max_rot_iter), 1e-3)) {
3242 surface_user.
gp = &session.
gp;
3244 const long rg_cap = cfg_.max_steps > 0 ? cfg_.max_steps : 16;
3246 for (
long s = 0; s < rg_cap; ++s) {
3252 if (rg_report.max_force <= cfg_.force_tolerance) {
3256 Eigen::VectorXd rg_pos(dof);
3257 if (rg_ok && minmode.
position(rg_pos.data()) &&
3258 rg_pos.allFinite() && rg_report.curvature < 0.0) {
3261 result.
newForce = rg_report.max_force;
3263 result.
alignment = std::abs(initialMode.dot(
3264 path.
tangentAt(ci_image_idx).normalized()));
3265 result.
oracle_calls =
static_cast<int>(rg_report.rotations);
3274 Eigen::VectorXd ci_pos = savedPositions;
3275 const double seed_displacement = detail::resolveMmfSeedDisplacement(
3276 cfg_.perturb_along_tangent, force_improving_recovery_active_,
3277 trusted_recovery_active_);
3278 if (seed_displacement != 0.0) {
3279 ci_pos += seed_displacement * initialMode;
3295 middle_point.
R = flatToCoord1xD(ci_pos);
3313 const int dimer_model_owner =
3315 const bool per_image_ready = dimer_model_owner >= 0;
3321 dimer.setProjectRigidModesForConvergence(
true);
3323 dimer.setForceStopCertificateStep(0.0);
3324 const bool has_gp =
static_cast<bool>(neb_config.
gp_setup);
3341 detail::MmfPosteriorActionFingerprint dimer_action;
3344 static_cast<long>(ci_image_idx))) {
3349 savedPositions, dimer_action,
static_cast<long>(ci_image_idx),
3351 const bool lease_session_gp =
3352 has_gp && !trap_detected && !reject_latched_here;
3353 Eigen::VectorXd curvature_seed = initialMode;
3368 std::cout <<
"[secant-seed] climbing-image burst keeps its "
3372 if (lease_session_gp) {
3373 runBurstUnderSessionModelLease(ci_image_idx, oracle, neb_config,
3374 session, curvature_seed,
3375 middle_point,
dimer, per_image_ready,
3376 result, staged_dimer_observations);
3378 runBurstOnTruePotential(oracle, neb_config, session, trap_detected,
3379 curvature_seed, middle_point,
dimer,
3380 pre_neb_force, has_gp, result,
3381 staged_dimer_observations);
3385 }
catch (
const std::runtime_error& error) {
3386 std::cout <<
"[ocineb] climbing-image dimer stopped by oracle "
3388 << error.what() <<
"; refinement failed, band kept"
3408 Eigen::VectorXd dimer_final_pos =
dimer.getFinalCoordOfMidPoint();
3410 const Eigen::VectorXd finalMode =
3411 final_orient_coord.cols() > 0
3412 ? coordToFlat(final_orient_coord).normalized()
3413 : Eigen::VectorXd();
3414 Eigen::VectorXd currentTangent = path.
tangentAt(ci_image_idx).normalized();
3416 (finalMode.size() == currentTangent.size() && finalMode.size() > 0)
3417 ? std::abs(finalMode.dot(currentTangent))
3421 const double e0 = (e_zero.size() > 0) ? e_zero(0, 0) : 0.0;
3424 const std::vector<atmd::AtomicDimer::DimerPhaseRecord>& history =
3425 dimer.getPhaseHistory();
3426 int best_phase = -1;
3427 double best_curv = std::numeric_limits<double>::infinity();
3428 for (
int h = 0; h < static_cast<int>(history.size()); ++h) {
3429 if (std::isfinite(history[h].curvature) &&
3430 history[h].curvature < best_curv) {
3431 best_curv = history[h].curvature;
3435 const bool found_saddle_mode = (best_phase >= 0 && best_curv < 0.0);
3436 const bool hit_step_budget =
3437 cfg_.max_steps > 0 &&
3440 const double helped_emd_disp =
3441 (
dimer.getConverged() &&
3442 dimer_final_pos.size() == savedPositions.size())
3443 ? emdDistance(dimer_final_pos, savedPositions, session.
atoms_config)
3444 : std::numeric_limits<double>::infinity();
3445 const bool dimerAngleCertified =
3446 found_saddle_mode &&
dimer.isMinModeAngleCertified();
3447 const bool helpedPathCertified = detail::forceOnlyHelpedPathCertified(
3448 dimerAngleCertified, result.
alignment, cfg_.alignment_cos_tol);
3452 const bool helped_ran_away =
3453 detail::shouldRejectUncertifiedHelpedDisplacement(
3454 dimer.getConverged(), dimerAngleCertified, helped_emd_disp,
3457 const double dimerFinalEnergy =
dimer.getFinalEnergy() + e0;
3461 const double helped_neb_force = [&]() ->
double {
3462 if (!(
dimer.getConverged() &&
3463 dimer_final_pos.size() == savedPositions.size() &&
3464 dimer_final_pos.size() > 0)) {
3465 return std::numeric_limits<double>::infinity();
3467 const Eigen::VectorXd g_final =
dimer.getFinalGradientAtMidPoint();
3468 detail::ScopedImageState restore(path, ci_image_idx);
3470 path.
image(ci_image_idx).
energy = dimerFinalEnergy;
3474 return path.
nebForce(ci_image_idx).norm();
3476 const bool helped_force_improves = std::isfinite(helped_neb_force) &&
3477 std::isfinite(pre_neb_force) &&
3478 helped_neb_force < pre_neb_force;
3492 const bool helped_descended_below_seed = savedCiEnergyValid &&
3493 std::isfinite(dimerFinalEnergy) &&
3494 dimerFinalEnergy < savedCiEnergy;
3495 const bool helped_below_endpoints =
3496 detail::shouldRejectForceOnlyHelpedBelowEndpoints(
3497 dimer.getConverged(), dimerAngleCertified, dimerFinalEnergy,
3501 const double ceiling_slack =
3507 const bool helped_above_ceiling =
3509 std::isfinite(dimerFinalEnergy) &&
3511 const bool helped_wrong_mode =
3512 !helpedPathCertified || helped_above_ceiling ||
3513 (!dimerAngleCertified &&
3514 (helped_below_endpoints ||
3515 (helped_descended_below_seed && !helped_force_improves)));
3516 const bool search_recovery_portfolio =
3517 detail::shouldSearchMmfRecoveryPortfolio(
3518 dimer.getConverged(), helped_ran_away, helpedPathCertified,
3527 const double dimer_true_force =
dimer.getFinalForceNormForConvergence();
3528 const bool dimer_force_under_tolerance =
3529 dimer.getConverged() && std::isfinite(dimer_true_force) &&
3530 dimer_true_force < forceTolerance();
3531 if (
dimer.getConverged() && !helped_ran_away && !helped_above_ceiling &&
3532 (dimer_force_under_tolerance || !helped_wrong_mode)) {
3536 cached_mode_ = finalMode;
3537 has_cached_mode_ =
true;
3538 const Eigen::VectorXd g_final =
dimer.getFinalGradientAtMidPoint();
3540 path.
image(ci_image_idx).
energy = dimerFinalEnergy;
3557 std::cout <<
"[ocineb] burst @ outer hook: Helped, dimer "
3558 <<
"converged to saddle (force " << pre_force <<
" -> "
3562 <<
", angle_certified="
3566 }
else if (
dimer.getConverged() && !helped_ran_away && helped_wrong_mode &&
3567 !search_recovery_portfolio) {
3574 has_cached_mode_ =
false;
3579 if (!helpedPathCertified) {
3581 }
else if (helped_below_endpoints) {
3587 if (!helpedPathCertified) {
3588 std::cout <<
"[ocineb] burst @ outer hook: Helped rejected "
3589 <<
"(force-only lacks path certificate: alignment="
3591 <<
", tol=" << cfg_.alignment_cos_tol
3593 <<
"), restored CI position" << std::endl;
3594 }
else if (helped_below_endpoints) {
3595 std::cout <<
"[ocineb] burst @ outer hook: Helped rejected "
3597 << detail::forceOnlyHelpedBelowEndpointDiagnostic(
3601 <<
"), restored CI position" << std::endl;
3604 <<
"[ocineb] burst @ outer hook: Helped rejected "
3605 <<
"(unaligned min-mode descended below seed CI energy: "
3606 << dimerFinalEnergy <<
" < " << savedCiEnergy
3608 <<
"), restored CI position" << std::endl;
3611 }
else if (
dimer.getConverged() && helped_ran_away) {
3619 has_cached_mode_ =
false;
3625 std::cout <<
"[ocineb] burst @ outer hook: Helped rejected "
3626 <<
"(EMD displacement " << helped_emd_disp <<
" > cap "
3628 <<
", angle_certified=" << (dimerAngleCertified ? 1 : 0)
3630 <<
"), restored CI position" << std::endl;
3632 }
else if (!found_saddle_mode) {
3638 has_cached_mode_ =
false;
3642 detail::isMmfRecoveryPortfolioExhausted(
3647 std::cout <<
"[ocineb] burst @ outer hook: PositiveCurvature "
3648 <<
"(no negative mode along trajectory, min curv = "
3649 << best_curv <<
"), restored CI position" << std::endl;
3656 std::vector<detail::MmfRecoveryCandidate> recovery_candidates;
3657 recovery_candidates.reserve(history.size());
3659 std::vector<Eigen::VectorXd> true_phase_grad(history.size());
3660 std::vector<double> true_phase_energy(
3661 static_cast<std::size_t
>(history.size()),
3662 std::numeric_limits<double>::quiet_NaN());
3663 int reused_oracle_phases = 0;
3664 int oracle_phase_queries = 0;
3667 for (
int h = 0; h < static_cast<int>(history.size()); ++h) {
3668 const auto& phase = history[h];
3672 const Eigen::VectorXd phase_pos = coordToFlat(phase.
position);
3673 if (phase_pos.size() != savedPositions.size() ||
3674 phase_pos.size() == 0) {
3677 const double phase_disp =
3678 emdDistance(phase_pos, savedPositions, session.
atoms_config);
3682 const detail::MmfRecoveryPhaseEvidence recorded_evidence =
3683 detail::recordedMmfRecoveryPhaseEvidence(phase, e0,
3685 double true_E = recorded_evidence.energy;
3686 Eigen::VectorXd true_G = recorded_evidence.gradient;
3687 bool true_pes_evidence_certified =
3688 recorded_evidence.oracle_certified;
3689 if (recorded_evidence.oracle_certified) {
3690 ++reused_oracle_phases;
3693 const auto true_eval =
3694 detail::evaluateOieOraclePosition(phase_pos, oracle);
3695 true_E = true_eval.first;
3696 true_G = true_eval.second;
3697 true_pes_evidence_certified =
true;
3699 ++oracle_phase_queries;
3705 true_E = phase.
energy + e0;
3706 true_G = coordToFlat(phase.
gradient);
3709 if (!std::isfinite(true_E) || true_G.size() != phase_pos.size()) {
3710 true_E = phase.
energy + e0;
3711 true_G = coordToFlat(phase.
gradient);
3712 true_pes_evidence_certified =
false;
3714 true_phase_energy[
static_cast<std::size_t
>(h)] = true_E;
3715 true_phase_grad[
static_cast<std::size_t
>(h)] = true_G;
3716 const double phase_neb_force = [&]() {
3717 detail::ScopedImageState restore(path, ci_image_idx);
3723 return path.
nebForce(ci_image_idx).norm();
3725 const double phase_raw_force =
3727 : std::numeric_limits<double>::infinity();
3732 double phase_recovery_force =
3733 std::numeric_limits<double>::infinity();
3734 if (std::isfinite(phase_neb_force) && phase_neb_force > 0.0) {
3735 phase_recovery_force = phase_neb_force;
3737 if (std::isfinite(phase_raw_force) && phase_raw_force > 0.0) {
3738 phase_recovery_force =
3739 std::isfinite(phase_recovery_force)
3740 ? std::min(phase_recovery_force, phase_raw_force)
3743 const bool phase_saddle_certified =
3744 true_pes_evidence_certified &&
3745 detail::isTruePesRecoverySaddleCertified(
3746 true_E, phase_raw_force, forceTolerance(), reactant_E,
3748 const bool phase_path_mode_certified =
3749 detail::forceOnlyHelpedPathCertified(
3751 cfg_.alignment_cos_tol);
3752 recovery_candidates.push_back(
3755 phase_recovery_force,
3758 phase_saddle_certified,
3759 phase_path_mode_certified,
3763 const double recovery_baseline =
3764 detail::mmfRecoveryForceBaseline(pre_neb_force, pre_force);
3765 const double recovery_reference_energy =
3766 savedCiEnergyValid ? savedCiEnergy
3767 : std::numeric_limits<double>::quiet_NaN();
3768 detail::MmfRecoverySelectionStats recovery_selection_stats;
3769 int recovery_phase = detail::chooseMmfRecoveryPhase(
3770 recovery_candidates, recovery_baseline, recovery_disp_cap,
3771 current_threshold_, cfg_.keep_force_improving_burst,
3772 recovery_reference_energy, reactant_E, product_E,
3773 &recovery_selection_stats,
3775 if (detail::shouldAcquireMmfMinModeProbe(
3776 true, recovery_phase,
3777 recovery_selection_stats.accepted_candidates,
3778 recovery_selection_stats.negative_curvature_candidates,
3779 recovery_selection_stats.force_improving_candidates,
3780 recovery_selection_stats.out_of_trust_candidates)) {
3781 const Eigen::VectorXd& probe_mode =
3782 (finalMode.size() == savedPositions.size() &&
3783 finalMode.allFinite())
3786 const double probe_step = detail::mmfMinModeProbeStep(
3787 recovery_disp_cap, seed_displacement,
3788 cfg_.max_burst_displacement);
3789 const Eigen::VectorXd probe_pos = detail::minModeProbePosition(
3790 savedPositions, probe_mode, probe_step);
3791 if (probe_pos.size() == savedPositions.size() &&
3792 !detail::hasPosition(session.
training_obs, probe_pos)) {
3794 const auto true_eval =
3795 detail::evaluateOieOraclePosition(probe_pos, oracle);
3796 const double probe_E = true_eval.first;
3797 const Eigen::VectorXd& probe_G = true_eval.second;
3799 if (std::isfinite(probe_E) &&
3800 probe_G.size() == probe_pos.size() &&
3801 probe_G.allFinite()) {
3803 ci_image_idx, probe_pos, probe_E, probe_G);
3805 const double probe_disp = emdDistance(
3807 const double probe_neb_force = [&]() {
3808 detail::ScopedImageState restore(path,
3815 return path.
nebForce(ci_image_idx).norm();
3817 const double probe_raw =
3820 : std::numeric_limits<double>::infinity();
3821 double probe_recovery_force =
3822 std::numeric_limits<double>::infinity();
3823 if (std::isfinite(probe_neb_force) &&
3824 probe_neb_force > 0.0) {
3825 probe_recovery_force = probe_neb_force;
3827 if (std::isfinite(probe_raw) && probe_raw > 0.0) {
3828 probe_recovery_force =
3829 std::isfinite(probe_recovery_force)
3830 ? std::min(probe_recovery_force, probe_raw)
3833 const bool probe_saddle_certified =
3834 detail::isTruePesRecoverySaddleCertified(
3835 probe_E, probe_raw, forceTolerance(),
3836 reactant_E, product_E);
3837 const bool accept_probe =
3838 detail::shouldAcceptMmfRecovery(
3839 recovery_baseline, probe_recovery_force,
3840 probe_disp, recovery_disp_cap,
3842 cfg_.keep_force_improving_burst,
3843 recovery_reference_energy, probe_E, reactant_E,
3844 product_E, probe_saddle_certified,
3849 std::cout <<
"[ocineb] burst @ outer hook: "
3850 "min-mode true-PES probe "
3851 <<
"step=" << probe_step
3852 <<
" disp=" << probe_disp
3853 <<
" force=" << probe_recovery_force
3854 <<
" accepted=" << (accept_probe ? 1 : 0)
3866 probe_recovery_force < recovery_baseline;
3868 probe_saddle_certified;
3880 has_cached_mode_ =
false;
3886 std::cout <<
"[ocineb] burst @ outer hook: min-mode probe "
3887 "advanced CI (force "
3888 << pre_force <<
" -> " << result.
newForce <<
")\n";
3890 }
else if (recovery_phase < 0) {
3891 if (recovery_selection_stats.out_of_trust_candidates > 0 &&
3892 recovery_selection_stats.accepted_candidates == 0) {
3896 mmf_wait_for_true_sample_ =
true;
3900 detail::isMmfRecoveryPortfolioExhausted(
3901 true, recovery_phase,
3902 recovery_selection_stats.accepted_candidates);
3911 <<
"[ocineb] burst @ outer hook: recovery rejected "
3912 <<
"(min curv = " << best_curv <<
", candidates="
3913 << recovery_selection_stats.negative_curvature_candidates
3915 << recovery_selection_stats.invalid_candidates
3916 <<
", force_improving="
3917 << recovery_selection_stats.force_improving_candidates
3918 <<
", out_of_trust="
3919 << recovery_selection_stats.out_of_trust_candidates
3920 <<
", directional_out_of_trust="
3921 << recovery_selection_stats
3922 .directional_out_of_trust_candidates
3923 <<
", threshold_rejected="
3924 << recovery_selection_stats.threshold_rejected_candidates
3925 <<
", no_trust_threshold="
3926 << recovery_selection_stats
3927 .no_trust_threshold_rejected_candidates
3928 <<
", certified_lower_energy="
3929 << recovery_selection_stats
3930 .certified_lower_energy_candidates
3931 <<
", uncertified_lower_energy="
3932 << recovery_selection_stats
3933 .uncertified_lower_energy_candidates
3934 <<
", uncertified_energy_descent="
3935 << recovery_selection_stats
3936 .uncertified_energy_descent_candidates
3938 << recovery_selection_stats.accepted_candidates
3939 <<
", oracle_phase_queries=" << oracle_phase_queries
3940 <<
", reused_oracle_phases=" << reused_oracle_phases
3942 <<
"CI position" << std::endl;
3946 history[recovery_phase];
3947 const Eigen::VectorXd best_pos = coordToFlat(best.
position);
3950 Eigen::VectorXd best_grad =
3951 (recovery_phase >= 0 &&
3952 recovery_phase < static_cast<int>(true_phase_grad.size()) &&
3953 true_phase_grad[
static_cast<std::size_t
>(recovery_phase)]
3954 .size() == best_pos.size())
3955 ? true_phase_grad[
static_cast<std::size_t
>(recovery_phase)]
3957 const double best_true_E =
3958 (recovery_phase >= 0 &&
3959 recovery_phase < static_cast<int>(true_phase_energy.size()) &&
3960 std::isfinite(true_phase_energy[
static_cast<std::size_t
>(
3962 ? true_phase_energy[
static_cast<std::size_t
>(
3965 const auto selected_candidate = std::find_if(
3966 recovery_candidates.begin(), recovery_candidates.end(),
3967 [recovery_phase](
const detail::MmfRecoveryCandidate& c) {
3968 return c.phase == recovery_phase;
3970 const double recovery_neb_force =
3971 selected_candidate != recovery_candidates.end()
3972 ? selected_candidate->recovery_force
3973 : std::numeric_limits<double>::infinity();
3974 const double recovery_saddle_energy =
3975 selected_candidate != recovery_candidates.end()
3976 ? selected_candidate->saddle_energy
3977 : std::numeric_limits<double>::infinity();
3978 const double recovery_displacement =
3979 selected_candidate != recovery_candidates.end()
3980 ? selected_candidate->displacement
3981 : std::numeric_limits<double>::infinity();
3982 const double best_force =
3983 (best_grad.size() > 0)
3985 : std::numeric_limits<double>::infinity();
3986 const bool reject_uncertified_handback =
3987 !(selected_candidate != recovery_candidates.end() &&
3988 selected_candidate->path_mode_certified &&
3989 selected_candidate->measured_descent_certified) &&
3990 detail::shouldRejectUncertifiedMmfRecoveryHandback(
3991 best_force, recovery_displacement, recovery_disp_cap,
3993 if (reject_uncertified_handback) {
3998 std::cout <<
"[ocineb] burst @ outer hook: recovery "
3999 <<
"rejected (EMD displacement "
4000 << recovery_displacement <<
" > cap "
4001 << recovery_disp_cap <<
", raw force "
4002 << best_force <<
" within convergence band), "
4003 <<
"restored CI position" << std::endl;
4027 const bool recovery_saddle_certified =
4028 selected_candidate != recovery_candidates.end() &&
4029 selected_candidate->saddle_certified;
4033 recovery_saddle_certified &&
4034 detail::isLowerValidSaddleEnergy(recovery_reference_energy,
4035 recovery_saddle_energy,
4036 reactant_E, product_E);
4039 <<
"[ocineb] burst @ outer hook: "
4040 << detail::trustedRecoveryAdvanceDiagnostic(
4041 dimer.getRelaxationTerminationReason(),
4042 recovery_phase, history.size(), best.
curvature,
4043 recovery_baseline, recovery_neb_force, pre_force,
4044 best_force, recovery_reference_energy,
4045 recovery_saddle_energy, reactant_E, product_E,
4046 recovery_saddle_certified)
4059 if (harvest_helped_trajectory) {
4060 for (std::size_t si = 0; si < staged_dimer_observations.size(); ++si) {
4062 staged_dimer_observations[si];
4063 const bool is_final =
4064 staged.
positions.size() == dimer_final_pos.size() &&
4065 (staged.
positions.array() == dimer_final_pos.array()).all();
4066 if (!is_final && !detail::shouldCommitMmfObservation(
4076 }
else if (detail::shouldHarvestAcceptedRecoveryObservation(
4078 const auto& accepted = path.
image(ci_image_idx);
4079 detail::appendAcceptedMmfRecoveryObservation(session, ci_image_idx,
4083 if (!detail::shouldHarvestRejectedMmfObservation(
4085 staged.positions, savedPositions, session.
atoms_config,
4086 recovery_disp_cap)) {
4090 staged.energy, staged.gradient,
4101 std::cout <<
"[ocineb] burst: status="
4102 <<
static_cast<int>(result.
status) <<
" force " << pre_force
4105 <<
" threshold=" << current_threshold_
4111 const double post_neb_force = path.
nebForce(ci_image_idx).norm();
4112 const double threshold_pre_force =
4113 detail::mmfThresholdForce(pre_neb_force, pre_force);
4114 const double threshold_post_force =
4115 detail::mmfThresholdForce(post_neb_force, result.
newForce);
4119 const bool force_improved = std::isfinite(threshold_post_force) &&
4120 std::isfinite(threshold_pre_force) &&
4121 threshold_post_force < threshold_pre_force &&
4123 const bool adaptive_threshold_seeded =
4124 detail::isMmfAdaptiveThresholdSeeded(current_threshold_);
4125 recordBurstOutcome(path, ci_image_idx, neb_config, session, savedPositions,
4126 adaptive_threshold_seeded, force_improved,
4127 threshold_pre_force, threshold_post_force, result);
4129 mmf_attempted_ = detail::mmfAttemptConsumedAfterRecovery(
4139 const bool force_certified = detail::mmfForceCertifiedForConvergence(
4140 result.
newForce, threshold_post_force, forceTolerance());
4141 const bool helped_angle_certified =
4143 const bool helped_path_certified =
4145 detail::forceOnlyHelpedPathCertified(
4146 helped_angle_certified, result.
alignment, cfg_.alignment_cos_tol);
4157 detail::mmfBurstConvergedAfterAcceptance(
4158 result.
status, force_certified, helped_angle_certified,
4176 const std::shared_ptr<OCINEBController>& controller,
NEBOracle& oracle,
4177 const GPNEBConfig& neb_config,
int& total_oracle_calls,
int& bursts_fired,
4178 int& dimer_saddle_image_idx,
4179 const std::shared_ptr<OciMmfHandoffTrapState>& handoff_trap_state,
4182 bool& converged,
bool trap_detected)
4185 caller_hook(path, ci_image_idx, outer_iter, sess, converged,
4188 const double conv_force = path.
nebForce(ci_image_idx).norm();
4193 double band_conv_force = conv_force;
4194 for (
int i = 1; i < path.
numImages() - 1; ++i) {
4195 band_conv_force = std::max(band_conv_force, path.
nebForce(i).norm());
4199 controller->updateStabilityForOuter(
static_cast<long>(ci_image_idx),
4202 const std::size_t ntrain_now =
4204 const auto diagnostics_before_growth = controller->diagnostics();
4205 const bool active_recovery = detail::activeMmfRecoveryOwnsClimbingImage(
4206 diagnostics_before_growth.force_improving_recovery_active,
4207 diagnostics_before_growth.trusted_recovery_active);
4208 const bool exhausted_recovery_applies =
4209 detail::exhaustedRecoveryRejectAppliesToCi(
4210 diagnostics_before_growth.exhausted_recovery_reject_active,
4211 diagnostics_before_growth.mmf_reject_climbing_image, ci_image_idx);
4212 const int active_recovery_owner = detail::activeOieRecoveryOwnerImage(
4213 diagnostics_before_growth.recovery_owner_image, ci_image_idx,
4214 diagnostics_before_growth.force_improving_recovery_active,
4215 diagnostics_before_growth.trusted_recovery_active);
4216 const int recovery_owner = active_recovery_owner > 0 ? active_recovery_owner
4217 : exhausted_recovery_applies ? ci_image_idx
4219 const int candidate_image =
4221 const int recovery_model_image =
4222 recovery_owner > 0 ? recovery_owner : ci_image_idx;
4223 const detail::MmfSurrogateFingerprint mmf_surrogate_now =
4226 detail::MmfPosteriorActionFingerprint mmf_action_now;
4227 mmf_action_now.surrogate = mmf_surrogate_now;
4228 const bool rejected_position_matches =
4229 controller->rejectedMmfSeedPositionMatches(
4231 static_cast<long>(ci_image_idx));
4232 if (diagnostics_before_growth.info_gate !=
4233 detail::MmfInformationGate::Open ||
4234 rejected_position_matches) {
4236 controller->previewMmfAction(sess, path, ci_image_idx, neb_config);
4238 const bool rejected_seed_replay = controller->rejectedMmfSeedReplay(
4241 const bool exhausted_owner_model_growth_requested =
4242 exhausted_recovery_applies && candidate_image == recovery_owner;
4243 const bool recovery_model_growth_requested =
4244 detail::shouldRequestOieRecoveryModelGrowth(
4245 diagnostics_before_growth.force_improving_recovery_active,
4246 diagnostics_before_growth.trusted_recovery_active,
4247 rejected_seed_replay, diagnostics_before_growth.info_gate) ||
4248 exhausted_owner_model_growth_requested;
4249 const bool recovery_model_growth_ready =
4250 detail::isOieRecoveryOwnerModelGrowthReady(
4251 recovery_model_growth_requested, mmf_surrogate_now,
4252 diagnostics_before_growth.mmf_surrogate_at_last_reject);
4258 const double magn_sigma2 =
4260 const double posterior_threshold =
4261 detail::effectivePosteriorVarianceThreshold(
4262 neb_config, std::optional<double>{magn_sigma2});
4263 const bool band_information_exhausted =
4264 detail::isBandInformationExhaustedForMmf(chain_var, noise_floor,
4265 posterior_threshold,
4267 const bool band_acquisition_quiet =
4268 detail::isOieAcquisitionQuietForMmf(chain_var, posterior_threshold);
4269 const bool ci_is_energy_max =
4271 const bool ci_posterior_confident =
4272 detail::ciPosteriorConfident(path, ci_image_idx, neb_config.
ucb_kappa);
4275 const bool current_saddle_stencil_certificate =
4276 detail::hasCurrentOciSaddleStencilCertificate(sess, path, ci_image_idx);
4277 const bool candidate_posterior_confident =
4278 candidate_image > 0 && detail::ciPosteriorConfident(
4279 path, candidate_image, neb_config.
ucb_kappa);
4280 const bool candidate_chain_certificate =
4281 candidate_image > 0 &&
4284 const bool candidate_saddle_stencil_certificate =
4285 candidate_image > 0 && detail::hasCurrentOciSaddleStencilCertificate(
4286 sess, path, candidate_image);
4287 const bool band_force_converged =
4288 std::isfinite(band_conv_force) &&
4289 band_conv_force < detail::effectiveModelNoiseTolerance(neb_config);
4290 const bool release_exhausted_recovery =
4291 detail::shouldReleaseOieExhaustedRecoveryForCertifiedHandover(
4292 diagnostics_before_growth.exhausted_recovery_reject_active,
4293 diagnostics_before_growth.mmf_reject_climbing_image,
4294 candidate_image, candidate_posterior_confident,
4295 candidate_chain_certificate, candidate_saddle_stencil_certificate);
4296 if (release_exhausted_recovery) {
4297 controller->releaseExhaustedRecoveryForCertifiedHandover();
4298 if (neb_config.
verbose && isRank0()) {
4299 std::cout <<
"[ocineb] exhausted-recovery-handover outer="
4300 << outer_iter <<
" owner="
4301 << diagnostics_before_growth.mmf_reject_climbing_image
4302 <<
" candidate=" << candidate_image
4303 <<
" candidate_confident="
4304 << candidate_posterior_confident
4305 <<
" candidate_chain_cert=" << candidate_chain_certificate
4306 <<
" candidate_stencil_cert="
4307 << candidate_saddle_stencil_certificate << std::endl;
4311 const bool release_recovery_owner =
4312 detail::shouldReleaseOieRecoveryForCertifiedHandover(
4313 active_recovery, recovery_owner, candidate_image,
4314 candidate_posterior_confident, candidate_chain_certificate,
4315 candidate_saddle_stencil_certificate);
4316 if (release_recovery_owner) {
4317 controller->releaseRecoveryOwnerForCertifiedHandover(
4319 static_cast<long>(recovery_owner));
4320 if (neb_config.
verbose && isRank0()) {
4321 std::cout <<
"[ocineb] recovery-handover outer=" << outer_iter
4322 <<
" owner=" << recovery_owner
4323 <<
" candidate=" << candidate_image
4324 <<
" candidate_confident="
4325 << candidate_posterior_confident
4326 <<
" band_force_cert=" << band_force_converged
4327 <<
" candidate_chain_cert=" << candidate_chain_certificate
4328 <<
" candidate_stencil_cert="
4329 << candidate_saddle_stencil_certificate
4330 <<
" mmf_surrogate_owner=" << mmf_surrogate_now.
owner
4331 <<
" mmf_surrogate_revision="
4332 << mmf_surrogate_now.
revision << std::endl;
4336 const bool release_invalidated_owner =
4337 detail::shouldReleaseOieRecoveryForInvalidatedOwner(
4338 active_recovery, recovery_owner, ci_image_idx,
4339 recovery_model_growth_ready, band_force_converged,
4340 current_chain_certificate, current_saddle_stencil_certificate,
4341 ci_posterior_confident, ci_is_energy_max);
4342 if (release_invalidated_owner) {
4343 controller->releaseRecoveryOwnerForCertifiedHandover(
4345 static_cast<long>(recovery_owner));
4346 if (neb_config.
verbose && isRank0()) {
4347 std::cout <<
"[ocineb] recovery-owner-invalidated outer="
4348 << outer_iter <<
" owner=" << recovery_owner
4349 <<
" retry=" << ci_image_idx
4350 <<
" band_force_cert=" << band_force_converged
4351 <<
" owner_chain_cert=" << current_chain_certificate
4352 <<
" owner_stencil_cert="
4353 << current_saddle_stencil_certificate
4354 <<
" owner_confident=" << ci_posterior_confident
4355 <<
" owner_energy_max=" << ci_is_energy_max
4356 <<
" mmf_surrogate_owner=" << mmf_surrogate_now.
owner
4357 <<
" mmf_surrogate_revision="
4358 << mmf_surrogate_now.
revision << std::endl;
4362 const bool retry_matches_recovery_owner =
4363 detail::shouldAdvanceOieRecoveryInformationGate(
4364 active_recovery, recovery_owner, ci_image_idx);
4365 if (!retry_matches_recovery_owner) {
4366 if (neb_config.
verbose && isRank0()) {
4367 std::cout <<
"[ocineb] recovery-owner-wait outer=" << outer_iter
4368 <<
" owner=" << recovery_owner
4369 <<
" retry=" << ci_image_idx
4370 <<
" candidate=" << candidate_image
4371 <<
" candidate_confident="
4372 << candidate_posterior_confident
4373 <<
" candidate_chain_cert=" << candidate_chain_certificate
4374 <<
" candidate_stencil_cert="
4375 << candidate_saddle_stencil_certificate << std::endl;
4379 controller->noteMmfActionChange(std::move(mmf_action_now));
4380 const bool certified_active_recovery_model_growth =
4382 detail::isOieRecoveryModelGrowthCertified(
4383 recovery_owner, ci_image_idx, recovery_model_growth_ready,
4384 current_chain_certificate, current_saddle_stencil_certificate,
4386 const bool certified_exhausted_recovery_model_growth =
4387 exhausted_owner_model_growth_requested &&
4388 detail::isOieExhaustedRecoveryModelGrowthCertified(
4389 recovery_owner, ci_image_idx, recovery_model_growth_ready,
4390 current_chain_certificate, current_saddle_stencil_certificate,
4391 ci_is_energy_max, rejected_seed_replay);
4392 const bool certified_recovery_model_growth =
4393 certified_active_recovery_model_growth ||
4394 certified_exhausted_recovery_model_growth;
4395 const bool transition_focal_handoff =
4396 detail::isOracleTransitionFocalHandoff(
4398 current_chain_certificate, current_saddle_stencil_certificate);
4399 const bool handoff_ci_posterior_confident = ci_posterior_confident ||
4400 transition_focal_handoff ||
4401 certified_recovery_model_growth;
4402 const bool handoff_ci_is_energy_max = ci_is_energy_max ||
4403 transition_focal_handoff ||
4404 certified_recovery_model_growth;
4405 const bool handoff_data_ready = detail::isOciMmfHandoffDataReady(
4406 band_acquisition_quiet, current_saddle_stencil_certificate,
4407 handoff_ci_posterior_confident, handoff_ci_is_energy_max);
4408 if (band_information_exhausted) {
4409 controller->openInformationGateAtNoiseFloor(
4411 static_cast<long>(ci_image_idx));
4418 const bool adaptive_handoff_trap =
4419 handoff_trap_state && handoff_trap_state->requested_current_ci &&
4420 handoff_trap_state->ci_image_idx == ci_image_idx &&
4421 detail::shouldPromoteCurrentCiHandoffMismatchToTrap(
4422 handoff_trap_state->outer_iter, outer_iter,
4423 handoff_trap_state->gp_force, conv_force,
4424 handoff_trap_state->threshold);
4425 const bool effective_trap = trap_detected || adaptive_handoff_trap ||
4426 certified_recovery_model_growth;
4441 const double lease_force = (handoff_data_ready || stagnation_handoff)
4449 const double quiet_track_force =
4450 controller->baselineSet() ? lease_force : band_conv_force;
4451 controller->recordMmfHandoffForce(quiet_track_force, handoff_data_ready);
4452 if (stagnation_handoff && neb_config.
verbose && isRank0()) {
4453 std::cout <<
"[band] stagnation-handoff outer=" << outer_iter
4454 <<
" image=" << ci_image_idx <<
" F=" << lease_force
4457 const bool trigger =
4458 (handoff_data_ready || stagnation_handoff) &&
4459 controller->shouldTrigger(
4460 lease_force,
true,
static_cast<long>(ci_image_idx),
4461 static_cast<long>(path.
numImages() - 2),
4462 handoff_ci_posterior_confident, effective_trap, ntrain_now,
4463 handoff_ci_is_energy_max, band_information_exhausted,
4464 band_acquisition_quiet, rejected_seed_replay,
4465 current_chain_certificate, current_saddle_stencil_certificate,
4466 rejected_position_matches, stagnation_handoff);
4467 if (stagnation_handoff && !trigger) {
4474 if (neb_config.
verbose && isRank0()) {
4475 const auto diagnostics = controller->diagnostics();
4476 const bool exhausted_recovery_gate =
4477 detail::exhaustedRecoveryRejectAppliesToCi(
4478 diagnostics.exhausted_recovery_reject_active,
4479 diagnostics.mmf_reject_climbing_image,
4480 static_cast<long>(ci_image_idx));
4482 <<
"[ocineb] gate-skip outer=" << outer_iter
4483 <<
" ci=" << ci_image_idx <<
" force=" << conv_force
4484 <<
" band_force=" << band_conv_force
4485 <<
" threshold=" << diagnostics.current_threshold
4486 <<
" baseline=" << diagnostics.baseline_force
4487 <<
" pure_lock=" << diagnostics.pure_reject_lock
4488 <<
" soft_block=" << diagnostics.soft_quiet_blocked_after_reject
4489 <<
" quiet_stalled=" << diagnostics.oie_quiet_handoff_stalled
4490 <<
" force_recovery="
4491 << diagnostics.force_improving_recovery_active
4492 <<
" trusted_recovery=" << diagnostics.trusted_recovery_active
4493 <<
" recovery_owner=" << diagnostics.recovery_owner_image
4494 <<
" exhausted_recovery_reject="
4495 << diagnostics.exhausted_recovery_reject_active
4496 <<
" exhausted_recovery_gate=" << exhausted_recovery_gate
4497 <<
" trusted_retry_force="
4498 << diagnostics.trusted_retry_reject_force
4499 <<
" uncert_hook=" << diagnostics.uncertified_hook_reject_active
4501 << mmfInformationGateName(diagnostics.info_gate)
4502 <<
" mmf_surrogate=" << mmfSurrogateOwnerName(mmf_surrogate_now)
4503 <<
" reject_ci=" << diagnostics.mmf_reject_climbing_image
4504 <<
" rejected_seed=" << rejected_seed_replay
4505 <<
" rejected_position=" << rejected_position_matches
4506 <<
" current_cert=" << current_chain_certificate
4507 <<
" local_stencil=" << current_saddle_stencil_certificate
4508 <<
" handoff_ready=" << handoff_data_ready
4509 <<
" quiet=" << band_acquisition_quiet
4510 <<
" band_quiet=" << band_acquisition_quiet
4511 <<
" exhausted=" << band_information_exhausted
4512 <<
" confident=" << ci_posterior_confident
4513 <<
" transition_focal=" << transition_focal_handoff
4514 <<
" recovery_growth_requested="
4515 << recovery_model_growth_requested
4516 <<
" recovery_growth_ready=" << recovery_model_growth_ready
4517 <<
" recovery_growth_certified="
4518 << certified_recovery_model_growth <<
" trap=" << effective_trap
4519 <<
" adaptive_trap=" << adaptive_handoff_trap
4520 <<
" gp_handoff_force="
4521 << (handoff_trap_state
4522 ? handoff_trap_state->gp_force
4523 : std::numeric_limits<double>::infinity())
4524 <<
" gp_handoff_threshold="
4525 << (handoff_trap_state
4526 ? handoff_trap_state->threshold
4527 : std::numeric_limits<double>::quiet_NaN())
4528 <<
" energy_max=" << ci_is_energy_max
4529 <<
" ntrain=" << ntrain_now
4530 <<
" mmf_surrogate_owner=" << mmf_surrogate_now.
owner
4531 <<
" mmf_surrogate_revision=" << mmf_surrogate_now.
revision
4532 <<
" reject_mmf_surrogate_owner="
4533 << diagnostics.mmf_surrogate_at_last_reject.owner
4534 <<
" reject_mmf_surrogate_revision="
4535 << diagnostics.mmf_surrogate_at_last_reject.revision
4536 <<
" chain_var=" << chain_var <<
" noise_floor=" << noise_floor
4537 <<
" posterior_threshold=" << posterior_threshold << std::endl;
4541 if (neb_config.
verbose && isRank0()) {
4542 const auto diagnostics = controller->diagnostics();
4543 const bool exhausted_recovery_gate =
4544 detail::exhaustedRecoveryRejectAppliesToCi(
4545 diagnostics.exhausted_recovery_reject_active,
4546 diagnostics.mmf_reject_climbing_image,
4547 static_cast<long>(ci_image_idx));
4549 <<
"[ocineb] gate-fire outer=" << outer_iter
4550 <<
" ci=" << ci_image_idx <<
" force=" << conv_force
4551 <<
" band_force=" << band_conv_force
4552 <<
" threshold=" << diagnostics.current_threshold
4553 <<
" baseline=" << diagnostics.baseline_force
4554 <<
" pure_lock=" << diagnostics.pure_reject_lock
4555 <<
" soft_block=" << diagnostics.soft_quiet_blocked_after_reject
4556 <<
" quiet_stalled=" << diagnostics.oie_quiet_handoff_stalled
4557 <<
" force_recovery=" << diagnostics.force_improving_recovery_active
4558 <<
" trusted_recovery=" << diagnostics.trusted_recovery_active
4559 <<
" recovery_owner=" << diagnostics.recovery_owner_image
4560 <<
" exhausted_recovery_reject="
4561 << diagnostics.exhausted_recovery_reject_active
4562 <<
" exhausted_recovery_gate=" << exhausted_recovery_gate
4563 <<
" trusted_retry_force=" << diagnostics.trusted_retry_reject_force
4564 <<
" uncert_hook=" << diagnostics.uncertified_hook_reject_active
4565 <<
" info_gate=" << mmfInformationGateName(diagnostics.info_gate)
4566 <<
" mmf_surrogate=" << mmfSurrogateOwnerName(mmf_surrogate_now)
4567 <<
" reject_ci=" << diagnostics.mmf_reject_climbing_image
4568 <<
" rejected_seed=" << rejected_seed_replay
4569 <<
" rejected_position=" << rejected_position_matches
4570 <<
" current_cert=" << current_chain_certificate
4571 <<
" local_stencil=" << current_saddle_stencil_certificate
4572 <<
" handoff_ready=" << handoff_data_ready
4573 <<
" quiet=" << band_acquisition_quiet
4574 <<
" band_quiet=" << band_acquisition_quiet
4575 <<
" exhausted=" << band_information_exhausted
4576 <<
" confident=" << ci_posterior_confident
4577 <<
" transition_focal=" << transition_focal_handoff
4578 <<
" recovery_growth_requested=" << recovery_model_growth_requested
4579 <<
" recovery_growth_ready=" << recovery_model_growth_ready
4580 <<
" recovery_growth_certified=" << certified_recovery_model_growth
4581 <<
" trap=" << effective_trap
4582 <<
" adaptive_trap=" << adaptive_handoff_trap
4583 <<
" gp_handoff_force="
4584 << (handoff_trap_state ? handoff_trap_state->gp_force
4585 : std::numeric_limits<double>::infinity())
4586 <<
" gp_handoff_threshold="
4587 << (handoff_trap_state ? handoff_trap_state->threshold
4588 : std::numeric_limits<double>::quiet_NaN())
4589 <<
" energy_max=" << ci_is_energy_max <<
" ntrain=" << ntrain_now
4590 <<
" mmf_surrogate_owner=" << mmf_surrogate_now.
owner
4591 <<
" mmf_surrogate_revision=" << mmf_surrogate_now.
revision
4592 <<
" reject_mmf_surrogate_owner="
4593 << diagnostics.mmf_surrogate_at_last_reject.owner
4594 <<
" reject_mmf_surrogate_revision="
4595 << diagnostics.mmf_surrogate_at_last_reject.revision
4596 <<
" chain_var=" << chain_var <<
" noise_floor=" << noise_floor
4597 <<
" posterior_threshold=" << posterior_threshold << std::endl;
4600 if (handoff_trap_state) {
4601 handoff_trap_state->requested_current_ci =
false;
4603 detail::OracleNoiseUpdatePause noise_pause(
4606 auto burst = controller->run(path, ci_image_idx, oracle, neb_config, sess,
4609 total_oracle_calls += burst.oracle_calls;
4611 (void)detail::publishOracleSessionPathCheckpoint(neb_config, path,
4613 const auto observe_oracle_outcome =
4614 [&neb_config, ci_image_idx](
const MMFRunResult& current) {
4621 std::isfinite(current.previousForce) &&
4622 std::isfinite(current.newForce);
4624 current.certified_lower_saddle_advanced;
4625 outcome.
converged = current.convergedAfterMMF;
4628 observe_oracle_outcome(burst);
4633 const double rerelease_force_tolerance =
4634 detail::effectiveModelNoiseTolerance(neb_config);
4635 burst = detail::continueImmediateOciRecovery(
4636 burst, rerelease_force_tolerance,
4637 [controller] {
return controller->diagnostics().current_threshold; },
4638 [&sess, &path, ci_image_idx] {
4639 return detail::hasCurrentOciSaddleStencilCertificate(sess, path,
4644 if (neb_config.
verbose && isRank0()) {
4645 std::cout <<
"[ocineb] immediate recovery re-lease outer="
4646 << outer_iter <<
" ci=" << ci_image_idx
4648 <<
" thr=" << threshold
4649 <<
" tol=" << rerelease_force_tolerance
4651 <<
" force_progress="
4653 <<
" lower_saddle_progress="
4658 auto next = controller->run(path, ci_image_idx, oracle, neb_config,
4659 sess, effective_trap);
4660 total_oracle_calls += next.oracle_calls;
4662 (void)detail::publishOracleSessionPathCheckpoint(neb_config, path,
4664 observe_oracle_outcome(next);
4667 if (burst.convergedAfterMMF) {
4668 dimer_saddle_image_idx = ci_image_idx;
4674 const Eigen::VectorXd& final_state,
int n_images,
4681 if (!detail::shouldInstallOciMmfHook(neb_config, oci_config_in)) {
4687 gpNEB(oracle, initial, final_state, n_images, tagged, &session);
4690 neb_config, &session);
4697 if (image >= 0 && image < result.neb_result.path->numImages()) {
4717 auto caller_force_tolerance_provider =
4720 [&neb_config, caller_force_tolerance_provider =
4721 std::move(caller_force_tolerance_provider)]() {
4722 double tol = detail::effectiveModelNoiseTolerance(neb_config);
4723 if (caller_force_tolerance_provider) {
4724 const double caller_tol = caller_force_tolerance_provider();
4725 if (std::isfinite(caller_tol) && caller_tol > tol) {
4732 auto controller = std::make_shared<OCINEBController>(oci_config);
4733 auto handoff_trap_state = std::make_shared<OciMmfHandoffTrapState>();
4734 int total_oracle_calls = 0;
4735 int bursts_fired = 0;
4736 int dimer_saddle_image_idx = -1;
4742 [controller, handoff_trap_state, kappa = neb_config.
ucb_kappa](
4743 const NEBPath& path,
int ci_image_idx,
int outer_iter,
4745 const bool ci_is_energy_max =
4746 path.highestEnergyImageIndex() == ci_image_idx;
4747 const bool wants_current_ci = controller->wantsCurrentCiOracle(
4748 ci_force,
true,
static_cast<long>(ci_image_idx),
4749 static_cast<long>(path.numImages() - 2), outer_iter,
4750 detail::ciPosteriorConfident(path, ci_image_idx, kappa),
4751 false, 0, ci_is_energy_max);
4752 if (detail::shouldRefreshCurrentCiHandoffPrediction(
4753 handoff_trap_state->requested_current_ci,
4754 handoff_trap_state->ci_image_idx, wants_current_ci,
4756 handoff_trap_state->outer_iter = outer_iter;
4757 handoff_trap_state->ci_image_idx = ci_image_idx;
4758 handoff_trap_state->gp_force = ci_force;
4759 handoff_trap_state->threshold = controller->threshold();
4760 handoff_trap_state->requested_current_ci = wants_current_ci;
4762 return wants_current_ci;
4765 [controller, kappa = neb_config.
ucb_kappa,
4768 const NEBPath& path,
int ci_image_idx,
int outer_iter,
4769 double ci_force,
double max_chain_energy_variance,
4770 double posterior_variance_threshold,
bool current_chain_certificate,
4771 bool planned_current_chain_or_ci,
4775 if (!(ci_image_idx > 0 && ci_image_idx < path.numImages() - 1)) {
4778 const bool band_information_exhausted =
4780 detail::isBandInformationExhaustedForMmf(
4781 max_chain_energy_variance, sess->gp.getSigma2(),
4782 posterior_variance_threshold, inner_unc_relative);
4783 if (!controller->shouldPrepareMmfHandoff(
4784 false, band_information_exhausted,
4785 current_chain_certificate)) {
4788 const auto diagnostics = controller->diagnostics();
4789 const detail::MmfSurrogateFingerprint surrogate =
4790 sess !=
nullptr ? sess->mmfSurrogateFingerprint(
4791 ci_image_idx, dimer_use_global_gp)
4793 detail::MmfPosteriorActionFingerprint action;
4794 action.surrogate = surrogate;
4795 const bool rejected_seed_replay = controller->rejectedMmfSeedReplay(
4796 path.image(ci_image_idx).positions, action,
4797 static_cast<long>(ci_image_idx),
4798 sess !=
nullptr ? &sess->atoms_config :
nullptr);
4799 const bool trusted_retry_progress_pending =
4800 diagnostics.trusted_recovery_active &&
4801 std::isfinite(diagnostics.trusted_retry_reject_force) &&
4802 diagnostics.trusted_retry_reject_force > 0.0;
4803 const bool band_acquisition_quiet =
4804 detail::isOieAcquisitionQuietForMmf(
4805 max_chain_energy_variance, posterior_variance_threshold);
4806 const bool current_saddle_stencil_certificate =
4808 detail::hasCurrentOciSaddleStencilCertificate(*sess, path,
4810 const bool ci_posterior_confident =
4811 detail::ciPosteriorConfident(path, ci_image_idx, kappa);
4812 const bool ci_is_energy_maximum =
4813 path.highestEnergyImageIndex() == ci_image_idx;
4814 detail::OieInnerHandoffPrecheck state;
4815 state.handoff_data_ready = detail::isOciMmfHandoffDataReady(
4816 band_acquisition_quiet, current_saddle_stencil_certificate,
4817 ci_posterior_confident, ci_is_energy_maximum);
4818 state.current_chain_certificate = current_chain_certificate;
4819 state.current_saddle_stencil_certificate =
4820 current_saddle_stencil_certificate;
4821 state.soft_quiet_blocked_after_reject =
4822 diagnostics.soft_quiet_blocked_after_reject;
4823 state.trusted_recovery_active = diagnostics.trusted_recovery_active;
4824 state.trusted_retry_progress_pending =
4825 trusted_retry_progress_pending;
4826 state.oie_quiet_handoff_stalled =
4827 diagnostics.oie_quiet_handoff_stalled;
4828 state.rejected_seed_replay = rejected_seed_replay;
4829 state.planned_current_chain_or_ci = planned_current_chain_or_ci;
4830 state.ci_force = ci_force;
4831 state.handoff_force_threshold = diagnostics.current_threshold;
4832 return detail::shouldBypassOieInnerForHandoff(
4838 caller_oie_fixed_image,
4839 caller_oie_fixed_image_lease](
4843 const auto diagnostics_before_stability = controller->diagnostics();
4844 const int owner_before_stability = detail::activeOieRecoveryOwnerImage(
4845 diagnostics_before_stability.recovery_owner_image, ci_image_idx,
4846 diagnostics_before_stability.force_improving_recovery_active,
4847 diagnostics_before_stability.trusted_recovery_active);
4848 controller->updateStabilityForOuter(
4849 static_cast<long>(owner_before_stability > 0
4850 ? owner_before_stability
4853 const auto diagnostics = controller->diagnostics();
4854 const int recovery_owner = detail::activeOieRecoveryOwnerImage(
4855 diagnostics.recovery_owner_image, ci_image_idx,
4856 diagnostics.force_improving_recovery_active,
4857 diagnostics.trusted_recovery_active);
4858 const bool rejected_recovery_seed =
4859 diagnostics.trusted_recovery_active &&
4860 diagnostics.mmf_reject_climbing_image == recovery_owner;
4862 detail::makeOieRecoveryFixedImageLease(
4863 recovery_owner, diagnostics.force_improving_recovery_active,
4864 diagnostics.trusted_recovery_active, rejected_recovery_seed,
4865 diagnostics.info_gate,
4866 diagnostics.pure_reject_lock ||
4867 diagnostics.soft_quiet_blocked_after_reject);
4869 return recovery_lease;
4872 detail::makeOieExhaustedRecoveryEvidenceLease(
4873 ci_image_idx, diagnostics.exhausted_recovery_reject_active,
4874 diagnostics.mmf_reject_climbing_image,
4875 path.highestEnergyImageIndexPreferring(ci_image_idx));
4877 return exhausted_recovery_lease;
4879 if (caller_oie_fixed_image_lease) {
4880 return caller_oie_fixed_image_lease(path, ci_image_idx, outer_iter);
4883 if (caller_oie_fixed_image) {
4885 caller_oie_fixed_image(path, ci_image_idx, outer_iter);
4887 return caller_lease;
4891 [controller, caller_hook_reject, &neb_config](
4892 const NEBPath& path,
int ci_image_idx,
int outer_iter,
4894 if (caller_hook_reject) {
4895 caller_hook_reject(path, ci_image_idx, outer_iter, sess);
4897 if (!(ci_image_idx > 0 && ci_image_idx < path.numImages() - 1)) {
4900 const double ci_force = path.nebForce(ci_image_idx).norm();
4901 detail::MmfPosteriorActionFingerprint action =
4902 controller->previewMmfAction(sess, path, ci_image_idx,
4904 controller->recordUncertifiedMmfHookReject(
4905 ci_force, path.image(ci_image_idx).positions, std::move(action),
4906 static_cast<long>(ci_image_idx));
4913 [controller, &oracle, &neb_config, &total_oracle_calls, &bursts_fired,
4914 &dimer_saddle_image_idx, handoff_trap_state, caller_hook](
4915 NEBPath& path,
int ci_image_idx,
int outer_iter,
4918 total_oracle_calls, bursts_fired,
4919 dimer_saddle_image_idx, handoff_trap_state,
4920 caller_hook, path, ci_image_idx, outer_iter,
4921 sess, converged, trap_detected);
4925 neb_cfg_with_hook, &session);
4926 const bool dimer_summary_applied = detail::applyDimerSaddleSummary(
4928 (void)dimer_summary_applied;
4939 if (image >= 0 && image < result.neb_result.path->numImages()) {
4950 const Eigen::VectorXd& x_seed,
double e_seed,
const Eigen::VectorXd& g_seed,
4951 const Eigen::VectorXd& mode_seed,
double energy_ceiling)
4954 if (x_seed.size() == 0 || g_seed.size() != x_seed.size() ||
4955 mode_seed.size() != x_seed.size() || !std::isfinite(e_seed))
4967 probe.
R = flatToCoord1xD(x_seed);
4969 double resid = std::numeric_limits<double>::quiet_NaN();
4970 double e_gp = std::numeric_limits<double>::quiet_NaN();
4971 if (probe.
G.rows() > 0 && probe.
G.cols() == x_seed.size()) {
4972 Eigen::VectorXd g_gp(x_seed.size());
4973 for (Eigen::Index j = 0; j < x_seed.size(); ++j)
4974 g_gp(j) = probe.
G(0, j);
4975 resid = (g_gp - g_seed).norm();
4977 if (probe.
E.size() > 0) e_gp = probe.
E(0, 0);
4980 double batch_resid = std::numeric_limits<double>::quiet_NaN();
4983 batch.
R.resize(2, x_seed.size());
4984 batch.
R.row(0) = x_seed.transpose();
4985 Eigen::VectorXd shifted = x_seed;
4986 Eigen::VectorXd dir = mode_seed;
4987 if (dir.norm() > 0.0) shifted += 0.01 * dir.normalized();
4988 batch.
R.row(1) = shifted.transpose();
4990 if (batch.
G.rows() > 1 && batch.
G.cols() == x_seed.size()) {
4991 Eigen::VectorXd g0(x_seed.size());
4992 for (Eigen::Index j = 0; j < x_seed.size(); ++j)
4993 g0(j) = batch.
G(0, j);
4994 batch_resid = (g0 - g_seed).norm();
4998 vprobe.
R = flatToCoord1xD(x_seed);
4999 vprobe.
E.resize(1, 1);
5000 vprobe.
G.resize(1, x_seed.size());
5002 std::cout <<
"[ocineb] index escape seed: rows="
5004 <<
" gp_force_residual=" << resid
5005 <<
" batch_row0_force_residual=" << batch_resid
5006 <<
" gp_energy_error=" << (e_gp - e_seed)
5007 <<
" energy_variance="
5008 << (vprobe.
E.size() > 0
5010 : std::numeric_limits<double>::quiet_NaN())
5013 <<
" ceiling=" << energy_ceiling << std::endl;
5018 middle_point.
R = flatToCoord1xD(x_seed);
5019 middle_point.
E.resize(1, 1);
5020 middle_point.
E(0, 0) = e_seed;
5021 middle_point.
G = flatToCoord1xD(g_seed);
5024 const bool use_analytic_hssvd =
5025 detail::shouldUseHssvdAnalyticDimerCurvature(
5028 neb_config, oci_config, tmp, use_analytic_hssvd);
5042 dimer.setProjectRigidModesForConvergence(
true);
5044 dimer.setForceStopCertificateStep(0.0);
5045 dimer.attachExternalGP(&model.
gp());
5047 Eigen::VectorXd orient = mode_seed;
5048 if (orient.norm() > 0.0) orient.normalize();
5049 dimer.initialize(parameters, init_observations, middle_point,
5052 dimer.setUseHssvdAnalyticCurvature(use_analytic_hssvd);
5053 dimer.setHssvdModeSelectionPolicy(
5055 dimer.setPreserveInitialAlignmentReference(
false);
5056 dimer.setAlignmentAbortTol(0.0);
5057 dimer.setAbortOnDegenerateProbes(
true);
5058 dimer.setMeasuredEnergyCeiling(energy_ceiling);
5059 dimer.setAbortOnInteratomicCollapse(
true);
5060 dimer.setRejectHigherIndexSurrogateConvergence(
true);
5063 dimer.getVarianceGateConfig();
5066 detail::resolveDimerVarianceTauRelative(neb_config, oci_config);
5070 dimer.setVarianceGateConfig(vg);
5072#ifdef USE_READCON_DB
5073 dimer.setObservationArchive(session.observationArchive());
5078 dimer.secantLedger();
5079 dimer.execute(potential);
5088 out.oracle_calls =
static_cast<int>(
dimer.getTotalForceCalls());
5089 out.phases =
static_cast<int>(
dimer.getPhaseHistory().size());
5091 const double e0 = (e_zero.size() > 0) ? e_zero(0, 0) : 0.0;
5094 dimer.getMidPointCoordForAllObservationPointsRef();
5096 dimer.getEnergyForAllObservationPointsRef();
5098 for (
const auto& staged: detail::stageDimerObservationUpdates(
5099 init_observations, dimer_R, dimer_E, dimer_G, e0)) {
5106 out.converged =
dimer.getConverged();
5107 out.wall_clock_limit =
5108 dimer.getRelaxationTerminationReason() ==
5110 out.force =
dimer.getFinalForceNormForConvergence();
5111 out.curvature =
dimer.getFinalCurvature();
5112 out.positions =
dimer.getFinalCoordOfMidPoint();
5113 out.gradient =
dimer.getFinalGradientAtMidPoint();
5114 out.energy =
dimer.getFinalEnergy() + e0;
5115 restore_model.restore();
5120 const Eigen::VectorXd& final_state,
int n_images,
5136 (saved_attempt_wall > 0.0)
5137 ? std::min(saved_attempt_wall,
5143 neb_config, oci_config, session);
5147 int active_n_images = n_images;
5148 for (
int refinement = 0; refinement < max_refinements; ++refinement) {
5156 const bool discretization_holds =
5161 : detail::bandDiscretizationCertificateHolds(
5172 bool midpoint_holds =
true;
5173 double midpoint_excess = 0.0;
5174 double midpoint_raw_excess = 0.0;
5175 int midpoint_segment = -1;
5176 Eigen::VectorXd midpoint_worst_position;
5178 int midpoint_calls = 0;
5184 midpoint_holds = mid.evaluated && mid.holds;
5185 midpoint_excess = mid.excess;
5186 midpoint_raw_excess = mid.raw_excess;
5187 midpoint_segment = mid.worst_segment;
5188 midpoint_worst_position = mid.measured_position.size() > 0
5189 ? mid.measured_position
5190 : mid.worst_position;
5192 const bool refine_for_discretization =
5193 !discretization_holds &&
5195 std::cout <<
"[ocineb] attempt " << (refinement + 1)
5196 <<
" converged=" << (converged ? 1 : 0) <<
" status="
5198 <<
" midpoint=" << (midpoint_holds ? 1 : 0)
5199 <<
" midpoint_excess=" << midpoint_excess
5200 <<
" midpoint_raw=" << midpoint_raw_excess
5201 <<
" midpoint_segment=" << midpoint_segment
5202 <<
" discretization=" << (discretization_holds ? 1 : 0)
5203 <<
" refine_for_discretization="
5204 << (refine_for_discretization ? 1 : 0)
5206 if (converged && midpoint_holds && !refine_for_discretization)
break;
5212 bool local_refined =
false;
5231 if (!midpoint_holds && midpoint_segment >= 0 &&
5234 midpoint_worst_position.size() ==
5238 const Eigen::Index dof = midpoint_worst_position.size();
5241 for (
int k = 0; k < n; ++k) {
5243 if (k == midpoint_segment)
5244 refined.row(row++) = midpoint_worst_position.transpose();
5250 active_n_images = n - 1;
5251 local_refined =
true;
5252 std::cout <<
"[ocineb] midpoint of segment " << midpoint_segment
5253 <<
" inserted as an image; the band restarts from "
5254 << n + 1 <<
" images" << std::endl;
5265 const auto leak_report =
5266 detail::bandDiscretizationCertificateReport(
5268 const double ratio =
5270 std::isfinite(leak_report.leak_max) &&
5272 ? leak_report.leak_max / neb_config.
conv_tol
5274 const double factor =
5275 std::clamp(std::sqrt(std::max(ratio, 1.0)), 1.0, 3.0);
5276 const int n_interior = coarse.
numImages() - 2;
5277 const int n_new_interior = std::max(
5278 n_interior + 2,
static_cast<int>(std::ceil(
5279 static_cast<double>(n_interior) * factor)));
5280 const std::vector<double> rest =
5281 detail::chordLeakSpringRestLengths(coarse, neb_config.
conv_tol);
5282 const EigenMatrix refined = detail::resamplePathByRestLengths(
5283 coarse, n_new_interior + 2, rest);
5284 if (refined.rows() == n_new_interior + 2) {
5287 std::vector<double> chord(
5288 static_cast<std::size_t
>(n_new_interior + 1));
5289 for (
int k = 0; k + 1 < refined.rows(); ++k)
5290 chord[
static_cast<std::size_t
>(k)] =
5291 (refined.row(k + 1) - refined.row(k)).norm();
5294 : std::vector<double>{};
5295 active_n_images = n_new_interior;
5296 local_refined =
true;
5299 if (!local_refined) active_n_images *= 2;
5301 struct CoarseCounts {
5302 int oracle_calls, endpoints, initial, outer, validation;
5303 int outer_iterations, refits, refreshes, dimer_calls, refinements;
5314 result =
runOCINEB(oracle, initial, final_state, active_n_images,
5315 neb_config, oci_config, session);
5335 neb_config, oci_config, session);
5345 if (image > 0 && image < path.
numImages() - 1) {
5365 for (
int i = 0; i < path.
numImages(); ++i)
5376 runOCINEB(oracle, initial, final_state, active_n_images,
5377 warm, oci_config, session);
5378 resumed.neb_result.oracle_calls += kept_calls;
5379 resumed.neb_result.oracle_calls_outer += kept_calls;
5380 resumed.neb_result.outer_iterations += kept_outers;
5381 resumed.neb_result.index_gate_true_calls +=
5383 result = std::move(resumed);
5396 const Eigen::VectorXd& initial,
5397 const Eigen::VectorXd& final_state,
5398 int active_n_images,
const GPNEBConfig& neb_config,
5402 const auto markWallClockStop = [&]() {
5410 markWallClockStop();
5420 auto record_band_certificate = [&]() {
5422 const auto report = detail::bandDiscretizationCertificateReport(
5427 band_scale > 0.0 ? detail::bandPathCertificateHolds(
5437 int midpoint_calls = 0;
5446 markWallClockStop();
5448 }
catch (
const std::exception& error) {
5450 std::cout <<
"[ocineb] band midpoint certificate refused by the "
5452 << error.what() << std::endl;
5461 record_band_certificate();
5465 const int max_attempts = std::max(1, 3 * neb_config.
n_atoms);
5466 int certificate_calls = 0;
5467 Eigen::VectorXd previous_escape;
5468 for (
int attempt = 0; attempt < max_attempts; ++attempt) {
5478 if (ci <= 0 || ci >= path.
numImages() - 1)
break;
5479 auto& image = path.
image(ci);
5480 if (!image.evaluated ||
5481 image.gradient.size() != image.positions.size())
5486 oracle, session, image.positions, image.energy,
5495 markWallClockStop();
5497 }
catch (
const std::exception& error) {
5500 std::cout <<
"[ocineb] index certificate refused by the "
5502 << error.what() << std::endl;
5527 record.
add(
"attempt",
static_cast<long>(attempt + 1))
5533 .
add(
"rounds",
static_cast<long>(cert.
rounds))
5540 .
add(
"energy", image.energy)
5541 .
add(
"positions", image.positions)
5542 .
add(
"gradient", image.gradient)
5545 tracker->appendRecord(
"certificate/index", record);
5546 const long step =
static_cast<long>(attempt + 1);
5547 tracker->logMetric(
"certificate.oracle_curvature1",
5549 tracker->logMetric(
"certificate.oracle_curvature2",
5551 tracker->logMetric(
"certificate.surrogate_lambda1",
5553 tracker->logMetric(
"certificate.surrogate_lambda2",
5555 tracker->logMetric(
"certificate.residual1", cert.
residual1,
5557 tracker->logMetric(
"certificate.residual2", cert.
residual2,
5559 tracker->logMetric(
"certificate.oracle_calls",
5562 tracker->logMetric(
"certificate.certified",
5564 tracker->logMetric(
"certificate.verified",
5576 oracle, session, image.positions, image.energy,
5578 std::max(1, neb_config.
n_atoms),
5585 markWallClockStop();
5587 }
catch (
const std::exception& error) {
5588 std::cout <<
"[ocineb] index certificate polish refused "
5590 << error.what() << std::endl;
5594 std::cout <<
"[ocineb] index certificate polish: force "
5598 << polished.
steps <<
" steps, "
5600 if (polished.
steps == 0)
break;
5602 image.energy = polished.
energy;
5603 image.gradient = polished.
gradient;
5604 image.evaluated =
true;
5615 const double e_refused = image.energy;
5616 double e_d = std::numeric_limits<double>::quiet_NaN();
5617 Eigen::VectorXd g_d;
5618 ++certificate_calls;
5620 std::tie(e_d, g_d) = detail::evaluateOieOraclePosition(
5625 markWallClockStop();
5627 }
catch (
const std::exception& error) {
5630 std::cout <<
"[ocineb] index escape refused by the oracle: "
5631 << error.what() << std::endl;
5634 if (!std::isfinite(e_d) || g_d.size() != image.positions.size() ||
5640 image.gradient = g_d;
5641 image.evaluated =
true;
5643 const Eigen::VectorXd escape_mode =
5644 cert.
mode1.size() == image.positions.size()
5650 oci_config, neb_config, session, oracle,
5655 }
catch (
const std::runtime_error& error) {
5658 std::cout <<
"[ocineb] index escape dimer stopped by oracle "
5660 << error.what() << std::endl;
5663 std::cout <<
"[ocineb] index escape (gprd): converged="
5666 <<
" phases=" << esc.
phases
5668 <<
" energy=" << esc.
energy << std::endl;
5677 esc.
positions.size() == image.positions.size() &&
5678 esc.
gradient.size() == image.positions.size() &&
5679 std::isfinite(esc.
energy)) {
5685 if (previous_escape.size() == esc.
positions.size() &&
5686 (esc.
positions - previous_escape).norm() <=
5687 1e-8 * (1.0 + previous_escape.norm())) {
5688 std::cout <<
"[ocineb] index escape returned to its "
5689 "previous point; no further attempt."
5695 image.energy = esc.
energy;
5697 image.evaluated =
true;
5699 record_band_certificate();
5703 std::cout <<
"[ocineb] index escape: band midpoint "
5704 "certificate fails around the dimer saddle "
5708 <<
"); relaxing the band from it" << std::endl;
5715 for (
int i = 0; i < path.
numImages(); ++i)
5718 result =
runOCINEB(oracle, initial, final_state, active_n_images,
5719 warm, oci_config, session);
5732 record_band_certificate();
5733 const bool index_required =
5738 const bool discretization_required =
5740 const bool discretization_holds = !discretization_required ||
5743 const bool midpoint_holds =
5746 if (!index_holds || !discretization_holds || !midpoint_holds) {
5758 MPI_Initialized(&mpi_up);
5761 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
5763 int global_calls = 0;
5764 MPI_Allreduce(&local_calls, &global_calls, 1, MPI_INT, MPI_SUM,
5766 return global_calls;
TPE-style OIE acquisition over the discrete interior-image axis.
Adapter: ~NEBOracle~ lambda -> ~potPotentialWrapper~.
GP-OCINEB controller – faithful port of the eOn ~NEBOcinebController~ pattern (eOn/client/ NEBOcinebC...
void initialize(const gpr::InputParameters ¶meters, const gpr::Observation &initial_data, const gpr::Observation &middle_point, const gpr::Coord &initial_orientation, const gpr::AtomsConfiguration &init_atom_config)
Initilalize with initial data.
void setVarianceGateConfig(const VarianceGateConfig &cfg) noexcept
gpr::optim::SecantCurvatureCounts secantCounts() const
void setWallClockLimit(std::shared_ptr< const gpr::WallClockLimit > limit)
Share an enclosing deadline (used by OCI-NEB and deterministic tests).
const VarianceGateConfig & getVarianceGateConfig() const noexcept
gpr::optim::SecantCurvatureCounts secantLedger() const noexcept
Pair, probe and rejection counts, without the GP's quadratic-mean uses.
void setForceStopCertificateStep(double step) noexcept
gpr::Coord & getGradientForAllObservationPointsRef()
Return gradients for all observed points.
void setAlignmentAbortTol(double tol) noexcept
void setSecantOrientationSeed(bool enabled) noexcept
void setSelfOwnedUseFfPriorMean(bool use) noexcept
void setLikelihoodNoiseFloorSigma2(double floor_sigma2) noexcept
gpr::FieldMatrixd & getEnergyForAllObservationPointsRef()
Return energies for all observed points.
void setUseHssvdAnalyticCurvature(bool enabled) noexcept
void setPreserveInitialAlignmentReference(bool enabled) noexcept
void setKappaDimer(double beta)
void setHssvdModeSelectionPolicy(HssvdModeSelectionPolicy policy) noexcept
void setTrainingPolicy(const gpr::policy::TrainingPolicy *policy)
Not owned. The pointer must outlive execute(). Null is the engine.
gpr::FieldMatrixd getEnergyZeroLevel() const
Internal E_zero_level used by the dimer's cutOffEnergy bookkeeping. The energies returned by ~getEner...
DimerSurrogateActionCertificate previewFirstSurrogateAction(const gpr::Observation &oracle_middle_point, const gpr::Coord &initial_orientation)
gpr::Index_t getTotalForceCalls() const
Return the total number of force calls.
void setSelfOwnedUseZblPriorMean(bool use) noexcept
void attachExternalGP(gpr::GaussianProcessRegression *external_gp) noexcept
Attach an externally-owned GPR model. Must be called BEFORE ~initialize~. The dimer will use this GP ...
void setSecantHessianConfig(const gpr::optim::SecantHessianConfig &config)
Replace the true-force secant and drop its history.
void setProjectRigidModesForConvergence(bool enabled) noexcept
void setSelfOwnedModelProfile(gpr::GPModelProfile profile) noexcept
gpr::Coord & getMidPointCoordForAllObservationPointsRef()
Return gpr::Coordinates of all observed points.
void execute(pot::PotentialWrapper &general_potential)
This function uses the atomic GP-dimer method to converge to a saddle point, starting from somewhere ...
gpr::Index_t getIterations() const
Return the total number of cycles.
void setLeashRelaxWhenClose(bool enabled) noexcept
void dist_emd(const gpr::Coord &x1, const gpr::Coord &x2, const gpr::AtomsConfiguration &conf_info, gpr::FieldMatrixd &dist)
Calculates the Earth Mover's Distance between sets of configurations.
double getSigma2() const noexcept
void calculateVarianceDispatched(Observation &image1)
bool hasReusableHssvdPosterior() const noexcept
void calculatePotentialDispatched(Observation &image1)
SexpatCF & getSexpAtCovarianceFunction()
ScopedParameterRestore scopedParameterRestore() &
gpr::GaussianProcessRegression & gp() const
const gpr::Observation & observations() const
NEB path: chain of images between two endpoints.
int highestEnergyImageIndex() const
Highest finite interior energy, or -1 when none exists.
Eigen::VectorXd tangentAt(int i) const
Improved (energy-weighted) tangent at image i, normalised. Used by the OCINEB controller to seed the ...
const Eigen::VectorXd & nebForce(int i) const
Get the NEB force for image i.
int highestEnergyImageIndexPreferring(int preferred) const
void computeNEBForces()
Compute NEB forces for all intermediate images.
Image & image(int i)
Access image i.
double saddleForce(int i) const
void noteMmfRejectActionSnapshot(detail::MmfPosteriorActionFingerprint action)
Enter the information wait with the posterior action MMF would consume.
void recordUncertifiedMmfHookReject(double convForce, const Eigen::VectorXd &ci_position, detail::MmfSurrogateFingerprint surrogate, long climbingImage=-1)
MMFRunResult run(NEBPath &path, int ci_image_idx, NEBOracle &oracle, const GPNEBConfig &neb_config, ActiveLearningSession &session, bool trap_detected=false)
bool wantsCurrentCiOracle(double convForce, bool ci_active, long climbingImage, long numImages, int outerIter, bool ci_posterior_confident, bool trap_detected=false, std::size_t ntrain_now=0, bool ci_is_energy_maximum=false)
void updateStabilityForOuter(long climbingImage, int outerIter)
Idempotent stability update keyed by GP-NEB outer iteration.
void noteMmfRejectSurrogateSnapshot(detail::MmfSurrogateFingerprint surrogate)
Enter AwaitingFirstTrainingGrowth with the model lease MMF consumed.
bool shouldTrigger(double convForce, bool ci_active, long climbingImage, long numImages, bool ci_posterior_confident, bool trap_detected=false, std::size_t ntrain_now=0, bool ci_is_energy_maximum=false, bool band_information_exhausted=false, bool oie_acquisition_quiet=false, bool rejected_seed_replay=false, bool current_chain_certificate=false, bool current_saddle_stencil_certificate=false, bool rejected_seed_position_matches=false, bool stagnation_handoff=false) const
void releaseRecoveryOwnerForCertifiedHandover(const Eigen::VectorXd &owner_position, long owner_image)
OCINEBController(OCINEBConfig cfg)
bool rejectedMmfSeedReplay(const Eigen::VectorXd &ci_position, detail::MmfSurrogateFingerprint surrogate, long climbingImage=-1, const gpr::AtomsConfiguration *atoms_config=nullptr) const
void noteMmfActionChange(detail::MmfPosteriorActionFingerprint action)
void noteMmfSurrogateChange(detail::MmfSurrogateFingerprint surrogate)
void initBaseline(double baseline_force)
bool rejectedMmfSeedPositionMatches(const Eigen::VectorXd &ci_position, const gpr::AtomsConfiguration *atoms_config=nullptr, long climbingImage=-1) const
bool shouldPrepareMmfHandoff(bool trap_detected=false, bool band_information_exhausted=false, bool current_chain_certificate=false) const
void noteMmfMinModeProbeConsumed()
Record that the rejected action consumed a true-potential mode probe.
detail::MmfPosteriorActionFingerprint previewMmfAction(ActiveLearningSession &session, const NEBPath &path, int ci_image_idx, const GPNEBConfig &neb_config) const
void noteMmfRejectCiPosition(const Eigen::VectorXd &ci_position, long climbingImage=-1)
void updateStability(long climbingImage)
void releaseExhaustedRecoveryForCertifiedHandover()
void recordMmfPosteriorUpdate()
void recordMmfHandoffForce(double handoff_force, bool handoff_data_ready=false)
bool step(rgsaddle_surface_fn surface, void *user, rgsaddle_report_t &report)
bool bind(RgsaddleClient &client, int64_t n_atoms, const double *position, const double *mode, double force_tol, Kind kind=Kind::Dimer, int32_t force_gate=2, int32_t max_rotations=16, double rotation_tol=1e-3)
static constexpr Kind kOciBurstKind
bool position(double *out)
bool load(const std::string &path={})
A JSON object assembled field by field; one line of a record stream.
JsonRecord & add(std::string_view key, double value)
Type-erased wrapper around any potential that provides a force() interface.
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
@ ReferenceConnectedNegative
DimerRelaxationTerminationReason
@ InvalidParameters
The search parameters cannot define a dimer (non-positive separation).
@ WallClockLimit
The shared monotonic wall-clock deadline was reached.
@ InvalidAtomsConfiguration
execute() rejected the atom configuration before any search step.
@ OracleBudget
The caller's oracle-call budget was spent.
double flatDot(const Eigen::MatrixBase< DerivedA > &a, const Eigen::MatrixBase< DerivedB > &b)
Half surrogate(GaussianProcessRegression &gp, const Eigen::VectorXd &x, Kind kind, const Options &options)
double gaussianExceedanceProbability(double reference_mean, double reference_variance, double challenger_mean, double challenger_variance)
Probability that a Gaussian challenger equals or exceeds a Gaussian reference under the independent-m...
The nudged elastic band: path, GP-NEB driver, configuration and result, acquisition,...
int reduceOracleProviderCalls(int local_calls)
void certifyOCINEBResult(OCINEBResult &result, NEBOracle oracle, const Eigen::VectorXd &initial, const Eigen::VectorXd &final_state, int active_n_images, const GPNEBConfig &neb_config, const OCINEBConfig &oci_config, ActiveLearningSession &session)
double testingHelpedModeCurvature()
int vibrationalIndexOuterBudget(const GPNEBConfig &config, int n_images)
Outer-iteration cap, including the per-image reading.
SaddlePolishResult polishSaddleOnSurrogate(const NEBOracle &oracle, ActiveLearningSession &session, const Eigen::VectorXd &x0, double e0, const Eigen::VectorXd &g0, double force_tol, int max_steps, double max_move, double hessian_fd_step)
VibrationalIndexDecision decideVibrationalIndex(const Eigen::VectorXd &positions, const Eigen::VectorXd &gradient, const gpr::AtomsConfiguration *atoms, gpr::GaussianProcessRegression *gp, double variance, double variance_threshold, double move, double stencil_step, const NEBOracle *oracle, const NEBBatchOracle *batch, Eigen::Index batch_chunk, gpr::optim::VibrationalStencil stencil)
std::function< std::pair< double, Eigen::VectorXd >( const Eigen::VectorXd &positions)> NEBOracle
Oracle function: positions -> (energy, gradient).
@ WallClockLimit
The shared monotonic wall-clock deadline was reached.
OCINEBResult runOCINEB(NEBOracle oracle, const Eigen::VectorXd &initial, const Eigen::VectorXd &final_state, int n_images, const GPNEBConfig &neb_config, const OCINEBConfig &oci_config_in, ActiveLearningSession &session)
rgsaddle_status_t gprRgsaddleSurface(void *user, rgsaddle_surface_request_t *req)
pot::PotentialWrapper makePotentialWrapperFromOracle(NEBOracle oracle)
GPNEBResult gpNEB(NEBOracle oracle, const Eigen::VectorXd &initial, const Eigen::VectorXd &final_state, int n_images, const GPNEBConfig &config, ActiveLearningSession *session)
Run GP-accelerated NEB.
ClimbingImageIndexCertificate certifyClimbingImageIndex(const NEBOracle &oracle, ActiveLearningSession &session, const Eigen::VectorXd &x_ci, double e_ci, const Eigen::VectorXd &g_ci, double hessian_fd_step, double max_move, double force_tol, const NEBBatchOracle *batch_oracle, Eigen::Index batch_chunk)
@ RecoveryPortfolioExhausted
BandMidpointCertificate certifyBandMidpointsMeasured(ActiveLearningSession &session, const NEBPath &path, double force_tol, NEBOracle &oracle, int max_measurements, int *oracle_calls)
double indexGateVarianceThreshold(double noise_variance) noexcept
IndexEscapeResult runIndexEscapeGpDimer(const OCINEBConfig &oci_config, const GPNEBConfig &neb_config, ActiveLearningSession &session, NEBOracle &oracle, const Eigen::VectorXd &x_seed, double e_seed, const Eigen::VectorXd &g_seed, const Eigen::VectorXd &mode_seed, double energy_ceiling)
void applyVibrationalIndexDecision(GPNEBResult &result, const VibrationalIndexDecision &decision, int outer_budget)
void runOciNebOuterIteration(const std::shared_ptr< OCINEBController > &controller, NEBOracle &oracle, const GPNEBConfig &neb_config, int &total_oracle_calls, int &bursts_fired, int &dimer_saddle_image_idx, const std::shared_ptr< OciMmfHandoffTrapState > &handoff_trap_state, const GPNEBConfig::OuterIterHook &caller_hook, NEBPath &path, int ci_image_idx, int outer_iter, ActiveLearningSession &sess, bool &converged, bool trap_detected)
OCINEBResult runOCINEBRefined(NEBOracle oracle, const Eigen::VectorXd &initial, const Eigen::VectorXd &final_state, int n_images, GPNEBConfig neb_config, const OCINEBConfig &oci_config, ActiveLearningSession &session)
MMFStatus
Outcome of one MMF burst, mirroring eOn's enum class.
@ Helped
Mode converged, alignment in tol.
@ MaxIterations
Hit dimer iter cap; usable but no signal.
@ Skipped
Invalid input or mode drifted outside tol.
@ PositiveCurvature
CI was a minimum; restore position.
double saddleForceMagnitude(const Eigen::VectorXd &gradient)
NEBMode
NEB evaluation mode.
constexpr double stencilStepOrDefault(double requested) noexcept
The requested stencil step, or the default when none was requested.
SecantSeed secantSeedDirection(const SecantHessian &secant, const Eigen::VectorXd ¤t_direction)
const char * secantSeedStatusName(SecantSeedStatus status) noexcept
void setBofillRgsaddleLibrary(const char *path)
MlflowRun * activeRun() noexcept
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
bool collectiveWallClockLimitReached(const std::shared_ptr< const WallClockLimit > &limit, const linalg::MpiContext &context)
Eigen::Matrix< double, EigenDynamic, EigenDynamic, EigenMatrixStorage > EigenMatrix
Eigen::Matrix< double, EigenDynamic, EigenDynamic, FieldMatrixStorage > FieldMatrixd
void applyCanonicalReadconDimerDefaults(InputParameters ¶meters, const CanonicalDimerDefaultOptions &options)
Apply the canonical readcon dimer defaults to parameters.
rgsaddle_report_t gpr_rgsaddle_report_t
One entry of the dimer trajectory history – the midpoint configuration and dimer curvature estimate a...
double energy
energy relative to E_zero_level
double curvature
dimer curvature estimate this phase
gpr::Coord position
midpoint coordinates (1 x D)
gpr::Coord gradient
midpoint gradient (1 x D)
bool measured_descent_certified
The true-PES force strictly improves the preceding accepted center.
double reference_alignment
double imspe_soft_threshold
double accept_tau_relative
Stores configurations of all atoms in the system.
Observation data: energy, gradient and positions.
static void notePeak(const char *phase) noexcept
static SurrogateFingerprint global(std::uint64_t revision)
int mmfModelOwner(int image_idx, bool dimer_use_global_gp) const
SurrogateFingerprint surrogateFingerprint(int owner) const
bool hasCurrentChainCertificate(int image_idx, const Eigen::VectorXd &positions) const
double path_energy_ceiling
ModelLease acquireImageModel(int i)
void appendCurrentChainObservation(int image_idx, const Eigen::VectorXd &positions, double energy, const Eigen::VectorXd &gradient, ObservationRetention retention=ObservationRetention::RecordAcquisition, optim::SecantAccounting secant_accounting=optim::SecantAccounting::Count)
ModelLease acquireGlobalModel()
gpr::Observation training_obs
std::uint64_t trainingRevision() const noexcept
void addSecantCounts(const optim::SecantCurvatureCounts &extra)
bool refitGPIfTrainingChanged(bool reinit_seeds)
SurrogateFingerprint mmfSurrogateFingerprint(int image_idx, bool dimer_use_global_gp) const
gpr::GaussianProcessRegression gp
gpr::AtomsConfiguration atoms_config
void ensureSingletonForGlobal()
void appendObservation(const Eigen::VectorXd &positions, double energy, const Eigen::VectorXd &gradient, ObservationRetention retention=ObservationRetention::RecordAcquisition, optim::SecantAccounting secant_accounting=optim::SecantAccounting::Count)
const optim::SecantHessian * imageSecantHessian(int image_idx) const noexcept
double last_max_chain_energy_variance
int worst_segment
segment with the highest energy upper bound
double excess
mean E_mid - E_ci for that segment (eV)
Eigen::VectorXd displaced_positions
double escapeEnergyCeiling(double refused_energy) const noexcept
bool certified
both required curvature signs are resolved
double polish_force_target
bool evaluated
the surrogate Hessian was available
bool verified
the complete non-rigid subspace was evaluated
int rounds
Hessian-vector products taken.
std::string reason
why evaluation or sign resolution failed
Configuration for GP-NEB.
gpr::optim::SecantHessianConfig secant_hessian
OuterIterHook outer_iter_hook
Eigen::Index oracle_batch_chunk
bool outer_budget_per_image
const policy::TrainingPolicy * training_policy
bool band_midpoint_certificate
OieFixedImageLeaseProvider oie_fixed_image_lease
const double * oracle_energy_noise_rms
std::vector< double > initial_rest_lengths
OuterIterHookReject outer_iter_hook_reject
double inner_unc_relative
OieInnerHandoffPriority oie_inner_handoff_priority
NEBBatchOracle batch_oracle
bool force_stop_certificate
std::function< void(const NEBOracleOptimizationOutcome &)> oracle_optimization_outcome
gpr::optim::VibrationalStencil vibrational_stencil
policy::SearchKind training_search_kind
Label published to the policy. runOCINEB sets OciNeb.
CurrentCiOraclePriority current_ci_oracle_priority
std::string rgsaddle_library
double first_attempt_wall_seconds
bool * oracle_noise_updates_enabled
OieFixedImage oie_fixed_image
bool hold_refined_spacing
std::shared_ptr< const gpr::WallClockLimit > wall_clock_limit
std::function< void(gpr::InputParameters &, gpr::AtomsConfiguration &)> gp_setup
double band_certificate_force_scale
std::function< void( NEBPath &path, int ci_image_idx, int outer_iter, ActiveLearningSession &session, bool &converged, bool trap_detected)> OuterIterHook
bool ci_index_certificate
int oracle_transition_focal_image
double attempt_wall_seconds
std::function< bool()> oracle_session_restart_requested
int index_gate_true_calls
bool index_refused
A force-quiet point failed the index-1 gate and no budget remains.
bool index_checked
The vibrational-index gate ran on this result.
GPNEBStopReason stop_reason
GPNEBConvergenceStatus convergence_status
int hyperparameter_refits
bool index_continue
The gate stepped the climbing image; the caller resumes the search.
int oracle_calls_validation
std::unique_ptr< NEBPath > path
int fixed_theta_refreshes
int oracle_calls_endpoints
GP-NEB GaussianProcessRegression as dest PointSurface.
gpr::GaussianProcessRegression * gp
double posterior_variance
Eigen::VectorXd positions
Eigen::VectorXd positions
final midpoint
int oracle_calls
oracle rows the search paid
bool converged
true-force convergence at the midpoint
int phases
measured dimer phases
Eigen::VectorXd gradient
true gradient at the final midpoint
bool wall_clock_limit
shared search deadline expired
Result of one ~OCINEBControllerrun~ invocation.
MMFRejectKind reject_kind
Reason for rejected_helped_handback, used by recovery-gate policy.
bool shouldResetOptimizer
Whether the caller should reset its outer optimiser state.
bool certified_lower_saddle_advanced
bool rejected_helped_handback
double alignment
Alignment of final mode to current path tangent.
bool convergedAfterMMF
True iff newForce < force_tolerance.
double final_mode_curvature
bool min_mode_angle_certified
bool trusted_recovery_advanced
A non-Helped recovery phase was accepted and written to the chain.
bool recovery_saddle_certified
bool force_improving_recovery_advanced
MMFStatus status
Final dimer-status for reporting / accounting.
double final_rotation_omega
double previousForce
Oracle force at CI image before this MMF burst.
bool recovery_selection_exhausted
The recovery selector found no acceptable phase to hand back.
bool requires_outer_path_refresh
bool comparable_true_pes_forces
bool certified_lower_saddle
MmfHandoffPolicy handoff_policy
double dimer_imspe_soft_threshold
int dimer_imspe_history_size
EMD-filtered ring-buffer size for the dimer IMSPE soft-skip.
std::function< double()> effective_force_tolerance
double dimer_variance_tau_abs
Eigen::VectorXd initial_orient
double dimer_kappa_beta
Xiao contour curvature restraint; zero disables, paper uses 5 Angstrom.
bool band_certificate_evaluated
double band_certificate_residual
bool band_certificate_holds
int refinements
Number of band refinements (image doublings) folded into this result.
int ci_index_oracle_calls
double ci_index_residual1
double ci_index_residual2
bool ci_index_evaluated
Climbing-image index certificate (see certifyClimbingImageIndex).
double band_midpoint_excess
double ci_index_curvature2
bool band_midpoint_evaluated
Surrogate midpoint check of the returned band (certifyBandMidpoints).
Eigen::VectorXd ci_final_position
int band_midpoint_segment
double ci_index_curvature1
double band_certificate_leak
Outcome of a saddle polish (see polishSaddleOnSurrogate).
double initial_max_atom_force
Eigen::VectorXd positions
double final_max_atom_force
Eigen::VectorXd gradient
true gradient at positions
double energy
true energy at positions
int oracle_calls
true-PES evaluations spent
int steps
accepted Newton steps
Eigen::VectorXd positions
int consistency_rejections
Eigen::VectorXd direction