Loading...
Searching...
No Matches
CapnProtoManager.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4
5#include "CapnProtoManager.h"
6
7#include <capnp/any.h>
8#include <fcntl.h>
9#include <sys/mman.h>
10#include <sys/stat.h>
11#include <unistd.h>
12
13#include <array>
14
15#include "gpr/Enums.h"
16#include "schema/gprd_params.capnp.h"
17
18namespace gpr::io {
19
20void loadParametersFromCapnp(const std::string& binary_filename,
21 gpr::InputParameters& parameters)
22{
23 int fd = open(binary_filename.c_str(), O_RDONLY);
24 if (fd < 0) {
25 throw std::runtime_error("Error: Could not open file: " +
26 binary_filename);
27 }
28
29 struct stat file_stats;
30 if (fstat(fd, &file_stats) < 0) {
31 close(fd);
32 throw std::runtime_error("Error: Could not get file stats for: " +
33 binary_filename);
34 }
35 off_t size = file_stats.st_size;
36
37 if (size == 0) {
38 close(fd);
39 throw std::runtime_error("Error: Input file is empty: " +
40 binary_filename);
41 }
42 const void* mapped_ptr = mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0);
43 if (mapped_ptr == MAP_FAILED) {
44 close(fd);
45 throw std::runtime_error("Error: Could not mmap file: " +
46 binary_filename);
47 }
48
49 kj::ArrayPtr<const capnp::word> wordPtr(
50 reinterpret_cast<const capnp::word*>(mapped_ptr),
51 size / sizeof(capnp::word));
52 capnp::FlatArrayMessageReader reader(wordPtr);
53 auto paramsReader = reader.getRoot<::InputParameters>();
54
55 // --- Adapt from Cap'n Proto reader to gpr::InputParameters ---
56
57 // --- Run Selector ---
58 auto runSelectorReader = paramsReader.getRunSelector();
59 parameters.i_dist.value = runSelectorReader.getIDist();
60 parameters.i_run.value = runSelectorReader.getIRun();
61 auto sepDistsReader = runSelectorReader.getSepDists();
62 for (size_t i = 0; i < sepDistsReader.size() && i < 4; ++i) {
63 parameters.dist_sp.value[i] = sepDistsReader[i];
64 }
65
66 // --- Problem Group ---
67 auto problemReader = paramsReader.getProblem();
68 parameters.actdist_fro.value = problemReader.getActdistFro();
69 parameters.dimer_sep.value = problemReader.getDimerSep();
70 if (problemReader.getMethodRot() == DimerOptimizer::LBFGS)
71 parameters.method_rot.value = "LBFGS_alg";
72 if (problemReader.getMethodTrans() == DimerOptimizer::LBFGS)
73 parameters.method_trans.value = "LBFGS_alg";
74
75 auto paramTransReader = problemReader.getParamTrans();
76 parameters.param_trans.value[0] = paramTransReader.getStepLength();
77 parameters.param_trans.value[1] = paramTransReader.getMaxStepLength();
79 paramTransReader.getRotremThresh();
80
81 // Final convergence on the true PES
82 parameters.T_dimer.value = problemReader.getFinalConvergenceForce();
83
84 // Initial rotations phase
85 auto initialRotationsReader = problemReader.getInitialRotations();
86 parameters.num_iter_initrot.value =
87 initialRotationsReader.getMaxIterations();
88 // Note the inversion: initrot_nogp=1 means NO GP, so useGpr=false
89 parameters.initrot_nogp.value = initialRotationsReader.getUseGpr() ? 0 : 1;
90 parameters.T_anglerot_init.value =
91 initialRotationsReader.getConvergenceAngle();
92
93 // Main relaxation phase
94 auto relaxationReader = problemReader.getRelaxation();
95 parameters.num_bigiter.value = relaxationReader.getMaxOuterIterations();
96 parameters.num_iter.value = relaxationReader.getMaxInnerIterations();
97 parameters.num_iter_rot_gp.value =
98 relaxationReader.getMaxRotationIterations();
99 parameters.num_bigiter_initloc.value =
100 relaxationReader.getWarmupFromInitialLocation();
101 parameters.num_bigiter_initparam.value =
102 relaxationReader.getWarmupFromInitHyperparameters();
103 parameters.islarge_num_iter.value =
104 relaxationReader.getAssumeManyIterations() ? 1 : 0;
105 // 'inittrans_nogp' has no gpr::InputParameters field.
106
107 auto relaxationConvergenceReader = relaxationReader.getConvergence();
108 parameters.T_anglerot_gp.value = relaxationConvergenceReader.getAngle();
109 // gpr::InputParameters uses T_dimer for the relaxation force criterion.
110
111 // Other problem parameters
112 parameters.divisor_T_dimer_gp.value = problemReader.getDivisorTdimerGP();
113 parameters.disp_max.value = problemReader.getMidpointMaxDisp();
114 parameters.ratio_at_limit.value = problemReader.getRatioAtLimit();
115
116 // Convergence force norm
117 switch (problemReader.getConvergenceForceNorm()) {
118 case (::ConvergenceForceNorm::L2_NORM):
119 parameters.convergence_force_norm.value = 0;
120 break;
121 case (::ConvergenceForceNorm::LINF_NORM):
122 parameters.convergence_force_norm.value = 1;
123 break;
124 case (::ConvergenceForceNorm::MAX_FORCE_ON_ATOM):
125 parameters.convergence_force_norm.value = 2;
126 break;
127 }
128
129 // --- GPR Model ---
130 auto gprReader = paramsReader.getGpr();
131 parameters.gp_sigma2.value = gprReader.getGpSigma2();
132 parameters.jitter_sigma2.value = gprReader.getJitterSigma2();
133 parameters.sigma2.value = gprReader.getNoiseSigma2();
135 gprReader.getUseAlphaKPredictMean();
137 gprReader.getUseAlphaKLaplaceMean();
139 gprReader.getSkipScgThreshold();
141 gprReader.getUseTrainingGeometryHandle();
142 parameters.profile_predict_mean.value = gprReader.getProfilePredictMean();
143 parameters.profile_energy_split.value = gprReader.getProfileEnergySplit();
144 parameters.profile_gradient_split.value =
145 gprReader.getProfileGradientSplit();
146 parameters.log_training_geometry.value = gprReader.getLogTrainingGeometry();
147 parameters.log_rank_block_cholesky.value =
148 gprReader.getLogRankBlockCholesky();
149 // A gprd_params message predates the published prior defaults. One that
150 // omits gpr.prior meant zeros and keeps reading as zeros, which GP
151 // initialization rejects by name; the schema default is not applied.
152 if (gprReader.hasPrior()) {
153 auto priorReader = gprReader.getPrior();
154 parameters.prior_mu.value = priorReader.getMu();
155 parameters.prior_nu.value = priorReader.getNu();
156 parameters.prior_s2.value = priorReader.getS2();
157 } else {
158 parameters.prior_mu.value = 0.0;
159 parameters.prior_nu.value = 0.0;
160 parameters.prior_s2.value = 0.0;
161 }
162
163 // --- Early stopping
164 auto earlyStoppingReader = paramsReader.getEarlyStopping();
165 switch (earlyStoppingReader.getDistMetric()) {
166 case (::DistanceMetric::MAX1_D_LOG): {
168 break;
169 }
170 case (::DistanceMetric::RMSD): {
172 break;
173 }
174 case (::DistanceMetric::EMD): {
176 break;
177 }
178 default:
179 throw("Shouldn't be here");
180 }
181 parameters.es_threshold.value = earlyStoppingReader.getThreshold();
183 earlyStoppingReader.getUseAdaptiveThreshold();
184 parameters.es_adaptive_A.value = earlyStoppingReader.getAdaptiveA();
185 parameters.es_adaptive_floor.value = earlyStoppingReader.getAdaptiveFloor();
186 parameters.es_t_min.value = earlyStoppingReader.getTMin();
187 parameters.es_delta_explore.value = earlyStoppingReader.getDeltaExplore();
188 parameters.es_half_life.value = earlyStoppingReader.getHalfLife();
189
190 // --- Hyperparameter Optimizer ---
191 auto optimizerReader = paramsReader.getOptimizer();
192 parameters.check_derivative.value =
193 optimizerReader.getCheckDerivative() ? "true" : "false";
194 parameters.max_iter.value = optimizerReader.getMaxIter();
195 parameters.tolerance_func.value = optimizerReader.getTolFunc();
196 parameters.tolerance_sol.value = optimizerReader.getTolSol();
197
198 switch (optimizerReader.getAlgorithm()) {
199 case HyperparameterOptimizer::SCG: {
200 parameters.optimization_alg.value = "SCG_opt";
201 auto scgReader = optimizerReader.getScg();
202 parameters.lambda_limit.value = scgReader.getLambdaLimit();
203 parameters.lambda.value = scgReader.getLambda();
204 switch (scgReader.getCurvatureMode()) {
206 parameters.curvature_mode.value = "exact";
207 break;
209 parameters.curvature_mode.value = "finite_difference";
210 break;
212 parameters.curvature_mode.value = "nlml_hessian_vector";
213 break;
214 }
215 break;
216 }
217 case HyperparameterOptimizer::ADAM: {
218 parameters.optimization_alg.value = "ADAM_opt";
219 auto adamReader = optimizerReader.getAdam();
220 parameters.learning_rate.value = adamReader.getLr();
221 parameters.learning_rate_decay.value = adamReader.getLrd();
222 parameters.beta1.value = adamReader.getB1();
223 parameters.beta2.value = adamReader.getB2();
224 parameters.epsilon.value = adamReader.getEps();
225 parameters.weight_decay.value = adamReader.getWeightDecay();
226 parameters.amsgrad.value = adamReader.getAmsgrad();
227 break;
228 }
229 }
230
231 // --- Pruning ---
232 auto pruningReader = paramsReader.getPruning();
233 parameters.use_prune.value = pruningReader.getUsePrune();
234 parameters.start_prune_at.value = pruningReader.getPruneBegin();
235 parameters.nprune_vals.value = pruningReader.getPruneNVals();
236 parameters.prune_threshold.value = pruningReader.getPruneThreshold();
237
238 // --- Debug ---
239 auto debugReader = paramsReader.getDebug();
240 parameters.report_level.value = debugReader.getReportLevel();
241 parameters.debug_level.value = debugReader.getDebugLevel();
242 parameters.debug_output_dir.value = debugReader.getDebugOutDir().cStr();
243 parameters.debug_output_file_R.value = debugReader.getDebugPosFile().cStr();
244 parameters.debug_output_file_E.value =
245 debugReader.getDebugEnergyFile().cStr();
246 parameters.debug_output_file_G.value =
247 debugReader.getDebugGradFile().cStr();
249 debugReader.getDebugOutExt().cStr();
251 debugReader.getDebugOffsetMidPoint();
252 parameters.debug_dy.value = debugReader.getDebugDy();
253 parameters.debug_dz.value = debugReader.getDebugDz();
254 parameters.profile_dimer_times.value = debugReader.getProfileDimerTimes();
255
256 // --- Linear algebra ---
257 auto linalgReader = paramsReader.getLinearAlgebra();
258 parameters.scalapack_block_size.value =
259 linalgReader.getScalapackBlockSize();
260 parameters.scalapack_nprow.value = linalgReader.getScalapackNprow();
261 parameters.cutlass_plugin_path.value =
262 linalgReader.getCutlassPluginPath().cStr();
263
264 // --- Cell Dimensions ---
265 auto cellDimsReader = paramsReader.getCellDimensions();
266 for (size_t i = 0; i < cellDimsReader.size() && i < 9; ++i) {
267 parameters.cell_dimensions.value[i] = cellDimsReader[i];
268 }
269
270 // Cleanup
271 munmap(const_cast<void*>(mapped_ptr), size);
272 close(fd);
273}
274
275namespace {
276
277constexpr std::size_t sectionCount(auto bounded)
278{
279 return static_cast<std::size_t>(capnp::unbound(bounded));
280}
281
282struct RootShape {
283 std::size_t data_words;
284 std::size_t pointers;
285};
286
287template <typename Params>
288constexpr RootShape schemaRoot()
289{
290 constexpr auto size = capnp::_::structSize<Params>();
291 return {sectionCount(size.data), sectionCount(size.pointers)};
292}
293
294constexpr bool within(RootShape root, RootShape smallest, RootShape largest)
295{
296 return root.data_words >= smallest.data_words &&
297 root.data_words <= largest.data_words &&
298 root.pointers >= smallest.pointers &&
299 root.pointers <= largest.pointers;
300}
301
302constexpr bool same(RootShape a, RootShape b)
303{
304 return a.data_words == b.data_words && a.pointers == b.pointers;
305}
306
307// Since their field numbers settled, both InputParameters structs have only
308// gained fields (the schema/*.capnp.ordinals records keep it so), and a
309// writer emits the full sections of its own revision. params.capnp has had
310// one data word since its first revision, which had 20 pointers, so each of
311// its roots up to the current one is a prefix of the current layout.
312// gprd_params.capnp gained data words and pointers in different revisions,
313// so a root between two of its revisions, such as 7 data words and 10
314// pointers, came from no writer and is refused. Its revisions wrote these
315// roots, oldest first; the first ends at cellDimensions @17, as in
316// input/capnp_params.bin. The revision before it put pruning at @13, where
317// earlyStopping is now, in a root of 6 data words and 9 pointers, which is
318// refused. The first revision used other numbers in a root of the same 6
319// and 10, so its messages cannot be told apart.
320constexpr std::array<RootShape, 4> kLegacyRoots{
321 {{6, 10}, {6, 14}, {7, 14}, {7, 15}}};
322constexpr RootShape kOldestUnifiedRoot{1, 20};
323constexpr RootShape kLegacyRoot = schemaRoot<::InputParameters>();
324constexpr RootShape kUnifiedRoot = schemaRoot<gpr::schema::InputParameters>();
325static_assert(same(kLegacyRoots.back(), kLegacyRoot),
326 "the last gprd_params.capnp root must be the current struct's; "
327 "list the root of each revision that changes its size");
328static_assert(within(kOldestUnifiedRoot, kOldestUnifiedRoot, kUnifiedRoot),
329 "the oldest params.capnp root must fit inside its current root");
330
331constexpr bool isLegacyRoot(RootShape root)
332{
333 for (const auto& legacy: kLegacyRoots)
334 if (same(root, legacy)) return true;
335 return false;
336}
337static_assert(kLegacyRoot.pointers < kOldestUnifiedRoot.pointers,
338 "no root may be both a gprd_params.capnp and a params.capnp "
339 "revision");
340
341std::string count(std::size_t smallest, std::size_t largest,
342 const std::string& noun)
343{
344 std::string text = std::to_string(smallest);
345 if (largest != smallest) text += " to " + std::to_string(largest);
346 return text + " " + noun + (largest == 1 ? "" : "s");
347}
348
349std::string describe(RootShape smallest, RootShape largest)
350{
351 return count(smallest.data_words, largest.data_words, "data word") +
352 " and " + count(smallest.pointers, largest.pointers, "pointer");
353}
354
355std::string describeLegacyRoots()
356{
357 std::string text;
358 for (std::size_t i = 0; i < kLegacyRoots.size(); ++i) {
359 if (i > 0) text += i + 1 == kLegacyRoots.size() ? " or " : ", ";
360 text += describe(kLegacyRoots[i], kLegacyRoots[i]);
361 }
362 return text;
363}
364
365// `version` is empty when the root carries no params.capnp schema version
366// to name. The size text stays the same either way, so existing checks for
367// an unmatched root keep matching.
368std::string unmatchedRoot(RootShape root, const std::string& version)
369{
370 std::string text = "Cap'n Proto root of " + describe(root, root);
371 if (!version.empty()) text += " with schema version " + version;
372 text += " matches no InputParameters revision: params.capnp roots have " +
373 describe(kOldestUnifiedRoot, kUnifiedRoot) + " (at least " +
374 describe(kUnifiedRoot, kUnifiedRoot) +
375 " from a newer writer), gprd_params.capnp roots have " +
376 describeLegacyRoots();
377 return text;
378}
379
380template <typename List>
381void copyFloats(List src, capnp::List<double>::Builder dst)
382{
383 for (unsigned int i = 0; i < src.size(); ++i)
384 dst.set(i, src[i]);
385}
386
387} // namespace
388
389bool readerIsLegacyDimer(capnp::MessageReader& reader)
390{
391 const auto any =
392 reader.getRoot<capnp::AnyPointer>().getAs<capnp::AnyStruct>();
393 const RootShape root{any.getDataSection().size() / sizeof(capnp::word),
394 any.getPointerSection().size()};
395 if (isLegacyRoot(root)) return true;
396 // Versions this build knows wrote a root in [kOldestUnifiedRoot,
397 // kUnifiedRoot]. A writer newer than this build appends to the current
398 // root and stamps a schema version the caller rejects. The same larger
399 // root stamped with a known version matches nothing in that table.
400 if (within(root, kOldestUnifiedRoot, kUnifiedRoot)) return false;
401 if (root.data_words >= kUnifiedRoot.data_words &&
402 root.pointers >= kUnifiedRoot.pointers) {
403 const auto version =
404 reader.getRoot<gpr::schema::InputParameters>().getSchemaVersion();
405 if (version > gpr::schema::CURRENT_SCHEMA_VERSION) return false;
406 throw std::runtime_error(unmatchedRoot(root, std::to_string(version)));
407 }
408 throw std::runtime_error(unmatchedRoot(root, {}));
409}
410
411void overlayLegacyDimerReader(capnp::MessageReader& reader,
412 gpr::schema::InputParameters::Builder unified)
413{
414 const auto legacy = reader.getRoot<::InputParameters>();
415 const auto problem = legacy.getProblem();
416 auto dimer = unified.getMethod().getDimer();
417 dimer.setActdistFro(problem.getActdistFro());
418 dimer.setDimerSep(problem.getDimerSep());
419 dimer.setMethodRot(gpr::schema::DimerOptimizer::LBFGS);
420 dimer.setMethodTrans(gpr::schema::DimerOptimizer::LBFGS);
421 {
422 const auto src = problem.getParamTrans();
423 auto dst = dimer.initParamTrans();
424 dst.setStepLength(src.getStepLength());
425 dst.setMaxStepLength(src.getMaxStepLength());
426 dst.setRotremThresh(src.getRotremThresh());
427 }
428 dimer.setFinalConvergenceForce(problem.getFinalConvergenceForce());
429 {
430 const auto src = problem.getInitialRotations();
431 auto dst = dimer.initInitialRotations();
432 dst.setMaxIterations(src.getMaxIterations());
433 dst.setUseGpr(src.getUseGpr());
434 dst.setConvergenceAngle(src.getConvergenceAngle());
435 }
436 {
437 const auto src = problem.getRelaxation();
438 auto dst = dimer.initRelaxation();
439 dst.setMaxOuterIterations(src.getMaxOuterIterations());
440 dst.setMaxInnerIterations(src.getMaxInnerIterations());
441 dst.setMaxRotationIterations(src.getMaxRotationIterations());
442 dst.setWarmupFromInitialLocation(src.getWarmupFromInitialLocation());
443 dst.setWarmupFromInitHyperparameters(
444 src.getWarmupFromInitHyperparameters());
445 dst.setAssumeManyIterations(src.getAssumeManyIterations());
446 dst.initConvergence().setAngle(src.getConvergence().getAngle());
447 }
448 dimer.setDivisorTdimerGP(problem.getDivisorTdimerGP());
449 dimer.setMidpointMaxDisp(problem.getMidpointMaxDisp());
450 dimer.setRatioAtLimit(problem.getRatioAtLimit());
451 switch (problem.getConvergenceForceNorm()) {
452 case ::ConvergenceForceNorm::LINF_NORM:
453 dimer.setConvergenceForceNorm(
454 gpr::schema::ConvergenceForceNorm::LINF_NORM);
455 break;
456 case ::ConvergenceForceNorm::MAX_FORCE_ON_ATOM:
457 dimer.setConvergenceForceNorm(
458 gpr::schema::ConvergenceForceNorm::MAX_FORCE_ON_ATOM);
459 break;
460 default:
461 dimer.setConvergenceForceNorm(
462 gpr::schema::ConvergenceForceNorm::L2_NORM);
463 break;
464 }
465 {
466 const auto src = legacy.getOrientInit();
467 copyFloats(src, dimer.initOrientInit(src.size()));
468 }
469 {
470 const auto src = legacy.getOrientStart();
471 copyFloats(src, dimer.initOrientStart(src.size()));
472 }
473 {
474 const auto src = legacy.getDisplacedPositions();
475 copyFloats(src, dimer.initDisplacedPositions(src.size()));
476 }
477
478 const auto gpr_src = legacy.getGpr();
479 auto gpr = unified.getGpr();
480 gpr.setGpSigma2(gpr_src.getGpSigma2());
481 gpr.setJitterSigma2(gpr_src.getJitterSigma2());
482 gpr.setNoiseSigma2(gpr_src.getNoiseSigma2());
483 gpr.setUseAlphaKPredictMean(gpr_src.getUseAlphaKPredictMean());
484 gpr.setUseAlphaKLaplaceMean(gpr_src.getUseAlphaKLaplaceMean());
485 gpr.setSkipScgThreshold(gpr_src.getSkipScgThreshold());
486 gpr.setUseTrainingGeometryHandle(gpr_src.getUseTrainingGeometryHandle());
487 gpr.setProfilePredictMean(gpr_src.getProfilePredictMean());
488 gpr.setProfileEnergySplit(gpr_src.getProfileEnergySplit());
489 gpr.setProfileGradientSplit(gpr_src.getProfileGradientSplit());
490 gpr.setLogTrainingGeometry(gpr_src.getLogTrainingGeometry());
491 gpr.setLogRankBlockCholesky(gpr_src.getLogRankBlockCholesky());
492 {
493 // An omitted legacy prior meant zeros. Write them explicitly so
494 // the schema 4 default does not replace them in the converted
495 // message.
496 auto dst = gpr.getPrior();
497 if (gpr_src.hasPrior()) {
498 const auto src = gpr_src.getPrior();
499 dst.setMu(src.getMu());
500 dst.setNu(src.getNu());
501 dst.setS2(src.getS2());
502 } else {
503 dst.setMu(0.0);
504 dst.setNu(0.0);
505 dst.setS2(0.0);
506 }
507 }
508
509 const auto early_src = legacy.getEarlyStopping();
510 auto early = unified.getEarlyStopping();
511 switch (early_src.getDistMetric()) {
512 case ::DistanceMetric::MAX1_D_LOG:
513 early.setDistMetric(gpr::schema::DistanceMetric::MAX1_D_LOG);
514 break;
515 case ::DistanceMetric::RMSD:
516 early.setDistMetric(gpr::schema::DistanceMetric::RMSD);
517 break;
518 default:
519 early.setDistMetric(gpr::schema::DistanceMetric::EMD);
520 break;
521 }
522 early.setThreshold(early_src.getThreshold());
523 early.setUseAdaptiveThreshold(early_src.getUseAdaptiveThreshold());
524 early.setAdaptiveA(early_src.getAdaptiveA());
525 early.setAdaptiveFloor(early_src.getAdaptiveFloor());
526 early.setTMin(early_src.getTMin());
527 early.setDeltaExplore(early_src.getDeltaExplore());
528 early.setHalfLife(early_src.getHalfLife());
529
530 const auto opt_src = legacy.getOptimizer();
531 auto optimizer = unified.getOptimizer();
532 optimizer.setCheckDerivative(opt_src.getCheckDerivative());
533 optimizer.setMaxIter(opt_src.getMaxIter());
534 optimizer.setTolFunc(opt_src.getTolFunc());
535 optimizer.setTolSol(opt_src.getTolSol());
536 if (opt_src.getAlgorithm() == ::HyperparameterOptimizer::ADAM) {
537 optimizer.setAlgorithm(gpr::schema::HyperparameterOptimizer::ADAM);
538 const auto src = opt_src.getAdam();
539 auto dst = optimizer.initAdam();
540 dst.setLr(src.getLr());
541 dst.setLrd(src.getLrd());
542 dst.setB1(src.getB1());
543 dst.setB2(src.getB2());
544 dst.setEps(src.getEps());
545 dst.setWeightDecay(src.getWeightDecay());
546 dst.setAmsgrad(src.getAmsgrad());
547 } else {
548 optimizer.setAlgorithm(gpr::schema::HyperparameterOptimizer::SCG);
549 const auto src = opt_src.getScg();
550 auto dst = optimizer.initScg();
551 dst.setLambdaLimit(src.getLambdaLimit());
552 dst.setLambda(src.getLambda());
553 switch (src.getCurvatureMode()) {
554 case ::ScgCurvatureMode::FINITE_DIFFERENCE:
555 dst.setCurvatureMode(
556 gpr::schema::ScgCurvatureMode::FINITE_DIFFERENCE);
557 break;
558 case ::ScgCurvatureMode::NLML_HESSIAN_VECTOR:
559 dst.setCurvatureMode(
560 gpr::schema::ScgCurvatureMode::NLML_HESSIAN_VECTOR);
561 break;
562 default:
563 dst.setCurvatureMode(gpr::schema::ScgCurvatureMode::EXACT);
564 break;
565 }
566 }
567
568 const auto prune_src = legacy.getPruning();
569 auto pruning = unified.getPruning();
570 pruning.setUsePrune(prune_src.getUsePrune());
571 pruning.setPruneBegin(prune_src.getPruneBegin());
572 pruning.setPruneNVals(prune_src.getPruneNVals());
573 pruning.setPruneThreshold(prune_src.getPruneThreshold());
574
575 const auto debug_src = legacy.getDebug();
576 auto debug = unified.getDebug();
577 debug.setReportLevel(debug_src.getReportLevel());
578 debug.setDebugLevel(debug_src.getDebugLevel());
579 debug.setDebugOutDir(debug_src.getDebugOutDir().cStr());
580 debug.setDebugPosFile(debug_src.getDebugPosFile().cStr());
581 debug.setDebugEnergyFile(debug_src.getDebugEnergyFile().cStr());
582 debug.setDebugGradFile(debug_src.getDebugGradFile().cStr());
583 debug.setDebugOutExt(debug_src.getDebugOutExt().cStr());
584 debug.setDebugOffsetMidPoint(debug_src.getDebugOffsetMidPoint());
585 debug.setDebugDy(debug_src.getDebugDy());
586 debug.setDebugDz(debug_src.getDebugDz());
587 debug.setProfileDimerTimes(debug_src.getProfileDimerTimes());
588
589 const auto linalg_src = legacy.getLinearAlgebra();
590 auto linalg = unified.getLinearAlgebra();
591 linalg.setScalapackBlockSize(linalg_src.getScalapackBlockSize());
592 linalg.setScalapackNprow(linalg_src.getScalapackNprow());
593 linalg.setCutlassPluginPath(linalg_src.getCutlassPluginPath().cStr());
594
595 const auto run_src = legacy.getRunSelector();
596 auto run = unified.getRunSelector();
597 run.setIDist(run_src.getIDist());
598 run.setIRun(run_src.getIRun());
599 {
600 const auto src = run_src.getSepDists();
601 copyFloats(src, run.initSepDists(src.size()));
602 }
603 {
604 const auto src = legacy.getCellDimensions();
605 copyFloats(src, unified.initCellDimensions(src.size()));
606 }
607 unified.setConfigFile(legacy.getConfigFile().cStr());
608}
609
610} // namespace gpr::io
std::string version()
Definition gpridge.hpp:339
void overlayLegacyDimerReader(capnp::MessageReader &reader, gpr::schema::InputParameters::Builder unified)
Copy a gprd_params.capnp reader onto a unified builder.
void loadParametersFromCapnp(const std::string &binary_filename, gpr::InputParameters &parameters)
Loads parameters by reading a memory-mapped Cap'n Proto binary file.
bool readerIsLegacyDimer(capnp::MessageReader &reader)
Whether reader is a gprd_params.capnp message rather than a params.capnp message.
Dense and structured linear algebra behind the GP: Cholesky and eigen solvers, linear operators,...
std::string describe(const Stamp &stamp)
Definition RgminAbi.h:41
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16
Structure of the input parameters. All input parameters are pairs of string names and values.
Definition Structures.h:370
KeyValuePair< double[2]> param_trans
Definition Structures.h:440
KeyValuePair< bool > log_rank_block_cholesky
Definition Structures.h:635
KeyValuePair< double > T_anglerot_gp
Definition Structures.h:484
KeyValuePair< double > prior_s2
Definition Structures.h:650
KeyValuePair< double > es_t_min
Definition Structures.h:659
KeyValuePair< double > laplace_skip_scg_threshold
Definition Structures.h:623
KeyValuePair< std::string > debug_output_file_G
Definition Structures.h:589
KeyValuePair< int > max_iter
Definition Structures.h:674
KeyValuePair< int > i_dist
Definition Structures.h:371
KeyValuePair< int > initrot_nogp
Definition Structures.h:467
KeyValuePair< DistanceMetricType > es_dist_metric
Definition Structures.h:652
KeyValuePair< std::string > optimization_alg
Definition Structures.h:614
KeyValuePair< bool > es_use_adaptive_threshold
Definition Structures.h:655
KeyValuePair< double[9]> cell_dimensions
Definition Structures.h:605
KeyValuePair< double > dimer_sep
Definition Structures.h:425
KeyValuePair< int > start_prune_at
Definition Structures.h:571
KeyValuePair< int > islarge_num_iter
Definition Structures.h:544
KeyValuePair< double > lambda
Definition Structures.h:678
KeyValuePair< double > prior_nu
Definition Structures.h:649
KeyValuePair< int > report_level
Definition Structures.h:673
KeyValuePair< double > rotation_removal_projection_threshold
Definition Structures.h:667
KeyValuePair< double > T_anglerot_init
Definition Structures.h:474
KeyValuePair< double > learning_rate_decay
Definition Structures.h:681
KeyValuePair< int > scalapack_nprow
Definition Structures.h:638
KeyValuePair< double > jitter_sigma2
Definition Structures.h:613
KeyValuePair< std::string > debug_output_dir
Definition Structures.h:584
KeyValuePair< int > scalapack_block_size
Definition Structures.h:637
KeyValuePair< double > ratio_at_limit
Definition Structures.h:512
KeyValuePair< int > debug_level
Definition Structures.h:597
KeyValuePair< std::string > method_trans
Definition Structures.h:435
KeyValuePair< double > weight_decay
Definition Structures.h:685
KeyValuePair< double > beta2
Definition Structures.h:683
KeyValuePair< double > debug_dz
Definition Structures.h:596
KeyValuePair< double > prune_threshold
Definition Structures.h:581
KeyValuePair< double > beta1
Definition Structures.h:682
KeyValuePair< double > es_delta_explore
Definition Structures.h:660
KeyValuePair< int > nprune_vals
Definition Structures.h:576
KeyValuePair< int > num_bigiter_initloc
Definition Structures.h:519
KeyValuePair< int > convergence_force_norm
Definition Structures.h:461
KeyValuePair< bool > use_training_geometry_handle
Definition Structures.h:625
KeyValuePair< bool > profile_gradient_split
Definition Structures.h:631
KeyValuePair< double > actdist_fro
Definition Structures.h:379
KeyValuePair< double > epsilon
Definition Structures.h:684
KeyValuePair< int > num_bigiter_initparam
Definition Structures.h:527
KeyValuePair< std::string > method_rot
Definition Structures.h:430
KeyValuePair< bool > use_prune
Definition Structures.h:562
KeyValuePair< int > divisor_T_dimer_gp
Definition Structures.h:498
KeyValuePair< double > learning_rate
Definition Structures.h:680
KeyValuePair< int > num_iter
Definition Structures.h:537
KeyValuePair< int > num_iter_initrot
Definition Structures.h:479
KeyValuePair< double > lambda_limit
Definition Structures.h:677
KeyValuePair< double > debug_offset_from_mid_point
Definition Structures.h:593
KeyValuePair< double > disp_max
Definition Structures.h:505
KeyValuePair< double > tolerance_func
Definition Structures.h:675
KeyValuePair< std::string > check_derivative
Definition Structures.h:672
KeyValuePair< bool > profile_dimer_times
Definition Structures.h:633
KeyValuePair< std::string > cutlass_plugin_path
Definition Structures.h:639
KeyValuePair< std::string > debug_output_file_E
Definition Structures.h:587
KeyValuePair< double[4]> dist_sp
Definition Structures.h:374
KeyValuePair< double > es_adaptive_A
Definition Structures.h:657
KeyValuePair< bool > profile_energy_split
Definition Structures.h:630
KeyValuePair< int > es_half_life
Definition Structures.h:661
KeyValuePair< bool > log_training_geometry
Definition Structures.h:634
KeyValuePair< bool > use_alpha_k_laplace_mean
Definition Structures.h:621
KeyValuePair< bool > use_alpha_k_predict_mean
Definition Structures.h:619
KeyValuePair< std::string > debug_output_file_extension
Definition Structures.h:591
KeyValuePair< double > tolerance_sol
Definition Structures.h:676
KeyValuePair< double > prior_mu
Definition Structures.h:648
KeyValuePair< int > num_bigiter
Definition Structures.h:532
KeyValuePair< double > sigma2
Definition Structures.h:616
KeyValuePair< std::string > curvature_mode
Definition Structures.h:679
KeyValuePair< bool > profile_predict_mean
Definition Structures.h:629
KeyValuePair< int > i_run
Definition Structures.h:372
KeyValuePair< bool > amsgrad
Definition Structures.h:686
KeyValuePair< double > es_threshold
Definition Structures.h:654
KeyValuePair< double > debug_dy
Definition Structures.h:595
KeyValuePair< std::string > debug_output_file_R
Definition Structures.h:585
KeyValuePair< double > gp_sigma2
Definition Structures.h:612
KeyValuePair< double > es_adaptive_floor
Definition Structures.h:658
KeyValuePair< double > T_dimer
Definition Structures.h:453
KeyValuePair< int > num_iter_rot_gp
Definition Structures.h:490