|
1146 | 1146 | "print(output_data[ComponentType.line][\"i_from\"])" |
1147 | 1147 | ] |
1148 | 1148 | }, |
| 1149 | + { |
| 1150 | + "cell_type": "markdown", |
| 1151 | + "id": "344efbe8", |
| 1152 | + "metadata": {}, |
| 1153 | + "source": [ |
| 1154 | + "#### Cartesian product of batch datasets\n", |
| 1155 | + "\n", |
| 1156 | + "It is possible to conduct a batch calculation of multiple datasets in form of a cartesian product of their scenarios.\n", |
| 1157 | + "Assume certain batch datasets with N1, N2, N3, ... scenarios. \n", |
| 1158 | + "This would give us $N1 * N2 * N3 * ...$ possible combinations via the cartesian product.\n", |
| 1159 | + "The resultant output data is in flat form and it has dimension of N1 * N2 * N3 with first dataset being the highest\n", |
| 1160 | + "dimension. \n", |
| 1161 | + "This can be beneficial in reducing complexity of implementation of such batch calculation \n", |
| 1162 | + "along with keeping the size of such resultant update_data to a minimum.\n", |
| 1163 | + "\n", |
| 1164 | + "```note\n", |
| 1165 | + "The data validation module mentioned in #validation-(optional) does not support cartesian product of datasets. \n", |
| 1166 | + "It is advised to combine the datasets them manually via numpy to use the validator.\n", |
| 1167 | + "```" |
| 1168 | + ] |
| 1169 | + }, |
| 1170 | + { |
| 1171 | + "cell_type": "markdown", |
| 1172 | + "id": "5de1a2f7", |
| 1173 | + "metadata": {}, |
| 1174 | + "source": [ |
| 1175 | + "We can combine the time series mutation for all n-1 contingencies together in following way.\n", |
| 1176 | + "Both the batch datasets are passed together in `update_data` in a list." |
| 1177 | + ] |
| 1178 | + }, |
| 1179 | + { |
| 1180 | + "cell_type": "code", |
| 1181 | + "execution_count": 29, |
| 1182 | + "id": "d690eeb7", |
| 1183 | + "metadata": {}, |
| 1184 | + "outputs": [ |
| 1185 | + { |
| 1186 | + "name": "stdout", |
| 1187 | + "output_type": "stream", |
| 1188 | + "text": [ |
| 1189 | + "Output data has shape (30, 3)\n", |
| 1190 | + "[0 1 1]\n", |
| 1191 | + "[0 1 1]\n", |
| 1192 | + "[1 0 1]\n", |
| 1193 | + "[1 0 1]\n" |
| 1194 | + ] |
| 1195 | + } |
| 1196 | + ], |
| 1197 | + "source": [ |
| 1198 | + "output_data = model.calculate_power_flow(update_data=[n_min_1_mutation_update_specific, time_series_mutation])\n", |
| 1199 | + "print(\"Output data has shape\", output_data[ComponentType.line].shape)\n", |
| 1200 | + "line_output = output_data[ComponentType.line][\"energized\"]\n", |
| 1201 | + "print(line_output[0, :])\n", |
| 1202 | + "print(line_output[1, :])\n", |
| 1203 | + "print(line_output[10, :])\n", |
| 1204 | + "print(line_output[11, :])" |
| 1205 | + ] |
| 1206 | + }, |
1149 | 1207 | { |
1150 | 1208 | "attachments": {}, |
1151 | 1209 | "cell_type": "markdown", |
|
1210 | 1268 | }, |
1211 | 1269 | { |
1212 | 1270 | "cell_type": "code", |
1213 | | - "execution_count": 29, |
| 1271 | + "execution_count": 30, |
1214 | 1272 | "id": "b5f10bae", |
1215 | 1273 | "metadata": {}, |
1216 | 1274 | "outputs": [ |
|
1270 | 1328 | }, |
1271 | 1329 | { |
1272 | 1330 | "cell_type": "code", |
1273 | | - "execution_count": 30, |
| 1331 | + "execution_count": 31, |
1274 | 1332 | "id": "1a221507", |
1275 | 1333 | "metadata": {}, |
1276 | 1334 | "outputs": [ |
|
1312 | 1370 | }, |
1313 | 1371 | { |
1314 | 1372 | "cell_type": "code", |
1315 | | - "execution_count": 31, |
| 1373 | + "execution_count": 32, |
1316 | 1374 | "id": "541af620", |
1317 | 1375 | "metadata": {}, |
1318 | 1376 | "outputs": [ |
1319 | 1377 | { |
1320 | 1378 | "name": "stdout", |
1321 | 1379 | "output_type": "stream", |
1322 | 1380 | "text": [ |
1323 | | - "Iteration failed to converge after 20 iterations! Max deviation: 3.54512e-16, error tolerance: 1e-20.\n", |
| 1381 | + "Iteration failed to converge after 20 iterations! Max deviation: 3.54512293063893e-16, error tolerance: 1e-20.\n", |
1324 | 1382 | "\n", |
1325 | 1383 | "Try validate_input_data() or validate_batch_data() to validate your data.\n", |
1326 | 1384 | "\n" |
|
1360 | 1418 | }, |
1361 | 1419 | { |
1362 | 1420 | "cell_type": "code", |
1363 | | - "execution_count": 32, |
| 1421 | + "execution_count": 33, |
1364 | 1422 | "id": "20d8285c", |
1365 | 1423 | "metadata": {}, |
1366 | 1424 | "outputs": [], |
|
1371 | 1429 | }, |
1372 | 1430 | { |
1373 | 1431 | "cell_type": "code", |
1374 | | - "execution_count": 33, |
| 1432 | + "execution_count": 34, |
1375 | 1433 | "id": "b702eb15", |
1376 | 1434 | "metadata": {}, |
1377 | 1435 | "outputs": [ |
|
1384 | 1442 | "\n", |
1385 | 1443 | "Failed scenarios: [3 7]\n", |
1386 | 1444 | "Succeeded scenarios: [0 1 2 4 5 6 8 9]\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" |
| 1445 | + "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.\\nSee https://github.com/PowerGridModel/power-grid-model/issues/864.']\n" |
1388 | 1446 | ] |
1389 | 1447 | } |
1390 | 1448 | ], |
|
1406 | 1464 | }, |
1407 | 1465 | { |
1408 | 1466 | "cell_type": "code", |
1409 | | - "execution_count": 34, |
| 1467 | + "execution_count": 35, |
1410 | 1468 | "id": "1ba71901", |
1411 | 1469 | "metadata": {}, |
1412 | 1470 | "outputs": [ |
|
1415 | 1473 | "output_type": "stream", |
1416 | 1474 | "text": [ |
1417 | 1475 | "Node data with invalid results\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", |
| 1476 | + "[[9.99401170e-001 9.92685785e-001 9.94521366e-001]\n", |
| 1477 | + " [9.99347687e-001 9.86226389e-001 9.89352855e-001]\n", |
| 1478 | + " [9.99288384e-001 9.79654011e-001 9.84095542e-001]\n", |
| 1479 | + " [2.18565566e-312 4.89761332e-310 2.97079411e-313]\n", |
| 1480 | + " [9.99151380e-001 9.66149483e-001 9.73298790e-001]\n", |
| 1481 | + " [9.99073166e-001 9.59205860e-001 9.67750710e-001]\n", |
| 1482 | + " [9.98988099e-001 9.52126208e-001 9.62096474e-001]\n", |
| 1483 | + " [4.89761332e-310 4.89761332e-310 4.89761332e-310]\n", |
| 1484 | + " [9.98796126e-001 9.37530046e-001 9.50447962e-001]\n", |
| 1485 | + " [9.98688504e-001 9.29997471e-001 9.44441670e-001]]\n", |
1428 | 1486 | "Node data with only valid results\n", |
1429 | 1487 | "[[0.99940117 0.99268579 0.99452137]\n", |
1430 | 1488 | " [0.99934769 0.98622639 0.98935286]\n", |
|
1467 | 1525 | ], |
1468 | 1526 | "metadata": { |
1469 | 1527 | "kernelspec": { |
1470 | | - "display_name": "venv", |
| 1528 | + "display_name": "power-grid-model", |
1471 | 1529 | "language": "python", |
1472 | 1530 | "name": "python3" |
1473 | 1531 | }, |
|
1481 | 1539 | "name": "python", |
1482 | 1540 | "nbconvert_exporter": "python", |
1483 | 1541 | "pygments_lexer": "ipython3", |
1484 | | - "version": "3.13.3" |
| 1542 | + "version": "3.14.2" |
1485 | 1543 | } |
1486 | 1544 | }, |
1487 | 1545 | "nbformat": 4, |
|
0 commit comments