AMGX icon indicating copy to clipboard operation
AMGX copied to clipboard

Using AMGX_config_add_parameters with .json options.

Open YvanFournier opened this issue 5 years ago • 5 comments

Hello,

I am trying to use AMGX_config_add_parameters to modify the solver tolerance (which I need to do in my code to adjust the tolerance to the right-hand side normalization), with an initial configuration based on a .json file.

Using the text syntax such as in the examples, I can use AMGX_config_add_parameters(&cfg, options);

with the options string containing:

config_version=2, main:convergence=ABSOLUTE, main:tolerance=2.042244e-09

But get a return code 12 (Incorrect amgx configuration provided) when using a .json syntax:

{"config_version": 2, "solver": {"convergence": "ABSOLUTE",  "tolerance": 4.081224e-09}}

Where the "solver" entry in the main .json file (FGMRES.json from the AmgX examples for example) has "scope": "main".

I can't find anything relative to another .json syntax, and would like to avoid the repeated warning that Cannot read file as JSON object, trying as AMGX config.

Am I missing something ? Could an example of the correct syntax be provided in the documentation ?

YvanFournier avatar Oct 13 '20 11:10 YvanFournier

Interesting, i didn't look into usecase of using AMGX_config_add_parameters with json, let me check this.

marsaev avatar Nov 05 '20 16:11 marsaev

Issue comes from the way we treat json configs. Whenever object is seen in json config amgx tries to parse it as solver, but in this scenario there is no "solver" string. It can be workarounded with following config string: {"config_version": 2, "solver": {"convergence": "ABSOLUTE", "tolerance": 4.081224e-09, "solver": "FGMRES"}} passed to the AMGX_config_add_parameters. It's possible to match using namespaces, without specifying solver identification will do that. Will make a fix so following config string would be acceptable to AMGX_config_add_parameters: {"config_version": 2, "solver": {"convergence": "ABSOLUTE", "tolerance": 4.081224e-09, "scope": "main"}}

marsaev avatar Nov 05 '20 23:11 marsaev

Actually my proposal doesn't really seem fitting to me. Maybe it would be better to change parsing of configuration string of AMGX_config_add_parameters() if JSON string is given - in a similar way it's done for plain strings, i.e. if initial config is:

{"config_version": 2, 
    "solver": {
        "convergence": "ABSOLUTE",  
        "tolerance": 4.081224e-09,
        "solver": "FGMRES",
        "scope": "main"
    }
}

then accept following as input to AMGX_config_add_parameters(): {"main": {"convergence": "RELATIVE", "tolerance": 1e-03}}

In any way, will address this later due to low priority

marsaev avatar Feb 03 '21 10:02 marsaev

Tracking internally: AMGX-46

marsaev avatar Apr 07 '21 18:04 marsaev

If technically possible, AMGX_config_add_parameters() should accept string that is relative to the current config instead of matching the scope name. Otherwise, it would limit the flexibility that JSON files provide.

It would be very useful to be able to read any valid config JSON file with the possibility to add/modify some parameters - e.g. absolute convergence with specific tolerance - in the top-level solver defined by the config.

ghost avatar Dec 29 '22 21:12 ghost