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

For now, lightsim2grid ships with at most TODO DOC fully working (and tested) solvers:

  • LS+GS (LightSimBackend+Gauss Seidel): the grid2op backend based on lightsim2grid that uses the “Gauss Seidel” solver to compute the powerflows.

  • LS+GS S (LightSimBackend+Gauss Seidel Synchronous): the grid2op backend based on lightsim2grid that uses a variant of the “Gauss Seidel” method to compute the powerflows.

  • LS+SLU (Newton Raphson+SparseLU): the grid2op backend based on lightsim2grid that uses the “Newton Raphson” algorithm coupled with the linear solver “SparseLU” from the Eigen c++ library (available on all platform). This solver supports distributed slack bus.

  • LS+SLU (single) (Newton Raphson+SparseLU): same as above but this solver does not support distributed slack bus and can thus be slightly faster.

  • LS+KLU (Newton Raphson+KLU): he grid2op backend based on lightsim2grid that uses the “Newton Raphson” algorithm coupled with the linear solver “KLU” from the SuiteSparse C package. This solver supports distributed slack bus.

  • LS+KLU (single) (Newton Raphson+KLU): same as above but this solver does not support distributed slack bus and can thus be slightly faster.

  • LS+NICSLU (Newton Raphson+NICSLU): he grid2op backend based on lightsim2grid that uses the “Newton Raphson” algorithm coupled with the linear solver “NICSLU”. [NB NICSLU is a free software but not open source, in order to use it with lightsim2grid, you need to install lightsim2grid from source for such solver]

  • LS+NICSLU (single) (Newton Raphson+NICSLU): same as above but this solver does not support distributed slack bus and can thus be slightly faster.

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.

A concrete example of how to change the solver in this backend is:

import grid2op
import lightsim2grid
from lightsim2grid import LightSimBackend

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

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

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

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

For the list of availbale solvers, you can consult the “enum” lightsim2grid.solver.SolverType.

Detailed usage

Classes:

AnySolver

This is a "wrapper" class that allows the user to perform some powerflow using the same API using different solvers.

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.

ErrorType

This enum controls the error encountered in the solver

GaussSeidelSolver

Default implementation of the "Gauss Seidel" powerflow 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).

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).

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).

KLUSolverSingleSlack

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

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).

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.

NICSLUSolverSingleSlack

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

SolverType

This enum controls the solver you want to use.

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.

SparseLUSolverSingleSlack

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_nb_iter(self)

Returns the number of iterations effectively performed by the solver (> 0 integer).

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 or lightsim2grid.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_nb_iter(self: lightsim2grid_cpp.AnySolver) int

Returns the number of iterations effectively performed by the solver (> 0 integer).

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.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 referred to by the DC member (eg env_lightsim.backend.set_solver_type(lightsim2grid.solver.SolverType.DC)).

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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 solver

  • timer_check_ (float) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerance

  • timer_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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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:

name

property name
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 faster.

See Even more advanced usage for more information on how to use it.

Note

In the enum lightsim2grid.solver.SolverType, it is referred to by the GaussSeidel member (eg env_lightsim.backend.set_solver_type(lightsim2grid.solver.SolverType.GaussSeidel)).

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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 solver

  • timer_check_ (float) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerance

  • timer_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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 faster.

See Even more advanced usage for more information on how to use it.

Note

In the enum lightsim2grid.solver.SolverType, it is referred to by the GaussSeidelSynch member (eg env_lightsim.backend.set_solver_type(lightsim2grid.solver.SolverType.GaussSeidelSynch)).

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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 solver

  • timer_check_ (float) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerance

  • timer_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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 referred to by the KLUDC member (eg env_lightsim.backend.set_solver_type(lightsim2grid.solver.SolverType.KLUDC)).

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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 solver

  • timer_check_ (float) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerance

  • timer_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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 referred to by the KLU member (eg env_lightsim.backend.set_solver_type(lightsim2grid.solver.SolverType.KLU)).

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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 solver

  • timer_check_ (float) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerance

  • timer_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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 referred to by the KLUSingleSlack member (eg env_lightsim.backend.set_solver_type(lightsim2grid.solver.SolverType.KLUSingleSlack)).

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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 solver

  • timer_check_ (float) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerance

  • timer_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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 referred to by the NICSLUSingleSlack member (eg env_lightsim.backend.set_solver_type(lightsim2grid.solver.SolverType.NICSLUSingleSlack)).

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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 solver

  • timer_check_ (float) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerance

  • timer_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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 referred to by the NICSLU member (eg env_lightsim.backend.set_solver_type(lightsim2grid.solver.SolverType.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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 solver

  • timer_check_ (float) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerance

  • timer_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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 referred to by the NICSLUSingleSlack member (eg env_lightsim.backend.set_solver_type(lightsim2grid.solver.SolverType.NICSLUSingleSlack)).

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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 solver

  • timer_check_ (float) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerance

  • timer_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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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

Attributes:

name

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 referred to by the SparseLU member (eg env_lightsim.backend.set_solver_typelightsim2grid.solver.SolverType.SparseLU)).

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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 solver

  • timer_check_ (float) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerance

  • timer_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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 referred to by the SparseLUSolverSingleSlack member (eg env_lightsim.backend.set_solver_type(lightsim2grid.solver.SolverType.SparseLUSolverSingleSlack)).

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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [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 solver

  • timer_check_ (float) – Time spent in checking whether or not the mismatch of the KCL met the specified tolerance

  • timer_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 system

  • V (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 bus

  • slack_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 coefficient

  • pv (numpy.ndarray, vector of integers) – Index of the pv buses

  • pq (numpy.ndarray, vector of integers) – Index of the pq buses

  • max_iter (int) – Maximum number of iterations performed by the solver. [might be ignore by some solvers]

  • tol (float) – Solver tolerance (eg 1e-8) [might be ignore by some solvers]

Examples

Some detailed examples are provided in section Even more advanced usage of the documentation.