Skip to content

Commit

Permalink
Merge branch 'main' into feature/error-on-type-check
Browse files Browse the repository at this point in the history
  • Loading branch information
mgovers authored Nov 7, 2024
2 parents 05e4ab9 + 0f8ccb7 commit bc43654
Show file tree
Hide file tree
Showing 20 changed files with 652 additions and 290 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 24.8.0
rev: 24.10.0
hooks:
- id: black-jupyter
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
6 changes: 1 addition & 5 deletions docs/examples/Asymmetric Calculation Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@
"source": [
"# some basic imports\n",
"import numpy as np\n",
"import warnings\n",
"\n",
"with warnings.catch_warnings(action=\"ignore\", category=DeprecationWarning):\n",
" # suppress warning about pyarrow as future required dependency\n",
" import pandas as pd\n",
"import pandas as pd\n",
"\n",
"from power_grid_model import LoadGenType, ComponentType, DatasetType\n",
"from power_grid_model import PowerGridModel, CalculationMethod, CalculationType, MeasuredTerminalType\n",
Expand Down
6 changes: 1 addition & 5 deletions docs/examples/Make Test Dataset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,7 @@
"# first build the network\n",
"\n",
"import numpy as np\n",
"import warnings\n",
"\n",
"with warnings.catch_warnings(action=\"ignore\", category=DeprecationWarning):\n",
" # suppress warning about pyarrow as future required dependency\n",
" import pandas as pd\n",
"import pandas as pd\n",
"\n",
"from power_grid_model import LoadGenType, ComponentType, DatasetType\n",
"from power_grid_model import PowerGridModel\n",
Expand Down
127 changes: 91 additions & 36 deletions docs/examples/Power Flow Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@
"source": [
"# some basic imports\n",
"import numpy as np\n",
"import warnings\n",
"\n",
"with warnings.catch_warnings(action=\"ignore\", category=DeprecationWarning):\n",
" # suppress warning about pyarrow as future required dependency\n",
" import pandas as pd\n",
"import pandas as pd\n",
"\n",
"from power_grid_model import LoadGenType, ComponentType, DatasetType, ComponentAttributeFilterOptions\n",
"from power_grid_model import PowerGridModel, CalculationMethod, CalculationType\n",
Expand Down Expand Up @@ -640,15 +636,40 @@
},
{
"cell_type": "markdown",
"id": "fcc57354",
"id": "25a3f722",
"metadata": {},
"source": [
"Columnar data is also supported"
"If you are updating all components of the same type (uniformly) in the same order as in the input data, providing IDs is optional."
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "6a4d9802",
"metadata": {},
"outputs": [],
"source": [
"update_sym_load_no_id = initialize_array(DatasetType.update, ComponentType.sym_load, 2)\n",
"update_sym_load_no_id[\"p_specified\"] = [30e6, 15e6] # change active power for both sym_loads\n",
"# leave reactive power the same, no need to specify\n",
"\n",
"update_line_no_id = initialize_array(DatasetType.update, ComponentType.line, 3)\n",
"update_line_no_id[\"from_status\"] = [0, 1, 1] # switch off at from side for line #3\n",
"\n",
"update_data_no_id = {ComponentType.sym_load: update_sym_load_no_id, ComponentType.line: update_line_no_id}"
]
},
{
"cell_type": "markdown",
"id": "fcc57354",
"metadata": {},
"source": [
"Columnar data is also supported."
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "aaf8fe64",
"metadata": {},
"outputs": [],
Expand All @@ -660,7 +681,34 @@
"}\n",
"# leave to-side swiching status the same, no need to specify\n",
"\n",
"update_data = {ComponentType.sym_load: update_sym_load, ComponentType.line: columnar_update_line}"
"update_data_col = {ComponentType.sym_load: update_sym_load, ComponentType.line: columnar_update_line}"
]
},
{
"cell_type": "markdown",
"id": "f5179288",
"metadata": {},
"source": [
"Columnar data also supports optional IDs."
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "7eabed0c",
"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",
" ), # The update for the whole column needs to be specified\n",
"}\n",
"# leave to-side swiching status the same, no need to specify\n",
"\n",
"update_data_col_no_id = {ComponentType.sym_load: update_sym_load, ComponentType.line: columnar_no_ID_update_line}"
]
},
{
Expand All @@ -676,14 +724,21 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 18,
"id": "63ea4cc3",
"metadata": {},
"outputs": [],
"source": [
"from power_grid_model.validation import assert_valid_batch_data\n",
"\n",
"assert_valid_batch_data(input_data=input_data, update_data=update_data, calculation_type=CalculationType.power_flow)"
"assert_valid_batch_data(input_data=input_data, update_data=update_data, calculation_type=CalculationType.power_flow)\n",
"assert_valid_batch_data(\n",
" input_data=input_data, update_data=update_data_no_id, calculation_type=CalculationType.power_flow\n",
")\n",
"assert_valid_batch_data(input_data=input_data, update_data=update_data_col, calculation_type=CalculationType.power_flow)\n",
"assert_valid_batch_data(\n",
" input_data=input_data, update_data=update_data_col_no_id, calculation_type=CalculationType.power_flow\n",
")"
]
},
{
Expand All @@ -699,7 +754,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 19,
"id": "188f6663",
"metadata": {},
"outputs": [],
Expand All @@ -721,7 +776,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 20,
"id": "a93c1e16",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -810,7 +865,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 21,
"id": "42d5cd8f",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -844,7 +899,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 22,
"id": "4e25006f",
"metadata": {
"scrolled": true
Expand Down Expand Up @@ -887,7 +942,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 23,
"id": "afccf7a2",
"metadata": {
"scrolled": true
Expand Down Expand Up @@ -924,7 +979,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 24,
"id": "9af1be38",
"metadata": {
"scrolled": true
Expand Down Expand Up @@ -967,7 +1022,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 25,
"id": "041368dc",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -997,7 +1052,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 26,
"id": "34338ce3",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -1029,7 +1084,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 27,
"id": "04e56690",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -1061,7 +1116,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 28,
"id": "0d5b94c2",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -1144,7 +1199,7 @@
},
{
"cell_type": "code",
"execution_count": 27,
"execution_count": 29,
"id": "b5f10bae",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -1204,7 +1259,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 30,
"id": "1a221507",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -1246,7 +1301,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 31,
"id": "541af620",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -1294,7 +1349,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 32,
"id": "20d8285c",
"metadata": {},
"outputs": [],
Expand All @@ -1305,7 +1360,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": 33,
"id": "b702eb15",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -1340,7 +1395,7 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 34,
"id": "1ba71901",
"metadata": {},
"outputs": [
Expand All @@ -1349,16 +1404,16 @@
"output_type": "stream",
"text": [
"Node data with invalid results\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",
" [0.00000000e+000 3.04369633e+101 3.41345331e+241]\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",
" [1.66994188e-321 3.12878333e-312 9.75772002e+199]\n",
" [9.98796126e-001 9.37530046e-001 9.50447962e-001]\n",
" [9.98688504e-001 9.29997471e-001 9.44441670e-001]]\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",
"Node data with only valid results\n",
"[[0.99940117 0.99268579 0.99452137]\n",
" [0.99934769 0.98622639 0.98935286]\n",
Expand Down
6 changes: 1 addition & 5 deletions docs/examples/Serialization Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
"outputs": [],
"source": [
"import json\n",
"from pandas import DataFrame\n",
"import pprint\n",
"import warnings\n",
"\n",
"with warnings.catch_warnings(action=\"ignore\", category=DeprecationWarning):\n",
" # suppress warning about pyarrow as future required dependency\n",
" from pandas import DataFrame\n",
"\n",
"from power_grid_model import PowerGridModel, ComponentType, ComponentAttributeFilterOptions\n",
"from power_grid_model.utils import json_deserialize, json_serialize"
Expand Down
6 changes: 1 addition & 5 deletions docs/examples/Short Circuit Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@
"source": [
"# some basic imports\n",
"import numpy as np\n",
"import warnings\n",
"\n",
"with warnings.catch_warnings(action=\"ignore\", category=DeprecationWarning):\n",
" # suppress warning about pyarrow as future required dependency\n",
" import pandas as pd\n",
"import pandas as pd\n",
"\n",
"from power_grid_model import LoadGenType, ComponentType, DatasetType\n",
"from power_grid_model import (\n",
Expand Down
6 changes: 1 addition & 5 deletions docs/examples/State Estimation Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@
"source": [
"# some basic imports\n",
"import numpy as np\n",
"import warnings\n",
"\n",
"with warnings.catch_warnings(action=\"ignore\", category=DeprecationWarning):\n",
" # suppress warning about pyarrow as future required dependency\n",
" import pandas as pd\n",
"import pandas as pd\n",
"\n",
"from power_grid_model import LoadGenType, DatasetType, ComponentType\n",
"from power_grid_model import PowerGridModel, CalculationMethod, CalculationType, MeasuredTerminalType\n",
Expand Down
7 changes: 1 addition & 6 deletions docs/examples/Transformer Examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@
"source": [
"# some basic imports\n",
"import numpy as np\n",
"import warnings\n",
"\n",
"with warnings.catch_warnings():\n",
" warnings.simplefilter(\"ignore\", category=DeprecationWarning)\n",
" # suppress warning about pyarrow as future required dependency\n",
" import pandas as pd\n",
"import pandas as pd\n",
"\n",
"from power_grid_model import LoadGenType, DatasetType, ComponentType\n",
"from power_grid_model import (\n",
Expand Down
Loading

0 comments on commit bc43654

Please sign in to comment.