AutoPas  3.0.0
Loading...
Searching...
No Matches
AutoTuner.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <cstddef>
10#include <memory>
11#include <set>
12#include <tuple>
13
21#include "autopas/utils/Timer.h"
24
25namespace autopas {
26
41class AutoTuner {
42 public:
46 using TuningStrategiesListType = std::vector<std::unique_ptr<TuningStrategyInterface>>;
50 using SearchSpaceType = std::set<Configuration>;
51
61 AutoTuner(TuningStrategiesListType &tuningStrategies, const SearchSpaceType &searchSpace,
62 const AutoTunerInfo &autoTunerInfo, unsigned int rebuildFrequency, const std::string &outputSuffix);
63
69 AutoTuner &operator=(AutoTuner &&other) noexcept;
70
74 void forceRetune();
75
81
86 void receiveLiveInfo(const LiveInfo &liveInfo);
87
93 bool isStartOfTuningPhase() const;
94
99 bool tuningPhaseAboutToBegin() const;
100
107 [[nodiscard]] bool needsLiveInfo() const;
108
113 void bumpIterationCounters(bool needToWait = false);
114
122 bool willRebuildNeighborLists() const;
123
128 [[nodiscard]] const Configuration &getCurrentConfig() const;
129
135 [[nodiscard]] std::tuple<Configuration, bool> getNextConfig();
136
149 [[nodiscard]] std::tuple<Configuration, bool> rejectConfig(const Configuration &rejectedConfig, bool indefinitely);
150
155 bool searchSpaceIsTrivial() const;
156
161 bool searchSpaceIsEmpty() const;
162
168 void logTuningResult(bool tuningIteration, long tuningTime) const;
169
174 bool initEnergy();
175
180 bool resetEnergy();
181
186 std::tuple<double, double, double, long> sampleEnergy();
187
198 void addMeasurement(long sample, bool neighborListRebuilt);
199
207 void addDomainSimilarityStatistics(double pdBinDensityStdDev, double pdBinMaxDensity);
208
213 const std::vector<Configuration> &getConfigQueue() const;
214
219 const std::vector<std::unique_ptr<TuningStrategyInterface>> &getTuningStrategies() const;
220
225 bool inTuningPhase() const;
226
231 bool inFirstTuningIteration() const;
232
237 bool inLastTuningIteration() const;
238
244
249 bool canMeasureEnergy() const;
250
257 void setRebuildFrequency(double rebuildFrequency);
258
266
267 private:
272 size_t getCurrentNumSamples() const;
273
280 [[nodiscard]] long estimateRuntimeFromSamples() const;
281
291 bool tuneConfiguration();
292
296 SelectorStrategyOption _selectorStrategy;
297
302 std::vector<std::unique_ptr<TuningStrategyInterface>> _tuningStrategies;
303
308 size_t _iteration{0};
309
316 size_t _tuningPhase{0};
317
322 size_t _tuningInterval;
323
327 TuningMetricOption _tuningMetric;
328
332 bool _useLOESSSmoothening;
333
338 bool _energyMeasurementPossible;
339
346 double _rebuildFrequency;
347
351 size_t _maxSamples;
352
357 double _earlyStoppingFactor;
358
362 bool _needsDomainSimilarityStatistics;
363
367 bool _needsLiveInfo;
368
372 std::vector<double> _pdBinDensityStdDevOfLastTenIterations{};
373
377 std::vector<double> _pdBinMaxDensityOfLastTenIterations{};
378
385 std::vector<long> _samplesNotRebuildingNeighborLists;
386
391 std::vector<long> _samplesRebuildingNeighborLists{};
392
396 EvidenceCollection _evidenceCollection{};
397
401 SearchSpaceType _searchSpace;
402
409 std::vector<Configuration> _configQueue;
410
414 TuningResultLogger _tuningResultLogger;
415
419 TuningDataLogger _tuningDataLogger;
420
424 utils::EnergySensor _energySensor;
425
429 bool _isTuning{false};
430
436 bool _endOfTuningPhase{false};
437
442 bool _forceRetune{false};
443
448 bool _earlyStoppingOfResampling{false};
449
455 size_t _iterationBaseline{0};
456};
457} // namespace autopas
This class manages all logic related to the auto tuning mechanic.
Definition: AutoTuner.h:41
std::tuple< double, double, double, long > sampleEnergy()
Take an energy measurement.
Definition: AutoTuner.cpp:348
bool searchSpaceIsEmpty() const
Indicator function whether the search space has no configurations in it.
Definition: AutoTuner.cpp:76
void addDomainSimilarityStatistics(double pdBinDensityStdDev, double pdBinMaxDensity)
Adds domain similarity statistics to a vector of measurements, which can be smoothed for use in MPI T...
Definition: AutoTuner.cpp:59
AutoTuner & operator=(AutoTuner &&other) noexcept
Move assignment operator.
Definition: AutoTuner.cpp:54
void bumpIterationCounters(bool needToWait=false)
Increase internal iteration counters by one.
Definition: AutoTuner.cpp:307
std::tuple< Configuration, bool > getNextConfig()
Ask the tuner for the next configuration to use.
Definition: AutoTuner.cpp:176
void logTuningResult(bool tuningIteration, long tuningTime) const
After a tuning phase has finished, write the result to a file.
Definition: AutoTuner.cpp:64
std::set< Configuration > SearchSpaceType
Type for the search space holding all possible configurations.
Definition: AutoTuner.h:50
bool willRebuildNeighborLists() const
Returns whether rebuildNeighborLists() should be triggered in the next iteration.
Definition: AutoTuner.cpp:327
bool resetEnergy()
Reset the rapl meter to prepare for a new measurement.
Definition: AutoTuner.cpp:346
const std::vector< std::unique_ptr< TuningStrategyInterface > > & getTuningStrategies() const
Get the list of tuning strategies that are used.
Definition: AutoTuner.cpp:386
std::vector< std::unique_ptr< TuningStrategyInterface > > TuningStrategiesListType
Type for the member holding all tuning strategies.
Definition: AutoTuner.h:46
bool isStartOfTuningPhase() const
Returns true if the AutoTuner is about to calculate the first interactions of a tuning phase (i....
Definition: AutoTuner.cpp:373
bool inLastTuningIteration() const
Indicate if the tuner is in the last iteration of the tuning phase.
Definition: AutoTuner.cpp:428
std::tuple< Configuration, bool > rejectConfig(const Configuration &rejectedConfig, bool indefinitely)
Tell the tuner that the given config is not applicable.
Definition: AutoTuner.cpp:192
void addMeasurement(long sample, bool neighborListRebuilt)
Save the runtime of a given traversal.
Definition: AutoTuner.cpp:228
bool needsLiveInfo() const
Returns true if the AutoTuner needs live info.
Definition: AutoTuner.cpp:379
const std::vector< Configuration > & getConfigQueue() const
Getter for the current queue of configurations.
Definition: AutoTuner.cpp:384
bool initEnergy()
Initialize pmt sensor.
Definition: AutoTuner.cpp:341
bool canMeasureEnergy() const
Returns whether the AutoTuner can take energy measurements.
Definition: AutoTuner.cpp:432
bool inTuningPhase() const
Indicate if the tuner considers itself currently in a tuning phase according to its internal counters...
Definition: AutoTuner.cpp:420
void receiveLiveInfo(const LiveInfo &liveInfo)
Pass live info on to all tuning strategies.
Definition: AutoTuner.cpp:390
bool inFirstTuningIteration() const
Indicate if the tuner is in the first iteration of a tuning phase.
Definition: AutoTuner.cpp:426
const Configuration & getCurrentConfig() const
Get the currently selected configuration.
Definition: AutoTuner.cpp:174
const EvidenceCollection & getEvidenceCollection() const
Getter for the internal evidence collection.
Definition: AutoTuner.cpp:430
const TuningMetricOption & getTuningMetric() const
Getter for the primary metric for tuning.
Definition: AutoTuner.cpp:418
bool searchSpaceIsTrivial() const
Indicator function whether the search space consists of exactly one configuration.
Definition: AutoTuner.cpp:74
void forceRetune()
Force the internal tuner to enter a new tuning phase upon the next call to computeInteractions().
Definition: AutoTuner.cpp:78
void setRebuildFrequency(double rebuildFrequency)
Sets the _rebuildFrequency.
Definition: AutoTuner.cpp:434
void checkEarlyStoppingCondition()
Checks whether the current configuration performs so poorly that it shouldn't be resampled further wi...
Definition: AutoTuner.cpp:436
bool tuningPhaseAboutToBegin() const
Returns true if the AutoTuner is within 10 iterations of the start of a tuning phase.
Definition: AutoTuner.cpp:377
Class containing multiple options that form an algorithm configuration for the pairwise iteration.
Definition: Configuration.h:24
Class to manage all evidence.
Definition: EvidenceCollection.h:21
This class is able to gather and store important information for a tuning phase from a container and ...
Definition: LiveInfo.h:32
Class representing the load estimator choices.
Definition: TuningMetricOption.h:18
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
Helper struct encapsulating most minor information for the auto tuner.
Definition: AutoTunerInfo.h:17