### Install from index: pip install parallel-pandapower-solver[cpp] Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/build.html Installs the published p3s-cpp distribution, which includes the compiled nr_klu extension. This is the standard installation method for users. ```bash pip install parallel-pandapower-solver[cpp] # pulls in the published p3s-cpp distribution ``` -------------------------------- ### Install from source Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/installation.rst.txt Installs the package from the downloaded or cloned source directory using uv. ```sh cd parallel-pandapower-solver uv pip install . ``` -------------------------------- ### Install p3s-cpp from source checkout Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/build.rst.txt Builds and installs the extension from a local source checkout using pip and scikit-build-core. ```bash pip install ./p3s/cpp ``` -------------------------------- ### Install p3s-cpp from index Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/build.rst.txt Installs the published p3s-cpp distribution via pip, pulling in the compiled extension. This is the recommended way to get the extension from an index. ```bash pip install parallel-pandapower-solver[cpp] # pulls in the published p3s-cpp distribution ``` -------------------------------- ### Install with pip Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/installation.rst.txt Installs the parallel pandapower solver using pip, an alternative to the uv command. ```sh pip install parallel-pandapower-solver ``` -------------------------------- ### Install with uv Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/installation.rst.txt Installs the parallel pandapower solver using the uv package manager. This is the recommended command for a stable release installation. ```sh uv add parallel-pandapower-solver ``` -------------------------------- ### Install C++/KLU solver Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Install the C++/KLU accelerated solver. Building it needs a C++17 compiler and SuiteSparse/KLU (and CUDA toolkit for CUDA paths). ```bash pip install parallel-pandapower-solver[cpp] # from an index pip install ./p3s/cpp # from a source checkout ``` -------------------------------- ### N-1 contingency benchmark quick start commands Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/benchmark.html Run the standalone N-1 benchmark script with various options: all lines and transformers, limit to first 200 contingencies, skip pandapower loop, or use 8 threads and validate 25 contingencies. ```bash # All lines + transformers python -m tests.benchmark.benchmark_n_1_pegase # First 200 contingencies (quick estimate) python -m tests.benchmark.benchmark_n_1_pegase --limit 200 # p3s only (skip the slow pandapower loop) python -m tests.benchmark.benchmark_n_1_pegase --skip-pandapower # 8 threads + spot-check 25 contingencies against pandapower python -m tests.benchmark.benchmark_n_1_pegase --threads 8 --validate 25 ``` -------------------------------- ### Install numpy for build isolation Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/build.html Install numpy in the active environment when building with --no-build-isolation to ensure numpy headers are found. ```bash pip install numpy ``` -------------------------------- ### Install SuiteSparse via conda-forge Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/build.html The easiest cross-platform route to get SuiteSparse/KLU headers, libraries, and CMake config packages is conda-forge. A system libsuitesparse-dev also works on Linux. ```bash conda install -c conda-forge suitesparse ``` -------------------------------- ### Host-tuned local build: pip install ./p3s/cpp --config-settings=cmake.define.P3S_CPP_NATIVE=ON Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/build.html Builds a local development wheel tuned to the host CPU with -march=native. P3S_CPP_NATIVE defaults to OFF in the published wheel; use ON only for local development builds. ```bash pip install ./p3s/cpp --config-settings=cmake.define.P3S_CPP_NATIVE=ON ``` -------------------------------- ### Build from source checkout: pip install ./p3s/cpp Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/build.html Builds the package from a local source checkout. The build is driven by pip + scikit-build-core, which runs the CMake build in p3s/cpp/CMakeLists.txt. ```bash pip install ./p3s/cpp ``` -------------------------------- ### Output JSON file path pattern Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/benchmark.html Results are saved as JSON files using the pattern {output_dir}/{job_id}/{job_id}_{case}.json. Example: /mnt/home/user/p3s/results/123456/123456_case9.json. ```none {output_dir}/{job_id}/{job_id}_{case}.json ``` -------------------------------- ### Import the installed nr_klu module Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/build.html After a successful build, the module is installed into the p3s package by CMake, so it resolves without any path juggling. The fallback import path is from p3s.cpp import nr_klu. ```python from p3s import nr_klu # installed build # fallback: from p3s.cpp import nr_klu ``` -------------------------------- ### Install CUDA toolkit Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/installation.rst.txt Installs the CUDA toolkit and cuDSS via conda. Note that CUDA libraries are not part of the repository and must be acquired separately from NVIDIA under their license terms. ```sh conda install -c nvidia/label/cuda-13.2.2 cuda-toolkit` ``` -------------------------------- ### Set KLU_ROOT environment variable Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/build.rst.txt Sets the KLU_ROOT environment variable to point the build at a non-standard SuiteSparse installation. Shown for Windows PowerShell and Linux/macOS. ```bash # Windows (PowerShell) $env:KLU_ROOT = "C:\path\to\suitesparse" # Linux/macOS export KLU_ROOT=/path/to/suitesparse ``` -------------------------------- ### Set KLU_ROOT environment variable Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/build.html Set the KLU_ROOT environment variable to point the build at a non-standard SuiteSparse installation. The cmake/FindKLU.cmake honors KLU_ROOT, SuiteSparse_ROOT, and CONDA_PREFIX. ```powershell # Windows (PowerShell) $env:KLU_ROOT = "C:\path\to\suitesparse" ``` ```bash # Linux/macOS export KLU_ROOT=/path/to/suitesparse ``` -------------------------------- ### Test locally with all methods Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/benchmark.rst.txt Runs the benchmark for case9 with all methods (pp, p3s, cpp-1thr, cpp-Nthr, gpu). ```bash # Test case9 with all methods python tests/benchmark/benchmark_batched.py --case case9 --methods pp,p3s,cpp-1thr,cpp-Nthr,gpu ``` -------------------------------- ### Custom method selection - C++ and GPU Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/benchmark.rst.txt Runs the benchmark for case9 with only the cpp and gpu methods. ```bash # Only test C++ and GPU python tests/benchmark/benchmark_batched.py --case case9 --methods cpp,gpu ``` -------------------------------- ### Configure and build with CMake Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/build.html Commands to configure and build the project using CMake directly against p3s/cpp/CMakeLists.txt. Requires providing Python, pybind11, numpy, and KLU discovery manually. Use -DKLU_ROOT or -DSuiteSparse_ROOT for non-standard KLU locations. ```bash mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH= cmake --build . --config Release ``` -------------------------------- ### N-1 benchmark GPU backend commands Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/benchmark.html Run the N-1 benchmark with GPU backend, optionally setting GPU max chunk size, or compare CPU vs GPU with 'both' backend. ```bash python -m tests.benchmark.benchmark_n_1_pegase --backend gpu --limit 2000 python -m tests.benchmark.benchmark_n_1_pegase --backend gpu --gpu-max-chunk 512 python -m tests.benchmark.benchmark_n_1_pegase --backend both --limit 2000 # CPU vs GPU ``` -------------------------------- ### Host-tuned local build with P3S_CPP_NATIVE Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/build.rst.txt Builds the extension with host-specific tuning (-march=native) for local development. P3S_CPP_NATIVE defaults to OFF in published wheels; use ON only for local builds. ```bash pip install ./p3s/cpp --config-settings=cmake.define.P3S_CPP_NATIVE=ON ``` -------------------------------- ### Custom method selection for benchmark_batched.py Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/benchmark.html Run benchmark_batched.py with specific methods: 'cpp,gpu' for C++ and GPU, or 'cpp-1thr' for single-threaded C++. ```bash # Only test C++ and GPU python tests/benchmark/benchmark_batched.py --case case9 --methods cpp,gpu # Only single-threaded C++ python tests/benchmark/benchmark_batched.py --case case14 --method cpp-1thr ``` -------------------------------- ### Run on a cluster with sbatch Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/benchmark.html Submit all IEEE cases as a job array, or submit a specific method by setting the METHOD environment variable. ```bash # Submit all IEEE cases (job array: 0-29) sbatch tests/benchmark/benchmark_all.sbatch ``` ```bash # Submit specific method METHOD=gpu sbatch tests/benchmark/benchmark_all.sbatch ``` -------------------------------- ### Run p3s-only benchmark (skip pandapower) Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/benchmark.rst.txt Times only the p3s solver, skipping the slow pandapower loop. Use for a quick estimate of p3s performance. ```bash # p3s only (skip the slow pandapower loop) python -m tests.benchmark.benchmark_n_1_pegase --skip-pandapower ``` -------------------------------- ### Initialize NewtonPowerflowCUDA Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/usage.html Initializes the CUDA-accelerated Newton solver and calculates time-series voltages. The batch_size parameter determines the number of operating points solved per GPU chunk. ```python from p3s.cuda.NewtonPowerflowCuda import NewtonPowerflowCUDA npf = NewtonPowerflowCUDA(net) voltages = npf.calculate_timeseries_cuda(net, timeseries, batch_size=5) ``` -------------------------------- ### Custom method selection - single-threaded C++ Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/benchmark.rst.txt Runs the benchmark for case14 with only the cpp-1thr method. ```bash # Only single-threaded C++ python tests/benchmark/benchmark_batched.py --case case14 --method cpp-1thr ``` -------------------------------- ### Import p3s solvers Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Import the pure-Python CPU solver, the C++/KLU CPU solver, and the GPU solver from their respective submodules. ```python from p3s.NewtonPowerflow import NewtonPowerflow # pure-Python CPU solver from p3s.NewtonPowerflowCpp import NewtonPowerflow as NewtonPowerflowCpp # C++/KLU CPU solver from p3s.cuda.NewtonPowerflowCuda import NewtonPowerflowCUDA # GPU solver ``` -------------------------------- ### C++/KLU accelerated solver (p3s.NewtonPowerflowCpp) Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Drop-in accelerated variant of the Newton solver that offloads sparse factorisation to the compiled nr_klu extension. ```python from p3s.NewtonPowerflowCpp import NewtonPowerflow as NewtonPowerflowCpp npf = NewtonPowerflowCpp(net) voltage = npf.calculate(net, tolerance=1e-8, max_iterations=30) ``` -------------------------------- ### Run benchmark with 8 threads and validate 25 contingencies Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/benchmark.rst.txt Uses 8 OpenMP threads for nr_klu and spot-checks 25 contingencies against pandapower. The default validation count is 10. ```bash # 8 threads + spot-check 25 contingencies against pandapower python -m tests.benchmark.benchmark_n_1_pegase --threads 8 --validate 25 ``` -------------------------------- ### Import p3s package Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Import the p3s package. Most functionality lives in submodules, so import the solver you need explicitly. ```python import p3s ``` -------------------------------- ### Submit specific method on cluster Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/benchmark.rst.txt Submits the benchmark job with the gpu method by setting the METHOD environment variable. ```bash # Submit specific method METHOD=gpu sbatch tests/benchmark/benchmark_all.sbatch ``` -------------------------------- ### N-1 contingency benchmark - all lines and transformers Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/benchmark.rst.txt Runs the standalone N-1 contingency benchmark for all lines and transformers. ```bash # All lines + transformers python -m tests.benchmark.benchmark_n_1_pegase ``` -------------------------------- ### Test locally with benchmark_batched.py Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/benchmark.html Run the benchmark script locally for a specific IEEE case and method, or with specific T values for the GPU method. ```bash # Test case9 with all methods python tests/benchmark/benchmark_batched.py –case case9 –methods pp,p3s,cpp-1thr,cpp-Nthr,gpu ``` ```bash # Test with specific T values python tests/benchmark/benchmark_batched.py –case case118 –method gpu –T 64 256 1024 ``` -------------------------------- ### Submit all IEEE cases on cluster Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/benchmark.rst.txt Submits a SLURM job array (0-29) for all IEEE cases using the benchmark_all.sbatch script. ```bash # Submit all IEEE cases (job array: 0-29) sbatch tests/benchmark/benchmark_all.sbatch ``` -------------------------------- ### N-1 contingency benchmark - first 200 contingencies Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/benchmark.rst.txt Runs the N-1 contingency benchmark with a limit of 200 contingencies for a quick estimate. ```bash # First 200 contingencies (quick estimate) python -m tests.benchmark.benchmark_n_1_pegase --limit 200 ``` -------------------------------- ### Verify p3s import Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/build.html Import the nr_klu module from p3s to confirm the build succeeded. ```python from p3s import nr_klu ``` -------------------------------- ### Newton-Raphson solver (p3s.NewtonPowerflow) Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt General AC power-flow solver for transmission networks, PV/generator buses and trafos. Pure-Python implementation (NumPy/SciPy). init="dc" (default) initialises with a DC power flow; tolerance defaults to 1e-5; max_iterations defaults to 30. Writes results back into the network and returns the converged voltage vector. ```python from p3s.NewtonPowerflow import NewtonPowerflow npf = NewtonPowerflow(net) voltage = npf.calculate(net, init="dc", tolerance=1e-8, max_iterations=30) ``` -------------------------------- ### NewtonPowerflowCpp.calculate Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt A drop-in accelerated variant of the Newton solver that offloads the sparse factorisation to the compiled `nr_klu` extension. It is opt-in because building it needs a C++17 compiler and SuiteSparse/KLU. ```APIDOC ## NewtonPowerflowCpp.calculate ### Description A drop-in accelerated variant of the Newton solver that offloads the sparse factorisation to the compiled `nr_klu` extension. It is opt-in because building it needs a C++17 compiler and SuiteSparse/KLU. ### Method Function call ### Endpoint `from p3s.NewtonPowerflowCpp import NewtonPowerflow as NewtonPowerflowCpp` ### Parameters - **net** (pandapowerNet) - Required - The pandapower network to solve. - **tolerance** (float) - Optional - Convergence threshold. Default is `1e-5` (implied). - **max_iterations** (int) - Optional - Maximum number of iterations. Default is `30`. ### Request Example ```python from p3s.NewtonPowerflowCpp import NewtonPowerflow as NewtonPowerflowCpp npf = NewtonPowerflowCpp(net) voltage = npf.calculate(net, tolerance=1e-8, max_iterations=30) ``` ### Response #### Success Response - **voltage** (array) - The converged voltage vector. #### Response Example ```python voltage = npf.calculate(net, tolerance=1e-8, max_iterations=30) print(voltage) ``` ``` -------------------------------- ### Compile results with compile_results.py Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/benchmark.html Submit a SLURM job to compile benchmark results into a specified output directory. ```bash sbatch tests/resources/compile_results.sbatch python tests/compile_results.py –output-dir /mnt/home/user/p3s/results ``` -------------------------------- ### Custom T values for benchmark_batched.py Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/benchmark.html Run benchmark_batched.py with custom time steps using the --T flag. ```bash # Test with different time steps python tests/benchmark/benchmark_batched.py --case case300 --T 100 500 1000 5000 ``` -------------------------------- ### Import p3s module Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/build.rst.txt Verifies that the built p3s module imports correctly. ```python from p3s import nr_klu ``` -------------------------------- ### Download tarball Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/installation.rst.txt Downloads the source code as a tarball from the master branch. ```sh curl -OJL https://github.com/e2niee/parallel-pandapower-solver/tarball/master ``` -------------------------------- ### Test with specific T values Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/benchmark.rst.txt Runs the benchmark for case118 with the gpu method and specific T values (64, 256, 1024). ```bash # Test with specific T values python tests/benchmark/benchmark_batched.py --case case118 --method gpu --T 64 256 1024 ``` -------------------------------- ### Run validation tests with pytest Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/build.html Run the test suite located in p3s/cpp/tests using pytest. The tests cover solve_batch vs scipy, NewtonPowerflowCpp.calculate vs pandapower runpp, and self-consistency of converged voltages. ```bash python -m pytest p3s/cpp/tests ``` -------------------------------- ### GPU solver (p3s.cuda.NewtonPowerflowCUDA) Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt CUDA-accelerated Newton solver. Batched solves run fully on the GPU. voltages has shape (n_bus, T). batch_size controls how many operating points are solved per GPU chunk. The underlying linear solve can be selected via a backend argument (e.g. "cudss"). ```python from p3s.cuda.NewtonPowerflowCuda import NewtonPowerflowCUDA npf = NewtonPowerflowCUDA(net) voltages = npf.calculate_timeseries_cuda(net, timeseries, batch_size=5) ``` -------------------------------- ### Solve contingencies with CPU solver solve_contingencies_cpp Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Solves all contingencies in parallel using the CPU backend. n_threads controls parallelism; if not given, all cores are used. reslack_islands=False by default. ```python from p3s.contingency.solver_cpp import solve_contingencies_cpp res = solve_contingencies_cpp(net, reslack_islands=False, n_threads=1) ``` -------------------------------- ### Clone repository Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/installation.rst.txt Clones the public repository from GitHub to obtain the source files. ```sh git clone git://github.com/e2niee/parallel-pandapower-solver ``` -------------------------------- ### Run p3s test suite Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/build.rst.txt Runs the validation tests located in p3s/cpp/tests/. ```bash python -m pytest p3s/cpp/tests ``` -------------------------------- ### solve_contingencies_cpp Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Solves all N-1 contingencies in parallel on CPU using the C++ backend. Returns a ContingencyResultTable with voltages, served mask, convergence flags, and iteration counts. ```APIDOC ## solve_contingencies_cpp ### Description Solves all N-1 contingencies in parallel on CPU. The function takes the network and optional parameters for island re-slacking and thread count. Returns a ContingencyResultTable. ### Method Function call ### Endpoint from p3s.contingency.solver_cpp import solve_contingencies_cpp ### Parameters - **net** (pandapower network) - Required - The pandapower network with outage_group columns on lines and transformers. - **reslack_islands** (bool) - Optional - If True, re-slacks islands that form after an outage so that the whole island is served. If False, such islands are entirely unserved. Default is False. - **n_threads** (int) - Optional - Number of threads to use in parallel. If not given, all cores are used. ### Request Example ```python from p3s.contingency.solver_cpp import solve_contingencies_cpp res = solve_contingencies_cpp(net, reslack_islands=False, n_threads=1) ``` ### Response #### Success Response - **res** (ContingencyResultTable) - The result table with groups, voltages, served mask, convergence flags, and iterations. #### Response Example ```python res = solve_contingencies_cpp(net, reslack_islands=False, n_threads=1) ``` ``` -------------------------------- ### Diagnose GPU Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/installation.rst.txt Performs in-depth analysis to verify that the powerflow solver works and that the hardware produces correct results. ```sh python -m p3s.cuda.diagnose_gpu ``` -------------------------------- ### Solve contingencies with GPU solver solve_contingencies_cuda Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Solves all contingencies using a GPU backend. backend options: cudss (default), rf (old cusolverRF), qr (more stable but slower). reslack_islands=False by default. ```python from p3s.contingency.solver_cuda import solve_contingencies_cuda res = solve_contingencies_cuda(net, reslack_islands=False, backend="cudss") ``` -------------------------------- ### Manual result compilation with compile_results.py Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/benchmark.html Compile results manually with options to include partial and error-unknown results, specifying an output directory. ```bash python compile_results.py \ --include-partial \ --include-error-unknown \ --output-dir ./results/235449/ ``` -------------------------------- ### Time-series data format Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/usage.html Describes the dictionary format accepted by batched solvers (calculate_timeseries_cpp, calculate_timeseries_cuda, etc.) for time-series simulation. ```APIDOC ## Time-series data format ### Description Batched solvers accept a timeseries dictionary mapping each controlled (element, variable) pair to an array of shape (n_element, T). Supported elements are load, sgen, and gen; supported variables are p_mw and q_mvar. ### Parameters - **timeseries** (dict) - Required - Dictionary with keys as (element, variable) tuples and values as arrays of shape (n_element, T). ### Example ```python timeseries = { ("load", "p_mw"): p_matrix, # (n_load, T) ("load", "q_mvar"): q_matrix, # (n_load, T) ("sgen", "p_mw"): ..., # (n_sgen, T) ("gen", "p_mw"): ..., # (n_gen, T) } ``` ``` -------------------------------- ### Batched time-series with C++ solver Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Solve many operating points at once, sharing the symbolic factorisation across the whole batch. voltages has shape (n_bus, T). n_threads=0 (default) uses all available threads; set to 1 for a single thread. ```python npf = NewtonPowerflowCpp(net) voltages = npf.calculate_timeseries_cpp(net, timeseries, n_threads=0) ``` -------------------------------- ### Solve contingencies on CPU Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/usage.html Executes contingency analysis using the CPU-based solver. The n_threads parameter controls parallel execution. ```python from p3s.contingency.solver_cpp import solve_contingencies_cpp res = solve_contingencies_cpp(net, reslack_islands=False, n_threads=1) ``` -------------------------------- ### NewtonPowerflow.calculate Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Runs the Newton-Raphson AC power-flow solver on a pandapower network. This is the pure-Python implementation (NumPy/SciPy) for transmission networks, PV/generator buses and trafos. It writes results back into the network and returns the converged voltage vector. ```APIDOC ## NewtonPowerflow.calculate ### Description Runs the Newton-Raphson AC power-flow solver on a pandapower network. This is the pure-Python implementation (NumPy/SciPy) for transmission networks, PV/generator buses and trafos. It writes results back into the network (e.g., `net.res_bus.vm_pu`, `net.res_bus.va_degree`, plus other `res_*` tables) and returns the converged voltage vector. ### Method Function call ### Endpoint `from p3s.NewtonPowerflow import NewtonPowerflow` ### Parameters - **net** (pandapowerNet) - Required - The pandapower network to solve. - **init** (str) - Optional - Initialisation method: `"dc"` (default) uses a DC power flow; `"flat"` uses a 1.0 pu / 0° flat start. DC init preserves voltage-magnitude set-points at PV buses. - **tolerance** (float) - Optional - Convergence threshold (infinity norm of the power mismatch). Default is `1e-5`. - **max_iterations** (int) - Optional - Maximum number of iterations. Default is `30`. - **Additional keyword arguments** - Optional - Passed through to `scipy.sparse.linalg.spsolve`. ### Request Example ```python from p3s.NewtonPowerflow import NewtonPowerflow npf = NewtonPowerflow(net) voltage = npf.calculate(net, init="dc", tolerance=1e-8, max_iterations=30) ``` ### Response #### Success Response - **voltage** (array) - The converged voltage vector. - **net.res_bus.vm_pu** (DataFrame) - Voltage magnitudes written to the network. - **net.res_bus.va_degree** (DataFrame) - Voltage angles written to the network. - **net["_ppc"]["iterations"]** (int) - Number of iterations taken. #### Response Example ```python voltage = npf.calculate(net, init="dc", tolerance=1e-8, max_iterations=30) print(voltage) ``` ``` -------------------------------- ### Calculate transformer tap table Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Compute the tap table for networks with transformers. With inplace=True the result is written to net.trafo_characteristic_table; with the default inplace=False it is returned instead. Call this before any of the solvers for networks that contain trafos. ```python from p3s.calculateTrafoTapTable import calculateTrafoCharacteristic calculateTrafoCharacteristic(net, inplace=True) ``` -------------------------------- ### solve_contingencies_cuda Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Solves all N-1 contingencies in parallel on GPU using the CUDA backend. Supports multiple backends (cudss, rf, qr) and returns a ContingencyResultTable. ```APIDOC ## solve_contingencies_cuda ### Description Solves all N-1 contingencies in parallel on GPU. The function takes the network and optional parameters for island re-slacking and backend selection. Returns a ContingencyResultTable. ### Method Function call ### Endpoint from p3s.contingency.solver_cuda import solve_contingencies_cuda ### Parameters - **net** (pandapower network) - Required - The pandapower network with outage_group columns on lines and transformers. - **reslack_islands** (bool) - Optional - If True, re-slacks islands that form after an outage so that the whole island is served. If False, such islands are entirely unserved. Default is False. - **backend** (str) - Optional - Backend to use: 'cudss' (cudss backend), 'rf' (old cusolverRF backend), or 'qr' (cuda QR algorithm, more stable but slower). Default is 'cudss'. ### Request Example ```python from p3s.contingency.solver_cuda import solve_contingencies_cuda res = solve_contingencies_cuda(net, reslack_islands=False, backend="cudss") ``` ### Response #### Success Response - **res** (ContingencyResultTable) - The result table with groups, voltages, served mask, convergence flags, and iterations. #### Response Example ```python res = solve_contingencies_cuda(net, reslack_islands=False, backend="cudss") ``` ``` -------------------------------- ### NewtonPowerflowCpp.calculate_timeseries_cpp Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Solves many operating points at once using the C++ solver, sharing the symbolic factorisation across the whole batch. Returns a voltage array of shape (n_bus, T). ```APIDOC ## NewtonPowerflowCpp.calculate_timeseries_cpp ### Description Solves many operating points at once using the C++ solver, sharing the symbolic factorisation across the whole batch. Returns a voltage array of shape `(n_bus, T)`. ### Method Function call ### Endpoint `from p3s.NewtonPowerflowCpp import NewtonPowerflow as NewtonPowerflowCpp` ### Parameters - **net** (pandapowerNet) - Required - The pandapower network to solve. - **timeseries** (dict) - Required - Dictionary mapping each controlled `(element, variable)` pair to an array of shape `(n_element, T)`. See Time-series data section. - **n_threads** (int) - Optional - Number of threads to use. Default `0` uses all available threads; set to `1` for a single thread. ### Request Example ```python npf = NewtonPowerflowCpp(net) voltages = npf.calculate_timeseries_cpp(net, timeseries, n_threads=0) ``` ### Response #### Success Response - **voltages** (array) - Array of shape `(n_bus, T)`, one complex voltage per bus per time step. #### Response Example ```python voltages = npf.calculate_timeseries_cpp(net, timeseries, n_threads=0) print(voltages.shape) ``` ``` -------------------------------- ### Generate contingency cases with generate_cases Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Generates contingency cases (outage_group) without solving, returning a ContingencyBatch with shared CSR pattern and per-case values. Pure NumPy/SciPy, no compiled backend needed. reslack_islands=False by default. ```python from p3s.contingency.case_generator import generate_cases batch = generate_cases(net, reslack_islands=False) ``` -------------------------------- ### Time-series data format Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Dictionary mapping each controlled (element, variable) pair to an array of shape (n_element, T). Used by the batched solvers (calculate_timeseries_cpp, calculate_timeseries_cuda, ...). ```python timeseries = { ("load", "p_mw"): p_matrix, # (n_load, T) ("load", "q_mvar"): q_matrix, # (n_load, T) ("sgen", "p_mw"): ..., # (n_sgen, T) ("gen", "p_mw"): ..., # (n_gen, T) } ``` -------------------------------- ### generate_cases Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Generates contingency cases (outage groups) up front without solving, returning a ContingencyBatch with shared sparsity pattern and per-case values. ```APIDOC ## generate_cases ### Description Generates the contingency cases (outage groups) up front, without solving, to inspect or reuse the shared sparsity pattern. Returns a ContingencyBatch exposing the shared CSR pattern (Yp, Yj), the intact-grid values Yx_base, the list of groups and the per-case values. The generator is pure NumPy/SciPy and needs no compiled backend. ### Method Function call ### Endpoint from p3s.contingency.case_generator import generate_cases ### Parameters - **net** (pandapower network) - Required - The pandapower network with outage_group columns on lines and transformers. - **reslack_islands** (bool) - Optional - If True, re-slacks islands that form after an outage so that the whole island is served. If False, such islands are entirely unserved. Default is False. ### Request Example ```python from p3s.contingency.case_generator import generate_cases batch = generate_cases(net, reslack_islands=False) ``` ### Response #### Success Response - **batch** (ContingencyBatch) - The generated contingency batch with shared sparsity pattern and per-case values. #### Response Example ```python batch = generate_cases(net, reslack_islands=False) ``` ``` -------------------------------- ### Access ContingencyResultTable fields Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Shows the attributes of the ContingencyResultTable returned by both solvers: groups, V, vm, va, served, converged, and iterations. ```python res.groups # list of contingency names, one per column res.V # (n_bus, L) complex voltages; NaN where a bus is unserved res.vm # |V| view of res.V res.va # angle view of res.V res.served # (n_bus, L) bool, exact served/unserved mask res.converged # (L,) bool, per-contingency convergence res.iterations # (L,) iterations per contingency ``` -------------------------------- ### NewtonPowerflowCUDA.calculate_timeseries_cuda Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt A CUDA-accelerated Newton solver for batched solves that run fully on the GPU. Returns a voltage array of shape (n_bus, T). ```APIDOC ## NewtonPowerflowCUDA.calculate_timeseries_cuda ### Description A CUDA-accelerated Newton solver for batched solves that run fully on the GPU. Returns a voltage array of shape `(n_bus, T)`. ### Method Function call ### Endpoint `from p3s.cuda.NewtonPowerflowCuda import NewtonPowerflowCUDA` ### Parameters - **net** (pandapowerNet) - Required - The pandapower network to solve. - **timeseries** (dict) - Required - Dictionary mapping each controlled `(element, variable)` pair to an array of shape `(n_element, T)`. See Time-series data section. - **batch_size** (int) - Optional - Number of operating points solved per GPU chunk. Default is `5`. - **backend** (str) - Optional - Selects the underlying linear solve, e.g. `"cudss"`. ### Request Example ```python from p3s.cuda.NewtonPowerflowCuda import NewtonPowerflowCUDA npf = NewtonPowerflowCUDA(net) voltages = npf.calculate_timeseries_cuda(net, timeseries, batch_size=5) ``` ### Response #### Success Response - **voltages** (array) - Array of shape `(n_bus, T)`. #### Response Example ```python voltages = npf.calculate_timeseries_cuda(net, timeseries, batch_size=5) print(voltages.shape) ``` ``` -------------------------------- ### ContingencyResultTable Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt The result table returned by both solvers, containing contingency names, complex voltages, voltage magnitude and angle views, served mask, convergence flags, and iteration counts. ```APIDOC ## ContingencyResultTable ### Description The result table returned by both solvers (CPU and GPU). It provides access to contingency names, complex voltages, voltage magnitude and angle views, served mask, convergence flags, and iteration counts. ### Method Object attributes ### Endpoint res.groups, res.V, res.vm, res.va, res.served, res.converged, res.iterations ### Parameters - **groups** (list) - List of contingency names, one per column. - **V** (array) - (n_bus, L) complex voltages; NaN where a bus is unserved. - **vm** (array) - |V| view of res.V. - **va** (array) - angle view of res.V. - **served** (array) - (n_bus, L) bool, exact served/unserved mask. - **converged** (array) - (L,) bool, per-contingency convergence. - **iterations** (array) - (L,) iterations per contingency. ### Request Example ```python res.groups # list of contingency names, one per column res.V # (n_bus, L) complex voltages; NaN where a bus is unserved res.vm # |V| view of res.V res.va # angle view of res.V res.served # (n_bus, L) bool, exact served/unserved mask res.converged # (L,) bool, per-contingency convergence res.iterations # (L,) iterations per contingency ``` ### Response #### Success Response - **groups** (list) - List of contingency names. - **V** (array) - Complex voltages. - **vm** (array) - Voltage magnitudes. - **va** (array) - Voltage angles. - **served** (array) - Served mask. - **converged** (array) - Convergence flags. - **iterations** (array) - Iteration counts. #### Response Example ```python res.groups # list of contingency names, one per column res.V # (n_bus, L) complex voltages; NaN where a bus is unserved res.vm # |V| view of res.V res.va # angle view of res.V res.served # (n_bus, L) bool, exact served/unserved mask res.converged # (L,) bool, per-contingency convergence res.iterations # (L,) iterations per contingency ``` ``` -------------------------------- ### calculateTrafoCharacteristic Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Computes the transformer tap table for networks with transformers. With inplace=True the result is written to net.trafo_characteristic_table; with inplace=False (default) it is returned instead. Call this before any solver for networks containing trafos. ```APIDOC ## calculateTrafoCharacteristic ### Description Computes the transformer tap table for networks with transformers. With `inplace=True` the result is written to `net.trafo_characteristic_table`; with the default `inplace=False` it is returned instead. Call this before any of the solvers for networks that contain trafos. ### Method Function call ### Endpoint `from p3s.calculateTrafoTapTable import calculateTrafoCharacteristic` ### Parameters - **net** (pandapowerNet) - Required - The pandapower network containing transformers. - **inplace** (bool) - Optional - If True, writes the result to `net.trafo_characteristic_table`; if False (default), returns the result. ### Request Example ```python from p3s.calculateTrafoTapTable import calculateTrafoCharacteristic calculateTrafoCharacteristic(net, inplace=True) ``` ### Response #### Success Response - **net.trafo_characteristic_table** (DataFrame) - The computed tap table, written to the network when `inplace=True`. - **return value** (DataFrame) - The computed tap table, returned when `inplace=False`. #### Response Example ```python # When inplace=False tap_table = calculateTrafoCharacteristic(net) ``` ``` -------------------------------- ### Tag branches with outage_group column Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/usage.rst.txt Assigns each line and transformer its own outage_group index so each branch is considered as a separate contingency. Branches with null outage_group are never included; branches sharing a value are removed together. ```python net.line["outage_group"] = net.line.index # each line its own group net.trafo["outage_group"] = net.trafo.index ``` -------------------------------- ### Check cuDSS availability Source: https://parallel-pandapower-solver.readthedocs.io/en/stable/_sources/installation.rst.txt Checks whether cuDSS is actually usable for p3s. Nvidia cuDSS is currently the newest sparse matrix solver available for Nvidia hardware. ```sh python -m p3s.cuda.check_cudss ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.