### Start Using LightSim2Grid with Grid2op Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/quickstart.rst.txt This example demonstrates how to initialize a Grid2op environment with the LightSimBackend for powerflow computations. Ensure Grid2op and LightSimBackend are imported. ```python import grid2op from lightsim2grid.LightSimBackend import LightSimBackend from grid2op.Agent import RandomAgent # create an environment env_name = "l2rpn_case14_sandbox" # for example, other environments might be usable env = grid2op.make(env_name, backend=LightSimBackend() # this is the only change you have to make! ) # As of now, you can do whatever you want with this grid2op environment # for example... # create an agent my_agent = RandomAgent(env.action_space) # proceed as you would any open ai gym loop nb_episode = 10 for _ in range(nb_episde): # you perform in this case 10 different episodes obs = env.reset() reward = env.reward_range[0] done = False while not done: # here you loop on the time steps: at each step your agent receive an observation # takes an action # and the environment computes the next observation that will be used at the next step. act = agent.act(obs, reward, done) obs, reward, done, info = env.step(act) # the `LightSimBackend` will be used to carry out the powerflow computation instead # of the default grid2op `PandaPowerBackend` ``` -------------------------------- ### Install Benchmark Dependencies Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/benchmarks_dc.rst.txt Installs the necessary packages for running benchmarks, including grid2op and numba. Ensure lightsim2grid is already installed. ```bash pip install -r req_benchmarks.txt ``` -------------------------------- ### Install LightSim2Grid using pip Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/quickstart.rst.txt Use this command for a standard installation of the lightsim2grid package from PyPI. ```bash pip install lightsim2grid ``` -------------------------------- ### Install lightsim2grid Python Package Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/install_from_source.rst.txt Install the necessary pybind11 dependency and then compile and install the lightsim2grid Python package using pip. ```bash # install the dependency pip install -U pybind11 # compile and install the python package pip install -U . ``` -------------------------------- ### Example Docker Container Status Output Source: https://lightsim2grid.readthedocs.io/en/latest/quickstart.html An example of the expected output from the 'docker ps' command, showing a running container. ```text CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 89750964ca55 bdonnot/lightsim2grid "python3" 5 seconds ago Up 4 seconds 80/tcp lightsim_container ``` -------------------------------- ### Basic Security Analysis Setup Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/security_analysis.rst.txt Initialize SecurityAnalysis with a grid2op environment and add contingencies. This snippet shows the basic setup for performing security analysis and retrieving power flow results. ```python import grid2op from lightsim2grid import SecurityAnalysis from lightsim2grid import LightSimBackend env_name = ... env = grid2op.make(env_name, backend=LightSimBackend()) security_analysis = SecurityAnalysis(env) security_analysis.add_multiple_contingencies(...) # or security_analysis.add_single_contingency(...) res_p, res_a, res_v = security_analysis.get_flows() ``` -------------------------------- ### Install lightsim2grid Package Source: https://lightsim2grid.readthedocs.io/en/latest/install_from_source.html After installing dependencies, compile and install the lightsim2grid package itself using pip. ```bash pip install -U . ``` -------------------------------- ### Build and Install SuiteSparse with CMake Source: https://lightsim2grid.readthedocs.io/en/latest/install_from_source.html Build and install SuiteSparse using CMake. This sequence of commands configures the build, compiles the release version, and installs it to a specified directory. ```bash mkdir build and cd there: cd build cmake -DCMAKE_INSTALL_PREFIX=..built -DCMAKE_BUILD_TYPE=Release .. cmake –build . –config Release cmake –build . –config Release –target install ``` -------------------------------- ### Example Docker Run Command with Specific Path Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/quickstart.rst.txt An example of the docker run command with a placeholder local path replaced with a Linux-style directory. ```bash docker run -t -d -p 8888:8888 --name lightsim_container -v /home/MyName/L2RPNCompeitionCode:/L2RPNCompeitionCode -w /L2RPNCompeitionCode bdonnot/lightsim2grid ``` -------------------------------- ### Initialize LightSimBackend with pypowsybl Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/lightsimbackend.rst.txt Demonstrates how to create a grid2op environment using the LightSimBackend with the pypowsybl loader method. Ensure pypowsybl is installed. ```python import grid2op from lightsim2grid.LightSimBackend import LightSimBackend from grid2op.Agent import RandomAgent # create an environment env_with_iidm_as_the_grid_description = ... env = grid2op.make(env_name, backend=LightSimBackend(loader_method="pypowsybl") ) ``` -------------------------------- ### Install LightSim2Grid Package from Source Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/quickstart.rst.txt Compile and install the LightSim2Grid Python package using pip. Ensure you use the correct Python command for your system. ```bash # compile and install the python package python3 -m pip install -U . ``` -------------------------------- ### Benchmark Output Example Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/time_series.rst.txt An example of the output generated by the time series benchmark script, showing computation times and speedups compared to raw grid2op. ```bash For environment: l2rpn_neurips_2020_track2 Total time spent in "computer" to solve everything: 0.05s (12277 pf / s), 0.08 ms / pf) - time to pre process the injections: 0.00s - time to perform powerflows: 0.05s (12697 pf / s, 0.08 ms / pf) In addition, it took 0.00 s to retrieve the current from the complex voltages (in total 11681.3 pf /s, 0.09 ms / pf) Comparison with raw grid2op timings It took grid2op (with lightsim2grid): 0.66s to perform the same computation This is a 13.4 speed up from TimeSerie over raw grid2op (lightsim2grid) It took grid2op (with pandapower): 14.94s to perform the same computation This is a 302.9 speed up from TimeSerie over raw grid2op (pandapower) All results match ! ``` -------------------------------- ### Initialize and Use AnySolver Wrapper Source: https://lightsim2grid.readthedocs.io/en/latest/solvers.html Demonstrates how to initialize the LightSimBackend and obtain an AnySolver instance to interact with different powerflow solvers. Shows how to get the solver type and Jacobian matrix. ```python import grid2op from lightsim2grid import LightSimBackend env_name = ... # eg. "l2rpn_case14_test" env = grid2op.make(env_name, backend=LightSimBackend()) anysolver = env.backend._grid.get_solver() anysolver.get_type() # type of solver currently used anysolver.get_J() # current Jacobian matrix, if available by the method ``` -------------------------------- ### Using LightSimBackend with grid2op Source: https://lightsim2grid.readthedocs.io/en/latest/lightsimbackend.html This example demonstrates how to initialize a grid2op environment with the LightSimBackend. It shows the minimal change required to use the lightsim2grid simulator transparently within a standard grid2op loop. ```python import grid2op from lightsim2grid.LightSimBackend import LightSimBackend from grid2op.Agent import RandomAgent # create an environment env_name = "rte_case14_realistic" # for example, other environments might be usable env = grid2op.make(env_name, backend=LightSimBackend() # this is the only change you have to make! ) # create an agent my_agent = RandomAgent(env.action_space) # proceed as you would any open ai gym loop nb_episode = 10 for _ in range(nb_episde): # you perform in this case 10 different episodes obs = env.reset() reward = env.reward_range[0] done = False while not done: # here you loop on the time steps: at each step your agent receive an observation # takes an action # and the environment computes the next observation that will be used at the next step. act = agent.act(obs, reward, done) obs, reward, done, info = env.step(act) # the `LightSimBackend` will be used to carry out the powerflow computation instead # of the default grid2op `PandaPowerBackend` ``` -------------------------------- ### Retrieving Generator ID Source: https://lightsim2grid.readthedocs.io/en/latest/gridmodel.html Get the unique ID of a generator element within the grid model. This example demonstrates accessing the ID for the first generator. ```python 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 ``` -------------------------------- ### Get Shunt Information from GridModel Source: https://lightsim2grid.readthedocs.io/en/latest/gridmodel.html Retrieves shunt elements from the grid model. The shunts are returned as a `ShuntContainer` object. This example shows how to print the reactive power consumption for each shunt. ```python # 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 ``` -------------------------------- ### Basic Security Analysis Setup and Usage Source: https://lightsim2grid.readthedocs.io/en/latest/security_analysis.html Demonstrates how to initialize SecurityAnalysis, add contingencies, and retrieve power flow results. Ensure you have grid2op and LightSimBackend configured. ```python import grid2op from lightsim2grid import SecurityAnalysis from lightsim2grid import LightSimBackend env_name = ... env = grid2op.make(env_name, backend=LightSimBackend()) security_analysis = SecurityAnalysis(env) security_analysis.add_multiple_contingencies(...) # or security_analysis.add_single_contingency(...) res_p, res_a, res_v = security_analysis.get_flows() # in this results, then # res_p[row_id] will be the active power flows (origin side), on all powerlines corresponding to the `row_id` contingency. # res_a[row_id] will be the current flows, on all powerlines corresponding to step "row_id" # res_v[row_id] will be the complex voltage, on all bus of the grid corresponding to the `row_id` contingency. # you can retrieve which contingency is id'ed `row_id` with `security_analysis.contingency_order[row_id]` ``` -------------------------------- ### Install pybind11 Dependency Source: https://lightsim2grid.readthedocs.io/en/latest/install_from_source.html Before installing the package, ensure pybind11 is installed or updated to the latest version. ```bash pip install -U pybind11 ``` -------------------------------- ### Create and Use a Regular grid2op Environment with LightSimBackend Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/use_with_grid2op.rst.txt Demonstrates how to create a standard grid2op environment using `grid2op.make` and specifying `LightSimBackend()` for powerflow computations. This setup allows for transparent use within a typical grid2op agent-environment loop. ```python import grid2op from lightsim2grid.LightSimBackend import LightSimBackend from grid2op.Agent import RandomAgent # create an environment env_name = "rte_case14_realistic" # for example, other environments might be usable env = grid2op.make(env_name, backend=LightSimBackend() # this is the only change you have to make! ) # and use this as any grid2op environment, for example # create an agent my_agent = RandomAgent(env.action_space) # proceed as you would any open ai gym loop nb_episode = 10 for _ in range(nb_episde): # you perform in this case 10 different episodes obs = env.reset() reward = env.reward_range[0] done = False while not done: # here you loop on the time steps: at each step your agent receive an observation # takes an action # and the environment computes the next observation that will be used at the next step. act = agent.act(obs, reward, done) obs, reward, done, info = env.step(act) # the `LightSimBackend` will be used to carry out the powerflow computation instead # of the default grid2op `PandaPowerBackend` ``` -------------------------------- ### Basic LightSimBackend Integration with grid2op Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/lightsimbackend.rst.txt Demonstrates how to create a grid2op environment using the LightSimBackend. This is the primary method for integrating the simulator. ```python import grid2op from lightsim2grid.LightSimBackend import LightSimBackend from grid2op.Agent import RandomAgent # create an environment env_name = "rte_case14_realistic" # for example, other environments might be usable env = grid2op.make(env_name, backend=LightSimBackend() # this is the only change you have to make! ) # create an agent my_agent = RandomAgent(env.action_space) # proceed as you would any open ai gym loop nb_episode = 10 for _ in range(nb_episde): # you perform in this case 10 different episodes obs = env.reset() reward = env.reward_range[0] done = False while not done: # here you loop on the time steps: at each step your agent receive an observation # takes an action # and the environment computes the next observation that will be used at the next step. act = agent.act(obs, reward, done) obs, reward, done, info = env.step(act) # the `LightSimBackend` will be used to carry out the powerflow computation instead # of the default grid2op `PandaPowerBackend` ``` -------------------------------- ### Creating LightSimBackend with FDPF_BX_SparseLUSolver Source: https://lightsim2grid.readthedocs.io/en/latest/solvers.html Shows how to instantiate LightSimBackend with a specific solver type, FDPF_SparseLU, during creation. ```python LightSimBackend(solver_type=lightsim2grid.solver.FDPF_SparseLU) ``` -------------------------------- ### Initialize FDPF_XB_SparseLUSolver Source: https://lightsim2grid.readthedocs.io/en/latest/solvers.html Demonstrates how to set the solver type to FDPF_SparseLU using either the backend or directly during LightSimBackend initialization. ```python env_lightsim.backend.set_solver_type(lightsim2grid.solver.FDPF_SparseLU) LightSimBackend(solver_type=lightsim2grid.solver.FDPF_SparseLU) ``` -------------------------------- ### Install pybind11 on Linux/macOS Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/quickstart.rst.txt Install the pybind11 package using pip for C++ integration with Python on Linux or macOS systems. ```bash python3 -m pip install pybind11 ``` -------------------------------- ### Regular grid2op Environment with LightSimBackend Source: https://lightsim2grid.readthedocs.io/en/latest/use_with_grid2op.html Demonstrates how to create a standard grid2op environment using LightSimBackend for transparent power flow calculations. This is the primary method for integrating LightSimBackend into grid2op. ```python import grid2op from lightsim2grid.LightSimBackend import LightSimBackend from grid2op.Agent import RandomAgent # create an environment env_name = "rte_case14_realistic" # for example, other environments might be usable env = grid2op.make(env_name, backend=LightSimBackend() # this is the only change you have to make! ) # and use this as any grid2op environment, for example # create an agent my_agent = RandomAgent(env.action_space) # proceed as you would any open ai gym loop nb_episode = 10 for _ in range(nb_episde): # you perform in this case 10 different episodes obs = env.reset() reward = env.reward_range[0] done = False while not done: # here you loop on the time steps: at each step your agent receive an observation # takes an action # and the environment computes the next observation that will be used at the next step. act = agent.act(obs, reward, done) obs, reward, done, info = env.step(act) # the `LightSimBackend` will be used to carry out the powerflow computation instead # of the default grid2op `PandaPowerBackend` ``` -------------------------------- ### Initialize and Solve with DCSolver Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/use_solver.rst.txt Demonstrates how to initialize a DC solver and use it to solve the power flow equations. Ensure necessary Ybus, V0, and Sbus data are retrieved before calling the solve method. ```python from lightsim2grid.solver import DCSolver # or any of the names above # retrieve some Ybus, V0, etc. as above dc_solver = DCSolver() converged = dc_solver.solve(Ybus, V0, Sbus, ref, slack_weights, pv, pq, max_it, tol) # process the results as above ``` -------------------------------- ### Get Bus Injected Power Source: https://lightsim2grid.readthedocs.io/en/latest/time_series.html Get the complex power injected at each bus, identified by its solver ID, within the power grid. ```python s_buses = ts_cpp.get_sbuses() print(f"Injected power at buses: {s_buses}") ``` -------------------------------- ### Reproduce Benchmark Results Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/comparison_with_pypowsybl.rst.txt Navigate to the benchmarks directory and run the comparison script with a specified case name. ```bash cd benchmarks python compare_lightsim2grid_pypowsybl.py --case $CASE_NAME ``` -------------------------------- ### Install pybind11 on Windows Source: https://lightsim2grid.readthedocs.io/en/latest/quickstart.html Use this command to install the pybind11 Python package on Windows systems. The exact command to invoke Python may vary. ```bash py -m pip install pybind11 ``` ```bash python3 -m pip install pybind11 ``` -------------------------------- ### Initialize GridModel via LightSimBackend Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/gridmodel.rst.txt A recommended way to initialize the GridModel by creating a lightsim2grid environment using LightSimBackend. This approach is more tested. ```python 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 ``` -------------------------------- ### Run Grid Size Benchmark Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/benchmarks_grid_sizes.rst.txt Navigate to the benchmarks folder and execute the benchmark script. Results are for illustration and may vary. ```bash cd ../benchmarks python benchmark_grid_size.py ``` -------------------------------- ### Install pybind11 on Windows (Option 1) Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/quickstart.rst.txt Install the pybind11 package using pip on Windows. This command attempts to use 'py' to invoke Python. ```bash py -m pip install pybind11 ``` -------------------------------- ### Initialize Grid and Backend Actions Source: https://lightsim2grid.readthedocs.io/en/latest/_modules/lightsim2grid/lightSimBackend.html Initializes the grid, clears backend-specific attributes, and sets up the backend action class. Handles legacy grid2op versions if necessary. ```python self.init_pp_backend.__class__ = type(self.init_pp_backend).init_grid(type(self)) from lightsim2grid._utils import _DoNotUseAnyanywherePandaPowerBackend # lazy import _DoNotUseAnyanywherePandaPowerBackend._clear_grid_dependant_class_attributes() self._backend_action_class = _BackendAction.init_grid(type(self)) self._init_action_to_set = self._backend_action_class() try: _init_action_to_set = self.get_action_to_set() except TypeError: # I am in legacy grid2op version... _init_action_to_set = _dont_use_get_action_to_set_legacy(self) self._init_action_to_set += _init_action_to_set if self.prod_pu_to_kv is not None: assert np.isfinite(self.prod_pu_to_kv).all() if self.load_pu_to_kv is not None: assert np.isfinite(self.load_pu_to_kv).all() if self.lines_or_pu_to_kv is not None: assert np.isfinite(self.lines_or_pu_to_kv).all() if self.lines_ex_pu_to_kv is not None: assert np.isfinite(self.lines_ex_pu_to_kv).all() if self.__has_storage and self.n_storage > 0 and self.storage_pu_to_kv is not None: assert np.isfinite(self.storage_pu_to_kv).all() ``` -------------------------------- ### available_solvers Source: https://lightsim2grid.readthedocs.io/en/latest/gridmodel.html Returns a list of available solver types for the current lightsim2grid installation. ```APIDOC ## available_solvers ### Description Return the list of solver available on the current lightsim2grid installation. ### Method `available_solvers(self) -> list[lightsim2grid_cpp.SolverType]` ### Parameters None ### Response #### Success Response (200) A list of `lightsim2grid.solver.SolverType` objects. #### Response Example ```json { "example": [ "LS", "MAJI" ] } ``` ``` -------------------------------- ### Initialize lightSimBackend with Loader Method Source: https://lightsim2grid.readthedocs.io/en/latest/_modules/lightsim2grid/lightSimBackend.html Initializes the lightSimBackend based on the specified loader method. It sets the supported grid format and raises an error for unknown methods. Includes lazy loading of dependencies and compatibility checks for grid2op versions. ```python from lightsim2grid._utils import _DoNotUseAnywherePandaPowerBackend from grid2op.Space import GridObjects import grid2op from packaging import version # Assuming loader_method is defined elsewhere # Example: loader_method = "pandapower" self.can_output_theta = True self.supported_grid_format = None if loader_method == "pandapower": self.supported_grid_format = ("json", ) # new in 0.8.0 elif loader_method == "pypowsybl": self.supported_grid_format = ("xiidm", ) # new in 0.8.0 else: raise BackendError(f"Uknown loader_method : '{loader_method}'") self.__has_storage = hasattr(GridObjects, "n_storage") if not self.__has_storage: warnings.warn("Please upgrade your grid2op to >= 1.5.0. You are using a backward compatibility " "feature that will be removed in further lightsim2grid version.") grid2op_min_shunt_cls_properly_handled = "1.5.0" # Example value, replace with actual if available if version.parse(grid2op.__version__) < grid2op_min_shunt_cls_properly_handled: warnings.warn(f"You are using a legacy grid2op version. It is not possible to deactivate the shunts in lightsim2grid. " f"Please upgrade to grid2op >= {grid2op_min_shunt_cls_properly_handled}") self.shunts_data_available = True type(self).shunts_data_available = True self.nb_bus_total = None self.initdc = True self.__nb_powerline = None self.__nb_bus_before = None self._init_bus_load = None self._init_bus_gen = None self._init_bus_lor = None self._init_bus_lex = None self._big_topo_to_obj = None self.nb_obj_per_bus = None self._timer_preproc = 0. self._timer_postproc = 0. self._timer_solver = 0. self._timer_read_data_back = 0. self._timer_fetch_data_cpp = 0. self._timer_apply_act = 0. self.next_prod_p = None self.topo_vect = None self.shunt_topo_vect = None try: self.init_pp_backend = _DoNotUseAnywherePandaPowerBackend(with_numba=False) except TypeError as exc_: self.init_pp_backend = _DoNotUseAnywherePandaPowerBackend() self.V = None self.prod_pu_to_kv = None self.load_pu_to_kv = None self.lines_or_pu_to_kv = None self.lines_ex_pu_to_kv = None self.storage_pu_to_kv = None self.p_or = None self.q_or = None self.v_or = None self.a_or = None self.p_ex = None self.q_ex = None self.v_ex = None self.a_ex = None self.load_p = None self.load_q = None self.load_v = None self.prod_p = None self.prod_q = None self.prod_v = None self.storage_p = None self.storage_q = None self.storage_v = None # shunts self.sh_p = None self.sh_q = None self.sh_v = None self.sh_theta = None self.sh_bus = None # voltage angle self.line_or_theta = None self.line_ex_theta = None self.load_theta = None self.gen_theta = None self.storage_theta = None self.thermal_limit_a = None self.dim_topo = -1 self._init_action_to_set = None self._backend_action_class = None self.cst_1 = dt_float(1.0) # Assuming dt_float is defined elsewhere self.__me_at_init = None self.__init_topo_vect = None self.available_solvers = [] self.comp_time = 0. self.timer_gridmodel_xx_pf = 0. self._timer_postproc = 0. self._timer_preproc = 0. self._timer_solver = 0. self._timer_read_data_back = 0. self._timer_fetch_data_cpp = 0. self._timer_apply_act = 0. ``` -------------------------------- ### Get Voltages Source: https://lightsim2grid.readthedocs.io/en/latest/time_series.html Retrieve the complex voltage angles at each bus within the power grid. ```python voltages = ts_cpp.get_voltages() print(f"Voltages: {voltages}") ``` -------------------------------- ### Initialize LightSimBackend with Grid Information Source: https://lightsim2grid.readthedocs.io/en/latest/_modules/lightsim2grid/lightSimBackend.html Initializes the LightSimBackend by extracting various grid parameters from the provided power system backend. It handles different grid2op versions and includes optional storage-related attributes if available. ```python pp_cls = type(self.init_pp_backend) if pp_cls.n_line <= -1: warnings.warn("You are using a legacy (quite old now) grid2op version. Please upgrade it.") pp_cls = self.init_pp_backend self.n_line = pp_cls.n_line self.n_gen = pp_cls.n_gen self.n_load = pp_cls.n_load self.n_sub = pp_cls.n_sub self.sub_info = pp_cls.sub_info self.dim_topo = pp_cls.dim_topo self.load_to_subid = pp_cls.load_to_subid self.gen_to_subid = pp_cls.gen_to_subid self.line_or_to_subid = pp_cls.line_or_to_subid self.line_ex_to_subid = pp_cls.line_ex_to_subid self.load_to_sub_pos = pp_cls.load_to_sub_pos self.gen_to_sub_pos = pp_cls.gen_to_sub_pos self.line_or_to_sub_pos = pp_cls.line_or_to_sub_pos self.line_ex_to_sub_pos = pp_cls.line_ex_to_sub_pos self.name_gen = pp_cls.name_gen self.name_load = pp_cls.name_load self.name_line = pp_cls.name_line self.name_sub = pp_cls.name_sub self.prod_pu_to_kv = self.init_pp_backend.prod_pu_to_kv self.load_pu_to_kv = self.init_pp_backend.load_pu_to_kv self.lines_or_pu_to_kv = self.init_pp_backend.lines_or_pu_to_kv self.lines_ex_pu_to_kv = self.init_pp_backend.lines_ex_pu_to_kv # TODO storage check grid2op version and see if storage is available ! if self.__has_storage: self.n_storage = pp_cls.n_storage self.storage_to_subid = pp_cls.storage_to_subid self.storage_pu_to_kv = self.init_pp_backend.storage_pu_to_kv self.name_storage = pp_cls.name_storage self.storage_to_sub_pos = pp_cls.storage_to_sub_pos self.storage_type = pp_cls.storage_type self.storage_Emin = pp_cls.storage_Emin self.storage_Emax = pp_cls.storage_Emax self.storage_max_p_prod = pp_cls.storage_max_p_prod self.storage_max_p_absorb = pp_cls.storage_max_p_absorb self.storage_marginal_cost = pp_cls.storage_marginal_cost self.storage_loss = pp_cls.storage_loss self.storage_discharging_efficiency = pp_cls.storage_discharging_efficiency self.storage_charging_efficiency = pp_cls.storage_charging_efficiency self.nb_bus_total = self.init_pp_backend._grid.bus.shape[0] self.thermal_limit_a = copy.deepcopy(self.init_pp_backend.thermal_limit_a) ``` -------------------------------- ### FDPF_BX_NICSLUSolver: Get Number of Iterations Source: https://lightsim2grid.readthedocs.io/en/latest/solvers.html Returns the number of iterations performed by the solver. This will be a positive integer. ```python get_nb_iter(_self : lightsim2grid_cpp.FDPF_BX_NICSLUSolver_) → int ``` -------------------------------- ### Get Solver Type Source: https://lightsim2grid.readthedocs.io/en/latest/solvers.html Retrieves the identifier for the current powerflow solver being used by the AnySolver wrapper. ```python anysolver.get_type() ``` -------------------------------- ### Initialize NICSLUSolver at Creation Time Source: https://lightsim2grid.readthedocs.io/en/latest/solvers.html Shows how to specify the NICSLU solver type directly during the LightSimBackend creation. ```python LightSimBackend(solver_type=lightsim2grid.solver.NICSLU) ``` -------------------------------- ### Getting Current Solver Type Source: https://lightsim2grid.readthedocs.io/en/latest/_modules/lightsim2grid/lightSimBackend.html Retrieves the current solver type used by the grid model. ```python def get_current_solver_type(self) -> SolverType: return self.__current_solver_type ``` -------------------------------- ### Get Line Flow Source: https://lightsim2grid.readthedocs.io/en/latest/_modules/lightsim2grid/lightSimBackend.html Returns the line flow information. This is typically represented by the 'a_or' attribute. ```python def get_line_flow(self) -> np.ndarray: return self.a_or ``` -------------------------------- ### Direct Solver API Usage Source: https://lightsim2grid.readthedocs.io/en/latest/_sources/use_solver.rst.txt This example demonstrates how to use the raw Python class for solvers, which is not recommended for general use. It shows how to instantiate a solver and call its solve method with various power system parameters. ```python from lightsim2grid.solver import ASolverAvailable Ybus = ... # a csc sparse matrix (it's really important that it is a csc and not a csr !) V0 = ... # a complex vector (initial guess) Sbus = ... # a complex vector (power injected at each bus) ref = ... # a vector of integer giving the bus id of the slack buses slack_weight = ... # a vector of real number giving the weights associated to each slack bus pv = ... # a vector of integers giving the bus id of the PV bus pq = ... # a vector of integers giving the bus id of the PQ bus max_it = ... # a > 0 integer maximum number of iterations the solver is allowed to perform tol = ... # a > 0. real number giving the maximum KCL violation allowed for a all nodes solver = ASolverAvailable() converged = solver.solve(Ybus, V0, Sbus, ref, slack_weights, pv, pq, max_it, tol) # to retrieve the voltages related information (in case converged is True) solver.get_Va() # voltage magnitude solver.get_Vm() # voltage angle solver.get_V() # complex voltage # for compatible solvers solver.get_J() # see documentation of the `newton_pf` function for more information about the shape of J. # some other usefull information solver.get_nb_iter() # return the number of iteration performed solver.get_timers() # some execution times for some function (TODO DOC) sovler.get_error() # the id of the error encountered (TODO DOC) sovler.converged() # equal to the boolean `converged` above ``` -------------------------------- ### Get Current Solver Type Source: https://lightsim2grid.readthedocs.io/en/latest/time_series.html Return the type of the solver that is currently being used for powerflow computations. ```python solver_type = ts_cpp.get_solver_type() print(f"Current solver type: {solver_type}") ``` -------------------------------- ### FDPF_BX_NICSLUSolver: Get Error Code Source: https://lightsim2grid.readthedocs.io/en/latest/solvers.html Retrieves the error code from the solver. A value of 0 indicates no error. ```python get_error(_self : lightsim2grid_cpp.FDPF_BX_NICSLUSolver_) → lightsim2grid_cpp.ErrorType ``` -------------------------------- ### Running Time Series Benchmark Source: https://lightsim2grid.readthedocs.io/en/latest/time_series.html Execute the time series benchmark script from the examples directory. This script compares the performance of lightsim2grid against raw grid2op and pandapower. ```bash cd examples python3 time_serie.py ``` -------------------------------- ### Clone LightSim2Grid Repository and Initialize Submodules Source: https://lightsim2grid.readthedocs.io/en/latest/quickstart.html This sequence of commands clones the LightSim2Grid repository, navigates into the directory, optionally sets up a virtual environment, and initializes/updates git submodules for dependencies like SparseSuite and Eigen. ```bash git clone https://github.com/Grid2Op/lightsim2grid.git cd lightsim2grid # it is recommended to do a python virtual environment python -m virtualenv venv # optional source venv/bin/activate # optional # retrieve the code of SparseSuite and Eigen (dependencies, mandatory) git submodule init git submodule update ``` -------------------------------- ### Get Number of Iterations Source: https://lightsim2grid.readthedocs.io/en/latest/solvers.html Returns the number of iterations performed by the solver. This value must be a positive integer. ```python get_nb_iter(self) | Returns the number of iterations effectively performed by the solver (> 0 integer). ``` -------------------------------- ### Get Current Solver Type Source: https://lightsim2grid.readthedocs.io/en/latest/solvers.html Retrieves the type of the currently used solver. This returns an instance of `lightsim2grid.solver.SolverType`. ```python get_type(_self : lightsim2grid_cpp.AnySolver_) ```