Skip to content

Commit

Permalink
Remove glog dependency (#826)
Browse files Browse the repository at this point in the history
- Glog symbols conflict with absl symbols
- Glog is "community maintained", absl is "official"
- We have a dedicated logger

---------

Co-authored-by: abdoulbari zaher <[email protected]>
  • Loading branch information
JasonMarechal25 and a-zakir authored May 22, 2024
1 parent a9aa95b commit e19998e
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 50 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# CMake configuration
# ===========================================================================

CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

# ===========================================================================
# Project configuration
Expand Down Expand Up @@ -216,7 +216,6 @@ find_package(Cgl REQUIRED)
find_package(Clp REQUIRED)
find_package(CoinUtils REQUIRED)
find_package(Osi REQUIRED)
find_package(glog REQUIRED)

if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
Expand Down
2 changes: 1 addition & 1 deletion cmake/json-cmake-1.1.0/JSONParser.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.5)

if (DEFINED JSonParserGuard)
return()
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_by_batch/BendersByBatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "BatchCollection.h"
#include "CustomVector.h"
#include "RandomBatchShuffler.h"
#include "glog/logging.h"

BendersByBatch::BendersByBatch(
BendersBaseOptions const &options, Logger logger, Writer writer,
mpi::environment &env, mpi::communicator &world,
Expand Down
1 change: 0 additions & 1 deletion src/cpp/benders/benders_by_batch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ target_link_libraries (benders_by_batch_core
helpers
output_core
solvers
glog::glog
)

add_library (${PROJECT_NAME}::benders_by_batch_core ALIAS benders_by_batch_core)
6 changes: 3 additions & 3 deletions src/cpp/benders/benders_core/BendersBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "LastIterationWriter.h"
#include "LogUtils.h"
#include "VariablesGroup.h"
#include "glog/logging.h"

#include "solver_utils.h"

BendersBase::BendersBase(const BendersBaseOptions &options, Logger logger,
Expand Down Expand Up @@ -68,8 +68,8 @@ void BendersBase::OpenCsvFile() {
"time;basis;"
<< std::endl;
} else {
LOG(INFO) << "Impossible to open the .csv file: " << _csv_file_path
<< std::endl;
using namespace std::string_literals;
_logger->display_message("Impossible to open the .csv file: "s + _csv_file_path.string());
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/cpp/benders/benders_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ target_link_libraries (benders_core
helpers
output_core
solvers
glog::glog
TBB::tbb
${JSONCPP_LIB}
yaml-cpp
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/benders/benders_core/Worker.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Worker.h"

#include "LogUtils.h"
#include "glog/logging.h"

#include "solver_utils.h"
/*!
* \brief Free the problem
Expand Down
6 changes: 2 additions & 4 deletions src/cpp/benders/benders_core/WorkerMaster.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "WorkerMaster.h"

#include "glog/logging.h"

#include "solver_utils.h"

WorkerMaster::WorkerMaster(Logger logger) : Worker(logger) {
Expand Down Expand Up @@ -301,9 +301,7 @@ void WorkerMaster::_set_alpha_var() {
solver_addrows(*_solver, rowtype, rowrhs, {}, mstart, mclind, matval);
}
} else {
LOG(INFO)
<< "ERROR a variable named overall_subpb_cost_under_approx is in input"
<< std::endl;
logger_->display_message("ERROR a variable named overall_subpb_cost_under_approx is in input", LogUtils::LOGLEVEL::ERR);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/cpp/benders/benders_mpi/BendersMPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "CustomVector.h"
#include "Timer.h"
#include "glog/logging.h"


BendersMpi::BendersMpi(BendersBaseOptions const &options, Logger logger,
Writer writer, mpi::environment &env,
Expand Down Expand Up @@ -240,7 +240,6 @@ void BendersMpi::check_if_some_proc_had_a_failure(int success) {

void BendersMpi::write_exception_message(const std::exception &ex) const {
std::string error = "Exception raised : " + std::string(ex.what());
LOG(WARNING) << error << std::endl;
_logger->display_message(error);
}

Expand Down
1 change: 0 additions & 1 deletion src/cpp/benders/benders_mpi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ target_link_libraries (benders_mpi_core
output_core
Boost::mpi
MPI::MPI_C
glog::glog
${PROJECT_NAME}::factories
logger_lib
Boost::serialization
Expand Down
12 changes: 5 additions & 7 deletions src/cpp/benders/benders_sequential/BendersSequential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <utility>

#include "Timer.h"
#include "glog/logging.h"

#include "solver_utils.h"

/*!
Expand Down Expand Up @@ -129,18 +129,16 @@ void BendersSequential::Run() {
}

void BendersSequential::launch() {
LOG(INFO) << "Building input" << std::endl;

LOG(INFO) << "Constructing workers..." << std::endl;
_logger->display_message("Building input");
_logger->display_message("Constructing workers...");

InitializeProblems();
LOG(INFO) << "Running solver..." << std::endl;
_logger->display_message("Running solver...");
try {
Run();
LOG(INFO) << BendersName() + " solver terminated." << std::endl;
_logger->display_message(BendersName() + " solver terminated.");
} catch (std::exception const &ex) {
std::string error = "Exception raised : " + std::string(ex.what());
LOG(WARNING) << error << std::endl;
_logger->display_message(error);
}

Expand Down
1 change: 0 additions & 1 deletion src/cpp/benders/benders_sequential/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ target_link_libraries (benders_sequential_core
helpers
output_core
solvers
glog::glog
${PROJECT_NAME}::factories


Expand Down
7 changes: 0 additions & 7 deletions src/cpp/benders/factories/BendersFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include "Timer.h"
#include "Worker.h"
#include "WriterFactories.h"
#include "gflags/gflags.h"
#include "glog/logging.h"

BENDERSMETHOD DeduceBendersMethod(size_t coupling_map_size, size_t batch_size,
bool external_loop) {
Expand Down Expand Up @@ -52,11 +50,6 @@ pBendersBase BendersMainFactory::PrepareForExecution(

BendersBaseOptions benders_options(options.get_benders_options());

google::InitGoogleLogging(argv_[0]);
auto path_to_log =
std::filesystem::path(options.OUTPUTROOT) /
("bendersLog-rank" + std::to_string(pworld_->rank()) + ".txt.");
google::SetLogDestination(google::GLOG_INFO, path_to_log.string().c_str());

auto log_reports_name =
std::filesystem::path(options.OUTPUTROOT) / "reportbenders.txt";
Expand Down
1 change: 0 additions & 1 deletion src/cpp/benders/merge_mps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ target_link_libraries (merge_mps_core
factories
output_core
solvers
glog::glog
)

add_library (${PROJECT_NAME}::merge_mps_core ALIAS merge_mps_core)
15 changes: 7 additions & 8 deletions src/cpp/benders/merge_mps/MergeMPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "ArchiveReader.h"
#include "LogUtils.h"
#include "Timer.h"
#include "glog/logging.h"

MergeMPS::MergeMPS(const MergeMPSOptions &options, Logger &logger,
Writer writer)
Expand All @@ -26,7 +25,7 @@ void MergeMPS::launch() {
CouplingMap x_mps_id;
int cntProblems_l(0);

LOG(INFO) << "Merging problems..." << std::endl;
_logger->display_message("Merging problems...");
for (auto const &kvp : input) {
auto problem_name(inputRootDir / (kvp.first));
SolverAbstract::Ptr solver_l = factory.create_solver(solver_to_use);
Expand Down Expand Up @@ -87,16 +86,16 @@ void MergeMPS::launch() {
neles_reserve += kvp.second.size() * (kvp.second.size() - 1);
nrows_reserve += kvp.second.size() * (kvp.second.size() - 1) / 2;
}
LOG(INFO) << "About to add " << nrows_reserve << " coupling constraints"
<< std::endl;
_logger->display_message("About to add " + std::to_string(nrows_reserve) +
" coupling constraints");
values.reserve(neles_reserve);
cindex.reserve(neles_reserve);
mstart.reserve(nrows_reserve + 1);

// adding coupling constraints
for (auto const &kvp : x_mps_id) {
std::string const var_name(kvp.first);
LOG(INFO) << var_name << std::endl;
_logger->display_message(var_name);
bool is_first(true);
int id1(-1);
std::string first_mps;
Expand Down Expand Up @@ -125,11 +124,11 @@ void MergeMPS::launch() {
CharVector sense(nrows, 'E');
solver_addrows(*mergedSolver_l, sense, rhs, {}, mstart, cindex, values);

LOG(INFO) << "Problems merged." << std::endl;
LOG(INFO) << "Writting mps file" << std::endl;
_logger->display_message("Problems merged.");
_logger->display_message("Writing mps file");
mergedSolver_l->write_prob_mps(std::filesystem::path(_options.OUTPUTROOT) /
("log_merged" + MPS_SUFFIX));
LOG(INFO) << "Writting lp file" << std::endl;
_logger->display_message("Writing lp file");
mergedSolver_l->write_prob_lp(std::filesystem::path(_options.OUTPUTROOT) /
"log_merged.lp");

Expand Down
8 changes: 2 additions & 6 deletions src/cpp/exe/merge/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "SimulationOptions.h"
#include "Worker.h"
#include "WriterFactories.h"
#include "glog/logging.h"

#include "logger/User.h"
#include "solver_utils.h"

Expand All @@ -23,10 +23,7 @@ int main(int argc, char **argv) {

Logger logger = std::make_shared<xpansion::logger::User>(std::cout);

google::InitGoogleLogging(argv[0]);
auto path_to_log = std::filesystem::path(options.OUTPUTROOT) / "merge_mpsLog";
google::SetLogDestination(google::GLOG_INFO, path_to_log.string().c_str());
LOG(INFO) << "starting merge_mps" << std::endl;
logger->display_message("starting merge_mps");

Writer writer =
build_json_writer(std::filesystem::path(options.JSON_FILE), false);
Expand All @@ -36,7 +33,6 @@ int main(int argc, char **argv) {
} catch (std::exception &ex) {
std::string error =
"Exception raised and program stopped : " + std::string(ex.what());
LOG(WARNING) << error << std::endl;
logger->display_message(error);
exit(1);
}
Expand Down
5 changes: 2 additions & 3 deletions src/cpp/helpers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ add_library (helpers STATIC
${CMAKE_CURRENT_SOURCE_DIR}/AntaresArchiveUpdaterExeOptions.h
${CMAKE_CURRENT_SOURCE_DIR}/AntaresArchiveUpdaterExeOptions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/LoggerUtils.h
)
)

get_target_property(xpansion_interfaces_path xpansion_interfaces INTERFACE_INCLUDE_DIRECTORIES)

Expand All @@ -46,11 +46,10 @@ target_include_directories (helpers
${xpansion_interfaces_path}
)

target_link_libraries (helpers
target_link_libraries (helpers
PUBLIC
${JSONCPP_LIB}
solvers
glog::glog
gflags::gflags
Boost::boost Boost::program_options
MINIZIP::minizip-ng
Expand Down

0 comments on commit e19998e

Please sign in to comment.