|
Bertini 2 d882924 (2026-10-06 19:56 UTC)
Numerical algebraic geometry library (C++ core)
|
Base endgame class for all endgames offered in Bertini2. More...
#include <base_endgame.hpp>
Public Types | |
| using | TrackerType = typename PrecT::TrackerType |
| The path-tracker type. | |
| using | BaseComplexT = typename tracking::TrackerTraits<TrackerType>::BaseComplexT |
| The complex number type. | |
| using | BaseRealT = typename tracking::TrackerTraits<TrackerType>::BaseRealT |
| The real number type. | |
| using | EmitterType = FlavorT |
| The event-emitter type. | |
| using | Config = detail::Configured< typename AlgoTraits<FlavorT>::NeededConfigs > |
| The configuration bundle this endgame reads, public so that generic machinery which works in terms of an object's configs – the Python bindings' ConfiguredVisitor, which needs Config::UsedConfigs – can serve an endgame the same way it serves a tracker or a solver. | |
| using | UsedConfigs |
| The list of configuration types this object holds. | |
Public Member Functions | |
| template<typename ComplexT> | |
| auto | ComputeCOverK (SampCont< ComplexT > const &samples) const -> typename Eigen::NumTraits< ComplexT >::Real |
| An estimate of c/k from the three most recent geometric samples. | |
| template<typename T> | |
| bool | CheckForCOverKStabilization (std::deque< T > const &c_over_k_array) const |
| Have the last few c/k estimates settled to within the user's threshold? | |
| void | SetBoundaryTime (BCT const &t) |
| Set the endgame boundary (start) time. | |
| void | SetTargetTime (BCT const &t) |
| Set the final target time. | |
| BCT const & | BoundaryTime () const |
| BCT const & | TargetTime () const |
| SuccessCode | Run (Vec< BCT > const &start_point) |
| Run the endgame from the stored boundary time to the stored target time. | |
| template<typename ComplexT> | |
| void | EmitComputedSample (Vec< ComplexT > const &sample, ComplexT const &time) |
| Announce a completed sample point on the path, as a ComputedSamplePoint. | |
| template<typename ComplexT> | |
| SuccessCode | RefineAllSamples (SampCont< ComplexT > &samples, TimeCont< ComplexT > ×) |
| Refine every sample point to the endgame's refinement tolerance. | |
| template<typename ComplexT> | |
| SuccessCode | RefineSample (Vec< ComplexT > &result, Vec< ComplexT > const ¤t_sample, ComplexT const ¤t_time, NumErrorT tol, unsigned max_iterations) const |
| A function passed off to the precision-specific endgame part. | |
| template<typename ComplexT> | |
| SuccessCode | EndgameTrackPath (Vec< ComplexT > &result, ComplexT const &start_time, ComplexT const &end_time, Vec< ComplexT > const &start_point) const |
| Track through the tracker, adapting at the numeric-type boundary. | |
| template<typename Dummy = void> | |
| SuccessCode | EscalateAndMigrate (unsigned guard) |
| Raise the endgame to the next precision and migrate the containers' complex_dbl slot up to complex_mp when the tracker's authority escalates. | |
| const auto & | EndgameSettings () const |
| This function is inferior to the templated Get<ConfigT> function provided. | |
| const auto & | SecuritySettings () const |
| template<typename RealT> | |
| bool | BeyondSecurityMaxNorm (RealT const &norm) const |
| EndgameBase (TrackerType const &tr, const ConfigsAsTuple &settings) | |
| Construct the endgame for a tracker, with its configuration as a tuple. | |
| template<typename... Ts> | |
| EndgameBase (TrackerType const &tr, const Ts &... ts) | |
| Construct the endgame for a tracker, with configs given in any order. | |
| unsigned | CycleNumber () const |
| void | CycleNumber (unsigned c) |
| Set the cycle number. | |
| void | IncrementCycleNumber (unsigned inc) |
| Increase the cycle number by the given increment. | |
| const auto & | FinalTolerance () const |
| Get the final tolerance to which we are tracking the solution. | |
| void | SetFinalTolerance (NumErrorT const &ft) |
| Setter for the final tolerance. | |
| template<typename ComplexT> | |
| const Vec< ComplexT > & | FinalApproximation () const |
| Get the most-recent approximation. | |
| template<typename ComplexT> | |
| const Vec< ComplexT > & | PreviousApproximation () const |
| Get the second-most-recent approximation. | |
| NumErrorT | ApproximateError () const |
| Get the most recent accuracy estimate. | |
| const BCT & | LatestTime () const |
| Get the latest time at which a point on the path was computed. | |
| template<typename ComplexT> | |
| SuccessCode | ComputeInitialSamples (const ComplexT &start_time, const ComplexT &target_time, const Vec< ComplexT > &x_endgame_start, TimeCont< ComplexT > ×, SampCont< ComplexT > &samples) |
| Get the system being tracked on, which is referred to by the tracker. | |
| virtual | ~EndgameBase ()=default |
| const T & | Get () const |
| Get the held configuration object of type T. | |
| void | Set (T const &t) |
| Set the held configuration object of type T. | |
| void | AddObserver (AnyObserver &new_observer) const |
| Add an observer (non-owning) to observe this observable. | |
| void | AddObserver (std::shared_ptr< AnyObserver > const &new_observer) const |
| Add an observer whose lifetime is co-owned by this observable. | |
| void | RemoveObserver (AnyObserver &observer) const |
| Remove an observer from this observable. | |
| virtual bool | ObservableIsA (std::type_index t) const |
| Whether this observable may be observed as the given type. | |
Public Attributes | |
| std::tuple< Ts... > | configuration_ |
| The held configuration objects, one per config type. | |
Protected Types | |
| using | BCT = BaseComplexT |
| The complex number type. | |
| using | BRT = BaseRealT |
| The real number type. | |
| using | Configured = detail::Configured< typename AlgoTraits<FlavorT>::NeededConfigs > |
| The Configured base type. | |
| using | Configs = typename AlgoTraits<FlavorT>::NeededConfigs |
| The configuration bundle (Configured base). | |
| using | ConfigsAsTuple = typename Configs::ToTuple |
| The configuration structs as a tuple. | |
| using | NeededTypes = typename tracking::TrackerTraits<TrackerType>::NeededTypes |
| Arithmetic types this endgame may compute in (sourced from the tracker). | |
| using | TupOfVec = typename NeededTypes::ToTupleOfVec |
| A tuple of vector containers, one per numeric type. | |
| using | TupOfReal = typename NeededTypes::ToTupleOfReal |
| A tuple of real values, one per numeric type. | |
| using | TupleOfTimes = typename NeededTypes::template ToTupleOfCont<TimeCont> |
| A tuple of time containers, one per numeric type. | |
| using | TupleOfSamps = typename NeededTypes::template ToTupleOfCont<SampCont> |
| A tuple of sample containers, one per numeric type. | |
Protected Member Functions | |
| void | RefreshCOverKProbe (unsigned size) const |
| Draw the c/k probe direction for a run. | |
| template<typename ComplexT> | |
| Vec< ComplexT > const & | GetCOverKProbe (unsigned size, unsigned prec) const |
| The fixed random direction the c/k estimate is projected along. | |
| const FlavorT & | AsFlavor () const |
| convert the base endgame into the derived type. | |
| FlavorT & | AsFlavor () |
| Non-const version of AsFlavor. | |
| void | NotifyObservers (AnyEvent const &e) const |
| Sends an event to observers that subscribed to its exact dynamic type, then to all catch-all (untyped) observers. | |
| void | NotifyObservers (AnyEvent &e) const |
| Notify all observers of a (mutable) event. | |
| bool | HasObservers () const |
| Whether anyone is currently observing (conservative). | |
Protected Attributes | |
| Vec< BCT > | final_approximation_ |
| The latest computed approximation of the endpoint. | |
| Vec< BCT > | previous_approximation_ |
| The previous approximation of the endpoint. | |
| unsigned int | cycle_number_ = 0 |
| The current estimate of the cycle number. | |
| NumErrorT | approximate_error_ = std::numeric_limits<NumErrorT>::infinity() |
| The error estimate between successive approximations. | |
| BCT | start_time_ {} |
| The endgame boundary time; set via SetBoundaryTime(). | |
| BCT | target_time_ {} |
| The final target time (default 0); set via SetTargetTime(). | |
| Vec< complex_dbl > | c_over_k_probe_as_drawn_ |
| The random direction the c/k estimate is projected along, as drawn: in double precision, so that it is exact in every lane and at every multiple precision. | |
| TupOfVec | c_over_k_probe_ |
| The c/k probe in each numeric type the endgame computes in: exact conversions of c_over_k_probe_as_drawn_, re-derived when their size or precision is wrong, never rounded. | |
Base endgame class for all endgames offered in Bertini2.
Endgames in Bertini2 are the engine for finishing homotopy continuation where we may encounter singular solutions. The path is implicitly described by the system being tracked.
Since the Bertini Endgames have common functionality, and we want to be able to call arbitrary algorithms using and tracker type, we use inheritance. That is, there is common functionality in all endgames, such as
ComputeInitialSamples
Also, there are settings that will be kept at this level to not duplicate code.
To create a new endgame type, inherit from this class.
| using bertini::endgame::EndgameBase< FlavorT, PrecT >::BaseComplexT = typename tracking::TrackerTraits<TrackerType>::BaseComplexT |
The complex number type.
| using bertini::endgame::EndgameBase< FlavorT, PrecT >::BaseRealT = typename tracking::TrackerTraits<TrackerType>::BaseRealT |
The real number type.
|
protected |
The complex number type.
|
protected |
The real number type.
| using bertini::endgame::EndgameBase< FlavorT, PrecT >::Config = detail::Configured< typename AlgoTraits<FlavorT>::NeededConfigs > |
The configuration bundle this endgame reads, public so that generic machinery which works in terms of an object's configs – the Python bindings' ConfiguredVisitor, which needs Config::UsedConfigs – can serve an endgame the same way it serves a tracker or a solver.
The same type as the protected Configured alias below.
|
protected |
The configuration bundle (Configured base).
|
protected |
The configuration structs as a tuple.
|
protected |
The Configured base type.
| using bertini::endgame::EndgameBase< FlavorT, PrecT >::EmitterType = FlavorT |
The event-emitter type.
|
protected |
Arithmetic types this endgame may compute in (sourced from the tracker).
| using bertini::endgame::EndgameBase< FlavorT, PrecT >::TrackerType = typename PrecT::TrackerType |
The path-tracker type.
|
protected |
A tuple of sample containers, one per numeric type.
|
protected |
A tuple of time containers, one per numeric type.
|
protected |
A tuple of real values, one per numeric type.
|
protected |
A tuple of vector containers, one per numeric type.
|
inherited |
The list of configuration types this object holds.
|
inlineexplicit |
Construct the endgame for a tracker, with its configuration as a tuple.
|
inlineexplicit |
Construct the endgame for a tracker, with configs given in any order.
|
virtualdefault |
|
inlineinherited |
Add an observer (non-owning) to observe this observable.
Stores only a raw reference: the caller is responsible for keeping the observer alive while it is attached. This is the right overload for stack-allocated C++ observers added and removed within a scope. For an observer whose lifetime you would rather have tracked, see the shared_ptr overload.
Observers that override SubscribedEventTypes() with a non-empty list are registered in a type-indexed map so NotifyObservers only calls them for events they declared interest in. Observers returning an empty list (the default) are placed in a catch-all list and receive every event.
Safe to call from inside an observer's Observe() (i.e. during a notification): the add is deferred and applied once the current notification loop finishes. This is what lets a "meta-observer" attach new observers in response to events.
| IncompatibleObserver | if the observer's ObservedKind() is not one this observable can be observed as. |
|
inlineinherited |
Add an observer whose lifetime is co-owned by this observable.
The observable keeps a shared_ptr, so the observer stays alive (and keeps receiving events) for as long as it is attached, even after the caller drops their own reference — "attach it and forget it", with no dangling. It is released when RemoveObserver is called or this observable is destroyed. (Stack-allocated C++ observers can't be shared_ptr-owned; use the reference overload for those.)
| IncompatibleObserver | if incompatible (see the reference overload). |
|
inline |
Get the most recent accuracy estimate.
|
inlineprotected |
Non-const version of AsFlavor.
|
inlineprotected |
convert the base endgame into the derived type.
This enables the CRPT as used by the endgames
|
inline |
|
inline |
|
inline |
Have the last few c/k estimates settled to within the user's threshold?
The operating-zone test: consecutive estimates agreeing to within minimum_for_c_over_k_stabilization, for num_needed_for_stabilization of them, is taken as the cycle-number estimate having settled. Both endgames use this and mean the same thing by it (b2#402).
| T | The element type of the estimate window; real or complex, since only its magnitude is read (the Cauchy endgame keeps reals, the power series endgame keeps its numeric type). |
| c_over_k_array | The estimates so far, oldest first. |
|
inline |
An estimate of c/k from the three most recent geometric samples.
Assumes the path is in the endgame operating zone, where the Puiseux asymptotics dominate; as the cycle-number estimate settles, successive values of this estimate settle with it, which is what CheckForCOverKStabilization watches for.
It reads only the geometrically-spaced approach samples and the fixed probe, which every endgame flavor maintains – the power series endgame's samples_ and the Cauchy endgame's pseg_samples_ are the same window under two names – so it belongs here rather than to either flavor (b2#402). Consult page 53 of [4] for the heuristic.
| ComplexT | The complex number type. |
| samples | The geometric approach samples; the first three are used. |
|
inline |
Get the system being tracked on, which is referred to by the tracker.
Populates time and space samples so that we are ready to start the endgame.
start_time: is the time when we start the endgame process usually this is .1
x_endgame_start: is the space value at start_time
times: a deque of time values. These values will be templated to be ComplexT
samples: a deque of sample values that are in correspondence with the values in times. These values will be vectors with entries of ComplexT.
SuccessCode indicating whether tracking to all samples was successful.
The first sample will be (x_endgame_start) and the first time is start_time. From there we do a geometric progression using the sample factor (which by default is 1/2). Hence, next_time = start_time * sample_factor. We track then to the next_time and construct the next_sample.
| start_time | The time value at which we start the endgame. |
| target_time | The time value that we are trying to find a solution to. |
| x_endgame_start | The current space point at start_time. |
| times | A deque that will hold all the time values of the samples we are going to use to start the endgame. |
| samples | a deque that will hold all the samples corresponding to the time values in times. |
| ComplexT | The complex number type. |
|
inline |
|
inline |
Set the cycle number.
|
inline |
Announce a completed sample point on the path, as a ComputedSamplePoint.
The payload rides at BaseComplexT, so the adaptive endgame's hardware-double fast lane must convert – and only pays for that when something is actually observing. Shared by the initial window here and by each flavor's time advance, so the conversion rule lives in one place.
| sample | The newly completed sample point on the path. |
| time | The time value at which it was computed. |
| ComplexT | The complex number type the endgame is currently working in. |
|
inline |
This function is inferior to the templated Get<ConfigT> function provided.
|
inline |
Track through the tracker, adapting at the numeric-type boundary.
The tracker's TrackPath I/O is fixed to BaseComplexT (its TrackerLoopInitialization / CopySolution are non-templatable virtuals). When the adaptive-numeric-type endgame is computing in the hardware complex_dbl fast lane (ComplexT != BCT, i.e. the AMP case), we convert at the boundary: hand the tracker mpfr points at DoublePrecision – so the AMP tracker uses its hardware-double slot internally – then downcast the result back to complex_dbl. If the tracker escalated internally (GetCurrentPrecision() > DoublePrecision()), the caller's escalation hook discards this result and migrates the endgame to mpfr, so the truncating downcast is harmless.
When ComplexT == BCT (every fixed-precision tracker, and the AMP endgame's mpfr lane) this is a direct, zero-overhead call to the tracker – byte-identical to calling TrackPath itself.
MICRO-OPT (future): a native complex_dbl TrackPath overload on the AMP tracker would remove the boundary conversion churn (~1-2% of a track). Deferred – see the sprint notes.
|
inline |
Raise the endgame to the next precision and migrate the containers' complex_dbl slot up to complex_mp when the tracker's authority escalates.
|
inline |
Get the most-recent approximation.
|
inline |
Get the final tolerance to which we are tracking the solution.
|
inlineinherited |
Get the held configuration object of type T.
|
inlineprotected |
The fixed random direction the c/k estimate is projected along.
An exact conversion of the direction as drawn, at the requested precision. Converted, not rounded in place: the drawn values are doubles, which every multiple precision holds exactly, so the direction is the same in both lanes and survives any change of precision.
| ComplexT | The complex number type. |
| size | The number of coordinates the probe must have. |
| prec | The working precision to supply it at. |
|
inlineprotectedinherited |
Whether anyone is currently observing (conservative).
Lets an emitter skip constructing an event – and any work needed to build its payload, such as a numeric-type conversion – when there is no observer to receive it. Conservative: returns true if any watcher list is non-empty (even if a stale, emptied typed bucket lingers), so it never wrongly suppresses a real observer.
|
inline |
Increase the cycle number by the given increment.
|
inline |
Get the latest time at which a point on the path was computed.
|
inlineprotectedinherited |
Notify all observers of a (mutable) event.
|
inlineprotectedinherited |
Sends an event to observers that subscribed to its exact dynamic type, then to all catch-all (untyped) observers.
Mutations of the observer lists are deferred for the duration of a notification (see AddObserver/RemoveObserver), so iterating the live lists here is safe even when an observer subscribes/unsubscribes mid-dispatch. An observer that returns ObserveResult::Unsubscribe is dropped once the (possibly nested) notification completes. The depth counter keeps this correct under re-entrant emission.
|
inlinevirtualinherited |
Whether this observable may be observed as the given type.
Drives the compatibility check in AddObserver. The default accepts the wildcard typeid(void) and this observable's own dynamic type. An observable that emits its events templated on a base type (so a single observer type serves many concrete observables) should also accept that base type — e.g. ZeroDim accepts AnyZeroDim.
Reimplemented in bertini::algorithm::HomotopySolver< TrackerType, EndgameType, SystemType >, and bertini::algorithm::HomotopySolver< A, B, C >.
|
inline |
Get the second-most-recent approximation.
|
inline |
Refine every sample point to the endgame's refinement tolerance.
|
inline |
A function passed off to the precision-specific endgame part.
Templated on ComplexT so the adaptive-numeric-type endgame can refine in the hardware-complex_dbl fast lane as well as in complex_mp. The precision policy (FixedPrecEndgame / AMPEndgame) provides the matching RefineSampleImpl overload(s). Fixed precision only ever instantiates this at BCT.
|
inlineprotected |
Draw the c/k probe direction for a run.
Called at the start of every run, after whatever reseed the caller does for the path, so the direction is a function of the random-number stream at that point and nothing else.
| size | The number of coordinates the probe must have. |
|
inlineinherited |
Remove an observer from this observable.
Like AddObserver, this is safe to call during a notification: the removal is deferred until the current notification loop finishes.
|
inline |
Run the endgame from the stored boundary time to the stored target time.
Re-precisions the stored times to match start_point before dispatching to RunImpl, so the caller never needs to worry about precision alignment.
Call SetBoundaryTime() before invoking Run().
|
inline |
|
inlineinherited |
Set the held configuration object of type T.
|
inline |
Set the endgame boundary (start) time.
|
inline |
Setter for the final tolerance.
|
inline |
Set the final target time.
|
inline |
|
mutableprotected |
The error estimate between successive approximations.
Initialized to infinity, not left indeterminate: ApproximateError() is a public accessor, so a caller may read it before any endgame has run. Infinity is also the only safe sentinel here – every convergence gate in the flavors has the shape approximate_error_ < FinalTolerance(), and an indeterminate value that happened to be small would be a false convergence.
|
mutableprotected |
The c/k probe in each numeric type the endgame computes in: exact conversions of c_over_k_probe_as_drawn_, re-derived when their size or precision is wrong, never rounded.
|
mutableprotected |
The random direction the c/k estimate is projected along, as drawn: in double precision, so that it is exact in every lane and at every multiple precision.
Drawn at the start of every run (RefreshCOverKProbe) and fixed for the run, so consecutive estimates differ only because the samples differ. A fresh random probe every call made the stabilization test noisy – it could certify the operating zone spuriously – and churned mpfr allocations. See z_notes/20260629.
|
inherited |
The held configuration objects, one per config type.
|
mutableprotected |
The current estimate of the cycle number.
|
mutableprotected |
The latest computed approximation of the endpoint.
|
mutableprotected |
The previous approximation of the endpoint.
|
protected |
The endgame boundary time; set via SetBoundaryTime().
|
protected |
The final target time (default 0); set via SetTargetTime().