Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 23 additions & 26 deletions docs/examples/Power Flow Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"## Validation (optional)\n",
"For efficiency reasons, most of the data is not explicitly validated in the power grid model. However, in most cases, a power flow calculation will fail/crash if the data is invalid. Often with a low level error message that is hard to relate to the original objects. Therfore, it is recommended to always validate your data before constructing a PowerGridModel instance.\n",
"\n",
"The simplest and most effective way to validate your data is by using `assert_valid_input_data()` which will throw an error if it encounters any invalid data. See [Validation Examples](./Validation%20Examples.ipynb) for more detailed information on the validation functions."
"The simplest and most effective way to validate your data is by using `assert_valid_input_data()` which will throw an error if it encounters any invalid data. See the [Error Handling](#error-handling) section in this example notebook and [Validation Examples](./Validation%20Examples.ipynb) for more detailed information on the validation functions."
]
},
{
Expand Down Expand Up @@ -462,7 +462,9 @@
"id": "3d9d3d45",
"metadata": {},
"source": [
"### Validation (optional)"
"### Validation (optional)\n",
"\n",
"When performing batch calculation/updating dataset, `power-grid-model` provides the functions to validate. See the [Error Handling](#error-handling) section in this example notebook, or [Validation Examples](./Validation%20Examples.ipynb) for more detailed information on the validation functions."
]
},
{
Expand Down Expand Up @@ -916,18 +918,9 @@
"source": [
"## Error Handling\n",
"\n",
"The error handeling of `power-grid-model` is using exceptions in all cases."
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "cd824d12",
"metadata": {},
"source": [
"### Raise Exception\n",
"\n",
"If there is an error in the ctypes wrapper, a relevant exception will be raised (e.g. `KeyError`). If there is an error in the C++ core, the C++ exception will be translated into a `PowerGridError` in Python. Below we show some examples for the errors in the construction, update, and calculation."
"The error handeling of `power-grid-model` is done with exceptions in all cases.\n",
"We also provide an validation mechanism, which validates data structures and values offline. It is recommended to always validate your data before constructing a PowerGridModel instance. An alternative approach would be to validate only when an exception is raised, but be aware that not all data errors will raise exceptions: most of them will just yield invalid results without warning.\n",
"Below we give examples of catching different error types in power grid model calculations. Refer to [Validation Examples](./Validation%20Examples.ipynb) for more detailed information on the validation functions."
]
},
{
Expand All @@ -938,7 +931,7 @@
"source": [
"#### Construction\n",
"\n",
"We try to construct a grid with a line connecting two nodes with different rated voltages. An error is raised in the construction."
"We try to construct a grid with a line connecting two nodes with different rated voltages. An `ConflictVoltage` error is caught in the construction."
]
},
{
Expand All @@ -961,7 +954,7 @@
}
],
"source": [
"from power_grid_model.errors import PowerGridError\n",
"from power_grid_model.errors import PowerGridError, ConflictVoltage\n",
"\n",
"# node\n",
"node_error = initialize_array(\"input\", \"node\", 2)\n",
Expand All @@ -980,14 +973,16 @@
"line_error[\"tan1\"] = [0.0]\n",
"line_error[\"i_n\"] = [1000]\n",
"\n",
"error_data = {\n",
" \"node\": node_error,\n",
" \"line\": line_error\n",
"}\n",
"\n",
"try:\n",
" PowerGridModel(\n",
" {\n",
" \"node\": node_error,\n",
" \"line\": line_error\n",
" }\n",
" )\n",
"except PowerGridError as e:\n",
" assert_valid_input_data(error_data, symmetric=True)\n",
" model = PowerGridModel(error_data)\n",
" output_data = model.calculate_state_estimation(symmetric=True)\n",
"except ConflictVoltage as e:\n",
" print(e)"
]
},
Expand Down Expand Up @@ -1020,14 +1015,16 @@
}
],
"source": [
"from power_grid_model.errors import IDNotFound\n",
"\n",
"line_update_error = initialize_array(\"update\", \"line\", 1)\n",
"line_update_error[\"id\"] = [12345] # non-existing\n",
"line_update_error[\"from_status\"] = [1]\n",
"\n",
"\n",
"try:\n",
" model.update(update_data={\"line\": line_update_error})\n",
"except PowerGridError as e:\n",
"except IDNotFound as e:\n",
" print(e)"
]
},
Expand Down Expand Up @@ -1118,7 +1115,7 @@
"\n",
"Failed scenarios: [3 7]\n",
"Succeeded scenarios: [0 1 2 4 5 6 8 9]\n",
"Error messages: ['The id cannot be found: 1000\\n', 'Iteration failed to converge after 20 iterations! Max deviation: 43691065954360128432752954469939668333328459052496602949289781148532517437499693334528.000000, error tolerance: 0.000000.\\n']\n"
"Error messages: ['The id cannot be found: 1000\\n', 'Iteration failed to converge after 20 iterations! Max deviation: 58117414400716408619540873986620695630846752310955626332790372168240900260914085756928.000000, error tolerance: 0.000000.\\n']\n"
]
}
],
Expand Down Expand Up @@ -1218,7 +1215,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
"version": "3.12.3"
},
"vscode": {
"interpreter": {
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/Validation Examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Validation Examples\n",
"\n",
"As a result of optimizations, and the low level nature of the Power Grid Model's mathematical core, the core exceptions may not always be clear to the user. Therefore an optional validation mechanism is supplied, which validates data structures and values off-line. It is recommended to always validate your data before constructing a PowerGridModel instance. An alternative approach would be to validate only when an exception is raised, but be aware that not all data errors will raise exceptions, most of them wil just yield invalid results without warning."
"As a result of optimizations, and the low level nature of the Power Grid Model's mathematical core, the core exceptions may not always be clear to the user. Therefore an optional validation mechanism is supplied, which validates data structures and values off-line. It is recommended to always validate your data before constructing a PowerGridModel instance. An alternative approach would be to validate only when an exception is raised, but be aware that not all data errors will raise exceptions: most of them will just yield invalid results without warning."
]
},
{
Expand Down