Loading...
Searching...
No Matches
ZeroEnergyGeodesic.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
3
4#include <Eigen/Eigenvalues>
5#include <Eigen/LU>
6#include <algorithm>
7#include <cmath>
8#include <stdexcept>
9
12
13namespace gpr::quantum {
14namespace {
15using V = Eigen::VectorXd;
16using M = Eigen::MatrixXd;
17void require(bool value, const char* message)
18{
19 if (!value) throw std::invalid_argument(message);
20}
21struct MeshGeometry {
22 V tangent, curvature;
23 double speed{}, left{}, right{};
24};
25MeshGeometry meshGeometry(const V& previous, const V& point, const V& next,
26 double left, double right)
27{
28 const double scale = std::max(left, right);
29 left /= scale;
30 right /= scale;
31 const V first =
32 (right / left * (point - previous) + left / right * (next - point)) /
33 (left + right);
34 const V second = 2 * ((next - point) / right - (point - previous) / left) /
35 (left + right);
36 const double speed = first.norm();
37 require(speed > 0 && std::isfinite(speed) && second.allFinite(),
38 "Resolved graded geodesic derivative required");
39 const V tangent = first / speed;
40 const V curvature =
41 (second - tangent.dot(second) * tangent) / (speed * speed);
42 require(curvature.allFinite(), "Finite graded geodesic curvature required");
43 return {tangent, curvature, speed, left, right};
44}
45} // namespace
47 const M& omega, double radius, const std::vector<V>& path,
48 const std::vector<PotentialEvaluation>& native, double stiffness,
49 const std::vector<M>& hessians)
50{
51 return evaluateZeroEnergyGeodesic(omega, radius, path, native, stiffness,
52 hessians, {});
53}
55 const M& omega, double radius, const std::vector<V>& path,
56 const std::vector<PotentialEvaluation>& native, double stiffness,
57 const std::vector<M>& hessians, const std::vector<double>& meshWeights)
58{
59 const auto n = path.size();
60 require(n >= 3 && native.size() == n &&
61 (hessians.empty() || hessians.size() == n),
62 "Matching geodesic nodes and native values required");
63 require(meshWeights.empty() || meshWeights.size() + 1 == n,
64 "One graded mesh weight per geodesic link required");
65 for (double weight: meshWeights)
66 require(weight > 0 && std::isfinite(weight),
67 "Positive finite geodesic mesh weights required");
68 const auto d = path.front().size();
69 const M identity = M::Identity(d, d);
70 require(d > 0 && omega.rows() == d && omega.cols() == d &&
71 omega.allFinite() &&
72 (omega - omega.transpose()).norm() <=
73 1e-12 * std::max(1., omega.norm()) &&
74 radius > 0 && std::isfinite(radius) && stiffness > 0 &&
75 std::isfinite(stiffness),
76 "Positive geodesic well, radius and mesh scale required");
77 Eigen::SelfAdjointEigenSolver<M> spectrum(omega);
78 require(spectrum.info() == Eigen::Success &&
79 spectrum.eigenvalues().minCoeff() > 0,
80 "Positive harmonic well root required");
81 for (std::size_t j = 0; j < n; ++j) {
82 require(path[j].size() == d && path[j].allFinite() &&
83 native[j].gradient.size() == d &&
84 native[j].gradient.allFinite() &&
85 std::isfinite(native[j].energy),
86 "Invalid native geodesic point");
87 if (j + 1 < n && !(native[j].energy > 0))
88 throw std::domain_error(
89 "Interior geodesic nodes must remain in the forbidden region");
90 if (!hessians.empty())
91 require(hessians[j].rows() == d && hessians[j].cols() == d &&
92 hessians[j].allFinite() &&
93 (hessians[j] - hessians[j].transpose()).norm() <
94 1e-12 * std::max(1., hessians[j].norm()),
95 "Invalid geodesic search curvature");
96 }
97 std::vector<double> lengths;
98 std::vector<V> unit;
99 for (std::size_t j = 0; j + 1 < n; ++j) {
100 const V delta = path[j + 1] - path[j];
101 const double length = delta.norm();
102 require(length > 0 && std::isfinite(length),
103 "Distinct finite geodesic nodes required");
104 lengths.push_back(length);
105 unit.push_back(delta / length);
106 }
108 out.residual.assign(n, V::Zero(d));
109 if (!hessians.empty()) {
110 out.lower.assign(n, M::Zero(d, d));
111 out.diagonal = out.lower;
112 out.upper = out.lower;
113 }
114 const double r = path.front().norm();
115 require(r > 0 && std::isfinite(r),
116 "Nonzero harmonic matching cut required");
117 const V radial = path.front() / r, t0 = unit.front();
118 const M pr = identity - radial * radial.transpose();
119 const double p = std::sqrt(2 * native.front().energy),
120 frequency = omega.trace() / d;
121 const V momentum = omega * path.front() - p * t0;
122 const V angular = pr * momentum;
123 out.residual.front() = angular + frequency * (r - radius) * radial;
124 out.momentumResidual = angular.norm();
125 out.radiusResidual = std::abs(r - radius);
126 out.tailPointsOutward = (omega * path.front()).dot(t0) > 0;
127 if (!hessians.empty())
128 for (int side = 0; side < 2; ++side) {
129 const M dq = M((side == 0 ? 1. : 0.) * identity);
130 const M dr = pr * dq / r, dt = (identity - t0 * t0.transpose()) /
131 lengths.front() *
132 ((side == 0 ? -1. : 1.) * identity);
133 const M dm = omega * dq -
134 t0 * native.front().gradient.transpose() * dq / p -
135 p * dt;
136 M block = pr * dm -
137 (momentum.dot(radial) * identity +
138 radial * momentum.transpose()) *
139 dr +
140 frequency * (radial * radial.transpose() * dq +
141 (r - radius) * dr);
142 if (side == 0)
143 out.diagonal.front() = block;
144 else
145 out.upper.front() = block;
146 }
147 for (std::size_t j = 1; j + 1 < n; ++j) {
148 const double a = lengths[j - 1], b = lengths[j], sum = a + b;
149 const V u = unit[j - 1], v = unit[j], both = u + v;
150 const double norm = both.norm();
151 require(norm > 1e-12,
152 "Geodesic links cannot reverse at an interior node");
153 V t = both / norm, kappa = 2 * (v - u) / sum;
154 double mesh = a - b;
155 MeshGeometry graded;
156 if (!meshWeights.empty()) {
157 graded = meshGeometry(path[j - 1], path[j], path[j + 1],
158 meshWeights[j - 1], meshWeights[j]);
159 t = graded.tangent;
160 kappa = graded.curvature;
161 mesh = 2 * (graded.right * a - graded.left * b) /
162 (graded.left + graded.right);
163 }
164 const V g = native[j].gradient;
165 const M projection = identity - t * t.transpose();
166 const V force = projection * g - 2 * native[j].energy * kappa;
167 out.forceResidual = std::max(out.forceResidual, force.norm());
168 out.meshResidual = std::max(out.meshResidual, std::abs(mesh));
169 out.residual[j] = force + stiffness * mesh * t;
170 if (!hessians.empty())
171 for (int side = -1; side <= 1; ++side) {
172 const M prev = M((side == -1 ? 1. : 0.) * identity),
173 here = M((side == 0 ? 1. : 0.) * identity),
174 next = M((side == 1 ? 1. : 0.) * identity);
175 const M du = (identity - u * u.transpose()) / a * (here - prev),
176 dv = (identity - v * v.transpose()) / b * (next - here);
177 M dt = projection * (du + dv) / norm;
178 const Eigen::RowVectorXd dl = u.transpose() * (here - prev) +
179 v.transpose() * (next - here);
180 Eigen::RowVectorXd dc = u.transpose() * (here - prev) -
181 v.transpose() * (next - here);
182 M dk = 2 * (dv - du) / sum - kappa * dl / sum;
183 if (!meshWeights.empty()) {
184 const double hm = graded.left, hp = graded.right,
185 speed = graded.speed;
186 const M dw =
187 (hp / hm * (here - prev) + hm / hp * (next - here)) /
188 (hm + hp);
189 const M dz = 2 * ((next - here) / hp - (here - prev) / hm) /
190 (hm + hp);
191 const V second = 2 *
192 ((path[j + 1] - path[j]) / hp -
193 (path[j] - path[j - 1]) / hm) /
194 (hm + hp);
195 dt = projection * dw / speed;
196 dk = (projection * dz -
197 (second.dot(t) * identity + t * second.transpose()) *
198 dt) /
199 (speed * speed) -
200 2 * kappa * (t.transpose() * dw) / speed;
201 dc = 2 *
202 (hp * u.transpose() * (here - prev) -
203 hm * v.transpose() * (next - here)) /
204 (hm + hp);
205 }
206 const M block = projection * hessians[j] * here -
207 (g.dot(t) * identity + t * g.transpose()) * dt -
208 2 * kappa * g.transpose() * here -
209 2 * native[j].energy * dk +
210 stiffness * (t * dc + mesh * dt);
211 if (side == -1)
212 out.lower[j] = block;
213 else if (side == 0)
214 out.diagonal[j] = block;
215 else
216 out.upper[j] = block;
217 }
218 }
219 const auto last = n - 1;
220 const V t = unit.back(), g = native.back().gradient;
221 const M projection = identity - t * t.transpose();
222 const double length = lengths.back(), energy = native.back().energy;
223 const V transverse = projection * g;
224 out.residual.back() = transverse + (energy / length) * t;
225 out.forceResidual = std::max(out.forceResidual, transverse.norm());
226 out.turningEnergyResidual = std::abs(energy);
227 out.turningPointsInward = g.dot(t) < 0;
228 if (!hessians.empty())
229 for (int side = 0; side < 2; ++side) {
230 const M here = M((side == 1 ? 1. : 0.) * identity);
231 const M delta = M((side == 1 ? 1. : -1.) * identity),
232 dt = projection * delta / length;
233 const Eigen::RowVectorXd dl = t.transpose() * delta;
234 const M block =
235 projection * hessians[last] * here +
236 ((-g.dot(t) + energy / length) * identity - t * g.transpose()) *
237 dt +
238 t * (g.transpose() * here / length -
239 energy * dl / (length * length));
240 if (side == 0)
241 out.lower.back() = block;
242 else
243 out.diagonal.back() = block;
244 }
245 for (const auto& value: out.residual)
246 require(value.allFinite(), "Nonfinite geodesic residual");
247 return out;
248}
250 const ZeroEnergyGeodesicEvaluation& state)
251{
252 const auto n = state.residual.size();
253 require(n >= 3 && state.lower.size() == n && state.diagonal.size() == n &&
254 state.upper.size() == n,
255 "Geodesic Jacobian blocks required");
256 const auto d = state.residual.front().size();
257 require(d > 0, "Nonempty geodesic metric required");
258 for (std::size_t j = 0; j < n; ++j) {
259 require(state.residual[j].size() == d && state.residual[j].allFinite(),
260 "Invalid geodesic Newton source");
261 for (const M* block:
262 {&state.lower[j], &state.diagonal[j], &state.upper[j]})
263 require(
264 block->rows() == d && block->cols() == d && block->allFinite(),
265 "Invalid geodesic Newton block");
266 }
267 std::vector<M> forward(n);
268 std::vector<V> rhs(n), step(n);
269 for (std::size_t j = 0; j < n; ++j) {
270 M pivot = state.diagonal[j];
271 V source = -state.residual[j];
272 if (j) {
273 pivot -= state.lower[j] * forward[j - 1];
274 source -= state.lower[j] * rhs[j - 1];
275 }
276 Eigen::FullPivLU<M> solve(pivot);
277 if (solve.rank() != d)
278 throw std::runtime_error("Unresolved geodesic block pivot");
279 rhs[j] = solve.solve(source);
280 if (j + 1 < n) forward[j] = solve.solve(state.upper[j]);
281 }
282 for (std::size_t j = n; j-- > 0;)
283 step[j] = j + 1 == n ? rhs[j] : V(rhs[j] - forward[j] * step[j + 1]);
284 double error = 0, scale = 0;
285 for (std::size_t j = 0; j < n; ++j) {
286 V r = state.diagonal[j] * step[j] + state.residual[j];
287 if (j) r += state.lower[j] * step[j - 1];
288 if (j + 1 < n) r += state.upper[j] * step[j + 1];
289 error += r.squaredNorm();
290 scale += state.residual[j].squaredNorm();
291 }
292 if (!std::isfinite(error) ||
293 std::sqrt(error) > 1e-8 * std::max(1., std::sqrt(scale)))
294 throw std::runtime_error(
295 "Geodesic step fails its original block equations");
296 return step;
297}
299 const M& omega, double radius, const std::vector<V>& initial,
300 const ZeroEnergyGeodesicPotential& potential,
301 const ZeroEnergyGeodesicOptions& options,
302 const std::function<void(const ZeroEnergyGeodesicResult&)>& retain)
303{
304 require(bool(potential.evaluate) && bool(potential.searchHessians),
305 "Native geodesic value and search-curvature callbacks required");
306 for (double value:
307 {options.forceTolerance, options.momentumTolerance,
308 options.radiusTolerance, options.meshTolerance,
309 options.energyTolerance, options.maximumStep, options.meshStiffness})
310 require(value > 0 && std::isfinite(value),
311 "Positive finite geodesic search scales required");
312 require(options.maximumBacktracks > 0,
313 "Geodesic line search needs at least one trial");
314 std::size_t evaluations = 0, batches = 0, hessians = 0, proposals = 0,
315 rejectedProposals = 0;
316 auto measure = [&](const std::vector<V>& q, bool* observed = nullptr) {
318 result.path = q;
319 result.native = potential.evaluate(q);
320 evaluations += q.size();
321 ++batches;
322 if (observed) *observed = true;
324 omega, radius, q, result.native, options.meshStiffness, {},
325 options.meshWeights);
326 const auto& e = result.evaluation;
327 result.converged = e.tailPointsOutward && e.turningPointsInward &&
328 e.forceResidual <= options.forceTolerance &&
329 e.momentumResidual <= options.momentumTolerance &&
330 e.radiusResidual <= options.radiusTolerance &&
331 e.meshResidual <= options.meshTolerance &&
332 e.turningEnergyResidual <= options.energyTolerance;
333 result.evaluations = evaluations;
334 result.batchEvaluations = batches;
335 result.searchHessianEvaluations = hessians;
336 result.modelProposals = proposals;
337 result.rejectedModelProposals = rejectedProposals;
338 return result;
339 };
340 require(initial.size() >= 3 && initial.front().size() > 0 &&
341 initial.front().allFinite() && radius > 0 &&
342 std::isfinite(radius) && initial.front().norm() > 0,
343 "A finite nonzero initial matching cut is required");
344 auto feasibleInitial = initial;
345 const double initialRadius = feasibleInitial.front().norm();
346 require(
347 std::abs(initialRadius - radius) <= options.maximumStep * (1 + 1e-12),
348 "Initial matching-radius restoration exceeds the native displacement "
349 "bound");
350 feasibleInitial.front() *= radius / initialRadius;
351 auto state = measure(feasibleInitial);
352 if (retain) retain(state);
353 // The merit scales each independent boundary, transverse-force, mesh and
354 // turning-energy equation by its own physical tolerance.
355 for (std::size_t iteration = 0;
356 !state.converged && iteration < options.maximumIterations;
357 ++iteration) {
358 // Momentum and radius have separate physical tolerances. Their merit
359 // uses each trial's tangent frame so a rotated angular residual cannot
360 // acquire the radial constraint's units or tolerance.
361 auto frameNorm = [&](const ZeroEnergyGeodesicResult& point,
362 bool includeTurningEnergy = true) {
363 const auto& q = point.path;
364 const auto& e = point.evaluation;
365 double norm =
366 std::hypot(e.momentumResidual / options.momentumTolerance,
367 e.radiusResidual / options.radiusTolerance);
368 for (std::size_t j = 1; j + 1 < q.size(); ++j) {
369 const V left = (q[j] - q[j - 1]).normalized(),
370 right = (q[j + 1] - q[j]).normalized();
371 const V tangent = options.meshWeights.empty()
372 ? V((left + right).normalized())
373 : meshGeometry(q[j - 1], q[j], q[j + 1],
374 options.meshWeights[j - 1],
375 options.meshWeights[j])
376 .tangent;
377 const double along = e.residual[j].dot(tangent);
378 norm =
379 std::hypot(norm, (e.residual[j] - along * tangent).norm() /
380 options.forceTolerance);
381 norm = std::hypot(norm, along / (options.meshStiffness *
382 options.meshTolerance));
383 }
384 const V chord = q.back() - q[q.size() - 2],
385 tangent = chord.normalized();
386 const double along = e.residual.back().dot(tangent);
387 norm =
388 std::hypot(norm, (e.residual.back() - along * tangent).norm() /
389 options.forceTolerance);
390 return includeTurningEnergy
391 ? std::hypot(norm, along * chord.norm() /
392 options.energyTolerance)
393 : norm;
394 };
395 const double initialFrameNorm = frameNorm(state);
396 const V initialMesh =
397 geodesicMeshConstraints(state.path, options.meshWeights);
398 double trialStepLimit = options.maximumStep;
399 auto attempt = [&](const std::vector<V>& step,
400 std::size_t maximumBacktracks, const V& meshChange,
401 bool returnAfterObservation = false) {
402 double maximum = 0;
403 for (const auto& value: step)
404 maximum = std::max(maximum, value.norm());
405 double scale =
406 maximum > trialStepLimit ? trialStepLimit / maximum : 1.;
407 for (std::size_t trial = 0; trial < maximumBacktracks;
408 ++trial, scale *= .5) {
409 auto q = state.path;
410 for (std::size_t j = 0; j < q.size(); ++j)
411 q[j] += scale * step[j];
412 const double rawRadius = q.front().norm();
413 if (!(rawRadius > 0) || !std::isfinite(rawRadius)) continue;
414 q.front() *= radius / rawRadius;
415 try {
416 q = retractGeodesicMesh(q, options.meshWeights,
417 options.meshTolerance / 16.,
418 initialMesh + scale * meshChange);
419 } catch (const std::domain_error&) {
420 continue;
421 }
422 double displacement = 0;
423 for (std::size_t j = 0; j < q.size(); ++j)
424 displacement =
425 std::max(displacement, (q[j] - state.path[j]).norm());
426 if (displacement > options.maximumStep * (1 + 1e-12)) continue;
427 bool observed = false;
428 try {
429 auto next = measure(q, &observed);
430 if (options.restoreTurningEnergy &&
431 next.evaluation.turningEnergyResidual >
432 options.energyTolerance &&
433 frameNorm(next, false) < initialFrameNorm) {
434 std::vector<ZeroEnergyGeodesicResult> contours;
436 next.path[next.path.size() - 2], next.path.back(),
437 next.native.back(), 0., options.energyTolerance,
438 [&](const V& point) {
439 if ((point - state.path.back()).norm() >
440 options.maximumStep * (1 + 1e-12))
441 throw std::domain_error(
442 "Native contour restoration exceeds "
443 "the displacement bound");
444 auto restored = next.path;
445 restored.back() = point;
446 contours.push_back(measure(restored));
447 return contours.back().native.back();
448 });
449 for (auto& contour: contours) {
450 const auto& e = contour.evaluation;
451 if ((state.evaluation.tailPointsOutward &&
452 !e.tailPointsOutward) ||
453 (state.evaluation.turningPointsInward &&
454 !e.turningPointsInward))
455 continue;
456 if (frameNorm(contour) < frameNorm(next))
457 next = std::move(contour);
458 }
459 }
460 if ((state.evaluation.tailPointsOutward &&
461 !next.evaluation.tailPointsOutward) ||
462 (state.evaluation.turningPointsInward &&
463 !next.evaluation.turningPointsInward)) {
464 if (returnAfterObservation) return false;
465 continue;
466 }
467 if (next.converged || frameNorm(next) < initialFrameNorm) {
468 next.acceptedSteps = state.acceptedSteps + 1;
469 state = std::move(next);
470 if (retain) retain(state);
471 return true;
472 }
473 if (returnAfterObservation) return false;
474 } catch (const std::domain_error&) {
475 if (returnAfterObservation && observed) return false;
476 continue;
477 }
478 }
479 return false;
480 };
481 bool accepted = false;
482 if (potential.propose)
483 for (std::size_t modelTrial = 0; modelTrial < 2 && !accepted;
484 ++modelTrial) {
485 state.evaluations = evaluations;
486 state.batchEvaluations = batches;
487 state.searchHessianEvaluations = hessians;
488 state.modelProposals = proposals;
489 state.rejectedModelProposals = rejectedProposals;
490 const auto proposed = potential.propose(state);
491 if (!proposed.empty()) {
492 require(proposed.size() == state.path.size(),
493 "Geodesic model proposal image count differs");
494 std::vector<V> step;
495 double maximum = 0;
496 for (std::size_t j = 0; j < proposed.size(); ++j) {
497 require(proposed[j].size() == state.path[j].size() &&
498 proposed[j].allFinite(),
499 "Invalid geodesic model proposal metric or "
500 "coordinate");
501 step.push_back(proposed[j] - state.path[j]);
502 maximum = std::max(maximum, step.back().norm());
503 }
504 if (maximum > 0) {
505 ++proposals;
506 try {
507 auto endpoint = proposed;
508 const double endpointRadius =
509 endpoint.front().norm();
510 if (!(endpointRadius > 0) ||
511 !std::isfinite(endpointRadius))
512 throw std::domain_error(
513 "Finite model matching cut required");
514 endpoint.front() *= radius / endpointRadius;
515 const V meshChange =
517 options.meshWeights) -
518 initialMesh;
519 accepted = attempt(step, options.maximumBacktracks,
520 meshChange, true);
521 } catch (const std::domain_error&) {
522 accepted = false;
523 }
524 if (!accepted) {
525 ++rejectedProposals;
526 trialStepLimit =
527 .5 * std::min(trialStepLimit, maximum);
528 }
529 } else
530 break;
531 } else
532 break;
533 }
534 if (!accepted) {
535 trialStepLimit = options.maximumStep;
536 const auto search = potential.searchHessians(state.path);
537 hessians += state.path.size();
538 auto quadratic = evaluateZeroEnergyGeodesic(
539 omega, radius, state.path, state.native, options.meshStiffness,
540 search, options.meshWeights);
541 const auto d = state.path.front().size();
542 const V radial = state.path.front().normalized();
543 const M identity = M::Identity(d, d),
544 projection = identity - radial * radial.transpose();
545 // Parallel transport removes K*r from the Cartesian residual
546 // derivative, where K=dt*t^T-t*dt^T. The resulting Newton equation
547 // decreases the separate physical and mesh residual components.
548 auto transport = [&](M& block, const V& tangent, const V& residual,
549 const M& dt) {
550 const double along = residual.dot(tangent);
551 const V transverse = residual - along * tangent;
552 block += tangent * (transverse.transpose() * dt) - along * dt;
553 };
554 transport(quadratic.diagonal.front(), radial,
555 quadratic.residual.front(),
556 projection / state.path.front().norm());
557 for (std::size_t j = 1; j + 1 < state.path.size(); ++j) {
558 const V previous = state.path[j] - state.path[j - 1],
559 next = state.path[j + 1] - state.path[j];
560 const double a = previous.norm(), b = next.norm();
561 const V u = previous / a, v = next / b, both = u + v;
562 V tangent = both.normalized();
563 MeshGeometry graded;
564 if (!options.meshWeights.empty()) {
565 graded = meshGeometry(
566 state.path[j - 1], state.path[j], state.path[j + 1],
567 options.meshWeights[j - 1], options.meshWeights[j]);
568 tangent = graded.tangent;
569 }
570 const M normal = identity - tangent * tangent.transpose();
571 for (int side = -1; side <= 1; ++side) {
572 const double before = side == -1 ? 1. : 0.,
573 here = side == 0 ? 1. : 0.,
574 after = side == 1 ? 1. : 0.;
575 M dt;
576 if (options.meshWeights.empty()) {
577 const M derivative =
578 (here - before) / a *
579 (identity - u * u.transpose()) +
580 (after - here) / b * (identity - v * v.transpose());
581 dt = (derivative -
582 tangent * (tangent.transpose() * derivative)) /
583 both.norm();
584 } else {
585 const double hm = graded.left, hp = graded.right;
586 const double coefficient = (hp / hm * (here - before) +
587 hm / hp * (after - here)) /
588 (hm + hp);
589 dt = (coefficient / graded.speed) * normal;
590 }
591 M& block = side == -1 ? quadratic.lower[j]
592 : (side == 0 ? quadratic.diagonal[j]
593 : quadratic.upper[j]);
594 transport(block, tangent, quadratic.residual[j], dt);
595 }
596 }
597 const V chord =
598 state.path.back() - state.path[state.path.size() - 2],
599 tangent = chord.normalized();
600 const M turnNormal = identity - tangent * tangent.transpose();
601 transport(quadratic.lower.back(), tangent,
602 quadratic.residual.back(), M(-turnNormal / chord.norm()));
603 transport(quadratic.diagonal.back(), tangent,
604 quadratic.residual.back(), M(turnNormal / chord.norm()));
605 std::vector<V> step;
606 try {
607 step = solveZeroEnergyGeodesicStep(quadratic);
608 } catch (const std::exception& error) {
609 state.failure = error.what();
610 break;
611 }
612 accepted = attempt(step, options.maximumBacktracks, -initialMesh);
613 }
614 if (!accepted) {
615 state.failure =
616 "Native geodesic residual does not decrease along the search "
617 "step";
618 break;
619 }
620 }
621 if (!state.converged && state.failure.empty())
622 state.failure = "Maximum native geodesic iterations reached";
623 state.evaluations = evaluations;
624 state.batchEvaluations = batches;
625 state.searchHessianEvaluations = hessians;
626 state.modelProposals = proposals;
627 state.rejectedModelProposals = rejectedProposals;
628 return state;
629}
630} // namespace gpr::quantum
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.
std::vector< Eigen::VectorXd > retractGeodesicMesh(const std::vector< Eigen::VectorXd > &path, const std::vector< double > &weights, double tolerance, const Eigen::VectorXd &target={})
SphereEnergyProjection projectSphereEnergy(const Eigen::VectorXd &center, const Eigen::VectorXd &point, const PotentialEvaluation &value, double energy, double tolerance, const Evaluate &evaluate, std::size_t maximumIterations=8, std::size_t maximumBacktracks=12)
ZeroEnergyGeodesicResult optimizeZeroEnergyGeodesic(const M &omega, double radius, const std::vector< V > &initial, const ZeroEnergyGeodesicPotential &potential, const ZeroEnergyGeodesicOptions &options, const std::function< void(const ZeroEnergyGeodesicResult &)> &retain)
std::vector< V > solveZeroEnergyGeodesicStep(const ZeroEnergyGeodesicEvaluation &state)
Eigen::VectorXd geodesicMeshConstraints(const std::vector< Eigen::VectorXd > &path, const std::vector< double > &weights={})
ZeroEnergyGeodesicEvaluation evaluateZeroEnergyGeodesic(const M &omega, double radius, const std::vector< V > &path, const std::vector< PotentialEvaluation > &native, double stiffness, const std::vector< M > &hessians)
std::vector< Eigen::MatrixXd > diagonal
std::vector< Eigen::VectorXd > residual
std::function< std::vector< Eigen::MatrixXd >(const std::vector< Eigen::VectorXd > &)> searchHessians
std::function< std::vector< PotentialEvaluation >(const std::vector< Eigen::VectorXd > &)> evaluate
std::function< std::vector< Eigen::VectorXd >(const ZeroEnergyGeodesicResult &)> propose
std::vector< PotentialEvaluation > native
std::vector< Eigen::VectorXd > path
ZeroEnergyGeodesicEvaluation evaluation