Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Update solver_py.cpp #999

Merged
merged 20 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified build-aux/setup-Darwin-20.sh
100644 → 100755
Empty file.
29 changes: 18 additions & 11 deletions build-aux/setup-Linux-amzn-2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@ yum -q install ncurses-devel -y
#yum -q install epel-release -y
yum -q install libcurl-devel -y

# python3 support needed as of 4.2
yum -q install python37 python3-devel python3-tkinter -y
[ -f /bin/python3 -a ! -f /usr/local/bin/python3 ] && ln -s /bin/python3 /usr/local/bin/python3
[ -f /bin/python3-config -a ! -f /usr/local/bin/python3-config ] && echo '#!/bin/bash
/bin/python3-config $*' > /usr/local/bin/python3-config
chmod +x /usr/local/bin/python3-config
[ ! -f /usr/local/include/python3.7m ] && ln -sf /usr/include/python3.7m /usr/local/include/python3.7m
/usr/local/bin/python3 -m pip install --quiet --user matplotlib pandas mysql-connector Pillow
chmod -R a+w /usr/local/lib64/python3.7/site-packages
# python3.9.x support needed as of 4.2
if [ ! -x /usr/local/bin/python3 -o $(/usr/local/bin/python3 --version | cut -f-2 -d.) != "Python 3.9" ]; then
yum install openssl-devel bzip2-devel libffi-devel zlib-devel -q -y
cd /usr/local/src
curl https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz | tar xz
cd Python-3.9.6
./configure --prefix=/usr/local --enable-optimizations --with-system-ffi --with-computed-gotos --enable-loadable-sqlite-extensions CFLAGS="-fPIC"
make -j $(nproc)
make altinstall
ln -sf /usr/local/bin/python3.9 /usr/local/bin/python3
ln -sf /usr/local/bin/python3.9-config /usr/local/bin/python3-config
ln -sf /usr/local/bin/pydoc3.9 /usr/local/bin/pydoc
ln -sf /usr/local/bin/idle3.9 /usr/local/bin/idle
ln -sf /usr/local/bin/pip3.9 /usr/local/bin/pip3
curl -sSL https://bootstrap.pypa.io/get-pip.py | /usr/local/bin/python3
/usr/local/bin/python3 pip -m install mysql-connector mysql-client matplotlib numpy pandas Pillow networkx
fi

# mono
if [ ! -f /usr/bin/mono ]; then
Expand All @@ -45,8 +53,7 @@ mono /usr/local/natural_docs/NaturalDocs.exe \$*' > /usr/local/bin/natural_docs
fi

# converter support
/usr/local/bin/python3 -m pip install --quiet --user networkx
# cd /tmp
# curl http://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/m/mdbtools-0.7.1-3.el7.x86_64.rpm > mdbtools-0.7.1-3.el7.x86_64.rpm
# rpm -Uvh mdbtools-0.7.1-3.el7.x86_64.rpm
# yum -q install mdbtools -y
yum -q install mdbtools -y
83 changes: 83 additions & 0 deletions build-aux/setup-Linux-ubuntu-20.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

# Install needed system tools
# update first
apt-get -q update
apt-get -q install tzdata -y

# install system build tools needed by gridlabd
apt-get -q install git -y
apt-get -q install unzip -y
apt-get -q install autoconf -y
apt-get -q install libtool -y
apt-get -q install g++ -y
apt-get -q install cmake -y
apt-get -q install flex -y
apt-get -q install bison -y
apt-get -q install libcurl4-gnutls-dev -y
apt-get -q install libncurses5-dev -y
apt-get -q install liblzma-dev -y
apt-get -q install libssl-dev -y
apt-get -q install libbz2-dev -y
apt-get -q install libffi-dev -y
apt-get -q install zlib1g-dev -y

# install python 3.9
if [ ! -x /usr/local/bin/python3 -o $(/usr/local/bin/python3 --version | cut -f-2 -d.) != "Python 3.9" ]; then
cd /usr/local/src
curl https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz | tar xz
cd Python-3.9.6
./configure --prefix=/usr/local --enable-optimizations --with-system-ffi --with-computed-gotos --enable-loadable-sqlite-extensions CFLAGS="-fPIC"
make -j $(nproc)
make altinstall
ln -sf /usr/local/bin/python3.9 /usr/local/bin/python3
ln -sf /usr/local/bin/python3.9-config /usr/local/bin/python3-config
ln -sf /usr/local/bin/pydoc3.9 /usr/local/bin/pydoc
ln -sf /usr/local/bin/idle3.9 /usr/local/bin/idle
curl -sSL https://bootstrap.pypa.io/get-pip.py | /usr/local/bin/python3
fi

# install python libraries by validation
/usr/local/bin/python3 pip -m install --upgrade pip
/usr/local/bin/python3 pip -m install mysql-connector mysql-client matplotlib numpy pandas Pillow

# doxggen
apt-get -q install gawk -y
if [ ! -x /usr/bin/doxygen ]; then
if [ ! -d /usr/local/src/doxygen ]; then
git clone https://github.com/doxygen/doxygen.git /usr/local/src/doxygen
fi
if [ ! -d /usr/local/src/doxygen/build ]; then
mkdir /usr/local/src/doxygen/build
fi
cd /usr/local/src/doxygen/build
cmake -G "Unix Makefiles" ..
make
make install
fi

# mono
apt-get -q install curl -y
if [ ! -f /usr/bin/mono ]; then
cd /tmp
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/ubuntu wheezy/snapshots/4.8.0 main" | tee /etc/apt/sources.list.d/mono-official.list
apt-get -q update -y
apt-get -q install mono-devel -y
fi

# natural_docs
if [ ! -x /usr/local/bin/natural_docs ]; then
cd /usr/local
curl https://www.naturaldocs.org/download/natural_docs/2.0.2/Natural_Docs_2.0.2.zip > natural_docs.zip
unzip -qq natural_docs
rm -f natural_docs.zip
mv Natural\ Docs natural_docs
echo '#!/bin/bash
mono /usr/local/natural_docs/NaturalDocs.exe \$*' > /usr/local/bin/natural_docs
chmod a+x /usr/local/bin/natural_docs
fi

# converter support
/usr/local/bin/python3 pip -m install networkx
apt-get -q install mdbtools -y
2 changes: 1 addition & 1 deletion module/powerflow/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pkglib_LTLIBRARIES += module/powerflow/powerflow.la

module_powerflow_powerflow_la_CPPFLAGS = -DSOLVER_PY
module_powerflow_powerflow_la_CPPFLAGS = -DSOLVER_PY -I$(shell python3 -c 'import numpy; print(numpy.get_include())')
module_powerflow_powerflow_la_CPPFLAGS += -I$(top_srcdir)/third_party/superLU_MT
module_powerflow_powerflow_la_CPPFLAGS += -I$(top_srcdir)/module/powerflow
module_powerflow_powerflow_la_CPPFLAGS += $(AM_CPPFLAGS)
Expand Down
23 changes: 23 additions & 0 deletions module/powerflow/autotest/solver_mle.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# comments are helpful
solver enable

logfile ./solver_mle.log
loglevel 9

import_path ..

import solver_py

busdata name,type,phases,volt_base,mva_base,VAr,VAi,VBr,VBi,VCr,VCi,SAr,SAi,SBr,SBi,SCr,SCi,YAr,YAi,YBr,YBi,YCr,YCi,IAr,IAi,IBr,IBi,ICr,ICi
branchdata phases,from,to,lnk_type,v_ratio,YfromAr,YfromAi,YfromBr,YfromBi,YfromCr,YfromCi,YtoAr,YtoAi,YtoBr,YtoBi,YtoCr,YtoCi,YSfromAr,YSfromAi,YSfromBr,YSfromBi,YSfromCr,YSfromCi,YStoAr,YStoAi,YStoBr,YStoBi,YStoCr,YStoCi

#learndata powerflow_values
#learndata powerflow_values.deltaI_NR,powerflow_values.BA_diag,powerflow_values.Y_offdiag_PQ,powerflow_values.Y_diag_fixed,powerflow_values.Y_diag_update,powerflow_values.Y_Amatrix
learndata powerflow_values.deltaI_NR,powerflow_values.Y_offdiag_PQ,powerflow_values.Y_diag_fixed,powerflow_values.Y_diag_update

profiler solver_py.csv

option dump=dataframe

mle_data_only true

15 changes: 9 additions & 6 deletions module/powerflow/autotest/solver_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import pprint as pp
import datetime as dt

pd.options.display.max_rows = None
pd.options.display.max_columns = None

def solve(gridlabd,**kwargs):
"""solve(gridlabd,kwargs)

Expand Down Expand Up @@ -32,12 +35,12 @@ def solve(gridlabd,**kwargs):
if kwargs['options']['dump'] == 'dataframe':
branch = pd.DataFrame(data=kwargs['branchdata'],index=kwargs['branchtags'])
bus = pd.DataFrame(data=kwargs['busdata'],index=kwargs['bustags'])
print(branch)
print(bus)
print(branch,file=output_stream)
print(bus,file=output_stream)
elif kwargs['options']['dump'] == 'pretty':
pp.PrettyPrinter(indent=4,stream=output_stream).pprint(kwargs)
elif kwargs['options']['dump'] == 'print':
print(kwargs)
print(kwargs,file=output_stream)
return -1

def learn(gridlabd,**kwargs):
Expand Down Expand Up @@ -77,10 +80,10 @@ def learn(gridlabd,**kwargs):
if kwargs['options']['dump'] == 'dataframe':
branch = pd.DataFrame(data=kwargs['branchdata'],index=kwargs['branchtags'])
bus = pd.DataFrame(data=kwargs['busdata'],index=kwargs['bustags'])
print(branch)
print(bus)
print(branch,file=output_stream)
print(bus,file=output_stream)
elif kwargs['options']['dump'] == 'pretty':
pp.PrettyPrinter(indent=4,stream=output_stream).pprint(kwargs)
elif kwargs['options']['dump'] == 'print':
print(kwargs)
print(kwargs,file=output_stream)
return None
Loading