Skip to content

Commit

Permalink
v0.6.3. Update stepspy to include both parallel and serial library. I…
Browse files Browse the repository at this point in the history
…t is found that the serial version without openmp is 2 times faster than the parallel version if parallel_thread_number is set as 1. Therefore, both parallel and serial library files should be created.
  • Loading branch information
changgang committed Sep 18, 2019
1 parent 7d9be77 commit 599512f
Show file tree
Hide file tree
Showing 12 changed files with 3,013 additions and 1 deletion.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,24 @@ Here is a complete procedure of how to build STEPS.
4. Compile CppTest as static library. You can find CppTest.cbp in the code/ folder.
5. Compile STEPS as dynamic library or exectuable file. Include libUMFPACK.a, libBLAS.a, libCSparse.a, and libCpptest.a. Put libBLAS.a after libUMFPACK.a.

### Parallel and serial version
Dynamic simulator has both parallel and serial version. Typically, the serial version is 2 times faster than the parallel version if paralle number is set to 1. Therefore, in stepspy both parallel and serial library should be provided.

To build serial version, comment the following line in dynamic_simulator.cpp, then build with previous instructions to get libSTEPS.dll or libSTEPS.so:

> #define STEPS_DYNAMIC_SIMULATOR_OPENMP
To build parallel version, keep the following line in dynamic_simulator.cpp, then build with previous instructions to get another libSTEPS.dll or libSTEPS.so:

> #define STEPS_DYNAMIC_SIMULATOR_OPENMP
Then, you should change libSTEPS to libSTEPS-p, i.e., the library file becomes libSTEPS-p.dll or libSTEPS-p.so.

## How to use stepspy
stepspy is a Python module of advanced APIs of STEPS. It enables most of STEPS applications. It is recommended to use stepspy in Python 3 of 64-bit version, though Python 2 is also supported.

stepspy has been uploaded to pypi.org, and can be installed via:
- pip3 install stepspy
- python -m pip install stepspy

Both parallel and serial library files should be built and copied to the stepspy folder.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <ctime>
#include <omp.h>

#define STEPS_DYNAMIC_SIMULATOR_OPENMP
//#define STEPS_DYNAMIC_SIMULATOR_OPENMP

using namespace std;

Expand Down
21 changes: 21 additions & 0 deletions python/stepspy0.8.1/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Changgang Li

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
76 changes: 76 additions & 0 deletions python/stepspy0.8.1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# stepspy

> stepspy
stepspy is a Python module of Simulation Toolkit for Electrical Power Systems (STEPS).

## Table of Contents

- [Background](#background)
- [Release Note](#release-note)
- [Install](#install)
- [Usage](#usage)
- [Examples](#examples)
- [Maintainers](#maintainers)
- [Contributing](#contributing)
- [License](#license)

## Background

stepspy is a Python module of Simulation Toolkit for Electrical Power Systems (STEPS). It provides wrapper of APIs of STEPS in a dynamic library.

STEPS is a simulation toolkit for powerflow and dynamic simulation of large-scale power systems. It provides detailed models of bus, line, transformer, HVDC, generator, wind turbine generator, load, and fixed shunt. For more information about STEPS, see (https://github.com/changgang/steps).

## Realse Note

- 0.8.1. Sep. 18, 2019. Update and README.
- 0.8.0. Sep. 18, 2019. Update to enable both parallel and serial library. Since STEPS 0.6.3.
- 0.7.1. Sep. 18, 2019. Fix API to set and get parallel thread number.
- 0.7.0. Sep. 18, 2019. Add new API to set parallel thread number. Update README.
- 0.6.1. Aug. 27, 2019
- 0.6.0. Aug. 25, 2019


## Install

### Install stepspy

To install stepspy, you can run the following codes on your computer or server:

```python
python -m pip install stepspy
```

If you want to manually install stepspy, follow the instructions:

1. Go to https://github.com/changgang/steps to download or fork the latest version of STEPS.
2. Go to python/ folder of STEPS, and copy the latest version of stepspy/ to PYTHONPATH/Lib/site-packages/.

### Install dynamic library

After install the stepspy, you still need to compile and install the dynamic library of STEPS.

1. Go to [steps](https://github.com/changgang/steps) to download or fork the latest version of STEPS. The latest version is usually the [work] branch.
2. Compile STEPS into dynamic library following instructions of STEPS.
3, Move the dynamic library of STEPS to stepspy/libsteps/ in the PYTHONPATH/Lib/site-packages/.
4, If the VC runtime is missing, download and install Microsoft Visual C++ 2017 Redistributable of 32 or 64 bit version.
5, If VC runtime or Mingw Runtime is missing, install vcredit or copy libwinpthread-1.dll from mingw compiler/bin/ to c:/windows/system32 and c:/windows/SysWOW64

Follow README of STEPS if you want to use both serial and parallel library.

## Usage

## Examples


## Maintainers

[@changgang](https://github.com/changgang) <[email protected]> from the School of Electrical Engineering, Shandong University, China

## Contributing

Feel free to dive in! [Open an issue](https://github.com/changgang/steps/issues/new).

## License

[MIT](LICENSE) @ Changgang Li
187 changes: 187 additions & 0 deletions python/stepspy0.8.1/demo/demo_pysteps2_powerflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#coding = utf-8
'''
Here is a demo of showing how to slove powerflow with stepspy.
Changgang Li, 2019/08/25
'''

from stepspy import STEPS # import the class 'STEPS'

simulator = STEPS(is_default=True) # create a STEPS simulator instance


powerflow_data_file = 'IEEE9.raw' # file name of powerflow data. Use absolute path if necessary
powerflow_data_type = 'PSS/E' # powerflow data type. Currently, use 'PSS/E' only

simulator.load_powerflow_data(powerflow_data_file, powerflow_data_type) # load powerflow data into the simulator

data_type = 'D' # if you want to set or get doubule data, set data_type as 'F' or 'D'.
data_name = 'MAX ACTIVE POWER IMBALANCE IN MW' # the data name in the powerflow solver of the simulator
# the data_type and data_name should be consistent. make sure the data_type is correct.
# If the data is double, use 'F' or 'D'. If the data is integer, use 'I'. If the data is boolean, use 'B'. If the data is string, use 'S'
'''
(1) when data_type is 'D' or 'F' you can set/get the following data
'MAX ACTIVE POWER IMBALANCE IN MW': maximum allowed active power mismatch at each bus, in MW. This is the powerflow convergence threshold of P equations.
'MAX REACTIVE POWER IMBALANCE IN MVAR': maximum allowed reactive power mismatch at each bus, in MVar. This is the powerflow convergence threshold of Q equations.
'ITERATION ACCELERATOR': acceleration factor for iteration. by default it is 1.0. if >1.0, then the powerflow solver is accelerated. if <1.0, the powerflow solver is decellerated.
(2) when data_type is 'I', you can set/get the following data
'MAX ITERATION': maximum iteration count allowed for solving powerflow. If set as 1, you can get the solution step by step.
(3)when data_type is 'B', you can set/get the following data
'FLAT START LOGIC': if true, powerflow will be solved with unity voltage profile (1.0pu, 0.0deg), if false, poewrflow will be solved from the current voltage profile.
'''

# here goes get and set maximum active power imbalance in MW
data_type = 'D'
data_name = 'MAX ACTIVE POWER IMBALANCE IN MW'
P_error_MW = simulator.get_powerflow_solver_parameter(data_type, data_name)

value = 0.001
simulator.set_powerflow_solver_parameter(data_type, data_name, value)

# here goes get and set maximum reactive power imbalance in MVAR
data_type = 'D'
data_name = 'MAX REACTIVE POWER IMBALANCE IN MVAR'
Q_error_MVar = simulator.get_powerflow_solver_parameter(data_type, data_name)

value = 0.001
simulator.set_powerflow_solver_parameter(data_type, data_name, value)

# here goes get and set maximum iteration
data_type = 'I'
data_name = 'MAX ITERATION'
Iter_max = simulator.get_powerflow_solver_parameter(data_type, data_name)

value = 50
simulator.set_powerflow_solver_parameter(data_type, data_name, value)

# here goes get and set flat start logic
data_type = 'B'
data_name = 'FLAT START LOGIC'
flat_flag = simulator.get_powerflow_solver_parameter(data_type, data_name)

value = False
simulator.set_powerflow_solver_parameter(data_type, data_name, value)

# now assuming that maximum active and reactive power imbalance are already set.
# show how to solve powerflow

# solve powerflow with flat start logic disabled
data_type = 'B'
data_name = 'FLAT START LOGIC'
value = False
simulator.set_powerflow_solver_parameter(data_type, data_name, value)

simulator.solve_powerflow('NR') # use 'NR' for Newton-Raphson solution, use 'PQ' for PQ decoupled solution

# solve powerflow with flat start logic enabled
data_type = 'B'
data_name = 'FLAT START LOGIC'
value = True
simulator.set_powerflow_solver_parameter(data_type, data_name, value)

simulator.solve_powerflow('PQ')

# if you want to solve powerflow step by step to get the solution process,
# you can set MAX ITERATION as 1, and Flat start logic as false
data_type = 'I'
data_name = 'MAX ITERATION'
value = 1
simulator.set_powerflow_solver_parameter(data_type, data_name, value)

data_type = 'B'
data_name = 'FLAT START LOGIC'
value = True
simulator.set_powerflow_solver_parameter(data_type, data_name, value)

simulator.solve_powerflow('NR') # first slove it with flat start enable

data_type = 'B'
data_name = 'FLAT START LOGIC'
value = False
simulator.set_powerflow_solver_parameter(data_type, data_name, value) # from now on, disable flat start

while not simulator.is_powerflow_converged(): # use is_powerflow_converged() to check if powerflow is converged
simulator.solve_powerflow('NR')
simulator.save_jacobian_matrix('jacobian.txt') # if you are solving with NR method, you can get jacobian matrix of each iteration in the file

# once powerflow is converged, you can export powerflow result to file
powerflow_result_file = 'pf_result.txt'
simulator.save_powerflow_result(powerflow_result_file) # you can check the file's contents

# you can get power loss of a solved powerflow case
ploss_MW = simulator.get_powerflow_loss() # in MW
print('Loss is:', ploss_MW)

# if you want to get the voltage of each bus, you can try the following codes
buses = simulator.get_all_buses()
for bus in buses:
bus_name = simulator.get_bus_data(bus, 'S', 'Name')
voltage = simulator.get_bus_data(bus, 'D', 'Voltage in PU')
angle = simulator.get_bus_data(bus, 'D', 'Angle in deg')
print(bus, bus_name, voltage, angle)

# if you want to get the generation of each generator, you can try the following codes
generators = simulator.get_generators_at_bus(0) # 0 indicate all generators will be returned
for generator in generators:
P = simulator.get_generator_data(generator, 'D', 'PGEN_MW')
Q = simulator.get_generator_data(generator, 'D', 'QGEN_MVAR')
print(generator, P, Q)

# if you want to get the load of each load, you can try the following codes
loads = simulator.get_loads_at_bus(0) # 0 indicate all loads will be returned
for load in loads:
P = simulator.get_load_data(load, 'D', 'P_MW')
Q = simulator.get_load_data(load, 'D', 'Q_MVAR')
print(load, P, Q)

# if you want to get the power of each line, you can try the following codes
lines = simulator.get_lines_at_bus(0) # 0 indicate all lines will be returned
for line in lines:
bus_send = simulator.get_line_data(line, 'I', 'BUS_SEND') # get the bus number of sending side
bus_recv = simulator.get_line_data(line, 'I', 'BUS_RECV') # get the bus number of receiving side
Psend = simulator.get_line_data(line, 'D', 'PSEND_MW') # active power at sending side
Qsend = simulator.get_line_data(line, 'D', 'QSEND_MVAR') # reactive power at sending side
Precv = simulator.get_line_data(line, 'D', 'PRECV_MW') # active power at receiving side
Qrecv = simulator.get_line_data(line, 'D', 'QRECV_MVAR') # reactive power at receiving side
print(line, bus_send, (Psend, Qsend), bus_recv, (Precv, Qrecv))

# if you want to get the power of each transformer, you can try the following codes
transformers = simulator.get_transformers_at_bus(0) # 0 indicate all transformers will be returned
for transformer in transformers:
bus_pri = simulator.get_transformer_data(transformer, 'I', 'Primary', 'BUS') # get the bus number of primary side
bus_sec = simulator.get_transformer_data(transformer, 'I', 'Secondary', 'BUS') # get the bus number of secondary side

P_pri = simulator.get_transformer_data(transformer, 'D', 'Primary', 'P_MW') # active power at primary side
Q_pri = simulator.get_transformer_data(transformer, 'D', 'Primary', 'Q_MVAR') # reactive power at primary side
P_sec = simulator.get_transformer_data(transformer, 'D', 'Secondary', 'P_MW') # active power at secondary side
Q_sec = simulator.get_transformer_data(transformer, 'D', 'Secondary', 'Q_MVAR') # reactive power at secondary side
print(transformer, bus_pri, (P_pri, Q_pri), bus_sec, (P_sec, Q_sec))



# if you want to change generation of each generaor, trye the following codes
generator = (2,'1') # generator bus, and generator ID, check generator line of raw file
simulator.set_generator_data(generator, 'D', 'PGEN_MW', 50.0) # remember, only P of generator at bus of type 2 can be changed

data_type = 'I'
data_name = 'MAX ITERATION'
value = 10
simulator.set_powerflow_solver_parameter(data_type, data_name, value)

data_type = 'B'
data_name = 'FLAT START LOGIC'
value = True
simulator.set_powerflow_solver_parameter(data_type, data_name, value)

simulator.solve_powerflow('NR')










17 changes: 17 additions & 0 deletions python/stepspy0.8.1/howto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
1. install wheel and twine, use:

python -m pip install wheel twine

2. change version of stepsy in setup.py

3. to build stepspy module, use:

python setup.py sdist bdist_wheel

4. to upload stepspy module to pypi, use:

python -m twine upload dist/*

5. to check whether the built module is OK or not, use:

python -m twine check dist/*
23 changes: 23 additions & 0 deletions python/stepspy0.8.1/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import setuptools

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name="stepspy",
version="0.8.1",
author="Changgang Li",
author_email="[email protected]",
description="Python module of Simulation Toolkit for Electrical Power Systems",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/changgang/steps",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Programming Language :: C++",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)
3 changes: 3 additions & 0 deletions python/stepspy0.8.1/stepspy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .stepspy import STEPS
name = 'stepspy'
__all__ = ['STEPS']
1 change: 1 addition & 0 deletions python/stepspy0.8.1/stepspy/libsteps/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__all__ = ['pylibsteps']
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 599512f

Please sign in to comment.