Skip to content
Open
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
107 changes: 90 additions & 17 deletions docs/demos/connecting_new_consumer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -62,7 +62,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -86,7 +86,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -127,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -152,7 +152,7 @@
" x=new_consumer.x_coor[0],\n",
" y=new_consumer.y_coor[0],\n",
" )\n",
" closest_node = grid.node[closest_node_idx]\n",
" closest_node = grid.node.data[closest_node_idx]\n",
"\n",
" grid.append(new_consumer)\n",
" new_consumer_load.node = new_consumer.id\n",
Expand Down Expand Up @@ -188,9 +188,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "AttributeError",
"evalue": "'numpy.void' object has no attribute 'x_coor'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[5]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mconnect_new_consumer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgrid\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnew_consumer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnew_consumer_load\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 2\u001b[39m update_grid(grid)\n",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 28\u001b[39m, in \u001b[36mconnect_new_consumer\u001b[39m\u001b[34m(grid, new_consumer, new_consumer_load)\u001b[39m\n\u001b[32m 25\u001b[39m new_consumer_load.node = new_consumer.id\n\u001b[32m 26\u001b[39m grid.append(new_consumer_load)\n\u001b[32m---> \u001b[39m\u001b[32m28\u001b[39m dist = np.sqrt((\u001b[43mclosest_node\u001b[49m\u001b[43m.\u001b[49m\u001b[43mx_coor\u001b[49m - new_consumer.x_coor) ** \u001b[32m2\u001b[39m + (closest_node.y_coor - new_consumer.y_coor) ** \u001b[32m2\u001b[39m)\n\u001b[32m 30\u001b[39m new_line = ExtendedLineArray(\n\u001b[32m 31\u001b[39m from_node=[closest_node.id],\n\u001b[32m 32\u001b[39m to_node=[new_consumer.id],\n\u001b[32m (...)\u001b[39m\u001b[32m 39\u001b[39m i_n=[\u001b[32m200\u001b[39m],\n\u001b[32m 40\u001b[39m )\n\u001b[32m 41\u001b[39m grid.append(new_line)\n",
"\u001b[31mAttributeError\u001b[39m: 'numpy.void' object has no attribute 'x_coor'"
]
}
],
"source": [
"connect_new_consumer(grid, new_consumer, new_consumer_load)\n",
"update_grid(grid)"
Expand All @@ -209,27 +222,74 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" id | u_rated | node_type | feeder_branch_id | feeder_node_id | u | x_coor | y_coor \n",
" 1 | 10500.0 | 0 | 64 | 61 | 0.0 |190.591..|391.821..\n",
" 2 | 10500.0 | 0 | 64 | 61 | 0.0 |107.276..|479.614..\n",
" 3 | 10500.0 | 0 | 63 | 61 | 0.0 |236.780..|418.712..\n",
" 4 | 10500.0 | 0 | 78 | 61 | 0.0 |399.420..|447.300..\n",
" 5 | 10500.0 | 0 | 63 | 61 | 0.0 |146.187..|177.586..\n",
" (..12 hidden rows..) \n",
" 18 | 10500.0 | 0 | 63 | 61 | 0.0 |444.001..|139.411..\n",
" 19 | 10500.0 | 0 | 78 | 61 | 0.0 |370.190..|268.868..\n",
" 20 | 10500.0 | 0 | 64 | 61 | 0.0 |306.867..|334.454..\n",
" 61 | 10500.0 | 1 | -2147483648 | -2147483648 | 0.0 |336.963..|414.615..\n",
" 93 | 10500.0 | 0 | -2147483648 | -2147483648 | 0.0 | 300.0 | 300.0 \n"
]
}
],
"source": [
"print(grid.node)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" id | from_node | to_node | from_status | to_status | feeder_branch_id | feeder_node_id | is_feeder | r1 | x1 | c1 | tan1 | i_n | i_from \n",
" 63 | 61 | 17 | 1 | 1 | 63 | 61 | True |0.110..|0.013..| 0.0 | 0.0 |103.9613..| 0.0 \n",
" 64 | 61 | 13 | 1 | 1 | 64 | 61 | True |0.325..|0.015..| 0.0 | 0.0 |100.4538..| 0.0 \n",
" 65 | 17 | 5 | 1 | 1 | 63 | 61 | False |0.657..|2.575..| 0.0 | 0.0 |1311.550..| 0.0 \n",
" 66 | 13 | 11 | 1 | 1 | 64 | 61 | False |0.213..|0.016..| 0.0 | 0.0 |114.4995..| 0.0 \n",
" 67 | 5 | 18 | 1 | 1 | 63 | 61 | False |0.061..|0.029..| 0.0 | 0.0 |170.8020..| 0.0 \n",
" (..20 hidden rows..) \n",
" 88 | 19 | 15 | 1 | 0 | -2147483648 | -2147483648 | False |0.003..|0.003..| 0.0 | 0.0 |203.2692..| 0.0 \n",
" 89 | 1 | 18 | 1 | 0 | -2147483648 | -2147483648 | False |0.341..|0.012..| 0.0 | 0.0 |221.8579..| 0.0 \n",
" 90 | 18 | 2 | 1 | 0 | -2147483648 | -2147483648 | False |0.122..|0.006..| 0.0 | 0.0 |387.5294..| 0.0 \n",
" 91 | 61 | 17 | 1 | 0 | -2147483648 | -2147483648 | True |0.210..|0.001..| 0.0 | 0.0 |267.6662..| 0.0 \n",
" 92 | 3 | 11 | 1 | 0 | -2147483648 | -2147483648 | False |0.030..|0.050..| 0.0 | 0.0 |272.8941..| 0.0 \n"
]
}
],
"source": [
"print(grid.line)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overloaded nodes: [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 61 93]\n",
"Overloaded lines: []\n"
]
}
],
"source": [
"print(f\"Overloaded nodes: {grid.node[grid.node.is_overloaded].id}\")\n",
"print(f\"Overloaded lines: {grid.line[grid.line.is_overloaded].id}\")"
Expand All @@ -244,9 +304,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "AttributeError",
"evalue": "'numpy.void' object has no attribute 'x_coor'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[9]\u001b[39m\u001b[32m, line 5\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m _ \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[32m10\u001b[39m):\n\u001b[32m 2\u001b[39m new_consumer, new_consumer_load = create_new_consumer_arrays(\n\u001b[32m 3\u001b[39m \u001b[32m10_500\u001b[39m, np.random.uniform(\u001b[32m0\u001b[39m, \u001b[32m500\u001b[39m), np.random.uniform(\u001b[32m0\u001b[39m, \u001b[32m500\u001b[39m), \u001b[32m1_000_000\u001b[39m, \u001b[32m200_000\u001b[39m\n\u001b[32m 4\u001b[39m )\n\u001b[32m----> \u001b[39m\u001b[32m5\u001b[39m \u001b[43mconnect_new_consumer\u001b[49m\u001b[43m(\u001b[49m\u001b[43mgrid\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnew_consumer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnew_consumer_load\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 6\u001b[39m update_grid(grid)\n\u001b[32m 8\u001b[39m \u001b[38;5;28mprint\u001b[39m(\u001b[33mf\u001b[39m\u001b[33m\"\u001b[39m\u001b[33mOverloaded nodes: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mgrid.node[grid.node.is_overloaded].id\u001b[38;5;132;01m}\u001b[39;00m\u001b[33m\"\u001b[39m)\n",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[4]\u001b[39m\u001b[32m, line 28\u001b[39m, in \u001b[36mconnect_new_consumer\u001b[39m\u001b[34m(grid, new_consumer, new_consumer_load)\u001b[39m\n\u001b[32m 25\u001b[39m new_consumer_load.node = new_consumer.id\n\u001b[32m 26\u001b[39m grid.append(new_consumer_load)\n\u001b[32m---> \u001b[39m\u001b[32m28\u001b[39m dist = np.sqrt((\u001b[43mclosest_node\u001b[49m\u001b[43m.\u001b[49m\u001b[43mx_coor\u001b[49m - new_consumer.x_coor) ** \u001b[32m2\u001b[39m + (closest_node.y_coor - new_consumer.y_coor) ** \u001b[32m2\u001b[39m)\n\u001b[32m 30\u001b[39m new_line = ExtendedLineArray(\n\u001b[32m 31\u001b[39m from_node=[closest_node.id],\n\u001b[32m 32\u001b[39m to_node=[new_consumer.id],\n\u001b[32m (...)\u001b[39m\u001b[32m 39\u001b[39m i_n=[\u001b[32m200\u001b[39m],\n\u001b[32m 40\u001b[39m )\n\u001b[32m 41\u001b[39m grid.append(new_line)\n",
"\u001b[31mAttributeError\u001b[39m: 'numpy.void' object has no attribute 'x_coor'"
]
}
],
"source": [
"for _ in range(10):\n",
" new_consumer, new_consumer_load = create_new_consumer_arrays(\n",
Expand All @@ -262,7 +335,7 @@
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"display_name": "power-grid-model-ds",
"language": "python",
"name": "python3"
},
Expand All @@ -276,7 +349,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
"version": "3.14.2"
}
},
"nbformat": 4,
Expand Down
Loading