38 : well_(
std::move(positiveWell)),
43 require(period_ > 0 && std::isfinite(period_) && hbar_ > 0 &&
45 "Finite positive arc-tail scales required");
46 require(!weights_.empty(),
"An anharmonic arc needs at least one link");
48 for (
double weight: weights_) {
49 require(weight > 0 && std::isfinite(weight),
50 "Positive finite arc time weights required");
53 require(std::abs(sum - 1) <= 1e-12,
"Arc time weights must sum to one");
54 require(well_.rows() > 0 && well_.rows() == well_.cols() &&
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");
81 const std::vector<V>& q,
82 const std::vector<gpr::quantum::PotentialEvaluation>& native,
83 double arcDuration,
const std::vector<M>& nativeHessians = {})
const
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) {
107 const auto& kernel = reference.kernel();
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;
126 (kernel.L * kernel.L + kernel.A * kernel.A) * kernel.L;
127 const double residual =
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] +=
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] +=
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(
152 : reference.quadratic(nativeHessians[a],
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");