Loading...
Searching...
No Matches
RingBathKernel.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
6#pragma once
7#include <Eigen/Cholesky>
8#include <Eigen/Eigenvalues>
9#include <cmath>
10#include <numbers>
11#include <stdexcept>
12#include <vector>
13
16
17// Harmonic environment eliminated exactly from an N-bead ring. With the
18// environment x coupled to the ring coordinates q through the Hessian blocks
19// [[H_qq, C^T], [C, A]], the Gaussian integral over each ring normal mode of x
20// leaves the imaginary-time kernel
21//
22// U_env = (1/2) sum_k qhat_k^dagger Gamma_k qhat_k,
23// nu_k^2 = (2 / (beta_N hbar))^2 sin^2(pi k / N),
24//
25// with Gamma_k = -C^T (A + nu_k^2)^-1 C when V holds the environment frozen,
26// and Gamma_k = C^T [A^-1 - (A + nu_k^2)^-1] C when V is the relaxed
27// (adiabatic) potential. The relaxed kernel vanishes on the centroid, is
28// positive, and tends to the full static relaxation as nu_k grows; its
29// N -> infinity limit is the Caldeira-Leggett friction at the Matsubara
30// frequencies. Both are exact at every bead count.
31//
32// The responses C^T (A + s)^-1 C come with Loewner bounds from
33// bathresponse::boundResponse, built from native Hessian-vector products of
34// the environment, so every Gamma_k is known to lie in [lower_k, upper_k].
35// The first-order change of ln k under any kernel error d Gamma is
36// tr(W dK) with W fixed by the converged ring, and its supremum over the
37// Loewner box is a nuclear norm (logRateSensitivity).
39using Matrix = Eigen::MatrixXd;
40using Vector = Eigen::VectorXd;
41
42enum class Potential { Frozen, Relaxed };
43
44// nu_k^2 for k = 0..N/2; modes k and N - k share a frequency.
45inline Vector matsubaraShifts(Eigen::Index beads, double betaN, double hbar = 1)
46{
47 if (beads < 2 || !(betaN > 0) || !(hbar > 0) || !std::isfinite(betaN) ||
48 !std::isfinite(hbar))
49 throw std::invalid_argument(
50 "At least two beads and positive beta_N and hbar required");
51 Vector shifts(beads / 2 + 1);
52 for (Eigen::Index k = 0; k < shifts.size(); ++k) {
53 const double s =
54 2 * std::sin(std::numbers::pi * k / beads) / (betaN * hbar);
55 shifts(k) = s * s;
56 }
57 return shifts;
58}
59
60struct Kernel {
62 std::vector<Matrix> lower, upper; // Gamma_k bounds for k = 0..N/2
63 std::vector<Matrix> midpoint() const
64 {
65 std::vector<Matrix> mid;
66 for (std::size_t k = 0; k < lower.size(); ++k)
67 mid.push_back(.5 * (lower[k] + upper[k]));
68 return mid;
69 }
70};
71
72// C couples the ring coordinates of one bead to the environment, A >= alpha I
73// is the environment Hessian, Q an orthonormal basis containing range(C), and
74// AQ the native actions of A on Q. When Q spans the environment the bounds
75// coincide with the exact kernel.
76inline Kernel boundKernel(Potential potential, const Matrix& C, const Matrix& Q,
77 const Matrix& AQ, double alpha, const Vector& shifts)
78{
79 if (shifts.size() < 2 || !shifts.allFinite() || shifts(0) != 0 ||
80 (shifts.array() < 0).any())
81 throw std::invalid_argument(
82 "Matsubara shifts from matsubaraShifts required");
83 if (!(alpha > 0))
84 throw std::invalid_argument(
85 "A positive environment spectral bound is required at the centroid "
86 "shift");
87 Kernel kernel;
88 kernel.potential = potential;
89 const auto r = C.cols();
90 const auto zero = bathresponse::boundResponse(C, Q, AQ, alpha, 0.);
91 for (Eigen::Index k = 0; k < shifts.size(); ++k) {
92 const auto shifted =
93 k == 0 ? zero
94 : bathresponse::boundResponse(C, Q, AQ, alpha, shifts(k));
95 if (potential == Potential::Frozen) {
96 kernel.lower.push_back(-shifted.upper);
97 kernel.upper.push_back(-shifted.lower);
98 } else if (k == 0) {
99 kernel.lower.push_back(Matrix::Zero(r, r));
100 kernel.upper.push_back(Matrix::Zero(r, r));
101 } else {
102 kernel.lower.push_back(zero.lower - shifted.upper);
103 kernel.upper.push_back(zero.upper - shifted.lower);
104 }
105 }
106 return kernel;
107}
108
109// Weight of Gamma_k in the bead block (j, l): the real Fourier projector.
110inline double modeWeight(Eigen::Index k, Eigen::Index separation,
111 Eigen::Index beads)
112{
113 const double c = std::cos(2 * std::numbers::pi *
114 static_cast<double>(k * separation) / beads);
115 return (k == 0 || 2 * k == beads ? 1. : 2.) * c / beads;
116}
117
118inline void requireBlocks(const std::vector<Matrix>& blocks, Eigen::Index beads)
119{
120 if (beads < 2 || blocks.size() != static_cast<std::size_t>(beads / 2 + 1))
121 throw std::invalid_argument(
122 "One kernel block per Matsubara frequency k = 0..N/2 required");
123 for (const auto& b: blocks)
124 if (b.rows() != blocks.front().rows() || b.cols() != b.rows() ||
125 !b.allFinite() || b.rows() == 0)
126 throw std::invalid_argument(
127 "Finite square kernel blocks of one size required");
128}
129
130// Block-circulant ring matrix K with U_env = x^T K x / 2 for the stacked bead
131// displacements x, bead-major as in ratepost::Ring.
132inline Matrix ringMatrix(const std::vector<Matrix>& blocks, Eigen::Index beads)
133{
134 requireBlocks(blocks, beads);
135 const Eigen::Index d = blocks.front().rows();
136 Matrix K = Matrix::Zero(beads * d, beads * d);
137 for (Eigen::Index j = 0; j < beads; ++j)
138 for (Eigen::Index l = 0; l < beads; ++l)
139 for (std::size_t k = 0; k < blocks.size(); ++k)
140 K.block(j * d, l * d, d, d) +=
141 modeWeight(static_cast<Eigen::Index>(k),
142 (j - l + beads) % beads, beads) *
143 .5 * (blocks[k] + blocks[k].transpose());
144 return K;
145}
146
147// Adjoint of ringMatrix: tr(W ringMatrix(blocks)) = sum_k tr(projected_k
148// blocks_k).
149inline std::vector<Matrix> projectRing(const Matrix& W, Eigen::Index beads,
150 Eigen::Index d)
151{
152 if (beads < 2 || d < 1 || W.rows() != beads * d || W.cols() != beads * d ||
153 !W.allFinite())
154 throw std::invalid_argument("Ring matrix of matching size required");
155 std::vector<Matrix> projected(beads / 2 + 1, Matrix::Zero(d, d));
156 for (Eigen::Index j = 0; j < beads; ++j)
157 for (Eigen::Index l = 0; l < beads; ++l)
158 for (std::size_t k = 0; k < projected.size(); ++k)
159 projected[k] += modeWeight(static_cast<Eigen::Index>(k),
160 (j - l + beads) % beads, beads) *
161 W.block(l * d, j * d, d, d);
162 for (auto& p: projected)
163 p = (.5 * (p + p.transpose())).eval();
164 return projected;
165}
166
168 Matrix ringWeight; // W in d ln k = tr(W dK)
169 std::vector<Matrix> modeWeights; // projectRing(W)
170 double halfWidth = 0; // sup of |d ln k| over the kernel bounds
171 double actionLower = 0, actionUpper = 0; // U_env at the ring, certified
172};
173
174inline Matrix positiveRoot(const Matrix& D)
175{
176 Eigen::SelfAdjointEigenSolver<Matrix> s(.5 * (D + D.transpose()));
177 if (s.info() != Eigen::Success)
178 throw std::runtime_error("Kernel width spectrum failed");
179 const double tolerance =
180 1e-12 * std::max(1., s.eigenvalues().cwiseAbs().maxCoeff());
181 if (s.eigenvalues().minCoeff() < -tolerance)
182 throw std::domain_error("Kernel bounds are not ordered");
183 return s.eigenvectors() *
184 s.eigenvalues().cwiseMax(0.).cwiseSqrt().asDiagonal() *
185 s.eigenvectors().transpose();
186}
187
188inline double nuclearNorm(const Matrix& M)
189{
190 Eigen::SelfAdjointEigenSolver<Matrix> s(.5 * (M + M.transpose()),
191 Eigen::EigenvaluesOnly);
192 if (s.info() != Eigen::Success)
193 throw std::runtime_error("Nuclear norm spectrum failed");
194 return s.eigenvalues().cwiseAbs().sum();
195}
196
197// The ring was converged with the midpoint kernel included in ring.hessian and
198// ring.reactantHessian, and w = ratepost::logRateWeights of that ring. Bead
199// displacements are measured from the reactant, which a frozen kernel needs as
200// its reference; the relaxed kernel ignores the centroid. To first order in
201// d Gamma_k = Gamma_k - midpoint_k,
202//
203// d ln k = -beta_N x^T dK x / 2 + w_g^T dK x - tr(H^+ dK) / 2 + tr(H_R^-1 dK)
204// / 2,
205//
206// where w_g are the bead-gradient weights: dK x is the gradient of the kernel
207// error at the beads, its orbit response enters through w_g, and the action
208// has no orbit term at a stationary ring. Over -D_k/2 <= d Gamma_k <= D_k/2,
209// D_k = upper_k - lower_k, the supremum of tr(W_k d Gamma_k) is
210// ||D_k^1/2 W_k D_k^1/2||_* / 2.
212 const ratepost::Weights& w,
213 const Kernel& kernel)
214{
215 const auto N = static_cast<Eigen::Index>(ring.beads.size());
216 requireBlocks(kernel.lower, N);
217 requireBlocks(kernel.upper, N);
218 const Eigen::Index d = kernel.lower.front().rows();
219 if (N < 4 || ring.beads.front().size() != d ||
220 w.pseudoInverse.rows() != N * d)
221 throw std::invalid_argument(
222 "Kernel, ring and weights dimensions must match");
223 const bool hasReactant = ring.reactantHessian.size() != 0;
224 if (kernel.potential == Potential::Frozen && !hasReactant)
225 throw std::invalid_argument(
226 "A frozen environment kernel needs the reactant as reference");
227 const Vector reference = hasReactant ? ring.reactant : Vector::Zero(d);
228 Vector x(N * d), wg(N * d);
229 const Eigen::Index sites = hasReactant ? N + 1 : N;
230 if (w.channels.size() != sites * (d + 1))
231 throw std::invalid_argument("Weights do not match the ring");
232 for (Eigen::Index j = 0; j < N; ++j) {
233 x.segment(j * d, d) = ring.beads[j] - reference;
234 for (Eigen::Index c = 0; c < d; ++c)
235 wg(j * d + c) = w.channels(ratepost::siteChannel(sites, j, c));
236 }
237 Sensitivity result;
238 Matrix W = -.5 * ring.betaN * x * x.transpose() +
239 .5 * (wg * x.transpose() + x * wg.transpose()) -
240 .5 * w.pseudoInverse;
241 if (hasReactant) {
242 Eigen::LLT<Matrix> reactant(ring.reactantHessian);
243 if (reactant.info() != Eigen::Success)
244 throw std::domain_error("A positive reactant ring is required");
245 W += .5 * reactant.solve(Matrix::Identity(N * d, N * d));
246 }
247 result.ringWeight = .5 * (W + W.transpose());
248 result.modeWeights = projectRing(result.ringWeight, N, d);
249 for (std::size_t k = 0; k < kernel.lower.size(); ++k) {
250 const Matrix root = positiveRoot(kernel.upper[k] - kernel.lower[k]);
251 result.halfWidth +=
252 .5 * nuclearNorm(root * result.modeWeights[k] * root);
253 }
254 result.actionLower = .5 * x.dot(ringMatrix(kernel.lower, N) * x);
255 result.actionUpper = .5 * x.dot(ringMatrix(kernel.upper, N) * x);
256 return result;
257}
258} // namespace gpr::quantum::ringbath
@ x
Definition Enums.h:28
Bounds boundResponse(const Matrix &B, const Matrix &Q, const Matrix &AQ, double alpha, double shift)
Eigen::Index siteChannel(Eigen::Index sites, Eigen::Index site, Eigen::Index component)
Kernel boundKernel(Potential potential, const Matrix &C, const Matrix &Q, const Matrix &AQ, double alpha, const Vector &shifts)
std::vector< Matrix > projectRing(const Matrix &W, Eigen::Index beads, Eigen::Index d)
double nuclearNorm(const Matrix &M)
Sensitivity logRateSensitivity(const ratepost::Ring &ring, const ratepost::Weights &w, const Kernel &kernel)
Matrix positiveRoot(const Matrix &D)
Eigen::MatrixXd Matrix
Vector matsubaraShifts(Eigen::Index beads, double betaN, double hbar=1)
void requireBlocks(const std::vector< Matrix > &blocks, Eigen::Index beads)
Eigen::VectorXd Vector
Matrix ringMatrix(const std::vector< Matrix > &blocks, Eigen::Index beads)
double modeWeight(Eigen::Index k, Eigen::Index separation, Eigen::Index beads)
std::vector< Matrix > midpoint() const
std::vector< Matrix > upper
std::vector< Matrix > lower