From 03056a5bcfd2e2a5915e215ee0c9d2663bb41ee7 Mon Sep 17 00:00:00 2001 From: abdoulbari zakir <32519851+a-zakir@users.noreply.github.com> Date: Fri, 3 Nov 2023 07:40:20 -0700 Subject: [PATCH] print solver logs (#1717) * 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 --- docs/CHANGELOG.md | 5 +++++ docs/reference-guide/10-command_line.md | 1 + docs/reference-guide/13-file-format.md | 5 +++++ src/libs/antares/study/load-options.h | 2 ++ src/libs/antares/study/parameters.cpp | 13 +++++++++++++ src/libs/antares/study/parameters.h | 3 +++ src/solver/misc/options.cpp | 3 +++ .../optimisation/opt_appel_solveur_lineaire.cpp | 9 ++------- src/solver/simulation/sim_calcul_economique.cpp | 1 + .../simulation/sim_structure_probleme_economique.h | 1 + src/solver/utils/named_problem.cpp | 7 +++++-- src/solver/utils/named_problem.h | 9 ++++++++- src/solver/utils/ortools_utils.cpp | 4 ++++ 13 files changed, 53 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fa88e14d54..2aef2a8562 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -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 diff --git a/docs/reference-guide/10-command_line.md b/docs/reference-guide/10-command_line.md index 0d151481c2..2a69a44fe9 100644 --- a/docs/reference-guide/10-command_line.md +++ b/docs/reference-guide/10-command_line.md @@ -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.
(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. diff --git a/docs/reference-guide/13-file-format.md b/docs/reference-guide/13-file-format.md index 5339a71c6b..9938777292 100644 --- a/docs/reference-guide/13-file-format.md +++ b/docs/reference-guide/13-file-format.md @@ -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 diff --git a/src/libs/antares/study/load-options.h b/src/libs/antares/study/load-options.h index df655816ed..6c2dd5f644 100644 --- a/src/libs/antares/study/load-options.h +++ b/src/libs/antares/study/load-options.h @@ -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 diff --git a/src/libs/antares/study/parameters.cpp b/src/libs/antares/study/parameters.cpp index ec128bda4e..57735aab16 100644 --- a/src/libs/antares/study/parameters.cpp +++ b/src/libs/antares/study/parameters.cpp @@ -324,6 +324,7 @@ void Parameters::reset() include.exportMPS = mpsExportStatus::NO_EXPORT; include.exportStructure = false; namedProblems = false; + solverLogs = false; include.unfeasibleProblemBehavior = UnfeasibleProblemBehavior::ERROR_MPS; @@ -626,6 +627,11 @@ static bool SGDIntLoadFamily_Optimization(Parameters& d, { return stringToGlobalTransmissionCapacities(value, d.transmissionCapacities); } + + if (key == "solver-logs") + { + return value.to(d.solverLogs); + } return false; } static bool SGDIntLoadFamily_AdqPatch(Parameters& d, @@ -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(); @@ -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) @@ -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 diff --git a/src/libs/antares/study/parameters.h b/src/libs/antares/study/parameters.h index 98357e4709..325a62862b 100644 --- a/src/libs/antares/study/parameters.h +++ b/src/libs/antares/study/parameters.h @@ -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); diff --git a/src/solver/misc/options.cpp b/src/solver/misc/options.cpp index 918f73724b..c05f8ddb36 100644 --- a/src/solver/misc/options.cpp +++ b/src/solver/misc/options.cpp @@ -174,6 +174,9 @@ std::unique_ptr 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( diff --git a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp index bcbda69832..ed361d6206 100644 --- a/src/solver/optimisation/opt_appel_solveur_lineaire.cpp +++ b/src/solver/optimisation/opt_appel_solveur_lineaire.cpp @@ -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) @@ -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; diff --git a/src/solver/simulation/sim_calcul_economique.cpp b/src/solver/simulation/sim_calcul_economique.cpp index 14133c06f1..0183ee82e5 100644 --- a/src/solver/simulation/sim_calcul_economique.cpp +++ b/src/solver/simulation/sim_calcul_economique.cpp @@ -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 diff --git a/src/solver/simulation/sim_structure_probleme_economique.h b/src/solver/simulation/sim_structure_probleme_economique.h index e935899904..3d15844242 100644 --- a/src/solver/simulation/sim_structure_probleme_economique.h +++ b/src/solver/simulation/sim_structure_probleme_economique.h @@ -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; diff --git a/src/solver/utils/named_problem.cpp b/src/solver/utils/named_problem.cpp index 7553a729cc..e3fcc08643 100644 --- a/src/solver/utils/named_problem.cpp +++ b/src/solver/utils/named_problem.cpp @@ -11,15 +11,18 @@ PROBLEME_SIMPLEXE_NOMME::PROBLEME_SIMPLEXE_NOMME(const std::vector& const std::vector& VariablesEntieres, std::vector& StatutDesVariables, std::vector& 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 diff --git a/src/solver/utils/named_problem.h b/src/solver/utils/named_problem.h index f8d68a1f10..8a26ad4508 100644 --- a/src/solver/utils/named_problem.h +++ b/src/solver/utils/named_problem.h @@ -20,12 +20,14 @@ struct PROBLEME_SIMPLEXE_NOMME : public PROBLEME_SIMPLEXE const std::vector& VariablesEntieres, std::vector& StatutDesVariables, std::vector& StatutDesContraintes, - bool UseNamedProblems); + bool UseNamedProblems, + bool SolverLogs); private: const std::vector& NomDesVariables; const std::vector& NomDesContraintes; bool useNamedProblems_; + bool solverLogs_; public: std::vector& StatutDesVariables; @@ -54,6 +56,11 @@ struct PROBLEME_SIMPLEXE_NOMME : public PROBLEME_SIMPLEXE { return NomDesContraintes; } + + bool SolverLogs() const + { + return solverLogs_; + } }; } // namespace Optimization } // namespace Antares diff --git a/src/solver/utils/ortools_utils.cpp b/src/solver/utils/ortools_utils.cpp index 6d3911f76c..fc31bf5be7 100644 --- a/src/solver/utils/ortools_utils.cpp +++ b/src/solver/utils/ortools_utils.cpp @@ -55,6 +55,10 @@ MPSolver* ProblemSimplexeNommeConverter::Convert() CopyRows(solver); CopyMatrix(solver); + if (problemeSimplexe_->SolverLogs()) + { + solver->EnableOutput(); + } return solver; }