KratosMultiphysics / Kratos

Kratos Multiphysics (A.K.A Kratos) is a framework for building parallel multi-disciplinary simulation software. Modularity, extensibility and HPC are the main objectives. Kratos has BSD license and is written in C++ with extensive Python interface.
https://kratosmultiphysics.github.io/Kratos/
Other
1.04k stars 246 forks source link

json scheme #12835

Open RiccardoRossi opened 1 week ago

RiccardoRossi commented 1 week ago

Description @matekelemen @pooyan-dadvand i am sitting at the airport and i did (with the help of chatgpt) the exercise of generating a json scheme for amgcl, adding the possible choices and the current defaults. Indeed it looks cleaner that i expected.

to be honest i am not 100% sure this schema is valid ... but i think it should be close enough

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "Solver Configuration",
    "type": "object",
    "properties": {
        "preconditioner_type": {
            "type": "string",
            "default": "amg",
            "enum": ["amg", "relaxation", "dummy"]
        },
        "solver_type": {
            "type": "string",
            "default": "amgcl"
        },
        "smoother_type": {
            "type": "string",
            "default": "ilu0",
            "enum": ["spai0", "spai1", "ilu0", "ilut", "iluk", "damped_jacobi", "gauss_seidel", "chebyshev"]
        },
        "krylov_type": {
            "type": "string",
            "default": "gmres",
            "enum": ["gmres", "bicgstab", "cg", "bicgstabl", "lgmres", "fgmres", "bicgstab_with_gmres_fallback", "idrs"]
        },
        "coarsening_type": {
            "type": "string",
            "default": "aggregation",
            "enum": ["ruge_stuben", "aggregation", "smoothed_aggregation", "smoothed_aggr_emin"]
        },
        "max_iteration": {
            "type": "integer",
            "default": 100,
            "minimum": 1
        },
        "provide_coordinates": {
            "type": "boolean",
            "default": false
        },
        "gmres_krylov_space_dimension": {
            "type": "integer",
            "default": 100,
            "minimum": 1
        },
        "verbosity": {
            "type": "integer",
            "default": 1,
            "minimum": 0,
            "maximum": 3
        },
        "tolerance": {
            "type": "number",
            "default": 1e-6,
            "minimum": 0
        },
        "scaling": {
            "type": "boolean",
            "default": false
        },
        "block_size": {
            "type": "integer",
            "default": 1,
            "minimum": 1
        },
        "use_block_matrices_if_possible": {
            "type": "boolean",
            "default": true
        },
        "coarse_enough": {
            "type": "integer",
            "default": 1000,
            "minimum": 1
        },
        "max_levels": {
            "type": "integer",
            "default": -1,
            "minimum": -1
        },
        "pre_sweeps": {
            "type": "integer",
            "default": 1,
            "minimum": 0
        },
        "post_sweeps": {
            "type": "integer",
            "default": 1,
            "minimum": 0
        },
        "use_gpgpu": {
            "type": "boolean",
            "default": false
        }
    },
    "required": ["solver_type"],
    "additionalProperties": false
}
loumalouomega commented 1 week ago

Instead of Chatgpt I would use an API key to be able to do this in a more systematic manner. For some reason LLM are not good with JSON, see https://github.com/imaurer/awesome-llm-json

RiccardoRossi commented 1 week ago

Well, the point here was to do the exercise of underdtanding how a schema woukd look like for a parameter of medium complexity like the one of amgcl

Do you think that the output wpuld look different domingo it in a different way?

loumalouomega commented 1 week ago

Well, the point here was to do the exercise of underdtanding how a schema woukd look like for a parameter of medium complexity like the one of amgcl

Do you think that the output wpuld look different domingo it in a different way?

Not, it would look similar. I am just saying we have many many classes set via Parameters. So the ideal would be to do it in the most systematic manner, as it is not a complex task, but repetitive and tiresome.

RiccardoRossi commented 1 week ago

well, first of all we need to decide if this is the way we want to pursue. (this is a poposal by @matekelemen), i expressed my concern about the verbosity, but it actually looks better than what i expected

As i understand the idea of @matekelemen and @pooyan-dadvand would be to have GetDefaults to eventually return a schema to validate against.

matekelemen commented 1 week ago

GetDefaults to eventually return a schema to validate against

Yes, this would eventually be one of the goals. It would have some other advantages as well:

The obvious trade-offs are that

I must confess that I've never used JSON schemas before, and I've only heard about them from @Igarizza. Still, I think they have enough to offer to be worth the hassle. I say let's at least give them a shot.

pooyan-dadvand commented 4 days ago

Just to add that I agree with @matekelemen and I think we should tackle this gradually. Also I agree with @RiccardoRossi that we should first define what we want to put in the GetSpecification method before start populating them everywhere.