Loading...
Searching...
No Matches
ArcTailAction.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
6#pragma once
7#include <Eigen/Eigenvalues>
8#include <cmath>
9#include <vector>
10
12
13namespace gpr::quantum {
17 std::vector<Eigen::VectorXd> gradient, durationCrossGradient;
18 std::vector<gpr::quantum::gaussian::Segment> fluctuationSegments;
20};
21
22// Native nodes resolve the anharmonic excursion. One exact positive-well
23// bridge closes it and represents the dwell without interior force calls.
25 using M = Eigen::MatrixXd;
26 using V = Eigen::VectorXd;
27 M well_;
28 double period_{}, hbar_{};
29 std::vector<double> weights_;
30 static void require(bool value, const char* text)
31 {
32 if (!value) throw std::invalid_argument(text);
33 }
34
35public:
36 ArcTailAction(M positiveWell, double period, double hbar,
37 std::vector<double> arcWeights)
38 : well_(std::move(positiveWell)),
39 period_(period),
40 hbar_(hbar),
41 weights_(std::move(arcWeights))
42 {
43 require(period_ > 0 && std::isfinite(period_) && hbar_ > 0 &&
44 std::isfinite(hbar_),
45 "Finite positive arc-tail scales required");
46 require(!weights_.empty(), "An anharmonic arc needs at least one link");
47 double sum = 0;
48 for (double weight: weights_) {
49 require(weight > 0 && std::isfinite(weight),
50 "Positive finite arc time weights required");
51 sum += weight;
52 }
53 require(std::abs(sum - 1) <= 1e-12, "Arc time weights must sum to one");
54 require(well_.rows() > 0 && well_.rows() == well_.cols() &&
55 well_.allFinite() &&
56 (well_ - well_.transpose()).norm() <=
57 1e-12 * std::max(1., well_.norm()),
58 "Finite symmetric well curvature required");
59 Eigen::SelfAdjointEigenSolver<M> eig(well_);
60 require(eig.info() == Eigen::Success &&
61 (eig.eigenvalues().array() > 0).all(),
62 "Positive well curvature required");
63 }
64 double period() const
65 {
66 return period_;
67 }
68 const M& wellCurvature() const
69 {
70 return well_;
71 }
72 const std::vector<double>& arcWeights() const
73 {
74 return weights_;
75 }
76 // Coordinates are relative to the quadratic well centre. Potential values
77 // and gradients use that mass metric and the same relative energy origin.
78 // Native Hessians are optional; supplied Hessians define these links' own
79 // quadratic fluctuations, including the exact tail normalization.
81 const std::vector<V>& q,
82 const std::vector<gpr::quantum::PotentialEvaluation>& native,
83 double arcDuration, const std::vector<M>& nativeHessians = {}) const
84 {
85 const auto n = weights_.size() + 1;
86 const auto d = well_.rows();
87 require(q.size() == n && native.size() == n &&
88 (nativeHessians.empty() || nativeHessians.size() == n),
89 "Arc-tail node counts differ");
90 require(arcDuration > 0 && arcDuration < period_ &&
91 std::isfinite(arcDuration),
92 "Arc duration must lie inside the thermal period");
93 for (std::size_t j = 0; j < n; ++j)
94 require(q[j].size() == d && q[j].allFinite() &&
95 native[j].gradient.size() == d &&
96 native[j].gradient.allFinite() &&
97 std::isfinite(native[j].energy),
98 "Invalid native arc point");
100 out.gradient.assign(n, V::Zero(d));
101 out.durationCrossGradient.assign(n, V::Zero(d));
102 out.fluctuationHessianPhysical = !nativeHessians.empty();
103 const double logScale = std::log(2 * std::acos(-1.) * hbar_);
104 auto add = [&](std::size_t a, std::size_t b, double duration,
105 double durationSlope, bool tail) {
106 const gpr::quantum::HarmonicReference reference(well_, duration);
107 const auto& kernel = reference.kernel();
108 const auto left =
109 tail ? gpr::quantum::PotentialEvaluation{.5 * q[a].dot(well_ *
110 q[a]),
111 V(well_ * q[a])}
112 : native[a];
113 const auto right =
114 tail ? gpr::quantum::PotentialEvaluation{.5 * q[b].dot(well_ *
115 q[b]),
116 V(well_ * q[b])}
117 : native[b];
118 const auto link = reference.evaluate(q[a], q[b], left, right);
119 out.action += link.action;
120 out.gradient[a] += link.leftGradient;
121 out.gradient[b] += link.rightGradient;
122 out.logKernelNormalization += .5 * (kernel.logDetL - d * logScale);
123 const M adot = -kernel.L * kernel.L, ldot = -kernel.A * kernel.L;
124 const M addot = 2 * kernel.A * kernel.L * kernel.L;
125 const M lddot =
126 (kernel.L * kernel.L + kernel.A * kernel.A) * kernel.L;
127 const double residual =
128 tail ? 0
129 : .5 * (left.energy - .5 * q[a].dot(well_ * q[a]) +
130 right.energy - .5 * q[b].dot(well_ * q[b]));
131 const double energy = .5 * q[a].dot(adot * q[a]) +
132 .5 * q[b].dot(adot * q[b]) -
133 q[a].dot(ldot * q[b]) + residual;
134 out.durationGradient += durationSlope * energy;
135 out.durationHessian +=
136 durationSlope * durationSlope *
137 (.5 * q[a].dot(addot * q[a]) + .5 * q[b].dot(addot * q[b]) -
138 q[a].dot(lddot * q[b]));
139 out.durationCrossGradient[a] +=
140 durationSlope *
141 (adot * q[a] - ldot * q[b] +
142 (tail ? V::Zero(d).eval()
143 : V(.5 * (left.gradient - well_ * q[a]))));
144 out.durationCrossGradient[b] +=
145 durationSlope *
146 (adot * q[b] - ldot * q[a] +
147 (tail ? V::Zero(d).eval()
148 : V(.5 * (right.gradient - well_ * q[b]))));
149 if (!nativeHessians.empty())
150 out.fluctuationSegments.push_back(
151 tail ? kernel
152 : reference.quadratic(nativeHessians[a],
153 nativeHessians[b]));
154 };
155 for (std::size_t j = 0; j + 1 < n; ++j)
156 add(j, j + 1, weights_[j] * arcDuration, weights_[j], false);
157 add(n - 1, 0, period_ - arcDuration, -1, true);
158 require(std::isfinite(out.action) &&
159 std::isfinite(out.durationGradient) &&
160 std::isfinite(out.durationHessian) &&
161 std::isfinite(out.logKernelNormalization),
162 "Nonfinite arc-tail action");
163 for (std::size_t j = 0; j < n; ++j)
164 require(out.gradient[j].allFinite() &&
165 out.durationCrossGradient[j].allFinite(),
166 "Nonfinite arc-tail derivative");
167 return out;
168 }
169};
170} // namespace gpr::quantum
const M & wellCurvature() const
ArcTailEvaluation evaluate(const std::vector< V > &q, const std::vector< gpr::quantum::PotentialEvaluation > &native, double arcDuration, const std::vector< M > &nativeHessians={}) const
const std::vector< double > & arcWeights() const
ArcTailAction(M positiveWell, double period, double hbar, std::vector< double > arcWeights)
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
Models for quantum-path (instanton) searches: arc and tail actions, amplitude continuation.
STL namespace.
std::vector< Eigen::VectorXd > gradient
std::vector< Eigen::VectorXd > durationCrossGradient
std::vector< gpr::quantum::gaussian::Segment > fluctuationSegments