Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

kathvargasr
Copy link
Contributor

No description provided.

@kathvargasr kathvargasr force-pushed the feature/test-study-refactoring branch from 57f8f1f to f2e79db Compare October 10, 2022 08:36
@kathvargasr kathvargasr force-pushed the feature/test-study-refactoring branch 4 times, most recently from ab33615 to 07da5d9 Compare October 25, 2022 09:33
@kathvargasr kathvargasr force-pushed the feature/test-study-refactoring branch from 07da5d9 to c166bb2 Compare October 25, 2022 09:53
@kathvargasr kathvargasr marked this pull request as ready for review October 26, 2022 07:13
Copy link
Member

@flomnes flomnes left a 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/libs/antares/study/load-params.cpp Outdated Show resolved Hide resolved
src/libs/antares/study/load-params.cpp Outdated Show resolved Hide resolved
src/libs/antares/study/study.cpp Outdated Show resolved Hide resolved
src/libs/antares/study/study.cpp Outdated Show resolved Hide resolved
src/libs/antares/study/study.cpp Outdated Show resolved Hide resolved
src/libs/antares/study/study.cpp Outdated Show resolved Hide resolved
src/libs/antares/study/study.cpp Outdated Show resolved Hide resolved
src/libs/antares/study/study.cpp Outdated Show resolved Hide resolved
src/tests/src/libs/antares/study/loader/CMakeLists.txt Outdated Show resolved Hide resolved
@kathvargasr kathvargasr force-pushed the feature/test-study-refactoring branch from 9a6db98 to 0897afd Compare October 26, 2022 15:02
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 34 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

add_subdirectory(scenario-builder)
add_subdirectory(loader)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

study-loader

Comment on lines +51 to +53
void initializeSetsData(){
pstudy->initializeSetsData();
}
Copy link
Member

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.

Comment on lines +58 to +65
void inputExtensionCompatibility(){
pstudy->inputExtensionCompatibility();
}
//! Release all unnecessary buffers
void reduceMemoryUsage(){
pstudy->reduceMemoryUsage();
}
//@}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment on lines +78 to +79
#include "runtime.h"

Copy link
Member

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>;
Copy link
Member

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>

Copy link
Contributor

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>;
Copy link
Member

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

Comment on lines +2 to +3
#include <study.h>

Copy link
Member

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.

@guilpier-code
Copy link
Contributor

guilpier-code commented Nov 14, 2022

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;
Copy link
Contributor

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.

Comment on lines +558 to +559
computeRawNbParallelYear(options.forceParallel, options.maxNbYearsInParallel);
maxNbYearsInParallel = getNbYearsParallelRaw();
Copy link
Contributor

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>;
Copy link
Contributor

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
Copy link
Contributor

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>
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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.

@kathvargasr
Copy link
Contributor Author

replaced by #1017 and #1057

@kathvargasr kathvargasr closed this Jan 5, 2023
@kathvargasr kathvargasr deleted the feature/test-study-refactoring branch January 5, 2023 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants