|
118 | 118 | " ComponentType.node: node,\n", |
119 | 119 | " ComponentType.line: line,\n", |
120 | 120 | " ComponentType.sym_load: sym_load,\n", |
121 | | - " ComponentType.source: source\n", |
| 121 | + " ComponentType.source: source,\n", |
122 | 122 | "}" |
123 | 123 | ] |
124 | 124 | }, |
|
180 | 180 | "outputs": [], |
181 | 181 | "source": [ |
182 | 182 | "from power_grid_model.validation import assert_valid_input_data\n", |
| 183 | + "\n", |
183 | 184 | "assert_valid_input_data(input_data=input_data, calculation_type=CalculationType.power_flow)" |
184 | 185 | ] |
185 | 186 | }, |
|
249 | 250 | "outputs": [], |
250 | 251 | "source": [ |
251 | 252 | "output_data = model.calculate_power_flow(\n", |
252 | | - " symmetric=True,\n", |
253 | | - " error_tolerance=1e-8,\n", |
254 | | - " max_iterations=20,\n", |
255 | | - " calculation_method=CalculationMethod.newton_raphson)" |
| 253 | + " symmetric=True, error_tolerance=1e-8, max_iterations=20, calculation_method=CalculationMethod.newton_raphson\n", |
| 254 | + ")" |
256 | 255 | ] |
257 | 256 | }, |
258 | 257 | { |
|
340 | 339 | " error_tolerance=1e-8,\n", |
341 | 340 | " max_iterations=20,\n", |
342 | 341 | " calculation_method=CalculationMethod.newton_raphson,\n", |
343 | | - " output_component_types=[ComponentType.node])\n", |
| 342 | + " output_component_types=[ComponentType.node],\n", |
| 343 | + ")\n", |
344 | 344 | "\n", |
345 | 345 | "print(\"List of component types in result dataset\")\n", |
346 | 346 | "print(list(output_data.keys()))\n", |
|
450 | 450 | "update_line[\"from_status\"] = [0] # switch off at from side\n", |
451 | 451 | "# leave to-side swiching status the same, no need to specify\n", |
452 | 452 | "\n", |
453 | | - "update_data = {\n", |
454 | | - " ComponentType.sym_load: update_sym_load,\n", |
455 | | - " ComponentType.line: update_line\n", |
456 | | - "}" |
| 453 | + "update_data = {ComponentType.sym_load: update_sym_load, ComponentType.line: update_line}" |
457 | 454 | ] |
458 | 455 | }, |
459 | 456 | { |
|
475 | 472 | "outputs": [], |
476 | 473 | "source": [ |
477 | 474 | "from power_grid_model.validation import assert_valid_batch_data\n", |
| 475 | + "\n", |
478 | 476 | "assert_valid_batch_data(input_data=input_data, update_data=update_data, calculation_type=CalculationType.power_flow)" |
479 | 477 | ] |
480 | 478 | }, |
|
620 | 618 | "\n", |
621 | 619 | "time_series_mutation = {ComponentType.sym_load: load_profile}\n", |
622 | 620 | "\n", |
623 | | - "assert_valid_batch_data(input_data=input_data, update_data=time_series_mutation, calculation_type=CalculationType.power_flow)" |
| 621 | + "assert_valid_batch_data(\n", |
| 622 | + " input_data=input_data, update_data=time_series_mutation, calculation_type=CalculationType.power_flow\n", |
| 623 | + ")" |
624 | 624 | ] |
625 | 625 | }, |
626 | 626 | { |
|
730 | 730 | } |
731 | 731 | ], |
732 | 732 | "source": [ |
733 | | - "print(output_data[ComponentType.line][\"i_from\"][:,0])" |
| 733 | + "print(output_data[ComponentType.line][\"i_from\"][:, 0])" |
734 | 734 | ] |
735 | 735 | }, |
736 | 736 | { |
|
766 | 766 | "# below the same broadcasting trick\n", |
767 | 767 | "line_profile[\"id\"] = [[3, 5, 8]]\n", |
768 | 768 | "# fully specify the status of all lines, even it is the same as the base scenario\n", |
769 | | - "line_profile[\"from_status\"] = [\n", |
770 | | - " [0, 1, 1],\n", |
771 | | - " [1, 0, 1],\n", |
772 | | - " [1, 1, 0]\n", |
773 | | - "]\n", |
774 | | - "line_profile[\"to_status\"] = [\n", |
775 | | - " [0, 1, 1],\n", |
776 | | - " [1, 0, 1],\n", |
777 | | - " [1, 1, 0]\n", |
778 | | - "]\n", |
| 769 | + "line_profile[\"from_status\"] = [[0, 1, 1], [1, 0, 1], [1, 1, 0]]\n", |
| 770 | + "line_profile[\"to_status\"] = [[0, 1, 1], [1, 0, 1], [1, 1, 0]]\n", |
779 | 771 | "\n", |
780 | 772 | "n_min_1_mutation_update_all = {ComponentType.line: line_profile}\n", |
781 | 773 | "\n", |
782 | | - "assert_valid_batch_data(input_data=input_data, update_data=n_min_1_mutation_update_all, calculation_type=CalculationType.power_flow)" |
| 774 | + "assert_valid_batch_data(\n", |
| 775 | + " input_data=input_data, update_data=n_min_1_mutation_update_all, calculation_type=CalculationType.power_flow\n", |
| 776 | + ")" |
783 | 777 | ] |
784 | 778 | }, |
785 | 779 | { |
|
830 | 824 | "metadata": {}, |
831 | 825 | "outputs": [], |
832 | 826 | "source": [ |
833 | | - "line_profile = initialize_array(DatasetType.update, ComponentType.line, (3, 1)) # 3 scenarios, 1 object mutation per scenario\n", |
| 827 | + "line_profile = initialize_array(\n", |
| 828 | + " DatasetType.update, ComponentType.line, (3, 1)\n", |
| 829 | + ") # 3 scenarios, 1 object mutation per scenario\n", |
834 | 830 | "# for each mutation, only one object is specified\n", |
835 | 831 | "line_profile[\"id\"] = [[3], [5], [8]]\n", |
836 | 832 | "# specify only the changed status (switch off) of one line\n", |
|
839 | 835 | "\n", |
840 | 836 | "n_min_1_mutation_update_specific = {ComponentType.line: line_profile}\n", |
841 | 837 | "\n", |
842 | | - "assert_valid_batch_data(input_data=input_data, update_data=n_min_1_mutation_update_specific, calculation_type=CalculationType.power_flow)" |
| 838 | + "assert_valid_batch_data(\n", |
| 839 | + " input_data=input_data, update_data=n_min_1_mutation_update_specific, calculation_type=CalculationType.power_flow\n", |
| 840 | + ")" |
843 | 841 | ] |
844 | 842 | }, |
845 | 843 | { |
|
973 | 971 | "line_error[\"tan1\"] = [0.0]\n", |
974 | 972 | "line_error[\"i_n\"] = [1000]\n", |
975 | 973 | "\n", |
976 | | - "error_data = {\n", |
977 | | - " ComponentType.node: node_error,\n", |
978 | | - " ComponentType.line: line_error\n", |
979 | | - "}\n", |
| 974 | + "error_data = {ComponentType.node: node_error, ComponentType.line: line_error}\n", |
980 | 975 | "\n", |
981 | 976 | "try:\n", |
982 | 977 | " assert_valid_input_data(error_data, symmetric=True)\n", |
|
1059 | 1054 | "source": [ |
1060 | 1055 | "try:\n", |
1061 | 1056 | " model.calculate_power_flow(\n", |
1062 | | - " symmetric=True,\n", |
1063 | | - " error_tolerance=1e-20,\n", |
1064 | | - " max_iterations=20,\n", |
1065 | | - " calculation_method=CalculationMethod.newton_raphson)\n", |
| 1057 | + " symmetric=True, error_tolerance=1e-20, max_iterations=20, calculation_method=CalculationMethod.newton_raphson\n", |
| 1058 | + " )\n", |
1066 | 1059 | "except PowerGridError as e:\n", |
1067 | 1060 | " print(e)" |
1068 | 1061 | ] |
|
1097 | 1090 | "outputs": [], |
1098 | 1091 | "source": [ |
1099 | 1092 | "time_series_mutation[ComponentType.sym_load][\"id\"][3] = 1000 # unknown id\n", |
1100 | | - "time_series_mutation[ComponentType.sym_load][\"p_specified\"][7] = 1e100 # large power\n" |
| 1093 | + "time_series_mutation[ComponentType.sym_load][\"p_specified\"][7] = 1e100 # large power" |
1101 | 1094 | ] |
1102 | 1095 | }, |
1103 | 1096 | { |
|
1169 | 1162 | } |
1170 | 1163 | ], |
1171 | 1164 | "source": [ |
1172 | | - "# we run the batch calculation with continue_on_batch_error=True, \n", |
| 1165 | + "# we run the batch calculation with continue_on_batch_error=True,\n", |
1173 | 1166 | "# it will return the results with partially valid data\n", |
1174 | 1167 | "\n", |
1175 | 1168 | "\n", |
1176 | | - "output_data = model.calculate_power_flow(\n", |
1177 | | - " update_data=time_series_mutation,\n", |
1178 | | - " continue_on_batch_error=True\n", |
1179 | | - ")\n", |
| 1169 | + "output_data = model.calculate_power_flow(update_data=time_series_mutation, continue_on_batch_error=True)\n", |
1180 | 1170 | "\n", |
1181 | 1171 | "# print node data for u_pu, note that the data is rubbish for scenario 3 and 7\n", |
1182 | 1172 | "print(\"Node data with invalid results\")\n", |
|
0 commit comments