Skip to content

Commit

Permalink
Merge pull request e2nIEE#1356 from MMajidi137/julia_pkg
Browse files Browse the repository at this point in the history
add test file
  • Loading branch information
MMajidi137 authored Oct 12, 2021
2 parents adc996d + 86ec0de commit b4ddd23
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 35 deletions.
28 changes: 14 additions & 14 deletions doc/shortcircuit/elements.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.. _sc_elements:
==================
Network Elements
==================

Correction factors for generator and branch elements are implemented as defined in the IEC 60909 standard. The results for all elements are tested against commercial software to ensure that correction factors are correctly applied.


.. toctree::
:maxdepth: 1

voltage_source
current_source
branch_elements
.. _sc_elements:
==================
Network Elements
==================

Correction factors for generator and branch elements are implemented as defined in the IEC 60909 standard. The results for all elements are tested against commercial software to ensure that correction factors are correctly applied.


.. toctree::
:maxdepth: 1

voltage_source
current_source
branch_elements
42 changes: 21 additions & 21 deletions doc/shortcircuit/run.rst
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
====================================
Running a Short-Circuit Calculation
====================================

The short circuit calculation is carried out with the calc_sc function:

.. autofunction:: pandapower.shortcircuit.calc_sc


.. code:: python
import pandapower.shortcircuit as sc
import pandapower.networks as nw
net = nw.mv_oberrhein()
net.ext_grid["s_sc_min_mva"] = 100
net.ext_grid["rx_min"] = 0.1
net.line["endtemp_degree"] = 20
sc.calc_sc(net, case="min")
print(net.res_bus_sc)
====================================
Running a Short-Circuit Calculation
====================================

The short circuit calculation is carried out with the calc_sc function:

.. autofunction:: pandapower.shortcircuit.calc_sc


.. code:: python
import pandapower.shortcircuit as sc
import pandapower.networks as nw
net = nw.mv_oberrhein()
net.ext_grid["s_sc_min_mva"] = 100
net.ext_grid["rx_min"] = 0.1
net.line["endtemp_degree"] = 20
sc.calc_sc(net, case="min")
print(net.res_bus_sc)
1 change: 1 addition & 0 deletions pandapower/opf/run_powermodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def _call_pandamodels(buffer_file, julia_file, dev_mode): # pragma: no cover
except ImportError:
raise ImportError("cannot use PandaModels")


Main.buffer_file = buffer_file
result_pm = Main.eval(julia_file + "(buffer_file)")
return result_pm
Expand Down
131 changes: 131 additions & 0 deletions pandapower/test/opf/test_pandamodels_installation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Copyright (c) 2016-2021 by University of Kassel and Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel. All rights reserved.


import pytest

julia_installed = []

@pytest.mark.slow
@pytest.mark.skipif(julia_installed == False, reason="requires julia installation")
def test_julia_installation():

try:
from julia.core import UnsupportedPythonError
except AssertionError:
UnsupportedPythonError = Exception

try:
from julia import Main
status = True

except (AssertionError, RuntimeError, UnsupportedPythonError) as e:
status = False
print(e)


julia_installed.append(status)


@pytest.mark.slow
@pytest.mark.skipif(julia_installed == False, reason="requires julia installation")
@pytest.mark.dependency(depends=['test_julia_installation'])
def test_julia_connection():

try:
import julia
except:
raise AssertionError(
"install pyjulia properlly to run PandaModels.jl")

try:
julia.Julia()
except:
raise AssertionError(
"cannot connect to julia, check pyjulia configuration")


@pytest.mark.slow
@pytest.mark.skipif(julia_installed == False, reason="requires julia installation")
@pytest.mark.dependency(depends=['test_julia_connection'])
def test_pandamodels_installation():

from julia import Main
from julia import Pkg
from julia import Base

if Base.find_package("PandaModels"):
# remove PandaModels to reinstall it
Pkg.rm("PandaModels")
Pkg.resolve()

else:
print("PandaModels is not installed yet!")

Pkg.Registry.update()
Pkg.add("PandaModels")
Pkg.build()
Pkg.resolve()
print("PandaModels is added to julia packages")

try:
Main.using("PandaModels")
print("using PandaModels in its base mode!")
except:
raise AssertionError("cannot use PandaModels in its base mode")


@pytest.mark.slow
@pytest.mark.skipif(julia_installed == False, reason="requires julia installation")
@pytest.mark.dependency(depends=['test_pandamodels_installation'])
def test_pandamodels_dev_mode():

from julia import Main
from julia import Pkg
from julia import Base

if Base.find_package("PandaModels"):
# remove PandaModels to reinstall it
Pkg.rm("PandaModels")
Pkg.resolve()


Pkg.Registry.update()
Pkg.add("PandaModels")
print("installing dev mode is a slow process!")
Pkg.resolve()
Pkg.develop("PandaModels")
# add pandamodels dependencies: slow process
Pkg.instantiate()
Pkg.build()
Pkg.resolve()
print("dev mode of PandaModels is added to julia packages")

try:
Pkg.activate("PandaModels")
Main.using("PandaModels")
print("using PandaModels in its dev mode!")
except:
raise AssertionError("cannot use PandaModels in its base mode")

# activate julia base mode
Pkg.activate()
# remove dev mod
Pkg.rm("PandaModels")
Pkg.resolve()
# reinstall base mode
Pkg.Registry.update()
Pkg.add("PandaModels")
Pkg.build()
Pkg.resolve()
print("PandaModels is added to julia packages")


if __name__ == '__main__':

# test_julia_installation()
# test_julia_connection()
# test_pandamodels_installation()
# test_pandamodels_dev_mode()

pytest.main([__file__])

0 comments on commit b4ddd23

Please sign in to comment.