Skip to content

Latest commit

 

History

History
165 lines (123 loc) · 8.34 KB

solvers.rst

File metadata and controls

165 lines (123 loc) · 8.34 KB
.. currentmodule:: lightsim2grid.solver

Available "solvers" (doc in progress)

The documentation of this section is in progress. It is rather incomplete for the moment, and only expose the most basic features.

If you are interested in collaborating to improve this section, let us know.

Type of solvers available

In lightsim2grid you can have 4 different types of solvers:

Warning

Solvers based on NICSLU and CKTSO require a compilation from source. Solvers based on CKTSO are (for now) only tested on linux.

By default, when avaialble, lightsim2grid try to use the KLU linear solver, so the :class:`lightsim2grid.solver.KLUDCSolver`, :class:`lightsim2grid.solver.KLUSolverSingleSlack` and :class:`lightsim2grid.solver.KLUSolver`. If not available (for example if you compiled from source without including the KLU package) it falls back to the "SparseLU" linear solver so :class:`lightsim2grid.solver.DCSolver`, :class:`lightsim2grid.solver.SparseLUSolverSingleSlack` and :class:`lightsim2grid.solver.SparseLUSolver`.

If it detects that the grid is "single slack" it uses the "SingleSlack" version (:class:`lightsim2grid.solver.KLUSolverSingleSlack` or :class:`lightsim2grid.solver.SparseLUSolverSingleSlack`).

At any moment, you can change the solver used by lightsim2grid with:

import grid2op
import lightsim2grid
from lightsim2grid import LightSimBackend

# create an environment
env_name = "l2rpn_case14_sandbox"
env_lightsim = grid2op.make(env_name, backend=LightSimBackend())

env_lightsim.backend.set_solver_type(lightsim2grid.SolverType.KLU)  # for KLU solver

Or alternatively, you can change it when you create the backend:

import grid2op
import lightsim2grid
from lightsim2grid import LightSimBackend

# create an environment
env_name = "l2rpn_case14_sandbox"
env_lightsim = grid2op.make(env_name,
                            backend=LightSimBackend(solver_type=lightsim2grid.SolverType.KLU))

The correspondance between the type of solver used (in the above example :class:`lightsim2grid.solver.KLUSolver` ) and its "name" in the lightsim2grid.SolverType (in the above example lightsim2grid.SolverType.KLU ) module is :

Solver name in "SolverType"
:class:`lightsim2grid.solver.GaussSeidelSolver` GaussSeidel (SolverType.GaussSeidel)
:class:`lightsim2grid.solver.GaussSeidelSynchSolver` GaussSeidelSynch (SolverType.GaussSeidelSynch)
:class:`lightsim2grid.solver.DCSolver` DC (SolverType.DC)
:class:`lightsim2grid.solver.KLUDCSolver` KLUDC (SolverType.KLUDC)
:class:`lightsim2grid.solver.NICSLUDCSolver` NICSLUDC (SolverType.NICSLUDC)
:class:`lightsim2grid.solver.CKTSODCSolver` CKTSODC (SolverType.CKTSODC)
:class:`lightsim2grid.solver.SparseLUSolverSingleSlack` SparseLUSingleSlack (SolverType.SparseLUSingleSlack)
:class:`lightsim2grid.solver.KLUSolverSingleSlack` KLUSingleSlack (SolverType.KLUSingleSlack)
:class:`lightsim2grid.solver.NICSLUSolverSingleSlack` NICSLUSingleSlack (SolverType.NICSLUSingleSlack)
:class:`lightsim2grid.solver.CKTSOSolverSingleSlack` CKTSOSingleSlack (SolverType.CKTSOSingleSlack)
:class:`lightsim2grid.solver.SparseLUSolver` SparseLU (SolverType.SparseLU)
:class:`lightsim2grid.solver.KLUSolver` KLU (SolverType.KLU)
:class:`lightsim2grid.solver.NICSLUSolver` NICSLU (SolverType.NICSLU)
:class:`lightsim2grid.solver.CKTSOSolver` CKTSO (SolverType.CKTSO)

Usage

In this section we briefly explain how to switch from one solver to another. An example of code using this feature is given in the "benchmark_solvers.py" script available in the "benchmarks" directory of the lightsim2grid repository.

To change the solver used by the backend, the preferred solution is to set it once you create it:

import grid2op
import lightsim2grid
from lightsim2grid import LightSimBackend

# create an environment
env_name = "l2rpn_case14_sandbox"
env_lightsim = grid2op.make(env_name,
                            backend=LightSimBackend(solver_type=lightsim2grid.SolverType.KLU)
                           )

Note

For the list of availbale solvers, you can consult the "enum" :class:`lightsim2grid.solver.SolverType`.

You can also (so it's not recommended) change the solver after the backend is created with:

import grid2op
import lightsim2grid
from lightsim2grid import LightSimBackend

# create an environment
env_name = "l2rpn_case14_sandbox"
env_lightsim = grid2op.make(env_name, backend=LightSimBackend())

# retrieve the available solver types
available_solvers = env_lightsim.backend.available_solvers

# change the solver types (for example let's use the Gauss Seidel algorithm)
env_lightsim.backend.set_solver_type(lightsim2grid.SolverType.GaussSeidel)

# customize the solver (available for all solvers)
env_lightsim.backend.set_solver_max_iter(10000)  # all solvers here are iterative, this is the maximum number of iterations
env_lightsim.backend.set_tol(1e-7)  # change the tolerance (smaller tolerance gives a more accurate results but takes longer to compute)
# see the documentation of LightSimBackend for more information

env_lightsim.reset()  # do not forget to reset

Detailed usage

.. automodule:: lightsim2grid.solver
    :members:
    :autosummary: