Skip to content

Commit

Permalink
print solver logs (#1717)
Browse files Browse the repository at this point in the history
* enable outputs

* add CLI option to print solver logs

* remove macro

* @sylvlecl remarks 1/2

* read option from ini file

* update changelog

* @sylvlecl 2/2

* precision
  • Loading branch information
a-zakir authored Nov 3, 2023
1 parent 2242747 commit 03056a5
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 10 deletions.
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Antares Changelog
=================

8.9.0 (Unreleased yet)
--------------------
## New Features
* Solver logs can be enabled either by the command-line option (--solver-logs) or in the generaldata.ini by setting solver-logs = true under the optimization section [(#1717)](https://github.com/AntaresSimulatorTeam/Antares_Simulator/pull/1717)

8.7.0 (08/2023)
--------------------
## New Features
Expand Down
1 change: 1 addition & 0 deletions docs/reference-guide/10-command_line.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ _In all cases, arguments " –h" or "–help" can be used to get help_
|--no-ts-import | Do not import timeseries into the input folder. <br/> (This option may be useful for running old studies without upgrade)|
|-m, --mps-export | Export anonymous mps weekly or daily optimal UC+dispatch linear |
|-s, --named-mps-problems | Export named mps weekly or daily optimal UC+dispatch linear |
|--solver-logs | Print solver logs |

- Misc.

Expand Down
5 changes: 5 additions & 0 deletions docs/reference-guide/13-file-format.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Study format changes
This is a list of all recent changes that came with new Antares Simulator features. The main goal of this document is to lower the costs of changing existing interfaces, both GUI and scripts.
## v8.9.0
### Input
### Solver logs
* Solver logs can be enabled either by the command-line option (--solver-logs) or in the generaldata.ini file by setting solver-logs = true under the optimization section.

## v8.8.0
### Input
### Short-term storage
Expand Down
2 changes: 2 additions & 0 deletions src/libs/antares/study/load-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class StudyLoadOptions
bool mpsToExport;
//! named problems
bool namedProblems = false;
//! enable solver logs
bool solverLogs = false;
//! Ignore all constraints
bool ignoreConstraints;
//! Simulation mode
Expand Down
13 changes: 13 additions & 0 deletions src/libs/antares/study/parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ void Parameters::reset()
include.exportMPS = mpsExportStatus::NO_EXPORT;
include.exportStructure = false;
namedProblems = false;
solverLogs = false;

include.unfeasibleProblemBehavior = UnfeasibleProblemBehavior::ERROR_MPS;

Expand Down Expand Up @@ -626,6 +627,11 @@ static bool SGDIntLoadFamily_Optimization(Parameters& d,
{
return stringToGlobalTransmissionCapacities(value, d.transmissionCapacities);
}

if (key == "solver-logs")
{
return value.to<bool>(d.solverLogs);
}
return false;
}
static bool SGDIntLoadFamily_AdqPatch(Parameters& d,
Expand Down Expand Up @@ -1065,6 +1071,7 @@ bool Parameters::loadFromINI(const IniFile& ini, uint version, const StudyLoadOp
ortoolsSolver = options.ortoolsSolver;

namedProblems = options.namedProblems;
solverLogs = options.solverLogs || solverLogs;

// Attempt to fix bad values if any
fixBadValues();
Expand Down Expand Up @@ -1479,6 +1486,11 @@ void Parameters::prepareForSimulation(const StudyLoadOptions& options)
{
logs.info() << " :: The problems will contain named variables and constraints";
}
// indicated that solver logs will be printed
if (namedProblems)
{
logs.info() << " :: Printing solver logs : " << (solverLogs ? "True" : "False");
}
}

void Parameters::resetPlaylist(uint nbOfYears)
Expand Down Expand Up @@ -1594,6 +1606,7 @@ void Parameters::saveToINI(IniFile& ini) const
// Unfeasible problem behavior
section->add("include-unfeasible-problem-behavior",
Enum::toString(include.unfeasibleProblemBehavior));
section->add("solver-logs", solverLogs);
}

// Adequacy patch
Expand Down
3 changes: 3 additions & 0 deletions src/libs/antares/study/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ class Parameters final
// Naming constraints and variables in problems
bool namedProblems;

// solver logs
bool solverLogs;

private:
//! Load data from an INI file
bool loadFromINI(const IniFile& ini, uint version, const StudyLoadOptions& options);
Expand Down
3 changes: 3 additions & 0 deletions src/solver/misc/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ std::unique_ptr<GetOpt::Parser> CreateParser(Settings& settings,
"named-mps-problems",
"Export named constraints and variables in mps (both optim).");

// --solver-logs
parser->addFlag(options.solverLogs, ' ', "solver-logs", "Print solver logs.");

parser->addParagraph("\nMisc.");
// --progress
parser->addFlag(
Expand Down
9 changes: 2 additions & 7 deletions src/solver/optimisation/opt_appel_solveur_lineaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,6 @@ static SimplexResult OPT_TryToCallSimplex(
Probleme.CoutsMarginauxDesContraintes = ProblemeAResoudre->CoutsMarginauxDesContraintes.data();
Probleme.CoutsReduits = ProblemeAResoudre->CoutsReduits.data();

#ifndef NDEBUG
Probleme.AffichageDesTraces = ( PremierPassage ? OUI_SPX : NON_SPX );
#else
Probleme.AffichageDesTraces = NON_SPX;
#endif

Probleme.NombreDeContraintesCoupes = 0;

if (options.useOrtools)
Expand Down Expand Up @@ -310,7 +304,8 @@ bool OPT_AppelDuSimplexe(const OptimizationOptions& options,
ProblemeAResoudre->VariablesEntieres,
ProblemeAResoudre->StatutDesVariables,
ProblemeAResoudre->StatutDesContraintes,
problemeHebdo->NamedProblems);
problemeHebdo->NamedProblems,
problemeHebdo->solverLogs);

bool PremierPassage = true;

Expand Down
1 change: 1 addition & 0 deletions src/solver/simulation/sim_calcul_economique.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ void SIM_InitialisationProblemeHebdo(Data::Study& study,
problem.ExportMPS = study.parameters.include.exportMPS;
problem.ExportStructure = study.parameters.include.exportStructure;
problem.NamedProblems = study.parameters.namedProblems;
problem.solverLogs = study.parameters.solverLogs;
problem.exportMPSOnError = Data::exportMPS(parameters.include.unfeasibleProblemBehavior);

problem.OptimisationAvecCoutsDeDemarrage
Expand Down
1 change: 1 addition & 0 deletions src/solver/simulation/sim_structure_probleme_economique.h
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ struct PROBLEME_HEBDO
bool exportMPSOnError = false;
bool ExportStructure = false;
bool NamedProblems = false;
bool solverLogs = false;

uint32_t HeureDansLAnnee = 0;
bool LeProblemeADejaEteInstancie = false;
Expand Down
7 changes: 5 additions & 2 deletions src/solver/utils/named_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ PROBLEME_SIMPLEXE_NOMME::PROBLEME_SIMPLEXE_NOMME(const std::vector<std::string>&
const std::vector<bool>& VariablesEntieres,
std::vector<int>& StatutDesVariables,
std::vector<int>& StatutDesContraintes,
bool UseNamedProblems) :
bool UseNamedProblems,
bool SolverLogs) :

NomDesVariables(NomDesVariables),
NomDesContraintes(NomDesContraintes),
VariablesEntieres(VariablesEntieres),
StatutDesVariables(StatutDesVariables),
StatutDesContraintes(StatutDesContraintes),
useNamedProblems_(UseNamedProblems)
useNamedProblems_(UseNamedProblems),
solverLogs_(SolverLogs)
{
AffichageDesTraces = SolverLogs ? OUI_SPX : NON_SPX;
}

bool PROBLEME_SIMPLEXE_NOMME::isMIP() const
Expand Down
9 changes: 8 additions & 1 deletion src/solver/utils/named_problem.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ struct PROBLEME_SIMPLEXE_NOMME : public PROBLEME_SIMPLEXE
const std::vector<bool>& VariablesEntieres,
std::vector<int>& StatutDesVariables,
std::vector<int>& StatutDesContraintes,
bool UseNamedProblems);
bool UseNamedProblems,
bool SolverLogs);

private:
const std::vector<std::string>& NomDesVariables;
const std::vector<std::string>& NomDesContraintes;
bool useNamedProblems_;
bool solverLogs_;

public:
std::vector<int>& StatutDesVariables;
Expand Down Expand Up @@ -54,6 +56,11 @@ struct PROBLEME_SIMPLEXE_NOMME : public PROBLEME_SIMPLEXE
{
return NomDesContraintes;
}

bool SolverLogs() const
{
return solverLogs_;
}
};
} // namespace Optimization
} // namespace Antares
4 changes: 4 additions & 0 deletions src/solver/utils/ortools_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ MPSolver* ProblemSimplexeNommeConverter::Convert()
CopyRows(solver);

CopyMatrix(solver);
if (problemeSimplexe_->SolverLogs())
{
solver->EnableOutput();
}

return solver;
}
Expand Down

0 comments on commit 03056a5

Please sign in to comment.