Skip to content

Commit

Permalink
Merge branch 'refs/heads/devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
SanPen committed Sep 1, 2024
2 parents ace6332 + e7d9c74 commit 88e79d7
Show file tree
Hide file tree
Showing 7 changed files with 730 additions and 990 deletions.
1,544 changes: 632 additions & 912 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def update_diagram(self):
"""
lat, long = self.editor.to_lat_lon(self.rect().x(), self.rect().y())

self.lat = lat
self.lon = long

self.editor.update_diagram_element(device=self.api_object,
latitude=lat,
longitude=long,
Expand Down
3 changes: 3 additions & 0 deletions src/GridCal/Gui/Main/GridCalMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def load_all_config(self) -> None:
self.load_server_config()
self.add_plugins()

# apply the theme selected by the settings
self.change_theme_mode()

def closeEvent(self, event: QtGui.QCloseEvent) -> None:
"""
Close event
Expand Down
109 changes: 56 additions & 53 deletions src/GridCal/Gui/Main/SubClasses/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ def open_file(self):
else:
warning_msg('There is a file being processed now.')

def open_file_threaded(self, post_function=None, allow_diff_file_format: bool = False, title: str = 'Open file'):
def open_file_threaded(self, post_function=None,
allow_diff_file_format: bool = False,
title: str = 'Open file'):
"""
Open file from a Qt thread to remain responsive
:param post_function: Any function to run after
Expand Down Expand Up @@ -422,7 +424,7 @@ def post_open_file(self) -> None:
self.collect_memory()
self.setup_time_sliders()
self.get_circuit_snapshot_datetime()

self.change_theme_mode()

def select_csv_file(self, caption='Open CSV file'):
"""
Expand Down Expand Up @@ -466,60 +468,60 @@ def post_add_circuit(self):

if self.open_file_thread_object.valid:

if not new_circuit.valid_for_simulation():
# load the circuit right away
self.stuff_running_now.append('file_open')
self.post_open_file()
else:
# add the circuit
logger = self.circuit.add_circuit(new_circuit)
# if not new_circuit.valid_for_simulation():
# # load the circuit right away
# self.stuff_running_now.append('file_open')
# self.post_open_file()
# else:
# add the circuit
logger = self.circuit.add_circuit(new_circuit)

if len(logger) > 0:
dlg = LogsDialogue('File merge logger', logger)
dlg.exec_()
if len(logger) > 0:
dlg = LogsDialogue('File merge logger', logger)
dlg.exec_()

dlg2 = CustomQuestionDialogue(title="Grid differential",
question="How do you want to represent the loaded grid?",
answer1="Create new diagram",
answer2="Add to current diagram")
dlg2.exec_()
dlg2 = CustomQuestionDialogue(title="Grid differential",
question="How do you want to represent the loaded grid?",
answer1="Create new diagram",
answer2="Add to current diagram")
dlg2.exec_()

if dlg2.accepted_answer == 1:
# Create a blank diagram and add to it
diagram_widget = self.create_blank_schematic_diagram(name=new_circuit.name)
if dlg2.accepted_answer == 1:
# Create a blank diagram and add to it
diagram_widget = self.create_blank_schematic_diagram(name=new_circuit.name)

elif dlg2.accepted_answer == 2:
diagram_widget = self.get_selected_diagram_widget()
elif dlg2.accepted_answer == 2:
diagram_widget = self.get_selected_diagram_widget()

else:
return

if diagram_widget is not None:
injections_by_bus = new_circuit.get_injection_devices_grouped_by_bus()
injections_by_fluid_node = new_circuit.get_injection_devices_grouped_by_fluid_node()
injections_by_cn = new_circuit.get_injection_devices_grouped_by_cn()
diagram_widget.add_elements_to_schematic(buses=new_circuit.buses,
connectivity_nodes=new_circuit.connectivity_nodes,
busbars=new_circuit.bus_bars,
lines=new_circuit.lines,
dc_lines=new_circuit.dc_lines,
transformers2w=new_circuit.transformers2w,
transformers3w=new_circuit.transformers3w,
hvdc_lines=new_circuit.hvdc_lines,
vsc_devices=new_circuit.vsc_devices,
upfc_devices=new_circuit.upfc_devices,
switches=new_circuit.switch_devices,
fluid_nodes=new_circuit.fluid_nodes,
fluid_paths=new_circuit.fluid_paths,
injections_by_bus=injections_by_bus,
injections_by_fluid_node=injections_by_fluid_node,
injections_by_cn=injections_by_cn,
explode_factor=1.0,
prog_func=None,
text_func=None)
diagram_widget.set_selected_buses(buses=new_circuit.buses)
else:
info_msg("No diagram was selected...", title="Add to current diagram")
else:
return

if diagram_widget is not None:
injections_by_bus = new_circuit.get_injection_devices_grouped_by_bus()
injections_by_fluid_node = new_circuit.get_injection_devices_grouped_by_fluid_node()
injections_by_cn = new_circuit.get_injection_devices_grouped_by_cn()
diagram_widget.add_elements_to_schematic(buses=new_circuit.buses,
connectivity_nodes=new_circuit.connectivity_nodes,
busbars=new_circuit.bus_bars,
lines=new_circuit.lines,
dc_lines=new_circuit.dc_lines,
transformers2w=new_circuit.transformers2w,
transformers3w=new_circuit.transformers3w,
hvdc_lines=new_circuit.hvdc_lines,
vsc_devices=new_circuit.vsc_devices,
upfc_devices=new_circuit.upfc_devices,
switches=new_circuit.switch_devices,
fluid_nodes=new_circuit.fluid_nodes,
fluid_paths=new_circuit.fluid_paths,
injections_by_bus=injections_by_bus,
injections_by_fluid_node=injections_by_fluid_node,
injections_by_cn=injections_by_cn,
explode_factor=1.0,
prog_func=None,
text_func=None)
diagram_widget.set_selected_buses(buses=new_circuit.buses)
else:
info_msg("No diagram was selected...", title="Add to current diagram")

def export_circuit_differential(self):
"""
Expand Down Expand Up @@ -903,7 +905,8 @@ def export_simulation_data(self):
for elm_type in elms_in_category:
name = f"{category}_{elm_type}@{c}"
df = calc_input.get_structure(elm_type).astype(str)
df.to_excel(excel_writer=writer, sheet_name=name[:31]) # excel supports 31 chars per sheet name
df.to_excel(excel_writer=writer,
sheet_name=name[:31]) # excel supports 31 chars per sheet name

def load_results_driver(self):
"""
Expand Down Expand Up @@ -1029,4 +1032,4 @@ def save_custom_catalogue(self):
filename += ".xlsx"

if filename != "":
save_catalogue(fname=filename, grid=self.circuit)
save_catalogue(fname=filename, grid=self.circuit)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _dummy_accent_detector() -> None:
def _select_accent_detector():
if platform.system() == "Darwin":
if _check_macos_supported_version():
from qdarktheme._os_appearance._accent._mac_detect import get_mac_accent
from GridCal.ThirdParty.qdarktheme._os_appearance._accent._mac_detect import get_mac_accent

return get_mac_accent
return _dummy_accent_detector
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_ptdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def test_mlodf() -> None:
linear_multi_contingency = gce.LinearMultiContingencies(grid=main_circuit,
contingency_groups_used=main_circuit.get_contingency_groups())
linear_multi_contingency.compute(ptdf=linear_analysis.results.PTDF, lodf=linear_analysis.results.LODF)
mlodf = linear_multi_contingency.multi_contingencies[0].mlodf_factors.A # TODO: Suponemos que son los MLODF
mlodf = linear_multi_contingency.multi_contingencies[0].mlodf_factors.toarray() # TODO: Suponemos que son los MLODF

# Power flow per branches after multicontingency using MLODF method
Sfmlodf = Sf0 + np.matmul(mlodf, Sf0red)
Expand Down
57 changes: 34 additions & 23 deletions src/tests/test_simple_mip.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
import numpy as np
from GridCalEngine.Utils.MIP.SimpleMip import LpModel, LpExp, LpCst, LpVar

try:
import highspy

HIGHSPY_AVAILABLE = True
except ImportError:
HIGHSPY_AVAILABLE = False


def test_linear_formulation():

Expand Down Expand Up @@ -110,16 +117,17 @@ def test_lp_simple2():
prob.add_cst(A + B <= 4)
prob.add_cst(A + B >= 2)

prob.solve()
if HIGHSPY_AVAILABLE:
prob.solve()

assert prob.is_optimal()
assert prob.get_objective_value() == 4
assert prob.is_optimal()
assert prob.get_objective_value() == 4

prob.minimize(A + B + 1)
prob.solve()
prob.minimize(A + B + 1)
prob.solve()

assert prob.is_optimal()
assert prob.get_objective_value() == 3
assert prob.is_optimal()
assert prob.get_objective_value() == 3


def test_lp_simple3():
Expand All @@ -132,12 +140,14 @@ def test_lp_simple3():

prob.add_cst(3 * XR + 4 * XE <= 650)
prob.add_cst(2 * XR + 3 * XE <= 500)
prob.solve()

assert prob.is_optimal()
assert np.isclose(prob.get_objective_value(), 1137.5)
assert np.isclose(prob.get_value(XR), 0)
assert np.isclose(prob.get_value(XE), 162.5)
if HIGHSPY_AVAILABLE:
prob.solve()

assert prob.is_optimal()
assert np.isclose(prob.get_objective_value(), 1137.5)
assert np.isclose(prob.get_value(XR), 0)
assert np.isclose(prob.get_value(XE), 162.5)


def test_lp_simple4():
Expand All @@ -146,17 +156,18 @@ def test_lp_simple4():
X = prob.add_vars(name="X", size=4)
S = prob.add_vars(name="S", size=5)

prob.maximize(2 * X[3] + S[4])
if HIGHSPY_AVAILABLE:
prob.maximize(2 * X[3] + S[4])

prob.add_cst(X[0] + S[0] == 100)
prob.add_cst(S[0] - 0.5 * X[0] - X[1] - S[1] == 0)
prob.add_cst(2 * X[0] + S[1] - 0.5 * X[1] - X[2] - S[2] == 0)
prob.add_cst(2 * X[1] + S[2] - 0.5 * X[2] - X[3] - S[3] == 0)
prob.add_cst(2 * X[2] + S[3] - 0.5 * X[3] - S[4] == 0)
prob.add_cst(X[0] + S[0] == 100)
prob.add_cst(S[0] - 0.5 * X[0] - X[1] - S[1] == 0)
prob.add_cst(2 * X[0] + S[1] - 0.5 * X[1] - X[2] - S[2] == 0)
prob.add_cst(2 * X[1] + S[2] - 0.5 * X[2] - X[3] - S[3] == 0)
prob.add_cst(2 * X[2] + S[3] - 0.5 * X[3] - S[4] == 0)

prob.solve()
prob.solve()

assert prob.is_optimal()
assert np.isclose(prob.get_objective_value(), 208.13008130081298)
assert np.allclose(prob.get_array_value(X), np.array([27.642277, 58.536587, 26.016260, 104.065041]))
assert np.allclose(prob.get_array_value(S), np.array([72.357727, 0.0, 0.0, 0.0, 0.0]))
assert prob.is_optimal()
assert np.isclose(prob.get_objective_value(), 208.13008130081298)
assert np.allclose(prob.get_array_value(X), np.array([27.642277, 58.536587, 26.016260, 104.065041]))
assert np.allclose(prob.get_array_value(S), np.array([72.357727, 0.0, 0.0, 0.0, 0.0]))

0 comments on commit 88e79d7

Please sign in to comment.