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

Thermal clusters lists : cleaning #1844

Merged
merged 94 commits into from
Feb 22, 2024
Merged

Conversation

guilpier-code
Copy link
Contributor

@guilpier-code guilpier-code commented Dec 22, 2023

This PR follows the PR #1809 (about cleaning common cluster list and renewable cluster list)
It aims at simplifying thermal cluster lists as much as possible.

Goal :
Having only one list of thermal clusters.
This list would be private
Code would interact with this list through an interface. This interface would contain functions returning std::views that would result in filtering thermal clusters using a certain property of clusters : enabled / disabled, must-run or not, a combination of these.

What's done :

  • Simplifying the ClusterList<T>::add() method
  • Changing std::map mapping from class ThermalClusterList into a std::vector (named allClusters_)
  • Removing PartThermal::clusters (often reached by area.thermal.clusters)
  • Removing PartThermal::mustrunList (often reached by area.thermal.mustrunList)
  • Removing PartThermal::list (often reached by area.thermal.list.clusters)

Before starting a review, one should know several things :

  • what the old lists of clusters used to contain :
    • area.thermal.list.mapping : all clusters
    • area.thermal.mustrunList.clusters : clusters must-run and enabled
    • area.thermal.clusters : enabled clusters
    • area.thermal.list.clusters : list used to build the optimization problem (clusters enabled and not must-run). Careful with that list : when loading clusters from input, this list contains all clusters. Then it is progressively cleared from disabled and must-run clusters. So its content depends on where we are in the execution. This list is also used from the GUI. In that case, it always contains all clusters : it is not cleared from specific clusters.
  • the list area.thermal.list.clusters is the only list used in the GUI, and in that case, it contains all clusters.
  • As said previously, all lists of clusters are removed, except area.thermal.list.mapping, turned into a private std::vector (area.thermal.list.allClusters_) containing all clusters, and filtered to access only clusters of interest at any point of the code.
  • cluster indices : any cluster (thermal / renewable) used to have 2 indices :
    • index : it turns out to be an index regarding only enabled and not must-run clusters. So this index never concerns renewable clusters. It was moved down from parent class Cluster to class ThermalCluster.
    • areaWideIndex : index regarding only enabled clusters. Concerns both thermal and renewable clusters
  • the 2 lists area.thermal.mustrunList.clusters and area.thermal.list.clusters are closely related (inter-dependent) to the renewable cluster list, due to a common inheritance. So this work deeply impacts the renewable cluster lists.

Copy link

watermelon-copilot-for-code-review bot commented Dec 22, 2023

Watermelon AI Summary

AI Summary deactivated by guilpier-code

GitHub PRs

Antares_Simulator is an open repo and Watermelon will serve it for free.
🍉🫶

@pull-request-size pull-request-size bot added size/L and removed size/M labels Dec 26, 2023
@guilpier-code guilpier-code force-pushed the fix/clean_thermal_lists branch from d022bb6 to 7c7b6ea Compare December 27, 2023 10:33
@pull-request-size pull-request-size bot added size/M and removed size/L labels Dec 27, 2023
Base automatically changed from fix/renew-lists to develop December 27, 2023 13:06
thermalTSRefresh
= thermalTSRefresh || cluster.doWeGenerateTS(globalThermalTSgeneration);
});
for (auto c : area.thermal.list.each_enabled_and_not_mustrun())
Copy link
Member

Choose a reason for hiding this comment

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

Some redundancy. In some cases, we want to iterate over a container. In other cases, we want the number of elements.

It would be nicer to have

for (auto c : thermal.list.enabledNotMustRun.each())
{
 // ...
}
auto nbClusters = thermal.list.enabledNotMustRun.count();

Also, clear

thermal.list.enabledNotMustRun.clear();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So what you suggest is several lists, right ?
If so, it's goes in the opposite direction of the current work, which is to have only one list that we can filter.

@@ -136,8 +136,6 @@ class StudyRuntimeInfos
void initializeRangeLimits(const Study& study, StudyRangeLimits& limits);
//! Prepare all thermal clusters in 'must-run' mode
void initializeThermalClustersInMustRunMode(Study& study) const;
void removeDisabledThermalClustersFromSolverComputations(Study& study);
void removeDisabledRenewableClustersFromSolverComputations(Study& study);
void removeDisabledShortTermStorageClustersFromSolverComputations(Study& study);
Copy link
Member

Choose a reason for hiding this comment

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

TODO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean ?

src/libs/antares/study/parts/renewable/cluster_list.cpp Outdated Show resolved Hide resolved
@@ -293,7 +293,7 @@ void Create::createActionsForAStandardAreaCopy(Context& ctx, bool copyPosition)
auto* root = new RootNodePlant(pOriginalAreaName);

// browsing each thermal cluster
for (auto& c : area->thermal.list)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

About :

for (auto& c : area->thermal.list)

Actually, area->thermal.list.clusters was traversed here, because of method begin() and end() (now gone) were used behind the scene.

@@ -24,37 +24,21 @@ struct CompareClusterName final
class Cluster
{
public:
//! Map of renewable clusters
using Map = std::map<ClusterName, Cluster*>;
using Set = std::set<Cluster*, CompareClusterName>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

using Set = std::set<Cluster*, CompareClusterName>; : only moved from the bottom to the top of the class

** \brief Iterate through all clusters (const)
*/
template<class PredicateT>
void each(const PredicateT& predicate) const
Copy link
Contributor Author

Choose a reason for hiding this comment

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

void each(const PredicateT& predicate) const :
each(...) was used to traverse list clusters (clusters enabled and not must-run) and process a task on each element. We don't need it anymore : it was often replaced with a loop over the filtered complete list.

** \param t The cluster to add
** \return True if the cluster has been added, false otherwise
*/
SharedPtr add(const SharedPtr clusters);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SharedPtr add(const SharedPtr clusters); :
is replace with :
void addToCompleteList(std::shared_ptr<ClusterT> cluster);

**
** \param id ID of the cluster to find
** \return A pointer to a cluster. nullptr if not found
*/
ClusterT* find(const Data::ClusterName& id) const;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ClusterT* find(const Data::ClusterName& id) const; :
Used to be called only in GUI, searches in list clusters.
In GUI, clusters was containing all clusters.
It's been renamed findInAll , and now searches in private list allClusters_

@@ -32,17 +32,15 @@ bool renewableTSNumberData::apply(Study& study)

const uint tsGenCountRenewable = get_tsGenCount(study);

uint clusterIndex = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For renewable clusters, area.renewable.list used to contain (at this point of execution) only enabled clusters.
That's why we now loop over area.renewable.list.each_enabled()

@@ -66,25 +64,16 @@ void renewableTSNumberData::saveToINIFile(const Study& /* study */,
if (!pArea)
return;

// Foreach year
#ifndef NDEBUG
Copy link
Contributor Author

Choose a reason for hiding this comment

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

#ifndef NDEBUG
..
#endif

was remove, unnecessary / too few benefit

@@ -99,7 +88,7 @@ bool renewableTSNumberData::reset(const Study& study)
// solver or not.
// WARNING: At this point in time, the variable pArea->renewable.clusterCount()
// might not be valid (because not really initialized yet)
const uint clusterCount = pArea->renewable.list.size();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

reset() can be called both from GUI and solver. In GUI, the cluster list used contains contains all clusters. Otherwise, only enabled clusters. Setting clusterCount with allClustersCount() ensures that the matrix (of TS number) reset with clusterCount is large enough, as it is a max.

@@ -15,11 +15,11 @@ bool thermalTSNumberData::reset(const Study& study)
// If an area is available, it can only be an overlay for thermal timeseries
// WARNING: The total number of clusters may vary if used from the
// solver or not.
// WARNING: At this point in time, the variable pArea->thermal.clusterCount()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this file, the cluster lists usage used to be and still is particularly tricky.
What I mean :
the general philosophy in the scenario builder is :

  • if a function of this file is called from GUI, the clusters list it processes contains all clusters
  • if a function of this file is called from solver it contains only enabled clusters (must-run or not)

For example :

  • reset() is called from load higher level functions, so it can be called from both solver and GUI. This why we have a ternary operator inside this function. But the code before changes is wrong : when loading, the list pArea->thermal.list.clusters contains all cluster. So size pArea->thermal.list.size() + pArea->thermal.mustrunList.size() is too large. New code is both more clear and correct.
  • apply() : this function is only used by the solver. In the old code, it processes list area.thermal.clusters, that contains enabled thermal clusters (so it confirms that the intention is to process enabled clusters only in the scenario builder on the solver side). That's why each_enabled() is called in the new code.
  • saveToINIFile(...) : this function is only called from the GUI. In the old code, it processes pArea->thermal.list, which (when using the GUI) contains all clusters. New code is much more clear about that.

@@ -627,7 +627,7 @@ void ISimulation<Impl>::allocateMemoryForRandomNumbers(randomNumbers& randomForP
{
// logs.info() << " area : " << a << " :";
auto& area = *(study.areas.byIndex[a]);
size_t nbClusters = area.thermal.list.mapping.size();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Recall that area.thermal.list.mapping used to contain all thermal clusters

@guilpier-code guilpier-code marked this pull request as ready for review January 19, 2024 13:56
@payetvin payetvin modified the milestones: v8.8.1, Sprint 2 Feb 19, 2024
Copy link

@JasonMarechal25 JasonMarechal25 merged commit b181904 into develop Feb 22, 2024
5 checks passed
@JasonMarechal25 JasonMarechal25 deleted the fix/clean_thermal_lists branch February 22, 2024 09:22
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.

4 participants