Loading...
Searching...
No Matches
ReferenceForceGradient.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
6#pragma once
7#include <algorithm>
8#include <cmath>
9#include <functional>
10#include <stdexcept>
11
13
14namespace gpr::quantum {
19// All gradients and Hessian actions use mass coordinates. The action must
20// represent Hessian(V)-K for a physical derivative; search curvature gives
21// only a proposal derivative. The closed-trace correction is not an
22// independent fourth-order open-endpoint propagator.
24 const Eigen::VectorXd& residualGradient,
25 const std::function<Eigen::VectorXd(const Eigen::VectorXd&)>&
26 residualHessianAction,
27 double step)
28{
29 if (residualGradient.size() == 0 || !residualGradient.allFinite() ||
30 !residualHessianAction || !(step > 0) || !std::isfinite(step))
31 throw std::invalid_argument(
32 "Finite mass gradient, physical Hessian action and positive step "
33 "required");
34 const Eigen::VectorXd response = residualHessianAction(residualGradient);
35 if (response.size() != residualGradient.size() || !response.allFinite())
36 throw std::invalid_argument(
37 "Matching finite residual Hessian response required");
39 step * step * residualGradient.squaredNorm() / 24.,
40 step * step * response / 12.};
41 if (!std::isfinite(result.potentialCorrection) ||
42 !result.gradientCorrection.allFinite())
43 throw std::overflow_error(
44 "Nonfinite reference force-gradient correction");
45 return result;
46}
47// Exact Gaussian reference with symmetric residual endpoint weights. For
48// a physical quadratic V, the positive correction adds h^3(H-K)^2/24 to
49// each endpoint block and preserves the reference normalization and link.
51 const Eigen::MatrixXd& nativeCurvature,
52 const Eigen::MatrixXd& referenceCurvature, double step,
53 bool corrected = true)
54{
55 const auto d = nativeCurvature.rows();
56 if (d == 0 || nativeCurvature.cols() != d ||
57 referenceCurvature.rows() != d || referenceCurvature.cols() != d ||
58 !nativeCurvature.allFinite() || !referenceCurvature.allFinite() ||
59 (nativeCurvature - nativeCurvature.transpose()).norm() >
60 1e-12 * std::max(1., nativeCurvature.norm()) ||
61 (referenceCurvature - referenceCurvature.transpose()).norm() >
62 1e-12 * std::max(1., referenceCurvature.norm()))
63 throw std::invalid_argument(
64 "Matching finite symmetric native and reference curvature "
65 "required");
66 auto link = gpr::quantum::gaussian::exactSegment(referenceCurvature, step);
67 const Eigen::MatrixXd residual = nativeCurvature - referenceCurvature;
68 Eigen::MatrixXd endpoint = .5 * step * residual;
69 if (corrected)
70 endpoint.noalias() += step * step * step / 24. * residual * residual;
71 link.A += endpoint;
72 link.rightA = link.A;
73 if (!link.A.allFinite())
74 throw std::overflow_error("Nonfinite corrected Gaussian endpoint");
75 return link;
76}
77} // namespace gpr::quantum
Segment exactSegment(const Matrix &hessian, double duration)
Models for quantum-path (instanton) searches: arc and tail actions, amplitude continuation.
gpr::quantum::gaussian::Segment referenceForceGradientQuadratic(const Eigen::MatrixXd &nativeCurvature, const Eigen::MatrixXd &referenceCurvature, double step, bool corrected=true)
ReferenceForceGradientValue referenceForceGradient(const Eigen::VectorXd &residualGradient, const std::function< Eigen::VectorXd(const Eigen::VectorXd &)> &residualHessianAction, double step)