36#include <boost/type_index.hpp>
57 template<
class TrackerT>
59 :
public TypedObserver< FirstPrecisionRecorder<TrackerT>, TrackerT,
60 Initializing<typename TrackerTraits<TrackerT>::EventEmitterType,
61 typename TrackerTraits<TrackerT>::BaseComplexT>,
62 TrackingStarted<typename TrackerTraits<TrackerT>::EventEmitterType>,
63 PrecisionChanged<typename TrackerTraits<TrackerT>::EventEmitterType> >
64 { BOOST_TYPE_INDEX_REGISTER_CLASS
75 precision_increased_ =
false;
76 starting_precision_ = 0;
87 starting_precision_ = e.Get().CurrentPrecision();
103 precision_increased_ =
true;
104 next_precision_ = e.
Next();
105 time_of_first_increase_ = e.Get().CurrentTime();
113 return starting_precision_;
119 return next_precision_;
125 return precision_increased_;
131 return time_of_first_increase_;
138 bool have_start_ =
false;
139 unsigned starting_precision_ = 0;
140 unsigned next_precision_ = 0;
141 bool precision_increased_ =
false;
155 template<
class TrackerT>
157 :
public TypedObserver< MinMaxPrecisionRecorder<TrackerT>, TrackerT,
158 Initializing<typename TrackerTraits<TrackerT>::EventEmitterType,
159 typename TrackerTraits<TrackerT>::BaseComplexT>,
160 TrackingStarted<typename TrackerTraits<TrackerT>::EventEmitterType>,
161 PrecisionChanged<typename TrackerTraits<TrackerT>::EventEmitterType> >
162 { BOOST_TYPE_INDEX_REGISTER_CLASS
167 void Include(
unsigned p)
169 if (p < min_precision_)
171 if (p > max_precision_)
180 min_precision_ = std::numeric_limits<unsigned>::max();
188 Include(e.Get().CurrentPrecision());
203 return min_precision_;
209 return max_precision_;
214 { min_precision_ = m;}
218 { max_precision_ = m;}
224 unsigned min_precision_ = std::numeric_limits<unsigned>::max();
225 unsigned max_precision_ = 0;
239 template<
class TrackerT>
241 :
public TypedObserver< PathPrecisionRecorder<TrackerT>, TrackerT,
242 TrackingStarted<typename TrackerTraits<TrackerT>::EventEmitterType>,
243 PrecisionChanged<typename TrackerTraits<TrackerT>::EventEmitterType> >
244 { BOOST_TYPE_INDEX_REGISTER_CLASS
248 void Include(
unsigned p)
250 if (p < min_precision_)
252 if (p > max_precision_)
261 precision_increased_ =
false;
263 min_precision_ = std::numeric_limits<unsigned>::max();
270 Include(e.Get().CurrentPrecision());
281 precision_increased_ =
true;
282 time_of_first_increase_ = e.Get().CurrentTime();
303 bool precision_increased_ =
false;
305 unsigned min_precision_ = std::numeric_limits<unsigned>::max();
306 unsigned max_precision_ = 0;
311 template<
class TrackerT>
313 { BOOST_TYPE_INDEX_REGISTER_CLASS
319 const TrackingEvent<EmitterT>* p =
dynamic_cast<const TrackingEvent<EmitterT>*
>(&e);
322 precisions_.push_back(p->Get().CurrentPrecision());
338 std::vector<unsigned> precisions_;
346 template<
class TrackerT,
template<
class>
class EventT = SuccessfulStep>
348 :
public TypedObserver< AMPPathAccumulator<TrackerT,EventT>, TrackerT,
349 EventT<typename TrackerTraits<TrackerT>::EventEmitterType> >
350 { BOOST_TYPE_INDEX_REGISTER_CLASS
359 path_.push_back(e.Get().CurrentPoint());
364 const std::vector<Vec<complex_mp> >&
Path()
const
372 std::vector<Vec<complex_mp> > path_;
378 template<
class TrackerT>
380 { BOOST_TYPE_INDEX_REGISTER_CLASS
397 BOOST_LOG_TRIVIAL(severity_level::debug) << std::setprecision(
static_cast<int>(
DoublePrecision()))
398 <<
"initializing in double, tracking path\nfrom\tt = "
399 << p->StartTime() <<
"\nto\tt = " << p->EndTime()
400 <<
"\n from\tx = \n" << p->StartPoint()
401 <<
"\n tracking system " << p->Get().GetSystem() <<
"\n\n";
406 BOOST_LOG_TRIVIAL(severity_level::debug) << std::setprecision(
static_cast<int>(
Precision(p->StartPoint())))
407 <<
"initializing in multiprecision, tracking path\nfrom\tt = " << p->StartTime() <<
"\nto\tt = " << p->EndTime() <<
"\n from\tx = \n" << p->StartPoint()
408 <<
"\n tracking system " << p->Get().GetSystem() <<
"\n\n";
411 else if(
auto p =
dynamic_cast<const TrackingEnded<EmitterT>*
>(&e))
412 BOOST_LOG_TRIVIAL(severity_level::trace) <<
"tracking ended";
414 else if (
auto p =
dynamic_cast<const NewStep<EmitterT>*
>(&e))
417 BOOST_LOG_TRIVIAL(severity_level::trace) <<
"Tracker iteration " << t.NumTotalStepsTaken() <<
"\ncurrent precision: " << t.CurrentPrecision();
420 BOOST_LOG_TRIVIAL(severity_level::trace) << std::setprecision(
static_cast<int>(t.CurrentPrecision()))
421 <<
"t = " << t.CurrentTime()
422 <<
"\ncurrent stepsize: " << t.CurrentStepsize()
423 <<
"\ndelta_t = " << t.DeltaT()
424 <<
"\ncurrent x size = " << t.CurrentPoint().size()
425 <<
"\ncurrent x = " << t.CurrentPoint();
431 BOOST_LOG_TRIVIAL(severity_level::trace) <<
"singular start point";
432 else if (
auto p =
dynamic_cast<const InfinitePathTruncation<EmitterT>*
>(&e))
433 BOOST_LOG_TRIVIAL(severity_level::trace) <<
"tracker iteration indicated going to infinity, truncated path";
438 else if (
auto p =
dynamic_cast<const SuccessfulStep<EmitterT>*
>(&e))
440 BOOST_LOG_TRIVIAL(severity_level::trace) <<
"tracker iteration successful\n\n\n";
443 else if (
auto p =
dynamic_cast<const FailedStep<EmitterT>*
>(&e))
445 BOOST_LOG_TRIVIAL(severity_level::trace) <<
"tracker iteration unsuccessful\n\n\n";
455 BOOST_LOG_TRIVIAL(severity_level::trace) << std::setprecision(
static_cast<int>(
Precision(p->ResultingPoint()))) <<
"prediction successful (complex_mp), result:\n" << p->ResultingPoint();
459 BOOST_LOG_TRIVIAL(severity_level::trace) << std::setprecision(
static_cast<int>(
Precision(p->ResultingPoint()))) <<
"prediction successful (complex_dbl), result:\n" << p->ResultingPoint();
464 BOOST_LOG_TRIVIAL(severity_level::trace) << std::setprecision(
static_cast<int>(
Precision(p->ResultingPoint()))) <<
"correction successful (complex_mp), result:\n" << p->ResultingPoint();
468 BOOST_LOG_TRIVIAL(severity_level::trace) << std::setprecision(
static_cast<int>(
Precision(p->ResultingPoint()))) <<
"correction successful (complex_dbl), result:\n" << p->ResultingPoint();
472 else if (
auto p =
dynamic_cast<const PredictorHigherPrecisionNecessary<EmitterT>*
>(&e))
473 BOOST_LOG_TRIVIAL(severity_level::trace) <<
"Predictor, higher precision necessary";
474 else if (
auto p =
dynamic_cast<const CorrectorHigherPrecisionNecessary<EmitterT>*
>(&e))
475 BOOST_LOG_TRIVIAL(severity_level::trace) <<
"corrector, higher precision necessary";
479 else if (
auto p =
dynamic_cast<const CorrectorMatrixSolveFailure<EmitterT>*
>(&e))
480 BOOST_LOG_TRIVIAL(severity_level::trace) <<
"corrector, matrix solve failure or failure to converge";
481 else if (
auto p =
dynamic_cast<const PredictorMatrixSolveFailure<EmitterT>*
>(&e))
482 BOOST_LOG_TRIVIAL(severity_level::trace) <<
"predictor, matrix solve failure or failure to converge";
483 else if (
auto p =
dynamic_cast<const FirstStepPredictorMatrixSolveFailure<EmitterT>*
>(&e))
484 BOOST_LOG_TRIVIAL(severity_level::trace) <<
"Predictor, matrix solve failure in initial solve of prediction";
488 BOOST_LOG_TRIVIAL(severity_level::debug) <<
"changing precision from " << p->Previous() <<
" to " << p->Next();
491 BOOST_LOG_TRIVIAL(severity_level::debug) <<
"unlogged event, of type: " << boost::typeindex::type_id_runtime(e).pretty_name();
501 template<
class TrackerT>
503 :
public TypedObserver< StepFailScreenPrinter<TrackerT>, TrackerT,
504 FailedStep<typename TrackerTraits<TrackerT>::EventEmitterType> >
505 { BOOST_TYPE_INDEX_REGISTER_CLASS
513 std::cout <<
"observed step failure" << std::endl;
Contains the abstract base Tracker type, from which all other Trackers inherit.
Strawman Event type, enabling polymorphism.
Definition events.hpp:57
Actual observer type, which you should derive from to extract custom information from observable type...
Definition observer.hpp:117
CRTP base that turns an observer into a set of typed Observe() overloads.
Definition observer.hpp:201
Example usage: PathAccumulator<AMPTracker> path_accumulator;.
Definition observers.hpp:350
ObserveResult OnEvent(EventT< EmitterT > const &e)
On each observed event, append the tracker's current point to the path.
Definition observers.hpp:357
virtual ~AMPPathAccumulator()=default
const std::vector< Vec< complex_mp > > & Path() const
Get the accumulated path of space points.
Definition observers.hpp:364
Observer that records the starting precision and the first precision increase of each track: each cal...
Definition observers.hpp:64
TrackerTraits< TrackerT >::BaseComplexT TimeOfIncrease() const
Get the time value at which precision first increased.
Definition observers.hpp:129
ObserveResult OnEvent(TrackingStarted< EmitterT > const &e)
Tracking starts after the start point is refined: the start precision, unless a refinement change alr...
Definition observers.hpp:83
unsigned NextPrecision() const
Get the precision after the first increase.
Definition observers.hpp:117
ObserveResult OnEvent(Initializing< EmitterT, BCT > const &)
A track begins: the record starts afresh.
Definition observers.hpp:72
virtual ~FirstPrecisionRecorder()=default
bool DidPrecisionIncrease() const
Query whether precision increased at all during the track.
Definition observers.hpp:123
unsigned StartPrecision() const
Get the precision tracking started at.
Definition observers.hpp:111
ObserveResult OnEvent(PrecisionChanged< EmitterT > const &e)
A change of precision: the first one gives the start precision, and the first increase is recorded.
Definition observers.hpp:94
Observer that logs verbose ("gory detail") diagnostics for every tracking event.
Definition observers.hpp:380
virtual ~GoryDetailLogger()=default
typename TrackerTraits< TrackerT >::EventEmitterType EmitterT
The event-emitter type.
Definition observers.hpp:383
virtual ObserveResult Observe(AnyEvent const &e) override
Log a human-readable description of the event, dispatching on its dynamic type.
Definition observers.hpp:388
TrackPath is initializing the tracker.
Definition events.hpp:295
Observer that records the minimum and maximum precision of each track: each call to TrackPath,...
Definition observers.hpp:162
ObserveResult OnEvent(TrackingStarted< EmitterT > const &e)
Tracking starts: include the precision it starts at.
Definition observers.hpp:186
void MinPrecision(unsigned m)
Set the recorded minimum precision.
Definition observers.hpp:213
ObserveResult OnEvent(Initializing< EmitterT, BCT > const &)
A track begins: the record starts afresh.
Definition observers.hpp:178
void MaxPrecision(unsigned m)
Set the recorded maximum precision.
Definition observers.hpp:217
unsigned MinPrecision() const
Get the minimum precision observed.
Definition observers.hpp:201
ObserveResult OnEvent(PrecisionChanged< EmitterT > const &e)
A change of precision: include both ends of it.
Definition observers.hpp:193
unsigned MaxPrecision() const
Get the maximum precision observed.
Definition observers.hpp:207
virtual ~MinMaxPrecisionRecorder()=default
Observer that records the precision a whole path used, across every call to TrackPath that tracks it:...
Definition observers.hpp:244
TrackerTraits< TrackerT >::BaseComplexT TimeOfIncrease() const
The time of the path's first precision increase.
Definition observers.hpp:291
void Reset()
Start the record of a new path.
Definition observers.hpp:259
unsigned MinPrecision() const
The lowest precision the path used; the maximum unsigned value if it saw none.
Definition observers.hpp:294
ObserveResult OnEvent(PrecisionChanged< EmitterT > const &e)
A change of precision: include both ends, and record the path's first increase.
Definition observers.hpp:275
virtual ~PathPrecisionRecorder()=default
bool DidPrecisionIncrease() const
Whether precision increased anywhere on the path.
Definition observers.hpp:288
ObserveResult OnEvent(TrackingStarted< EmitterT > const &e)
A track of the path starts: include the precision it starts at.
Definition observers.hpp:268
unsigned MaxPrecision() const
The highest precision the path used; 0 if it saw none.
Definition observers.hpp:297
Observer that collects the precision at every tracking event into a vector.
Definition observers.hpp:313
virtual ~PrecisionAccumulator()=default
const std::vector< unsigned > & Precisions() const
Get the recorded sequence of precisions.
Definition observers.hpp:330
Event emitted when the tracker's working precision changes.
Definition events.hpp:139
auto Next() const
Get the next precision, what it changed to.
Definition events.hpp:166
auto Previous() const
Get the previous precision.
Definition events.hpp:161
Observer that prints a message to standard out whenever a step fails.
Definition observers.hpp:505
virtual ~StepFailScreenPrinter()=default
ObserveResult OnEvent(FailedStep< EmitterT > const &)
On a failed step, print a notice to standard out.
Definition observers.hpp:511
typename TrackerTraits< TrackerT >::EventEmitterType EmitterT
The event-emitter type.
Definition observers.hpp:508
The correct part of a time step was successful.
Definition events.hpp:102
The predict part of tracking step was successful.
Definition events.hpp:72
Logging in Bertini using Boost.Log.
Definition adaptive_precision_utilities.hpp:35
Definition algorithm_builder.hpp:36
constexpr unsigned DoublePrecision()
The number of digits considered "double precision" (16).
Definition num_traits.hpp:152
ObserveResult
The result an observer returns from Observe(), telling the observable whether to keep sending it even...
Definition observer.hpp:59
@ KeepObserving
Definition observer.hpp:59
@ SingularStartPoint
Definition config.hpp:62
unsigned Precision(Eigen::MatrixBase< Derived > const &v)
Get the precision of an Eigen object.
Definition eigen_extensions.hpp:339
Contains the observer base types.
Trait lookup mapping a tracker type to its numeric types, event-emitter type, precision config,...
Definition config.hpp:387
Contains the tracker/events base types.