Skip to content

Commit

Permalink
Normalize simulation mode Expansion, fix logs (#1771)
Browse files Browse the repository at this point in the history
* Fix expansion logs, clean up & refactor

* Use enum class SimulationMode instead of enum StudyMode

* Do not force MPS export when Expansion mode is enabled
  • Loading branch information
flomnes authored Dec 11, 2023
1 parent d2092b5 commit cbd55e5
Show file tree
Hide file tree
Showing 43 changed files with 146 additions and 197 deletions.
1 change: 0 additions & 1 deletion src/libs/antares/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ set(SRC
config.h
constants.h
constants.cpp
xpansion.h
# Misc

locale.h
Expand Down
1 change: 0 additions & 1 deletion src/libs/antares/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#ifndef __ANTARES_LIBS_CONSTANTS_H__
#define __ANTARES_LIBS_CONSTANTS_H__

#include "xpansion.h"
#include <array>

/*! Name of the app to use into logs */
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/exception/LoadingError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ CommandLineArguments::CommandLineArguments(uint errors) :
{
}

IncompatibleStudyModeForAdqPatch::IncompatibleStudyModeForAdqPatch() :
IncompatibleSimulationModeForAdqPatch::IncompatibleSimulationModeForAdqPatch() :
LoadingError("Adequacy Patch can only be used with Economy Simulation Mode")
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/exception/antares/exception/LoadingError.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ class CommandLineArguments : public LoadingError
explicit CommandLineArguments(uint errors);
};

class IncompatibleStudyModeForAdqPatch : public LoadingError
class IncompatibleSimulationModeForAdqPatch : public LoadingError
{
public:
IncompatibleStudyModeForAdqPatch();
IncompatibleSimulationModeForAdqPatch();
};

class NoAreaInsideAdqPatchMode : public LoadingError
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/area/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ static bool AreaListLoadFromFolderSingleArea(Study& study,
ret = area.thermal.list.loadEconomicCosts(study, buffer) && ret;

// In adequacy mode, all thermal clusters must be in 'mustrun' mode
if (study.usedByTheSolver && study.parameters.mode == stdmAdequacy)
if (study.usedByTheSolver && study.parameters.mode == SimulationMode::Adequacy)
area.thermal.list.enableMustrunForEveryone();
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/area/scratchpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ AreaScratchpad::AreaScratchpad(const StudyRuntimeInfos& rinfos, Area& area)
sum += area.miscGen[w][h];
miscGenSum[h] = sum;
}
if (mode == Data::stdmAdequacy)
if (mode == Data::SimulationMode::Adequacy)
{
for (uint h = 0; h != area.miscGen.height; ++h)
miscGenSum[h] -= area.reserves[Data::fhrPrimaryReserve][h];
Expand Down
18 changes: 8 additions & 10 deletions src/libs/antares/study/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,19 @@ enum StudyError
};

/*!
** \brief Types of Study
** \brief Types of Simulation
*/
enum StudyMode
enum class SimulationMode
{
stdmUnknown = -1,
//! Economic
stdmEconomy,
Economy,
//! Adequacy (subset of the economy mode)
stdmAdequacy,
Adequacy,
//! Expansion
stdmExpansion,
//! Max
stdmMax

}; // enum StudyMode
Expansion,
//! Unknown simulation mode
Unknown
};

/*
** \brief Simplex optimizations
Expand Down
8 changes: 4 additions & 4 deletions src/libs/antares/study/load-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ StudyLoadOptions::StudyLoadOptions() :
simplexOptimizationRange(sorUnknown),
mpsToExport(false),
ignoreConstraints(false),
forceMode(stdmUnknown),
forceMode(SimulationMode::Unknown),
enableParallel(false),
forceParallel(false),
maxNbYearsInParallel(0),
Expand Down Expand Up @@ -74,11 +74,11 @@ void StudyLoadOptions::checkForceSimulationMode()
throw Error::InvalidSimulationMode();
}
if (forceExpansion)
forceMode = stdmExpansion;
forceMode = SimulationMode::Expansion;
else if (forceEconomy)
forceMode = stdmEconomy;
forceMode = SimulationMode::Economy;
else if (forceAdequacy)
forceMode = stdmAdequacy;
forceMode = SimulationMode::Adequacy;
}
} // namespace Data
} // namespace Antares
2 changes: 1 addition & 1 deletion src/libs/antares/study/load-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class StudyLoadOptions
//! Ignore all constraints
bool ignoreConstraints;
//! Simulation mode
StudyMode forceMode;
SimulationMode forceMode;

//! Enables the parallel computation of MC years
bool enableParallel;
Expand Down
6 changes: 3 additions & 3 deletions src/libs/antares/study/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class OutputFolderIterator : public IO::Directory::IIterator<true>
} // anonymous namespace

Output::Output(const AnyString& folder) :
version(0), timestamp(0), mode(Data::stdmEconomy), menuID(-1), viewMenuID(-1), outputViewerID(-1)
version(0), timestamp(0), mode(Data::SimulationMode::Economy), menuID(-1), viewMenuID(-1), outputViewerID(-1)
{
loadFromFolder(folder);
}
Expand All @@ -110,7 +110,7 @@ bool Output::loadFromFolder(const AnyString& folder)
name.clear();
path.clear();
version = 0;
mode = Data::stdmUnknown;
mode = Data::SimulationMode::Unknown;

// Load the INI file in memory
IniFile ini;
Expand Down Expand Up @@ -152,7 +152,7 @@ bool Output::loadFromFolder(const AnyString& folder)
{
if (p->key == "mode")
{
StringToStudyMode(mode, p->value);
StringToSimulationMode(mode, p->value);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Output final
//! Date/time when the simulation has been launched
int64_t timestamp;
//! Mode (economy/adequacy/other)
Data::StudyMode mode;
Data::SimulationMode mode;
//! Tag for storing a wx menu id
int menuID;
//! Tag for storing a wx menu id (from the menu `output`)
Expand Down
73 changes: 24 additions & 49 deletions src/libs/antares/study/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static void ParametersSaveResultFormat(IniFile::Section* section, ResultFormat f
}
}

bool StringToStudyMode(StudyMode& mode, CString<20, false> text)
bool StringToSimulationMode(SimulationMode& mode, CString<20, false> text)
{
if (!text)
return false;
Expand All @@ -151,38 +151,37 @@ bool StringToStudyMode(StudyMode& mode, CString<20, false> text)
if (text == "economy" || text == "economic")
{
// The term `economic` was mis-used in previous versions of antares (<3.4)
mode = stdmEconomy;
mode = SimulationMode::Economy;
return true;
}
// Adequacy
if (text == "adequacy")
{
mode = stdmAdequacy;
mode = SimulationMode::Adequacy;
return true;
}
// Expansion
if (text == "expansion")
{
mode = stdmExpansion;
mode = SimulationMode::Expansion;
return true;
}
return false;
}

const char* StudyModeToCString(StudyMode mode)
const char* SimulationModeToCString(SimulationMode mode)
{
switch (mode)
{
case stdmEconomy:
case SimulationMode::Economy:
return "Economy";
case stdmAdequacy:
case SimulationMode::Adequacy:
return "Adequacy";
case stdmMax:
case stdmExpansion:
case stdmUnknown:
case SimulationMode::Expansion:
return "Expansion";
default:
return "Unknown";
}
return "Unknown";
}

Parameters::Parameters() : noOutput(false)
Expand All @@ -193,12 +192,12 @@ Parameters::~Parameters() = default;

bool Parameters::economy() const
{
return mode == stdmEconomy;
return mode == SimulationMode::Economy;
}

bool Parameters::adequacy() const
{
return mode == stdmAdequacy;
return mode == SimulationMode::Adequacy;
}

void Parameters::resetSeeds()
Expand Down Expand Up @@ -230,9 +229,7 @@ void Parameters::resetPlayedYears(uint nbOfYears)
void Parameters::reset()
{
// Mode
mode = stdmEconomy;
// Expansion
expansion = false;
mode = SimulationMode::Economy;
// Calendar
horizon.clear();

Expand Down Expand Up @@ -447,7 +444,7 @@ static bool SGDIntLoadFamily_General(Parameters& d,
return value.to(d.leapYear);

if (key == "mode")
return StringToStudyMode(d.mode, value);
return StringToSimulationMode(d.mode, value);

if (key == "nbyears")
{
Expand Down Expand Up @@ -1039,29 +1036,14 @@ bool Parameters::loadFromINI(const IniFile& ini, uint version, const StudyLoadOp
}

// Simulation mode
// ... Expansion
if (mode == stdmExpansion)
{
mode = stdmEconomy;
expansion = true;
}

// ... Enforcing simulation mode
if (options.forceMode != stdmUnknown)
if (options.forceMode != SimulationMode::Unknown)
{
if (options.forceMode == stdmExpansion)
{
mode = stdmEconomy;
expansion = true;
}
else
mode = options.forceMode;

logs.info() << " forcing the simulation mode " << StudyModeToCString(mode);
assert(mode != stdmMax && "Invalid simulation mode");
mode = options.forceMode;
logs.info() << " forcing the simulation mode " << SimulationModeToCString(mode);
}
else
logs.info() << " simulation mode: " << StudyModeToCString(mode);
logs.info() << " simulation mode: " << SimulationModeToCString(mode);

if (options.forceDerated)
derated = true;
Expand Down Expand Up @@ -1357,17 +1339,16 @@ void Parameters::prepareForSimulation(const StudyLoadOptions& options)

switch (mode)
{
case stdmEconomy:
case stdmAdequacy:
case SimulationMode::Economy:
case SimulationMode::Adequacy:
case SimulationMode::Expansion:
{
// The year-by-year mode might have been requested from the command line
if (options.forceYearByYear)
yearByYear = true;
break;
}
case stdmUnknown:
case stdmExpansion:
case stdmMax:
case SimulationMode::Unknown:
{
// The mode year-by-year can not be enabled in adequacy
yearByYear = false;
Expand Down Expand Up @@ -1437,7 +1418,7 @@ void Parameters::prepareForSimulation(const StudyLoadOptions& options)
exportTimeSeriesInInput = 0;
}

if (expansion)
if (mode == SimulationMode::Expansion)
logs.info() << " :: enabling expansion";
if (yearByYear)
logs.info() << " :: enabling the 'year-by-year' mode";
Expand Down Expand Up @@ -1504,13 +1485,7 @@ void Parameters::saveToINI(IniFile& ini) const
auto* section = ini.addSection("general");

// Mode
if (expansion && mode == stdmEconomy)
section->add("mode", "Expansion");
else
{
section->add("mode", StudyModeToCString(mode));
expansion = false;
}
section->add("mode", SimulationModeToCString(mode));

// Calendar
section->add("horizon", horizon);
Expand Down
17 changes: 6 additions & 11 deletions src/libs/antares/study/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,9 @@ class Parameters final
//! \name Mode
//@{
//! Mode of the study (adequacy, economy...)
StudyMode mode;
SimulationMode mode;
//@}

//! \name Expansion
//@{
//! Expansion flag
mutable bool expansion;

//! \name Horizon
//@{
//! Horizon year
Expand Down Expand Up @@ -542,18 +537,18 @@ class Parameters final
}; // class Parameters

/*!
** \brief Convert a study mode (enum) into a human readable C-String
** \brief Convert a simulation mode (enum) into a human readable C-String
*/
const char* StudyModeToCString(StudyMode mode);
const char* SimulationModeToCString(SimulationMode mode);

/*!
** \brief Convert a C-String (lowercase) into a study mode if possible
** \brief Convert a C-String (lowercase) into a simulation mode if possible
**
** \param[out] mode The study mode. It will remain untouched if the conversion failed
** \param[out] mode The simulation mode. It will remain untouched if the conversion failed
** \param Text An arbitrary Text (case insensitive)
** \return True if the conversion succeeded, false otherwise
*/
bool StringToStudyMode(StudyMode& mode, Yuni::CString<20, false> text);
bool StringToSimulationMode(SimulationMode& mode, Yuni::CString<20, false> text);

} // namespace Antares::Data

Expand Down
10 changes: 5 additions & 5 deletions src/libs/antares/study/parameters/adq-patch-params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ void AdqPatchParams::saveToINI(IniFile& ini) const
curtailmentSharing.addProperties(section);
}

bool AdqPatchParams::checkAdqPatchParams(const StudyMode studyMode,
bool AdqPatchParams::checkAdqPatchParams(const SimulationMode simulationMode,
const AreaList& areas,
const bool includeHurdleCostParameters) const
{
checkAdqPatchStudyModeEconomyOnly(studyMode);
checkAdqPatchSimulationModeEconomyOnly(simulationMode);
checkAdqPatchContainsAdqPatchArea(areas);
checkAdqPatchIncludeHurdleCost(includeHurdleCostParameters);
checkAdqPatchDisabledLocalMatching();
Expand All @@ -182,10 +182,10 @@ bool AdqPatchParams::checkAdqPatchParams(const StudyMode studyMode,
}

// Adequacy Patch can only be used with Economy Study/Simulation Mode.
void AdqPatchParams::checkAdqPatchStudyModeEconomyOnly(const StudyMode studyMode) const
void AdqPatchParams::checkAdqPatchSimulationModeEconomyOnly(const SimulationMode simulationMode) const
{
if (studyMode != StudyMode::stdmEconomy)
throw Error::IncompatibleStudyModeForAdqPatch();
if (simulationMode != SimulationMode::Economy)
throw Error::IncompatibleSimulationModeForAdqPatch();
}

// When Adequacy Patch is on at least one area must be inside Adequacy patch mode.
Expand Down
Loading

0 comments on commit cbd55e5

Please sign in to comment.