Skip to content

Commit

Permalink
Merge pull request #38 from jinningwang/interface
Browse files Browse the repository at this point in the history
Interface
  • Loading branch information
jinningwang authored Feb 19, 2024
2 parents 1beaa60 + 961f790 commit af214eb
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 152 deletions.
2 changes: 0 additions & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ cli:
pycoverage:
report_type: "xml"

codecov:
token: 5fc2d41f-bcba-455d-a843-f85beb76d28f
ignore:
- "ams/_version.py"
- "ams/pypower/**"
24 changes: 24 additions & 0 deletions .github/workflows/codacy-coverage-reporter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Codacy Coverage Reporter

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check secret presence
id: check_secret
run: |
echo "is_set=false" >> $GITHUB_OUTPUT
if [ ! -z "${{ secrets.CODACY_PROJECT_TOKEN }}" ]; then
echo "is_set=true" >> $GITHUB_OUTPUT
fi
- name: Conditional run codacy-coverage-reporter
if: steps.check_secret.outputs.is_set == 'true'
uses: codacy/[email protected]
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage.xml
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
33 changes: 33 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Python application

on: [push, pull_request]

jobs:
build:
name: Codecov
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: 3.11
mamba-version: "*"
miniforge-version: "latest"
channels: conda-forge,defaults
channel-priority: true
activate-environment: anaconda-client-env
- shell: bash -el {0}
name: Install dependencies
run: |
mamba install -y nbmake pytest-xdist line_profiler # add'l packages for notebook tests.
mamba install --file requirements.txt --file requirements-extra.txt
python -m pip install -e .
- shell: bash -el {0}
name: Test with pytest and collect coverage
run: |
pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
13 changes: 0 additions & 13 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ jobs:
name: Test notebooks.
run: |
pytest --nbmake examples --ignore=examples/demonstration
- shell: bash -el {0}
name: Test with pytest and collect coverage
run: |
pytest --cov=./ --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage to Codacy
run: |
bash <(curl -Ls https://coverage.codacy.com/get.sh) report -r coverage.xml
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
- name: Build a distribution if tagged
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.9'
run: |
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ icebar
~$*.xlsx

# conda
.conda/*
.conda/*

# coverage
.coverage
coverage.xml
8 changes: 4 additions & 4 deletions ams/interop/andes.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def to_andes(system, setup=False, addfile=None,
--------
>>> import ams
>>> import andes
>>> sp = ams.load(ams.get_case('ieee14/ieee14_rted.xlsx'), setup=True)
>>> sp = ams.load(ams.get_case('ieee14/ieee14_uced.xlsx'), setup=True)
>>> sa = sp.to_andes(setup=False,
... addfile=andes.get_case('ieee14/ieee14_wt3.xlsx'),
... addfile=andes.get_case('ieee14/ieee14_full.xlsx'),
... overwrite=True, no_output=True)
Notes
Expand Down Expand Up @@ -279,9 +279,10 @@ def parse_addfile(adsys, amsys, addfile):
# add dynamic models
for name, df in df_models.items():
# drop rows that all nan
df.replace(['', ' '], np.NaN, inplace=True) # replace empty string with nan
df.dropna(axis=0, how='all', inplace=True)
# if the dynamic model also exists in AMS, use AMS parameters for overlap
if name in amsys.models.keys():
if (name in amsys.models.keys()) and amsys.models[name].n > 0:
if df.shape[0] != amsys.models[name].n:
msg = f'<{name}> has different number of rows in addfile.'
logger.warning(msg)
Expand Down Expand Up @@ -903,7 +904,6 @@ def make_link_table(adsys):
ssa_key0 = pd.merge(left=ssa_key0, how='left', on='stg_idx',
right=ssa_rg[['stg_idx', 'rg_idx']])

pd.set_option('future.no_silent_downcasting', True)
ssa_key0 = ssa_key0.fillna(value=False)
dyr = ssa_key0['syg_idx'].astype(bool) + ssa_key0['dg_idx'].astype(bool) + ssa_key0['rg_idx'].astype(bool)
non_dyr = np.logical_not(dyr)
Expand Down
4 changes: 4 additions & 0 deletions docs/source/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ The APIs before v3.0.0 are in beta and may change without prior notice.
Pre-v1.0.0
==========

v0.8.6 (2024-02-xx)

- Fix ANDES file converter issue

v0.8.5 (2024-01-31)

- Improve quality of coverage and format
Expand Down
116 changes: 58 additions & 58 deletions examples/ex1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Last run time: 2024-01-24 09:37:17\n",
"ams:0.8.1.post5+ge752692\n"
"Last run time: 2024-02-19 08:36:36\n",
"ams:0.8.5.post1.dev0+gf07da80\n"
]
}
],
Expand Down Expand Up @@ -127,10 +127,10 @@
"output_type": "stream",
"text": [
"Parsing input file \"/Users/jinningwang/Documents/work/ams/ams/cases/5bus/pjm5bus_uced.xlsx\"...\n",
"Input file parsed in 0.1218 seconds.\n",
"Input file parsed in 0.1072 seconds.\n",
"Zero line rates detacted in rate_a, rate_b, rate_c, adjusted to 999.\n",
"If expect a line outage, please set 'u' to 0.\n",
"System set up in 0.0021 seconds.\n"
"System set up in 0.0022 seconds.\n"
]
}
],
Expand Down Expand Up @@ -164,33 +164,33 @@
{
"data": {
"text/plain": [
"OrderedDict([('Summary', Summary (3 devices) at 0x105584d30),\n",
" ('Bus', Bus (5 devices) at 0x1056110d0),\n",
" ('PQ', PQ (3 devices) at 0x12f9b8df0),\n",
" ('PV', PV (3 devices) at 0x12f9caa60),\n",
" ('Slack', Slack (1 device) at 0x12f9e0910),\n",
" ('Shunt', Shunt (0 devices) at 0x12f9eb3d0),\n",
" ('Line', Line (7 devices) at 0x12f9eb880),\n",
" ('PVD1', PVD1 (0 devices) at 0x12f9f4f70),\n",
" ('ESD1', ESD1 (0 devices) at 0x12fa065b0),\n",
" ('REGCA1', REGCA1 (0 devices) at 0x12fa06b20),\n",
" ('REGCV1', REGCV1 (0 devices) at 0x12fa11160),\n",
" ('REGCV2', REGCV2 (0 devices) at 0x12fa11940),\n",
" ('Area', Area (3 devices) at 0x12fa11e80),\n",
" ('Region', Region (2 devices) at 0x12fa1e640),\n",
" ('SFR', SFR (2 devices) at 0x12fa1edf0),\n",
" ('SR', SR (2 devices) at 0x12fa2e490),\n",
" ('NSR', NSR (2 devices) at 0x12fa2e8b0),\n",
" ('VSGR', VSGR (0 devices) at 0x12fa2ecd0),\n",
" ('GCost', GCost (4 devices) at 0x12fa3a160),\n",
" ('SFRCost', SFRCost (4 devices) at 0x12fa3a7f0),\n",
" ('SRCost', SRCost (4 devices) at 0x12fa3ad90),\n",
" ('NSRCost', NSRCost (4 devices) at 0x12fa471f0),\n",
" ('VSGCost', VSGCost (0 devices) at 0x12fa47610),\n",
" ('DCost', DCost (3 devices) at 0x12fa47910),\n",
" ('TimeSlot', TimeSlot (0 devices) at 0x12fa47e80),\n",
" ('EDTSlot', EDTSlot (24 devices) at 0x12fa50940),\n",
" ('UCTSlot', UCTSlot (24 devices) at 0x12fa50d60)])"
"OrderedDict([('Summary', Summary (3 devices) at 0x1478df070),\n",
" ('Bus', Bus (5 devices) at 0x1478df9d0),\n",
" ('PQ', PQ (3 devices) at 0x1478f81f0),\n",
" ('PV', PV (3 devices) at 0x147906250),\n",
" ('Slack', Slack (1 device) at 0x147906cd0),\n",
" ('Shunt', Shunt (0 devices) at 0x147916790),\n",
" ('Line', Line (7 devices) at 0x147916c40),\n",
" ('PVD1', PVD1 (0 devices) at 0x147933370),\n",
" ('ESD1', ESD1 (0 devices) at 0x147933970),\n",
" ('REGCA1', REGCA1 (0 devices) at 0x147933ee0),\n",
" ('REGCV1', REGCV1 (0 devices) at 0x147940520),\n",
" ('REGCV2', REGCV2 (0 devices) at 0x147940d00),\n",
" ('Area', Area (3 devices) at 0x14794c280),\n",
" ('Region', Region (2 devices) at 0x14794ca00),\n",
" ('SFR', SFR (2 devices) at 0x1479591f0),\n",
" ('SR', SR (2 devices) at 0x147959850),\n",
" ('NSR', NSR (2 devices) at 0x147959c70),\n",
" ('VSGR', VSGR (0 devices) at 0x1479640d0),\n",
" ('GCost', GCost (4 devices) at 0x147964520),\n",
" ('SFRCost', SFRCost (4 devices) at 0x147964bb0),\n",
" ('SRCost', SRCost (4 devices) at 0x147974190),\n",
" ('NSRCost', NSRCost (4 devices) at 0x1479745b0),\n",
" ('VSGCost', VSGCost (0 devices) at 0x1479749d0),\n",
" ('DCost', DCost (3 devices) at 0x147974cd0),\n",
" ('TimeSlot', TimeSlot (0 devices) at 0x14797d280),\n",
" ('EDTSlot', EDTSlot (24 devices) at 0x14797dd00),\n",
" ('UCTSlot', UCTSlot (24 devices) at 0x14798a160)])"
]
},
"execution_count": 5,
Expand Down Expand Up @@ -269,7 +269,7 @@
" <td>PQ_1</td>\n",
" <td>1.0</td>\n",
" <td>PQ 1</td>\n",
" <td>1</td>\n",
" <td>Bus_2</td>\n",
" <td>230.0</td>\n",
" <td>3.0</td>\n",
" <td>0.9861</td>\n",
Expand All @@ -283,7 +283,7 @@
" <td>PQ_2</td>\n",
" <td>1.0</td>\n",
" <td>PQ 2</td>\n",
" <td>2</td>\n",
" <td>Bus_3</td>\n",
" <td>230.0</td>\n",
" <td>3.0</td>\n",
" <td>0.9861</td>\n",
Expand All @@ -297,7 +297,7 @@
" <td>PQ_3</td>\n",
" <td>1.0</td>\n",
" <td>PQ 3</td>\n",
" <td>3</td>\n",
" <td>Bus_4</td>\n",
" <td>230.0</td>\n",
" <td>4.0</td>\n",
" <td>1.3147</td>\n",
Expand All @@ -311,11 +311,11 @@
"</div>"
],
"text/plain": [
" idx u name bus Vn p0 q0 vmax vmin owner ctrl\n",
"uid \n",
"0 PQ_1 1.0 PQ 1 1 230.0 3.0 0.9861 1.1 0.9 None 1.0\n",
"1 PQ_2 1.0 PQ 2 2 230.0 3.0 0.9861 1.1 0.9 None 1.0\n",
"2 PQ_3 1.0 PQ 3 3 230.0 4.0 1.3147 1.1 0.9 None 1.0"
" idx u name bus Vn p0 q0 vmax vmin owner ctrl\n",
"uid \n",
"0 PQ_1 1.0 PQ 1 Bus_2 230.0 3.0 0.9861 1.1 0.9 None 1.0\n",
"1 PQ_2 1.0 PQ 2 Bus_3 230.0 3.0 0.9861 1.1 0.9 None 1.0\n",
"2 PQ_3 1.0 PQ 3 Bus_4 230.0 4.0 1.3147 1.1 0.9 None 1.0"
]
},
"execution_count": 6,
Expand Down Expand Up @@ -343,23 +343,23 @@
{
"data": {
"text/plain": [
"OrderedDict([('DCPF', DCPF at 0x12f9b8490),\n",
" ('PFlow', PFlow at 0x12fa5fa00),\n",
" ('CPF', CPF at 0x12fa73070),\n",
" ('ACOPF', ACOPF at 0x12fa736a0),\n",
" ('DCOPF', DCOPF at 0x12fa73fa0),\n",
" ('ED', ED at 0x12fca9100),\n",
" ('EDDG', EDDG at 0x12fcb40a0),\n",
" ('EDES', EDES at 0x12fcc7ac0),\n",
" ('RTED', RTED at 0x12fe09fd0),\n",
" ('RTEDDG', RTEDDG at 0x12fe1c0d0),\n",
" ('RTEDES', RTEDES at 0x12fe42760),\n",
" ('RTEDVIS', RTEDVIS at 0x12fe684f0),\n",
" ('UC', UC at 0x12fe7ac40),\n",
" ('UCDG', UCDG at 0x160845430),\n",
" ('UCES', UCES at 0x160866370),\n",
" ('DOPF', DOPF at 0x16088dd60),\n",
" ('DOPFVIS', DOPFVIS at 0x1608b0070)])"
"OrderedDict([('DCPF', DCPF at 0x1478df0a0),\n",
" ('PFlow', PFlow at 0x14798ad60),\n",
" ('CPF', CPF at 0x14799b3d0),\n",
" ('ACOPF', ACOPF at 0x14799ba00),\n",
" ('DCOPF', DCOPF at 0x1479b3340),\n",
" ('ED', ED at 0x1479ca160),\n",
" ('EDDG', EDDG at 0x147b163d0),\n",
" ('EDES', EDES at 0x147b28df0),\n",
" ('RTED', RTED at 0x147b61340),\n",
" ('RTEDDG', RTEDDG at 0x147b61400),\n",
" ('RTEDES', RTEDES at 0x147b83a90),\n",
" ('RTEDVIS', RTEDVIS at 0x147ba9820),\n",
" ('UC', UC at 0x147bbaf70),\n",
" ('UCDG', UCDG at 0x161db9760),\n",
" ('UCES', UCES at 0x161ddd6a0),\n",
" ('DOPF', DOPF at 0x161e100d0),\n",
" ('DOPFVIS', DOPFVIS at 0x161e223a0)])"
]
},
"execution_count": 7,
Expand Down Expand Up @@ -396,7 +396,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"Routine <RTED> initialized in 0.0130 seconds.\n"
"Routine <RTED> initialized in 0.0114 seconds.\n"
]
},
{
Expand Down Expand Up @@ -466,7 +466,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"RTED solved as optimal in 0.0173 seconds, converged after 9 iterations using solver ECOS.\n"
"RTED solved as optimal in 0.0171 seconds, converged after 9 iterations using solver ECOS.\n"
]
},
{
Expand Down
Loading

0 comments on commit af214eb

Please sign in to comment.