Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
Loading...
Searching...
No Matches
config.hpp
Go to the documentation of this file.
1//This file is part of Bertini 2.
2//
3//trackers/include/bertini2/trackers/config.hpp is free software: you can redistribute it and/or modify
4//it under the terms of the GNU General Public License as published by
5//the Free Software Foundation, either version 3 of the License, or
6//(at your option) any later version.
7//
8//trackers/include/bertini2/trackers/config.hpp is distributed in the hope that it will be useful,
9//but WITHOUT ANY WARRANTY; without even the implied warranty of
10//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11//GNU General Public License for more details.
12//
13//You should have received a copy of the GNU General Public License
14//along with tracking/include/bertini2/trackers/config.hpp. If not, see <http://www.gnu.org/licenses/>.
15//
16// Copyright(C) Bertini2 Development Team
17//
18// See <http://www.gnu.org/licenses/> for a copy of the license,
19// as well as COPYING. Bertini2 is provided with permitted
20// additional terms in the b2/licenses/ directory.
21
22#ifndef BERTINI_TRACKING_CONFIG_HPP
23#define BERTINI_TRACKING_CONFIG_HPP
24
34
36
37
38namespace bertini
39{
40
41namespace tracking{
42
43
45 enum class PrecisionType //E.2.1
46 {
50 };
51
52
67
68
69
70
71
72
73
92
93
96 {
97 // mpq_rational: exact rationals with no MPFR precision state — safe in DefaultConstruct<T>::value statics.
98 // real_mp fields here would be initialized at BMP's startup precision (20) and contaminate
99 // tracker arithmetic when target precision < 20 via preserve_related_precision.
102 double min_step_size = 1e-100;
103
106
108
109 unsigned min_num_steps = 1;
110 unsigned max_num_steps = 1e5;
111
113 };
114
115
116
119 {
122 };
123
124
147
148
149
150
151
152
153
154
157 {
158 using RealT = double;
159
170 unsigned precision = 0;
171
175 explicit
177 { }
178
180 };
181
182
184 inline
185 std::ostream& operator<<(std::ostream & out, FixedPrecisionConfig const& /*fpc*/)
186 {
187 return out;
188 }
189
190
214 {
217
223
234
241
244 unsigned int maximum_precision = 300;
245
246 // Note: a single setting -- Bertini 1's StepsForIncrease, i.e.
247 // SteppingConfig::consecutive_successful_steps_before_stepsize_increase -- gates BOTH stepsize
248 // increase AND precision decrease (the required number of consecutive successful steps).
249 // Precision decrease is additionally subject to B1's digits-margin hysteresis (see
250 // ExtraDigitsBeforePrecisionDecrease in amp_tracker.hpp). The old, duplicate AMP-config setting
251 // `consecutive_successful_steps_before_precision_decrease` (a B2 deviation) was removed.
252
254
255
264 void SetBoundsFrom(System const& sys)
265 {
266 using std::pow;
267
268 // Refuse before DegreeBound() does, so the message is about what the caller was
269 // trying to do rather than about degrees. The two bounds are on the error of
270 // evaluating the Jacobian and the functions; the degree and coefficient bounds are
271 // merely the recipe for them that holds for polynomials. There is no accepted
272 // recipe for an analytic system -- see issue #439 -- so we do not invent one.
273 if (!sys.IsPolynomial())
274 throw std::runtime_error("adaptive precision derives its error bounds from the "
275 "degree of the system, and this system is not a polynomial one, so it has no "
276 "degree. Two ways on: track with a fixed-precision tracker, at double or at "
277 "multiple precision, which needs no such bound; or set this config's "
278 "jacobian_eval_error_bound and function_eval_error_bound yourself and hand it "
279 "to the tracker, choosing values you can defend for your system.");
280
284 }
285
286
299
307
321
331 explicit
337 }; // re: AdaptiveMultiplePrecisionConfig
338
340 inline
341 std::ostream& operator<<(std::ostream & out, AdaptiveMultiplePrecisionConfig const& AMP)
342 {
343 out << "coefficient_bound: " << AMP.coefficient_bound << "\n";
344 out << "degree_bound: " << AMP.degree_bound << "\n";
345 out << "linear_solve_error_bound: " << AMP.linear_solve_error_bound << "\n";
346 out << "jacobian_eval_error_bound: " << AMP.jacobian_eval_error_bound << "\n";
347 out << "function_eval_error_bound: " << AMP.function_eval_error_bound << "\n";
348 out << "safety_digits_1: " << AMP.safety_digits_1 << "\n";
349 out << "safety_digits_2: " << AMP.safety_digits_2 << "\n";
350 out << "max_num_precision_decreases: " << AMP.max_num_precision_decreases << "\n";
351 return out;
352 }
353
354
364 inline
365 static
367 {
369 AMP.SetAMPConfigFrom(sys);
370 return AMP;
371 }
372
373 // forward declarations
374 template<class D>
375 class Tracker;
376 template<class D>
377 class FixedPrecisionTracker;
378 class MultiplePrecisionTracker;
379 class DoublePrecisionTracker;
380
381
382// now for the TrackerTraits structs, which enable lookup of correct settings objects and types, etc.
385 template<class T>
387 {};
388
389
391
392 template<>
394 {
395 static constexpr char const* kRecordName = "double";
396 using BaseComplexT = complex_dbl;
397 using BaseRealT = double;
399 using PrecisionConfig = FixedPrecisionConfig;
400 enum {
401 IsFixedPrec = 1,
402 IsAdaptivePrec = 0
403 };
404
405 using NeededTypes = detail::TypeList<complex_dbl>;
406 using NeededConfigs = detail::TypeList<
407 SteppingConfig,
408 NewtonConfig,
409 TrackerConfig,
410 PrecisionConfig
411 >;
412 };
413
414
415 template<>
416 struct TrackerTraits<MultiplePrecisionTracker>
417 {
418 static constexpr char const* kRecordName = "multiple";
419 using BaseComplexT = complex_mp;
420 using BaseRealT = real_mp;
421 using EventEmitterType = FixedPrecisionTracker<MultiplePrecisionTracker>;
422 using PrecisionConfig = FixedPrecisionConfig;
423
424 enum {
425 IsFixedPrec = 1,
426 IsAdaptivePrec = 0
427 };
428
429 using NeededTypes = detail::TypeList<complex_mp>;
430
431 using NeededConfigs = detail::TypeList<
432 SteppingConfig,
433 NewtonConfig,
434 TrackerConfig,
435 PrecisionConfig
436 >;
437 };
438
439
440 class AMPTracker; // forward declare
441 template<>
443 {
444 static constexpr char const* kRecordName = "adaptive";
445 using BaseComplexT = complex_mp;
446 using BaseRealT = real_mp;
447 using EventEmitterType = AMPTracker;
448 using PrecisionConfig = AdaptiveMultiplePrecisionConfig;
449
450 enum {
451 IsFixedPrec = 0,
452 IsAdaptivePrec = 1
453 };
454
455 using NeededTypes = detail::TypeList<complex_dbl, complex_mp>;
456
457 using NeededConfigs = detail::TypeList<
458 SteppingConfig,
459 NewtonConfig,
460 TrackerConfig,
461 PrecisionConfig
462 >;
463 };
464
465
466
467
468 template<class D>
470 {
471 using BaseComplexT = typename TrackerTraits<D>::BaseComplexT;
472 using BaseRealT = typename TrackerTraits<D>::BaseRealT;
473 using EventEmitterType = typename TrackerTraits<D>::EventEmitterType;
474 using PrecisionConfig = typename TrackerTraits<D>::PrecisionConfig;
475
476 enum {
477 IsFixedPrec = 0,
478 IsAdaptivePrec = 1
479 };
480
481 using NeededTypes = typename TrackerTraits<D>::NeededTypes;
482 using NeededConfigs = typename TrackerTraits<D>::NeededConfigs;
483 };
484
486
487} // re: namespace tracking
488} // re: namespace bertini
489
490
491#endif
The fundamental polynomial system class for Bertini2.
Definition system.hpp:106
Eigen::NumTraits< NumT >::Real CoefficientBound(unsigned num_evaluations=1) const
Compute an estimate of an upper bound of the absolute values of the coefficients in the system.
bool IsPolynomial() const
Checks whether a system is polynomial, overall.
int DegreeBound() const
Compute an upper bound on the degree of the system.
size_t NumVariables() const
Get the total number of variables in this system, including homogenizing variables.
Functor-like class for tracking paths on a system.
Definition amp_tracker.hpp:409
A tracker that works entirely in hardware double precision.
Definition fixed_precision_tracker.hpp:423
CRTP base for trackers that work at a single fixed precision (double or fixed multiple).
Definition fixed_precision_tracker.hpp:56
Bertini extensions of the Eigen linear algebra library.
Extensions to the Boost.Multiprecision library.
AdaptiveMultiplePrecisionConfig AdaptiveMultiplePrecisionConfig
Alias bringing the AMP config type into this scope for the parser specialization below.
Definition tracking.hpp:579
double D(double const &norm_J, double const &norm_J_inverse, AdaptiveMultiplePrecisionConfig const &AMP_config)
Compute the expression from the AMP papers amp1, amp2, amp3.
Definition amp_criteria.hpp:84
Definition adaptive_precision_utilities.hpp:35
Predictor
The predictor (ODE integration) method used during path tracking.
Definition config.hpp:55
@ RKCashKarp45
Definition config.hpp:63
@ Euler
Definition config.hpp:57
@ RKNorsett34
Definition config.hpp:61
@ RKDormandPrince56
Definition config.hpp:64
@ RKVerner67
Definition config.hpp:65
@ RKF45
Definition config.hpp:62
@ HeunEuler
Definition config.hpp:60
@ Constant
Definition config.hpp:56
@ Heun
Definition config.hpp:58
@ RK4
Definition config.hpp:59
std::ostream & operator<<(std::ostream &out, FixedPrecisionConfig const &)
Stream-insertion for FixedPrecisionConfig (a no-op; the config carries no printable state).
Definition config.hpp:185
static AdaptiveMultiplePrecisionConfig AMPConfigFrom(System const &sys)
Construct a ready-to-go set of AMP settings from a system.
Definition config.hpp:366
PrecisionType
The precision regime a tracker operates in: fixed double, fixed multiple, or adaptive.
Definition config.hpp:46
@ Adaptive
Definition config.hpp:49
@ Fixed
Definition config.hpp:47
@ FixedMultiple
Definition config.hpp:48
Definition algorithm_builder.hpp:36
std::complex< double > complex_dbl
The double-precision complex number type.
Definition double_extensions.hpp:47
complex_dbl pow(const complex_dbl &z, int power)
Compute +,- integral powers of a std::complex<double> number.
Definition double_extensions.hpp:92
double NumErrorT
The numeric type used to hold error/tolerance magnitudes throughout Bertini2 – tracking tolerances,...
Definition num_traits.hpp:48
bmp::number< mpc_complex_backend< 0 >, bmp::et_on > complex_mp
The arbitrary-precision complex number type.
Definition mpfr_complex.hpp:58
boost::multiprecision::number< boost::multiprecision::mpfr_float_backend< 0 >, boost::multiprecision::et_on > real_mp
The arbitrary-precision real number type.
Definition mpfr_extensions.hpp:53
boost::multiprecision::number< boost::multiprecision::backends::gmp_rational, boost::multiprecision::et_on > mpq_rational
The exact rational number type.
Definition mpfr_extensions.hpp:55
A basic typelist, in the style of Modern C++ Design, but using variadic templates.
Definition typelist.hpp:42
Holds the program parameters with respect to Adaptive Multiple Precision.
Definition config.hpp:214
NumErrorT function_eval_error_bound
Bound on the error of evaluating the functions, divided by the unit roundoff error.
Definition config.hpp:240
NumErrorT coefficient_bound
User-defined bound on the sum of the abs vals of the coeffs for any polynomial in the system (for ada...
Definition config.hpp:215
void SetAMPConfigFrom(System const &sys)
Set every system-derived AMP setting from a system: the degree, coefficient and linear-solve bounds,...
Definition config.hpp:302
unsigned int maximum_precision
User-chosed setting for the maximum allowable precision. Paths will die if their precision is request...
Definition config.hpp:244
AdaptiveMultiplePrecisionConfig(System const &sys)
Construct AMP settings derived from a system's bounds, where that is possible.
Definition config.hpp:332
int safety_digits_2
User-chosen setting for the number of safety digits used during Criterion C.
Definition config.hpp:243
void SetErrorBoundsFromDegreeAndCoefficient()
Set the two evaluation error bounds from the degree and coefficient bounds.
Definition config.hpp:294
int safety_digits_1
User-chosen setting for the number of safety digits used during Criteria A & B.
Definition config.hpp:242
NumErrorT jacobian_eval_error_bound
Bound on the error of evaluating the Jacobian, divided by the unit roundoff error .
Definition config.hpp:233
unsigned max_num_precision_decreases
The maximum number of times precision can be lowered during tracking of a segment of path.
Definition config.hpp:253
NumErrorT linear_solve_error_bound
Bound on the growth in error from a linear solve.
Definition config.hpp:222
void SetBoundsFrom(System const &sys)
Set the linear-solve error bound, the degree bound and the coefficient bound from a system.
Definition config.hpp:264
AdaptiveMultiplePrecisionConfig()
Construct with default AMP bounds and safety digits.
Definition config.hpp:317
NumErrorT degree_bound
User-set bound on degrees of polynomials in the system - tricky to compute for factored polys,...
Definition config.hpp:216
Settings for a fixed-precision tracker (carries the single working precision in effect).
Definition config.hpp:157
double RealT
The real number type.
Definition config.hpp:158
unsigned precision
The number of digits to always work at.
Definition config.hpp:170
FixedPrecisionConfig(System const &)
Construct a ready-to-go set of fixed precision settings from a system.
Definition config.hpp:176
Settings governing the Newton corrector's iteration bounds.
Definition config.hpp:119
unsigned min_num_newton_iterations
The minimum number of Newton iterations per correction.
Definition config.hpp:121
unsigned max_num_newton_iterations
The maximum number of Newton iterations per correction. MaxNewtonIts.
Definition config.hpp:120
Metadata produced by a single predict or correct step.
Definition config.hpp:84
NumErrorT error_estimate
embedded-method error estimate (predictor, embedded only).
Definition config.hpp:89
NumErrorT condition_number_estimate
norm_J * norm_J_inverse (refreshed per frequency_of_CN_estimation).
Definition config.hpp:87
NumErrorT size_proportion
AMP "a" (predictor only).
Definition config.hpp:88
NumErrorT norm_J_inverse
estimate of ||J^{-1}|| via the condition probe.
Definition config.hpp:86
NumErrorT norm_J
||J|| (Frobenius) at the step.
Definition config.hpp:85
NumErrorT norm_delta_z
||latest Newton step|| (corrector only).
Definition config.hpp:90
Settings governing step-size adjustment during tracking.
Definition config.hpp:96
mpq_rational initial_step_size
The length of the first time step when calling TrackPath. StepInitSize.
Definition config.hpp:100
mpq_rational max_step_size
The largest allowed step size. MaxStepSize.
Definition config.hpp:101
unsigned frequency_of_CN_estimation
Estimate the condition number every so many steps. Eh.
Definition config.hpp:112
unsigned max_num_steps
The maximum number of steps allowed during tracking, counting FAILED steps as well as successful ones...
Definition config.hpp:110
mpq_rational step_size_fail_factor
Factor by which to contract the time step when triggered. StepFailFactor.
Definition config.hpp:105
unsigned min_num_steps
The minimum number of steps allowed during tracking.
Definition config.hpp:109
unsigned consecutive_successful_steps_before_stepsize_increase
What it says. If you can come up with a better name, please suggest it. StepsForIncrease.
Definition config.hpp:107
mpq_rational step_size_success_factor
Factor by which to dilate the time step when triggered. StepSuccessFactor.
Definition config.hpp:104
double min_step_size
The minimum allowed step size (threshold only, double precision is sufficient). MinStepSize.
Definition config.hpp:102
The thresholds a tracker judges a path against: close enough, and too big.
Definition config.hpp:142
NumErrorT path_truncation_threshold
The tracker abandons a path once the largest coordinate of its dehomogenized point exceeds this....
Definition config.hpp:145
NumErrorT tracking_tolerance
How tightly Newton must correct onto the path for a step to be accepted.
Definition config.hpp:144
Predictor predictor
The ODE method used to predict the next point along the path. RKF45 – order 4 with an embedded error ...
Definition config.hpp:143
Trait lookup mapping a tracker type to its numeric types, event-emitter type, precision config,...
Definition config.hpp:387
Provides the bertini::System class.
Contains the detail/typelist helper type, for templated getting/setting/storage of config structs.