Skip to content

Commit

Permalink
add options transfer to batchrun
Browse files Browse the repository at this point in the history
  • Loading branch information
flomnes authored and payetvin committed Nov 7, 2024
1 parent c0a3976 commit 663abc3
Showing 1 changed file with 34 additions and 166 deletions.
200 changes: 34 additions & 166 deletions src/tools/batchrun/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,151 +87,32 @@ int main(int argc, char* argv[])
// Initializing the toolbox
Antares::Resources::Initialize(argc, argv, true);

// options
std::string optInput;
std::string ortoolsSolver;
bool optNoTSImport = false;
bool optIgnoreAllConstraints = false;
bool optForceExpansion = false;
bool optForceEconomy = false;
bool optForceAdequacy = false;
bool optForce = false;
bool optYearByYear = false;
bool optNoOutput = false;
bool optParallel = false;
bool optVerbose = false;
bool ortoolsUsed = false;
Nullable<uint> optYears;
Nullable<String> optSolver;
Nullable<String> optName;
Nullable<uint> optForceParallel;

// Command Line options
if (argc < 2)
{
// Parser
GetOpt::Parser options;
//
options.addParagraph(String() << "Antares Batch Simulation Launcher v" << VersionToCString()
<< "\n");
// Input
options.addParagraph("Studies");
options.add(optInput, 'i', "input", "The input folder, where to find some studies");

// Simulation mode
options.addParagraph("\nSimulation mode");
options.addFlag(
optForceExpansion, ' ', "economy", "Force the simulation(s) in expansion mode");
options.addFlag(optForceEconomy, ' ', "economy", "Force the simulation(s) in economy mode");
options.addFlag(
optForceAdequacy, ' ', "adequacy", "Force the simulation(s) in adequacy mode");

options.addParagraph("\nParameters");
options.add(optName, 'n', "name", "Set the name of the new simulation outputs");
options.add(optYears, 'y', "year", "Override the number of MC years");
options.addFlag(optForce, 'f', "force", "Ignore all warnings at loading");
options.addFlag(
optNoOutput, ' ', "no-output", "Do not write the results in the output folder");
options.addFlag(optYearByYear,
' ',
"year-by-year",
"Force the writing of the result output for each year");

options.addParagraph("\nOptimization");
options.addFlag(
optNoTSImport, ' ', "no-ts-import", "Do not import timeseries into the input folder.");
options.addFlag(optIgnoreAllConstraints, ' ', "no-constraints", "Ignore all constraints");

options.addParagraph("\nExtras");
options.add(optSolver, ' ', "solver", "Specify the antares-solver location");
options.addFlag(
optParallel, 'p', "parallel", "Enable the parallel computation of MC years");
options.add(optForceParallel,
' ',
"force-parallel",
"Override the max number of years computed simultaneously");

// add option for ortools use
// --use-ortools
options.addFlag(ortoolsUsed, ' ', "use-ortools", "Use ortools library to launch solver");

//--ortools-solver
options.add(ortoolsSolver,
' ',
"ortools-solver",
"Ortools solver used for simulation (only available with use-ortools "
"option)\nAvailable solver list : "
+ availableOrToolsSolversString());

options.remainingArguments(optInput);
// Version
options.addParagraph("\nMisc.");
bool optVersion = false;
options.addFlag(optVersion, 'v', "version", "Print the version and exit");
options.addFlag(optVerbose, ' ', "verbose", "Displays study runs outputs");

if (options(argc, argv) == GetOpt::ReturnCode::error)
return options.errors() ? 1 : 0;
logs.error() << "Usage " << argv[0] << " optInput [other options]";
return EXIT_FAILURE;
}

if (optVersion)
{
PrintVersionToStdCout();
return 0;
}
const bool optVerbose = false;

// Command Line options
{
const std::string optInput(argv[1]);
if (optInput.empty())
{
logs.error() << "A folder input is required.";
return EXIT_FAILURE;
}

if (optForceExpansion and optForceAdequacy)
{
logs.error() << "contradictory options: --expansion and --adequacy";
return EXIT_FAILURE;
}

if (optForceEconomy and optForceAdequacy)
{
logs.error() << "contradictory options: --economy and --adequacy";
return EXIT_FAILURE;
}

if (ortoolsUsed)
{
const auto availableSolvers = getAvailableOrtoolsSolverName();
if (auto it
= std::find(availableSolvers.begin(), availableSolvers.end(), ortoolsSolver);
it == availableSolvers.end())
{
logs.error() << "Please specify a solver using --ortools-solver. Available solvers "
<< availableOrToolsSolversString() << "";
return EXIT_FAILURE;
}
}

// Source Folder
logs.debug() << "Folder : `" << optInput << '`';

String solver;
if (optSolver.empty())
{
Solver::FindLocation(solver);
if (solver.empty())
{
logs.fatal() << "The solver has not been found";
return EXIT_FAILURE;
}
}
else
Solver::FindLocation(solver);
if (solver.empty())
{
String tmp;
IO::MakeAbsolute(tmp, *optSolver);
IO::Normalize(solver, tmp);
if (not IO::File::Exists(solver))
{
logs.fatal() << "The solver has not been found. specify --solver=" << solver;
return EXIT_FAILURE;
}
logs.fatal() << "The solver has not been found";
return EXIT_FAILURE;
}

logs.info() << " Solver: '" << solver << "'";
Expand All @@ -246,19 +127,13 @@ int main(int argc, char* argv[])
if (not finder.list.empty())
{
if (finder.list.size() > 1)
logs.info() << "Found " << finder.list.size() << " studyies";
{
logs.info() << "Found " << finder.list.size() << " studies";
}
else
logs.info() << "Found 1 study";
logs.info() << "Starting...";

if (!(!optName))
{
String name;
name = *optName;
name.replace("\"", "\\\"");
*optName = name;
}

// The folder that contains the solver
String dirname;
IO::parentPath(dirname, solver);
Expand All @@ -285,32 +160,25 @@ int main(int argc, char* argv[])
else
cmd << "call "; // why is it required for working ???
cmd << "\"" << solver << "\"";
if (optForce)
cmd << " --force";
if (optForceExpansion)
cmd << " --economy";
if (optForceEconomy)
cmd << " --economy";
if (optForceAdequacy)
cmd << " --adequacy";
if (!(!optName))
cmd << " --name=\"" << *optName << "\"";
if (!(!optYears))
cmd << " --year=" << *optYears;
if (optNoOutput)
cmd << " --no-output";
if (optYearByYear)
cmd << " --year-by-year";
if (optNoTSImport)
cmd << " --no-ts-import";
if (optIgnoreAllConstraints)
cmd << " --no-constraints";
if (optParallel)
cmd << " --parallel";
if (optForceParallel)
cmd << " --force-parallel=" << *optForceParallel;
if (ortoolsUsed)
cmd << " --use-ortools --ortools-solver=" << ortoolsSolver;

// argv[0] => executable name
// argv[1] => directory name
for (int ii = 2; ii < argc; ii++)
{
const std::string arg(argv[ii]);
if (arg.find(" ") == std::string::npos)
{
cmd << " " << arg;
}
else
{
// Wrap spaces around quotes, if any
// example
// antares-batchrun directory --use-ortools --ortools-solver xpress
// --solver-parameters "PRESOLVE 1"
cmd << " \"" << arg << "\"";
}
}

cmd << " \"" << studypath << "\"";
if (!optVerbose)
Expand Down

0 comments on commit 663abc3

Please sign in to comment.