Repository: e2nIEE/pandapower

Issue:
Timeseries simulation not working with runpm_dc_opf()
When I run a DCOPF with 
`run_timeseries(net, time_steps, continue_on_divergence=True, verbose=True, recycle=False, run=pp.runpm_dc_opf)`

I get the following error:

`Progress: |████████████--------------------------------------| 25.0% CompleteTraceback (most recent call last):

  File "C:\Users\s792\Documents\Git_MathEnergy_PyBench\MathEnergy_PyBench\master_thesis_christoph\future_scenario_NEP_C2030\nepC2030_run.py", line 93, in <module>
    run_timeseries(net, time_steps, continue_on_divergence=True, verbose=True, recycle=False, run=pp.runpm_dc_opf)

  File "C:\Users\s792\anaconda3\envs\gitpandapower\lib\site-packages\pandapower\pandapower\timeseries\run_time_series.py", line 348, in run_timeseries
    run_loop(net, ts_variables, **kwargs)

  File "C:\Users\s792\anaconda3\envs\gitpandapower\lib\site-packages\pandapower\pandapower\timeseries\run_time_series.py", line 320, in run_loop
    run_time_step(net, time_step, ts_variables, run_control_fct, output_writer_fct, **kwargs)

  File "C:\Users\s792\anaconda3\envs\gitpandapower\lib\site-packages\pandapower\pandapower\timeseries\run_time_series.py", line 121, in run_time_step
    run_control_fct(net, run_control=False, ctrl_variables=ts_variables, **kwargs)

  File "C:\Users\s792\anaconda3\envs\gitpandapower\lib\site-packages\pandapower\pandapower\control\run_control.py", line 260, in run_control
    control_implementation(net, controller_order, ctrl_variables, max_iter, **kwargs)

  File "C:\Users\s792\anaconda3\envs\gitpandapower\lib\site-packages\pandapower\pandapower\control\run_control.py", line 194, in control_implementation
    ctrl_variables = evaluate_net_fct(net, levelorder, ctrl_variables, **kwargs)

  File "C:\Users\s792\anaconda3\envs\gitpandapower\lib\site-packages\pandapower\pandapower\control\run_control.py", line 160, in _evaluate_net
    run_funct(net, **kwargs)  # run can be runpp, runopf or whatever

TypeError: runpm_dc_opf() got an unexpected keyword argument 'run_control'`

I tried pandapower 2.4.0 and right now I am using the latest commit from the develop branch, but with both versions I get the same error.


Discussion:

Resolving patch:
diff --git a/pandapower/runpm.py b/pandapower/runpm.py
--- a/pandapower/runpm.py
+++ b/pandapower/runpm.py
@@ -17,7 +17,7 @@ def runpm(net, julia_file=None, pp_to_pm_callback=None, calculate_voltage_angles
           trafo_model="t", delta=1e-8, trafo3w_losses="hv", check_connectivity=True,
           correct_pm_network_data=True, pm_model="ACPPowerModel", pm_solver="ipopt",
           pm_mip_solver="cbc", pm_nl_solver="ipopt", pm_time_limits=None, pm_log_level=0,
-          delete_buffer_file=True, pm_file_path = None, opf_flow_lim="S"):  # pragma: no cover
+          delete_buffer_file=True, pm_file_path = None, opf_flow_lim="S", **kwargs):  # pragma: no cover
     """
     Runs a power system optimization using PowerModels.jl. with a custom julia file.
     
@@ -104,7 +104,7 @@ def runpm(net, julia_file=None, pp_to_pm_callback=None, calculate_voltage_angles
 def runpm_dc_opf(net, pp_to_pm_callback=None, calculate_voltage_angles=True,
                  trafo_model="t", delta=1e-8, trafo3w_losses="hv", check_connectivity=True,
                  correct_pm_network_data=True, pm_model="DCPPowerModel", pm_solver="ipopt",
-                 pm_time_limits=None, pm_log_level=0):  # pragma: no cover
+                 pm_time_limits=None, pm_log_level=0, **kwargs):  # pragma: no cover
     """
     Runs a linearized power system optimization using PowerModels.jl.
 
@@ -173,7 +173,7 @@ def runpm_ac_opf(net, pp_to_pm_callback=None, calculate_voltage_angles=True,
                  trafo_model="t", delta=1e-8, trafo3w_losses="hv", check_connectivity=True,
                  pm_model="ACPPowerModel", pm_solver="ipopt", correct_pm_network_data=True,
                  pm_time_limits=None, pm_log_level=0, pm_file_path = None, delete_buffer_file=True,
-                 opf_flow_lim="S"):  # pragma: no cover
+                 opf_flow_lim="S", **kwargs):  # pragma: no cover
     """
     Runs a non-linear power system optimization using PowerModels.jl.
 
@@ -254,7 +254,7 @@ def runpm_ac_opf(net, pp_to_pm_callback=None, calculate_voltage_angles=True,
 def runpm_tnep(net, pp_to_pm_callback=None, calculate_voltage_angles=True,
                trafo_model="t", delta=1e-8, trafo3w_losses="hv", check_connectivity=True,
                pm_model="DCPPowerModel", pm_solver=None, correct_pm_network_data=True,
-               pm_nl_solver="ipopt", pm_mip_solver="cbc", pm_time_limits=None, pm_log_level=0):  # pragma: no cover
+               pm_nl_solver="ipopt", pm_mip_solver="cbc", pm_time_limits=None, pm_log_level=0, **kwargs):  # pragma: no cover
     """
     Runs a non-linear transmission network extension planning (tnep) optimization using PowerModels.jl.
 
@@ -306,7 +306,7 @@ def runpm_tnep(net, pp_to_pm_callback=None, calculate_voltage_angles=True,
 def runpm_ots(net, pp_to_pm_callback=None, calculate_voltage_angles=True,
               trafo_model="t", delta=1e-8, trafo3w_losses="hv", check_connectivity=True,
               pm_model="DCPPowerModel", pm_solver="juniper", pm_nl_solver="ipopt", pm_mip_solver="cbc",
-              correct_pm_network_data=True, pm_time_limits=None, pm_log_level=0):  # pragma: no cover
+              correct_pm_network_data=True, pm_time_limits=None, pm_log_level=0, **kwargs):  # pragma: no cover
     """
     Runs a non-linear optimal transmission switching (OTS) optimization using PowerModels.jl.
 
@@ -355,7 +355,7 @@ def runpm_ots(net, pp_to_pm_callback=None, calculate_voltage_angles=True,
 def runpm_storage_opf(net, calculate_voltage_angles=True,
                       trafo_model="t", delta=1e-8, trafo3w_losses="hv", check_connectivity=True,
                       n_timesteps=24, time_elapsed=1.0, correct_pm_network_data=True,
-                      pm_model="ACPPowerModel", pm_time_limits=None, pm_log_level=0):  # pragma: no cover
+                      pm_model="ACPPowerModel", pm_time_limits=None, pm_log_level=0, **kwargs):  # pragma: no cover
     """
     Runs a non-linear power system optimization with storages and time series using PowerModels.jl.
 


Test patch:
diff --git a/pandapower/test/opf/test_powermodels.py b/pandapower/test/opf/test_powermodels.py
--- a/pandapower/test/opf/test_powermodels.py
+++ b/pandapower/test/opf/test_powermodels.py
@@ -20,6 +20,8 @@
 from pandapower.test.toolbox import add_grid_connection, create_test_line
 from pandapower.converter import convert_pp_to_pm
 from pandapower.test.opf.test_basic import simple_opf_test_net
+import pandapower.control
+import pandapower.timeseries
 
 try:
     from julia.core import UnsupportedPythonError
@@ -556,6 +558,20 @@ def test_pm_to_pp_conversion(simple_opf_test_net):
     assert np.allclose(net.res_bus.va_degree, va_degree, atol=1e-2, rtol=1e-2)
 
 
+@pytest.mark.skipif(not julia_installed, reason="requires julia installation")
+def test_timeseries_powermodels():
+    profiles = pd.DataFrame()
+    n_timesteps = 3
+    profiles['load1'] = np.random.random(n_timesteps) * 2e1
+    ds = pp.timeseries.DFData(profiles)
+
+    net = nw.simple_four_bus_system()
+    time_steps = range(3)
+    pp.control.ConstControl(net, 'load', 'p_mw', element_index=0, data_source=ds, profile_name='load1', scale_factor=0.85)
+    net.load['controllable'] = False
+    pp.timeseries.run_timeseries(net, time_steps, continue_on_divergence=True, verbose=False, recycle=False, run=pp.runpm_dc_opf)
+
+
 if __name__ == '__main__':
     test_pwl()
     # pytest.main([__file__])