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 Oct 27, 2023
1 parent 2cce152 commit cda3e61
Showing 1 changed file with 21 additions and 36 deletions.
57 changes: 21 additions & 36 deletions examples/Validation Examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,16 @@
"metadata": {},
"outputs": [
{
"ename": "RuntimeError",
"evalue": "Wrong type for object with id 4\n",
"ename": "PowerGridError",
"evalue": "Wrong type for object with id 4\n\nTry validate_input_data() or validate_batch_data() to validate your data.\n",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[2], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Without validation\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m model \u001b[38;5;241m=\u001b[39m \u001b[43mPowerGridModel\u001b[49m\u001b[43m(\u001b[49m\u001b[43merror_data\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 3\u001b[0m output_data \u001b[38;5;241m=\u001b[39m model\u001b[38;5;241m.\u001b[39mcalculate_state_estimation(symmetric\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
"File \u001b[0;32msrc/power_grid_model/_power_grid_core.pyx:312\u001b[0m, in \u001b[0;36mpower_grid_model._power_grid_core.PowerGridModel.__init__\u001b[0;34m()\u001b[0m\n",
"\u001b[0;31mRuntimeError\u001b[0m: Wrong type for object with id 4\n"
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mPowerGridError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mc:\\headers\\power-grid-model\\docs\\examples\\Validation Examples.ipynb Cell 4\u001b[0m line \u001b[0;36m2\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/headers/power-grid-model/docs/examples/Validation%20Examples.ipynb#W3sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39m# Without validation\u001b[39;00m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/headers/power-grid-model/docs/examples/Validation%20Examples.ipynb#W3sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m model \u001b[39m=\u001b[39m PowerGridModel(error_data)\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/headers/power-grid-model/docs/examples/Validation%20Examples.ipynb#W3sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m output_data \u001b[39m=\u001b[39m model\u001b[39m.\u001b[39mcalculate_state_estimation(symmetric\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n",
"File \u001b[1;32mC:\\headers\\power-grid-model\\src\\power_grid_model\\core\\power_grid_model.py:110\u001b[0m, in \u001b[0;36mPowerGridModel.__init__\u001b[1;34m(self, input_data, system_frequency)\u001b[0m\n\u001b[0;32m 108\u001b[0m prepared_input \u001b[39m=\u001b[39m prepare_input_view(input_data)\n\u001b[0;32m 109\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_model_ptr \u001b[39m=\u001b[39m pgc\u001b[39m.\u001b[39mcreate_model(system_frequency, input_data\u001b[39m=\u001b[39mprepared_input\u001b[39m.\u001b[39mget_dataset_ptr())\n\u001b[1;32m--> 110\u001b[0m assert_no_error()\n\u001b[0;32m 111\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_all_component_count \u001b[39m=\u001b[39m {k: v \u001b[39mfor\u001b[39;00m k, v \u001b[39min\u001b[39;00m prepared_input\u001b[39m.\u001b[39mget_info()\u001b[39m.\u001b[39mtotal_elements()\u001b[39m.\u001b[39mitems() \u001b[39mif\u001b[39;00m v \u001b[39m>\u001b[39m \u001b[39m0\u001b[39m}\n",
"File \u001b[1;32mC:\\headers\\power-grid-model\\src\\power_grid_model\\core\\error_handling.py:71\u001b[0m, in \u001b[0;36massert_no_error\u001b[1;34m(batch_size)\u001b[0m\n\u001b[0;32m 69\u001b[0m error \u001b[39m=\u001b[39m find_error(batch_size\u001b[39m=\u001b[39mbatch_size)\n\u001b[0;32m 70\u001b[0m \u001b[39mif\u001b[39;00m error \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m---> 71\u001b[0m \u001b[39mraise\u001b[39;00m error\n",
"\u001b[1;31mPowerGridError\u001b[0m: Wrong type for object with id 4\n\nTry validate_input_data() or validate_batch_data() to validate your data.\n"
]
}
],
Expand All @@ -128,14 +129,14 @@
"outputs": [
{
"ename": "ValidationException",
"evalue": "There are 7 validation errors in input_data:\n 1. Field 'i_n' is missing for 3 lines.\n 2. Fields line.id and sym_power_sensor.id are not unique for 2 lines/sym_power_sensors.\n 3. Field 'to_node' does not contain a valid node id for 1 line.\n 4. Field 'power_sigma' is not greater than zero for 2 sym_power_sensors.\n 5. Field 'measured_object' does not contain a valid line/transformer/source/shunt/sym_load/asym_load/sym_gen/asym_gen id for 1 sym_power_sensor.\n 6. Field 'measured_object' does not contain a valid line/transformer id for 1 sym_power_sensor. (measured_terminal_type=branch_from)\n 7. Field 'measured_object' does not contain a valid source id for 1 sym_power_sensor. (measured_terminal_type=source)",
"evalue": "There are 5 validation errors in input_data:\n 1. Fields line.id and sym_power_sensor.id are not unique for 2 lines/sym_power_sensors.\n 2. Field 'to_node' does not contain a valid node id for 1 line.\n 3. Field 'power_sigma' is not greater than zero for 2 sym_power_sensors.\n 4. Field 'measured_object' does not contain a valid line/transformer id for 1 sym_power_sensor. (measured_terminal_type=branch_from)\n 5. Field 'measured_object' does not contain a valid source id for 1 sym_power_sensor. (measured_terminal_type=source)",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValidationException\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[3], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpower_grid_model\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mvalidation\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m assert_valid_input_data\n\u001b[1;32m 3\u001b[0m \u001b[38;5;66;03m# Assert valid data\u001b[39;00m\n\u001b[0;32m----> 4\u001b[0m \u001b[43massert_valid_input_data\u001b[49m\u001b[43m(\u001b[49m\u001b[43merror_data\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msymmetric\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 5\u001b[0m model \u001b[38;5;241m=\u001b[39m PowerGridModel(error_data)\n\u001b[1;32m 6\u001b[0m output_data \u001b[38;5;241m=\u001b[39m model\u001b[38;5;241m.\u001b[39mcalculate_state_estimation(symmetric\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
"File \u001b[0;32m~/repos/power-grid-model-workshop/.venv/lib/python3.11/site-packages/power_grid_model/validation/assertions.py:57\u001b[0m, in \u001b[0;36massert_valid_input_data\u001b[0;34m(input_data, calculation_type, symmetric)\u001b[0m\n\u001b[1;32m 53\u001b[0m validation_errors \u001b[38;5;241m=\u001b[39m validate_input_data(\n\u001b[1;32m 54\u001b[0m input_data\u001b[38;5;241m=\u001b[39minput_data, calculation_type\u001b[38;5;241m=\u001b[39mcalculation_type, symmetric\u001b[38;5;241m=\u001b[39msymmetric\n\u001b[1;32m 55\u001b[0m )\n\u001b[1;32m 56\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m validation_errors:\n\u001b[0;32m---> 57\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ValidationException(validation_errors, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124minput_data\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
"\u001b[0;31mValidationException\u001b[0m: There are 7 validation errors in input_data:\n 1. Field 'i_n' is missing for 3 lines.\n 2. Fields line.id and sym_power_sensor.id are not unique for 2 lines/sym_power_sensors.\n 3. Field 'to_node' does not contain a valid node id for 1 line.\n 4. Field 'power_sigma' is not greater than zero for 2 sym_power_sensors.\n 5. Field 'measured_object' does not contain a valid line/transformer/source/shunt/sym_load/asym_load/sym_gen/asym_gen id for 1 sym_power_sensor.\n 6. Field 'measured_object' does not contain a valid line/transformer id for 1 sym_power_sensor. (measured_terminal_type=branch_from)\n 7. Field 'measured_object' does not contain a valid source id for 1 sym_power_sensor. (measured_terminal_type=source)"
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mValidationException\u001b[0m Traceback (most recent call last)",
"\u001b[1;32mc:\\headers\\power-grid-model\\docs\\examples\\Validation Examples.ipynb Cell 5\u001b[0m line \u001b[0;36m4\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/headers/power-grid-model/docs/examples/Validation%20Examples.ipynb#W4sZmlsZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mpower_grid_model\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mvalidation\u001b[39;00m \u001b[39mimport\u001b[39;00m assert_valid_input_data\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/headers/power-grid-model/docs/examples/Validation%20Examples.ipynb#W4sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m \u001b[39m# Assert valid data\u001b[39;00m\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/headers/power-grid-model/docs/examples/Validation%20Examples.ipynb#W4sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m assert_valid_input_data(error_data, symmetric\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m)\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/headers/power-grid-model/docs/examples/Validation%20Examples.ipynb#W4sZmlsZQ%3D%3D?line=4'>5</a>\u001b[0m model \u001b[39m=\u001b[39m PowerGridModel(error_data)\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/headers/power-grid-model/docs/examples/Validation%20Examples.ipynb#W4sZmlsZQ%3D%3D?line=5'>6</a>\u001b[0m output_data \u001b[39m=\u001b[39m model\u001b[39m.\u001b[39mcalculate_state_estimation(symmetric\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n",
"File \u001b[1;32mC:\\headers\\power-grid-model\\src\\power_grid_model\\validation\\assertions.py:57\u001b[0m, in \u001b[0;36massert_valid_input_data\u001b[1;34m(input_data, calculation_type, symmetric)\u001b[0m\n\u001b[0;32m 53\u001b[0m validation_errors \u001b[39m=\u001b[39m validate_input_data(\n\u001b[0;32m 54\u001b[0m input_data\u001b[39m=\u001b[39minput_data, calculation_type\u001b[39m=\u001b[39mcalculation_type, symmetric\u001b[39m=\u001b[39msymmetric\n\u001b[0;32m 55\u001b[0m )\n\u001b[0;32m 56\u001b[0m \u001b[39mif\u001b[39;00m validation_errors:\n\u001b[1;32m---> 57\u001b[0m \u001b[39mraise\u001b[39;00m ValidationException(validation_errors, \u001b[39m\"\u001b[39m\u001b[39minput_data\u001b[39m\u001b[39m\"\u001b[39m)\n",
"\u001b[1;31mValidationException\u001b[0m: There are 5 validation errors in input_data:\n 1. Fields line.id and sym_power_sensor.id are not unique for 2 lines/sym_power_sensors.\n 2. Field 'to_node' does not contain a valid node id for 1 line.\n 3. Field 'power_sigma' is not greater than zero for 2 sym_power_sensors.\n 4. Field 'measured_object' does not contain a valid line/transformer id for 1 sym_power_sensor. (measured_terminal_type=branch_from)\n 5. Field 'measured_object' does not contain a valid source id for 1 sym_power_sensor. (measured_terminal_type=source)"
]
}
],
Expand All @@ -158,12 +159,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"MissingValueError line : [4, 5, 6]\n",
"MultiComponentNotUniqueError ['line', 'sym_power_sensor'] : [('line', 6), ('sym_power_sensor', 6)]\n",
"InvalidIdError line : [6]\n",
"NotGreaterThanError sym_power_sensor : [6, 7]\n",
"InvalidIdError sym_power_sensor : [6]\n",
"InvalidIdError sym_power_sensor : [6]\n",
"InvalidIdError sym_power_sensor : [7]\n"
]
}
Expand Down Expand Up @@ -191,14 +190,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
"There are 7 validation errors in the data:\n",
" 1. Field 'i_n' is missing for 3 lines.\n",
" 2. Fields line.id and sym_power_sensor.id are not unique for 2 lines/sym_power_sensors.\n",
" 3. Field 'to_node' does not contain a valid node id for 1 line.\n",
" 4. Field 'power_sigma' is not greater than zero for 2 sym_power_sensors.\n",
" 5. Field 'measured_object' does not contain a valid line/transformer/source/shunt/sym_load/asym_load/sym_gen/asym_gen id for 1 sym_power_sensor.\n",
" 6. Field 'measured_object' does not contain a valid line/transformer id for 1 sym_power_sensor. (measured_terminal_type=branch_from)\n",
" 7. Field 'measured_object' does not contain a valid source id for 1 sym_power_sensor. (measured_terminal_type=source)\n"
"There are 5 validation errors in the data:\n",
" 1. Fields line.id and sym_power_sensor.id are not unique for 2 lines/sym_power_sensors.\n",
" 2. Field 'to_node' does not contain a valid node id for 1 line.\n",
" 3. Field 'power_sigma' is not greater than zero for 2 sym_power_sensors.\n",
" 4. Field 'measured_object' does not contain a valid line/transformer id for 1 sym_power_sensor. (measured_terminal_type=branch_from)\n",
" 5. Field 'measured_object' does not contain a valid source id for 1 sym_power_sensor. (measured_terminal_type=source)\n"
]
}
],
Expand All @@ -224,12 +221,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"There are 7 validation errors in the data:\n",
"\n",
"\tField 'i_n' is missing for 3 lines.\n",
"\t\tcomponent: line\n",
"\t\tfield: 'i_n'\n",
"\t\tids: [4, 5, 6]\n",
"There are 5 validation errors in the data:\n",
"\n",
"\tFields line.id and sym_power_sensor.id are not unique for 2 lines/sym_power_sensors.\n",
"\t\tcomponent: line/sym_power_sensor\n",
Expand All @@ -249,13 +241,6 @@
"\t\tids: [6, 7]\n",
"\t\tref_value: zero\n",
"\n",
"\tField 'measured_object' does not contain a valid line/transformer/source/shunt/sym_load/asym_load/sym_gen/asym_gen id for 1 sym_power_sensor.\n",
"\t\tcomponent: sym_power_sensor\n",
"\t\tfield: 'measured_object'\n",
"\t\tids: [6]\n",
"\t\tref_components: line/transformer/source/shunt/sym_load/asym_load/sym_gen/asym_gen\n",
"\t\tfilters: \n",
"\n",
"\tField 'measured_object' does not contain a valid line/transformer id for 1 sym_power_sensor. (measured_terminal_type=branch_from)\n",
"\t\tcomponent: sym_power_sensor\n",
"\t\tfield: 'measured_object'\n",
Expand Down

0 comments on commit cda3e61

Please sign in to comment.