PowerGridModel / power-grid-model

Python/C++ library for distribution power system analysis
Mozilla Public License 2.0
141 stars 29 forks source link

[FEATURE] Generate component attributes documentation using code generator #692

Open mgovers opened 1 month ago

mgovers commented 1 month ago

Currently, several files are generated by the code generator in https://github.com/PowerGridModel/power-grid-model/tree/main/code_generation .

However, there is component documentation based on that generated code in https://power-grid-model.readthedocs.io/en/stable/user_manual/components.html that is manually created. This documentation can go out of date without anyone noticing, e.g. because default values changing.

This ticket is about generating the component documentation via the code generator.

TODO

TBD

Example

{
    "name": "input",
    "include_guard": "INPUT",
    "classes": [
        {
            "name": "BranchInput",
            "base": "BaseInput",
            "attributes": [
                {
                    "data_type": "ID",
                    "names": [
                        "from_node",
                        "to_node"
                    ],
                    "description": "node IDs to which this branch is connected at both sides",
                    "is_updateable": false,
                    "unit":  null,
                    "long_description": [
                        "ID of node at from-side",
                        "ID of node at to-side"
                    ],
                    "required": true,
                    "valid_values": "a valid node ID",
                    "default_value": null
                },
                {
                    "data_type": "IntS",
                    "names": [
                        "from_status",
                        "to_status"
                    ],
                    "description": "whether the branch is connected at each side",
                    "is_updateable": true,
                    "unit":  null,
                    "long_description": [
                        "connection status at from-side",
                        "connection status at to-side"
                    ],
                    "required": true,
                    "valid_values": "`0` or `1`",
                    "default_value": null
                }
            ]
        }
    ]
}
TonyXiang8787 commented 1 month ago

I am not sure about this issue. The logic is pretty complicated. Also in documentation we will explain the mathematics of the components and their required value ranges.

It is for sure not a good first issue.

mgovers commented 1 month ago

I am not sure about this issue. The logic is pretty complicated. Also in documentation we will explain the mathematics of the components and their required value ranges.

As long as they just copy-paste the contents of the tables, that should not be too hard, right?

It is for sure not a good first issue.

Creating the jinja template is not hard. If we refine the TBD parts a bit better, I think the same is true for the json part.

TonyXiang8787 commented 1 month ago

In the current documentation we have also many equations to explain the electrical model of certain component.

If you want to generate that one, you have to put the whole equation (in markdown and latex) in json with many escape characters. I really do not think this is easy. Let alone the maintainability.

mgovers commented 1 month ago

In the current documentation we have also many equations to explain the electrical model of certain component.

They can remain in the template file in markdown as is, right? only the table generation has to be jinja templated. No need to add

If you want to generate that one, you have to put the whole equation (in markdown and latex) in json with many escape characters. I really do not think this is easy. Let alone the maintainebility.

If you really want to, it's possible to really only generate a file with nothing more than the tables and then in-place include them in the original components.md file. See e.g. https://stackoverflow.com/questions/69939832/include-whole-text-sections-from-other-rst-files-into-this-file

petersalemink95 commented 1 month ago

I also have my doubts about this issue. Auto generating this particular documentation seems overly complicated in my opinion.

Of course it can happen that docs are not properly updated, but they should. If you change a default value you should update the docs and as reviewer you should also notice this. Besides that, I don't think many things will change here, only new components might be added, but we won't change default behavior that quickly.

mgovers commented 1 month ago

Cfr. offline discussion: We want to have the additional safeguard of extra reviewing round. Might be a tool to ease our lives at a later stage, but it's not a feature we want to automate.

Related: do we want to combine the input.json and update.json configuration files? If so, we can split that from this issue into a new one and close this one