### Install C-API Library Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Install the built C-API dynamic library to a local directory. ```shell cmake --install build/ --config Release --prefix install/ ``` -------------------------------- ### Install Power Grid Model Source: https://context7.com/powergridmodel/power-grid-model/llms.txt Commands to install the library using pip or conda. ```bash # Install from PyPI pip install power-grid-model # Install from Conda conda install -c conda-forge power-grid-model ``` -------------------------------- ### Install power-grid-model from PyPI Source: https://github.com/powergridmodel/power-grid-model/blob/main/README.md Install the package directly using pip. ```sh pip install power-grid-model ``` -------------------------------- ### Clone and Install Python Library from Source Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Clones the power-grid-model repository and installs the Python library in develop mode using uv. ```shell git clone https://github.com/PowerGridModel/power-grid-model.git cd power-grid-model ``` ```shell uv sync uv run pytest ``` -------------------------------- ### Install Documentation Dependencies Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Installs the necessary packages for building the documentation using uv. Ensure the 'doc' group is included in your project's dependencies. ```shell uv sync --group doc ``` -------------------------------- ### Example C program using Power Grid Model C API Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/c-api.md This is an example C program demonstrating how to use the Power Grid Model C API. It serves as a practical guide for integrating the library into C/C++ applications. ```c #include #include #include "power_grid_model_c/power_grid_model_c.h" int main() { PGM_Handle handle = PGM_create_handle(); PGM_Model model = PGM_create_model(handle); if (PGM_error_code(handle) != PGM_SUCCESS) { fprintf(stderr, "Error creating model: %s\n", PGM_error_message(handle)); return 1; } PGM_Options options = PGM_create_options(handle); if (PGM_error_code(handle) != PGM_SUCCESS) { fprintf(stderr, "Error creating options: %s\n", PGM_error_message(handle)); PGM_destroy_model(handle, model); return 1; } // Set calculation options PGM_set_int_option(handle, options, "max_iter", 100); PGM_set_double_option(handle, options, "tolerance", 1e-6); // Load data from files (example) // PGM_load_json(handle, model, "path/to/input.json"); // Perform calculation PGM_calculate(handle, model, options); if (PGM_error_code(handle) != PGM_SUCCESS) { fprintf(stderr, "Error during calculation: %s\n", PGM_error_message(handle)); PGM_destroy_options(handle, options); PGM_destroy_model(handle, model); return 1; } // Retrieve results (example) // double voltage = PGM_get_node_attribute(handle, model, "node_id_1", "u_rated"); // Clean up PGM_destroy_options(handle, options); PGM_destroy_model(handle, model); PGM_destroy_handle(handle); printf("Power Grid Model calculation completed successfully.\n"); return 0; } ``` -------------------------------- ### Link C Example Executable with Library Source: https://github.com/powergridmodel/power-grid-model/blob/main/power_grid_model_c_example/CMakeLists.txt Links the 'power_grid_model_c_example' executable against the 'power_grid_model_c' library. This makes the library's functionality available to the example. ```cmake target_link_libraries(power_grid_model_c_example PRIVATE power_grid_model_c) ``` -------------------------------- ### Install Power Grid Model C API via Homebrew Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/index.md Install the C API and experimental C++ wrapper using Homebrew. ```sh brew install powergridmodel/pgm/power-grid-model ``` -------------------------------- ### Install Test Executable and Runtime Artifacts Source: https://github.com/powergridmodel/power-grid-model/blob/main/tests/package_tests/CMakeLists.txt Installs the compiled test executable and any imported runtime artifacts from the 'power_grid_model::power_grid_model_c' target. This makes the test executable available after installation. ```cmake install(TARGETS power_grid_model_package_test) install(IMPORTED_RUNTIME_ARTIFACTS power_grid_model::power_grid_model_c) ``` -------------------------------- ### Install C API Library Source: https://github.com/powergridmodel/power-grid-model/blob/main/power_grid_model_c/power_grid_model_c/CMakeLists.txt Installs the C API library and its public headers as part of the power_grid_model component. ```cmake install( TARGETS power_grid_model_c EXPORT power_grid_modelTargets COMPONENT power_grid_model FILE_SET pgm_c_public_headers ) ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Synchronize the environment using uv to prepare build dependencies. ```shell uv sync ``` -------------------------------- ### Build and Install CMake Project Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Builds and installs the CMake project for the current preset. This is a prerequisite for the package tests. ```shell cmake --build --preset --target install ``` -------------------------------- ### Verify Python Installation Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Run the self-test utility to verify the installation and core data flow. ```python from power_grid_model.utils import self_test self_test() ``` -------------------------------- ### Add Test for C Example Source: https://github.com/powergridmodel/power-grid-model/blob/main/power_grid_model_c_example/CMakeLists.txt Configures a CTest to run the 'power_grid_model_c_example' executable. This allows for automated testing of the example's functionality. ```cmake add_test( PGMExample ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/power_grid_model_c_example ) ``` -------------------------------- ### Install Ubuntu Software Packages Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Installs essential build tools and optional packages for coverage reports, debugging, and general use on Ubuntu systems. ```shell sudo apt update && sudo apt -y upgrade sudo apt install -y build-essential gcc g++ clang-18 make ninja-build pkg-config ``` ```shell sudo apt install -y gcovr lcov # For coverage reports ``` ```shell sudo apt install -y gdb # For debugging ``` ```shell sudo apt install -y wget curl zip unzip tar git # General use tools ``` -------------------------------- ### Install uv on Windows Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Installs the uv package manager on Windows using PowerShell. This command bypasses the execution policy for the installation script. ```powershell powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" ``` -------------------------------- ### Add Executable for C Example Source: https://github.com/powergridmodel/power-grid-model/blob/main/power_grid_model_c_example/CMakeLists.txt Defines the C example executable and its source file. This is a standard CMake command to create a build target. ```cmake add_executable(power_grid_model_c_example main.c) ``` -------------------------------- ### Single-Phase-to-Ground Fault Example Source: https://context7.com/powergridmodel/power-grid-model/llms.txt Sets up a single-phase-to-ground fault on phase A for short circuit calculation. This demonstrates how to configure specific fault types and phases. ```python # Single-phase-to-ground fault example fault_spg = initialize_array(DatasetType.input, ComponentType.fault, 1) fault_spg[AttributeType.id] = [21] fault_spg[AttributeType.status] = [1] fault_spg[AttributeType.fault_object] = [2] fault_spg[AttributeType.fault_type] = [FaultType.single_phase_to_ground] fault_spg[AttributeType.fault_phase] = [FaultPhase.a] # fault on phase A fault_spg[AttributeType.r_f] = [0.0] fault_spg[AttributeType.x_f] = [0.0] ``` -------------------------------- ### Build and Run Package Tests Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Configure, build, install, and execute the package test that consumes the C-API library. ```shell cd tests/package_tests cmake -DCMAKE_BUILD_TYPE=Release -Dpower_grid_model_DIR="../../install/lib/cmake/power_grid_model/" -B build/ cmake --build build/ --config Release cmake --install build/ --config Release --prefix install/ ./install/bin/power_grid_model_package_test ``` -------------------------------- ### Initialize and Populate Batch Input Data Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/examples/Validation Examples.ipynb This example demonstrates how to initialize arrays for nodes, sources, and loads, populate them with specific values, and then combine them into an input data dictionary for batch validation. ```python from power_grid_model.validation import validate_batch_data node = initialize_array(DatasetType.input, ComponentType.node, 1) node[:] = (1, 10e3) source = initialize_array(DatasetType.input, ComponentType.source, 1) source[:] = (2, 1, 1, 1.0, 0.0, 1e10, 0.1, 1.0) load = initialize_array(DatasetType.input, ComponentType.sym_load, 1) load[:] = (3, 1, 1, 0, 1000, 1000) input_data = { ComponentType.node: node, ComponentType.source: source, ComponentType.sym_load: load, } ``` -------------------------------- ### Install power-grid-model from Conda Source: https://github.com/powergridmodel/power-grid-model/blob/main/README.md Install the package from the conda-forge channel using conda. ```sh conda install -c conda-forge power-grid-model ``` -------------------------------- ### Node Voltage Results Example Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/examples/Asymmetric Line.ipynb Example output showing the calculated node voltages from a state estimation. This is typically a pandas DataFrame. ```text ------node result------ 0 1 2 0 1000.000001 999.999991 1000.000007 1 1000.000019 999.999988 999.999997 2 1000.000001 999.999999 999.999999 ``` -------------------------------- ### Build and Test Python Library (Linux) Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Installs Python dependencies using uv and runs tests. Assumes the repository has been cloned and the user is in the project's root directory. ```shell uv sync uv run pytest ``` -------------------------------- ### Install C++ Dependencies via Homebrew (Linux) Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Installs C++ packages and the uv library using Homebrew, recommended for CMake builds on Linux. ```shell brew install boost eigen nlohmann-json msgpack-cxx doctest cmake uv ``` -------------------------------- ### Configure Generic Branch Network Model Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/examples/Generic Branch Example.ipynb Initializes nodes, loads, sources, and generic branches to model a power grid with a PST. Ensure the power-grid-model package is installed and configured before execution. ```python # some basic imports import warnings with warnings.catch_warnings(): warnings.simplefilter("ignore", category=DeprecationWarning) # Suppress warning about pyarrow as future required dependency from power_grid_model import ( AttributeType, CalculationMethod, CalculationType, ComponentType, DatasetType, LoadGenType, PowerGridModel, initialize_array, ) from power_grid_model.validation import assert_valid_input_data # network network = """ (100km) (100km) B5,230kV L 100MW <-|----L46-----------| |-----------L45---------------|-> L 100 MW B6,230kV ----- B4 |- | | L34 (cheap kabel, 40km) | | L57 (100km) ----- B3 | | | (100km) PST23 (100km) |- L 200MW <-|----L28--------| | |----------L27-------------|-> L 200 MW B8,230kV --------- B2,230kV B7,230kV | T12 Transformer | ----- B1, 15.5kV ^ | G (*Slack) """ # node node = initialize_array(DatasetType.input, ComponentType.node, 8) node[AttributeType.id] = [1, 2, 3, 4, 5, 6, 7, 8] node[AttributeType.u_rated] = [15.5e3, 230e3, 230e3, 230e3, 230e3, 230e3, 230e3, 230e3] node_name = ["B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8"] branch_name = ["L27", "L28", "L45", "L46", "L57", "L34", "T12", "PST23"] # load sym_load = initialize_array(DatasetType.input, ComponentType.sym_load, 4) sym_load[AttributeType.id] = [9, 10, 11, 12] sym_load[AttributeType.node] = [5, 6, 7, 8] sym_load[AttributeType.status] = [1, 1, 1, 1] sym_load[AttributeType.type] = [LoadGenType.const_power] sym_load[AttributeType.p_specified] = [100e6, 100e6, 200e6, 200e6] sym_load[AttributeType.q_specified] = [0.0, 0.0, 0.0, 0.0] # source source = initialize_array(DatasetType.input, ComponentType.source, 1) source[AttributeType.id] = [13] source[AttributeType.node] = [1] source[AttributeType.status] = [1] source[AttributeType.u_ref] = [1.0] source[AttributeType.sk] = [1e40] # generic_branch theta_pst = -0.1 # shift angle of PST gb = initialize_array(DatasetType.input, ComponentType.generic_branch, 8) # L27 L28 L45 L46 L57 L34 T12 P23 gb[AttributeType.id] = [14, 15, 16, 17, 18, 19, 20, 21] gb[AttributeType.from_node] = [2, 2, 4, 4, 5, 3, 1, 2] gb[AttributeType.to_node] = [7, 8, 5, 6, 7, 4, 2, 3] gb[AttributeType.from_status] = [1, 1, 1, 1, 1, 1, 1, 1] gb[AttributeType.to_status] = [1, 1, 1, 1, 1, 1, 1, 1] gb[AttributeType.r1] = [2.0, 2.0, 2.0, 2.0, 2.0, 4.6, 0.5, 0.0] gb[AttributeType.x1] = [8.0, 8.0, 8.0, 8.0, 8.0, 3.4, 2.0, 4.0] gb[AttributeType.g1] = [0.0, 0.0, 0.0, 0.0, 0.0, 4e-6, 0.0, 0.0] gb[AttributeType.b1] = [0.0, 0.0, 0.0, 0.0, 0.0, 40e-4, 0.0, 0.0] gb[AttributeType.k] = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] gb[AttributeType.theta] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, theta_pst] gb[AttributeType.sn] = [500e6, 500e6, 500e6, 500e6, 250e6, 500e6, 1000e6, 1000e6] ``` -------------------------------- ### JSON Schema Batch Update Dataset Example Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/user_manual/serialization.md Example of a batch update dataset in JSON format. It demonstrates updating sym_loads and asym_loads, showing how not all components or attributes need to be present in every update. ```json { "version": "1.0", "type": "update", "is_batch": true, "attributes": { "sym_load": ["id", "p_specified", "q_specified"], "asym_load": ["id", "p_specified"] }, "data": [ { "sym_load": [ [7, 20.0, 50.0] ], "asym_load": [ [9, [100.0, null, 200.0]] ] }, { "asym_load": [ [9, null] ] }, { "sym_load": [ [7, null, 10.0], { "id": 8, "status": 0 } ], "asym_load": [ { "id": 9, "q_specified": [70.0, 80.0, 90.0] } ] } ] } ``` -------------------------------- ### Empty Symmetric Batch Output JSON Example Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/examples/Make Test Dataset.ipynb Provides a template for an empty symmetric batch output JSON file. Used to trigger batch calculations when reference results are unavailable. ```json { "attributes": {}, "data": [{}, {}, {}], "is_batch": true, "type": "sym_output", "version": "1.0" } ``` -------------------------------- ### Find and Link Power Grid Model Package Source: https://github.com/powergridmodel/power-grid-model/blob/main/tests/package_tests/CMakeLists.txt Finds the installed 'power_grid_model' package and links the test executable against its C and C++ shared libraries. This setup is for testing the installed package. ```cmake find_package(power_grid_model REQUIRED CONFIG) set(PROJECT_SOURCES "test_c_api_package.cpp") # Link against shared power_grid_model object installed by main project add_executable(power_grid_model_package_test ${PROJECT_SOURCES}) target_link_libraries( power_grid_model_package_test PRIVATE power_grid_model::power_grid_model_c ) target_link_libraries( power_grid_model_package_test PRIVATE power_grid_model::power_grid_model_cpp ) ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Commands to build the HTML documentation. First, navigate to the doxygen directory and run doxygen, then use sphinx-build to generate the HTML files in docs/_build/html. ```shell cd docs/doxygen doxygen cd .. sphinx-build -b html . _build/html ``` -------------------------------- ### Initialize network components using helper function Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/examples/Transformer Examples.ipynb Uses the `initialize_array` helper function to create input datasets for various network components like nodes, loads, sources, and transformers. This is a prerequisite for building the power grid model. ```python # node node = initialize_array(DatasetType.input, ComponentType.node, 2) node[AttributeType.id] = np.array([2, 4]) node[AttributeType.u_rated] = [1e4, 4e2] # load sym_load = initialize_array(DatasetType.input, ComponentType.sym_load, 1) sym_load[AttributeType.id] = [5] sym_load[AttributeType.node] = [4] sym_load[AttributeType.status] = [1] sym_load[AttributeType.type] = [LoadGenType.const_power] sym_load[AttributeType.p_specified] = [1e3] sym_load[AttributeType.q_specified] = [5e3] # source source = initialize_array(DatasetType.input, ComponentType.source, 1) source[AttributeType.id] = [1] source[AttributeType.node] = [2] source[AttributeType.status] = [1] source[AttributeType.u_ref] = [1.0] # transformer transformer = initialize_array(DatasetType.input, ComponentType.transformer, 1) transformer[AttributeType.id] = [3] transformer[AttributeType.from_node] = [2] transformer[AttributeType.to_node] = [4] transformer[AttributeType.from_status] = [1] transformer[AttributeType.to_status] = [1] transformer[AttributeType.u1] = [1e4] transformer[AttributeType.u2] = [4e2] transformer[AttributeType.sn] = [1e5] transformer[AttributeType.uk] = [0.1] transformer[AttributeType.pk] = [1e3] transformer[AttributeType.i0] = [1.0e-6] transformer[AttributeType.p0] = [0.1] transformer[AttributeType.winding_from] = [2] transformer[AttributeType.winding_to] = [1] transformer[AttributeType.clock] = [5] transformer[AttributeType.tap_side] = [0] transformer[AttributeType.tap_pos] = [3] transformer[AttributeType.tap_min] = [-11] transformer[AttributeType.tap_max] = [9] transformer[AttributeType.tap_size] = [100] # all input_data = { ComponentType.node: node, ComponentType.transformer: transformer, ComponentType.sym_load: sym_load, ComponentType.source: source, } ``` -------------------------------- ### Install C++ Dependencies with Homebrew Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/advanced_documentation/build-guide.md Installs necessary C++ packages and libraries like ninja, cmake, boost, and uv using Homebrew on macOS. ```shell brew install ninja cmake boost eigen nlohmann-json msgpack-cxx doctest uv ``` -------------------------------- ### JSON Schema Single Dataset Example Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/user_manual/serialization.md Example of a single input dataset in JSON format. It includes nodes, lines, and sources, with components represented using HomogeneousComponentData and InhomogeneousComponentData. ```json { "version": "1.0", "type": "input", "is_batch": false, "attributes": { "node": ["id", "u_rated"], "sym_load": ["id", "node", "status", "type", "p_specified", "q_specified"], "source": ["id", "node", "status", "u_ref", "sk"] }, "data": { "node": [ [1, 10.5e3], [2, 10.5e3], [3, 10.5e3], [100, "inf"], [101, "+inf"], [102, "-inf"] ], "line": [ { "id": 4, "from_node": 1, "to_node": 2, "from_status": 1, "to_status": 1, "r1": 0.11, "x1": 0.12, "c1": 4e-05, "tan1": 0.1, "i_n": 500.0 }, { "id": 5, "from_node": 2, "to_node": 3, "from_status": 1, "to_status": 1, "r1": 0.15, "x1": 0.16, "c1": 5e-05, "tan1": 0.12, "i_n": 550.0 } ], "source": [ [15, 1, 1, 1.03, 1e20], [16, 1, 1, 1.04, null], { "id": 17, "node": 1, "status": 1, "u_ref": 1.03, "sk": 1e10, "rx_ratio": 0.2 } ], "sym_load": [ [7, 2, 1, 0, 1.01e6, 0.21e6], [8, 3, 1, 0, 1.02e6, 0.22e6] ] } } ``` -------------------------------- ### Basics - power_grid_model_c/basics.h Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/api_reference/power-grid-model-c-api-reference.rst Contains definitions of opaque structs and enumerations for basic types. ```APIDOC ## Basics The header `power_grid_model_c/basics.h` contains definitions of opaque structs and enumerations. .. doxygenfile:: power_grid_model_c/basics.h ``` -------------------------------- ### Initialize and Calculate Power Flow Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/examples/Generic Branch Example.ipynb Sets up input data components and executes a Newton-Raphson power flow calculation. ```python input_data = { ComponentType.node: node, ComponentType.generic_branch: gb, ComponentType.sym_load: sym_load, ComponentType.source: source, } assert_valid_input_data(input_data=input_data, calculation_type=CalculationType.power_flow) model = PowerGridModel(input_data) output_data = model.calculate_power_flow( symmetric=True, error_tolerance=1e-8, max_iterations=20, calculation_method=CalculationMethod.newton_raphson ) ``` -------------------------------- ### Instantiate Power Grid Model Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/quickstart.md Creates a model instance using the prepared input data and a specified system frequency. ```python model = PowerGridModel(input_data, system_frequency=50.0) ``` -------------------------------- ### Validation Error Output Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/examples/Validation Examples.ipynb Example output generated by the validation process when data constraints are violated. ```text There is a validation error in the data, batch #0: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #1: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #2: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #3: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #4: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #5: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #6: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #7: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #8: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #9: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #10: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #11: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #12: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #13: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #14: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #15: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #16: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #17: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #18: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #19: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #20: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #21: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #22: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #23: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #24: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the data, batch #25: Field 'status' is not a boolean (0 or 1) for 1 sym_load. component: sym_load field: 'status' ids: [3] There is a validation error in the ``` -------------------------------- ### Construct Network Input Data and Model Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/examples/Multi-dimensional batch calculation example.ipynb Initializes nodes, lines, loads, and sources to build the PowerGridModel instance. ```python # node node = initialize_array(DatasetType.input, ComponentType.node, 3) node[AttributeType.id] = np.array([1, 2, 6]) node[AttributeType.u_rated] = [10.5e3, 10.5e3, 10.5e3] # line line = initialize_array(DatasetType.input, ComponentType.line, 3) line[AttributeType.id] = [3, 5, 8] line[AttributeType.from_node] = [1, 2, 1] line[AttributeType.to_node] = [2, 6, 6] line[AttributeType.from_status] = [1, 1, 1] line[AttributeType.to_status] = [1, 1, 1] line[AttributeType.r1] = [0.25, 0.25, 0.25] line[AttributeType.x1] = [0.2, 0.2, 0.2] line[AttributeType.c1] = [10e-6, 10e-6, 10e-6] line[AttributeType.tan1] = [0.0, 0.0, 0.0] line[AttributeType.i_n] = [1000, 1000, 1000] # load sym_load = initialize_array(DatasetType.input, ComponentType.sym_load, 2) sym_load[AttributeType.id] = [4, 7] sym_load[AttributeType.node] = [2, 6] sym_load[AttributeType.status] = [1, 1] sym_load[AttributeType.type] = [LoadGenType.const_power, LoadGenType.const_power] sym_load[AttributeType.p_specified] = [20e6, 10e6] sym_load[AttributeType.q_specified] = [5e6, 2e6] # source source = { AttributeType.id: np.array([10], dtype=attribute_dtype(DatasetType.input, ComponentType.source, AttributeType.id)), AttributeType.node: np.array( [1], dtype=attribute_dtype(DatasetType.input, ComponentType.source, AttributeType.node) ), AttributeType.status: np.array( [1], dtype=attribute_dtype(DatasetType.input, ComponentType.source, AttributeType.status) ), AttributeType.u_ref: np.array( [1.0], dtype=attribute_dtype(DatasetType.input, ComponentType.source, AttributeType.u_ref) ), } # all input_data = { ComponentType.node: node, ComponentType.line: line, ComponentType.sym_load: sym_load, ComponentType.source: source, } # validate input data assert_valid_input_data(input_data=input_data, calculation_type=CalculationType.power_flow) # create model model = PowerGridModel(input_data) ``` -------------------------------- ### Initialize Three-Winding Transformer Model in Python Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/examples/Generic Branch Example.ipynb Sets up the network topology, node data, source, loads, and generic branch parameters for a three-winding transformer configuration. ```python import warnings with warnings.catch_warnings(): warnings.simplefilter("ignore", category=DeprecationWarning) # Suppress warning about pyarrow as future required dependency import pandas as pd from power_grid_model import ( AttributeType, CalculationMethod, CalculationType, ComponentType, DatasetType, LoadGenType, PowerGridModel, initialize_array, ) from power_grid_model.validation import assert_valid_input_data # network network = """ 5,Source -->|---Line, Br12----| | ------ 1, HV | 0 Br8, T1 0 | 4, AUX 2,MV x--------x---------x 3, LV | | 0 Br9,T2 0 Br10, T3 0 0 | | ---- -----> 7, Load | | | Line, Br11 | | ----- 11, Station1 | ----> 6, Load """ # Voltage levels of the transformer u_rated = {"HV": 200e3, "MV": 150e3, "LV": 30.2e3, "AUX": 200e3, "Station1": 150e3, "Source": 200e3} # Injected power on the HV side source_voltage = u_rated["Source"] # 200 kV source_power = 1e40 # High short-circuit power -> v_pu = 1.0 # Loads load_MV = {"P": 30e6, "Q": 5e6} load_LV = {"P": 1.5e6, "Q": 0.15e6} # Self-consumption # Assignment of node numbers nodes = {"HV": 1, "MV": 2, "LV": 3, "AUX": 4, "Station1": 11, "Source": 14} non = len(nodes) # number of nodes # Tap-changer v_tap = 6.0e3 # Generate nodes node_data = initialize_array(DatasetType.input, ComponentType.node, non) node_data[AttributeType.id] = list(nodes.values()) node_data[AttributeType.u_rated] = list(u_rated.values()) # Slack source_data = initialize_array(DatasetType.input, ComponentType.source, 1) source_data[AttributeType.id] = [5] source_data[AttributeType.node] = [nodes["Source"]] source_data[AttributeType.status] = [1] source_data[AttributeType.u_ref] = [1.0] source_data[AttributeType.sk] = [source_power] # Loads 110kV load_data = initialize_array(DatasetType.input, ComponentType.sym_load, 2) load_data[AttributeType.id] = [6, 7] load_data[AttributeType.type] = [LoadGenType.const_power, LoadGenType.const_power] load_data[AttributeType.node] = [nodes["Station1"], nodes["LV"]] load_data[AttributeType.p_specified] = [load_MV["P"], load_LV["P"]] load_data[AttributeType.q_specified] = [load_MV["Q"], load_LV["Q"]] load_data[AttributeType.status] = [1, 1] node_name = ["HV", "MV", "LV", "AUX", "Station1", "Source"] branch_name = ["BHV", "BMV", "BLV", "BLine2", "BLine1"] branch_data = initialize_array(DatasetType.input, ComponentType.generic_branch, 5) branch_data[AttributeType.id] = [8, 9, 10, 12, 13] branch_data[AttributeType.from_node] = [nodes["HV"], nodes["AUX"], nodes["AUX"], nodes["MV"], nodes["Source"]] branch_data[AttributeType.to_node] = [nodes["AUX"], nodes["MV"], nodes["LV"], nodes["Station1"], nodes["HV"]] branch_data[AttributeType.from_status] = [1, 1, 1, 1, 1] branch_data[AttributeType.to_status] = [1, 1, 1, 1, 1] ``` -------------------------------- ### Dataset Types Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/user_manual/dataset-terminology.md Details the different types of datasets available for grid modeling, including their purpose and example attributes. ```APIDOC ### Type of Dataset The types of `Dataset` include the following: `input`, `update`, `sym_output`, `asym_output`, and `sc_output`. They are included under the enum {py:class}`DatasetType `. Exemplary datasets attributes are given in a dataset containing a `line` component. - **input:** Contains attributes relevant to configuration of grid. - Example: `id`, `from_node`, `from_status` - **update:** Contains attributes relevant to multiple scenarios. - Example: `from_status`,`to_status` - **sym_output:** Contains attributes relevant to symmetrical steady state output of power flow or state estimation calculation. - Example: `p_from`, `p_to` - **asym_output:** Contains attributes relevant to asymmetrical steady state output of power flow or state estimation calculation. Attributes are similar to `sym_output` except some values of the asymmetrical dataset will contain detailed data for all 3 phases individually. - Example: `p_from`, `p_to` - **sc_output:** Contains attributes relevant to symmetrical short circuit calculation output. Like for the `asym_output`, detailed data for all 3 phases will be provided where relevant. - Example: `i_from`, `i_from_angle` ``` -------------------------------- ### Run Library Self-Test Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/quickstart.md Executes a diagnostic check to verify the installation and ensure no build errors or runtime issues exist. ```python self_test() ``` -------------------------------- ### Construct Power Grid Model Source: https://context7.com/powergridmodel/power-grid-model/llms.txt Initialize the model by defining nodes, lines, loads, and sources using structured arrays. ```python import numpy as np from power_grid_model import ( PowerGridModel, initialize_array, LoadGenType, DatasetType, ComponentType, AttributeType ) # Create nodes node = initialize_array(DatasetType.input, ComponentType.node, 2) node[AttributeType.id] = [1, 2] node[AttributeType.u_rated] = [10.5e3, 10.5e3] # 10.5 kV rated voltage # Create line connecting nodes line = initialize_array(DatasetType.input, ComponentType.line, 1) line[AttributeType.id] = [3] line[AttributeType.from_node] = [1] line[AttributeType.to_node] = [2] line[AttributeType.from_status] = [1] line[AttributeType.to_status] = [1] line[AttributeType.r1] = [0.25] # positive-sequence resistance (ohm) line[AttributeType.x1] = [0.2] # positive-sequence reactance (ohm) line[AttributeType.c1] = [10e-6] # positive-sequence capacitance (F) line[AttributeType.tan1] = [0.0] # loss factor line[AttributeType.i_n] = [1000] # rated current (A) # Create symmetric load sym_load = initialize_array(DatasetType.input, ComponentType.sym_load, 1) sym_load[AttributeType.id] = [4] sym_load[AttributeType.node] = [2] sym_load[AttributeType.status] = [1] sym_load[AttributeType.type] = [LoadGenType.const_power] sym_load[AttributeType.p_specified] = [2e6] # 2 MW active power sym_load[AttributeType.q_specified] = [0.5e6] # 0.5 MVAr reactive power # Create source (external grid) source = initialize_array(DatasetType.input, ComponentType.source, 1) source[AttributeType.id] = [5] source[AttributeType.node] = [1] source[AttributeType.status] = [1] source[AttributeType.u_ref] = [1.0] # per-unit reference voltage # Assemble input data and create model input_data = { ComponentType.node: node, ComponentType.line: line, ComponentType.sym_load: sym_load, ComponentType.source: source } model = PowerGridModel(input_data, system_frequency=50.0) ``` -------------------------------- ### Set Target Include Directories Source: https://github.com/powergridmodel/power-grid-model/blob/main/power_grid_model_c/power_grid_model_c/CMakeLists.txt Configures the include directories for the C API library, making headers available during build and installation. ```cmake target_include_directories( power_grid_model_c PUBLIC $ $ ) ``` -------------------------------- ### Update Model Components in Python Source: https://github.com/powergridmodel/power-grid-model/blob/main/docs/examples/Power Flow Example.ipynb Call the `update` method on a copy of the model to apply changes. This example demonstrates updating with `update_data`. ```python model_2 = model.copy() model_2.update(update_data=update_data) ```