Loading...
Searching...
No Matches
ReducedGaussianGLE.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
6#pragma once
7
8#include <Eigen/Cholesky>
9#include <Eigen/Core>
10#include <Eigen/Eigenvalues>
11#include <Eigen/QR>
12#include <algorithm>
13#include <cmath>
14#include <limits>
15#include <stdexcept>
16#include <tuple>
17#include <vector>
18
21
22namespace gpr::quantum {
24 Eigen::MatrixXd effectiveHessian;
28 Eigen::Index bathNegative{};
29 Eigen::Index effectiveNegative{};
30 Eigen::Index fullNegative{};
31 Eigen::Index bathUnresolved{};
32 Eigen::Index effectiveUnresolved{};
33 Eigen::Index fullUnresolved{};
34};
35
36// Exact finite-path Schur elimination for Gaussian links with nonuniform
37// durations and endpoint curvatures. The retained basis is shared at every
38// bead; the eliminated bath block may vary along the path.
40 Eigen::MatrixXd effectiveHessian;
41 Eigen::MatrixXd activeBasis;
45 Eigen::Index bathDimension{};
46 Eigen::Index activeDimension{};
47 Eigen::Index fullDimension{};
48 Eigen::Index effectiveNegative{};
49 Eigen::Index effectiveUnresolved{};
50 Eigen::Index beads{};
51 Eigen::Index physicalDimension{};
52 double duration{};
53};
54
56 const std::vector<gaussian::Segment>& segments,
57 const Eigen::MatrixXd& activeBasis, double unresolvedTolerance = 1e-12)
58{
59 using Matrix = Eigen::MatrixXd;
60 using Index = Eigen::Index;
61 const Index beads = static_cast<Index>(segments.size());
62 const Index physical = activeBasis.rows(), active = activeBasis.cols();
63 if (beads < 3 || physical <= 1 || active <= 0 || active >= physical ||
64 !activeBasis.allFinite() ||
65 (activeBasis.transpose() * activeBasis -
66 Matrix::Identity(active, active))
67 .norm() > 1e-10 ||
68 !(unresolvedTolerance >= 0.) || !std::isfinite(unresolvedTolerance))
69 throw std::invalid_argument(
70 "Finite links and an orthonormal proper active subspace are "
71 "required");
72 const Index bath = physical - active, activeTotal = beads * active,
73 bathTotal = beads * bath;
74 if (beads > std::numeric_limits<Index>::max() / physical ||
75 beads * physical > 16384 || bathTotal > 8192)
76 throw std::length_error(
77 "Finite Gaussian segment reduction exceeds its dense factorization "
78 "limit");
79 Eigen::HouseholderQR<Matrix> qr(activeBasis);
80 const Matrix orthogonal =
81 qr.householderQ() * Matrix::Identity(physical, physical);
82 const Matrix bathBasis = orthogonal.rightCols(bath);
83 Matrix aa = Matrix::Zero(activeTotal, activeTotal);
84 Matrix ab = Matrix::Zero(activeTotal, bathTotal);
85 Matrix bb = Matrix::Zero(bathTotal, bathTotal);
86 double duration = 0., linkNormalization = 0.;
87 for (Index i = 0; i < beads; ++i) {
88 const auto& link = segments[static_cast<std::size_t>(i)];
89 const Index j = (i + 1) % beads;
90 const auto& right = link.rightEndpoint();
91 if (link.A.rows() != physical || link.A.cols() != physical ||
92 right.rows() != physical || right.cols() != physical ||
93 link.L.rows() != physical || link.L.cols() != physical ||
94 !link.A.allFinite() || !right.allFinite() || !link.L.allFinite() ||
95 !std::isfinite(link.logDetL) || !(link.duration > 0.) ||
96 !std::isfinite(link.duration))
97 throw std::invalid_argument(
98 "Gaussian links must match the active-space physical "
99 "dimension");
100 const Matrix aaLeft = activeBasis.transpose() * link.A * activeBasis;
101 const Matrix aaRight = activeBasis.transpose() * right * activeBasis;
102 const Matrix aaCross = activeBasis.transpose() * link.L * activeBasis;
103 const Matrix abLeft = activeBasis.transpose() * link.A * bathBasis;
104 const Matrix abRight = activeBasis.transpose() * right * bathBasis;
105 const Matrix abCross = activeBasis.transpose() * link.L * bathBasis;
106 const Matrix baCross =
107 activeBasis.transpose() * link.L.transpose() * bathBasis;
108 const Matrix bbLeft = bathBasis.transpose() * link.A * bathBasis;
109 const Matrix bbRight = bathBasis.transpose() * right * bathBasis;
110 const Matrix bbCross = bathBasis.transpose() * link.L * bathBasis;
111 aa.block(i * active, i * active, active, active) += aaLeft;
112 aa.block(j * active, j * active, active, active) += aaRight;
113 aa.block(i * active, j * active, active, active) -= aaCross;
114 aa.block(j * active, i * active, active, active) -= aaCross.transpose();
115 ab.block(i * active, i * bath, active, bath) += abLeft;
116 ab.block(j * active, j * bath, active, bath) += abRight;
117 ab.block(i * active, j * bath, active, bath) -= abCross;
118 ab.block(j * active, i * bath, active, bath) -= baCross;
119 bb.block(i * bath, i * bath, bath, bath) += bbLeft;
120 bb.block(j * bath, j * bath, bath, bath) += bbRight;
121 bb.block(i * bath, j * bath, bath, bath) -= bbCross;
122 bb.block(j * bath, i * bath, bath, bath) -= bbCross.transpose();
123 duration += link.duration;
124 linkNormalization += link.logDetL;
125 }
126 const double symmetryTolerance = 128 *
127 std::numeric_limits<double>::epsilon() *
128 std::max({1., aa.norm(), bb.norm()});
129 if (!aa.allFinite() || !ab.allFinite() || !bb.allFinite() ||
130 (aa - aa.transpose()).norm() > symmetryTolerance ||
131 (bb - bb.transpose()).norm() > symmetryTolerance ||
132 !std::isfinite(duration) || !std::isfinite(linkNormalization))
133 throw std::runtime_error(
134 "Assembled Gaussian segment blocks are not finite and symmetric");
135 aa = (.5 * aa + .5 * aa.transpose()).eval();
136 bb = (.5 * bb + .5 * bb.transpose()).eval();
137 Eigen::LLT<Matrix> bathFactor(bb);
138 if (bathFactor.info() != Eigen::Success)
139 throw std::domain_error(
140 "The finite-path eliminated Gaussian bath is not positive "
141 "definite");
142 const Matrix diagonal = bathFactor.matrixL().toDenseMatrix().diagonal();
143 const double scale = std::max(1., bb.cwiseAbs().maxCoeff());
144 if ((diagonal.array() <= std::sqrt(unresolvedTolerance * scale)).any())
145 throw std::domain_error(
146 "The finite-path eliminated Gaussian bath is unresolved");
147 const double bathLog = 2. * diagonal.array().log().sum();
148 const Matrix response = bathFactor.solve(ab.transpose());
149 if (bathFactor.info() != Eigen::Success || !response.allFinite())
150 throw std::runtime_error("Finite-path bath response solve failed");
151 Matrix effective = aa - ab * response;
152 if (!effective.allFinite() ||
153 (effective - effective.transpose()).norm() > symmetryTolerance)
154 throw std::runtime_error(
155 "Finite-path reduced Gaussian exceeds symmetry tolerance");
156 effective = (.5 * effective + .5 * effective.transpose()).eval();
157 Eigen::SelfAdjointEigenSolver<Matrix> eigen(effective,
158 Eigen::EigenvaluesOnly);
159 if (eigen.info() != Eigen::Success || !eigen.eigenvalues().allFinite())
160 throw std::runtime_error(
161 "Finite-path reduced Gaussian eigensolve failed");
162 const double effectiveScale =
163 std::max(1., eigen.eigenvalues().cwiseAbs().maxCoeff());
164 double effectiveLog = 0.;
165 Index negative = 0, unresolved = 0;
166 for (double value: eigen.eigenvalues()) {
167 if (std::abs(value) <= unresolvedTolerance * effectiveScale)
168 ++unresolved;
169 else {
170 negative += value < 0.;
171 effectiveLog += std::log(std::abs(value));
172 }
173 }
174 return {std::move(effective),
175 activeBasis,
176 bathLog,
177 effectiveLog,
178 linkNormalization,
179 bathTotal,
180 active,
181 beads * physical,
182 negative,
183 unresolved,
184 beads,
185 physical,
186 duration};
187}
188
190 const ReducedGaussianSegmentResult& reduced)
191{
192 if (reduced.fullDimension <= 0 || reduced.bathDimension <= 0 ||
193 reduced.activeDimension <= 0 || reduced.effectiveHessian.rows() <= 0 ||
194 reduced.effectiveHessian.rows() != reduced.effectiveHessian.cols() ||
195 !(reduced.duration > 0.) || !std::isfinite(reduced.duration))
196 throw std::invalid_argument(
197 "A finite reduced Gaussian segment result is required");
199 trace.dimension = reduced.fullDimension;
200 trace.duration = reduced.duration;
201 trace.inertia.positive = static_cast<std::size_t>(
202 reduced.bathDimension + reduced.effectiveHessian.rows() -
203 reduced.effectiveNegative - reduced.effectiveUnresolved);
204 trace.inertia.negative =
205 static_cast<std::size_t>(reduced.effectiveNegative);
206 trace.inertia.zero = static_cast<std::size_t>(reduced.effectiveUnresolved);
207 if (!trace.inertia.zero)
211 return trace;
212}
213
214inline gaussian::TwistedRestrictedResult
216 const ReducedGaussianSegmentResult& reduced,
217 const Eigen::VectorXd& phaseNormal, double unresolvedTolerance = 1e-12)
218{
219 using Index = Eigen::Index;
220 const Index full = reduced.fullDimension;
221 const Index activeTotal = reduced.effectiveHessian.rows();
222 if (full <= 1 || activeTotal <= 1 || reduced.activeDimension <= 0 ||
223 reduced.beads < 3 ||
224 reduced.physicalDimension <= reduced.activeDimension ||
225 reduced.activeBasis.rows() != reduced.physicalDimension ||
226 reduced.activeBasis.cols() != reduced.activeDimension ||
227 phaseNormal.size() != full || !phaseNormal.allFinite() ||
228 std::abs(phaseNormal.squaredNorm() - 1.) > 1e-12 ||
229 !(reduced.duration > 0.) || !(unresolvedTolerance >= 0.) ||
230 !std::isfinite(unresolvedTolerance))
231 throw std::invalid_argument(
232 "A unit full-path phase normal and finite reduced result are "
233 "required");
234 if (reduced.beads * reduced.activeDimension != activeTotal ||
235 reduced.beads * reduced.physicalDimension != full ||
236 reduced.bathDimension != reduced.beads * (reduced.physicalDimension -
237 reduced.activeDimension))
238 throw std::invalid_argument(
239 "Reduced active and full-path dimensions differ");
240 Eigen::VectorXd activeNormal(activeTotal);
241 double discardedNorm = 0.;
242 for (Index bead = 0; bead < reduced.beads; ++bead) {
243 const auto fullBlock = phaseNormal.segment(
244 bead * reduced.physicalDimension, reduced.physicalDimension);
245 activeNormal.segment(bead * reduced.activeDimension,
246 reduced.activeDimension) =
247 reduced.activeBasis.transpose() * fullBlock;
248 discardedNorm += (fullBlock - reduced.activeBasis *
249 activeNormal.segment(
250 bead * reduced.activeDimension,
251 reduced.activeDimension))
252 .squaredNorm();
253 }
254 if (discardedNorm > 1e-20 ||
255 std::abs(activeNormal.squaredNorm() - 1.) > 1e-12)
256 throw std::invalid_argument(
257 "The phase normal must lie in the retained active subspace");
258 Eigen::HouseholderQR<Eigen::MatrixXd> qr(activeNormal);
259 const Eigen::MatrixXd q =
260 qr.householderQ() * Eigen::MatrixXd::Identity(activeTotal, activeTotal);
261 const Eigen::MatrixXd tangent = q.rightCols(activeTotal - 1);
262 const Eigen::MatrixXd restricted =
263 tangent.transpose() * reduced.effectiveHessian * tangent;
264 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eigen(
265 restricted, Eigen::EigenvaluesOnly);
266 if (eigen.info() != Eigen::Success || !eigen.eigenvalues().allFinite())
267 throw std::runtime_error(
268 "Finite-path restricted Gaussian eigensolve failed");
270 trace.dimension = activeTotal - 1 + reduced.bathDimension;
271 trace.codimension = 1;
272 trace.duration = reduced.duration;
273 const double scale =
274 std::max(1., eigen.eigenvalues().cwiseAbs().maxCoeff());
275 double logAbs =
277 trace.inertia.positive = static_cast<std::size_t>(reduced.bathDimension);
278 for (double value: eigen.eigenvalues()) {
279 if (std::abs(value) <= unresolvedTolerance * scale)
281 else {
282 if (value > 0.)
283 ++trace.inertia.positive;
284 else
285 ++trace.inertia.negative;
286 logAbs += std::log(std::abs(value));
287 }
288 }
289 if (!trace.unresolvedBorderEigenvalues) trace.logAbsNormalizedDet = logAbs;
290 return trace;
291}
292
293// Eliminates a positive harmonic environment from a periodic, mass-weighted
294// finite-bead action. activeHessians[j] is the statically relaxed active
295// curvature A_j in V_ad(x) + 1/2 (y-E^-1 C^T x)^T E (y-E^-1 C^T x).
296// The returned active Hessian includes the exact discrete Matsubara memory
297// kernel; its determinant combines with the bath determinant to equal the
298// determinant of the unreduced full-coordinate action.
300 const std::vector<Eigen::MatrixXd>& activeHessians,
301 const Eigen::MatrixXd& coupling, const Eigen::MatrixXd& bathCurvature,
302 double step, double unresolvedTolerance = 1e-12)
303{
304 using Matrix = Eigen::MatrixXd;
305 const Eigen::Index beads = static_cast<Eigen::Index>(activeHessians.size());
306 const Eigen::Index active = coupling.rows(), bath = coupling.cols();
307 auto symmetric = [](const Matrix& matrix) {
308 return (matrix - matrix.transpose()).norm() <=
309 1e-12 * std::max(1., matrix.norm());
310 };
311 if (beads < 3 || active <= 0 || bath <= 0 || bathCurvature.rows() != bath ||
312 bathCurvature.cols() != bath || !coupling.allFinite() ||
313 !bathCurvature.allFinite() || !symmetric(bathCurvature) ||
314 !(step > 0.) || !std::isfinite(step) || !(unresolvedTolerance >= 0.) ||
315 !std::isfinite(unresolvedTolerance))
316 throw std::invalid_argument(
317 "Finite periodic action, coupling and symmetric bath required");
318 for (const auto& hessian: activeHessians)
319 if (hessian.rows() != active || hessian.cols() != active ||
320 !hessian.allFinite() || !symmetric(hessian))
321 throw std::invalid_argument(
322 "Matching finite symmetric active Hessians required");
323
324 Eigen::SelfAdjointEigenSolver<Matrix> bathEigen(bathCurvature);
325 if (bathEigen.info() != Eigen::Success ||
326 bathEigen.eigenvalues().minCoeff() <= 0.)
327 throw std::invalid_argument("The eliminated GLE bath must be positive");
328 const auto& frequencies = bathEigen.eigenvalues();
329 const Matrix modalCoupling = coupling * bathEigen.eigenvectors();
330 std::vector<Matrix> memory;
331 memory.reserve(static_cast<std::size_t>(beads));
332 for (Eigen::Index mode = 0; mode < beads; ++mode) {
333 const double sine = std::sin(std::acos(-1.) * mode / beads);
334 const double lambda = 4. * sine * sine / (step * step);
335 Eigen::VectorXd weights(bath);
336 for (Eigen::Index k = 0; k < bath; ++k)
337 weights[k] = lambda / (frequencies[k] * (frequencies[k] + lambda));
338 memory.push_back(modalCoupling * weights.asDiagonal() *
339 modalCoupling.transpose());
340 }
341
342 const Eigen::Index dimension = beads * active;
343 Matrix effective = Matrix::Zero(dimension, dimension);
344 for (Eigen::Index i = 0; i < beads; ++i) {
345 for (Eigen::Index j = 0; j < beads; ++j) {
346 const Eigen::Index separation = (j - i + beads) % beads;
347 Matrix kernel = Matrix::Zero(active, active);
348 for (Eigen::Index mode = 0; mode < beads; ++mode)
349 kernel.noalias() +=
350 std::cos(2. * std::acos(-1.) * mode * separation / beads) *
351 memory[mode];
352 kernel /= static_cast<double>(beads);
353 effective.block(i * active, j * active, active, active) =
354 step * kernel;
355 if (i == j)
356 effective.block(i * active, j * active, active, active) +=
357 step * activeHessians[i];
358 if (i == j)
359 effective.block(i * active, j * active, active, active)
360 .diagonal()
361 .array() += 2. / step;
362 if (j == (i + 1) % beads || i == (j + 1) % beads)
363 effective.block(i * active, j * active, active, active)
364 .diagonal()
365 .array() -= 1. / step;
366 }
367 }
368
369 const auto inertiaAndLogAbs = [unresolvedTolerance](const Matrix& matrix) {
370 Eigen::SelfAdjointEigenSolver<Matrix> eigen(matrix,
371 Eigen::EigenvaluesOnly);
372 if (eigen.info() != Eigen::Success || !eigen.eigenvalues().allFinite())
373 throw std::runtime_error("Periodic Gaussian GLE eigensolve failed");
374 Eigen::Index negative = 0, unresolved = 0;
375 double logAbs = 0.;
376 const double scale =
377 std::max(1., eigen.eigenvalues().cwiseAbs().maxCoeff());
378 for (double value: eigen.eigenvalues()) {
379 if (std::abs(value) <= unresolvedTolerance * scale) {
380 ++unresolved;
381 } else {
382 negative += value < 0.;
383 logAbs += std::log(std::abs(value));
384 }
385 }
386 return std::tuple<double, Eigen::Index, Eigen::Index>{logAbs, negative,
387 unresolved};
388 };
389
390 double bathLogAbs = 0.;
391 Eigen::Index bathNegative = 0, bathUnresolved = 0;
392 for (Eigen::Index mode = 0; mode < beads; ++mode) {
393 const double sine = std::sin(std::acos(-1.) * mode / beads);
394 const double lambda = 4. * sine * sine / (step * step);
395 for (Eigen::Index k = 0; k < bath; ++k) {
396 const double value = step * (frequencies[k] + lambda);
397 if (std::abs(value) <= unresolvedTolerance)
398 ++bathUnresolved;
399 else {
400 bathNegative += value < 0.;
401 bathLogAbs += std::log(std::abs(value));
402 }
403 }
404 }
405 const auto [effectiveLogAbs, effectiveNegative, effectiveUnresolved] =
406 inertiaAndLogAbs(effective);
407 const Eigen::Index fullNegative = bathNegative + effectiveNegative;
408 const Eigen::Index fullUnresolved = bathUnresolved + effectiveUnresolved;
409 return {std::move(effective), bathLogAbs,
410 effectiveLogAbs, bathLogAbs + effectiveLogAbs,
411 bathNegative, effectiveNegative,
412 fullNegative, bathUnresolved,
413 effectiveUnresolved, fullUnresolved};
414}
415
416// Eliminates a frozen positive bath for a cyclic Gaussian action with a
417// matrix-valued kinetic link. The full action blocks at Fourier mode k are
418// h*H_A + ell_k*L_AA, h*C + ell_k*L_AB, and h*H_B + ell_k*L_BB, where
419// ell_k=2*(1-cos(2*pi*k/N)). This preserves frequency-fitted kinetic links,
420// whose active-bath coupling cannot be represented by a scalar Matsubara
421// memory term.
423 const std::vector<Eigen::MatrixXd>& activeHessians,
424 const Eigen::MatrixXd& coupling, const Eigen::MatrixXd& bathCurvature,
425 const Eigen::MatrixXd& activeKineticLink,
426 const Eigen::MatrixXd& activeBathKineticLink,
427 const Eigen::MatrixXd& bathKineticLink, double step,
428 double unresolvedTolerance = 1e-12)
429{
430 using Matrix = Eigen::MatrixXd;
431 using Index = Eigen::Index;
432 const Index beads = static_cast<Index>(activeHessians.size());
433 const Index active = coupling.rows(), bath = coupling.cols();
434 auto symmetric = [](const Matrix& matrix) {
435 return (matrix - matrix.transpose()).norm() <=
436 1e-12 * std::max(1., matrix.norm());
437 };
438 if (beads < 3 || active <= 0 || bath <= 0 || bathCurvature.rows() != bath ||
439 bathCurvature.cols() != bath || activeKineticLink.rows() != active ||
440 activeKineticLink.cols() != active ||
441 activeBathKineticLink.rows() != active ||
442 activeBathKineticLink.cols() != bath ||
443 bathKineticLink.rows() != bath || bathKineticLink.cols() != bath ||
444 !coupling.allFinite() || !bathCurvature.allFinite() ||
445 !activeKineticLink.allFinite() || !activeBathKineticLink.allFinite() ||
446 !bathKineticLink.allFinite() || !symmetric(bathCurvature) ||
447 !symmetric(activeKineticLink) || !symmetric(bathKineticLink) ||
448 !(step > 0.) || !std::isfinite(step) || !(unresolvedTolerance >= 0.) ||
449 !std::isfinite(unresolvedTolerance))
450 throw std::invalid_argument(
451 "Finite periodic active, bath and kinetic blocks are required");
452 for (const auto& hessian: activeHessians)
453 if (hessian.rows() != active || hessian.cols() != active ||
454 !hessian.allFinite() || !symmetric(hessian))
455 throw std::invalid_argument(
456 "Matching finite symmetric active curvatures are required");
457
458 const Index dimension = beads * active;
459 Matrix effective = Matrix::Zero(dimension, dimension);
460 std::vector<Matrix> schurModes;
461 schurModes.reserve(static_cast<std::size_t>(beads));
462 double bathLogAbs = 0.;
463 for (Index mode = 0; mode < beads; ++mode) {
464 const double angle = 2. * std::acos(-1.) * mode / beads;
465 const double ell = 2. * (1. - std::cos(angle));
466 const Matrix bathBlock = step * bathCurvature + ell * bathKineticLink;
467 Eigen::LLT<Matrix> factor(bathBlock);
468 if (factor.info() != Eigen::Success)
469 throw std::domain_error(
470 "Frequency-mode Gaussian GLE bath is not positive definite");
471 const Matrix diagonal = factor.matrixL().toDenseMatrix();
472 const double scale = std::max(1., bathBlock.cwiseAbs().maxCoeff());
473 if ((diagonal.diagonal().array() <=
474 std::sqrt(unresolvedTolerance * scale))
475 .any())
476 throw std::domain_error(
477 "Frequency-mode Gaussian GLE bath is unresolved");
478 bathLogAbs += 2. * diagonal.diagonal().array().log().sum();
479 const Matrix cross = step * coupling + ell * activeBathKineticLink;
480 const Matrix response = factor.solve(cross.transpose());
481 if (factor.info() != Eigen::Success || !response.allFinite())
482 throw std::runtime_error(
483 "Frequency-mode Gaussian GLE bath solve failed");
484 schurModes.push_back(cross * response);
485 }
486
487 for (Index bead = 0; bead < beads; ++bead) {
488 const Index next = (bead + 1) % beads;
489 effective.block(bead * active, bead * active, active, active) +=
490 step * activeHessians[static_cast<std::size_t>(bead)] +
491 2. * activeKineticLink;
492 effective.block(bead * active, next * active, active, active) -=
493 activeKineticLink;
494 effective.block(next * active, bead * active, active, active) -=
495 activeKineticLink.transpose();
496 }
497 for (Index i = 0; i < beads; ++i)
498 for (Index j = 0; j < beads; ++j) {
499 const Index separation = (j - i + beads) % beads;
500 Matrix block = Matrix::Zero(active, active);
501 for (Index mode = 0; mode < beads; ++mode)
502 block.noalias() +=
503 std::cos(2. * std::acos(-1.) * mode * separation / beads) *
504 schurModes[static_cast<std::size_t>(mode)];
505 effective.block(i * active, j * active, active, active) -=
506 block / static_cast<double>(beads);
507 }
508 const double symmetryTolerance = 128. *
509 std::numeric_limits<double>::epsilon() *
510 std::max(1., effective.norm());
511 if (!effective.allFinite() ||
512 (effective - effective.transpose()).norm() > symmetryTolerance)
513 throw std::runtime_error(
514 "Reduced frequency-fitted GLE precision exceeds symmetry "
515 "tolerance");
516 effective = (.5 * effective + .5 * effective.transpose()).eval();
517 Eigen::SelfAdjointEigenSolver<Matrix> eigen(effective,
518 Eigen::EigenvaluesOnly);
519 if (eigen.info() != Eigen::Success || !eigen.eigenvalues().allFinite())
520 throw std::runtime_error(
521 "Reduced frequency-fitted GLE eigensolve failed");
522 const double scale =
523 std::max(1., eigen.eigenvalues().cwiseAbs().maxCoeff());
524 Index negative = 0, unresolved = 0;
525 double effectiveLogAbs = 0.;
526 for (const double value: eigen.eigenvalues()) {
527 if (std::abs(value) <= unresolvedTolerance * scale)
528 ++unresolved;
529 else {
530 negative += value < 0.;
531 effectiveLogAbs += std::log(std::abs(value));
532 }
533 }
534 return {std::move(effective),
535 bathLogAbs,
536 effectiveLogAbs,
537 bathLogAbs + effectiveLogAbs,
538 0,
539 negative,
540 negative,
541 0,
542 unresolved,
543 unresolved};
544}
545
546// Builds the active reactant trace used in a saddle-family rate ratio. The
547// eliminated-bath determinant is reported by the reduction result and cancels
548// only when the same E and C define the saddle and reactant integrations.
550 const ReducedGaussianGLEResult& reduced, double duration,
551 double unresolvedTolerance = 1e-12)
552{
553 const Eigen::Index dimension = reduced.effectiveHessian.rows();
554 if (dimension <= 0 || reduced.effectiveHessian.cols() != dimension ||
555 !(duration > 0.) || !std::isfinite(duration) ||
556 !(unresolvedTolerance >= 0.) || !std::isfinite(unresolvedTolerance))
557 throw std::invalid_argument(
558 "Finite reduced Gaussian trace and duration required");
559 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eigen(
560 reduced.effectiveHessian, Eigen::EigenvaluesOnly);
561 if (eigen.info() != Eigen::Success || !eigen.eigenvalues().allFinite())
562 throw std::runtime_error("Reduced Gaussian trace eigensolve failed");
564 trace.dimension = dimension;
565 trace.duration = duration;
566 for (double value: eigen.eigenvalues()) {
567 if (std::abs(value) <=
568 unresolvedTolerance *
569 std::max(1., eigen.eigenvalues().cwiseAbs().maxCoeff())) {
571 ++trace.inertia.zero;
572 } else {
573 if (value > 0.)
574 ++trace.inertia.positive;
575 else
576 ++trace.inertia.negative;
577 }
578 }
579 if (!trace.unresolvedSchurEigenvalues && !trace.inertia.negative)
581 return trace;
582}
583
584// Restricts the reduced active ring Hessian to the supplied unit phase plane.
585// The phase normal must lie entirely in the retained active coordinates so
586// its coarea Jacobian is unchanged by bath integration.
588 const ReducedGaussianGLEResult& reduced, const Eigen::VectorXd& phaseNormal,
589 double duration, double unresolvedTolerance = 1e-12)
590{
591 const Eigen::Index fullDimension = reduced.effectiveHessian.rows();
592 if (fullDimension < 2 || reduced.effectiveHessian.cols() != fullDimension ||
593 phaseNormal.size() != fullDimension || !phaseNormal.allFinite() ||
594 std::abs(phaseNormal.squaredNorm() - 1.) > 1e-12 || !(duration > 0.) ||
595 !std::isfinite(duration) || !(unresolvedTolerance >= 0.) ||
596 !std::isfinite(unresolvedTolerance))
597 throw std::invalid_argument(
598 "Finite reduced Gaussian ring and unit phase normal required");
599 Eigen::HouseholderQR<Eigen::MatrixXd> qr(phaseNormal);
600 Eigen::MatrixXd orthogonal =
601 qr.householderQ() *
602 Eigen::MatrixXd::Identity(fullDimension, fullDimension);
603 const Eigen::MatrixXd tangent = orthogonal.rightCols(fullDimension - 1);
604 const Eigen::MatrixXd restricted =
605 tangent.transpose() * reduced.effectiveHessian * tangent;
606 Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eigen(
607 restricted, Eigen::EigenvaluesOnly);
608 if (eigen.info() != Eigen::Success || !eigen.eigenvalues().allFinite())
609 throw std::runtime_error(
610 "Reduced restricted Gaussian eigensolve failed");
612 trace.dimension = fullDimension - 1;
613 trace.codimension = 1;
614 trace.duration = duration;
615 double logAbs = 0.;
616 const double scale =
617 std::max(1., eigen.eigenvalues().cwiseAbs().maxCoeff());
618 for (double value: eigen.eigenvalues()) {
619 if (std::abs(value) <= unresolvedTolerance * scale) {
621 } else {
622 if (value > 0.)
623 ++trace.inertia.positive;
624 else
625 ++trace.inertia.negative;
626 logAbs += std::log(std::abs(value));
627 }
628 }
629 if (!trace.unresolvedBorderEigenvalues) trace.logAbsNormalizedDet = logAbs;
630 return trace;
631}
632} // namespace gpr::quantum
Models for quantum-path (instanton) searches: arc and tail actions, amplitude continuation.
gaussian::TwistedRestrictedResult reducedGaussianSegmentGLERestrictedTrace(const ReducedGaussianSegmentResult &reduced, const Eigen::VectorXd &phaseNormal, double unresolvedTolerance=1e-12)
gaussian::TwistedTraceResult reducedGaussianGLETrace(const ReducedGaussianGLEResult &reduced, double duration, double unresolvedTolerance=1e-12)
Eigen::MatrixXd Matrix
ReducedGaussianSegmentResult reduceGaussianSegmentsGLE(const std::vector< gaussian::Segment > &segments, const Eigen::MatrixXd &activeBasis, double unresolvedTolerance=1e-12)
ReducedGaussianGLEResult reducePeriodicGaussianGLE(const std::vector< Eigen::MatrixXd > &activeHessians, const Eigen::MatrixXd &coupling, const Eigen::MatrixXd &bathCurvature, double step, double unresolvedTolerance=1e-12)
gaussian::TwistedRestrictedResult reducedGaussianGLERestrictedTrace(const ReducedGaussianGLEResult &reduced, const Eigen::VectorXd &phaseNormal, double duration, double unresolvedTolerance=1e-12)
gaussian::TwistedTraceResult reducedGaussianSegmentGLETrace(const ReducedGaussianSegmentResult &reduced)