diff --git a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp index 69a3318b8..e08d1c65b 100644 --- a/src/cpp/benders/benders_by_batch/BendersByBatch.cpp +++ b/src/cpp/benders/benders_by_batch/BendersByBatch.cpp @@ -18,9 +18,9 @@ void BendersByBatch::InitializeProblems() { MatchProblemToId(); BuildMasterProblem(); - const auto &coupling_map_size = coupling_map.size(); + const auto &coupling_map_size = coupling_map_.size(); std::vector problem_names; - for (const auto &[problem_name, _] : coupling_map) { + for (const auto &[problem_name, _] : coupling_map_) { problem_names.emplace_back(problem_name); } auto batch_size = @@ -40,7 +40,7 @@ void BendersByBatch::InitializeProblems() { Rank()) { // Assign [problemNumber % WorldSize] to processID const auto subProblemFilePath = GetSubproblemPath(problem_name); - AddSubproblem({problem_name, coupling_map[problem_name]}); + AddSubproblem({problem_name, coupling_map_[problem_name]}); AddSubproblemName(problem_name); } problem_count++; diff --git a/src/cpp/benders/benders_core/BendersBase.cpp b/src/cpp/benders/benders_core/BendersBase.cpp index a9fd8a64f..9fa96397d 100644 --- a/src/cpp/benders/benders_core/BendersBase.cpp +++ b/src/cpp/benders/benders_core/BendersBase.cpp @@ -662,31 +662,21 @@ void BendersBase::set_solver_log_file(const std::filesystem::path &log_file) { } /*! - * \brief Build the input from the structure file + * \brief set the input * - * Function to build the map linking each problem name to its variables and - *their id - * - * \param root : root of the structure file - * - * \param summary_name : name of the structure file - * - * \param coupling_map : empty map to increment - * - * \note The id in the coupling_map is that of the variable in the solver - *responsible for the creation of the structure file. + * \param coupling_map : CouplingMap */ -void BendersBase::build_input_map() { - auto input = build_input(get_structure_path()); - _totalNbProblems = input.size(); +void BendersBase::set_input_map(const CouplingMap &coupling_map) { + coupling_map_ = coupling_map; + _totalNbProblems = coupling_map_.size(); _writer->write_nbweeks(_totalNbProblems); _data.nsubproblem = _totalNbProblems - 1; - master_variable_map = get_master_variable_map(input); - coupling_map = GetCouplingMap(input); + master_variable_map_ = get_master_variable_map(coupling_map_); + coupling_map_.erase(get_master_name()); } std::map BendersBase::get_master_variable_map( - std::map> input_map) const { + const std::map> &input_map) const { auto const it_master(input_map.find(get_master_name())); if (it_master == input_map.end()) { _logger->display_message(LOGLOCATION + "UNABLE TO FIND " + @@ -696,17 +686,6 @@ std::map BendersBase::get_master_variable_map( return it_master->second; } -CouplingMap BendersBase::GetCouplingMap(CouplingMap input) const { - CouplingMap couplingMap; - auto master_name = get_master_name(); - std::copy_if(input.begin(), input.end(), - std::inserter(couplingMap, couplingMap.end()), - [master_name](const CouplingMap::value_type &kvp) { - return kvp.first != master_name; - }); - return couplingMap; -} - void BendersBase::reset_master(WorkerMaster *worker_master) { _master.reset(worker_master); } @@ -726,7 +705,7 @@ void BendersBase::free_subproblems() { } void BendersBase::MatchProblemToId() { int count = 0; - for (const auto &problem : coupling_map) { + for (const auto &problem : coupling_map_) { _problem_to_id[problem.first] = count; count++; } diff --git a/src/cpp/benders/benders_core/include/BendersBase.h b/src/cpp/benders/benders_core/include/BendersBase.h index a5a2653ac..4961ba764 100644 --- a/src/cpp/benders/benders_core/include/BendersBase.h +++ b/src/cpp/benders/benders_core/include/BendersBase.h @@ -39,11 +39,12 @@ class BendersBase { } double execution_time() const; virtual std::string BendersName() const = 0; + void set_input_map(const CouplingMap &coupling_map); protected: CurrentIterationData _data; - VariableMap master_variable_map; - CouplingMap coupling_map; + VariableMap master_variable_map_; + CouplingMap coupling_map_; std::shared_ptr mathLoggerDriver_; protected: @@ -75,7 +76,6 @@ class BendersBase { [[nodiscard]] std::filesystem::path get_structure_path() const; [[nodiscard]] LogData bendersDataToLogData( const CurrentIterationData &data) const; - virtual void build_input_map(); virtual void reset_master(WorkerMaster *worker_master); void free_master() const; void free_subproblems(); @@ -158,8 +158,7 @@ class BendersBase { void compute_cut_aggregate(const SubProblemDataMap &subproblem_data_map); void compute_cut(const SubProblemDataMap &subproblem_data_map); [[nodiscard]] std::map get_master_variable_map( - std::map> input_map) const; - [[nodiscard]] CouplingMap GetCouplingMap(CouplingMap input) const; + const std::map> &input_map) const; [[nodiscard]] virtual bool shouldParallelize() const = 0; Output::Iteration iteration(const WorkerMasterDataPtr &masterDataPtr_l) const; LogData FinalLogData() const; diff --git a/src/cpp/benders/benders_core/include/common.h b/src/cpp/benders/benders_core/include/common.h index 728e25910..3bf4c0dd1 100644 --- a/src/cpp/benders/benders_core/include/common.h +++ b/src/cpp/benders/benders_core/include/common.h @@ -49,7 +49,7 @@ typedef std::vector ActiveCutStorage; typedef std::pair mps_coupling; typedef std::list mps_coupling_list; -enum class BENDERSMETHOD { BENDERS, BENDERSBYBATCH, MERGEMPS }; +enum class BENDERSMETHOD { BENDERS, BENDERSBYBATCH }; struct Predicate { bool operator()(PointPtr const &lhs, PointPtr const &rhs) const { diff --git a/src/cpp/benders/benders_mpi/BendersMPI.cpp b/src/cpp/benders/benders_mpi/BendersMPI.cpp index 56cd05a6c..0c9b3b2bf 100644 --- a/src/cpp/benders/benders_mpi/BendersMPI.cpp +++ b/src/cpp/benders/benders_mpi/BendersMPI.cpp @@ -28,7 +28,7 @@ void BendersMpi::InitializeProblems() { BuildMasterProblem(); int current_problem_id = 0; // Dispatch subproblems to process - for (const auto &problem : coupling_map) { + for (const auto &problem : coupling_map_) { // In case there are more subproblems than process if (auto process_to_feed = current_problem_id % _world.size(); process_to_feed == @@ -43,7 +43,7 @@ void BendersMpi::InitializeProblems() { } void BendersMpi::BuildMasterProblem() { if (_world.rank() == rank_0) { - reset_master(new WorkerMaster(master_variable_map, get_master_path(), + reset_master(new WorkerMaster(master_variable_map_, get_master_path(), get_solver_name(), get_log_level(), _data.nsubproblem, solver_log_manager_, IsResumeMode(), _logger)); @@ -284,9 +284,6 @@ void BendersMpi::PreRunInitialization() { } void BendersMpi::launch() { - build_input_map(); - _world.barrier(); - InitializeProblems(); _world.barrier(); diff --git a/src/cpp/benders/benders_sequential/BendersSequential.cpp b/src/cpp/benders/benders_sequential/BendersSequential.cpp index cdace96c3..cc56b7423 100644 --- a/src/cpp/benders/benders_sequential/BendersSequential.cpp +++ b/src/cpp/benders/benders_sequential/BendersSequential.cpp @@ -26,11 +26,11 @@ BendersSequential::BendersSequential( void BendersSequential::InitializeProblems() { MatchProblemToId(); - reset_master(new WorkerMaster(master_variable_map, get_master_path(), + reset_master(new WorkerMaster(master_variable_map_, get_master_path(), get_solver_name(), get_log_level(), _data.nsubproblem, solver_log_manager_, IsResumeMode(), _logger)); - for (const auto &problem : coupling_map) { + for (const auto &problem : coupling_map_) { const auto subProblemFilePath = GetSubproblemPath(problem.first); AddSubproblem(problem); @@ -129,8 +129,6 @@ void BendersSequential::Run() { } void BendersSequential::launch() { - build_input_map(); - LOG(INFO) << "Building input" << std::endl; LOG(INFO) << "Constructing workers..." << std::endl; diff --git a/src/cpp/benders/factories/BendersFactory.cpp b/src/cpp/benders/factories/BendersFactory.cpp index 163bffbf2..db55338cb 100644 --- a/src/cpp/benders/factories/BendersFactory.cpp +++ b/src/cpp/benders/factories/BendersFactory.cpp @@ -1,8 +1,7 @@ -#include "BendersFactory.h" - #include +#include "BendersFactory.h" #include "LogUtils.h" #include "LoggerFactories.h" #include "StartUp.h" @@ -12,9 +11,16 @@ #include "gflags/gflags.h" #include "glog/logging.h" +BENDERSMETHOD DeduceBendersMethod(size_t coupling_map_size, size_t batch_size) { + auto method = (batch_size == 0 || batch_size == coupling_map_size - 1) + ? BENDERSMETHOD::BENDERS + : BENDERSMETHOD::BENDERSBYBATCH; + + return method; +} + int RunBenders(char** argv, const std::filesystem::path& options_file, - mpi::environment& env, mpi::communicator& world, - const BENDERSMETHOD& method) { + mpi::environment& env, mpi::communicator& world) { // Read options, needed to have options.OUTPUTROOT BendersLoggerBase benders_loggers; Logger logger; @@ -40,6 +46,9 @@ int RunBenders(char** argv, const std::filesystem::path& options_file, std::filesystem::path(options.OUTPUTROOT) / "benders_solver.log"; Writer writer; + const auto coupling_map = build_input(benders_options.STRUCTURE_FILE); + const auto method = + DeduceBendersMethod(coupling_map.size(), options.BATCH_SIZE); if (world.rank() == 0) { auto benders_log_console = benders_options.LOG_LEVEL > 0; @@ -63,17 +72,18 @@ int RunBenders(char** argv, const std::filesystem::path& options_file, benders_loggers.AddLogger(logger); benders_loggers.AddLogger(math_log_driver); pBendersBase benders; - if (method == BENDERSMETHOD::BENDERS) { - benders = std::make_shared(benders_options, logger, writer, - env, world, math_log_driver); - } else if (method == BENDERSMETHOD::BENDERSBYBATCH) { - benders = std::make_shared( - benders_options, logger, writer, env, world, math_log_driver); - } else { - auto err_msg = "Error only benders or benders-by-batch allowed!"; - benders_loggers.display_message(err_msg); - std::exit(1); + switch (method) { + case BENDERSMETHOD::BENDERS: + benders = std::make_shared(benders_options, logger, writer, + env, world, math_log_driver); + break; + case BENDERSMETHOD::BENDERSBYBATCH: + benders = std::make_shared( + benders_options, logger, writer, env, world, math_log_driver); + break; } + + benders->set_input_map(coupling_map); std::ostringstream oss_l = start_message(options, benders->BendersName()); oss_l << std::endl; benders_loggers.display_message(oss_l.str()); @@ -116,10 +126,10 @@ int RunBenders(char** argv, const std::filesystem::path& options_file, } BendersMainFactory::BendersMainFactory(int argc, char** argv, - const BENDERSMETHOD& method, + mpi::environment& env, mpi::communicator& world) - : argv_(argv), method_(method), penv_(&env), pworld_(&world) { + : argv_(argv), penv_(&env), pworld_(&world) { // First check usage (options are given) if (world.rank() == 0) { usage(argc); @@ -128,19 +138,14 @@ BendersMainFactory::BendersMainFactory(int argc, char** argv, options_file_ = std::filesystem::path(argv_[1]); } BendersMainFactory::BendersMainFactory( - int argc, char** argv, const BENDERSMETHOD& method, - const std::filesystem::path& options_file, mpi::environment& env, - mpi::communicator& world) - : argv_(argv), - method_(method), - options_file_(options_file), - penv_(&env), - pworld_(&world) { + int argc, char** argv, const std::filesystem::path& options_file, + mpi::environment& env, mpi::communicator& world) + : argv_(argv), options_file_(options_file), penv_(&env), pworld_(&world) { // First check usage (options are given) if (world.rank() == 0) { usage(argc); } } int BendersMainFactory::Run() const { - return RunBenders(argv_, options_file_, *penv_, *pworld_, method_); + return RunBenders(argv_, options_file_, *penv_, *pworld_); } diff --git a/src/cpp/benders/factories/include/BendersFactory.h b/src/cpp/benders/factories/include/BendersFactory.h index db304e415..54ab0c415 100644 --- a/src/cpp/benders/factories/include/BendersFactory.h +++ b/src/cpp/benders/factories/include/BendersFactory.h @@ -5,23 +5,19 @@ #include "BendersSequential.h" #include "ILogger.h" #include "OutputWriter.h" -#include "common.h" class BendersMainFactory { private: char** argv_; - BENDERSMETHOD method_; std::filesystem::path options_file_; boost::mpi::environment* penv_ = nullptr; boost::mpi::communicator* pworld_ = nullptr; public: explicit BendersMainFactory(int argc, char** argv, - const BENDERSMETHOD& method, boost::mpi::environment& env, boost::mpi::communicator& world); explicit BendersMainFactory(int argc, char** argv, - const BENDERSMETHOD& method, const std::filesystem::path& options_file, boost::mpi::environment& env, boost::mpi::communicator& world); diff --git a/src/cpp/exe/CMakeLists.txt b/src/cpp/exe/CMakeLists.txt index 56ae4afb9..efe61cbf1 100644 --- a/src/cpp/exe/CMakeLists.txt +++ b/src/cpp/exe/CMakeLists.txt @@ -15,5 +15,3 @@ add_subdirectory ("${CMAKE_CURRENT_SOURCE_DIR}/antares_archive_updater") add_subdirectory ("${CMAKE_CURRENT_SOURCE_DIR}/benders") - -add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/benders_by_batch") \ No newline at end of file diff --git a/src/cpp/exe/benders/main.cpp b/src/cpp/exe/benders/main.cpp index 95f7a0175..5e27445f6 100644 --- a/src/cpp/exe/benders/main.cpp +++ b/src/cpp/exe/benders/main.cpp @@ -4,7 +4,6 @@ int main(int argc, char **argv) { mpi::environment env(argc, argv); mpi::communicator world; - auto benders_factory = - BendersMainFactory(argc, argv, BENDERSMETHOD::BENDERS, env, world); + auto benders_factory = BendersMainFactory(argc, argv, env, world); return benders_factory.Run(); } diff --git a/src/cpp/exe/benders_by_batch/CMakeLists.txt b/src/cpp/exe/benders_by_batch/CMakeLists.txt deleted file mode 100644 index fa4095d05..000000000 --- a/src/cpp/exe/benders_by_batch/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# =========================================================================== -# CMake configuration -# =========================================================================== - -# =========================================================================== -# Targets -# =========================================================================== - -# --------------------------------------------------------------------------- -# Benders by batch Exe -# --------------------------------------------------------------------------- - -add_executable (bendersbybatch - ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp -) - -target_link_libraries (bendersbybatch - ${PROJECT_NAME}::benders_core - ${PROJECT_NAME}::benders_by_batch_core - ${PROJECT_NAME}::factories - ${PROJECT_NAME}::output_core - logger_lib) - -install(TARGETS bendersbybatch DESTINATION bin) \ No newline at end of file diff --git a/src/cpp/exe/benders_by_batch/main.cpp b/src/cpp/exe/benders_by_batch/main.cpp deleted file mode 100644 index 11a3c1c98..000000000 --- a/src/cpp/exe/benders_by_batch/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ - -#include "BendersFactory.h" - -int main(int argc, char **argv) { - mpi::environment env(argc, argv); - mpi::communicator world; - - auto benders_factory = - BendersMainFactory(argc, argv, BENDERSMETHOD::BENDERSBYBATCH, env, world); - - return benders_factory.Run(); -} \ No newline at end of file diff --git a/src/cpp/exe/full_run/main.cpp b/src/cpp/exe/full_run/main.cpp index 997593efb..59203a50a 100644 --- a/src/cpp/exe/full_run/main.cpp +++ b/src/cpp/exe/full_run/main.cpp @@ -30,10 +30,9 @@ int main(int argc, char** argv) { world.barrier(); int argc_ = 2; const auto options_file = options_parser.BendersOptionsFile(); - const auto benders_method = options_parser.Method(); auto benders_factory = - BendersMainFactory(argc_, argv, benders_method, options_file, env, world); + BendersMainFactory(argc_, argv, options_file, env, world); benders_factory.Run(); if (world.rank() == 0) { diff --git a/src/cpp/full_run/FullRunOptionsParser.cpp b/src/cpp/full_run/FullRunOptionsParser.cpp index 9d79d669b..aa0efe03c 100644 --- a/src/cpp/full_run/FullRunOptionsParser.cpp +++ b/src/cpp/full_run/FullRunOptionsParser.cpp @@ -4,8 +4,7 @@ namespace po = boost::program_options; FullRunOptionsParser::FullRunOptionsParser() : ProblemGenerationExeOptions() { - AddOptions()("method,m", po::value(&method_str_)->required(), - "benders method")( + AddOptions()( "benders_options,b", po::value(&benders_options_file_)->required(), "benders options file")( @@ -15,17 +14,4 @@ FullRunOptionsParser::FullRunOptionsParser() : ProblemGenerationExeOptions() { } void FullRunOptionsParser::Parse(unsigned int argc, const char* const* argv) { ProblemGenerationExeOptions::Parse(argc, argv); - SetMethod(); -} -void FullRunOptionsParser::SetMethod() { - if (method_str_ == "benders") { - method_ = BENDERSMETHOD::BENDERS; - } else if (method_str_ == "benders_by_batch") { - method_ = BENDERSMETHOD::BENDERSBYBATCH; - } else if (method_str_ == "mergeMPS") { - method_ = BENDERSMETHOD::MERGEMPS; - } else { - throw FullRunOptionsParser::FullRunOptionInvalidMethod(LOGLOCATION + - method_str_); - } } \ No newline at end of file diff --git a/src/cpp/full_run/include/FullRunOptionsParser.h b/src/cpp/full_run/include/FullRunOptionsParser.h index c376c6e20..078562e82 100644 --- a/src/cpp/full_run/include/FullRunOptionsParser.h +++ b/src/cpp/full_run/include/FullRunOptionsParser.h @@ -10,31 +10,15 @@ class FullRunOptionsParser : public ProblemGenerationExeOptions { FullRunOptionsParser(); ~FullRunOptionsParser() override = default; void Parse(unsigned int argc, const char* const* argv) override; - class FullRunOptionInvalidMethod : public std::runtime_error { - public: - explicit FullRunOptionInvalidMethod(const std::string& method) - : std::runtime_error( - std::string("Eror in FullRunOptionParser, method: ") + method + - " is not supported! Please choose one of: " + - FullRunOptionsParser::ListAvailalbleMethods()) {} - }; - [[nodiscard]] BENDERSMETHOD Method() const { return method_; }; - [[nodiscard]] std::filesystem::path BendersOptionsFile() const { + + std::filesystem::path BendersOptionsFile() const { return benders_options_file_; } - [[nodiscard]] std::filesystem::path SolutionFile() const { - return solutionFile_; - } - static inline std::string ListAvailalbleMethods() { - return "benders,\n benders_by_batch,\n mergeMPS\n"; - } + std::filesystem::path SolutionFile() const { return solutionFile_; } private: - std::string method_str_; - BENDERSMETHOD method_; std::filesystem::path benders_options_file_; std::filesystem::path solutionFile_; - void SetMethod(); }; #endif // ANTARES_XPANSION_SRC_CPP_FULL_RUN_FULLRUNOPTIONSPARSER_H diff --git a/src/python/antares_xpansion/benders_driver.py b/src/python/antares_xpansion/benders_driver.py index 358d49a04..47c74d1ce 100644 --- a/src/python/antares_xpansion/benders_driver.py +++ b/src/python/antares_xpansion/benders_driver.py @@ -13,13 +13,12 @@ class BendersDriver: - def __init__(self, benders, benders_by_batch, merge_mps, options_file) -> None: + def __init__(self, benders, merge_mps, options_file) -> None: self.oversubscribe = False self.allow_run_as_root = False self.benders = benders self.merge_mps = merge_mps - self.benders_by_batch = benders_by_batch self.logger = step_logger(__name__, __class__.__name__) if (options_file != ""): @@ -92,8 +91,6 @@ def set_solver(self): self.solver = self.benders elif self.method == "mergeMPS": self.solver = self.merge_mps - elif self.method == "benders_by_batch": - self.solver = self.benders_by_batch else: self.logger.error("Illegal optim method") raise BendersDriver.BendersSolverError( diff --git a/src/python/antares_xpansion/config_file_parser.py b/src/python/antares_xpansion/config_file_parser.py index 194ede534..a39180ae2 100644 --- a/src/python/antares_xpansion/config_file_parser.py +++ b/src/python/antares_xpansion/config_file_parser.py @@ -11,8 +11,7 @@ def __init__(self, config_file) -> None: self.default_install_dir = "" self.ANTARES_DEFAULT = "antares-solver" self.MERGE_MPS_DEFAULT = "merge_mps" - self.BENDERS_DEFAULT = "benders_mpi" - self.BENDERS_BY_BATCH_DEFAULT = "benders_by_batch" + self.BENDERS_DEFAULT = "benders" self.LP_NAMER_DEFAULT = "lp_namer" self.STUDY_UPDATER_DEFAULT = "study_updater" self.FULL_RUN_DEFAULT = "full_run" @@ -33,8 +32,6 @@ def get_config_parameters(self) -> ConfigParameters: MERGE_MPS=content.get('MERGE_MPS', self.MERGE_MPS_DEFAULT), BENDERS=content.get( 'BENDERS', self.BENDERS_DEFAULT), - BENDERS_BY_BATCH=content.get( - 'BENDERS_BY_BATCH', self.BENDERS_BY_BATCH_DEFAULT), LP_NAMER=content.get('LP_NAMER', self.LP_NAMER_DEFAULT), STUDY_UPDATER=content.get( 'STUDY_UPDATER', self.STUDY_UPDATER_DEFAULT), diff --git a/src/python/antares_xpansion/config_loader.py b/src/python/antares_xpansion/config_loader.py index 8c89b79be..c1353ed48 100644 --- a/src/python/antares_xpansion/config_loader.py +++ b/src/python/antares_xpansion/config_loader.py @@ -599,8 +599,6 @@ def lp_namer_exe(self): def benders_exe(self): return self.exe_path(self._config.BENDERS) - def benders_by_batch_exe(self): - return self.exe_path(self._config.BENDERS_BY_BATCH) def merge_mps_exe(self): return self.exe_path(self._config.MERGE_MPS) diff --git a/src/python/antares_xpansion/driver.py b/src/python/antares_xpansion/driver.py index 52c90869b..eedd5860e 100644 --- a/src/python/antares_xpansion/driver.py +++ b/src/python/antares_xpansion/driver.py @@ -47,7 +47,6 @@ def __init__(self, config_loader: ConfigLoader): self.benders_driver = BendersDriver( self.config_loader.benders_exe(), - self.config_loader.benders_by_batch_exe(), self.config_loader.merge_mps_exe(), self.config_loader.options_file_name() ) @@ -76,7 +75,6 @@ def launch(self): self.config_loader.benders_pre_actions() self.full_run_driver.launch(self.config_loader.simulation_output_path(), self.config_loader.is_relaxed(), - self.config_loader.method(), self.config_loader.json_file_path(), self.config_loader.keep_mps(), self.config_loader.n_mpi(), @@ -178,7 +176,6 @@ def resume_study(self): self.config_loader.launcher_options_file_path(), self.config_loader.options_file_name(), self.config_loader.benders_exe(), - self.config_loader.benders_by_batch_exe(), self.config_loader.merge_mps_exe()) resume_study = ResumeStudy(resume_study_data) diff --git a/src/python/antares_xpansion/full_run_driver.py b/src/python/antares_xpansion/full_run_driver.py index e2d417235..7a978fd9f 100644 --- a/src/python/antares_xpansion/full_run_driver.py +++ b/src/python/antares_xpansion/full_run_driver.py @@ -20,7 +20,6 @@ def __init__(self, full_exe, problem_generation_driver: ProblemGeneratorDriver, def prepare_drivers(self, output_path: Path, problem_generation_is_relaxed: bool, - benders_method, json_file_path, benders_keep_mps=False, benders_n_mpi=1, @@ -37,7 +36,7 @@ def prepare_drivers(self, output_path: Path, self.keep_mps = benders_keep_mps # Benders pre-step - self.benders_driver.method = benders_method + self.benders_driver.method = "benders" self.benders_driver.n_mpi = benders_n_mpi self.benders_driver.oversubscribe = benders_oversubscribe self.benders_driver.allow_run_as_root = benders_allow_run_as_root @@ -48,14 +47,13 @@ def prepare_drivers(self, output_path: Path, def launch(self, output_path: Path, problem_generation_is_relaxed: bool, - benders_method, json_file_path, benders_keep_mps=False, benders_n_mpi=1, benders_oversubscribe=False, benders_allow_run_as_root=False): self.prepare_drivers( - output_path, problem_generation_is_relaxed, benders_method, + output_path, problem_generation_is_relaxed, json_file_path, benders_keep_mps, benders_n_mpi, benders_oversubscribe, benders_allow_run_as_root) self.run() @@ -82,12 +80,12 @@ def run(self): def full_command(self) -> List: bare_solver_command = [ - self.full_exe, "--benders_options", self.benders_driver.options_file, "--method", self.benders_driver.method, "-s", + self.full_exe, "--benders_options", self.benders_driver.options_file, "-s", str(self.json_file_path)] bare_solver_command.extend( self.problem_generation_driver.lp_namer_options()) - if (self.benders_driver.solver in [self.benders_driver.benders, self.benders_driver.benders_by_batch]) and self.benders_driver.n_mpi > 1: + if self.benders_driver.solver == self.benders_driver.benders and self.benders_driver.n_mpi > 1: mpi_command = self.benders_driver.get_mpi_run_command_root() mpi_command.extend(bare_solver_command) return mpi_command diff --git a/src/python/antares_xpansion/input_parser.py b/src/python/antares_xpansion/input_parser.py index cdadff2fe..f2145f565 100644 --- a/src/python/antares_xpansion/input_parser.py +++ b/src/python/antares_xpansion/input_parser.py @@ -38,7 +38,7 @@ def _initialize_parser(self): dest=LauncherOptionsKeys.method_key(), type=str, choices=["benders", - "mergeMPS", "benders_by_batch"], + "mergeMPS"], help="Choose the optimization method", default=LauncherOptionsDefaultValues.DEFAULT_VALUE()) self.parser.add_argument("-n", "--np", diff --git a/src/python/antares_xpansion/resume_study.py b/src/python/antares_xpansion/resume_study.py index 1dd04731b..3e12c6e5a 100644 --- a/src/python/antares_xpansion/resume_study.py +++ b/src/python/antares_xpansion/resume_study.py @@ -16,7 +16,6 @@ class ResumeStudyData: launcher_options_file: Path benders_options_file: str benders_exe: str - benders_by_batch_exe: str merge_mps_exe: str @@ -29,7 +28,6 @@ def __init__(self, resume_study_data: ResumeStudyData) -> None: resume_study_data.launcher_options_file self._load_resume_options() self.benders_exe = resume_study_data.benders_exe - self.benders_by_batch_exe = resume_study_data.benders_by_batch_exe self.merge_mps_exe = resume_study_data.merge_mps_exe self.benders_options_file = resume_study_data.benders_options_file @@ -111,7 +109,6 @@ def _update_options_file(self): benders_driver = BendersDriver( self.benders_exe, - self.benders_by_batch_exe, self.merge_mps_exe, self.benders_options_file ) diff --git a/src/python/antares_xpansion/xpansionConfig.py b/src/python/antares_xpansion/xpansionConfig.py index 01d31e7b7..cf6d78e9a 100644 --- a/src/python/antares_xpansion/xpansionConfig.py +++ b/src/python/antares_xpansion/xpansionConfig.py @@ -16,7 +16,6 @@ class ConfigParameters: ANTARES: str MERGE_MPS: str BENDERS: str - BENDERS_BY_BATCH: str LP_NAMER: str STUDY_UPDATER: str SENSITIVITY_EXE: str @@ -56,7 +55,6 @@ def __init__( self.ANTARES: str = "" self.MERGE_MPS: str = "" self.BENDERS: str = "" - self.BENDERS_BY_BATCH: str = "" self.LP_NAMER: str = "" self.STUDY_UPDATER: str = "" self.SENSITIVITY_EXE: str = "" @@ -239,7 +237,6 @@ def _get_config_values(self): self.ANTARES = self.config_parameters.ANTARES self.MERGE_MPS = self.config_parameters.MERGE_MPS self.BENDERS = self.config_parameters.BENDERS - self.BENDERS_BY_BATCH = self.config_parameters.BENDERS_BY_BATCH self.LP_NAMER = self.config_parameters.LP_NAMER self.STUDY_UPDATER = self.config_parameters.STUDY_UPDATER self.FULL_RUN = self.config_parameters.FULL_RUN diff --git a/src/python/config.yaml.in b/src/python/config.yaml.in index 57bb8fc3c..722780fff 100644 --- a/src/python/config.yaml.in +++ b/src/python/config.yaml.in @@ -2,7 +2,6 @@ DEFAULT_INSTALL_DIR : ${CURRENT_RUNTIME_OUTPUT_DIRECTORY} ANTARES : @ANTARES_SOLVER_APP@ MERGE_MPS : $ BENDERS : @BENDERS@ -BENDERS_BY_BATCH : $ LP_NAMER : $ STUDY_UPDATER : $ FULL_RUN : $ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6b19951d1..e96e7c844 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,9 +12,9 @@ find_python_module(pytest) find_python_module(numpy) if (PYTHON_MODULE_pytest_FOUND AND PYTHON_MODULE_numpy_FOUND) - set(xpress_avalaible "False") + set(xpress_available "") if(${XPRESS}) - set(xpress_avalaible "True") + set(xpress_available "--xpress") endif() # Python unit test add_test( @@ -89,7 +89,7 @@ if (PYTHON_MODULE_pytest_FOUND AND PYTHON_MODULE_numpy_FOUND) # benders end to end tests add_test( NAME sequential - COMMAND Python3::Interpreter -m pytest --installDir=${XPANSION_INSTALL_DIR} --xpress=${xpress_avalaible} test_bendersSequentialEndToEnd.py + COMMAND Python3::Interpreter -m pytest --installDir=${XPANSION_INSTALL_DIR} ${xpress_available} test_bendersSequentialEndToEnd.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/end_to_end/benders ) set_property(TEST sequential PROPERTY LABELS benders benders-sequential end_to_end) @@ -101,7 +101,7 @@ if (PYTHON_MODULE_pytest_FOUND AND PYTHON_MODULE_numpy_FOUND) set_property(TEST sequential_restart PROPERTY LABELS benders benders-sequential end_to_end restart) add_test( NAME mpibenders - COMMAND Python3::Interpreter -m pytest --allow_run_as_root=${ALLOW_RUN_AS_ROOT} --installDir=${XPANSION_INSTALL_DIR} --xpress=${xpress_avalaible} test_bendersmpibendersEndToEnd.py + COMMAND Python3::Interpreter -m pytest --allow_run_as_root=${ALLOW_RUN_AS_ROOT} --installDir=${XPANSION_INSTALL_DIR} ${xpress_available} test_bendersmpibendersEndToEnd.py WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/end_to_end/benders ) set_property(TEST mpibenders PROPERTY LABELS benders benders-mpi end_to_end) diff --git a/tests/cpp/benders/benders_sequential_test.cpp b/tests/cpp/benders/benders_sequential_test.cpp index b6a2d9c72..2dd3782c0 100644 --- a/tests/cpp/benders/benders_sequential_test.cpp +++ b/tests/cpp/benders/benders_sequential_test.cpp @@ -64,7 +64,6 @@ class BendersSequentialDouble : public BendersSequential { void BuildCut() override{}; void compute_ub() override { _data.ub = parametrized_ub; }; CurrentIterationData get_data() const { return _data; } - void build_input_map() override{}; void write_basis() const override{}; void EndWritingInOutputFile() const override{}; void UpdateTrace() override{}; @@ -80,11 +79,11 @@ class BendersSequentialDouble : public BendersSequential { MatchProblemToId(); auto solver_log_manager = SolverLogManager(solver_log_file()); - reset_master(new WorkerMaster(master_variable_map, get_master_path(), + reset_master(new WorkerMaster(master_variable_map_, get_master_path(), get_solver_name(), get_log_level(), _data.nsubproblem, solver_log_manager, IsResumeMode(), _logger)); - for (const auto &problem : coupling_map) { + for (const auto &problem : coupling_map_) { const auto subProblemFilePath = GetSubproblemPath(problem.first); AddSubproblem(problem); AddSubproblemName(problem.first); diff --git a/tests/cpp/full_run/FullRunTest.cpp b/tests/cpp/full_run/FullRunTest.cpp index c8418b27f..084a80f98 100644 --- a/tests/cpp/full_run/FullRunTest.cpp +++ b/tests/cpp/full_run/FullRunTest.cpp @@ -4,23 +4,6 @@ #include "gtest/gtest.h" namespace po = boost::program_options; -// struct CommandLine { -// std::string exe_name; -// std::string output = "--output"; -// std::string output_value; -// std::string benders_options = "--benders_options"; -// std::string benders_options_value; -// std::string method = "--method"; -// std::string method_value; -// std::string solution = "--solution"; -// std::string solution_value; -// // std::string ToString() const { -// // return exe_name + " " + output + " " + output_value + " " + -// // benders_options + " " + benders_options_value + " " + method + -// " " -// // + method_value + " " + solution + " " + solution_value; -// // } -// }; class FullRunOptionsParserTest : public ::testing::TestWithParam> { @@ -55,23 +38,6 @@ TEST_P(FullRunOptionsParserTest, ThatBendersOptionFileIsRequired) { } } -TEST_P(FullRunOptionsParserTest, ThatMethodOptionIsRequired) { - auto params = GetParam(); - std::vector pargs; - std::ranges::transform(params, std::back_inserter(pargs), - [](const std::string& s) { return s.data(); }); - const char argv5[] = "--benders_options"; - const char argv6[] = "something"; - pargs.push_back(argv5); - pargs.push_back(argv6); - try { - full_run_options_options_parser_.Parse(pargs.size(), pargs.data()); - } catch (const std::exception& e) { - EXPECT_EQ(e.what(), - std::string("the option '--method' is required but missing")); - } -} - TEST_P(FullRunOptionsParserTest, ThatSolutionOptionIsRequired) { auto params = GetParam(); std::vector pargs; @@ -81,10 +47,6 @@ TEST_P(FullRunOptionsParserTest, ThatSolutionOptionIsRequired) { const char argv6[] = "something"; pargs.push_back(argv5); pargs.push_back(argv6); - const char argv7[] = "-m"; - const char argv8[] = "mpibenders"; - pargs.push_back(argv7); - pargs.push_back(argv8); try { full_run_options_options_parser_.Parse(pargs.size(), pargs.data()); } catch (const std::exception& e) { @@ -103,21 +65,18 @@ TEST_P(FullRunOptionsParserTestFullPath, OptionsParsing) { const char argv6[] = "something"; pargs.push_back(argv5); pargs.push_back(argv6); - const char argv7[] = "-m"; - const char argv8[] = "benders"; + const char argv7[] = "-s"; + const char argv8[] = "/path/to/solution.json"; pargs.push_back(argv7); pargs.push_back(argv8); - const char argv9[] = "-s"; - const char argv10[] = "/path/to/solution.json"; - pargs.push_back(argv9); - pargs.push_back(argv10); + full_run_options_options_parser_.Parse(pargs.size(), pargs.data()); ASSERT_EQ(full_run_options_options_parser_.BendersOptionsFile(), std::filesystem::path(argv6)); ASSERT_EQ(full_run_options_options_parser_.SolutionFile(), - std::filesystem::path(argv10)); - ASSERT_EQ(full_run_options_options_parser_.Method(), BENDERSMETHOD::BENDERS); + std::filesystem::path(argv8)); } + auto full_path_params() { return ::testing::ValuesIn(std::vector>{ {"full_run.exe", "--archive", "/path/to/output.zip"}, @@ -126,35 +85,3 @@ auto full_path_params() { } INSTANTIATE_TEST_SUITE_P(args, FullRunOptionsParserTestFullPath, full_path_params()); - -TEST_P(FullRunOptionsParserTestParameterizedMethod_output, AllowedMethods) { - const char argv0[] = "full_run.exe"; - const char argv3[] = "--output"; - const char argv4[] = "/path/to/output"; - const char argv5[] = "--benders_options"; - const char argv6[] = "options.json"; - const char argv7[] = "-m"; - const char argv8[] = "-s"; - const char argv9[] = "/path/to/solution.json"; - auto [method_str, expected_method_enum] = GetParam(); - std::vector ppargv = { - argv0, argv3, argv4, argv5, - argv6, argv7, method_str.c_str(), - argv8, argv9}; - full_run_options_options_parser_.Parse(ppargv.size(), ppargv.data()); - ASSERT_EQ(full_run_options_options_parser_.BendersOptionsFile(), - std::filesystem::path(argv6)); - ASSERT_EQ(full_run_options_options_parser_.SolutionFile(), - std::filesystem::path(argv9)); - ASSERT_EQ(full_run_options_options_parser_.Method(), expected_method_enum); -} - -auto GetData() { - return ::testing::ValuesIn(std::vector>{ - {"benders", BENDERSMETHOD::BENDERS}, - {"benders_by_batch", BENDERSMETHOD::BENDERSBYBATCH}, - {"mergeMPS", BENDERSMETHOD::MERGEMPS}}); -} -INSTANTIATE_TEST_SUITE_P(Method, - FullRunOptionsParserTestParameterizedMethod_output, - GetData()); \ No newline at end of file diff --git a/tests/end_to_end/benders/conftest.py b/tests/end_to_end/benders/conftest.py index 5f26a34cd..30fa30d52 100644 --- a/tests/end_to_end/benders/conftest.py +++ b/tests/end_to_end/benders/conftest.py @@ -7,7 +7,7 @@ def pytest_addoption(parser): parser.addoption("--installDir", action="store", default=build_config_reader.get_install_dir()) parser.addoption("--allow_run_as_root", action="store", default="") - parser.addoption("--xpress", action="store", default="") + parser.addoption("--xpress", action="store_false", default=False) @pytest.fixture() diff --git a/tests/end_to_end/examples/example_test.py b/tests/end_to_end/examples/example_test.py index c58152865..a65717fad 100644 --- a/tests/end_to_end/examples/example_test.py +++ b/tests/end_to_end/examples/example_test.py @@ -39,7 +39,7 @@ def remove_outputs(study_path): shutil.rmtree(f) -def launch_xpansion(install_dir, study_path, method: BendersMethod, allow_run_as_root=False, nproc: int = 4): +def launch_xpansion(install_dir, study_path, allow_run_as_root=False, nproc: int = 4): # Clean study output remove_outputs(study_path) @@ -52,8 +52,6 @@ def launch_xpansion(install_dir, study_path, method: BendersMethod, allow_run_as install_dir_full, "--dataDir", str(study_path), - "--method", - method.value, "--step", "full", "-n", @@ -353,7 +351,7 @@ def test_full_study_long_sequential( tmp_study = tmp_path / study_path.name shutil.copytree(study_path, tmp_study) launch_xpansion(install_dir, tmp_study, - BendersMethod.BENDERS, allow_run_as_root, 1) + allow_run_as_root, 1) verify_solution(tmp_study, expected_values, expected_investment_solution) verify_study_update( tmp_study, expected_investment_solution, antares_version) @@ -375,8 +373,7 @@ def test_full_study_long_mpi( ): tmp_study = tmp_path / study_path.name shutil.copytree(study_path, tmp_study) - launch_xpansion(install_dir, tmp_study, - BendersMethod.BENDERS, allow_run_as_root) + launch_xpansion(install_dir, tmp_study, allow_run_as_root) verify_solution(tmp_study, expected_values, expected_investment_solution) verify_study_update( tmp_study, expected_investment_solution, antares_version) @@ -401,8 +398,7 @@ def test_full_study_long_benders_by_batch_parallel( shutil.move(tmp_study/"user"/"expansion"/"settings_by_batch.ini", tmp_study/"user"/"expansion"/"settings.ini") method = BendersMethod.BENDERS_BY_BATCH - launch_xpansion(install_dir, tmp_study, - method, allow_run_as_root) + launch_xpansion(install_dir, tmp_study, allow_run_as_root) verify_solution(tmp_study, expected_values, expected_investment_solution, method) verify_study_update( @@ -569,8 +565,7 @@ def test_full_study_medium_sequential( ): tmp_study = tmp_path / study_path.name shutil.copytree(study_path, tmp_study) - launch_xpansion(install_dir, tmp_study, - BendersMethod.BENDERS, allow_run_as_root, 1) + launch_xpansion(install_dir, tmp_study, allow_run_as_root, 1) verify_solution(tmp_study, expected_values, expected_investment_solution) verify_study_update( tmp_study, expected_investment_solution, antares_version) @@ -592,8 +587,7 @@ def test_full_study_medium_parallel( ): tmp_study = tmp_path / study_path.name shutil.copytree(study_path, tmp_study) - launch_xpansion(install_dir, tmp_study, - BendersMethod.BENDERS, allow_run_as_root) + launch_xpansion(install_dir, tmp_study, allow_run_as_root) verify_solution(tmp_study, expected_values, expected_investment_solution) verify_study_update( tmp_study, expected_investment_solution, antares_version) @@ -618,8 +612,7 @@ def test_full_study_medium_benders_by_batch_parallel( shutil.move(tmp_study/"user"/"expansion"/"settings_by_batch.ini", tmp_study/"user"/"expansion"/"settings.ini") method = BendersMethod.BENDERS_BY_BATCH - launch_xpansion(install_dir, tmp_study, - method, allow_run_as_root) + launch_xpansion(install_dir, tmp_study, allow_run_as_root) verify_solution(tmp_study, expected_values, expected_investment_solution, method) verify_study_update( @@ -685,7 +678,7 @@ def test_full_study_short_sequential( ): tmp_study = tmp_path / study_path.name shutil.copytree(study_path, tmp_study) - launch_xpansion(install_dir, tmp_study, BendersMethod.BENDERS, + launch_xpansion(install_dir, tmp_study, allow_run_as_root, nproc=1) verify_solution(tmp_study, expected_values, expected_investment_solution) verify_study_update( @@ -708,8 +701,7 @@ def test_full_study_short_parallel( ): tmp_study = tmp_path / study_path.name shutil.copytree(study_path, tmp_study) - launch_xpansion(install_dir, tmp_study, - BendersMethod.BENDERS, allow_run_as_root) + launch_xpansion(install_dir, tmp_study, allow_run_as_root) verify_solution(tmp_study, expected_values, expected_investment_solution) verify_study_update( tmp_study, expected_investment_solution, antares_version) @@ -734,8 +726,7 @@ def test_full_study_short_benders_by_batch_parallel( shutil.move(tmp_study/"user"/"expansion"/"settings_by_batch.ini", tmp_study/"user"/"expansion"/"settings.ini") method = BendersMethod.BENDERS_BY_BATCH - launch_xpansion(install_dir, tmp_study, - method, allow_run_as_root) + launch_xpansion(install_dir, tmp_study, allow_run_as_root) verify_solution(tmp_study, expected_values, expected_investment_solution, method) verify_study_update( diff --git a/tests/python/test_benders_driver.py b/tests/python/test_benders_driver.py index 4a4ad2274..cbfea10ea 100644 --- a/tests/python/test_benders_driver.py +++ b/tests/python/test_benders_driver.py @@ -25,24 +25,24 @@ def setup_method(self): def test_lp_path(self, tmp_path): lp_path = tmp_path / "lp" os.mkdir(lp_path) - benders_driver = BendersDriver("", "", "", self.OPTIONS_JSON) + benders_driver = BendersDriver("", "", self.OPTIONS_JSON) benders_driver.set_simulation_output_path(tmp_path) assert benders_driver.get_lp_path() == lp_path def test_non_existing_output_path(self, tmp_path): - benders_driver = BendersDriver("", "", "", self.OPTIONS_JSON) + benders_driver = BendersDriver("", "", self.OPTIONS_JSON) with pytest.raises(BendersDriver.BendersOutputPathError): benders_driver.launch(tmp_path / "i_dont_exist", "test", False, 13) def test_empty_output_path(self, tmp_path): - benders_driver = BendersDriver("", "", "", self.OPTIONS_JSON) + benders_driver = BendersDriver("", "", self.OPTIONS_JSON) with pytest.raises(BendersDriver.BendersLpPathError): benders_driver.launch(tmp_path, "") def test_illegal_method(self, tmp_path): lp_path = tmp_path / "lp" os.mkdir(lp_path) - benders_driver = BendersDriver("", "", "", self.OPTIONS_JSON) + benders_driver = BendersDriver("", "", self.OPTIONS_JSON) with pytest.raises(BendersDriver.BendersSolverError): benders_driver.launch(tmp_path, "test") @@ -53,7 +53,7 @@ def test_benders_cmd_mpibenders(self, tmp_path): exe_path = os.path.normpath( os.path.join(my_install_dir, my_benders_mpi)) - benders_driver = BendersDriver(exe_path, "", "", self.OPTIONS_JSON) + benders_driver = BendersDriver(exe_path, "", self.OPTIONS_JSON) simulation_output_path = tmp_path lp_path = Path(os.path.normpath( @@ -78,7 +78,7 @@ def test_benders_cmd_mpibenders_with_oversubscribe_linux_only(self, tmp_path): os.path.join(my_install_dir, my_benders_mpi)) benders_driver = BendersDriver( - exe_path, "", "", self.OPTIONS_JSON) + exe_path, "", self.OPTIONS_JSON) simulation_output_path = tmp_path lp_path = Path(os.path.normpath( @@ -100,7 +100,7 @@ def test_benders_cmd_sequential(self, tmp_path): exe_path = os.path.normpath( os.path.join(my_install_dir, my_sequential)) - benders_driver = BendersDriver(exe_path, "", "", self.OPTIONS_JSON) + benders_driver = BendersDriver(exe_path, "", self.OPTIONS_JSON) simulation_output_path = tmp_path lp_path = Path(os.path.normpath( @@ -120,7 +120,7 @@ def test_benders_cmd_merge_mps(self, tmp_path): exe_path = os.path.normpath( os.path.join(my_install_dir, my_merges_mps)) - benders_driver = BendersDriver("", "", exe_path, self.OPTIONS_JSON) + benders_driver = BendersDriver("", exe_path, self.OPTIONS_JSON) simulation_output_path = tmp_path lp_path = Path(os.path.normpath( @@ -142,7 +142,7 @@ def test_raise_execution_error(self, tmp_path): exe_path = os.path.normpath( os.path.join(my_install_dir, my_benders_mpi)) - benders_driver = BendersDriver(exe_path, "", "", self.OPTIONS_JSON) + benders_driver = BendersDriver(exe_path, "", self.OPTIONS_JSON) simulation_output_path = tmp_path lp_path = Path(os.path.normpath( @@ -161,7 +161,7 @@ def test_clean_solver_log_file(self, tmp_path): my_n_mpi = 13 exe_path = os.path.normpath( os.path.join(my_install_dir, my_benders_mpi)) - benders_driver = BendersDriver(exe_path, "", "", self.OPTIONS_JSON) + benders_driver = BendersDriver(exe_path, "", self.OPTIONS_JSON) simulation_output_path = tmp_path lp_path = Path(os.path.normpath( @@ -191,7 +191,7 @@ def test_unsupported_platform(self, tmp_path): with patch(MOCK_SYS, autospec=True) as sys_: sys_.platform = "exotic_platform" with pytest.raises(BendersDriver.BendersUnsupportedPlatform): - BendersDriver("", "", "", self.OPTIONS_JSON) + BendersDriver("", "", self.OPTIONS_JSON) def test_clean_benders_step_if_not_keep_mps(self, tmp_path): my_benders_mpi = "something" @@ -200,7 +200,7 @@ def test_clean_benders_step_if_not_keep_mps(self, tmp_path): os.path.join(my_install_dir, my_benders_mpi)) keep_mps = False - benders_driver = BendersDriver(exe_path, "", "", self.OPTIONS_JSON) + benders_driver = BendersDriver(exe_path, "", self.OPTIONS_JSON) simulation_output_path = tmp_path lp_path = Path(os.path.normpath( @@ -233,7 +233,7 @@ def test_clean_benders_step_if_not_keep_mps(self, tmp_path): def test_invalid_options_file(self): with pytest.raises(BendersDriver.BendersOptionsFileError): - BendersDriver("", "", "", "") + BendersDriver("", "", "") def _create_empty_file(self, tmp_path: Path, fname: str): file = tmp_path / fname diff --git a/tests/python/test_config_file_parser.py b/tests/python/test_config_file_parser.py index fdbb92fb3..96ba16938 100644 --- a/tests/python/test_config_file_parser.py +++ b/tests/python/test_config_file_parser.py @@ -21,8 +21,7 @@ def test_config_file_empty(self, tmp_path): assert config_param.default_install_dir == "" assert config_param.ANTARES == "antares-solver" assert config_param.MERGE_MPS == "merge_mps" - assert config_param.BENDERS == "benders_mpi" - assert config_param.BENDERS_BY_BATCH == "benders_by_batch" + assert config_param.BENDERS == "benders" assert config_param.LP_NAMER == "lp_namer" assert config_param.STUDY_UPDATER == "study_updater" assert config_param.SENSITIVITY_EXE == "sensitivity" diff --git a/tests/python/test_full_run_driver.py b/tests/python/test_full_run_driver.py index 2035127f4..30c742f37 100644 --- a/tests/python/test_full_run_driver.py +++ b/tests/python/test_full_run_driver.py @@ -38,16 +38,15 @@ def test_sequential_command(self, tmp_path): problem_generation.set_output_path(output_path) problem_generation.create_lp_dir() benders_driver = BendersDriver( - "benders.exe", "", "", self.benders_driver_options_file) + "benders.exe", "", self.benders_driver_options_file) full_run_driver = FullRunDriver(self.full_run_exe, problem_generation, benders_driver) - full_run_driver.prepare_drivers(output_path, is_relaxed, benders_method, json_file_path, + full_run_driver.prepare_drivers(output_path, is_relaxed, json_file_path, benders_keep_mps=benders_keep_mps, benders_oversubscribe=benders_oversubscribe, benders_allow_run_as_root=benders_allow_run_as_root) xpansion_output_dir = output_path.parent / \ (output_path.stem+"-Xpansion") expected_command = [self.full_run_exe, "--benders_options", self.benders_driver_options_file, - "--method", benders_method, "-s", str(json_file_path), "-a", str(output_path), "-f", - "integer", "-e", self.pb_gen_data.additional_constraints] + "-s", str(json_file_path), "-a", str(output_path), "-f", "integer", "-e", self.pb_gen_data.additional_constraints] command = full_run_driver.full_command() assert len(expected_command) == len(command) @@ -73,16 +72,15 @@ def test_mpi_command(self, tmp_path): problem_generation.create_lp_dir() benders_driver = BendersDriver( - "benders.exe", "", "", self.benders_driver_options_file) + "benders.exe", "", self.benders_driver_options_file) full_run_driver = FullRunDriver(self.full_run_exe, problem_generation, benders_driver) - full_run_driver.prepare_drivers(output_path, is_relaxed, benders_method, json_file_path, + full_run_driver.prepare_drivers(output_path, is_relaxed, json_file_path, benders_keep_mps, benders_n_mpi, benders_oversubscribe, benders_allow_run_as_root) xpansion_output_dir = output_path.parent / \ (output_path.stem+"-Xpansion") expected_command = [benders_driver.MPI_LAUNCHER, "-n", str(benders_n_mpi), self.full_run_exe, "--benders_options", self.benders_driver_options_file, - "--method", benders_method, "-s", str(json_file_path), "-a", str(output_path), "-f", - "integer", "-e", self.pb_gen_data.additional_constraints] + "-s", str(json_file_path), "-a", str(output_path), "-f", "integer", "-e", self.pb_gen_data.additional_constraints] command = full_run_driver.full_command() diff --git a/tests/python/test_resume_study.py b/tests/python/test_resume_study.py index 9e7bea3aa..41be47943 100644 --- a/tests/python/test_resume_study.py +++ b/tests/python/test_resume_study.py @@ -31,7 +31,7 @@ def test_fail_if_simulation_output_path_not_found(self, tmp_path): with pytest.raises(ResumeStudy.StudyOutputPathError): ResumeStudy(ResumeStudyData( - output_path, "", "", "", "", "")) + output_path, "", "", "", "")) def test_fail_if_launcher_options_is_not_found(self, tmp_path): @@ -39,7 +39,7 @@ def test_fail_if_launcher_options_is_not_found(self, tmp_path): output_path.mkdir() with pytest.raises(ResumeStudy.ResumeOptionsFileNotFound): resume_study = ResumeStudy(ResumeStudyData( - output_path, "fefe", "", "", "", "")) + output_path, "fefe", "", "", "")) def test_fail_if_launcher_options_is_empty(self, tmp_path): output_path = tmp_path / "lp" @@ -48,7 +48,7 @@ def test_fail_if_launcher_options_is_empty(self, tmp_path): launcher_options_file.touch() with pytest.raises(json.decoder.JSONDecodeError): ResumeStudy(ResumeStudyData( - output_path, launcher_options_file.name, "fefe", "", "", "")) + output_path, launcher_options_file.name, "fefe", "", "")) def test_fail_if_options_file_not_found(self, tmp_path): output_path = tmp_path / "lp" @@ -57,7 +57,7 @@ def test_fail_if_options_file_not_found(self, tmp_path): launcher_options_file.write_text("{}") with pytest.raises(ResumeStudy.OptionsFileNotFound): resume_study = ResumeStudy(ResumeStudyData( - output_path, launcher_options_file.name, "fefe", "", "", "")) + output_path, launcher_options_file.name, "fefe", "", "")) resume_study.launch() def test_fail_if_last_master_file_keyword_is_not_found(self, tmp_path): @@ -78,7 +78,7 @@ def test_fail_if_last_master_file_keyword_is_not_found(self, tmp_path): with pytest.raises(ResumeStudy.KeyWordNotFound): resume_study = ResumeStudy(ResumeStudyData( - output_path, launcher_options_file.name, benders_options_file_name, "", "", "")) + output_path, launcher_options_file.name, benders_options_file_name, "", "")) resume_study.launch() def test_fail_if_last_master_file_not_found(self, tmp_path): @@ -99,7 +99,7 @@ def test_fail_if_last_master_file_not_found(self, tmp_path): with pytest.raises(ResumeStudy.LastMasterFileNotFound): resume_study = ResumeStudy(ResumeStudyData( - output_path, launcher_options_file.name, benders_options_file_name, "", "", "")) + output_path, launcher_options_file.name, benders_options_file_name, "", "")) resume_study.launch() def test_fail_if_options_file_is_updated(self, tmp_path): @@ -130,7 +130,7 @@ def test_fail_if_options_file_is_updated(self, tmp_path): create_master_file.write_text("master file content") resume_study = ResumeStudy(ResumeStudyData( - output_path, launcher_options_file.name, benders_options_file_name, "", "", "")) + output_path, launcher_options_file.name, benders_options_file_name, "", "")) with patch(MOCK_SUBPROCESS_RUN, autospec=True) as run_function: run_function.return_value.returncode = 0 resume_study.launch()