Skip to content

Commit

Permalink
Update the examples
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub Actions Bot <[email protected]>
  • Loading branch information
actions-user committed Nov 19, 2024
1 parent a207b46 commit 9333aa4
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions examples/Power Flow Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"\n",
"from power_grid_model import LoadGenType, ComponentType, DatasetType, ComponentAttributeFilterOptions\n",
"from power_grid_model import PowerGridModel, CalculationMethod, CalculationType\n",
"from power_grid_model import initialize_array, power_grid_meta_data"
"from power_grid_model import initialize_array, attribute_dtype"
]
},
{
Expand Down Expand Up @@ -127,7 +127,7 @@
"\n",
"A columnar data format better integrates with most databases. In addition, it may bring memory and, in some cases, even computational performance improvements, because unused attribute columns can be omitted.\n",
"\n",
"Make sure to provide the correct `dtype` to the numpy arrays, exposed for each dataset type, component and attribute via the `power_grid_meta_data` object."
"Make sure to provide the correct `dtype` to the numpy arrays, exposed for each dataset type, component and attribute via the helper function `attribute_dtype` function."
]
},
{
Expand All @@ -137,12 +137,11 @@
"metadata": {},
"outputs": [],
"source": [
"source_attribute_dtypes = power_grid_meta_data[DatasetType.input][ComponentType.source].dtype\n",
"source_columns = {\n",
" \"id\": np.array([10], dtype=source_attribute_dtypes[\"id\"]),\n",
" \"node\": np.array([1], dtype=source_attribute_dtypes[\"node\"]),\n",
" \"status\": np.array([1], dtype=source_attribute_dtypes[\"status\"]),\n",
" \"u_ref\": np.array([1.0], dtype=source_attribute_dtypes[\"u_ref\"]),\n",
" \"id\": np.array([10], dtype=attribute_dtype(DatasetType.input, ComponentType.source, \"id\")),\n",
" \"node\": np.array([1], dtype=attribute_dtype(DatasetType.input, ComponentType.source, \"node\")),\n",
" \"status\": np.array([1], dtype=attribute_dtype(DatasetType.input, ComponentType.source, \"status\")),\n",
" \"u_ref\": np.array([1.0], dtype=attribute_dtype(DatasetType.input, ComponentType.source, \"u_ref\")),\n",
" # We're not creating columns for u_ref_angle, sk, ... Instead, the default values are used. This saves us memory.\n",
"}\n",
"\n",
Expand Down Expand Up @@ -674,10 +673,11 @@
"metadata": {},
"outputs": [],
"source": [
"line_update_dtype = power_grid_meta_data[DatasetType.update][ComponentType.line].dtype\n",
"columnar_update_line = {\n",
" \"id\": np.array([3], dtype=line_update_dtype[\"id\"]), # change line ID 3\n",
" \"from_status\": np.array([0], dtype=line_update_dtype[\"from_status\"]), # switch off at from side\n",
" \"id\": np.array([3], dtype=attribute_dtype(DatasetType.update, ComponentType.line, \"id\")), # change line ID 3\n",
" \"from_status\": np.array(\n",
" [0], dtype=attribute_dtype(DatasetType.update, ComponentType.line, \"from_status\")\n",
" ), # switch off at from side\n",
"}\n",
"# leave to-side swiching status the same, no need to specify\n",
"\n",
Expand All @@ -699,11 +699,10 @@
"metadata": {},
"outputs": [],
"source": [
"line_update_dtype = power_grid_meta_data[DatasetType.update][ComponentType.line].dtype\n",
"columnar_no_ID_update_line = {\n",
" # Update IDs are not specified\n",
" \"from_status\": np.array(\n",
" [0, 1, 1], dtype=line_update_dtype[\"from_status\"]\n",
" [0, 1, 1], dtype=attribute_dtype(DatasetType.update, ComponentType.line, \"from_status\")\n",
" ), # The update for the whole column needs to be specified\n",
"}\n",
"# leave to-side swiching status the same, no need to specify\n",
Expand Down Expand Up @@ -1404,16 +1403,16 @@
"output_type": "stream",
"text": [
"Node data with invalid results\n",
"[[0.99940117 0.99268579 0.99452137]\n",
" [0.99934769 0.98622639 0.98935286]\n",
" [0.99928838 0.97965401 0.98409554]\n",
" [0. 0. 0. ]\n",
" [0.99915138 0.96614948 0.97329879]\n",
" [0.99907317 0.95920586 0.96775071]\n",
" [0.9989881 0.95212621 0.96209647]\n",
" [0. 0. 0. ]\n",
" [0.99879613 0.93753005 0.95044796]\n",
" [0.9986885 0.92999747 0.94444167]]\n",
"[[9.99401170e-001 9.92685785e-001 9.94521366e-001]\n",
" [9.99347687e-001 9.86226389e-001 9.89352855e-001]\n",
" [9.99288384e-001 9.79654011e-001 9.84095542e-001]\n",
" [3.94357132e+180 2.87518198e+161 2.04418455e+214]\n",
" [9.99151380e-001 9.66149483e-001 9.73298790e-001]\n",
" [9.99073166e-001 9.59205860e-001 9.67750710e-001]\n",
" [9.98988099e-001 9.52126208e-001 9.62096474e-001]\n",
" [0.00000000e+000 0.00000000e+000 0.00000000e+000]\n",
" [9.98796126e-001 9.37530046e-001 9.50447962e-001]\n",
" [9.98688504e-001 9.29997471e-001 9.44441670e-001]]\n",
"Node data with only valid results\n",
"[[0.99940117 0.99268579 0.99452137]\n",
" [0.99934769 0.98622639 0.98935286]\n",
Expand Down Expand Up @@ -1456,7 +1455,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand Down

0 comments on commit 9333aa4

Please sign in to comment.