{"id":29698606,"url":"https://github.com/powsybl/powsybl-open-loadflow-knitro-solver","last_synced_at":"2025-07-23T10:10:49.288Z","repository":{"id":265516633,"uuid":"883763713","full_name":"powsybl/powsybl-open-loadflow-knitro-solver","owner":"powsybl","description":"An extension to PowSyBl Open Load Flow to solve the load flow equations with the non-linear solver Knitro","archived":false,"fork":false,"pushed_at":"2025-06-26T16:11:39.000Z","size":241,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-26T17:19:35.807Z","etag":null,"topics":["energy-system","java","knitro","load-flow","power-flow","power-system-simulation","power-systems","powerflow","powsybl"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/powsybl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-05T14:30:52.000Z","updated_at":"2025-06-10T12:54:00.000Z","dependencies_parsed_at":"2024-12-18T14:26:56.065Z","dependency_job_id":"5986dcc5-b81a-41df-99a9-ca56e3b15901","html_url":"https://github.com/powsybl/powsybl-open-loadflow-knitro-solver","commit_stats":null,"previous_names":["powsybl/powsybl-open-loadflow-knitro-solver"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/powsybl/powsybl-open-loadflow-knitro-solver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powsybl%2Fpowsybl-open-loadflow-knitro-solver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powsybl%2Fpowsybl-open-loadflow-knitro-solver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powsybl%2Fpowsybl-open-loadflow-knitro-solver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powsybl%2Fpowsybl-open-loadflow-knitro-solver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/powsybl","download_url":"https://codeload.github.com/powsybl/powsybl-open-loadflow-knitro-solver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/powsybl%2Fpowsybl-open-loadflow-knitro-solver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266658748,"owners_count":23963745,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["energy-system","java","knitro","load-flow","power-flow","power-system-simulation","power-systems","powerflow","powsybl"],"created_at":"2025-07-23T10:10:42.237Z","updated_at":"2025-07-23T10:10:49.278Z","avatar_url":"https://github.com/powsybl.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PowSyBl Open Load Flow - Knitro Solver\n\n[![Actions Status](https://github.com/powsybl/powsybl-open-loadflow-knitro-solver/workflows/CI/badge.svg)](https://github.com/powsybl/powsybl-open-loadflow-knitro-solver/actions/workflows/maven.yml)\n[![Snapshot Status](https://github.com/powsybl/powsybl-open-loadflow-knitro-solver/workflows/Snapshot%20CI/badge.svg)](https://github.com/powsybl/powsybl-open-loadflow-knitro-solver/actions/workflows/snapshot-ci.yml)\n[![Coverage Status](https://sonarcloud.io/api/project_badges/measure?project=com.powsybl%3Apowsybl-open-loadflow-knitro-solver\u0026metric=coverage)](https://sonarcloud.io/component_measures?id=com.powsybl%3Apowsybl-open-loadflow-knitro-solver\u0026metric=coverage)\n[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=com.powsybl%3Apowsybl-open-loadflow-knitro-solver\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=com.powsybl%3Apowsybl-open-loadflow-knitro-solver)\n[![MPL-2.0 License](https://img.shields.io/badge/license-MPL_2.0-blue.svg)](https://www.mozilla.org/en-US/MPL/2.0/)\n[![Slack](https://img.shields.io/badge/slack-powsybl-blueviolet.svg?logo=slack)](https://join.slack.com/t/powsybl/shared_invite/zt-rzvbuzjk-nxi0boim1RKPS5PjieI0rA)\n\n\nPowSyBl (**Pow**er **Sy**stem **Bl**ocks) is an open source library written in Java, that makes it easy to write complex\nsoftware for power systems’ simulations and analysis. Its modular approach allows developers to extend or customize its\nfeatures.\n\nPowSyBl is part of the LF Energy Foundation, a project of The Linux Foundation that supports open source innovation projects\nwithin the energy and electricity sectors.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/powsybl/powsybl-gse/main/gse-spi/src/main/resources/images/logo_lfe_powsybl.svg?sanitize=true\" alt=\"PowSyBl Logo\" width=\"50%\"/\u003e\n\u003c/p\u003e\n\nRead more at https://www.powsybl.org !\n\nThis project and everyone participating in it is under the [Linux Foundation Energy governance principles](https://www.powsybl.org/pages/project/governance.html) and must respect the [PowSyBl Code of Conduct](https://github.com/powsybl/.github/blob/main/CODE_OF_CONDUCT.md).\nBy participating, you are expected to uphold this code. Please report unacceptable behavior to [powsybl-tsc@lists.lfenergy.org](mailto:powsybl-tsc@lists.lfenergy.org).\n\n## PowSyBl vs PowSyBl Open Load Flow Knitro Solver\n\nPowSyBl Open Load Flow Knitro Solver is an extension to [PowSyBl Open Load Flow](https://github.com/powsybl/powsybl-open-loadflow) allowing to solve\nthe load flow equations with the **non-linear solver Knitro** instead of the default **Newton-Raphson** method.\n\nThe Knitro solver extension models the load flow problem as a **constraint satisfaction problem** (without an objective function).\n\n## Getting Started\n\nTo use the PowSyBl Open Load Flow Knitro Solver extension, a valid Knitro installation is required.\n\n### Platform compatibility\n\nKnitro supports Linux, Windows, and macOS; however, its Java bindings are currently available only on Linux and Windows.\n\n### Installing Knitro\n\n1. Obtain the installation kit and trial license from the [Artelys website](https://www.artelys.com/solvers/knitro/programs/#trial).\n2. Configure the following environment variables:\n  - `KNITRODIR`: Path to the Knitro installation directory.\n  - `ARTELYS_LICENSE`: Path to the Knitro license file or its content.\n\nYou may then validate your installation by running one of the Java examples like this (here on Linux):\n\n```bash\ncd $KNITRODIR/examples/java/examples\n# compile example\njavac -cp \".;../lib/*\" com/artelys/knitro/examples/ExampleNLP1.java\n# run example\njava -cp \".;../lib/*\" com.artelys.knitro.examples.ExampleNLP1\n```\n\n\u003cdetails\u003e\n\n\u003csummary\u003eHere an example output (click to expand)\u003c/summary\u003e\n\n```\n$ java -cp \".;../lib/*\" com.artelys.knitro.examples.ExampleNLP1\n\n--- snip ---\n\nOptimal objective value  = 306.5000025616414\nOptimal x (with corresponding multiplier)\nx1 = 0,500000 (lambda = -700,000000)\nx2 = 2,000000 (lambda = -0,000000)\nOptimal constraint values (with corresponding multiplier)\n c[0] = 1,000000 (lambda = -700,000000)\n c[1] = 4,500000 (lambda = -0,000000)\nFeasibility violation    = 0,000000\nOptimality violation     = 0,000003\n```\n\n\u003c/details\u003e\n\n\n### Installing Knitro Java Bindings\nKnitro Java bindings require a private JAR file that must be installed locally, as it is not available on Maven Central.\nUse the following command:\n\n```bash\n./mvnw install:install-file -Dfile=\"$KNITRODIR/examples/Java/lib/Knitro-Interfaces-2.5-KN_14.2.0.jar\" -DgroupId=com.artelys -DartifactId=knitro-interfaces -Dversion=14.2.0 -Dpackaging=jar -DgeneratePom=true\n```\n\n### Running a Load Flow with Knitro Solver\n\nTo run a load flow with PowSyBl Open Load Flow Knitro Solver. We first add a few Maven\ndependencies to respectively have access to network model, IEEE test networks and simple logging capabilities:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.powsybl\u003c/groupId\u003e\n    \u003cartifactId\u003epowsybl-iidm-impl\u003c/artifactId\u003e\n    \u003cversion\u003e6.7.0\u003c/version\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.powsybl\u003c/groupId\u003e\n    \u003cartifactId\u003epowsybl-ieee-cdf-converter\u003c/artifactId\u003e\n    \u003cversion\u003e6.7.0\u003c/version\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.slf4j\u003c/groupId\u003e\n    \u003cartifactId\u003eslf4j-simple\u003c/artifactId\u003e\n    \u003cversion\u003e2.0.13\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nWe are now able to load the IEEE 14 bus test network:\n ```java\nNetwork network = IeeeCdfNetworkFactory.create14();\n ```\n\nAfter adding dependency on both Open Load Flow implementation and Knitro Solver extension:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.powsybl\u003c/groupId\u003e\n    \u003cartifactId\u003epowsybl-open-loadflow\u003c/artifactId\u003e\n    \u003cversion\u003e1.15.0\u003c/version\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.powsybl\u003c/groupId\u003e\n    \u003cartifactId\u003epowsybl-open-loadflow-knitro-solver\u003c/artifactId\u003e\n    \u003cversion\u003e0.1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nTo run the load flow with the Knitro solver, configure the\n[Open Load Flow parameter `acSolverType`](https://powsybl.readthedocs.io/projects/powsybl-open-loadflow/en/latest/loadflow/parameters.html)\nas follows:\n\n```java\nLoadFlowParameters parameters = new LoadFlowParameters();\nOpenLoadFlowParameters.create(parameters)\n   .setAcSolverType(\"KNITRO\"); // Change default Open Load Flow parameter acSolverType from NEWTON_RAPHSON to KNITRO\nLoadFlow.run(network, parameters);\n```\n\n## Features\n\nThe Knitro solver is used as a substitute for the **inner loop calculations** in the load flow process.\nThe **outer loops** such as distributed slack, reactive limits, etc... operate identically as when using the Newton-Raphson method.\n\n### Configuration\n\nMost parameters for Knitro are configured similarly to the Newton-Raphson method.\nHowever, specific parameters tailored to Knitro are provided through the `KnitroLoadFlowParameters` extension of `LoadFlowParameters`. \n\nHere an example on how to provide Knitro solver specific parameters in Java:\n\n```java\nLoadFlowParameters parameters = new LoadFlowParameters();\nOpenLoadFlowParameters.create(parameters)\n   .setAcSolverType(\"KNITRO\");\nKnitroLoadFlowParameters knitroLoadFlowParameters = new KnitroLoadFlowParameters();\nknitroLoadFlowParameters.setGradientComputationMode(2);\nparameters.addExtension(KnitroLoadFlowParameters.class, knitroLoadFlowParameters);\n```\n\n### Knitro Parameters\n\n1. **Voltage Bounds**:\n    - Default range: **0.5 p.u. to 1.5 p.u.** : they define lower and upper bounds of voltages.\n    - Modify using:\n        - `setLowerVoltageBound`\n        - `setUpperVoltageBound`\n\n2. **Jacobian Matrix Usage**:\n    - The solver utilizes the **Jacobian matrix** for solving successive linear approximations of the problem.\n    - **Gradient Computation Modes**:\n        - `1 (exact)`: Gradients computed in PowSyBl are provided to Knitro.\n        - `2 (forward)`: Knitro computes gradients via forward finite differences.\n        - `3 (central)`: Knitro computes gradients via central finite differences.\n    - Use `setGradientComputationMode` in the `KnitroLoadFlowParameters` extension.\n\n3. **Jacobian Sparsity**:\n    - Default: **Sparse form** (highly recommended, improves calculation as load flow problems are highly sparse problems).\n    - To specify dense form:\n        - Use `setGradientUserRoutineKnitro` in the `KnitroLoadFlowParameters` extension.\n    - **Options**:\n        - `1 (dense)`: All constraints are considered as dependent of all variables.\n        - `2 (sparse)`: Derivatives are computed only for variables involved in the constraints (recommended).\n\n4. **Maximum Iterations**:\n    - Default: **200**\n    - Modify using `setMaxIterations`.\n\n### Constraint Handling\n\nConstraints are categorized into two types:\n\n1. **Linear and Quadratic Constraints**:\n    - Explicitly passed to the solver.\n\n2. **Non-linear (Non-quadratic) Constraints**:\n    - Evaluated during each iteration by a **callback class**, based on the current state.\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowsybl%2Fpowsybl-open-loadflow-knitro-solver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpowsybl%2Fpowsybl-open-loadflow-knitro-solver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpowsybl%2Fpowsybl-open-loadflow-knitro-solver/lists"}