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

Solver : add options for optim 1 and 2 #2672

Open
wants to merge 10 commits into
base: feature/new_quad_solvers
Choose a base branch
from

Conversation

guilpier-code
Copy link
Contributor

@guilpier-code guilpier-code commented Feb 28, 2025

Fixes ANT-2753.

What is done eventually :

  • Setting and checking solver options is spread in different places, we regroup them in one place, for clarity and cohesion.
  • adding command line options --lp-solver-param-optim-1 and --lp-solver-param-optim-2
  • checking command line options validity
  • Unit testing solver command line options separately (instead of testing them through unit testing generaldata.ini parameters)
  • making solver take command line options into account
  • adding documentation about command line options

@guilpier-code guilpier-code marked this pull request as draft February 28, 2025 16:43
@@ -98,6 +98,22 @@ std::unique_ptr<Yuni::GetOpt::Parser> CreateParser(Settings& settings, StudyLoad
"solver-parameters",
"Deprecated, use linear-solver-parameters instead.");

// --lp-solver-param-optim-1
Copy link
Contributor

Choose a reason for hiding this comment

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

don't forget to add the same information to the CLI doc on the website

// TODO : this function is too long and has a bad name.
// TODO : we should split it into (at least) 4 functions.
// TODO : Naming will be easier.
void Application::readStudy_makeChecks_and_printThings(Data::StudyLoadOptions& options)
Copy link
Contributor Author

@guilpier-code guilpier-code Feb 28, 2025

Choose a reason for hiding this comment

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

Quickly rename this function with a less misleading name, though imperfect.
Previous name was not good at all. This one is long but more accurate.
As specified in comment, we should split this function.

@pull-request-size pull-request-size bot added size/L and removed size/M labels Mar 4, 2025
@@ -70,7 +70,7 @@ SimulationResults APIInternal::execute(

Settings settings;
auto& parameters = study_->parameters;
parameters.optOptions = optOptions;
parameters.optOptions << optOptions;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

parameters.optOptions = optOptions;

is replaced with :

parameters.optOptions << optOptions;

I suppose that existing operator<< is meant to be used here.
@pet-mit : as you introduced this operator, what do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok for <<, it seems more coherent with CLI use

Copy link
Member

Choose a reason for hiding this comment

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

What does this operator<< do specifically ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see with @pet-mit, its his.

Copy link
Contributor

Choose a reason for hiding this comment

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

following @guilpier-code 's proposal on this PR, this operator overrides all fields of the optimization options, except for the logs flag, on which it operates a logical OR (code here)

@@ -20,7 +20,6 @@
*/

#include <antares/checks/checkLoadedInputData.h>
#include <antares/exception/InitializationError.hpp>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

#include <antares/exception/InitializationError.hpp>

was never used here. We remove it.

// Return false if the user requested the version ,available solvers, etc, true otherwise
bool handleOptions(const Data::StudyLoadOptions& options);
// Return false if the user requested help, true otherwise
bool parseCommandLine(Data::StudyLoadOptions& options);
void handleParserReturn(Yuni::GetOpt::Parser* parser);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

void handleParserReturn(Yuni::GetOpt::Parser* parser);

is declared but has never been defined or used. We remove it.

@guilpier-code guilpier-code marked this pull request as ready for review March 5, 2025 14:42
@guilpier-code guilpier-code requested a review from pet-mit March 5, 2025 14:42
@@ -70,7 +70,7 @@ SimulationResults APIInternal::execute(

Settings settings;
auto& parameters = study_->parameters;
parameters.optOptions = optOptions;
parameters.optOptions << optOptions;
Copy link
Member

Choose a reason for hiding this comment

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

What does this operator<< do specifically ?

bool found = std::ranges::find(availableSolversList, solverName) != availableSolversList.end();
if (!found)
{
throw Error::InvalidSolver(solverName, boost::algorithm::join(availableSolversList, ","));
Copy link
Member

Choose a reason for hiding this comment

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

there is already a function just for that, no need to add new code (boost::algorithm::join)

std::string availableOrToolsSolversString();

@@ -262,6 +262,7 @@ bool OPT_OptimisationLineaire(const OptimizationOptions& options,
OPT_ExportStructures(problemeHebdo, writer);
}

options.linearSolverParameters = options.lpSolverParamOptim1;
Copy link
Member

Choose a reason for hiding this comment

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

This is bad. Don't let OPT_OptimisationLineaire change it's options. What's more options is unique (unique like in "not options[numSpace]"), so we'll encounter race conditions in parallel simulations.

One solution is to add methods on this structure
OptimizationOptions opt1 = options.getOptionsOptim1()
OptimizationOptions opt2 = options.getOptionsOptim2()

But then you need to clarify the role of OptimizationOptions, and maybe create a new class to retain the options in general (excluding optimization 1 & 2).

// Options for a single optimization
class SingleOptOptions
{
};
class OptimizationOptions
{
SingleOptOptions getOptionsOptim1();
SingleOptOptions getOptionsOptim2();
};

// ...
        return runWeeklyOptimization(options.getOptionsOptim2(),
                                     problemeHebdo,
                                     writer,
                                     DEUXIEME_OPTIMISATION,
                                     simulationObserver);

WDYT ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants