GridModel module (doc in progress)

The main class of the lightsim2grid python package is the GridModel class, that is a python class created from the the c++ GridModel (thanks fo pybind11).

This class basically represents a powergrid (what elements it is made for, their electro technical properties etc.)

To create such class, for now the only way is to get it from a pandapower grid (and it does not model every elements there !)

For example, you can init it like (NOT RECOMMENDED, though sometimes needed):

from lightsim2grid.gridmodel import init
pp_net = ...  # any pandapower grid eg. pp_net = pn.case118()

lightsim_grid_model = init(pp_net)  # some warnings might be issued as well as some warnings

A better initialization is through the lightsim2grid.LightSimBackend.LightSimBackend class:

from lightsim2grid.gridmodel import init
# create a lightsim2grid "gridmodel"
env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())
grid_model = env.backend._grid

Warning

We do not recommend to manipulate directly the lightsim2grid.gridmodel.GridModel directy, but to use it via the backend class. This is much more tested this way.

Elements modeled

Generators (standard)

class lightsim2grid.elements.DataGen

This class allows to iterate through the generators of the lightsim2grid.gridmodel.GridModel easily, as if they were in a python list.

In lightsim2grid they are modeled as “pv” meanings you give the active production setpoint and voltage magnitude setpoint (see lightsim2grid.elements.DataSGen for more exotic PQ generators).

The active production value setpoint are modified only for the generators participating to the slack buses (see lightsim2grid.elements.GenInfo.is_slack and lightsim2grid.elements.GenInfo.slack_weight).

Generators are modeled as in pandapower and can be represented a the pandapower generators .

Examples

import grid2op
from lightsim2grid import LightSimBackend

env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())

grid_model = env.backend._grid

for gen in grid_model.get_generators():
    # do something with gen !
    gen.bus_id

print(f"There are {len(grid_model.get_generators())} generators on the grid.")

first_generator = grid_model.get_generators()[0]

You can have a look at lightsim2grid.elements.GenInfo for properties of these elements.

class lightsim2grid.elements.GenInfo

This class represents what you get from retrieving some elements from lightsim2grid.elements.DataGen

It allows to read information from each generator of the powergrid.

Warning

Data ca only be accessed from this element. You cannot modify (yet) the grid using this class.

Examples

import grid2op
from lightsim2grid import LightSimBackend

env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())

grid_model = env.backend._grid

first_generator = grid_model.get_generators()[0]  # first generator is a `GenInfo`

for gen in grid_model.get_generators():
    # gen is a `GenInfo`
    gen.bus_id

Attributes:

bus_id

Get the bus id (as an integer) at which each element of a lightsim2grid.gridmodel.GridModel is connected.

connected

Get the status (True = connected, False = disconnected) of each element of a lightsim2grid.gridmodel.GridModel

has_res

This property specify whether or not a given element contains some "result" information.

id

Get the ideas of the element.

is_slack

Tells whether or not this generator paticipated to the distributed slack bus.

max_q_mvar

Maximum reactive value that can be produced / absorbed by this generator given MVAr.

min_q_mvar

Minimum reactive value that can be produced / absorbed by this generator given MVAr.

res_p_mw

Get the active production (or consumption) in MW for element of the grid supporting this feature.

res_q_mvar

Get the reactive production (or consumption) in MVAr for element of the grid supporting this feature.

res_theta_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this object is connected.

res_v_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this object is connected.

slack_weight

For each generators, gives the participation (for the distributed slack) of this particular generator.

target_p_mw

Get the active production (or consumption) setpoint in MW for element of the grid supporting this feature.

target_vm_pu

Get the voltage magnitude setpoint (in pair unit and NOT in kV) for each element of the grid supporting this feature.

property bus_id

Get the bus id (as an integer) at which each element of a lightsim2grid.gridmodel.GridModel is connected. If -1 is returned it means that the object is disconnected.

property connected

Get the status (True = connected, False = disconnected) of each element of a lightsim2grid.gridmodel.GridModel

property has_res

This property specify whether or not a given element contains some “result” information. If set to True then the fields starting with res_ (eg res_p_mw) are filled otherwise they are initialized with an arbitrary (and meaningless) value.

property id

Get the ideas of the element. Ids are integer from 0 to n-1 (if n denotes the number of such elements on the grid.)

Examples

We give the example only for generators, but it works similarly for every other types of objects in a lightsim2grid.gridmodel.GridModel.

This gives something like:

import grid2op
from lightsim2grid import LightSimBackend

env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())

grid_model = env.backend._grid

first_gen = grid_model.get_generators()[0]  # or get_loads for loads, etc.
first_gen.id  # should be 0
property is_slack

Tells whether or not this generator paticipated to the distributed slack bus.

Note

Depending on the solver used, it is possible that a generator we asked to participate to the distributed slack bus do not participate to it (for example if there is a more than one generator where is_slack is True but the model used to computed the powerflow do not support distributed slack buses - eg lightsim2grid.solver.SparseLUSolverSingleSlack)

This is why we recommend to use the (slower) but more accurate lightsim2grid.solver.SparseLUSolver or lightsim2grid.solver.KLUSolver for example.

property max_q_mvar

Maximum reactive value that can be produced / absorbed by this generator given MVAr.

Note

This is for now not taken into account by the solver. It is only used in lightsim2grid.gridmodel.check_solution() if check_q_limits is set to True

property min_q_mvar

Minimum reactive value that can be produced / absorbed by this generator given MVAr.

Note

This is for now not taken into account by the solver. It is only used in lightsim2grid.gridmodel.check_solution() if check_q_limits is set to True

property res_p_mw

Get the active production (or consumption) in MW for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_q_mvar

Get the reactive production (or consumption) in MVAr for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_theta_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this object is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_theta_deg”

property res_v_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this object is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_v_kv”

property slack_weight

For each generators, gives the participation (for the distributed slack) of this particular generator.

Note

Weights do not scale to one for this variable thus this number has no meaning by itself and should be compared with the others.

property target_p_mw

Get the active production (or consumption) setpoint in MW for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

property target_vm_pu

Get the voltage magnitude setpoint (in pair unit and NOT in kV) for each element of the grid supporting this feature.

Warning

This is given in “pair unit” (pu) system and not in kilo Volt (kV) !

Static Generators (more exotic)

class lightsim2grid.elements.DataSGen

This class allows to iterate through the static generators of the lightsim2grid.gridmodel.GridModel easily, as if they were in a python list.

In lightsim2grid they are two types of generators the more standard PV generators (see lightsim2grid.elements.DataGen). These are more exotic generators known as PQ, where you give the active production value and reactive production value. It’s basically like loads, but using the generator convention (if the value is positive, it means power is taken from the grid to the element)

They cannot participate to the distributed slack bus.

Static generators are modeled as in pandapower and can be represented a the pandapower static generators .

Examples

import grid2op
from lightsim2grid import LightSimBackend

# create a lightsim2grid "gridmodel"
env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())
grid_model = env.backend._grid

# manipulate the static generators
for sgen in grid_model.get_static_generators():
    # do something with sgen !
    sgen.bus_id

print(f"There are {len(grid_model.get_static_generators())} static generators on the grid.")

first_static_generator = grid_model.get_static_generators()[0]

You can have a look at lightsim2grid.elements.SGenInfo for properties of these elements.

class lightsim2grid.elements.SGenInfo

This class represents what you get from retrieving some elements from lightsim2grid.elements.DataSGen

It allows to read information from each static generator of the powergrid.

Warning

Data ca only be accessed from this element. You cannot modify (yet) the grid using this class.

Examples

import grid2op
from lightsim2grid import LightSimBackend

# create a lightsim2grid "gridmodel"
env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())
grid_model = env.backend._grid

# do something with the static generators
first_static_generator = grid_model.get_static_generators()[0]  # first static generator is a `SGenInfo`

for sgen in grid_model.get_static_generators():
    # sgen is a `SGenInfo`
    sgen.bus_id

Attributes:

bus_id

Get the bus id (as an integer) at which each element of a lightsim2grid.gridmodel.GridModel is connected.

connected

Get the status (True = connected, False = disconnected) of each element of a lightsim2grid.gridmodel.GridModel

has_res

This property specify whether or not a given element contains some "result" information.

id

Get the ideas of the element.

max_p_mw

Maximum active value that can be produced / absorbed by this generator given in MW.

max_q_mvar

Maximum reactive value that can be produced / absorbed by this generator given MVAr.

min_p_mw

Minimum active value that can be produced / absorbed by this generator given in MW.

min_q_mvar

Minimum reactive value that can be produced / absorbed by this generator given MVAr.

res_p_mw

Get the active production (or consumption) in MW for element of the grid supporting this feature.

res_q_mvar

Get the reactive production (or consumption) in MVAr for element of the grid supporting this feature.

res_theta_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this object is connected.

res_v_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this object is connected.

target_p_mw

Get the active production (or consumption) setpoint in MW for element of the grid supporting this feature.

target_q_mvar

Get the reactive production (or consumption) setpoint in MVAr for element of the grid supporting this feature.

property bus_id

Get the bus id (as an integer) at which each element of a lightsim2grid.gridmodel.GridModel is connected. If -1 is returned it means that the object is disconnected.

property connected

Get the status (True = connected, False = disconnected) of each element of a lightsim2grid.gridmodel.GridModel

property has_res

This property specify whether or not a given element contains some “result” information. If set to True then the fields starting with res_ (eg res_p_mw) are filled otherwise they are initialized with an arbitrary (and meaningless) value.

property id

Get the ideas of the element. Ids are integer from 0 to n-1 (if n denotes the number of such elements on the grid.)

Examples

We give the example only for generators, but it works similarly for every other types of objects in a lightsim2grid.gridmodel.GridModel.

This gives something like:

import grid2op
from lightsim2grid import LightSimBackend

env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())

grid_model = env.backend._grid

first_gen = grid_model.get_generators()[0]  # or get_loads for loads, etc.
first_gen.id  # should be 0
property max_p_mw

Maximum active value that can be produced / absorbed by this generator given in MW.

Note

This is for now not taken into account by the solver. It is only used in lightsim2grid.gridmodel.check_solution() if check_q_limits is set to True

property max_q_mvar

Maximum reactive value that can be produced / absorbed by this generator given MVAr.

Note

This is for now not taken into account by the solver. It is only used in lightsim2grid.gridmodel.check_solution() if check_q_limits is set to True

property min_p_mw

Minimum active value that can be produced / absorbed by this generator given in MW.

Note

This is for now not taken into account by the solver. It is only used in lightsim2grid.gridmodel.check_solution() if check_q_limits is set to True

property min_q_mvar

Minimum reactive value that can be produced / absorbed by this generator given MVAr.

Note

This is for now not taken into account by the solver. It is only used in lightsim2grid.gridmodel.check_solution() if check_q_limits is set to True

property res_p_mw

Get the active production (or consumption) in MW for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_q_mvar

Get the reactive production (or consumption) in MVAr for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_theta_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this object is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_theta_deg”

property res_v_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this object is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_v_kv”

property target_p_mw

Get the active production (or consumption) setpoint in MW for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

property target_q_mvar

Get the reactive production (or consumption) setpoint in MVAr for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

Loads and Storage Units

class lightsim2grid.elements.DataLoad

This class allows to iterate through the loads and storage units of the lightsim2grid.gridmodel.GridModel easily, as if they were in a python list.

They cannot participate to the distributed slack bus yet. If you want this feature, fill free to send us a github issue.

Loads are modeled as in pandapower and can be represented a the pandapower loads .

Note

lightsim2grid Storages are modeled as load.

Examples

import grid2op
from lightsim2grid import LightSimBackend

# create a lightsim2grid "gridmodel"
env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())
grid_model = env.backend._grid

# manipulate the load
for load in grid_model.get_loads():
    # do something with load !
    load.bus_id

print(f"There are {len(grid_model.get_loads())} loads on the grid.")

first_load = grid_model.get_loads()[0]

# or the storage units
for storage in grid_model.get_storages():
    # do something with storage !
    storage.bus_id

print(f"There are {len(grid_model.get_storages())} storage units on the grid.")

first_storage_unit = grid_model.get_storages()[0]

You can have a look at lightsim2grid.elements.LoadInfo for properties of these elements.

class lightsim2grid.elements.LoadInfo

This class represents what you get from retrieving some elements from lightsim2grid.elements.DataLoad. We remind the reader that storage units are also modeled as load in lightsim2grid.

It allows to read information from each load / storage unit of the powergrid.

Warning

Data ca only be accessed from this element. You cannot modify (yet) the grid using this class.

Note

lightsim2grid Storages are modeled as load.

Examples

import grid2op
from lightsim2grid import LightSimBackend

# create a lightsim2grid "gridmodel"
env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())
grid_model = env.backend._grid

# for loads
first_load = grid_model.get_loads()[0]  # first static generator is a `LoadInfo`
for load in grid_model.get_loads():
    # load is a `LoadInfo`
    load.bus_id

# for loads
first_storage_unit = grid_model.get_storages()[0]  # first static generator is a `LoadInfo`
for storage in grid_model.get_storages():
    # storage is a `LoadInfo`
    storage.bus_id

Attributes:

bus_id

Get the bus id (as an integer) at which each element of a lightsim2grid.gridmodel.GridModel is connected.

connected

Get the status (True = connected, False = disconnected) of each element of a lightsim2grid.gridmodel.GridModel

has_res

This property specify whether or not a given element contains some "result" information.

id

Get the ideas of the element.

res_p_mw

Get the active production (or consumption) in MW for element of the grid supporting this feature.

res_q_mvar

Get the reactive production (or consumption) in MVAr for element of the grid supporting this feature.

res_theta_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this object is connected.

res_v_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this object is connected.

target_p_mw

Get the active production (or consumption) setpoint in MW for element of the grid supporting this feature.

target_q_mvar

Get the reactive production (or consumption) setpoint in MVAr for element of the grid supporting this feature.

property bus_id

Get the bus id (as an integer) at which each element of a lightsim2grid.gridmodel.GridModel is connected. If -1 is returned it means that the object is disconnected.

property connected

Get the status (True = connected, False = disconnected) of each element of a lightsim2grid.gridmodel.GridModel

property has_res

This property specify whether or not a given element contains some “result” information. If set to True then the fields starting with res_ (eg res_p_mw) are filled otherwise they are initialized with an arbitrary (and meaningless) value.

property id

Get the ideas of the element. Ids are integer from 0 to n-1 (if n denotes the number of such elements on the grid.)

Examples

We give the example only for generators, but it works similarly for every other types of objects in a lightsim2grid.gridmodel.GridModel.

This gives something like:

import grid2op
from lightsim2grid import LightSimBackend

env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())

grid_model = env.backend._grid

first_gen = grid_model.get_generators()[0]  # or get_loads for loads, etc.
first_gen.id  # should be 0
property res_p_mw

Get the active production (or consumption) in MW for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_q_mvar

Get the reactive production (or consumption) in MVAr for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_theta_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this object is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_theta_deg”

property res_v_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this object is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_v_kv”

property target_p_mw

Get the active production (or consumption) setpoint in MW for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

property target_q_mvar

Get the reactive production (or consumption) setpoint in MVAr for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

Shunts

class lightsim2grid.elements.DataShunt

This class allows to iterate through the load of the lightsim2grid.gridmodel.GridModel easily, as if they were in a python list.

Shunts are modeled as in pandapower and can be represented a the pandapower shunts .

Examples

import grid2op
from lightsim2grid import LightSimBackend

# create a lightsim2grid "gridmodel"
env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())
grid_model = env.backend._grid

# manipulate the load
for shunt in grid_model.get_shunts():
    # do something with shunt !
    shunt.bus_id

print(f"There are {len(grid_model.get_shunts())} shunts on the grid.")

first_shunt = grid_model.get_shunts()[0]

You can have a look at lightsim2grid.elements.ShuntInfo for properties of these elements.

class lightsim2grid.elements.ShuntInfo

This class represents what you get from retrieving the shunts from lightsim2grid.elements.DataShunt.

It allows to read information from each shunt of the powergrid.

Warning

Data ca only be accessed from this element. You cannot modify (yet) the grid using this class.

Examples

import grid2op
from lightsim2grid import LightSimBackend

# create a lightsim2grid "gridmodel"
env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())
grid_model = env.backend._grid

# for shunts
first_shunt = grid_model.get_shunts()[0]  # first shunt, this is a `ShuntInfo`
for shunt in grid_model.get_shunts():
    # shunt is a `ShuntInfo`
    shunt.bus_id

Attributes:

bus_id

Get the bus id (as an integer) at which each element of a lightsim2grid.gridmodel.GridModel is connected.

connected

Get the status (True = connected, False = disconnected) of each element of a lightsim2grid.gridmodel.GridModel

has_res

This property specify whether or not a given element contains some "result" information.

id

Get the ideas of the element.

res_p_mw

Get the active production (or consumption) in MW for element of the grid supporting this feature.

res_q_mvar

Get the reactive production (or consumption) in MVAr for element of the grid supporting this feature.

res_theta_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this object is connected.

res_v_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this object is connected.

target_p_mw

Get the active production (or consumption) setpoint in MW for element of the grid supporting this feature.

target_q_mvar

Get the reactive production (or consumption) setpoint in MVAr for element of the grid supporting this feature.

property bus_id

Get the bus id (as an integer) at which each element of a lightsim2grid.gridmodel.GridModel is connected. If -1 is returned it means that the object is disconnected.

property connected

Get the status (True = connected, False = disconnected) of each element of a lightsim2grid.gridmodel.GridModel

property has_res

This property specify whether or not a given element contains some “result” information. If set to True then the fields starting with res_ (eg res_p_mw) are filled otherwise they are initialized with an arbitrary (and meaningless) value.

property id

Get the ideas of the element. Ids are integer from 0 to n-1 (if n denotes the number of such elements on the grid.)

Examples

We give the example only for generators, but it works similarly for every other types of objects in a lightsim2grid.gridmodel.GridModel.

This gives something like:

import grid2op
from lightsim2grid import LightSimBackend

env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())

grid_model = env.backend._grid

first_gen = grid_model.get_generators()[0]  # or get_loads for loads, etc.
first_gen.id  # should be 0
property res_p_mw

Get the active production (or consumption) in MW for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_q_mvar

Get the reactive production (or consumption) in MVAr for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_theta_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this object is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_theta_deg”

property res_v_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this object is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_v_kv”

property target_p_mw

Get the active production (or consumption) setpoint in MW for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

property target_q_mvar

Get the reactive production (or consumption) setpoint in MVAr for element of the grid supporting this feature.

For generators (and static generators) it is given following the “generator convention” (positive = power is injected to the grid)

For loads (and storage units) it is given following the “load convention” (positive = power is absorbed from the grid)

Lines

class lightsim2grid.elements.DataLine

This class allows to iterate through the powerlines of the lightsim2grid.gridmodel.GridModel easily, as if they were in a python list.

Powerlines are modeled as in pandapower and can be represented a the pandapower lines .

Examples

import grid2op
from lightsim2grid import LightSimBackend

# create a lightsim2grid "gridmodel"
env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())
grid_model = env.backend._grid

# manipulate the powerlines
for line in grid_model.get_lines():
    # do something with line !
    line.bus_or_id

print(f"There are {len(grid_model.get_lines())} lines on the grid.")

first_line = grid_model.get_lines()[0]

You can have a look at lightsim2grid.elements.LineInfo for properties of these elements.

class lightsim2grid.elements.LineInfo

This class represents what you get from retrieving the powerlines from lightsim2grid.elements.DataLine.

It allows to read information from each powerline of the powergrid.

Powerlines have two sides, one is “or” for “origin” and one is “ex” for “extremity” that are connected and linked to each other by some equations.

For accessing the results, it’s basically the same as having two “elements” (so you get two “voltage_magnitude” res_v_kv, two “injected power” res_p_mw etc.)

Warning

Data ca only be accessed from this element. You cannot modify (yet) the grid using this class.

Examples

import grid2op
from lightsim2grid import LightSimBackend

# create a lightsim2grid "gridmodel"
env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())
grid_model = env.backend._grid

# for powerlines
first_line = grid_model.get_lines()[0]  # first line, this is a `LineInfo`
for line in grid_model.get_lines():
    # line is a `LineInfo`
    line.bus_or_id

Notes

Line are modeled using the “line model” as shown in the schema at the end of the paragraph.

The tap ratio n on this schema will be 1.0 for all powerline. If you want to model phase shifters, please model them as Trafo (see lightsim2grid.elements.TrafoInfo)

For more information about the model and the equations linking all the quantities, please visit matpower manual , especially the “3. Modeling” and the “3.2 Branches” subsection, as well as the equation 3.1, 3.2 and 3.3 therein.

The “line model” (also valid for transformers) is:

            ior                      ________            iex
`or bus` o------>   -----------------|r + j.x|---------<-------o `ex bus`
         |       ) (            |                  |           |
         |       ) (         |     |            |     |        |
         | vor   ) ( n:1     |1/2*h|            |1/2*h|        | vex
         |       ) (         |     |            |     |        |
         \/      ) (            |                  |           \/
ground---o-------   -------------------------------------------o---- ground

(fyi: ior, iex, n and y are all complex numbers. r and x are real numbers. j is a complex number such that j^2 = -1)

Attributes:

bus_ex_id

Get the bus id (as an integer) at which the "lv" side of the line is connected.

bus_or_id

Get the bus id (as an integer) at which the "or" side of the line is connected.

connected

Get the status (True = connected, False = disconnected) of each element of a lightsim2grid.gridmodel.GridModel

h_pu

Retrieve the capacitance (real part) and dielectric conductance (imaginary part) (given in pair unit system) of the powerlines or the transformers.

has_res

This property specify whether or not a given element contains some "result" information.

id

Get the ideas of the element.

r_pu

Retrieve the resistance (given in pair unit system, and not in Ohm) of the powerlines or the transformers.

res_a_ex_ka

Get the current flows (in kA) at the "ex" side of the line.

res_a_or_ka

Get the current flows (in kA) at the "or" side of the line.

res_p_ex_mw

Get the active power in MW for at the "ex" side of the line.

res_p_or_mw

Get the active power in MW for at the "or" side of the line.

res_q_ex_mvar

Get the reactive power in MVAr for at the "ex" side of the line.

res_q_or_mvar

Get the reactive power in MVAr for at the "or" side of the line.

res_theta_ex_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this "ex" side of the line is connected.

res_theta_or_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this "or" side of the line is connected.

res_v_ex_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this "ex" side of the line is connected.

res_v_or_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this "or" side of the line is connected.

x_pu

Retrieve the reactance (given in pair unit system, and not in Ohm) of the powerlines or the transformers.

property bus_ex_id

Get the bus id (as an integer) at which the “lv” side of the line is connected. If -1 is returned it means that the line is disconnected.

property bus_or_id

Get the bus id (as an integer) at which the “or” side of the line is connected. If -1 is returned it means that the line is disconnected.

property connected

Get the status (True = connected, False = disconnected) of each element of a lightsim2grid.gridmodel.GridModel

property h_pu

Retrieve the capacitance (real part) and dielectric conductance (imaginary part) (given in pair unit system) of the powerlines or the transformers.

This is a complex number and is represented by the number h in the line model.

The “line model” (also valid for transformers) is:

            ior                      ________            iex
`or bus` o------>   -----------------|r + j.x|---------<-------o `ex bus`
         |       ) (            |                  |           |
         |       ) (         |     |            |     |        |
         | vor   ) ( n:1     |1/2*h|            |1/2*h|        | vex
         |       ) (         |     |            |     |        |
         \/      ) (            |                  |           \/
ground---o-------   -------------------------------------------o---- ground

(fyi: ior, iex, n and y are all complex numbers. r and x are real numbers. j is a complex number such that j^2 = -1)

property has_res

This property specify whether or not a given element contains some “result” information. If set to True then the fields starting with res_ (eg res_p_mw) are filled otherwise they are initialized with an arbitrary (and meaningless) value.

property id

Get the ideas of the element. Ids are integer from 0 to n-1 (if n denotes the number of such elements on the grid.)

Examples

We give the example only for generators, but it works similarly for every other types of objects in a lightsim2grid.gridmodel.GridModel.

This gives something like:

import grid2op
from lightsim2grid import LightSimBackend

env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())

grid_model = env.backend._grid

first_gen = grid_model.get_generators()[0]  # or get_loads for loads, etc.
first_gen.id  # should be 0
property r_pu

Retrieve the resistance (given in pair unit system, and not in Ohm) of the powerlines or the transformers. This is a real number and is represented by the number r in the line model.

The “line model” (also valid for transformers) is:

            ior                      ________            iex
`or bus` o------>   -----------------|r + j.x|---------<-------o `ex bus`
         |       ) (            |                  |           |
         |       ) (         |     |            |     |        |
         | vor   ) ( n:1     |1/2*h|            |1/2*h|        | vex
         |       ) (         |     |            |     |        |
         \/      ) (            |                  |           \/
ground---o-------   -------------------------------------------o---- ground

(fyi: ior, iex, n and y are all complex numbers. r and x are real numbers. j is a complex number such that j^2 = -1)

property res_a_ex_ka

Get the current flows (in kA) at the “ex” side of the line.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_a_or_ka

Get the current flows (in kA) at the “or” side of the line.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_p_ex_mw

Get the active power in MW for at the “ex” side of the line. If it is positive it means power is absorbed by the line.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_p_or_mw

Get the active power in MW for at the “or” side of the line. If it is positive it means power is absorbed by the line.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_q_ex_mvar

Get the reactive power in MVAr for at the “ex” side of the line. If it is positive it means power is absorbed by the line.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_q_or_mvar

Get the reactive power in MVAr for at the “or” side of the line. If it is positive it means power is absorbed by the line.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_theta_ex_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this “ex” side of the line is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_theta_deg”

property res_theta_or_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this “or” side of the line is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_theta_deg”

property res_v_ex_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this “ex” side of the line is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_v_kv”

property res_v_or_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this “or” side of the line is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_v_kv”

property x_pu

Retrieve the reactance (given in pair unit system, and not in Ohm) of the powerlines or the transformers. This is a real number and is represented by the number x in the line model.

The “line model” (also valid for transformers) is:

            ior                      ________            iex
`or bus` o------>   -----------------|r + j.x|---------<-------o `ex bus`
         |       ) (            |                  |           |
         |       ) (         |     |            |     |        |
         | vor   ) ( n:1     |1/2*h|            |1/2*h|        | vex
         |       ) (         |     |            |     |        |
         \/      ) (            |                  |           \/
ground---o-------   -------------------------------------------o---- ground

(fyi: ior, iex, n and y are all complex numbers. r and x are real numbers. j is a complex number such that j^2 = -1)

Transformers

class lightsim2grid.elements.DataTrafo

This class allows to iterate through the transformers of the lightsim2grid.gridmodel.GridModel easily, as if they were in a python list.

Transformers are modeled as in pandapower and can be represented a the pandapower transformers .

Examples

import grid2op
from lightsim2grid import LightSimBackend

# create a lightsim2grid "gridmodel"
env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())
grid_model = env.backend._grid

# manipulate the tranformers
for trafo in grid_model.get_trafos():
    # do something with trafo !
    trafo.bus_hv_id

print(f"There are {len(grid_model.get_trafos())} transformers on the grid.")

first_transformer = grid_model.get_trafos()[0]

You can have a look at lightsim2grid.elements.TrafoInfo for properties of these elements.

class lightsim2grid.elements.TrafoInfo

This class represents what you get from retrieving the transformers from lightsim2grid.elements.DataTrafo.

It allows to read information from each transformer of the powergrid.

Transformers have two sides, one is “hv” for “high voltage” and one is “lv” for “low voltage” that are connected and linked to each other by some equations.

For accessing the results, it’s basically the same as having two “elements” (so you get two “voltage_magnitude” res_v_kv, two “injected power” res_p_mw etc.)

Warning

Data ca only be accessed from this element. You cannot modify (yet) the grid using this class.

Examples

import grid2op
from lightsim2grid import LightSimBackend

# create a lightsim2grid "gridmodel"
env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())
grid_model = env.backend._grid

# for transformers
first_transformer = grid_model.get_trafos()[0]  # first transformer, this is a `TrafoInfo`
for trafo in grid_model.get_trafos():
    # trafo is a `TrafoInfo`
    trafo.bus_hv_id

Notes

Transformer are modeled using the “line model”.

Usually, the “or” side is the “hv” side and the “ex” side is the “lv” side.

The tap ratio n bellow is a complex number with its magnitude corresponding to the tap ratio and its angle to the phase shifter.

For more information about the model and the equations linking all the quantities, please visit matpower manual , especially the “3. Modeling” and the “3.2 Branches” subsection, as well as the equation 3.1, 3.2 and 3.3 therein.

The “line model” (also valid for transformers) is:

            ior                      ________            iex
`or bus` o------>   -----------------|r + j.x|---------<-------o `ex bus`
         |       ) (            |                  |           |
         |       ) (         |     |            |     |        |
         | vor   ) ( n:1     |1/2*h|            |1/2*h|        | vex
         |       ) (         |     |            |     |        |
         \/      ) (            |                  |           \/
ground---o-------   -------------------------------------------o---- ground

(fyi: ior, iex, n and y are all complex numbers. r and x are real numbers. j is a complex number such that j^2 = -1)

Attributes:

bus_hv_id

Get the bus id (as an integer) at which the "hv" side of the transformer is connected.

bus_lv_id

Get the bus id (as an integer) at which the "lv" side of the transformer is connected.

connected

Get the status (True = connected, False = disconnected) of each element of a lightsim2grid.gridmodel.GridModel

h_pu

Retrieve the capacitance (real part) and dielectric conductance (imaginary part) (given in pair unit system) of the powerlines or the transformers.

has_res

This property specify whether or not a given element contains some "result" information.

id

Get the ideas of the element.

is_tap_hv_side

Gives whether the tap (both for the ratio and the phase shifter) is located "hv" side (default, when True) or "lv" side (when False).

r_pu

Retrieve the resistance (given in pair unit system, and not in Ohm) of the powerlines or the transformers.

ratio

Retrieve the ratio (absolute value of the complex coefficient n in the powerline model).

res_a_hv_ka

Get the current flows (in kA) at the "hv" side of the transformer.

res_a_lv_ka

Get the current flows (in kA) at the "lv" side of the transformer.

res_p_hv_mw

Get the active power in MW for at the "hv" side of the transformer.

res_p_lv_mw

Get the active power in MW for at the "lv" side of the transformer.

res_q_hv_mvar

Get the reactive power in MVAr for at the "hv" side of the transformer.

res_q_lv_mvar

Get the reactive power in MVAr for at the "lv" side of the transformer.

res_theta_hv_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this "hv" side of the transformer is connected.

res_theta_lv_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this "lv" side of the transformer is connected.

res_v_hv_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this "hv" side of the transformer is connected.

res_v_lv_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this "lv" side of the transformer is connected.

shift_rad

Retrieve the shift angle (angle of the complex coefficient n in the powerline model).

x_pu

Retrieve the reactance (given in pair unit system, and not in Ohm) of the powerlines or the transformers.

property bus_hv_id

Get the bus id (as an integer) at which the “hv” side of the transformer is connected. If -1 is returned it means that the transformer is disconnected.

property bus_lv_id

Get the bus id (as an integer) at which the “lv” side of the transformer is connected. If -1 is returned it means that the transformer is disconnected.

property connected

Get the status (True = connected, False = disconnected) of each element of a lightsim2grid.gridmodel.GridModel

property h_pu

Retrieve the capacitance (real part) and dielectric conductance (imaginary part) (given in pair unit system) of the powerlines or the transformers.

This is a complex number and is represented by the number h in the line model.

The “line model” (also valid for transformers) is:

            ior                      ________            iex
`or bus` o------>   -----------------|r + j.x|---------<-------o `ex bus`
         |       ) (            |                  |           |
         |       ) (         |     |            |     |        |
         | vor   ) ( n:1     |1/2*h|            |1/2*h|        | vex
         |       ) (         |     |            |     |        |
         \/      ) (            |                  |           \/
ground---o-------   -------------------------------------------o---- ground

(fyi: ior, iex, n and y are all complex numbers. r and x are real numbers. j is a complex number such that j^2 = -1)

property has_res

This property specify whether or not a given element contains some “result” information. If set to True then the fields starting with res_ (eg res_p_mw) are filled otherwise they are initialized with an arbitrary (and meaningless) value.

property id

Get the ideas of the element. Ids are integer from 0 to n-1 (if n denotes the number of such elements on the grid.)

Examples

We give the example only for generators, but it works similarly for every other types of objects in a lightsim2grid.gridmodel.GridModel.

This gives something like:

import grid2op
from lightsim2grid import LightSimBackend

env_name = ... # eg. "l2rpn_case14_test"
env = grid2op.make(env_name, backend=LightSimBackend())

grid_model = env.backend._grid

first_gen = grid_model.get_generators()[0]  # or get_loads for loads, etc.
first_gen.id  # should be 0
property is_tap_hv_side

Gives whether the tap (both for the ratio and the phase shifter) is located “hv” side (default, when True) or “lv” side (when False).

property r_pu

Retrieve the resistance (given in pair unit system, and not in Ohm) of the powerlines or the transformers. This is a real number and is represented by the number r in the line model.

The “line model” (also valid for transformers) is:

            ior                      ________            iex
`or bus` o------>   -----------------|r + j.x|---------<-------o `ex bus`
         |       ) (            |                  |           |
         |       ) (         |     |            |     |        |
         | vor   ) ( n:1     |1/2*h|            |1/2*h|        | vex
         |       ) (         |     |            |     |        |
         \/      ) (            |                  |           \/
ground---o-------   -------------------------------------------o---- ground

(fyi: ior, iex, n and y are all complex numbers. r and x are real numbers. j is a complex number such that j^2 = -1)

property ratio

Retrieve the ratio (absolute value of the complex coefficient n in the powerline model). It has no units

The “line model” (also valid for transformers) is:

            ior                      ________            iex
`or bus` o------>   -----------------|r + j.x|---------<-------o `ex bus`
         |       ) (            |                  |           |
         |       ) (         |     |            |     |        |
         | vor   ) ( n:1     |1/2*h|            |1/2*h|        | vex
         |       ) (         |     |            |     |        |
         \/      ) (            |                  |           \/
ground---o-------   -------------------------------------------o---- ground

(fyi: ior, iex, n and y are all complex numbers. r and x are real numbers. j is a complex number such that j^2 = -1)

property res_a_hv_ka

Get the current flows (in kA) at the “hv” side of the transformer.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_a_lv_ka

Get the current flows (in kA) at the “lv” side of the transformer.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_p_hv_mw

Get the active power in MW for at the “hv” side of the transformer. If it is positive it means power is absorbed by the transformer.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_p_lv_mw

Get the active power in MW for at the “lv” side of the transformer. If it is positive it means power is absorbed by the transformer.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_q_hv_mvar

Get the reactive power in MVAr for at the “hv” side of the transformer. If it is positive it means power is absorbed by the transformer.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_q_lv_mvar

Get the reactive power in MVAr for at the “lv” side of the transformer. If it is positive it means power is absorbed by the transformer.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

property res_theta_hv_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this “hv” side of the transformer is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_theta_deg”

property res_theta_lv_deg

Get the angle of the complex voltage (in degree, not in radian) of the bus at which this “lv” side of the transformer is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_theta_deg”

property res_v_hv_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this “hv” side of the transformer is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_v_kv”

property res_v_lv_kv

Get the magnitude of the complex voltage (in kV) of the bus at which this “lv” side of the transformer is connected.

Warning

This feature is only relevant if the results have been computed (for example if a powerflow has successfully run)

Note

All elements (load, generators, side of powerline etc.) connected at the same bus have the same “res_v_kv”

property shift_rad

Retrieve the shift angle (angle of the complex coefficient n in the powerline model). It is given in radian (and not in degree)

The “line model” (also valid for transformers) is:

            ior                      ________            iex
`or bus` o------>   -----------------|r + j.x|---------<-------o `ex bus`
         |       ) (            |                  |           |
         |       ) (         |     |            |     |        |
         | vor   ) ( n:1     |1/2*h|            |1/2*h|        | vex
         |       ) (         |     |            |     |        |
         \/      ) (            |                  |           \/
ground---o-------   -------------------------------------------o---- ground

(fyi: ior, iex, n and y are all complex numbers. r and x are real numbers. j is a complex number such that j^2 = -1)

property x_pu

Retrieve the reactance (given in pair unit system, and not in Ohm) of the powerlines or the transformers. This is a real number and is represented by the number x in the line model.

The “line model” (also valid for transformers) is:

            ior                      ________            iex
`or bus` o------>   -----------------|r + j.x|---------<-------o `ex bus`
         |       ) (            |                  |           |
         |       ) (         |     |            |     |        |
         | vor   ) ( n:1     |1/2*h|            |1/2*h|        | vex
         |       ) (         |     |            |     |        |
         \/      ) (            |                  |           \/
ground---o-------   -------------------------------------------o---- ground

(fyi: ior, iex, n and y are all complex numbers. r and x are real numbers. j is a complex number such that j^2 = -1)

Detailed documentation

Classes:

GridModel

This class represent a lightsim2grid power network.

Functions:

init(pp_net)

Convert a pandapower network as input into a GridModel.

class lightsim2grid.gridmodel.GridModel

This class represent a lightsim2grid power network. All the elements that can be manipulated by lightsim2grid are represented here.

We do not recommend to use this class directly, but rather to use a lightsim2grid.LightSimBackend.LightSimBackend.

Examples

We DO NOT recommend to do:

import lightsim2grid
from lightsim2grid.gridmodel import init
pp_net = ...  # any pandapower network for example pp_net = pn.case118()

grid_model = init(pp_net)

It’s better to do:

import grid2op
from lightsim2grid import LightSimBackend
env_name = ...  # any grid2op environment
grid2op_env = grid2op.make(env_name, backend=LightSimBackend())

grid_model = grid2op_env.backend._grid

The best way to use this class is through the LightSimBackend and not to use it directly !

Methods:

ac_pf(self, arg0, arg1, arg2)

Allows to perform an AC (alternating current) powerflow.

add_gen_slackbus(self, arg0, arg1)

INTERNAL

available_solvers(self)

Return the list of solver available on the current lightsim2grid installation.

change_bus_gen(self, arg0, arg1)

INTERNAL

change_bus_load(self, arg0, arg1)

INTERNAL

change_bus_powerline_ex(self, arg0, arg1)

INTERNAL

change_bus_powerline_or(self, arg0, arg1)

INTERNAL

change_bus_sgen(self, arg0, arg1)

INTERNAL

change_bus_shunt(self, arg0, arg1)

INTERNAL

change_bus_storage(self, arg0, arg1)

INTERNAL

change_bus_trafo_hv(self, arg0, arg1)

INTERNAL

change_bus_trafo_lv(self, arg0, arg1)

INTERNAL

change_p_gen(self, arg0, arg1)

INTERNAL

change_p_load(self, arg0, arg1)

INTERNAL

change_p_sgen(self, arg0, arg1)

INTERNAL

change_p_shunt(self, arg0, arg1)

INTERNAL

change_p_storage(self, arg0, arg1)

INTERNAL

change_q_load(self, arg0, arg1)

INTERNAL

change_q_sgen(self, arg0, arg1)

INTERNAL

change_q_shunt(self, arg0, arg1)

INTERNAL

change_q_storage(self, arg0, arg1)

INTERNAL

change_solver(self, arg0)

This function allows to control which solver is used during the powerflow.

change_v_gen(self, arg0, arg1)

INTERNAL

check_solution(self, arg0, arg1)

This function allows to check that a given complex voltage vector satisfies the KCL or not, given the state of the sytem.

compute_newton(self, arg0, arg1, arg2)

Allows to perform an AC (alternating current) powerflow.

copy(self)

dc_pf(self, arg0, arg1, arg2)

This function has the same interface, inputs, outputs, behaviour, etc.

deactivate_bus(self, arg0)

INTERNAL

deactivate_gen(self, arg0)

INTERNAL

deactivate_load(self, arg0)

INTERNAL

deactivate_powerline(self, arg0)

INTERNAL

deactivate_result_computation(self)

Allows to deactivate the computation of the flows, reactive power absorbed by generators etc.

deactivate_sgen(self, arg0)

INTERNAL

deactivate_shunt(self, arg0)

INTERNAL

deactivate_storage(self, arg0)

INTERNAL

deactivate_trafo(self, arg0)

INTERNAL

get_J(self)

Returns the Jacobian matrix used for solving the powerflow as a scipy sparse CSC matrix matrix of real number.

get_Sbus(self)

This function returns the (complex) Sbus vector, which is the vector of active / reactive power injected at each active bus

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

This function returns the (complex) Ybus matrix used to compute the powerflow.

get_bus_gen(self, arg0)

INTERNAL

get_bus_load(self, arg0)

INTERNAL

get_bus_powerline_ex(self, arg0)

INTERNAL

get_bus_powerline_or(self, arg0)

INTERNAL

get_bus_sgen(self, arg0)

INTERNAL

get_bus_shunt(self, arg0)

INTERNAL

get_bus_storage(self, arg0)

INTERNAL

get_bus_trafo_hv(self, arg0)

INTERNAL

get_bus_trafo_lv(self, arg0)

INTERNAL

get_computation_time(self)

Return the total computation time (in second) spend in the solver when performing a powerflow.

get_dcYbus(self)

It is the equivalent of lightsim2grid.gridmodel.GridModel.get_Ybus() but for the dc solver.

get_dc_computation_time(self)

Return the total computation time (in second) spend in the solver (used to perform DC approximation) when performing a DC powerflow.

get_dc_solver(self)

Return the solver currently in use as a lightsim2grid.solver.AnySolver() instance for the dc powerflow.

get_dc_solver_type(self)

Return the type of the solver currently used to compute DC powerflow.

get_gen_res(self)

INTERNAL

get_gen_status(self)

INTERNAL

get_gen_theta(self)

INTERNAL

get_generators(self)

This function allows to retrieve the (standard) generators (as a lightsim2grid.elements.DataGen object, see Elements modeled for more information)

get_init_vm_pu(self)

INTERNAL

get_lineex_res(self)

INTERNAL

get_lineex_theta(self)

INTERNAL

get_lineor_res(self)

INTERNAL

get_lineor_theta(self)

INTERNAL

get_lines(self)

This function allows to retrieve the powerlines (as a lightsim2grid.elements.DataLine object, see Elements modeled for more information)

get_lines_status(self)

INTERNAL

get_load_theta(self)

INTERNAL

get_loads(self)

This function allows to retrieve the loads (as a lightsim2grid.elements.DataLoad object, see Elements modeled for more information)

get_loads_res(self)

INTERNAL

get_loads_status(self)

INTERNAL

get_pq(self)

Returns the ids of the buses that are labelled as "PQ".

get_pv(self)

Returns the ids of the buses that are labelled as "PV" (ie the buses on which at least a generator is connected.).

get_sgens_res(self)

INTERNAL

get_sgens_status(self)

INTERNAL

get_shunt_theta(self)

INTERNAL

get_shunts(self)

This function allows to retrieve the shunts (as a lightsim2grid.elements.DataShunt object, see Elements modeled for more information)

get_shunts_res(self)

INTERNAL

get_shunts_status(self)

INTERNAL

get_slack_ids(self)

Returns the ids of the buses that are part of the distributed slack.

get_slack_weights(self)

For each bus used by the solver, it outputs its participation to the distributed slack.

get_sn_mva(self)

INTERNAL

get_solver(self)

Return the solver currently in use as a lightsim2grid.solver.AnySolver() instance.

get_solver_type(self)

Return the type of the solver currently used.

get_static_generators(self)

This function allows to retrieve the (more exotic) static generators (as a lightsim2grid.elements.DataSGen object, see Elements modeled for more information)

get_storage_theta(self)

INTERNAL

get_storages(self)

This function allows to retrieve the storage units (as a lightsim2grid.elements.DataLoad object, see Elements modeled for more information)

get_storages_res(self)

INTERNAL

get_storages_status(self)

INTERNAL

get_trafo_status(self)

INTERNAL

get_trafohv_res(self)

INTERNAL

get_trafohv_theta(self)

INTERNAL

get_trafolv_res(self)

INTERNAL

get_trafolv_theta(self)

INTERNAL

get_trafos(self)

This function allows to retrieve the transformers (as a lightsim2grid.elements.DataLine object, see Elements modeled for more information)

id_ac_solver_to_me(self)

In lightsim2grid, buses are labelled from 0 to n-1 (if n denotes the total number of buses on the grid) [this is called "grid model bus id"]

id_dc_solver_to_me(self)

Same as lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me but only used for the DC approximation.

id_me_to_ac_solver(self)

In lightsim2grid, buses are labelled from 0 to n-1 (if n denotes the total number of buses on the grid) [this is called "grid model bus id"]

id_me_to_dc_solver(self)

Same as lightsim2grid.gridmodel.GridModel.id_me_to_ac_solver but only used for the DC approximation.

init_bus(self, arg0, arg1, arg2)

INTERNAL

init_generators(self, arg0, arg1, arg2, ...)

INTERNAL

init_loads(self, arg0, arg1, arg2)

INTERNAL

init_powerlines(self, arg0, arg1, arg2, ...)

INTERNAL

init_sgens(self, arg0, arg1, arg2, arg3, ...)

INTERNAL

init_shunt(self, arg0, arg1, arg2)

INTERNAL

init_storages(self, arg0, arg1, arg2)

INTERNAL

init_trafo(self, arg0, arg1, arg2, arg3, ...)

INTERNAL

nb_bus(self)

Returns (>0 integer) the number of connected buses on the powergrid (ignores the disconnected bus).

reactivate_bus(self, arg0)

INTERNAL

reactivate_gen(self, arg0)

INTERNAL

reactivate_load(self, arg0)

INTERNAL

reactivate_powerline(self, arg0)

INTERNAL

reactivate_result_computation(self)

Allows to reactivate the computation of the flows, reactive power absorbed by generators etc.

reactivate_sgen(self, arg0)

INTERNAL

reactivate_shunt(self, arg0)

INTERNAL

reactivate_storage(self, arg0)

INTERNAL

reactivate_trafo(self, arg0)

INTERNAL

remove_gen_slackbus(self, arg0)

INTERNAL

set_gen_pos_topo_vect(self, arg0)

INTERNAL

set_gen_to_subid(self, arg0)

INTERNAL

set_init_vm_pu(self, arg0)

INTERNAL

set_line_ex_pos_topo_vect(self, arg0)

INTERNAL

set_line_ex_to_subid(self, arg0)

INTERNAL

set_line_or_pos_topo_vect(self, arg0)

INTERNAL

set_line_or_to_subid(self, arg0)

INTERNAL

set_load_pos_topo_vect(self, arg0)

INTERNAL

set_load_to_subid(self, arg0)

INTERNAL

set_n_sub(self, arg0)

INTERNAL

set_sn_mva(self, arg0)

INTERNAL

set_storage_pos_topo_vect(self, arg0)

INTERNAL

set_storage_to_subid(self, arg0)

INTERNAL

set_trafo_hv_pos_topo_vect(self, arg0)

INTERNAL

set_trafo_hv_to_subid(self, arg0)

INTERNAL

set_trafo_lv_pos_topo_vect(self, arg0)

INTERNAL

set_trafo_lv_to_subid(self, arg0)

INTERNAL

tell_topo_changed(self)

INTERNAL

total_bus(self)

Returns (>0 integer) the total number of buses in the powergrid (both connected and disconnected)

unset_topo_changed(self)

INTERNAL

update_bus_status(self, arg0, arg1)

INTERNAL

update_gens_p(self, arg0, arg1)

INTERNAL

update_gens_v(self, arg0, arg1)

INTERNAL

update_loads_p(self, arg0, arg1)

INTERNAL

update_loads_q(self, arg0, arg1)

INTERNAL

update_storages_p(self, arg0, arg1)

INTERNAL

update_topo(self, arg0, arg1)

INTERNAL

ac_pf(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.complex128[m, 1]], arg1: int, arg2: float) numpy.ndarray[numpy.complex128[m, 1]]

Allows to perform an AC (alternating current) powerflow.

Note

It is expected that you provide a complex number even for the buses that are disconnected in the grid model. They will not be affected (if the powerflow converges) and you can put anything you want there. We keep the public interface this way to avoid headaches with the bus order between the grid model and the solver (you can refer to lightsim2grid.gridmodel.GridModel.id_me_to_ac_solver() and lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me() if you still want to have a look)

See also

lightsim2grid.gridmodel.GridModel.dc_pf() if you want to perform DC powerflow (same interface, same results, same behaviour)

Warning

The input vector V is modified (and is equal to the resulting vector V)

Parameters
  • V – It expects a complex voltage vector (having as many components as the total number of buses in the grid.) representing the initial guess of the resulting flows. This vector will be modified !

  • max_iter (int) – Maximum number of iterations allowed (this might be ignored) and should be a >= 0 integer

  • tol (float) – Tolerance criteria to stop the computation. This should be > 0 real number.

Returns

A complex vector given the complex voltage at each buses of the grid model. Will be empty when the powerflow diverged.

Return type

V

Examples

# create a grid model
import grid2op
from lightsim2grid import LightSimBackend
env_name = ...  # eg "l2rpn_case14_sandbox"
env = grid2op.make(env_name, backend=LightSimbackend())
grid_model = env.backend._grid

V = grid_model.ac_pf(V, 10, 1e-8)
# if the powerflow has converged, V.shape > 0 otherwise V is empty (size 0)
# the original V is modified in the process !
add_gen_slackbus(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

available_solvers(self: lightsim2grid_cpp.GridModel) List[lightsim2grid_cpp.SolverType]

Return the list of solver available on the current lightsim2grid installation.

This is a list of lightsim2grid.solver.SolverType.

change_bus_gen(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_bus_load(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_bus_powerline_ex(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_bus_powerline_or(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_bus_sgen(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_bus_shunt(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_bus_storage(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_bus_trafo_hv(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_bus_trafo_lv(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_p_gen(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_p_load(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_p_sgen(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_p_shunt(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_p_storage(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_q_load(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_q_sgen(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_q_shunt(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_q_storage(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

change_solver(self: lightsim2grid_cpp.GridModel, arg0: lightsim2grid_cpp.SolverType) None

This function allows to control which solver is used during the powerflow. See the section Even more advanced usage for more information about them.

See also

lightsim2grid.solver.SolverType for a list of the available solver (NB: some solvers might not be available on all platform)

Note

If the solver type entered is a DC solver (eg from lightsim2grid.solver.SolverType, DC, KLUDC or NICSLUDC), it will change the _dc_solver otherwise the regular _solver is modified.

Examples

from lightsim2grid.solver import SolverType
# init the grid model
from lightsim2grid.gridmodel import init
pp_net = ...  # any pandapower grid
lightsim_grid_model = init(pp_net)  # some warnings might be issued as well as some warnings

# change the solver used for the powerflow
# to use internally a solver based on Newton Raphson algorithme using Eigen sparse LU
lightsim_grid_model.change_solver(SolverType.SparseLUSolver)
change_v_gen(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

check_solution(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.complex128[m, 1]], arg1: bool) numpy.ndarray[numpy.complex128[m, 1]]

This function allows to check that a given complex voltage vector satisfies the KCL or not, given the state of the sytem.

Note

It is expected that you provide a complex number even for the buses that are disconnected in the grid model. They will not be ignored so you can put anything you want. We keep the public interface this way to avoid headaches with the bus order between the grid model and the solver (you can refer to lightsim2grid.gridmodel.GridModel.id_me_to_ac_solver() and lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me() if you still want to have a look)

See also

lightsim2grid.physical_law_checker.PhysicalLawChecker for an easier to use, more pythonic function !

Parameters
  • V – It expects a complex voltage vector (having as many components as the total number of buses in the grid.) representing the vector you want to test.

  • check_q_limits (bool) – whether you want to take into account the reactive limit of generators when performing the check

Returns

A complex vector having the size of the number of total buses on the grid, given, for each of them, the active / reactive power mismatch at each bus (ie the power you would need to take from the grid and have the input vector V checking the KCL given the current state of the grid)

Return type

mismatch

compute_newton(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.complex128[m, 1]], arg1: int, arg2: float) numpy.ndarray[numpy.complex128[m, 1]]

Allows to perform an AC (alternating current) powerflow.

Note

It is expected that you provide a complex number even for the buses that are disconnected in the grid model. They will not be affected (if the powerflow converges) and you can put anything you want there. We keep the public interface this way to avoid headaches with the bus order between the grid model and the solver (you can refer to lightsim2grid.gridmodel.GridModel.id_me_to_ac_solver() and lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me() if you still want to have a look)

See also

lightsim2grid.gridmodel.GridModel.dc_pf() if you want to perform DC powerflow (same interface, same results, same behaviour)

Warning

The input vector V is modified (and is equal to the resulting vector V)

Parameters
  • V – It expects a complex voltage vector (having as many components as the total number of buses in the grid.) representing the initial guess of the resulting flows. This vector will be modified !

  • max_iter (int) – Maximum number of iterations allowed (this might be ignored) and should be a >= 0 integer

  • tol (float) – Tolerance criteria to stop the computation. This should be > 0 real number.

Returns

A complex vector given the complex voltage at each buses of the grid model. Will be empty when the powerflow diverged.

Return type

V

Examples

# create a grid model
import grid2op
from lightsim2grid import LightSimBackend
env_name = ...  # eg "l2rpn_case14_sandbox"
env = grid2op.make(env_name, backend=LightSimbackend())
grid_model = env.backend._grid

V = grid_model.ac_pf(V, 10, 1e-8)
# if the powerflow has converged, V.shape > 0 otherwise V is empty (size 0)
# the original V is modified in the process !
copy(self: lightsim2grid_cpp.GridModel) lightsim2grid_cpp.GridModel
dc_pf(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.complex128[m, 1]], arg1: int, arg2: float) numpy.ndarray[numpy.complex128[m, 1]]

This function has the same interface, inputs, outputs, behaviour, etc. as the lightsim2grid.gridmodel.GridModel.ac_pf().

deactivate_bus(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

deactivate_gen(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

deactivate_load(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

deactivate_powerline(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

deactivate_result_computation(self: lightsim2grid_cpp.GridModel) None

Allows to deactivate the computation of the flows, reactive power absorbed by generators etc. to gain a bit of time when it is not needed.

deactivate_sgen(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

deactivate_shunt(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

deactivate_storage(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

deactivate_trafo(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_J(self: lightsim2grid_cpp.GridModel) 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

Some powerflows (eg DC or Gauss Seidel) do not rely on jacobian matrix, in this case, calling this function will return an exception.

J has the shape:

| s | slack_bus |               | (pvpq+1,1) |   (1, pvpq)  |  (1, pq)   |
| l |  -------  |               |            | ------------------------- |
| a | J11 | J12 | = dimensions: |            | (pvpq, pvpq) | (pvpq, pq) |
| c | --------- |               |   ------   | ------------------------- |
| k | J21 | J22 |               |  (pq, 1)   |  (pq, pvpq)  | (pq, pq)   |

With:

  • J11 = dS_dVa[array([pvpq]).T, pvpq].real (= real part of dS / dVa for all pv and pq buses)

  • J12 = dS_dVm[array([pvpq]).T, pq].real

  • J21 = dS_dVa[array([pq]).T, pvpq].imag

  • J22 = dS_dVm[array([pq]).T, pq].imag (= imaginary part of dS / dVm for all pq buses)

  • slack_bus = is the representation of the equation for the reference slack bus dS_dVa[slack_bus_id, pvpq].real and dS_dVm[slack_bus_id, pq].real

  • slack is the representation of the equation connecting together the slack buses (represented by slack_weights) the remaining pq components are all 0.

Note

By default (and this cannot be changed at the moment), all buses in ref will be pv buses except the first one.

Note

the notation pvpq above means “the concatenation of the pv vector and the pq vector” (after the distributed slack is taken into account - see note just above)

get_Sbus(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.complex128[m, 1]]

This function returns the (complex) Sbus vector, which is the vector of active / reactive power injected at each active bus

The resulting vector is a vector of complex number having the size of the number of connected buses on the grid.

Warning

Each row / columns of this matrix represents a “solver bus” (and not a “grid model bus”). In other word, the first row / column of this matrix is not necessarily the first bus of the grid model.

Warning

This is given in the pair unit system and in load convention (so generation will be negative)

See also

lightsim2grid.gridmodel.GridModel.id_me_to_ac_solver() and lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me() for ways to link the “grid model” bus id to the “solver” bus id.

Notes

Suppose that the grid model bus of id k is connected. Then the row / column id_me_to_ac_solver[k] (will be >= 0) and will represent this bus: Sbus[id_me_to_ac_solver[k]] is the total power injected at the grid model bus solver k.

Warning

The above only holds when the bus of id k is connected which is when id_me_to_ac_solver[k] >= 0 !

get_V(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.complex128[m, 1]]

Returns the complex voltage for each buses as a numpy vector of complex number. This vector have the size of the total number of active buses on the system.

You can use the lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me (or lightsim2grid.gridmodel.GridModel.id_dc_solver_to_me) to know at which bus (on the grid) they corresponds.

get_Va(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.float64[m, 1]]

Returns the voltage angles for each buses as a numpy vector of real number. This vector have the size of the total number of active buses on the system.

You can use the lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me (or lightsim2grid.gridmodel.GridModel.id_dc_solver_to_me) to know at which bus (on the grid) they corresponds.

get_Vm(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.float64[m, 1]]

Returns the voltage magnitude for each buses as a numpy vector of real number. This vector have the size of the total number of active buses on the system.

You can use the lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me (or lightsim2grid.gridmodel.GridModel.id_dc_solver_to_me) to know at which bus (on the grid) they corresponds.

get_Ybus(self: lightsim2grid_cpp.GridModel) scipy.sparse.csc_matrix[numpy.complex128]

This function returns the (complex) Ybus matrix used to compute the powerflow.

The resulting matrix is a CSC scipy sparse matrix of complex number.

It is a square matrix, as many rows (columns) as there are connected buses on the grid.

Warning

Each row / columns of this matrix represents a “solver bus” (and not a “grid model bus”). In other word, the first row / column of this matrix is not necessarily the first bus of the grid model.

Warning

This is given in the pair unit system !

See also

lightsim2grid.gridmodel.GridModel.id_me_to_ac_solver() and lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me() for ways to link the “grid model” bus id to the “solver” bus id.

Notes

Suppose that the grid model bus of id k is connected. Then the row / column id_me_to_ac_solver[k] (will be >= 0) and will represent this bus: Ybus[id_me_to_ac_solver[k],:] (rows of this bus), Ybus[:, id_me_to_ac_solver[k]] (column for this bus)

Warning

The above only holds when the bus of id k is connected which is when id_me_to_ac_solver[k] >= 0 !

get_bus_gen(self: lightsim2grid_cpp.GridModel, arg0: int) int

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_bus_load(self: lightsim2grid_cpp.GridModel, arg0: int) int

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_bus_powerline_ex(self: lightsim2grid_cpp.GridModel, arg0: int) int

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_bus_powerline_or(self: lightsim2grid_cpp.GridModel, arg0: int) int

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_bus_sgen(self: lightsim2grid_cpp.GridModel, arg0: int) int

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_bus_shunt(self: lightsim2grid_cpp.GridModel, arg0: int) int

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_bus_storage(self: lightsim2grid_cpp.GridModel, arg0: int) int

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_bus_trafo_hv(self: lightsim2grid_cpp.GridModel, arg0: int) int

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_bus_trafo_lv(self: lightsim2grid_cpp.GridModel, arg0: int) int

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_computation_time(self: lightsim2grid_cpp.GridModel) float

Return the total computation time (in second) spend in the solver when performing a powerflow.

This is equivalent to the get_computation_time of the lightsim2grid.solver.AnySolver.get_computation_time() of the solver used (lightsim2grid.gridmodel.GridModel.get_solver())

get_dcYbus(self: lightsim2grid_cpp.GridModel) scipy.sparse.csc_matrix[numpy.complex128]

It is the equivalent of lightsim2grid.gridmodel.GridModel.get_Ybus() but for the dc solver.

Warning

As opposed to some other librairies (for example Matpower of pandapower), the Ybus for the dc approximation in lightsim2grid has no imaginary components.

It could have returned a real matrix, but we choose (out of consistency with other solvers) to keep the representation as a complex numbers.

get_dc_computation_time(self: lightsim2grid_cpp.GridModel) float

Return the total computation time (in second) spend in the solver (used to perform DC approximation) when performing a DC powerflow.

This is equivalent to the get_computation_time of the lightsim2grid.solver.AnySolver.get_computation_time() of the DC solver used (lightsim2grid.gridmodel.GridModel.get_dc_solver())

get_dc_solver(self: lightsim2grid_cpp.GridModel) lightsim2grid_cpp.AnySolver

Return the solver currently in use as a lightsim2grid.solver.AnySolver() instance for the dc powerflow.

get_dc_solver_type(self: lightsim2grid_cpp.GridModel) lightsim2grid_cpp.SolverType

Return the type of the solver currently used to compute DC powerflow.

get_gen_res(self: lightsim2grid_cpp.GridModel) Tuple[numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_gen_status(self: lightsim2grid_cpp.GridModel) List[bool]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_gen_theta(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.float64[m, 1]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_generators(self: lightsim2grid_cpp.GridModel) lightsim2grid_cpp.DataGen

This function allows to retrieve the (standard) generators (as a lightsim2grid.elements.DataGen object, see Elements modeled for more information)

Examples

# init the grid model
from lightsim2grid.gridmodel import init
pp_net = ...  # any pandapower grid
lightsim_grid_model = init(pp_net)  # some warnings might be issued as well as some warnings

# usage example: print some information about the generators
print([el.target_p_mw for el in lightsim_grid_model.get_generators()]) # to print the active production setpoint for each generators
get_init_vm_pu(self: lightsim2grid_cpp.GridModel) float

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_lineex_res(self: lightsim2grid_cpp.GridModel) Tuple[numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_lineex_theta(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.float64[m, 1]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_lineor_res(self: lightsim2grid_cpp.GridModel) Tuple[numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_lineor_theta(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.float64[m, 1]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_lines(self: lightsim2grid_cpp.GridModel) lightsim2grid_cpp.DataLine

This function allows to retrieve the powerlines (as a lightsim2grid.elements.DataLine object, see Elements modeled for more information)

Examples

# init the grid model
from lightsim2grid.gridmodel import init
pp_net = ...  # any pandapower grid
lightsim_grid_model = init(pp_net)  # some warnings might be issued as well as some warnings

# usage example: print some information about the powerlines
print([el.x_pu for el in lightsim_grid_model.get_lines()]) # to print the "x" for each powerlines
get_lines_status(self: lightsim2grid_cpp.GridModel) List[bool]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_load_theta(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.float64[m, 1]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_loads(self: lightsim2grid_cpp.GridModel) lightsim2grid_cpp.DataLoad

This function allows to retrieve the loads (as a lightsim2grid.elements.DataLoad object, see Elements modeled for more information)

Examples

# init the grid model
from lightsim2grid.gridmodel import init
pp_net = ...  # any pandapower grid
lightsim_grid_model = init(pp_net)  # some warnings might be issued as well as some warnings

# print the target consumption of each loads
print([el.target_p_mw for el in lightsim_grid_model.get_loads()]) # to print the active consumption for each load
get_loads_res(self: lightsim2grid_cpp.GridModel) Tuple[numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_loads_status(self: lightsim2grid_cpp.GridModel) List[bool]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_pq(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.int32[m, 1]]

Returns the ids of the buses that are labelled as “PQ”.

It returns a vector of integer.

Warning

The index are given in the “solver bus” convention. This means that it will might be the bus of the original grid model.

See also

lightsim2grid.gridmodel.GridModel.id_me_to_ac_solver() and lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me() for ways to link the “grid model” bus id to the “solver” bus id.

get_pv(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.int32[m, 1]]

Returns the ids of the buses that are labelled as “PV” (ie the buses on which at least a generator is connected.).

It returns a vector of integer.

Warning

The index are given in the “solver bus” convention. This means that it might not be the bus of the original grid model.

See also

lightsim2grid.gridmodel.GridModel.id_me_to_ac_solver() and lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me() for ways to link the “grid model” bus id to the “solver” bus id.

get_sgens_res(self: lightsim2grid_cpp.GridModel) Tuple[numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_sgens_status(self: lightsim2grid_cpp.GridModel) List[bool]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_shunt_theta(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.float64[m, 1]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_shunts(self: lightsim2grid_cpp.GridModel) lightsim2grid_cpp.DataShunt

This function allows to retrieve the shunts (as a lightsim2grid.elements.DataShunt object, see Elements modeled for more information)

Examples

# init the grid model
from lightsim2grid.gridmodel import init
pp_net = ...  # any pandapower grid
lightsim_grid_model = init(pp_net)  # some warnings might be issued as well as some warnings

# usage example: print some information about the shunts
print([el.target_q_mvar for el in lightsim_grid_model.get_shunts()]) # to print the reactive consumption for each shunts
get_shunts_res(self: lightsim2grid_cpp.GridModel) Tuple[numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_shunts_status(self: lightsim2grid_cpp.GridModel) List[bool]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_slack_ids(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.int32[m, 1]]

Returns the ids of the buses that are part of the distributed slack.

It returns a vector of integer.

Warning

The index are given in the “solver bus” convention. This means that it might not be the bus of the original grid model.

See also

lightsim2grid.gridmodel.GridModel.id_me_to_ac_solver() and lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me() for ways to link the “grid model” bus id to the “solver” bus id.

get_slack_weights(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.float64[m, 1]]

For each bus used by the solver, it outputs its participation to the distributed slack.

It’s 0 if the current bus does not participate to it, otherwise it is made of > 0. real numbers.

This vector sums to 1 and has the same size as the number of active buses on the grid.

Warning

This vector represents “solver buses” and not “original grid model buses”.

See also

lightsim2grid.gridmodel.GridModel.id_me_to_ac_solver() and lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me() for ways to link the “grid model” bus id to the “solver” bus id.

get_sn_mva(self: lightsim2grid_cpp.GridModel) float

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_solver(self: lightsim2grid_cpp.GridModel) lightsim2grid_cpp.AnySolver

Return the solver currently in use as a lightsim2grid.solver.AnySolver() instance.

get_solver_type(self: lightsim2grid_cpp.GridModel) lightsim2grid_cpp.SolverType

Return the type of the solver currently used.

This is equivalent to the get_type of the lightsim2grid.solver.AnySolver.get_type() of the solver used.

get_static_generators(self: lightsim2grid_cpp.GridModel) lightsim2grid_cpp.DataSGen

This function allows to retrieve the (more exotic) static generators (as a lightsim2grid.elements.DataSGen object, see Elements modeled for more information)

Examples

# init the grid model
from lightsim2grid.gridmodel import init
pp_net = ...  # any pandapower grid
lightsim_grid_model = init(pp_net)  # some warnings might be issued as well as some warnings

# usage example: print some information about the static generators
print([el.target_p_mw for el in lightsim_grid_model.get_static_generators()]) # to print the active production setpoint for each static generator
get_storage_theta(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.float64[m, 1]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_storages(self: lightsim2grid_cpp.GridModel) lightsim2grid_cpp.DataLoad

This function allows to retrieve the storage units (as a lightsim2grid.elements.DataLoad object, see Elements modeled for more information)

Note

We want to emphize that, as far as lightsim2grid is concerned, the storage units are modeled as loads. This is why this function will return a lightsim2grid.elements.DataLoad.

Examples

# init the grid model
from lightsim2grid.gridmodel import init
pp_net = ...  # any pandapower grid
lightsim_grid_model = init(pp_net)  # some warnings might be issued as well as some warnings

# print the target consumption of each storage units
print([el.target_p_mw for el in lightsim_grid_model.get_storages()]) # to print the active consumption for each storage unit
get_storages_res(self: lightsim2grid_cpp.GridModel) Tuple[numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_storages_status(self: lightsim2grid_cpp.GridModel) List[bool]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_trafo_status(self: lightsim2grid_cpp.GridModel) List[bool]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_trafohv_res(self: lightsim2grid_cpp.GridModel) Tuple[numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_trafohv_theta(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.float64[m, 1]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_trafolv_res(self: lightsim2grid_cpp.GridModel) Tuple[numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]], numpy.ndarray[numpy.float64[m, 1]]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_trafolv_theta(self: lightsim2grid_cpp.GridModel) numpy.ndarray[numpy.float64[m, 1]]

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

get_trafos(self: lightsim2grid_cpp.GridModel) lightsim2grid_cpp.DataTrafo

This function allows to retrieve the transformers (as a lightsim2grid.elements.DataLine object, see Elements modeled for more information)

Examples

# init the grid model
from lightsim2grid.gridmodel import init
pp_net = ...  # any pandapower grid
lightsim_grid_model = init(pp_net)  # some warnings might be issued as well as some warnings

# usage example: print some information about the trafos
print([el.x_pu for el in lightsim_grid_model.get_trafos()]) # to print the "x" for each transformer
id_ac_solver_to_me(self: lightsim2grid_cpp.GridModel) List[int]

In lightsim2grid, buses are labelled from 0 to n-1 (if n denotes the total number of buses on the grid) [this is called “grid model bus id”]

At any given point in time, some buses might be deactivated (for example because nothing is connected to them).

On the other end, the solvers need a contiguous list of only active buses (otherwise they might run into divergence issue) [this will be called “solver bus id” later on]

This function allows, for all buses exported in the solver, to retrieve which was the initial bus in the lightsim2grid.gridmodel.GridModel. It has the same size as the number of active buses on the grid.

Examples

# create a grid model
import grid2op
from lightsim2grid import LightSimBackend
env_name = ...  # eg "l2rpn_case14_sandbox"
env = grid2op.make(env_name, backend=LightSimbackend())
grid_model = env.backend._grid

id_ac_solver_to_me = grid.id_ac_solver_to_me()
# is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

# put everything to bus 2 on substation O
_ = env.step(env.action_space({"set_bus": {"substations_id": [(0, (2, 2, 2))]}}))

id_ac_solver_to_me2 = grid.id_ac_solver_to_me()
# is [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]

See also

lightsim2grid.gridmodel.GridModel.id_dc_solver_to_me for its counterpart when a dc powerflow is used

See also

lightsim2grid.gridmodel.GridModel.id_me_to_ac_solver for the “reverse” operation (given a “solver bus” id, returns the “gridmodel bus id”)

Notes

For all steps, you have the propertie that, if id_ac_solver_to_me = gridmodel.id_ac_solver_to_me() and id_me_to_ac_solver = gridmodel.id_me_to_ac_solver() and by denoting gridmodel_bus_id = np.arange(gridmodel.total_bus()) and solver_bus_id = np.arange(gridmodel.nb_bus()):

  • solver_bus_id and id_ac_solver_to_me have the same shape

  • gridmodel_bus_id and id_me_to_ac_solver have the same shape

  • solver_bus_id is shorter (or of the same length) than gridmodel_bus_id

  • the connected bus (in the grid model) are given by gridmodel_bus_id[id_ac_solver_to_me], and it gives their order

id_dc_solver_to_me(self: lightsim2grid_cpp.GridModel) List[int]

Same as lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me but only used for the DC approximation.

id_me_to_ac_solver(self: lightsim2grid_cpp.GridModel) List[int]

In lightsim2grid, buses are labelled from 0 to n-1 (if n denotes the total number of buses on the grid) [this is called “grid model bus id”]

At any given point in time, some buses might be deactivated (for example because nothing is connected to them).

On the other end, the solvers need a contiguous list of only active buses (otherwise they might run into divergence issue) [this will be called “solver bus id” later on]

This function allows, for all buses of the lightsim2grid.gridmodel.GridModel to know on which “solver bus” they are affected. It has the same size as the total number of buses on the grid. And for each of them it tells to which “solver bus” it is connected (unless there is a -1, meaning the associated bus is deactivated).

Examples

# create a grid model
import grid2op
from lightsim2grid import LightSimBackend
env_name = ...  # eg "l2rpn_case14_sandbox"
env = grid2op.make(env_name, backend=LightSimbackend())
grid_model = env.backend._grid

id_me_to_ac_solver = grid.id_me_to_ac_solver()
# is [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]

# put everything to bus 2 on substation O
_ = env.step(env.action_space({"set_bus": {"substations_id": [(0, (2, 2, 2))]}}))

id_me_to_ac_solver2 = grid.id_me_to_ac_solver()
# is [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]

See also

lightsim2grid.gridmodel.GridModel.id_me_to_dc_solver for its counterpart when a dc powerflow is used

See also

lightsim2grid.gridmodel.GridModel.id_ac_solver_to_me for the “reverse” operation (given a “solver bus” id, returns the “gridmodel bus id”)

Notes

For all steps, you have the propertie that, if id_ac_solver_to_me = gridmodel.id_ac_solver_to_me() and id_me_to_ac_solver = gridmodel.id_me_to_ac_solver() and by denoting gridmodel_bus_id = np.arange(gridmodel.total_bus()) and solver_bus_id = np.arange(gridmodel.nb_bus()):

  • solver_bus_id and id_ac_solver_to_me have the same shape

  • gridmodel_bus_id and id_me_to_ac_solver have the same shape

  • solver_bus_id is shorter (or of the same length) than gridmodel_bus_id

  • the connected bus (in the grid model) are given by gridmodel_bus_id[id_ac_solver_to_me], and it gives their order

id_me_to_dc_solver(self: lightsim2grid_cpp.GridModel) List[int]

Same as lightsim2grid.gridmodel.GridModel.id_me_to_ac_solver but only used for the DC approximation.

init_bus(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.float64[m, 1]], arg1: int, arg2: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

init_generators(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.float64[m, 1]], arg1: numpy.ndarray[numpy.float64[m, 1]], arg2: numpy.ndarray[numpy.float64[m, 1]], arg3: numpy.ndarray[numpy.float64[m, 1]], arg4: numpy.ndarray[numpy.int32[m, 1]]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

init_loads(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.float64[m, 1]], arg1: numpy.ndarray[numpy.float64[m, 1]], arg2: numpy.ndarray[numpy.int32[m, 1]]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

init_powerlines(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.float64[m, 1]], arg1: numpy.ndarray[numpy.float64[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.int32[m, 1]], arg4: numpy.ndarray[numpy.int32[m, 1]]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

init_sgens(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.float64[m, 1]], arg1: numpy.ndarray[numpy.float64[m, 1]], arg2: numpy.ndarray[numpy.float64[m, 1]], arg3: numpy.ndarray[numpy.float64[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.float64[m, 1]], arg6: numpy.ndarray[numpy.int32[m, 1]]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

init_shunt(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.float64[m, 1]], arg1: numpy.ndarray[numpy.float64[m, 1]], arg2: numpy.ndarray[numpy.int32[m, 1]]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

init_storages(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.float64[m, 1]], arg1: numpy.ndarray[numpy.float64[m, 1]], arg2: numpy.ndarray[numpy.int32[m, 1]]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

init_trafo(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.float64[m, 1]], arg1: numpy.ndarray[numpy.float64[m, 1]], arg2: numpy.ndarray[numpy.complex128[m, 1]], arg3: numpy.ndarray[numpy.float64[m, 1]], arg4: numpy.ndarray[numpy.float64[m, 1]], arg5: numpy.ndarray[numpy.float64[m, 1]], arg6: List[bool], arg7: numpy.ndarray[numpy.int32[m, 1]], arg8: numpy.ndarray[numpy.int32[m, 1]]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

nb_bus(self: lightsim2grid_cpp.GridModel) int

Returns (>0 integer) the number of connected buses on the powergrid (ignores the disconnected bus).

reactivate_bus(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

reactivate_gen(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

reactivate_load(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

reactivate_powerline(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

reactivate_result_computation(self: lightsim2grid_cpp.GridModel) None

Allows to reactivate the computation of the flows, reactive power absorbed by generators etc. when they are needed again after having been deactivated.

reactivate_sgen(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

reactivate_shunt(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

reactivate_storage(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

reactivate_trafo(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

remove_gen_slackbus(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_gen_pos_topo_vect(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_gen_to_subid(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_init_vm_pu(self: lightsim2grid_cpp.GridModel, arg0: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_line_ex_pos_topo_vect(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_line_ex_to_subid(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_line_or_pos_topo_vect(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_line_or_to_subid(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_load_pos_topo_vect(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_load_to_subid(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_n_sub(self: lightsim2grid_cpp.GridModel, arg0: int) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_sn_mva(self: lightsim2grid_cpp.GridModel, arg0: float) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_storage_pos_topo_vect(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_storage_to_subid(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_trafo_hv_pos_topo_vect(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_trafo_hv_to_subid(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_trafo_lv_pos_topo_vect(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

set_trafo_lv_to_subid(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

tell_topo_changed(self: lightsim2grid_cpp.GridModel) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

total_bus(self: lightsim2grid_cpp.GridModel) int

Returns (>0 integer) the total number of buses in the powergrid (both connected and disconnected)

unset_topo_changed(self: lightsim2grid_cpp.GridModel) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

update_bus_status(self: lightsim2grid_cpp.GridModel, arg0: int, arg1: numpy.ndarray[bool[m, 2], flags.writeable, flags.c_contiguous]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

update_gens_p(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[bool[m, 1], flags.writeable], arg1: numpy.ndarray[numpy.float32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

update_gens_v(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[bool[m, 1], flags.writeable], arg1: numpy.ndarray[numpy.float32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

update_loads_p(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[bool[m, 1], flags.writeable], arg1: numpy.ndarray[numpy.float32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

update_loads_q(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[bool[m, 1], flags.writeable], arg1: numpy.ndarray[numpy.float32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

update_storages_p(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[bool[m, 1], flags.writeable], arg1: numpy.ndarray[numpy.float32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

update_topo(self: lightsim2grid_cpp.GridModel, arg0: numpy.ndarray[bool[m, 1], flags.writeable], arg1: numpy.ndarray[numpy.int32[m, 1], flags.writeable]) None

INTERNAL

Warning

/!\ Internal, do not use unless you know what you are doing /!\

This is used as part of a dedicated code for lightsim2grid.LightSimBackend.LightSimBackend

lightsim2grid.gridmodel.init(pp_net)[source]

Convert a pandapower network as input into a GridModel.

This can fail to convert the grid and still not throw any error, use with care (for example, you can run a powerflow after this conversion, run a powerflow with pandapower, and compare the results to make sure they match !)

Cases for which conversion is not possible include, but are not limited to:

  • the pandapower grid has 3 winding transformers

  • the pandapower grid has xwards

  • the pandapower grid has dcline

  • the pandapower grid has switch, motor, assymetric loads, etc.

  • the pandapower grid any parrallel “elements” (at least one of the column “parrallel” is not 1)

  • some g_us_per_km for some lines are not zero ? TODO not sure if that is still the case !

  • some p_mw for some shunts are not zero

if you really need any of the above, please submit a github issue and we will work on their support.

This conversion has been extensively studied for the case118() of pandapower.networks and should work really well for this grid. Actually, this grid is used for testing the GridModel class.

Parameters

pp_net (pandapower.grid) – The initial pandapower network you want to convert

Returns

model – The initialize gridmodel

Return type

lightsim2grid.gridmodel.GridModel