56 const std::vector<gaussian::Segment>& segments,
57 const Eigen::MatrixXd& activeBasis,
double unresolvedTolerance = 1e-12)
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))
68 !(unresolvedTolerance >= 0.) || !std::isfinite(unresolvedTolerance))
69 throw std::invalid_argument(
70 "Finite links and an orthonormal proper active subspace are "
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 "
79 Eigen::HouseholderQR<Matrix> qr(activeBasis);
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 "
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;
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;
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 "
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)
170 negative += value < 0.;
171 effectiveLog += std::log(std::abs(value));
174 return {std::move(effective),
217 const Eigen::VectorXd& phaseNormal,
double unresolvedTolerance = 1e-12)
219 using Index = Eigen::Index;
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 "
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(
248 discardedNorm += (fullBlock - reduced.
activeBasis *
249 activeNormal.segment(
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 =
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");
274 std::max(1., eigen.eigenvalues().cwiseAbs().maxCoeff());
278 for (
double value: eigen.eigenvalues()) {
279 if (std::abs(value) <= unresolvedTolerance * scale)
286 logAbs += std::log(std::abs(value));
300 const std::vector<Eigen::MatrixXd>& activeHessians,
301 const Eigen::MatrixXd& coupling,
const Eigen::MatrixXd& bathCurvature,
302 double step,
double unresolvedTolerance = 1e-12)
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());
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");
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());
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)
350 std::cos(2. * std::acos(-1.) * mode * separation / beads) *
352 kernel /=
static_cast<double>(beads);
353 effective.block(i * active, j * active, active, active) =
356 effective.block(i * active, j * active, active, active) +=
357 step * activeHessians[i];
359 effective.block(i * active, j * active, active, active)
361 .array() += 2. / step;
362 if (j == (i + 1) % beads || i == (j + 1) % beads)
363 effective.block(i * active, j * active, active, active)
365 .array() -= 1. / step;
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;
377 std::max(1., eigen.eigenvalues().cwiseAbs().maxCoeff());
378 for (
double value: eigen.eigenvalues()) {
379 if (std::abs(value) <= unresolvedTolerance * scale) {
382 negative += value < 0.;
383 logAbs += std::log(std::abs(value));
386 return std::tuple<double, Eigen::Index, Eigen::Index>{logAbs, negative,
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)
400 bathNegative += value < 0.;
401 bathLogAbs += std::log(std::abs(value));
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};
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)
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());
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");
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))
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);
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) -=
494 effective.block(next * active, bead * active, active, active) -=
495 activeKineticLink.transpose();
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)
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);
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 "
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");
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)
530 negative += value < 0.;
531 effectiveLogAbs += std::log(std::abs(value));
534 return {std::move(effective),
537 bathLogAbs + effectiveLogAbs,
589 double duration,
double unresolvedTolerance = 1e-12)
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 =
602 Eigen::MatrixXd::Identity(fullDimension, fullDimension);
603 const Eigen::MatrixXd tangent = orthogonal.rightCols(fullDimension - 1);
604 const Eigen::MatrixXd restricted =
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");
617 std::max(1., eigen.eigenvalues().cwiseAbs().maxCoeff());
618 for (
double value: eigen.eigenvalues()) {
619 if (std::abs(value) <= unresolvedTolerance * scale) {
626 logAbs += std::log(std::abs(value));