PowSyBl (Power System Blocks) is an open source library written in Java, that makes it easy to write complex software for power systems’ simulations and analysis. Its modular approach allows developers to extend or customize its features.
PowSyBl is part of the LF Energy Foundation, a project of The Linux Foundation that supports open source innovation projects within the energy and electricity sectors.
Read more at https://www.powsybl.org !
This project and everyone participating in it is under the Linux Foundation Energy governance principles and must respect the PowSyBl Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].
PowSyBl Open Load Flow Knitro Solver is an extension to PowSyBl Open Load Flow allowing to solve the load flow equations with the non-linear solver Knitro instead of the default Newton-Raphson method.
The Knitro solver extension offers two different ways to model the load flow problem: either as a constraint satisfaction problem (without an objective function) or as an optimisation problem with relaxed constraints (and an objective function minimizing the violations).
To use the PowSyBl Open Load Flow Knitro Solver extension, a valid Knitro installation is required.
PowSyBl Open Load Flow Knitro Solver supports Linux, Windows, and macOS.
The PowSyBl Open Load Flow Knitro Solver extension currently uses Knitro 15.1.0.
- Obtain the installation kit and trial license from the Artelys website.
- Configure the following environment variables:
KNITRODIR: Path to the Knitro installation directory.ARTELYS_LICENSE: Path to the Knitro license file or its content.
You may then validate your installation by running one of the Java examples like this (here on Linux):
cd $KNITRODIR/examples/java/examples
# compile example
javac -cp ".;../lib/*" com/artelys/knitro/examples/ExampleNLP1.java
# run example
java -cp ".;../lib/*" com.artelys.knitro.examples.ExampleNLP1Here an example output (click to expand)
$ java -cp ".;../lib/*" com.artelys.knitro.examples.ExampleNLP1
--- snip ---
Optimal objective value = 306.5000025616414
Optimal x (with corresponding multiplier)
x1 = 0,500000 (lambda = -700,000000)
x2 = 2,000000 (lambda = -0,000000)
Optimal constraint values (with corresponding multiplier)
c[0] = 1,000000 (lambda = -700,000000)
c[1] = 4,500000 (lambda = -0,000000)
Feasibility violation = 0,000000
Optimality violation = 0,000003
The Knitro Java bindings require a private JAR file that must be installed locally, as it is not available on Maven Central.
On Linux or macOS, use the following command:
./mvnw install:install-file -Dfile="$KNITRODIR/examples/Java/lib/Knitro-Interfaces-2.5-KN_15.1.0.jar" -DgroupId=com.artelys -DartifactId=knitro-interfaces -Dversion=15.1.0 -Dpackaging=jar -DgeneratePom=trueOn Windows, use the following command:
mvn install:install-file -Dfile="$env:KNITRODIR/examples/Java/lib/Knitro-Interfaces-2.5-KN_15.1.0.jar" -DgroupId="com.artelys" -DartifactId=knitro-interfaces -Dversion="15.1.0" -Dpackaging=jar -DgeneratePom=trueTo run a load flow with PowSyBl Open Load Flow Knitro Solver. We first add a few Maven dependencies to respectively have access to network model, IEEE test networks and simple logging capabilities:
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-impl</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-ieee-cdf-converter</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.13</version>
</dependency>We are now able to load the IEEE 14 bus test network:
Network network = IeeeCdfNetworkFactory.create14();After adding dependency on both Open Load Flow implementation and Knitro Solver extension:
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-open-loadflow</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-open-loadflow-knitro-solver</artifactId>
<version>0.1.0</version>
</dependency>To run the load flow with the Knitro solver, configure the
Open Load Flow parameter acSolverType
as follows:
LoadFlowParameters parameters = new LoadFlowParameters();
OpenLoadFlowParameters.create(parameters)
.setAcSolverType("KNITRO"); // Change default Open Load Flow parameter acSolverType from NEWTON_RAPHSON to KNITRO
LoadFlow.run(network, parameters);The Knitro solver is used as a substitute for the inner loop calculations in the load flow process. The outer loops such as distributed slack, reactive limits, etc... operate identically as when using the Newton-Raphson method.
Most parameters for Knitro are configured similarly to the Newton-Raphson method.
However, specific parameters tailored to Knitro are provided through the KnitroLoadFlowParameters extension of LoadFlowParameters.
Here an example on how to provide Knitro solver specific parameters in Java:
LoadFlowParameters parameters = new LoadFlowParameters();
OpenLoadFlowParameters.create(parameters)
.setAcSolverType("KNITRO");
KnitroLoadFlowParameters knitroLoadFlowParameters = new KnitroLoadFlowParameters();
knitroLoadFlowParameters.setGradientComputationMode(2);
parameters.addExtension(KnitroLoadFlowParameters.class, knitroLoadFlowParameters);-
Knitro Solver Type:
- Specifies the way to model the load flow problem :
-
Knitro Solver Types:
-
STANDARD (default): the constraint satisfaction problem formulation and a direct substitute to the Newton-Raphson solver. -
RELAXED: the optimisation problem formulation relaxing satisfaction problem.
-
- Use
setKnitroSolverTypein theKnitroLoadFlowParametersextension.
-
Voltage Bounds:
- Default range: 0.5 p.u. to 1.5 p.u. : they define lower and upper bounds of voltages.
- Modify using:
setLowerVoltageBoundsetUpperVoltageBound
-
Jacobian Matrix Usage:
- The solver utilizes the Jacobian matrix for solving successive linear approximations of the problem.
-
Gradient Computation Modes:
-
1 (exact): Gradients computed in PowSyBl are provided to Knitro. -
2 (forward): Knitro computes gradients via forward finite differences. -
3 (central): Knitro computes gradients via central finite differences.
-
- Use
setGradientComputationModein theKnitroLoadFlowParametersextension. - Warning: for options
2 (forward)and3 (central)set the solver's number of threads to 1 usingsetThreadNumberin theKnitroLoadFlowParametersextension.
-
Jacobian Sparsity:
- Default: Sparse form (highly recommended, improves calculation as load flow problems are highly sparse problems).
- To specify dense form:
- Use
setGradientUserRoutineKnitroin theKnitroLoadFlowParametersextension.
- Use
-
Options:
-
1 (dense): All constraints are considered as dependent of all variables. -
2 (sparse): Derivatives are computed only for variables involved in the constraints (recommended).
-
-
Hessian Matrix Usage:
- The solver utilizes the Hessian matrix of the problem's Lagrangian.
-
Hessian Computation Mode:
-
1 (exact): Exact Hessian matrix is provided to Knitro. (not implemented yet) -
2 (bfgs): Knitro computes a (dense) quasi-Newton BFGS Hessian. -
3 (sr1): Knitro computes a (dense) quasi-Newton SR1 Hessian. -
4 (product_findiff): Knitro computes Hessian-vector products using finite-differences. -
5 (product): User provides a routine to compute the Hessian-vector products. -
6 (lbfgs): Knitro computes a limited-memory quasi-Newton BFGS Hessian with size 10 limited memory pairs. (recommended for large network) -
7 (gauss_newton): Knitro computes a Gauss-Newton approximation of the hessian.
-
- Use
setHessianComputationModein theKnitroLoadFlowParametersextension.
-
Feasibility Stopping Criteria:
- Default values:
$10^{-6}$ p.u for relative (to initial value) feasibility error and$10^{-3}$ p.u for absolute feasibility error. - Modify in the
KnitroLoadFlowParametersextension using:setRelConvEpssetAbsConvEps
- Default values:
-
Optimality Stopping Criteria:
- Default values:
$10^{-6}$ p.u for relative (to initial value) optimality error and$10^{-3}$ p.u for absolute optimality error. - Specify the final stopping tolerances for the KKT (optimality) error.
- Modify in the
KnitroLoadFlowParametersextension using:setRelOptEpssetAbsOptEps
- Default values:
-
Maximum Iterations:
- Default: 200
- Modify using
setMaxIterations.
-
Slack Threshold:
- Default value:
$10^{-6}$ p.u : defines a slack values threshold below which we ignore insignificant activated slack variables. - Use
setSlackThresholdin theKnitroLoadFlowParametersextension.
- Default value:
-
Number of Threads:
- Default value: -1 (Knitro will automatically determine the number of threads to use and how to distribute them)
- Specify the number of threads to be used when solving the problem.
- Use
setThreadNumberin theKnitroLoadFlowParametersextension. - Warning: for options
2 (forward)and3 (central)set the solver's number of threads to 1.
Constraints are categorized into two types:
-
Linear and Quadratic Constraints:
- Explicitly passed to the solver.
-
Non-linear (Non-quadratic) Constraints:
- Evaluated during each iteration by a callback class, based on the current state.