|
47 | 47 | "import numpy as np\n", |
48 | 48 | "import pandas as pd\n", |
49 | 49 | "\n", |
50 | | - "from power_grid_model import LoadGenType, ComponentType, DatasetType, ComponentAttributeFilterOptions\n", |
51 | | - "from power_grid_model import PowerGridModel, CalculationMethod, CalculationType\n", |
52 | | - "from power_grid_model import initialize_array, attribute_dtype" |
| 50 | + "from power_grid_model import (\n", |
| 51 | + " CalculationMethod,\n", |
| 52 | + " CalculationType,\n", |
| 53 | + " ComponentAttributeFilterOptions,\n", |
| 54 | + " ComponentType,\n", |
| 55 | + " DatasetType,\n", |
| 56 | + " LoadGenType,\n", |
| 57 | + " PowerGridModel,\n", |
| 58 | + " attribute_dtype,\n", |
| 59 | + " initialize_array,\n", |
| 60 | + ")" |
53 | 61 | ] |
54 | 62 | }, |
55 | 63 | { |
|
464 | 472 | " max_iterations=20,\n", |
465 | 473 | " calculation_method=CalculationMethod.newton_raphson,\n", |
466 | 474 | " output_component_types={\n", |
467 | | - " ComponentType.node: None, # node output as row-based\n", |
468 | | - " ComponentType.line: [\"id\", \"p_from\"], # line output columns id and p_from\n", |
469 | | - " ComponentType.sym_load: ComponentAttributeFilterOptions.everything, # all sym_load attributes as columns\n", |
| 475 | + " # node output as row-based\n", |
| 476 | + " ComponentType.node: None,\n", |
| 477 | + " # line output columns id and p_from\n", |
| 478 | + " ComponentType.line: [\"id\", \"p_from\"],\n", |
| 479 | + " # all sym_load attributes as columns\n", |
| 480 | + " ComponentType.sym_load: ComponentAttributeFilterOptions.everything,\n", |
470 | 481 | " },\n", |
471 | 482 | ")\n", |
472 | 483 | "\n", |
|
515 | 526 | " error_tolerance=1e-8,\n", |
516 | 527 | " max_iterations=20,\n", |
517 | 528 | " calculation_method=CalculationMethod.newton_raphson,\n", |
518 | | - " output_component_types=ComponentAttributeFilterOptions.everything, # all attributes for all component types as columns\n", |
| 529 | + " # all attributes for all component types as columns\n", |
| 530 | + " output_component_types=ComponentAttributeFilterOptions.everything,\n", |
519 | 531 | ")\n", |
520 | 532 | "\n", |
521 | 533 | "print(\"List of component types in result dataset\")\n", |
|
934 | 946 | "source": [ |
935 | 947 | "##### Accessing batch data\n", |
936 | 948 | "\n", |
937 | | - "It may be a bit unintuitive to read the `output_data` or `update_data` of a component directly as they are a dictionary of 3 dimension data, ie. $ids \\times batches \\times attributes$. Remember that the `output_data` or `update_data` are a dictionary of numpy structured arrays. Hence the component should be indexed first. The index that follows can be [indexed with numpy structured arrays](https://numpy.org/doc/stable/user/basics.rec.html#indexing-structured-arrays)\n", |
| 949 | + "It may be a bit unintuitive to read the `output_data` or `update_data` of a component directly as they are a dictionary of 3 dimension data, i.e., $ids \\times batches \\times attributes$. Remember that the `output_data` or `update_data` are a dictionary of numpy structured arrays. Hence the component should be indexed first. The index that follows can be [indexed with numpy structured arrays](https://numpy.org/doc/stable/user/basics.rec.html#indexing-structured-arrays)\n", |
938 | 950 | "\n", |
939 | 951 | "To read the result of a single batch, lets say 1st batch," |
940 | 952 | ] |
|
1216 | 1228 | } |
1217 | 1229 | ], |
1218 | 1230 | "source": [ |
1219 | | - "from power_grid_model.errors import PowerGridError, ConflictVoltage\n", |
| 1231 | + "from power_grid_model.errors import ConflictVoltage, PowerGridError\n", |
1220 | 1232 | "\n", |
1221 | 1233 | "# node\n", |
1222 | 1234 | "node_error = initialize_array(DatasetType.input, ComponentType.node, 2)\n", |
|
1372 | 1384 | "\n", |
1373 | 1385 | "Failed scenarios: [3 7]\n", |
1374 | 1386 | "Succeeded scenarios: [0 1 2 4 5 6 8 9]\n", |
1375 | | - "Error messages: ['The id cannot be found: 1000\\n', 'Iteration failed to converge after 20 iterations! Max deviation: 5.81174e+85, error tolerance: 1e-08.\\n']\n" |
| 1387 | + "Error messages: ['The id cannot be found: 1000\\n', 'Sparse matrix error, possibly singular matrix!\\nIf you get this error from state estimation, it might mean the system is not fully observable, i.e. not enough measurements.\\nIt might also mean that you are running into a corner case where PGM cannot resolve yet.See https://github.com/PowerGridModel/power-grid-model/issues/864.']\n" |
1376 | 1388 | ] |
1377 | 1389 | } |
1378 | 1390 | ], |
|
1403 | 1415 | "output_type": "stream", |
1404 | 1416 | "text": [ |
1405 | 1417 | "Node data with invalid results\n", |
1406 | | - "[[9.99401170e-001 9.92685785e-001 9.94521366e-001]\n", |
1407 | | - " [9.99347687e-001 9.86226389e-001 9.89352855e-001]\n", |
1408 | | - " [9.99288384e-001 9.79654011e-001 9.84095542e-001]\n", |
1409 | | - " [3.94357132e+180 2.87518198e+161 2.04418455e+214]\n", |
1410 | | - " [9.99151380e-001 9.66149483e-001 9.73298790e-001]\n", |
1411 | | - " [9.99073166e-001 9.59205860e-001 9.67750710e-001]\n", |
1412 | | - " [9.98988099e-001 9.52126208e-001 9.62096474e-001]\n", |
1413 | | - " [0.00000000e+000 0.00000000e+000 0.00000000e+000]\n", |
1414 | | - " [9.98796126e-001 9.37530046e-001 9.50447962e-001]\n", |
1415 | | - " [9.98688504e-001 9.29997471e-001 9.44441670e-001]]\n", |
| 1418 | + "[[ 9.99401170e-001 9.92685785e-001 9.94521366e-001]\n", |
| 1419 | + " [ 9.99347687e-001 9.86226389e-001 9.89352855e-001]\n", |
| 1420 | + " [ 9.99288384e-001 9.79654011e-001 9.84095542e-001]\n", |
| 1421 | + " [-2.66881060e+116 2.33997016e-302 6.70346672e-198]\n", |
| 1422 | + " [ 9.99151380e-001 9.66149483e-001 9.73298790e-001]\n", |
| 1423 | + " [ 9.99073166e-001 9.59205860e-001 9.67750710e-001]\n", |
| 1424 | + " [ 9.98988099e-001 9.52126208e-001 9.62096474e-001]\n", |
| 1425 | + " [-2.44756775e+092 5.35663612e-256 1.91838796e-203]\n", |
| 1426 | + " [ 9.98796126e-001 9.37530046e-001 9.50447962e-001]\n", |
| 1427 | + " [ 9.98688504e-001 9.29997471e-001 9.44441670e-001]]\n", |
1416 | 1428 | "Node data with only valid results\n", |
1417 | 1429 | "[[0.99940117 0.99268579 0.99452137]\n", |
1418 | 1430 | " [0.99934769 0.98622639 0.98935286]\n", |
|
1455 | 1467 | ], |
1456 | 1468 | "metadata": { |
1457 | 1469 | "kernelspec": { |
1458 | | - "display_name": ".venv", |
| 1470 | + "display_name": "venv", |
1459 | 1471 | "language": "python", |
1460 | 1472 | "name": "python3" |
1461 | 1473 | }, |
|
1469 | 1481 | "name": "python", |
1470 | 1482 | "nbconvert_exporter": "python", |
1471 | 1483 | "pygments_lexer": "ipython3", |
1472 | | - "version": "3.13.0" |
| 1484 | + "version": "3.13.3" |
1473 | 1485 | } |
1474 | 1486 | }, |
1475 | 1487 | "nbformat": 4, |
|
0 commit comments