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

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:

  • GaussSeidel methods: lightsim2grid.solver.GaussSeidelSolver and lightsim2grid.solver.GaussSeidelSynchSolver solves the AC powerflow using the Gauss Seidel method (an example of this algorithm is available in the great matpower library here gausspf )
  • DC methods: solve the DC approximation of the AC powerflow. To solve them it requires manipulating sparse matrices and you can use different linear algebra library for that. This is why you have up to 4 different DC solvers: lightsim2grid.solver.DCSolver (use Eigen SparseLU ), lightsim2grid.solver.KLUDCSolver (uses KLU ) lightsim2grid.solver.NICSLUDCSolver (uses NICSLU and requires and license and to compile lightsim2grid from source) lightsim2grid.solver.CKTSODCSolver (uses CKTSO and requires and license and to compile lightsim2grid from source)
  • AC with single slack methods: solves the AC equations where only one bus is the slack bus (if multiple slack buses are detected, only the first one will be used as slack bus, the others will be treated as "pv" buses). It also exists in different "flavours" that uses different linear albrea libraries (same as DC) which are: lightsim2grid.solver.SparseLUSolverSingleSlack, lightsim2grid.solver.KLUSolverSingleSlack, lightsim2grid.solver.NICSLUSolverSingleSlack and lightsim2grid.solver.CKTSOSolverSingleSlack
  • AC with distributed slack methods: solves the AC equations with multple slack buses. As for DC and AC with single slack, this is avaialble in 4 different flavours (each using internally a different linear albrea solver): lightsim2grid.solver.SparseLUSolver, lightsim2grid.solver.KLUSolver, lightsim2grid.solver.NICSLUSolver and lightsim2grid.solver.CKTSOSolver

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 lightsim2grid.solver.KLUDCSolver, lightsim2grid.solver.KLUSolverSingleSlack and 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 lightsim2grid.solver.DCSolver, lightsim2grid.solver.SparseLUSolverSingleSlack and lightsim2grid.solver.SparseLUSolver.

If it detects that the grid is "single slack" it uses the "SingleSlack" version (lightsim2grid.solver.KLUSolverSingleSlack or 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 lightsim2grid.solver.KLUSolver ) and its "name" in the lightsim2grid.SolverType (in the above example lightsim2grid.SolverType.KLU ) module is :

Solver name in "SolverType"
lightsim2grid.solver.GaussSeidelSolver GaussSeidel (SolverType.GaussSeidel)
lightsim2grid.solver.GaussSeidelSynchSolver GaussSeidelSynch (SolverType.GaussSeidelSynch)
lightsim2grid.solver.DCSolver DC (SolverType.DC)
lightsim2grid.solver.KLUDCSolver KLUDC (SolverType.KLUDC)
lightsim2grid.solver.NICSLUDCSolver NICSLUDC (SolverType.NICSLUDC)
lightsim2grid.solver.CKTSODCSolver CKTSODC (SolverType.CKTSODC)
lightsim2grid.solver.SparseLUSolverSingleSlack SparseLUSingleSlack (SolverType.SparseLUSingleSlack)
lightsim2grid.solver.KLUSolverSingleSlack KLUSingleSlack (SolverType.KLUSingleSlack)
lightsim2grid.solver.NICSLUSolverSingleSlack NICSLUSingleSlack (SolverType.NICSLUSingleSlack)
lightsim2grid.solver.CKTSOSolverSingleSlack CKTSOSingleSlack (SolverType.CKTSOSingleSlack)
lightsim2grid.solver.SparseLUSolver SparseLU (SolverType.SparseLU)
lightsim2grid.solver.KLUSolver KLU (SolverType.KLU)
lightsim2grid.solver.NICSLUSolver NICSLU (SolverType.NICSLU)
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" 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

lightsim2grid.solver

  • genindex
  • modindex
  • search