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
andlightsim2grid.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
andlightsim2grid.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
andlightsim2grid.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” 

GaussSeidel (SolverType.GaussSeidel) 

GaussSeidelSynch (SolverType.GaussSeidelSynch) 

DC (SolverType.DC) 

KLUDC (SolverType.KLUDC) 

NICSLUDC (SolverType.NICSLUDC) 

CKTSODC (SolverType.CKTSODC) 

SparseLUSingleSlack (SolverType.SparseLUSingleSlack) 

KLUSingleSlack (SolverType.KLUSingleSlack) 

NICSLUSingleSlack (SolverType.NICSLUSingleSlack) 

CKTSOSingleSlack (SolverType.CKTSOSingleSlack) 

SparseLU (SolverType.SparseLU) 

KLU (SolverType.KLU) 

NICSLU (SolverType.NICSLU) 

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(1e7) # 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
Classes:
This is a "wrapper" class that allows the user to perform some powerflow using the same API using different solvers. 

Alternative implementation of the DC solver, it uses the faster CKTSO solver available in the CKTSO library to solve for the DC voltage given the DC admitance matrix and the power injected at each nodes (requires a build from source). 

This classes implements the Newton Raphson algorithm, allowing for distributed slack and using the faster CKTSO solver available in the CKTSO library for the linear algebra (requires a build from source) 

This classes implements the Newton Raphson algorithm, the faster CKTSO solver available in the CKTSO library for the linear algebra. 

Default implementation of the DC solver, it uses the default Eigen sparse lu decomposition to solve for the DC voltage given the DC admitance matrix and the power injected at each nodes. 

This enum controls the error encountered in the solver 

Default implementation of the Fast Decoupled Powerflow solver (XB version: "alg 3" / "fdbx" in pypower / pandapower), it uses the fast CKTSO library for its underlying sparse matrix manipulation. 

Default implementation of the Fast Decoupled Powerflow solver (XB version: "alg 3" / "fdxb" in pypower / pandapower), it uses the fast KLU library for its underlying sparse matrix manipulation. 

Default implementation of the Fast Decoupled Powerflow solver (XB version: "alg 3" / "fdbx" in pypower / pandapower), it uses the fast NICSLU library for its underlying sparse matrix manipulation. 

Default implementation of the Fast Decoupled Powerflow solver (XB version: "alg 3" / "fdbx" in pypower / pandapower), it uses the default Eigen sparse lu decomposition for its underlying sparse matrix manipulation. 

Default implementation of the Fast Decoupled Powerflow solver (XB version: "alg 2" / "fdxb" in pypower / pandapower), it uses the fast CKTSO library for its underlying sparse matrix manipulation. 

Default implementation of the Fast Decoupled Powerflow solver (XB version: "alg 2" / "fdbx" in pypower / pandapower), it uses the fast KLU library for its underlying sparse matrix manipulation. 

Default implementation of the Fast Decoupled Powerflow solver (XB version: "alg 2" / "fdxb" in pypower / pandapower), it uses the fast NICSLU library for its underlying sparse matrix manipulation. 

Default implementation of the Fast Decoupled Powerflow solver (XB version: "alg 2" / "fdxb" in pypower / pandapower), it uses the default Eigen sparse lu decomposition for its underlying sparse matrix manipulation. 

Default implementation of the "Gauss Seidel" powerflow solver. 

Variant implementation of the "Gauss Seidel" powerflow solver, where every buses are updated at once (can be significantly faster than the 

Alternative implementation of the DC solver, it uses the faster KLU solver available in the SuiteSparse library to solve for the DC voltage given the DC admitance matrix and the power injected at each nodes (can be unavailable if you build lightsim2grid from source). 

This classes implements the Newton Raphson algorithm, allowing for distributed slack and using the faster KLU solver available in the SuiteSparse library for the linear algebra (can be unavailable if you build lightsim2grid from source). 

This classes implements the Newton Raphson algorithm,the faster KLU solver available in the SuiteSparse library for the linear algebra. 

Alternative implementation of the DC solver, it uses the faster NICSLU solver available in the NICSLU library to solve for the DC voltage given the DC admitance matrix and the power injected at each nodes (requires a build from source). 

This classes implements the Newton Raphson algorithm, allowing for distributed slack and using the faster NICSLU solver available in the NICSLU library for the linear algebra. 

This classes implements the Newton Raphson algorithm, the faster NICSLU solver available in the NICSLU library for the linear algebra. 

This enum controls the solver you want to use. 

This classes implements the Newton Raphson algorithm, allowing for distributed slack and using the default Eigen sparse solver available in Eigen for the linear algebra. 

This classes implements the Newton Raphson algorithm, using the default Eigen sparse solver available in Eigen for the linear algebra. 
 class lightsim2grid.solver.AnySolver
This is a “wrapper” class that allows the user to perform some powerflow using the same API using different solvers. It is not recommended to use this wrapper directly. It is rather a class exported to be compatible with the env_lightsim2grid.backend._grid.get_solver() method.
Examples
This class is built to be used like this:
import grid2op from lightsim2grid import LightSimBackend env_name = ... # eg. "l2rpn_case14_test" env = grid2op.make(env_name, backend=LightSimBackend()) anysolver = env.backend._grid.get_solver() anysolver.get_type() # type of solver currently used anysolver.get_J() # current Jacobian matrix, if available by the method
Methods:
converged
(self)Returns whether or not the solver has converged or not.
get_J
(self)Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_computation_time
(self)Return the total computation time (in second) spend in the solver when performing a powerflow.
get_error
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_fdpf_bx_lu
(self)INTERNAL
get_fdpf_xb_lu
(self)INTERNAL
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)TODO
get_timers_jacobian
(self)TODO
get_timers_ptdf_lodf
(self)TODO
get_type
(self)Retrieve the current solver used.
 converged(self: lightsim2grid_cpp.AnySolver) bool
Returns whether or not the solver has converged or not.
 get_J(self: lightsim2grid_cpp.AnySolver) scipy.sparse.csc_matrix[numpy.float64]
Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
Note
Depending on the underlying solver used (eg
lightsim2grid.solver.DCSolver
orlightsim2grid.solver.GaussSeidelSolver
) the jacobian matrix might be irrelevant and an attempt to use this function will throw a RuntimeError.
 get_V(self: lightsim2grid_cpp.AnySolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.AnySolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.AnySolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_computation_time(self: lightsim2grid_cpp.AnySolver) float
Return the total computation time (in second) spend in the solver when performing a powerflow.
This is equivalent to the timer_total_ returned value of the`***.get_timers()` function.
 get_error(self: lightsim2grid_cpp.AnySolver) lightsim2grid_cpp.ErrorType
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_fdpf_bx_lu(self: lightsim2grid_cpp.AnySolver) lightsim2grid_cpp.FDPF_BX_SparseLUSolver
INTERNAL
Warning
/!\ Internal, do not use unless you know what you are doing /!\
This is used as part of a dedicated code for
lightsim2grid.LightSimBackend.LightSimBackend
 get_fdpf_xb_lu(self: lightsim2grid_cpp.AnySolver) lightsim2grid_cpp.FDPF_XB_SparseLUSolver
INTERNAL
Warning
/!\ Internal, do not use unless you know what you are doing /!\
This is used as part of a dedicated code for
lightsim2grid.LightSimBackend.LightSimBackend
 get_nb_iter(self: lightsim2grid_cpp.AnySolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.AnySolver) tuple[float, float, float, float]
TODO
 get_timers_jacobian(self: lightsim2grid_cpp.AnySolver) tuple[float, float, float, float, float, float, float, float, float]
TODO
 get_timers_ptdf_lodf(self: lightsim2grid_cpp.AnySolver) tuple[float, float, float]
TODO
 get_type(self: lightsim2grid_cpp.AnySolver) lightsim2grid_cpp.SolverType
Retrieve the current solver used. This will return an instance of
lightsim2grid.solver.SolverType
indicating which is the underlying solver in use.This should be equivalent to
lightsim2grid.gridmodel.GridModel.get_solver_type()
 class lightsim2grid.solver.CKTSODCSolver
Alternative implementation of the DC solver, it uses the faster CKTSO solver available in the CKTSO library to solve for the DC voltage given the DC admitance matrix and the power injected at each nodes (requires a build from source).
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called CKTSODCYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.CKTSODC) after creation
LightSimBackend(solver_type=lightsim2grid.solver.CKTSODC) at creation time
Warning
This is a DC solver that uses the DC approximation. If you want to use this approximation, you need to specified it when you create the grid2op environment, for example with “param.ENV_DC=True”.
Otherwise, it is used internally to find good starting point to intialize the real AC solver.
Note
CKTSO is available at https://github.com/chenxm1986/cktso
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.CKTSODCSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.CKTSODCSolver) bool
Returns whether or not the solver has converged or not.
 get_V(self: lightsim2grid_cpp.CKTSODCSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.CKTSODCSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.CKTSODCSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.CKTSODCSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.CKTSODCSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.CKTSODCSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.CKTSODCSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.CKTSODCSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.CKTSOSolver
This classes implements the Newton Raphson algorithm, allowing for distributed slack and using the faster CKTSO solver available in the CKTSO library for the linear algebra (requires a build from source)
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called CKTSOYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.CKTSO) after creation
LightSimBackend(solver_type=lightsim2grid.solver.CKTSO) at creation time
Note
CKTSO is available at https://github.com/chenxm1986/cktso
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_J
(self)Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.CKTSOSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.CKTSOSolver) bool
Returns whether or not the solver has converged or not.
 get_J(self: lightsim2grid_cpp.CKTSOSolver) scipy.sparse.csc_matrix[numpy.float64]
Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
 get_V(self: lightsim2grid_cpp.CKTSOSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.CKTSOSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.CKTSOSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.CKTSOSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.CKTSOSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.CKTSOSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.CKTSOSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.CKTSOSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.CKTSOSolverSingleSlack
This classes implements the Newton Raphson algorithm, the faster CKTSO solver available in the CKTSO library for the linear algebra. It does not support the distributed slack, but can be slightly faster than the
lightsim2grid.solver.CKTSOSolver
.See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called CKTSOSingleSlackYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.CKTSOSingleSlack) after creation
LightSimBackend(solver_type=lightsim2grid.solver.CKTSOSingleSlack) at creation time
Note
CKTSO is available at https://github.com/chenxm1986/cktso
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_J
(self)Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.CKTSOSolverSingleSlack, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.CKTSOSolverSingleSlack) bool
Returns whether or not the solver has converged or not.
 get_J(self: lightsim2grid_cpp.CKTSOSolverSingleSlack) scipy.sparse.csc_matrix[numpy.float64]
Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
 get_V(self: lightsim2grid_cpp.CKTSOSolverSingleSlack) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.CKTSOSolverSingleSlack) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.CKTSOSolverSingleSlack) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.CKTSOSolverSingleSlack) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.CKTSOSolverSingleSlack) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.CKTSOSolverSingleSlack) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.CKTSOSolverSingleSlack) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.CKTSOSolverSingleSlack, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.DCSolver
Default implementation of the DC solver, it uses the default Eigen sparse lu decomposition to solve for the DC voltage given the DC admitance matrix and the power injected at each nodes.
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called DCYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.DC) after creation
LightSimBackend(solver_type=lightsim2grid.solver.DC) at creation time
Warning
This is a DC solver that uses the DC approximation. If you want to use this approximation, you need to specified it when you create the grid2op environment, for example with “param.ENV_DC=True”.
Otherwise, it is used internally to find good starting point to intialize the real AC solver.
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.DCSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.DCSolver) bool
Returns whether or not the solver has converged or not.
 get_V(self: lightsim2grid_cpp.DCSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.DCSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.DCSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.DCSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.DCSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.DCSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.DCSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.DCSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.ErrorType
This enum controls the error encountered in the solver
Members:
NoError : No error were encountered
SingularMatrix : The Jacobian matrix was singular and could not be factorized (most likely, the grid is not connex)
TooManyIterations : The solver reached the maximum number of iterations allowed
InifiniteValue : Some infinite values were encountered in the update vector (to update Vm or Va)
SolverAnalyze : The linear solver failed at the ‘analyze’ step (eg analyzePattern for Eigen, klu_analyze for KLU or Initialize for NICSLU
SolverFactor : The linear solver failed to factor the jacobian matrix (eg factorize for Eigen (first call), klu_factor for KLU or FactorizeMatrix for NICSLU (first call)
SolverReFactor : The linear solver failed to (re)factor the jacobian matrix (eg factorize for Eigen (later calls), klu_refactor for KLU or FactorizeMatrix for NICSLU (later calls)
SolverSolve : The linear solve failed to solve the linear system J.X = b (eg solve for Eigen, klu_solve for KLU or Solve for NICSLU
NotInitError : Attempt to perform some powerflow computation when the linear solver is not initiliazed
LicenseError : Impossible to use the linear solver as the license cannot be found (eg unable to locate the nicslu.lic file
Attributes:
 property name
 class lightsim2grid.solver.FDPF_BX_CKTSOSolver
Default implementation of the Fast Decoupled Powerflow solver (XB version: “alg 3” / “fdbx” in pypower / pandapower), it uses the fast CKTSO library for its underlying sparse matrix manipulation.
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called FDPF_CKTSOYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.FDPF_CKTSO) after creation
LightSimBackend(solver_type=lightsim2grid.solver.FDPF_CKTSO) at creation time
Warning
Use this solver requires a compilation of lightsim2grid from source (see readme) AND an appropriate license for cktso.
Note
CKTSO is available at https://github.com/chenxm1986/cktso
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.FDPF_BX_CKTSOSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.FDPF_BX_CKTSOSolver) bool
Returns whether or not the solver has converged or not.
 get_V(self: lightsim2grid_cpp.FDPF_BX_CKTSOSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.FDPF_BX_CKTSOSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.FDPF_BX_CKTSOSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.FDPF_BX_CKTSOSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.FDPF_BX_CKTSOSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.FDPF_BX_CKTSOSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.FDPF_BX_CKTSOSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.FDPF_BX_CKTSOSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.FDPF_BX_KLUSolver
Default implementation of the Fast Decoupled Powerflow solver (XB version: “alg 3” / “fdxb” in pypower / pandapower), it uses the fast KLU library for its underlying sparse matrix manipulation.
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called FDPF_KLUYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.FDPF_KLU) after creation
LightSimBackend(solver_type=lightsim2grid.solver.FDPF_KLU) at creation time
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.FDPF_BX_KLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.FDPF_BX_KLUSolver) bool
Returns whether or not the solver has converged or not.
 get_V(self: lightsim2grid_cpp.FDPF_BX_KLUSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.FDPF_BX_KLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.FDPF_BX_KLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.FDPF_BX_KLUSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.FDPF_BX_KLUSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.FDPF_BX_KLUSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.FDPF_BX_KLUSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.FDPF_BX_KLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.FDPF_BX_NICSLUSolver
Default implementation of the Fast Decoupled Powerflow solver (XB version: “alg 3” / “fdbx” in pypower / pandapower), it uses the fast NICSLU library for its underlying sparse matrix manipulation.
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called FDPF_NICSLUYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.FDPF_NICSLU) after creation
LightSimBackend(solver_type=lightsim2grid.solver.FDPF_NICSLU) at creation time
Warning
Use this solver requires a compilation of lightsim2grid from source (see readme) AND an appropriate license for nicslu.
Note
NICSLU is available at https://github.com/chenxm1986/nicslu
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.FDPF_BX_NICSLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.FDPF_BX_NICSLUSolver) bool
Returns whether or not the solver has converged or not.
 get_V(self: lightsim2grid_cpp.FDPF_BX_NICSLUSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.FDPF_BX_NICSLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.FDPF_BX_NICSLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.FDPF_BX_NICSLUSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.FDPF_BX_NICSLUSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.FDPF_BX_NICSLUSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.FDPF_BX_NICSLUSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.FDPF_BX_NICSLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.FDPF_BX_SparseLUSolver
Default implementation of the Fast Decoupled Powerflow solver (XB version: “alg 3” / “fdbx” in pypower / pandapower), it uses the default Eigen sparse lu decomposition for its underlying sparse matrix manipulation.
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called FDPF_SparseLUYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.FDPF_SparseLU) after creation
LightSimBackend(solver_type=lightsim2grid.solver.FDPF_SparseLU) at creation time
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
debug_get_Bp_python
(self)INTERNAL
debug_get_Bpp_python
(self)INTERNAL
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.FDPF_BX_SparseLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.FDPF_BX_SparseLUSolver) bool
Returns whether or not the solver has converged or not.
 debug_get_Bp_python(self: lightsim2grid_cpp.FDPF_BX_SparseLUSolver) scipy.sparse.csc_matrix[numpy.float64]
INTERNAL
Warning
/!\ Internal, do not use unless you know what you are doing /!\
This is used as part of a dedicated code for
lightsim2grid.LightSimBackend.LightSimBackend
 debug_get_Bpp_python(self: lightsim2grid_cpp.FDPF_BX_SparseLUSolver) scipy.sparse.csc_matrix[numpy.float64]
INTERNAL
Warning
/!\ Internal, do not use unless you know what you are doing /!\
This is used as part of a dedicated code for
lightsim2grid.LightSimBackend.LightSimBackend
 get_V(self: lightsim2grid_cpp.FDPF_BX_SparseLUSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.FDPF_BX_SparseLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.FDPF_BX_SparseLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.FDPF_BX_SparseLUSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.FDPF_BX_SparseLUSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.FDPF_BX_SparseLUSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.FDPF_BX_SparseLUSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.FDPF_BX_SparseLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.FDPF_XB_CKTSOSolver
Default implementation of the Fast Decoupled Powerflow solver (XB version: “alg 2” / “fdxb” in pypower / pandapower), it uses the fast CKTSO library for its underlying sparse matrix manipulation.
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called FDPF_CKTSOYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.FDPF_CKTSO) after creation
LightSimBackend(solver_type=lightsim2grid.solver.FDPF_CKTSO) at creation time
Warning
Use this solver requires a compilation of lightsim2grid from source (see readme) AND an appropriate license for cktso.
Note
CKTSO is available at https://github.com/chenxm1986/cktso
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.FDPF_XB_CKTSOSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.FDPF_XB_CKTSOSolver) bool
Returns whether or not the solver has converged or not.
 get_V(self: lightsim2grid_cpp.FDPF_XB_CKTSOSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.FDPF_XB_CKTSOSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.FDPF_XB_CKTSOSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.FDPF_XB_CKTSOSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.FDPF_XB_CKTSOSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.FDPF_XB_CKTSOSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.FDPF_XB_CKTSOSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.FDPF_XB_CKTSOSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.FDPF_XB_KLUSolver
Default implementation of the Fast Decoupled Powerflow solver (XB version: “alg 2” / “fdbx” in pypower / pandapower), it uses the fast KLU library for its underlying sparse matrix manipulation.
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called FDPF_KLUYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.FDPF_KLU) after creation
LightSimBackend(solver_type=lightsim2grid.solver.FDPF_KLU) at creation time
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.FDPF_XB_KLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.FDPF_XB_KLUSolver) bool
Returns whether or not the solver has converged or not.
 get_V(self: lightsim2grid_cpp.FDPF_XB_KLUSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.FDPF_XB_KLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.FDPF_XB_KLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.FDPF_XB_KLUSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.FDPF_XB_KLUSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.FDPF_XB_KLUSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.FDPF_XB_KLUSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.FDPF_XB_KLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.FDPF_XB_NICSLUSolver
Default implementation of the Fast Decoupled Powerflow solver (XB version: “alg 2” / “fdxb” in pypower / pandapower), it uses the fast NICSLU library for its underlying sparse matrix manipulation.
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called FDPF_NICSLUYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.FDPF_NICSLU) after creation
LightSimBackend(solver_type=lightsim2grid.solver.FDPF_NICSLU) at creation time
Warning
Use this solver requires a compilation of lightsim2grid from source (see readme) AND an appropriate license for nicslu.
Note
NICSLU is available at https://github.com/chenxm1986/nicslu
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.FDPF_XB_NICSLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.FDPF_XB_NICSLUSolver) bool
Returns whether or not the solver has converged or not.
 get_V(self: lightsim2grid_cpp.FDPF_XB_NICSLUSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.FDPF_XB_NICSLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.FDPF_XB_NICSLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.FDPF_XB_NICSLUSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.FDPF_XB_NICSLUSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.FDPF_XB_NICSLUSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.FDPF_XB_NICSLUSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.FDPF_XB_NICSLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.FDPF_XB_SparseLUSolver
Default implementation of the Fast Decoupled Powerflow solver (XB version: “alg 2” / “fdxb” in pypower / pandapower), it uses the default Eigen sparse lu decomposition for its underlying sparse matrix manipulation.
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called FDPF_SparseLUYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.FDPF_SparseLU) after creation
LightSimBackend(solver_type=lightsim2grid.solver.FDPF_SparseLU) at creation time
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
debug_get_Bp_python
(self)INTERNAL
debug_get_Bpp_python
(self)INTERNAL
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.FDPF_XB_SparseLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.FDPF_XB_SparseLUSolver) bool
Returns whether or not the solver has converged or not.
 debug_get_Bp_python(self: lightsim2grid_cpp.FDPF_XB_SparseLUSolver) scipy.sparse.csc_matrix[numpy.float64]
INTERNAL
Warning
/!\ Internal, do not use unless you know what you are doing /!\
This is used as part of a dedicated code for
lightsim2grid.LightSimBackend.LightSimBackend
 debug_get_Bpp_python(self: lightsim2grid_cpp.FDPF_XB_SparseLUSolver) scipy.sparse.csc_matrix[numpy.float64]
INTERNAL
Warning
/!\ Internal, do not use unless you know what you are doing /!\
This is used as part of a dedicated code for
lightsim2grid.LightSimBackend.LightSimBackend
 get_V(self: lightsim2grid_cpp.FDPF_XB_SparseLUSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.FDPF_XB_SparseLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.FDPF_XB_SparseLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.FDPF_XB_SparseLUSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.FDPF_XB_SparseLUSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.FDPF_XB_SparseLUSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.FDPF_XB_SparseLUSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.FDPF_XB_SparseLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.GaussSeidelSolver
Default implementation of the “Gauss Seidel” powerflow solver. We do not recommend to use it as the Newton Raphson based solvers are usually much (much) faster.
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called GaussSeidelYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.GaussSeidel) after creation
LightSimBackend(solver_type=lightsim2grid.solver.GaussSeidel) at creation time
Warning
It currently does not support distributed slack.
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.GaussSeidelSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.GaussSeidelSolver) bool
Returns whether or not the solver has converged or not.
 get_V(self: lightsim2grid_cpp.GaussSeidelSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.GaussSeidelSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.GaussSeidelSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.GaussSeidelSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.GaussSeidelSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.GaussSeidelSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.GaussSeidelSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.GaussSeidelSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.GaussSeidelSynchSolver
Variant implementation of the “Gauss Seidel” powerflow solver, where every buses are updated at once (can be significantly faster than the
lightsim2grid.solver.GaussSeidelSolver
for larger grid). We still do not recommend to use it as the Newton Raphson based solvers are usually much (much) faster.See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it called GaussSeidelSynchYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.GaussSeidelSynch) after creation
LightSimBackend(solver_type=lightsim2grid.solver.GaussSeidelSynch) at creation time
Warning
It currently does not support distributed slack.
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.GaussSeidelSynchSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.GaussSeidelSynchSolver) bool
Returns whether or not the solver has converged or not.
 get_V(self: lightsim2grid_cpp.GaussSeidelSynchSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.GaussSeidelSynchSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.GaussSeidelSynchSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.GaussSeidelSynchSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.GaussSeidelSynchSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.GaussSeidelSynchSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.GaussSeidelSynchSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.GaussSeidelSynchSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.KLUDCSolver
Alternative implementation of the DC solver, it uses the faster KLU solver available in the SuiteSparse library to solve for the DC voltage given the DC admitance matrix and the power injected at each nodes (can be unavailable if you build lightsim2grid from source).
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called KLUDCYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.KLUDC) after creation
LightSimBackend(solver_type=lightsim2grid.solver.KLUDC) at creation time
Warning
This is a DC solver that uses the DC approximation. If you want to use this approximation, you need to specified it when you create the grid2op environment, for example with “param.ENV_DC=True”.
Otherwise, it is used internally to find good starting point to intialize the real AC solver.
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.KLUDCSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.KLUDCSolver) bool
Returns whether or not the solver has converged or not.
 get_V(self: lightsim2grid_cpp.KLUDCSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.KLUDCSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.KLUDCSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.KLUDCSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.KLUDCSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.KLUDCSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.KLUDCSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.KLUDCSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.KLUSolver
This classes implements the Newton Raphson algorithm, allowing for distributed slack and using the faster KLU solver available in the SuiteSparse library for the linear algebra (can be unavailable if you build lightsim2grid from source). It is usually faster than the
lightsim2grid.solver.SparseLUSolver
.See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called KLUYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.KLU) after creation
LightSimBackend(solver_type=lightsim2grid.solver.KLU) at creation time
Note
This is the default solver used when a distributed slack bus is detected (when it’s available, otherwise see
lightsim2grid.solver.SparseLUSolver
).Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_J
(self)Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.KLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.KLUSolver) bool
Returns whether or not the solver has converged or not.
 get_J(self: lightsim2grid_cpp.KLUSolver) scipy.sparse.csc_matrix[numpy.float64]
Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
 get_V(self: lightsim2grid_cpp.KLUSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.KLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.KLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.KLUSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.KLUSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.KLUSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.KLUSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.KLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.KLUSolverSingleSlack
This classes implements the Newton Raphson algorithm,the faster KLU solver available in the SuiteSparse library for the linear algebra. It does not support the distributed slack, but can be slightly faster than the
lightsim2grid.solver.KLUSolver
.See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called KLUSingleSlackYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.KLUSingleSlack) after creation
LightSimBackend(solver_type=lightsim2grid.solver.KLUSingleSlack) at creation time
Note
This is the default solver used when available.
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_J
(self)Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.KLUSolverSingleSlack, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.KLUSolverSingleSlack) bool
Returns whether or not the solver has converged or not.
 get_J(self: lightsim2grid_cpp.KLUSolverSingleSlack) scipy.sparse.csc_matrix[numpy.float64]
Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
 get_V(self: lightsim2grid_cpp.KLUSolverSingleSlack) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.KLUSolverSingleSlack) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.KLUSolverSingleSlack) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.KLUSolverSingleSlack) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.KLUSolverSingleSlack) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.KLUSolverSingleSlack) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.KLUSolverSingleSlack) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.KLUSolverSingleSlack, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.NICSLUDCSolver
Alternative implementation of the DC solver, it uses the faster NICSLU solver available in the NICSLU library to solve for the DC voltage given the DC admitance matrix and the power injected at each nodes (requires a build from source).
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called NICSLUDCYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.NICSLUDC) after creation
LightSimBackend(solver_type=lightsim2grid.solver.NICSLUDC) at creation time
Warning
This is a DC solver that uses the DC approximation. If you want to use this approximation, you need to specified it when you create the grid2op environment, for example with “param.ENV_DC=True”.
Otherwise, it is used internally to find good starting point to intialize the real AC solver.
Warning
Use this solver requires a compilation of lightsim2grid from source (see readme) AND an appropriate license for nicslu.
Note
NICSLU is available at https://github.com/chenxm1986/nicslu
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.NICSLUDCSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.NICSLUDCSolver) bool
Returns whether or not the solver has converged or not.
 get_V(self: lightsim2grid_cpp.NICSLUDCSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.NICSLUDCSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.NICSLUDCSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.NICSLUDCSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.NICSLUDCSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.NICSLUDCSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.NICSLUDCSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.NICSLUDCSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.NICSLUSolver
This classes implements the Newton Raphson algorithm, allowing for distributed slack and using the faster NICSLU solver available in the NICSLU library for the linear algebra. It is usually faster than the
lightsim2grid.solver.SparseLUSolver
. (requires a build from source)See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called NICSLUYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.NICSLU) after creation
LightSimBackend(solver_type=lightsim2grid.solver.NICSLU) at creation time
Warning
Use this solver requires a compilation of lightsim2grid from source (see readme) AND an appropriate license for nicslu.
Note
NICSLU is available at https://github.com/chenxm1986/nicslu
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_J
(self)Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.NICSLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.NICSLUSolver) bool
Returns whether or not the solver has converged or not.
 get_J(self: lightsim2grid_cpp.NICSLUSolver) scipy.sparse.csc_matrix[numpy.float64]
Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
 get_V(self: lightsim2grid_cpp.NICSLUSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.NICSLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.NICSLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.NICSLUSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.NICSLUSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.NICSLUSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.NICSLUSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.NICSLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.NICSLUSolverSingleSlack
This classes implements the Newton Raphson algorithm, the faster NICSLU solver available in the NICSLU library for the linear algebra. It does not support the distributed slack, but can be slightly faster than the
lightsim2grid.solver.NICSLUSolver
.See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called NICSLUSingleSlackYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.NICSLUSingleSlack) after creation
LightSimBackend(solver_type=lightsim2grid.solver.NICSLUSingleSlack) at creation time
Warning
Use this solver requires a compilation of lightsim2grid from source (see readme) AND an appropriate license for nicslu.
Note
NICSLU is available at https://github.com/chenxm1986/nicslu
Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_J
(self)Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.NICSLUSolverSingleSlack, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.NICSLUSolverSingleSlack) bool
Returns whether or not the solver has converged or not.
 get_J(self: lightsim2grid_cpp.NICSLUSolverSingleSlack) scipy.sparse.csc_matrix[numpy.float64]
Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
 get_V(self: lightsim2grid_cpp.NICSLUSolverSingleSlack) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.NICSLUSolverSingleSlack) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.NICSLUSolverSingleSlack) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.NICSLUSolverSingleSlack) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.NICSLUSolverSingleSlack) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.NICSLUSolverSingleSlack) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.NICSLUSolverSingleSlack) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.NICSLUSolverSingleSlack, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.SolverType
This enum controls the solver you want to use.
Members:
GaussSeidel : denotes the
lightsim2grid.solver.GaussSeidelSolver
GaussSeidelSynch : denotes the
lightsim2grid.solver.GaussSeidelSynchSolver
SparseLU : denotes the
lightsim2grid.solver.SparseLUSolver
SparseLUSingleSlack : denotes the
lightsim2grid.solver.SparseLUSolverSingleSlack
DC : denotes the
lightsim2grid.solver.DCSolver
KLU : denotes the
lightsim2grid.solver.KLUSolver
KLUSingleSlack : denotes the
lightsim2grid.solver.KLUSolverSingleSlack
KLUDC : denotes the
lightsim2grid.solver.KLUDCSolver
NICSLU : denotes the
lightsim2grid.solver.NICSLUSolver
NICSLUSingleSlack : denotes the
lightsim2grid.solver.NICSLUSolverSingleSlack
NICSLUDC : denotes the
lightsim2grid.solver.NICSLUDCSolver
CKTSO : denotes the
lightsim2grid.solver.CKTSOSolver
CKTSOSingleSlack : denotes the
lightsim2grid.solver.CKTSOSolverSingleSlack
CKTSODC : denotes the
lightsim2grid.solver.CKTSODCSolver
FDPF_XB_SparseLU : denotes the
lightsim2grid.solver.FDPF_XB_SparseLUSolver
FDPF_BX_SparseLU : denotes the
lightsim2grid.solver.FDPF_BX_SparseLUSolver
FDPF_XB_KLU : denotes the
lightsim2grid.solver.FDPF_XB_KLUSolver
FDPF_BX_KLU : denotes the
lightsim2grid.solver.FDPF_BX_KLUSolver
FDPF_XB_NICSLU : denotes the
lightsim2grid.solver.FDPF_XB_NICSLUSolver
FDPF_BX_NICSLU : denotes the
lightsim2grid.solver.FDPF_BX_NICSLUSolver
FDPF_XB_CKTSO : denotes the
lightsim2grid.solver.FDPF_XB_CKTSOSolver
FDPF_BX_CKTSO : denotes the
lightsim2grid.solver.FDPF_BX_CKTSOSolver
Attributes:
 property name
 class lightsim2grid.solver.SparseLUSolver
This classes implements the Newton Raphson algorithm, allowing for distributed slack and using the default Eigen sparse solver available in Eigen for the linear algebra.
See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called SparseLU.You can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.SparseLU) after creation
LightSimBackend(solver_type=lightsim2grid.solver.SparseLU) at creation time
Note
Available on all plateform, this is the default solver used when
lightsim2grid.solver.KLUSolverSingleSlack
is not found (when a “single slack” is detected).Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_J
(self)Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.SparseLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.SparseLUSolver) bool
Returns whether or not the solver has converged or not.
 get_J(self: lightsim2grid_cpp.SparseLUSolver) scipy.sparse.csc_matrix[numpy.float64]
Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
 get_V(self: lightsim2grid_cpp.SparseLUSolver) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.SparseLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.SparseLUSolver) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.SparseLUSolver) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.SparseLUSolver) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.SparseLUSolver) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.SparseLUSolver) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.SparseLUSolver, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 class lightsim2grid.solver.SparseLUSolverSingleSlack
This classes implements the Newton Raphson algorithm, using the default Eigen sparse solver available in Eigen for the linear algebra. It does not support the distributed slack, but can be slightly faster than the
lightsim2grid.solver.SparseLUSolver
.See Even more advanced usage for more information on how to use it.
Note
In the enum
lightsim2grid.solver.SolverType
, it is called SparseLUSingleSlackYou can use it with:
env_lightsim.backend.set_solver_type(lightsim2grid.solver.SparseLUSingleSlack) after creation
LightSimBackend(solver_type=lightsim2grid.solver.SparseLUSingleSlack) at creation time
Note
Available on all plateform, this is the default solver used when a distributed slack bus is detected and
lightsim2grid.solver.SolverType.KLUSolver
is not found.Methods:
compute_pf
(self, arg0, arg1, arg2, arg3, ...)Function used to perform a powerflow.
converged
(self)Returns whether or not the solver has converged or not.
get_J
(self)Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
get_V
(self)Returns the complex voltage for each buses as a numpy vector of complex number.
get_Va
(self)Returns the voltage angles for each buses as a numpy vector of real number.
get_Vm
(self)Returns the voltage magnitude for each buses as a numpy vector of real number.
get_error
(self)Returns the error code (as an integer) encountered by the solver (0 = no error).
get_nb_iter
(self)Returns the number of iterations effectively performed by the solver (> 0 integer).
get_timers
(self)Returns information about the time taken by some part of the solvers (in seconds)
reset
(self)Reset the solver.
solve
(self, arg0, arg1, arg2, arg3, arg4, ...)Function used to perform a powerflow.
 compute_pf(self: lightsim2grid_cpp.SparseLUSolverSingleSlack, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.
 converged(self: lightsim2grid_cpp.SparseLUSolverSingleSlack) bool
Returns whether or not the solver has converged or not.
 get_J(self: lightsim2grid_cpp.SparseLUSolverSingleSlack) scipy.sparse.csc_matrix[numpy.float64]
Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.
 get_V(self: lightsim2grid_cpp.SparseLUSolverSingleSlack) numpy.ndarray[numpy.complex128[m, 1]]
Returns the complex voltage for each buses as a numpy vector of complex number.
 get_Va(self: lightsim2grid_cpp.SparseLUSolverSingleSlack) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage angles for each buses as a numpy vector of real number.
 get_Vm(self: lightsim2grid_cpp.SparseLUSolverSingleSlack) numpy.ndarray[numpy.float64[m, 1]]
Returns the voltage magnitude for each buses as a numpy vector of real number.
 get_error(self: lightsim2grid_cpp.SparseLUSolverSingleSlack) lightsim2grid_cpp.ErrorType
Returns the error code (as an integer) encountered by the solver (0 = no error). TODO DOC explain better
 get_nb_iter(self: lightsim2grid_cpp.SparseLUSolverSingleSlack) int
Returns the number of iterations effectively performed by the solver (> 0 integer).
 get_timers(self: lightsim2grid_cpp.SparseLUSolverSingleSlack) tuple[float, float, float, float]
Returns information about the time taken by some part of the solvers (in seconds)
Times are measured in seconds using the c++ steady_clock clock.
 Returns:
timer_Fx_ (
float
) – Time spent to compute the mismatch at the KCL for each bus (both for active and reactive power)timer_solve_ (
float
) – Total time spent in the underlying linear solvertimer_check_ (
float
) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerancetimer_total_ (
float
) – Total time spent in the solver
 reset(self: lightsim2grid_cpp.SparseLUSolverSingleSlack) None
Reset the solver. In this context this will clear all data used by the solver. It is mandatory to do it each time the Ybus matrix (or any of the pv, or pq or ref indices vector are changed).
 solve(self: lightsim2grid_cpp.SparseLUSolverSingleSlack, arg0: scipy.sparse.csc_matrix[numpy.complex128], arg1: numpy.ndarray[numpy.complex128[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.int32[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]], arg7: int, arg8: float) bool
Function used to perform a powerflow.
see section Even more advanced usage for more information about these.
Warning
There are strong assumption made on the validity of the parameters provided. Please have a look at the section Even more advanced usage for more details about this.
If a non compliant state is provided, it might result in crash of the python virtual machine (session terminates with error like segfault) and there is absolutely no way to do anything and any data not saved on the hard drive will be lost.
 Parameters:
Ybus (
scipy.sparse
matrix, CSC format) – The admittance matrix of the systemV (
numpy.ndarray
, vector of complex numbers) – The initial guess (and final result) for the complex angle at each bus (it is modified during the computation :)Sbus (
numpy.ndarray
, vector of complex numbers) – Complex power injected at each busslack_ids (
numpy.ndarray
, vector of integers) – Gives all the ids of the buses participating to the distributed slack bus. [might be ignore by some solvers]slack_weights (
numpy.ndarray
, vector of real numbers) – For each bus taking part in the distributed slack, it gives its coefficientpv (
numpy.ndarray
, vector of integers) – Index of the pv busespq (
numpy.ndarray
, vector of integers) – Index of the pq busesmax_iter (
int
) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]tol (
float
) – Solver tolerance (eg 1e8) [might be ignore by some solvers]
Examples
Some detailed examples are provided in section Even more advanced usage of the documentation.