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

print low level logs #719

Merged
merged 71 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
3423dfc
start Math log
a-zakir Nov 20, 2023
f184ff7
add overloaded method
a-zakir Nov 20, 2023
4cfd573
fix platform specific standard
a-zakir Nov 20, 2023
d3527c4
add MathloggerDriver
a-zakir Nov 20, 2023
d341b1b
print basic data
a-zakir Nov 20, 2023
f28101c
add math logger in benders
a-zakir Nov 20, 2023
3710fbb
Benders take mathlooger
a-zakir Nov 20, 2023
e2e9a91
print maths log
a-zakir Nov 20, 2023
847b9db
add missing include
a-zakir Nov 20, 2023
b2680f0
fix
a-zakir Nov 20, 2023
ef37857
print more data
a-zakir Nov 22, 2023
896fdde
Reset Simplex Iterations Bounds
a-zakir Nov 24, 2023
3616fcf
introducing MathlogImplementation
a-zakir Nov 24, 2023
ff73b89
fix
a-zakir Nov 24, 2023
53adca3
fix
a-zakir Nov 24, 2023
7307b13
ok
a-zakir Nov 24, 2023
707b6e5
set log destination
a-zakir Nov 24, 2023
52984bd
merge fork change (#729)
a-zakir Dec 12, 2023
a2d5b33
fix python typing
a-zakir Dec 12, 2023
4bc7224
Merge branch 'develop' into feature/low-level-logs
a-zakir Dec 12, 2023
71b8f88
writing warning in stdout
a-zakir Dec 12, 2023
815273b
delete useless print
a-zakir Dec 12, 2023
bd0d77f
rename var
a-zakir Dec 12, 2023
6f1f42b
avoid dangling refs
a-zakir Dec 12, 2023
3089987
clarity
a-zakir Dec 12, 2023
e7d74d9
update
a-zakir Dec 12, 2023
e0295d7
test
a-zakir Dec 13, 2023
43435f3
about benders time
a-zakir Dec 13, 2023
2dcc76f
make log headers identical
a-zakir Dec 13, 2023
36f50ab
clean
a-zakir Dec 13, 2023
9313166
add check to Logdestination's stream handler
a-zakir Dec 13, 2023
29b8db2
LogDestinationTest
a-zakir Dec 13, 2023
9314057
test ok
a-zakir Dec 13, 2023
b959f9f
move implementation details
a-zakir Dec 13, 2023
6b9199c
add test
a-zakir Dec 19, 2023
25e590e
Merge branch 'develop' into feature/low-level-logs
a-zakir Dec 19, 2023
f00f769
Merge branch 'develop' into feature/low-level-logs
a-zakir Dec 19, 2023
249319a
test log file content
a-zakir Dec 20, 2023
8e2af9c
fix
a-zakir Dec 20, 2023
9d1bc82
small changes
a-zakir Dec 20, 2023
bc0ab43
test passed
a-zakir Dec 20, 2023
31dd692
test by batch mathlogger headers
a-zakir Dec 20, 2023
7b4c9f4
test bbb LONG headers
a-zakir Dec 20, 2023
acfaf42
HeadersManager test
a-zakir Dec 20, 2023
f48ffa3
HeadersManager completed
a-zakir Dec 20, 2023
ec8f1dd
MathLoggerBendersByBatchTest printed data
a-zakir Dec 20, 2023
7ea33ac
MathLoggerBendersByBatchTest printed datastdout
a-zakir Dec 20, 2023
e8d3564
MathLoggerBendersByBatchTest printed datastdout
a-zakir Dec 20, 2023
a2d6f41
MathLoggerBendersBaseTest
a-zakir Dec 20, 2023
4f40605
windows
a-zakir Dec 20, 2023
fdf3c62
fix parsing of "expert_logs"
a-zakir Dec 21, 2023
ed5e00b
control all logs with log_level option
a-zakir Dec 22, 2023
d77e497
control solver logs
a-zakir Dec 22, 2023
e92292a
benders logs in file: only data
a-zakir Dec 22, 2023
04a69fa
redirect console logs
a-zakir Dec 22, 2023
41bbb64
COIN solver logs only if log_level >1 & log file provided
a-zakir Dec 22, 2023
b6ee322
shorten whitespaces
a-zakir Dec 22, 2023
84bcefc
update doc
a-zakir Dec 22, 2023
10e2a22
delete useless if/else statement
a-zakir Jan 2, 2024
7524e72
remove code duplications
a-zakir Jan 2, 2024
62c8114
fix
a-zakir Jan 2, 2024
136b8cb
Pr remarks
a-zakir Jan 2, 2024
2abbe7d
Pr remarks 2
a-zakir Jan 2, 2024
713d899
units
a-zakir Jan 4, 2024
2d92aff
rename vars
a-zakir Jan 4, 2024
a596298
2 rename vars
a-zakir Jan 4, 2024
bb85059
fix iteration time
a-zakir Jan 4, 2024
fc64ca2
fix
a-zakir Jan 4, 2024
434222f
fix test
a-zakir Jan 4, 2024
fdbfaa2
fix iteration_time
a-zakir Jan 4, 2024
c8ff834
Update docs
tbittar Jan 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if (NOT antares-solver_FOUND)

set(REPOSITORY "https://github.com/AntaresSimulatorTeam/Antares_Simulator.git")
set(TAG "v${ANTARES_VERSION_TAG}")
set(CMAKE_ARGS "-DBUILD_UI=OFF -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DDEPS_INSTALL_DIR=${DEPS_INSTALL_DIR} -DBUILD_not_system=OFF -DBUILD_ortools=ON")
set(CMAKE_ARGS "-DBUILD_UI=OFF -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DDEPS_INSTALL_DIR=${DEPS_INSTALL_DIR} -DBUILD_not_system=OFF -DBUILD_ortools=ON -DCMAKE_PREFIX_PATH=${DEPS_INSTALL_DIR}/../antares-xpansion/vcpkg_installed")

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(ANTARES_BUILD_TYPE "debug")
Expand Down
1 change: 1 addition & 0 deletions docs/user-guide/get-started/settings-definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The following section lists the configurable parameters. If the user does not sp
|[`separation_parameter`](#separation_parameter) | `0.5` | Step size for the in-out separation |

Choose a reason for hiding this comment

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

This PR contains console logs. Please review or remove them.

|[`relaxed_optimality_gap`](#relaxed_optimality_gap) | `1e-5` | Threshold to switch from relaxed to integer master |
|[`batch_size`](#batch_size) | `0` | Number of subproblems per batch |
|[`expert_logs`](#expert_logs) | `false` | display pure optimization data (/!\ the corresponding option(`EXPERT_LOGS`) for benders is `true` by default ) |
a-zakir marked this conversation as resolved.
Show resolved Hide resolved

The format is a standard `.ini` and should follow this template:
```ini
Expand Down
27 changes: 17 additions & 10 deletions src/cpp/benders/benders_by_batch/BendersByBatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
#include "BatchCollection.h"
#include "RandomBatchShuffler.h"
#include "glog/logging.h"
BendersByBatch::BendersByBatch(BendersBaseOptions const &options, Logger logger,
Writer writer, mpi::environment &env,
mpi::communicator &world)
: BendersMpi(options, logger, writer, env, world) {}
BendersByBatch::BendersByBatch(
BendersBaseOptions const &options, Logger logger, Writer writer,
mpi::environment &env, mpi::communicator &world,
std::shared_ptr<MathLoggerDriver> mathLoggerDriver)
: BendersMpi(options, logger, writer, env, world, mathLoggerDriver) {}

void BendersByBatch::InitializeProblems() {
MatchProblemToId();
Expand Down Expand Up @@ -75,8 +76,8 @@ void BendersByBatch::MasterLoop() {
random_batch_permutation_.resize(number_of_batch_);
batch_counter_ = 0;
current_batch_id_ = 0;

_data.number_of_subproblem_resolved = 0;
_data.number_of_subproblem_solved = 0;
_data.cumulative_number_of_subproblem_solved = 0;
cumulative_subproblems_timer_per_iter_ = 0;
first_unsolved_batch_ = 0;
while (!_data.stop) {
Expand Down Expand Up @@ -118,15 +119,16 @@ void BendersByBatch::MasterLoop() {
BroadCast(_data.stop, rank_0);
BroadCast(batch_counter_, rank_0);
SetSubproblemsCumulativeCpuTime(cumulative_subproblems_timer_per_iter_);
_logger->cumulative_number_of_sub_problem_resolved(
_data.number_of_subproblem_resolved +
GetNumOfSubProblemsResolvedBeforeResume());
_logger->cumulative_number_of_sub_problem_solved(
_data.cumulative_number_of_subproblem_solved +
GetNumOfSubProblemsSolvedBeforeResume());
_logger->LogSubproblemsSolvingCumulativeCpuTime(
GetSubproblemsCumulativeCpuTime());
_logger->LogSubproblemsSolvingWalltime(GetSubproblemsWalltime());
_logger->display_message(
"\\________________________________________________________________"
"________");
mathLoggerDriver_->Print(_data);
}
}
void BendersByBatch::SeparationLoop() {
Expand All @@ -135,13 +137,16 @@ void BendersByBatch::SeparationLoop() {
batch_counter_ = 0;
while (misprice_ && batch_counter_ < number_of_batch_) {
_data.it++;
ResetSimplexIterationsBounds();

_logger->log_at_initialization(_data.it + GetNumIterationsBeforeRestart());
ComputeXCut();
_logger->log_iteration_candidates(bendersDataToLogData(_data));
BroadcastXCut();
UpdateRemainingEpsilon();
_data.number_of_subproblem_solved = 0;
SolveBatches();

if (Rank() == rank_0) {
UpdateTrace();
SaveCurrentBendersData();
Expand Down Expand Up @@ -195,7 +200,8 @@ void BendersByBatch::SolveBatches() {
Reduce(GetSubproblemsCpuTime(), cumulative_subproblems_timer_per_iter_,
std::plus<double>(), rank_0);
if (Rank() == rank_0) {
_data.number_of_subproblem_resolved += batch_sub_problems.size();
_data.number_of_subproblem_solved += batch_sub_problems.size();
_data.cumulative_number_of_subproblem_solved += batch_sub_problems.size();
remaining_epsilon_ -= batch_subproblems_costs_contribution_in_gap;
}

Expand Down Expand Up @@ -229,6 +235,7 @@ void BendersByBatch::BuildCut(
for (const auto &subproblem_map : gathered_subproblem_map) {
for (auto &&[_, subproblem_data] : subproblem_map) {
SetSubproblemCost(GetSubproblemCost() + subproblem_data.subproblem_cost);
BoundSimplexIterations(subproblem_data.simplex_iter);
}
}
for (const auto &subproblem_map : gathered_subproblem_map) {
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/benders/benders_by_batch/include/BendersByBatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class BendersByBatch : public BendersMpi {

public:
BendersByBatch(BendersBaseOptions const &options, Logger logger,
Writer writer, mpi::environment &env,
mpi::communicator &world);
Writer writer, mpi::environment &env, mpi::communicator &world,
std::shared_ptr<MathLoggerDriver> mathLoggerDriver);
~BendersByBatch() override = default;
void Run() override;
void BuildCut(const std::vector<std::string> &batch_sub_problems,
Expand Down
32 changes: 26 additions & 6 deletions src/cpp/benders/benders_core/BendersBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
#include "solver_utils.h"

Choose a reason for hiding this comment

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

This PR contains console logs. Please review or remove them.


BendersBase::BendersBase(BendersBaseOptions options, Logger logger,
Writer writer)
Writer writer,
std::shared_ptr<MathLoggerDriver> mathLoggerDriver)
: _options(std::move(options)),
_csv_file_path(std::filesystem::path(_options.OUTPUTROOT) /
(_options.CSV_NAME + ".csv")),
_logger(std::move(logger)),
_writer(std::move(writer)) {}
_writer(std::move(writer)),
mathLoggerDriver_(mathLoggerDriver) {}

/*!
* \brief Initialize set of data used in the loop
Expand All @@ -34,7 +36,7 @@ void BendersBase::init_data() {
_data.best_it = 0;
_data.stopping_criterion = StoppingCriterion::empty;
_data.is_in_initial_relaxation = false;
_data.number_of_subproblem_resolved = 0;
_data.cumulative_number_of_subproblem_solved = 0;
}

void BendersBase::OpenCsvFile() {
Expand Down Expand Up @@ -467,7 +469,7 @@ LogData BendersBase::FinalLogData() const {
result.subproblem_cost = best_iteration_data.subproblem_cost;
result.invest_cost = best_iteration_data.invest_cost;
result.cumulative_number_of_subproblem_resolved =
_data.number_of_subproblem_resolved +
_data.cumulative_number_of_subproblem_solved +
cumulative_number_of_subproblem_resolved_before_resume;

return result;
Expand Down Expand Up @@ -525,7 +527,7 @@ Output::Iteration BendersBase::iteration(
masterDataPtr_l->_invest_cost + masterDataPtr_l->_operational_cost;
iteration.candidates = candidates_data(masterDataPtr_l);
iteration.cumulative_number_of_subproblem_resolved =
_data.number_of_subproblem_resolved +
_data.cumulative_number_of_subproblem_solved +
cumulative_number_of_subproblem_resolved_before_resume;
return iteration;
}
Expand Down Expand Up @@ -651,7 +653,7 @@ LogData BendersBase::bendersDataToLogData(
data.elapsed_time,
data.timer_master,
data.subproblems_walltime,
data.number_of_subproblem_resolved +
data.cumulative_number_of_subproblem_solved +
cumulative_number_of_subproblem_resolved_before_resume};
}
void BendersBase::set_solver_log_file(const std::filesystem::path &log_file) {
Expand Down Expand Up @@ -772,6 +774,24 @@ void BendersBase::SetSubproblemCost(const double &subproblem_cost) {
_data.subproblem_cost = subproblem_cost;
}

/*!
* \brief Update maximum and minimum of simplex iterations
*
* \param subproblem_iterations : number of iterations done with the subproblem
*
*/
void BendersBase::BoundSimplexIterations(int subproblem_iterations){

_data.max_simplexiter = (_data.max_simplexiter < subproblem_iterations) ? subproblem_iterations : _data.max_simplexiter;
_data.min_simplexiter = (_data.min_simplexiter > subproblem_iterations) ? subproblem_iterations : _data.min_simplexiter;

}

void BendersBase::ResetSimplexIterationsBounds()
{
_data.max_simplexiter = 0;
_data.min_simplexiter = std::numeric_limits<int>::max();
}
bool BendersBase::IsResumeMode() const { return _options.RESUME; }

void BendersBase::UpdateMaxNumberIterationResumeMode(
Expand Down
77 changes: 77 additions & 0 deletions src/cpp/benders/benders_core/BendersMathLogger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "BendersMathLogger.h"
JasonMarechal25 marked this conversation as resolved.
Show resolved Hide resolved

#include "LogUtils.h"
#include "LoggerUtils.h"

HeadersManager::HeadersManager(HEADERSTYPE type, const BENDERSMETHOD& method) {
headers_list.push_back("ITE");
headers_list.push_back("LB");
if (method == BENDERSMETHOD::BENDERS) {
headers_list.push_back("UB");
headers_list.push_back("BESTUB");
headers_list.push_back("AGAP");
headers_list.push_back("RGAP");
}
a-zakir marked this conversation as resolved.
Show resolved Hide resolved
headers_list.push_back("MinSpx");
headers_list.push_back("MaxSpx");

if (type == HEADERSTYPE::LONG || method == BENDERSMETHOD::BENDERSBYBATCH) {
headers_list.push_back("NbSubPbSolv");
}

if (type == HEADERSTYPE::LONG) {
headers_list.push_back("CumulNbSubPbSolv");
}
headers_list.push_back("IteTime");
headers_list.push_back("MasterTime");
headers_list.push_back("SPWallTime");
if (type == HEADERSTYPE::LONG) {
headers_list.push_back("SPCpuTime");
headers_list.push_back("NotSolvingWallTime");
a-zakir marked this conversation as resolved.
Show resolved Hide resolved
}
}

LogDestination::LogDestination(std::streamsize width)
: stream_(&std::cout), width_(width) {
(*stream_) << std::unitbuf;
}

LogDestination::LogDestination(const std::filesystem::path& file_path,
std::streamsize width)
: width_(width) {
file_stream_.open(file_path, std::ofstream::out | std::ofstream::trunc);
if (file_stream_.is_open()) {
stream_ = &file_stream_;
(*stream_) << std::unitbuf;
} else {
std::ostringstream err_msg;
err_msg << PrefixMessage(LogUtils::LOGLEVEL::WARNING, MATHLOGGERCONTEXT)
<< "Could not open the file: "
<< std::quoted(file_path.string().c_str()) << "\n";
std::cerr << err_msg.str();
}
}
void MathLoggerDriver::add_logger(
std::shared_ptr<MathLoggerImplementation> logger) {
if (logger) {
math_loggers_.push_back(logger);
}
}

void MathLoggerDriver::Print(const CurrentIterationData& data) {
for (auto logger : math_loggers_) {
logger->Print(data);
}
}

void MathLoggerDriver::write_header() {
for (auto logger : math_loggers_) {
logger->write_header();
}
}

void MathLoggerDriver::display_message(const std::string& str) {
for (auto logger : math_loggers_) {
logger->display_message(str);
}
}
1 change: 1 addition & 0 deletions src/cpp/benders/benders_core/BendersStructsDatas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Point WorkerMasterData::get_x_cut() const { return *_x_cut; }
Point WorkerMasterData::get_min_invest() const { return *_min_invest; }

Point WorkerMasterData::get_max_invest() const { return *_max_invest; }

4 changes: 3 additions & 1 deletion src/cpp/benders/benders_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ add_library (benders_core STATIC
${CMAKE_CURRENT_SOURCE_DIR}/LastIterationWriter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/LastIterationReader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/LastIterationPrinter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/StartUp.cpp)
${CMAKE_CURRENT_SOURCE_DIR}/StartUp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/BendersMathLogger.cpp
)

get_target_property(JSON_INC_PATH jsoncpp_lib INTERFACE_INCLUDE_DIRECTORIES)

Expand Down
3 changes: 2 additions & 1 deletion src/cpp/benders/benders_core/SimulationOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void SimulationOptions::set_weights() {
void SimulationOptions::print(std::ostream &stream) const {
#define BENDERS_OPTIONS_MACRO(name__, type__, default__, \
deserialization_method__) \
stream << std::setw(30) << #name__ << std::setw(50) << name__ << std::endl;
stream << std::setw(30) << #name__ << std::setw(50)<<std::boolalpha << name__ << std::endl;
#include "SimulationOptions.hxx"
#undef BENDERS_OPTIONS_MACRO
stream << std::endl;
Expand Down Expand Up @@ -167,6 +167,7 @@ BendersBaseOptions SimulationOptions::get_benders_options() const {
result.LAST_MASTER_MPS = LAST_MASTER_MPS;
result.LAST_MASTER_BASIS = LAST_MASTER_BASIS;
result.BATCH_SIZE = BATCH_SIZE;
result.EXPERT_LOGS = EXPERT_LOGS;

return result;
}
10 changes: 8 additions & 2 deletions src/cpp/benders/benders_core/include/BendersBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <execution>
#include <filesystem>

#include "BendersMathLogger.h"
#include "BendersStructsDatas.h"
#include "ILogger.h"
#include "OutputWriter.h"
Expand All @@ -29,7 +30,8 @@ auto selectPolicy(lambda f, bool shouldParallelize) {
class BendersBase {
public:
virtual ~BendersBase() = default;
BendersBase(BendersBaseOptions options, Logger logger, Writer writer);
BendersBase(BendersBaseOptions options, Logger logger, Writer writer,
std::shared_ptr<MathLoggerDriver> mathLoggerDriver);
virtual void launch() = 0;
void set_solver_log_file(const std::filesystem::path &log_file);
[[nodiscard]] std::filesystem::path solver_log_file() const {
Expand All @@ -42,6 +44,7 @@ class BendersBase {
CurrentIterationData _data;
VariableMap master_variable_map;
CouplingMap coupling_map;
std::shared_ptr<MathLoggerDriver> mathLoggerDriver_;

protected:
virtual void free() = 0;
Expand Down Expand Up @@ -134,10 +137,13 @@ class BendersBase {
BendersBaseOptions Options() const { return _options; }
virtual void UpdateStoppingCriterion();
virtual bool ShouldRelaxationStop() const;
int GetNumOfSubProblemsResolvedBeforeResume() {
int GetNumOfSubProblemsSolvedBeforeResume() {
return cumulative_number_of_subproblem_resolved_before_resume;
}

void BoundSimplexIterations(int subproblem_iteration);
void ResetSimplexIterationsBounds();

SolverLogManager solver_log_manager_;

private:
Expand Down
Loading