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
101 bool prepareIteration();
102
107 void bumpIterationCounters(bool needToWait = false);
108
116 bool willRebuildNeighborLists() const;
117
122 [[nodiscard]] const Configuration &getCurrentConfig() const;
123
129 [[nodiscard]] std::tuple<Configuration, bool> getNextConfig();
130
143 [[nodiscard]] std::tuple<Configuration, bool> rejectConfig(const Configuration &rejectedConfig, bool indefinitely);
144
149 bool searchSpaceIsTrivial() const;
150
155 bool searchSpaceIsEmpty() const;
156
162 void logTuningResult(bool tuningIteration, long tuningTime) const;
163
168 bool initEnergy();
169
174 bool resetEnergy();
175
180 std::tuple<double, double, double, long> sampleEnergy();
181
192 void addMeasurement(long sample, bool neighborListRebuilt);
193
200 void addHomogeneityAndMaxDensity(double homogeneity, double maxDensity, long time);
201
206 const std::vector<Configuration> &getConfigQueue() const;
207
212 const std::vector<std::unique_ptr<TuningStrategyInterface>> &getTuningStrategies() const;
213
218 bool inTuningPhase() const;
219
224 bool inFirstTuningIteration() const;
225
230 bool inLastTuningIteration() const;
231
237
242 bool canMeasureEnergy() const;
243
250 void setRebuildFrequency(double rebuildFrequency);
251
259
260 private:
265 size_t getCurrentNumSamples() const;
266
273 [[nodiscard]] long estimateRuntimeFromSamples() const;
274
284 bool tuneConfiguration();
285
289 SelectorStrategyOption _selectorStrategy;
290
295 std::vector<std::unique_ptr<TuningStrategyInterface>> _tuningStrategies;
296
301 size_t _iteration{0};
302
309 size_t _tuningPhase{0};
310
315 size_t _tuningInterval;
316
320 TuningMetricOption _tuningMetric;
321
325 bool _useLOESSSmoothening;
326
331 bool _energyMeasurementPossible;
332
339 double _rebuildFrequency;
340
344 size_t _maxSamples;
345
350 double _earlyStoppingFactor;
351
355 bool _needsHomogeneityAndMaxDensity;
356
360 bool _needsLiveInfo;
361
365 std::vector<double> _homogeneitiesOfLastTenIterations{};
366
370 std::vector<double> _maxDensitiesOfLastTenIterations{};
371
378 std::vector<long> _samplesNotRebuildingNeighborLists;
379
384 std::vector<long> _samplesRebuildingNeighborLists{};
385
389 EvidenceCollection _evidenceCollection{};
390
394 SearchSpaceType _searchSpace;
395
402 std::vector<Configuration> _configQueue;
403
408 autopas::utils::Timer _timerCalculateHomogeneity;
409
413 TuningResultLogger _tuningResultLogger;
414
418 TuningDataLogger _tuningDataLogger;
419
423 utils::EnergySensor _energySensor;
424
428 bool _isTuning{false};
429
435 bool _endOfTuningPhase{false};
436
441 bool _forceRetune{false};
442
447 bool _earlyStoppingOfResampling{false};
448
454 size_t _iterationBaseline{0};
455};
456} // 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:349
bool searchSpaceIsEmpty() const
Indicator function whether the search space has no configurations in it.
Definition: AutoTuner.cpp:77
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:308
std::tuple< Configuration, bool > getNextConfig()
Ask the tuner for the next configuration to use.
Definition: AutoTuner.cpp:177
void addHomogeneityAndMaxDensity(double homogeneity, double maxDensity, long time)
Adds measurements of homogeneity and maximal density to the vector of measurements.
Definition: AutoTuner.cpp:59
void logTuningResult(bool tuningIteration, long tuningTime) const
After a tuning phase has finished, write the result to a file.
Definition: AutoTuner.cpp:65
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:328
bool resetEnergy()
Reset the rapl meter to prepare for a new measurement.
Definition: AutoTuner.cpp:347
const std::vector< std::unique_ptr< TuningStrategyInterface > > & getTuningStrategies() const
Get the list of tuning strategies that are used.
Definition: AutoTuner.cpp:420
std::vector< std::unique_ptr< TuningStrategyInterface > > TuningStrategiesListType
Type for the member holding all tuning strategies.
Definition: AutoTuner.h:46
bool inLastTuningIteration() const
Indicate if the tuner is in the last iteration of the tuning phase.
Definition: AutoTuner.cpp:440
std::tuple< Configuration, bool > rejectConfig(const Configuration &rejectedConfig, bool indefinitely)
Tell the tuner that the given config is not applicable.
Definition: AutoTuner.cpp:193
void addMeasurement(long sample, bool neighborListRebuilt)
Save the runtime of a given traversal.
Definition: AutoTuner.cpp:229
const std::vector< Configuration > & getConfigQueue() const
Getter for the current queue of configurations.
Definition: AutoTuner.cpp:418
bool initEnergy()
Initialize pmt sensor.
Definition: AutoTuner.cpp:342
bool canMeasureEnergy() const
Returns whether the AutoTuner can take energy measurements.
Definition: AutoTuner.cpp:444
bool inTuningPhase() const
Indicate if the tuner considers itself currently in a tuning phase according to its internal counters...
Definition: AutoTuner.cpp:432
bool needsHomogeneityAndMaxDensityBeforePrepare() const
Indicator whether tuner needs homogeneity and max density information before the next call to prepare...
Definition: AutoTuner.cpp:411
void receiveLiveInfo(const LiveInfo &liveInfo)
Pass live info on to all tuning strategies.
Definition: AutoTuner.cpp:424
bool inFirstTuningIteration() const
Indicate if the tuner is in the first iteration of a tuning phase.
Definition: AutoTuner.cpp:438
const Configuration & getCurrentConfig() const
Get the currently selected configuration.
Definition: AutoTuner.cpp:175
const EvidenceCollection & getEvidenceCollection() const
Getter for the internal evidence collection.
Definition: AutoTuner.cpp:442
const TuningMetricOption & getTuningMetric() const
Getter for the primary metric for tuning.
Definition: AutoTuner.cpp:430
bool searchSpaceIsTrivial() const
Indicator function whether the search space consists of exactly one configuration.
Definition: AutoTuner.cpp:75
bool prepareIteration()
Determines what live infos are needed and passes collected live info to the tuning strategies.
Definition: AutoTuner.cpp:374
void forceRetune()
Force the internal tuner to enter a new tuning phase upon the next call to computeInteractions().
Definition: AutoTuner.cpp:79
void setRebuildFrequency(double rebuildFrequency)
Sets the _rebuildFrequency.
Definition: AutoTuner.cpp:446
void checkEarlyStoppingCondition()
Checks whether the current configuration performs so poorly that it shouldn't be resampled further wi...
Definition: AutoTuner.cpp:448
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:31
Class representing the load estimator choices.
Definition: TuningMetricOption.h:18
Timer class to stop times.
Definition: Timer.h:20
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