-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TEST] Refactoring study's loader #893
Conversation
57f8f1f
to
f2e79db
Compare
ab33615
to
07da5d9
Compare
07da5d9
to
c166bb2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Function
Study::internalLoadFromFolder
is still way too long, consider cutting it into smaller functions
src/tests/src/libs/antares/study/loader/test-study-load-internal.cpp
Outdated
Show resolved
Hide resolved
9a6db98
to
0897afd
Compare
Kudos, SonarCloud Quality Gate passed! |
add_subdirectory(scenario-builder) | ||
add_subdirectory(loader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
study-loader
void initializeSetsData(){ | ||
pstudy->initializeSetsData(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added for tests, not tested though. Either remove from this attorney class, or test.
void inputExtensionCompatibility(){ | ||
pstudy->inputExtensionCompatibility(); | ||
} | ||
//! Release all unnecessary buffers | ||
void reduceMemoryUsage(){ | ||
pstudy->reduceMemoryUsage(); | ||
} | ||
//@} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
#include "runtime.h" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include at top ? Or don't include
** \brief Antares StudyWrapper | ||
*/ | ||
|
||
using pStudy = std::shared_ptr<Study>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Study::Ptr
is already an alias to shared_ptr<Study>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And pStudy is very often (if not every time) a class data member variable that contains an instance of Study, not a type as here. There can be a confusion.
{ | ||
|
||
public: | ||
using Ptr = std::shared_ptr<StudyWrapper>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed in my opinion. This object can be allocated on the stack
#include <study.h> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
study-wrapper.h isn't part of any CMakeFile. It may result in an incomplete dependency graph.
Why not leave a clear introduction to the work ? Ok, I often forget to leave one but it's still useful Caution : the comments I leave here are not necessarily mandatory, we should discuss them |
if (!nbLogicalCores) | ||
logs.fatal() << "Number of logical cores available is 0."; | ||
|
||
table[ncMin] = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rename table into number_of_MC_year_threads (for instance), table is meaningless.
Besides, uint in std::map<NumberOfCoresMode, uint>
is overstated. int is enough.
computeRawNbParallelYear(options.forceParallel, options.maxNbYearsInParallel); | ||
maxNbYearsInParallel = getNbYearsParallelRaw(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not :
maxNbYearsInParallel = computeRawNbParallelYear(options.forceParallel, options.maxNbYearsInParallel);
?
** \brief Antares StudyWrapper | ||
*/ | ||
|
||
using pStudy = std::shared_ptr<Study>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And pStudy is very often (if not every time) a class data member variable that contains an instance of Study, not a type as here. There can be a confusion.
*/ | ||
|
||
using pStudy = std::shared_ptr<Study>; | ||
class StudyWrapper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of this study wrapper ? (It may have a real benefit, but I can't see which one)
I can see that this wrapper is only used (for now) in the newly created tests. So, if it is meant to be used in the context of tests, maybe we should move it next to the tests.
@@ -48,6 +48,8 @@ | |||
#include <yuni/core/system/cpu.h> // For use of Yuni::System::CPU::Count() | |||
#include <math.h> // For use of floor(...) and ceil(...) | |||
|
|||
#include <string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <string>
: is it useful ?
@@ -320,151 +322,127 @@ void Study::ensureDataAreAllInitialized() | |||
StudyEnsureDataThermalPrepro(this); | |||
} | |||
|
|||
std::map<std::string, uint> Study::getRawNumberCoresPerLevel() | |||
|
|||
void Study::computeRawNbParallelYear(const bool forceParallel, const uint nbYearsParallelForced) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this file, all changes are related to parallel MC years, right ?
We could try to extract all the logic (computing sets of parallel years) from the study, in order to :
- empty a little bit the god class Study. Said in another way, it would the number of responsibilities of Study
- this extracted code could be tested in isolation.
- avoid currently existing code duplication with solver.hxx : buildSetsOfParallelYears(...)
We could have something like :
class setsOfParallelYearsCalculator // Or some name more accurate
{
public:
setsOfParallelYearsCalculator (
int nbYears,
bool userPlaylist,
int timeSeriesToGenerate,
int timeSeriesToRefresh,
bool forceParallel,
int forcedNbOfParallelYears // Today called "maxNbYearsInParallel"
);
void build(); // Main function, it would do what "computeNumberOfCores" does
bool allSetsParallelYearsHaveSameSize();
private:
// Private methods
computeRawNbParallelYear();
computeMinNbYearsInParallelYearSet();
// Private data members
std::vector<std::vector<uint>> setsOfParallelYears_;
}
Note :
- In this proposal, the class does not take the whole object parameters as an argument for its constructor. Instead, we would pass the constructor exactly the list of data it really needs. Indeed, class parameters can be split or can change. The data we give won't.
set.clear(); | ||
} | ||
|
||
uint size(Study::SingleSetOfAreas& set) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uint size(Study::SingleSetOfAreas& set) const
: I don't see the point of this function.
Instead of calling sets_of_areas_handler.size(set_of_areas)
, let's simply call sets_of_areas.size()
|
||
} | ||
|
||
class SetHandlerAreas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each method of class SetHandlerAreas is given a SingleSetOfAreas& set
(which is a std::set<Area*>
), and makes something with this argument.
Why not put the set in the class and rename the class setOfAreas ?
There would be some side effects to that change : it will bring some other changes in the code.
It remains to evaluate the size of these changes.
namespace Data | ||
{ | ||
|
||
bool Study::initializeInternalData(const StudyLoadOptions& options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently, method initializeInternalData does 3 (at least) things :
- it initializes parameters (it should be done by a method of class Parameters, or better : in the Parameters constructor, if possible)
- it initializes the calendar (same remark as above, with class Date::Calendar)
- it makes a check (should be moved with other checks : to be explored)
Each bullet should be separated from the others in a function / method
This split would have few consequences test-study-load-internal.cpp.
No description provided.