powsybl / pypowsybl-grid2opbackend

Mozilla Public License 2.0
11 stars 0 forks source link

Better test suite from grid2op for backend #14

Closed BDonnot closed 1 year ago

BDonnot commented 1 year ago

Describe the current behavior

Currently, from our previous conversation, I noted that it was hard to "make sense" of the errors in grid2op tests for the backend.

This is why I made a clearer and more explicit test suite that tests only the backend API and nothing else and that can help debugging when creating a backend. All tests there should pass for a good integration with grid2op.

Describe the expected behavior

To run the tests, you need to install the developer / editable mode of grid2op 1.9.6 from github (see Extra Information paragraph for more information)

Then, you create a script (named eg "basic_test.py") with:

# TODO import pypowsyblbackend and all

from grid2op._create_test_suite import create_test_suite

def this_make_backend(self, detailed_infos_for_cascading_failures=False):
    return PypowSyblBackend(
            detailed_infos_for_cascading_failures=detailed_infos_for_cascading_failures
        )  # TODO change the name PypowSyblBackend if needed
add_name_cls = "test_pypowsyblBackend"

res = create_test_suite(make_backend_fun=this_make_backend,
                        add_name_cls=add_name_cls,
                        add_to_module=__name__,
                        extended_test=False,  # for now keep `extended_test=False` until all problems are solved
                        )

# and run it with `python -m unittest basic_test.py`
if __name__ == "__main__":
    unittest.main()

Describe the motivation

I made this function with a "test driven development" kind of method in mind. Tests are made in "increasing difficulty" (somewhat) with explicit error message when there are some issues.

Extra Information

Grid2op documentation is not up to date yet.

Grid2op needs to be installed from source from the github for this to work:

git clone https://github.com/rte-france/Grid2Op.git grid2op_dev
cd grid2op_dev
git checkout dev_1.9.6
pip install -e .
# remove the pyproject.toml file if any issues during the installation
BDonnot commented 1 year ago

Ce test peut être fait directement avec l'environnement de lightsim2grid ici https://github.com/BDonnot/lightsim2grid/tree/bd-dev/lightsim2grid/tests/case_14_storage_iidm qui est une copie des données utilisées par grid2op lorsque la "test suite" est lancée.

Un exemple d'usage est fourni ici: https://github.com/BDonnot/lightsim2grid/blob/cda64f663b01eaf1f5e993f80e29ef7892e0dd5d/lightsim2grid/tests/test_backend_pypowsybl.py#L68 (ligne 68 à 84, bien sur il faudra veiller à changer le chemin et pas utiliser simplement dir_path = os.path.dirname(os.path.realpath(__file__))

tschuppr commented 1 year ago

Handled with this commit 39bd5dd