Skip to content

Commit 6678b59

Browse files
committed
add docs example
Signed-off-by: Nitish Bharambe <nitish.bharambe@alliander.com>
1 parent f1844f3 commit 6678b59

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

docs/api_reference/python-api-reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ This is the Python API reference for the `power-grid-model` library
1414
.. autoclass:: PowerGridModel
1515
:show-inheritance:
1616
.. autofunction:: initialize_array
17+
.. autofunction:: attribute_dtype
18+
.. autofunction:: attribute_empty_value
1719
1820
.. py:data:: power_grid_meta_data
1921
:type: typing.PowerGridMetaData

docs/examples/Power Flow Example.ipynb

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"\n",
5050
"from power_grid_model import LoadGenType, ComponentType, DatasetType, ComponentAttributeFilterOptions\n",
5151
"from power_grid_model import PowerGridModel, CalculationMethod, CalculationType\n",
52-
"from power_grid_model import initialize_array, power_grid_meta_data"
52+
"from power_grid_model import initialize_array, attribute_dtype"
5353
]
5454
},
5555
{
@@ -127,7 +127,7 @@
127127
"\n",
128128
"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",
129129
"\n",
130-
"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."
130+
"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."
131131
]
132132
},
133133
{
@@ -137,12 +137,11 @@
137137
"metadata": {},
138138
"outputs": [],
139139
"source": [
140-
"source_attribute_dtypes = power_grid_meta_data[DatasetType.input][ComponentType.source].dtype\n",
141140
"source_columns = {\n",
142-
" \"id\": np.array([10], dtype=source_attribute_dtypes[\"id\"]),\n",
143-
" \"node\": np.array([1], dtype=source_attribute_dtypes[\"node\"]),\n",
144-
" \"status\": np.array([1], dtype=source_attribute_dtypes[\"status\"]),\n",
145-
" \"u_ref\": np.array([1.0], dtype=source_attribute_dtypes[\"u_ref\"]),\n",
141+
" \"id\": np.array([10], dtype=attribute_dtype(DatasetType.input, ComponentType.source, \"id\")),\n",
142+
" \"node\": np.array([1], dtype=attribute_dtype(DatasetType.input, ComponentType.source, \"node\")),\n",
143+
" \"status\": np.array([1], dtype=attribute_dtype(DatasetType.input, ComponentType.source, \"status\")),\n",
144+
" \"u_ref\": np.array([1.0], dtype=attribute_dtype(DatasetType.input, ComponentType.source, \"u_ref\")),\n",
146145
" # We're not creating columns for u_ref_angle, sk, ... Instead, the default values are used. This saves us memory.\n",
147146
"}\n",
148147
"\n",
@@ -403,7 +402,7 @@
403402
"List of attribute types in line result\n",
404403
"['id', 'p_from']\n",
405404
"------line result------\n",
406-
"{'id': array([3, 5, 8], dtype=int32), 'p_from': array([17360100.20222374, -3365613.74450156, 13854413.52498137])}\n"
405+
"{'id': array([3, 5, 8]), 'p_from': array([17360100.20222374, -3365613.74450156, 13854413.52498137])}\n"
407406
]
408407
}
409408
],
@@ -674,10 +673,11 @@
674673
"metadata": {},
675674
"outputs": [],
676675
"source": [
677-
"line_update_dtype = power_grid_meta_data[DatasetType.update][ComponentType.line].dtype\n",
678676
"columnar_update_line = {\n",
679-
" \"id\": np.array([3], dtype=line_update_dtype[\"id\"]), # change line ID 3\n",
680-
" \"from_status\": np.array([0], dtype=line_update_dtype[\"from_status\"]), # switch off at from side\n",
677+
" \"id\": np.array([3], dtype=attribute_dtype(DatasetType.update, ComponentType.line, \"id\")), # change line ID 3\n",
678+
" \"from_status\": np.array(\n",
679+
" [0], dtype=attribute_dtype(DatasetType.update, ComponentType.line, \"from_status\")\n",
680+
" ), # switch off at from side\n",
681681
"}\n",
682682
"# leave to-side swiching status the same, no need to specify\n",
683683
"\n",
@@ -699,11 +699,10 @@
699699
"metadata": {},
700700
"outputs": [],
701701
"source": [
702-
"line_update_dtype = power_grid_meta_data[DatasetType.update][ComponentType.line].dtype\n",
703702
"columnar_no_ID_update_line = {\n",
704703
" # Update IDs are not specified\n",
705704
" \"from_status\": np.array(\n",
706-
" [0, 1, 1], dtype=line_update_dtype[\"from_status\"]\n",
705+
" [0, 1, 1], dtype=attribute_dtype(DatasetType.update, ComponentType.line, \"from_status\")\n",
707706
" ), # The update for the whole column needs to be specified\n",
708707
"}\n",
709708
"# leave to-side swiching status the same, no need to specify\n",
@@ -1404,16 +1403,16 @@
14041403
"output_type": "stream",
14051404
"text": [
14061405
"Node data with invalid results\n",
1407-
"[[0.99940117 0.99268579 0.99452137]\n",
1408-
" [0.99934769 0.98622639 0.98935286]\n",
1409-
" [0.99928838 0.97965401 0.98409554]\n",
1410-
" [0. 0. 0. ]\n",
1411-
" [0.99915138 0.96614948 0.97329879]\n",
1412-
" [0.99907317 0.95920586 0.96775071]\n",
1413-
" [0.9989881 0.95212621 0.96209647]\n",
1414-
" [0. 0. 0. ]\n",
1415-
" [0.99879613 0.93753005 0.95044796]\n",
1416-
" [0.9986885 0.92999747 0.94444167]]\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+
" [6.95296562e-310 8.59448882e-312 6.95296562e-310]\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+
" [8.59448882e-312 8.59448882e-312 6.95296562e-310]\n",
1414+
" [9.98796126e-001 9.37530046e-001 9.50447962e-001]\n",
1415+
" [9.98688504e-001 9.29997471e-001 9.44441670e-001]]\n",
14171416
"Node data with only valid results\n",
14181417
"[[0.99940117 0.99268579 0.99452137]\n",
14191418
" [0.99934769 0.98622639 0.98935286]\n",
@@ -1456,7 +1455,7 @@
14561455
],
14571456
"metadata": {
14581457
"kernelspec": {
1459-
"display_name": "venv",
1458+
"display_name": ".venv",
14601459
"language": "python",
14611460
"name": "python3"
14621461
},
@@ -1470,7 +1469,7 @@
14701469
"name": "python",
14711470
"nbconvert_exporter": "python",
14721471
"pygments_lexer": "ipython3",
1473-
"version": "3.13.0"
1472+
"version": "3.12.7"
14741473
}
14751474
},
14761475
"nbformat": 4,

0 commit comments

Comments
 (0)