Naming conventions: “solver” vs “algorithm”
This page explains how the terms solver and algorithm are used in
LightSim2Grid, and how to read and build the names of the
AlgorithmType enum values and the corresponding
Python classes.
Three distinct meanings of “solver”
The word solver appears in three different contexts in LightSim2Grid, and they should not be confused:
The linear solver — a numerical library that solves a sparse linear system \(Ax = b\) eg at each Newton-Raphson iteration. Examples:
SparseLULinearSolver(Eigen built-in), KLU (SuiteSparse), NICSLU, CKTSO. These names end inLinearSolverin C++.The powerflow algorithm — the outer numerical method used to solve the power-flow equations. Examples: Newton-Raphson (NR), DC approximation, Fast-Decoupled Power Flow (FDPF), Gauss-Seidel. Each algorithm can use one linear solver internally (where applicable). This is what
AlgorithmTypeenumerates, and whatAlgorithmSelectordispatches.Solver bus numbering — the compact internal bus index used by the sparse matrices, which only includes connected buses (not disconnected ones). Methods like
get_Ybus_solver(),get_pv_solver(),id_me_to_ac_solver()etc. use “solver” in this third sense. These are low-level diagnostic accessors; the naming is intentionally kept for clarity.
How AlgorithmType enum names are built
Each enum value encodes both the outer powerflow algorithm and the linear solver library used for its internal linear algebra. The naming pattern is:
{Algorithm}_{LinearSolver}
Where the algorithm prefix is:
Prefix |
Meaning |
|---|---|
|
Newton-Raphson with distributed (multi-) slack |
|
Newton-Raphson with single slack (slightly faster when only one slack bus exists) |
|
DC approximation (linearised power flow) |
|
Fast-Decoupled Power Flow, XB variant ( |
|
Fast-Decoupled Power Flow, BX variant ( |
And the linear-solver suffix is:
Suffix |
Library |
|---|---|
|
Eigen’s built-in sparse LU — always available, no extra dependency |
|
SuiteSparse KLU — available when lightsim2grid is compiled with KLU support |
|
NICSLU — requires a license and a source build |
|
CKTSO — requires a license and a source build |
Special cases (no linear solver choice):
GaussSeidelAlgo— the Gauss-Seidel iterative method. No sparse factorisation is involved.GaussSeidelSynchAlgo— synchronous (all-buses-at-once) Gauss-Seidel variant.
Complete table
|
Python class |
Description |
|---|---|---|
|
NR multi-slack + SparseLU (default when KLU unavailable) |
|
|
NR single-slack + SparseLU |
|
|
DC + SparseLU |
|
|
Fast-Decoupled XB + SparseLU |
|
|
Fast-Decoupled BX + SparseLU |
|
|
NR multi-slack + KLU (default when KLU available) |
|
|
NR single-slack + KLU |
|
|
DC + KLU |
|
|
Fast-Decoupled XB + KLU |
|
|
Fast-Decoupled BX + KLU |
|
|
NR multi-slack + NICSLU (requires license) |
|
|
NR single-slack + NICSLU (requires license) |
|
|
DC + NICSLU (requires license) |
|
|
Fast-Decoupled XB + NICSLU |
|
|
Fast-Decoupled BX + NICSLU |
|
|
NR multi-slack + CKTSO (requires license) |
|
|
NR single-slack + CKTSO (requires license) |
|
|
DC + CKTSO (requires license) |
|
|
Fast-Decoupled XB + CKTSO |
|
|
Fast-Decoupled BX + CKTSO |
|
|
Gauss-Seidel iterative (no sparse factorisation) |
|
|
Synchronous Gauss-Seidel iterative |
|
|
– |
Sentinel value reported by |
String-only built-in solvers: NRRefactorRetry_*
NRRefactorRetry_KLU, NRRefactorRetry_NICSLU and NRRefactorRetry_CKTSO are
built-in solvers that never got their own AlgorithmType enum value, so unlike
everything in the table above they can only be selected by their string name, not by an
AlgorithmType.NRRefactorRetry_* attribute (which does not exist). Since lightsim2grid
1.0, set_algo_type() accepts such a
string directly, and – unlike changing the algorithm through the private
env.backend._grid.change_algorithm(...) – remembers the choice so it is re-applied
after every env.reset() and preserved by backend.copy():
env.backend.set_algo_type("NRRefactorRetry_KLU")
Each is the same algorithm as its NR_* counterpart (Newton-Raphson, distributed
slack), except that when a Jacobian refactorize() fails it falls back to a full
factorize() (reusing the existing symbolic factorization) before giving up, instead
of reporting an error immediately. Use get_linear_solver_stats() on the solver to
see how often the fallback fires. Because they have no dedicated enum value,
get_algo_type() reports AlgorithmType.Custom while one of them is active – the
same value reported for an actual plugin solver.
Warning
env.backend._grid.change_algorithm(...) acts directly on the underlying
C++ grid model and does not survive env.reset() / backend.copy(): use
the persistent set_algo_type()
shown above instead (it works the same for a plain AlgorithmType
or a string-only / plugin name).
Usage example
import grid2op
import lightsim2grid
from lightsim2grid.algorithm import AlgorithmType
env = grid2op.make("l2rpn_case14_sandbox", backend=lightsim2grid.LightSimBackend())
# switch to NR with KLU (if available)
env.backend.set_algo_type(AlgorithmType.NR_KLU)
# inspect what algorithm is currently active
print(env.backend.get_algo_types())
# >>> (<AlgorithmType.NR_KLU: 1>, <AlgorithmType.DC_KLU: 9>)
# list all algorithms available in this build
env.backend._grid.available_algorithm_names()
Note
The method is called change_algorithm(type) in the C++ LSGrid
Python binding (env.backend._grid.change_algorithm(AlgorithmType.NR_KLU)),
consistent with pandapower’s algorithm= parameter and MATPOWER’s
pf.alg option.
Migration from old names
Before version 1.0.0, the enum values and class names used shorter names that
did not make the algorithm component explicit (KLU, SparseLU, DC,
etc.). These old names are kept as deprecated aliases in the Python enum
so that existing code continues to work, but they will be removed in a future
release:
Old name (deprecated) |
New canonical name |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The same renaming affects two other places that predate this convention:
the
lightsim2grid.solvermodule (with its own, olderSolverTypeenum, e.g.SolverType.KLU) is deprecated in favour oflightsim2grid.algorithm/AlgorithmType. ASolverTypevalue is still accepted wherever anAlgorithmTypeis expected (it is converted automatically, with aDeprecationWarning);LightSimBackend’ssolver_typeconstructor keyword (and itsset_solver_typemethod) are deprecated in favour ofalgo_type/set_algo_type, for the same reason:solver_typereads as if it selected the linear solver, when it in fact selects the powerflow algorithm (combined with a linear solver).solver_typeis still accepted and mapped toalgo_type; passing both with different values raises aBackendError.
See also
Available powerflow algorithms for performance comparisons and practical guidance on choosing an algorithm.