Code Reference
toop-engine-benchmark.benchmark_toop.main
#
Hydra entry point benchmarking a single grid.
Configuration groups expected: grid: provides grid_file (+ optional grid_type) ga_config: genetic algorithm parameters lf_config: lightflow / solver parameters area_settings: voltage and area constraints
The grid config should be provided via group grid=config_grid_node_breaker or similar.
Source code in toop-engine-benchmark/benchmark_toop.py
toop-engine-benchmark.assess_benchmarks.main
#
Run benchmark assessment based on configuration.
| PARAMETER | DESCRIPTION |
|---|---|
cfg
|
Hydra configuration containing root path, save path, and print options.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Assessment report dictionary. |
Source code in toop-engine-benchmark/assess_benchmarks.py
toop_engine_topology_optimizer.benchmark.benchmark_utils
#
A module that contains methods to run the full end-to-end pipeline from grid file to optimization results.
Note that these methods are simply wrappers to use existing functionality in a sequence.
PipelineConfig
dataclass
#
PipelineConfig(
root_path=Path("./"),
iteration_name="",
file_name="grid.xiidm",
static_info_relpath=PREPROCESSING_PATHS[
"static_information_file_path"
],
initial_topology_subpath=PREPROCESSING_PATHS[
"initial_topology_path"
],
omp_num_threads=1,
num_cuda_devices=1,
grid_type="powsybl",
)
Configuration class for the pipeline, specifying file paths and runtime parameters.
root_path
class-attribute
instance-attribute
#
Root directory for data storage.
iteration_name
class-attribute
instance-attribute
#
Name of the current iteration or experiment.
file_name
class-attribute
instance-attribute
#
Name of the primary data file, a ZIP archive for CGMES or an xiidm file.
static_info_relpath
class-attribute
instance-attribute
#
static_info_relpath = PREPROCESSING_PATHS[
"static_information_file_path"
]
Relative path to the static information file, as defined in PREPROCESSING_PATHS.
initial_topology_subpath
class-attribute
instance-attribute
#
initial_topology_subpath = PREPROCESSING_PATHS[
"initial_topology_path"
]
Relative path to the initial topology file, as defined in PREPROCESSING_PATHS.
omp_num_threads
class-attribute
instance-attribute
#
Number of OpenMP threads to use for parallel processing.
num_cuda_devices
class-attribute
instance-attribute
#
Number of CUDA devices (GPUs) to utilize.
grid_type
class-attribute
instance-attribute
#
Type of grid model being used (power system analysis libraries).
set_environment_variables
#
Set environment variables for OpenMP, CUDA, and XLA based on the provided configuration.
| PARAMETER | DESCRIPTION |
|---|---|
cfg
|
Configuration object containing the following keys: - omp_num_threads (int): Number of OpenMP threads. - num_cuda_devices (int): Number of CUDA devices. - xla_force_host_platform_device_count (Optional[int]): Number of XLA host platform devices.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
|
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
run_task_process
#
Execute a task process based on the provided configuration.
This function initializes parameters for a genetic algorithm and a load flow solver from the given configuration, constructs command-line arguments, and runs the main optimization function. If a connection object is provided, the result is sent through the connection; otherwise, the result is returned directly. Args: cfg (DictConfig): Configuration object containing parameters for the task. conn (Connection, optional): Connection object for inter-process communication. Defaults to None.
| RETURNS | DESCRIPTION |
|---|---|
Optional[dict]
|
The result of the optimization process if no connection is provided; otherwise, None. |
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
get_paths
#
Generate and return key file and directory paths for a pipeline iteration.
This function constructs paths for the iteration directory, a specific file within that directory, a data folder based on the file name, and an optimizer snapshot directory within the data folder. It ensures that the optimizer snapshot directory exists, and raises an error if the specified file does not exist.
| PARAMETER | DESCRIPTION |
|---|---|
cfg
|
Configuration object containing root_path, iteration_name, and file_name attributes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tuple[Path, Path, Path, Path]
|
A tuple containing: - iteration_path (Path): Path to the iteration directory. - file_path (Path): Path to the specified file within the iteration directory. - data_folder (Path): Path to the data folder derived from the file name. - optimizer_snapshot_dir (Path): Path to the optimizer snapshot directory within the data folder. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the specified file does not exist at the constructed file_path. |
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
prepare_importer_parameters
#
Build importer parameter objects depending on file suffix.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
The path to the grid model file. The file suffix determines the type of importer parameters to create.
TYPE:
|
data_folder
|
The path to the folder containing additional data required for the import process.
TYPE:
|
area_settings
|
The area settings to use for the importer. If not provided, a default AreaSettings object is created.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
UcteImporterParameters | CgmesImporterParameters
|
An instance of either |
Notes
If file_path has a .uct suffix, a UcteImporterParameters object is returned.
Otherwise, a CgmesImporterParameters object is returned.
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
run_preprocessing
#
run_preprocessing(
importer_parameters,
data_folder,
preprocessing_parameters,
is_pandapower_net=False,
)
Run importer preprocessing and extract static information.
| PARAMETER | DESCRIPTION |
|---|---|
importer_parameters
|
Parameters required by the importer for file conversion. |
data_folder
|
Path to the folder where data files are stored and processed.
TYPE:
|
preprocessing_parameters
|
Parameters for preprocessing and loading the grid.
TYPE:
|
is_pandapower_net
|
Whether to use pandapower for loading the grid. Default is False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
info
|
Statistics and metadata about the static information extracted from the grid.
TYPE:
|
static_information
|
The extracted static information from the grid.
TYPE:
|
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
run_dc_optimization
#
Run the DC optimization process with the specified configuration.
This function sets up the necessary environment variables for optimization, including the number of OpenMP threads, CUDA devices, and optionally the XLA host platform device count. It then calls the optimization routine with the provided configuration.
| PARAMETER | DESCRIPTION |
|---|---|
dc_optim_config
|
Configuration object containing optimization parameters. Expected keys: - "omp_num_threads": int, number of OpenMP threads to use. - "num_cuda_devices": int, number of CUDA devices to make visible. - "xla_force_host_platform_device_count": int or None, optional XLA device count.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict
|
The result of the optimization process. |
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
load_action_set
#
Load an ActionSet object from a JSON file.
| PARAMETER | DESCRIPTION |
|---|---|
action_set_path
|
The file path to the JSON file containing the action set definition.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ActionSet
|
An instance of ActionSet initialized with the data from the JSON file. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the specified file does not exist. |
JSONDecodeError
|
If the file is not a valid JSON. |
TypeError
|
If the JSON structure does not match the ActionSet constructor requirements. |
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
apply_topology_and_save
#
apply_topology_and_save(
grid_path,
actions,
disconnections,
action_set,
save_path,
is_pandapower_grid=False,
)
Apply a set of topology actions and disconnections to the grid, then saves the modified network to a specified path.
| PARAMETER | DESCRIPTION |
|---|---|
grid_path
|
Path to the input grid file to be loaded.
TYPE:
|
actions
|
Iterable of actions to be applied to the network topology.
TYPE:
|
disconnections
|
Iterable of disconnections to be applied to the network.
TYPE:
|
action_set
|
Set of possible actions that can be applied to the network.
TYPE:
|
save_path
|
Path where the modified network will be saved.
TYPE:
|
is_pandapower_grid
|
Whether the grid is a pandapower grid. Default is False (powsybl grid).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Network
|
The modified network after applying the topology changes and disconnections. |
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
calculate_and_save_loadflow_results
#
Calculate AC and DC loadflow results using the provided runner and saves the results as CSV files.
| PARAMETER | DESCRIPTION |
|---|---|
runner
|
An instance capable of running AC and DC loadflow calculations.
TYPE:
|
topology_path
|
The directory path where the result CSV files will be saved.
TYPE:
|
actions
|
A list of action indices to apply during the loadflow calculation.
TYPE:
|
disconnections
|
A list of disconnection indices to apply during the loadflow calculation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
This function does not return anything. It saves the results to CSV files:
- "ac_loadflow_results.csv"
- "dc_loadflow_results.csv"
in the specified |
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
create_loadflow_runner
#
Create and configure a PowsyblRunner instance for loadflow analysis.
This function initializes a PowsyblRunner with a single process, loads the n-1 definition and action set
from the specified data_folder, and loads the base grid from the provided grid_file_path.
If the required files are not found, it raises a FileNotFoundError.
| PARAMETER | DESCRIPTION |
|---|---|
data_folder
|
The directory containing the n-1 definition and action set files.
TYPE:
|
grid_file_path
|
The path to the base grid file to be loaded.
TYPE:
|
n_processes
|
The number of processes to use for the loadflow runner. Default is 1.
TYPE:
|
pandaflow_runner
|
Whether to use a PandapowerRunner instead of PowsyblRunner. Default is False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AbstractLoadflowRunner
|
An instance of |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the n-1 definition file or action set file is not found in the specified |
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
save_slds_of_split_stations
#
Save single line diagrams (SLDs) as SVG files for a set of split stations.
For each station specified by the given actions, this function generates a single line diagram (SLD) using the provided network and saves it as an SVG file in the specified output directory.
Note that this method is applicable only for Powsybl networks.
| PARAMETER | DESCRIPTION |
|---|---|
action_set
|
The set of available actions, containing local actions and their associated grid model IDs.
TYPE:
|
actions
|
List of action indices corresponding to the stations for which SLDs should be generated and saved.
TYPE:
|
output_dir
|
The directory where the SLD SVG files will be saved. Files are saved under the 'sld' subdirectory.
TYPE:
|
network
|
The network object used to generate the single line diagrams.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
None
|
This function does not return anything. It saves SVG files to disk as a side effect. |
Notes
- Each SLD is saved with the filename format '{station_id}_sld.svg' under the 'sld' subdirectory of
output_dir. - Assumes that
get_single_line_diagram_customreturns an object with a_contentattribute containing SVG data. - Requires that the logger is properly configured.
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
perform_ac_analysis
#
perform_ac_analysis(
data_folder,
optimisation_run_path,
ac_validation_cfg,
pandapower_runner=False,
)
Perform AC loadflow and n-1 analysis on the best k topologies from the optimization results.
| PARAMETER | DESCRIPTION |
|---|---|
data_folder
|
Path to the folder containing the input grid data (e.g., 'grid.xiidm').
TYPE:
|
optimisation_run_path
|
Path to the optimizer snapshot directory containing 'res.json' and where results will be saved.
TYPE:
|
ac_validation_cfg
|
Configuration dictionary for AC validation, including: - 'n_processes': int, number of processes to use for loadflow analysis. - 'k_best_topos': int, number of best topologies to validate.
TYPE:
|
pandapower_runner
|
Whether to use a PandapowerRunner for loadflow analysis. Default is False (PowsyblRunner).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Path]
|
List of paths to the directories where the results for the specified topologies are saved. If no paths are generated (e.g., no topologies found), returns an empty list. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If the result JSON file ('res.json') is not found in the specified optimisation_run_path. |
Notes
This function applies the selected topology, runs AC loadflow analysis, and saves the results, including SLDs (Single Line Diagrams) of split stations, in the specified output directory.
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 | |
run_dc_optimization_stage
#
Run the DC optimization stage and save the results.
| PARAMETER | DESCRIPTION |
|---|---|
dc_optim_config
|
Configuration dictionary for the DC optimization stage.
TYPE:
|
optimizer_snapshot_dir
|
Directory where the optimizer snapshot results will be saved.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Path to the directory of this run's results. |
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
run_pipeline
#
run_pipeline(
pipeline_cfg,
importer_parameters,
preprocessing_parameters,
dc_optim_config,
ac_validation_cfg,
run_preprocessing_stage=True,
run_optimization_stage=True,
run_ac_validation_stage=True,
optimisation_run_dir=None,
)
Run the end-to-end pipeline including topology copying, preprocessing, DC optimization, and AC validation.
| PARAMETER | DESCRIPTION |
|---|---|
pipeline_cfg
|
Configuration object for the pipeline, containing paths and settings.
TYPE:
|
importer_parameters
|
Parameters for the grid model importer, specifying the source grid model file and related options. |
preprocessing_parameters
|
Parameters for the preprocessing stage, controlling data preparation and transformation.
TYPE:
|
dc_optim_config
|
Configuration dictionary for the DC optimization stage.
TYPE:
|
ac_validation_cfg
|
Configuration dictionary for the AC validation stage, including: - 'n_processes': int, number of processes to use for loadflow analysis. - 'k_best_topos': int, number of best topologies to validate.
TYPE:
|
run_preprocessing_stage
|
Whether to run the preprocessing stage. Default is True.
TYPE:
|
run_optimization_stage
|
Whether to run the DC optimization stage. Default is True.
TYPE:
|
run_ac_validation_stage
|
Whether to run the AC validation stage. Default is True.
TYPE:
|
optimisation_run_dir
|
If provided, this directory will be used for AC validation instead of running optimization.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Path to the directory where the results of the AC validation stage are saved. |
Notes
- The function logs progress at each major step.
- The optimizer results are saved as a JSON file in a new run directory under the optimizer snapshot directory.
- AC validation is performed if optimization results are available.
Source code in packages/topology_optimizer_pkg/src/toop_engine_topology_optimizer/benchmark/benchmark_utils.py
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 | |