Skip to content

Commit

Permalink
[WIP] Resolve conflicts, add changes back
Browse files Browse the repository at this point in the history
  • Loading branch information
jinningwang committed Feb 24, 2024
1 parent f6ed683 commit b48e82a
Show file tree
Hide file tree
Showing 17 changed files with 228 additions and 168 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Code coverage

on: [push, pull_request]

jobs:
build:
name: Report coverage
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 }}

- 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: Upload coverage to Codacy
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 }}
15 changes: 1 addition & 14 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 All @@ -60,4 +47,4 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
password: ${{ secrets.PYPI_PASSWORD }}
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
10 changes: 5 additions & 5 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 Expand Up @@ -932,4 +932,4 @@ def make_link_table(adsys):
'gammap', 'gammaq', # gamma
]
out = ssa_key[cols].sort_values(by='stg_idx', ascending=False).reset_index(drop=True)
return out
return out
12 changes: 9 additions & 3 deletions ams/routines/routine.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,14 @@ def _post_add_check(self):
"""
Post-addition check.
"""
# --- reset routine status ---
self.initialized = False
self.exec_time = 0.0
self.exit_code = 0
# --- reset symprocessor status ---
self._syms = False

Check warning on line 701 in ams/routines/routine.py

View check run for this annotation

Codecov / codecov/patch

ams/routines/routine.py#L701

Added line #L701 was not covered by tests
# --- reset optimization model status ---
self.om.initialized = False

Check warning on line 703 in ams/routines/routine.py

View check run for this annotation

Codecov / codecov/patch

ams/routines/routine.py#L703

Added line #L703 was not covered by tests

def addRParam(self,
name: str,
Expand Down Expand Up @@ -786,8 +791,9 @@ def addService(self,
model : str, optional
Model name.
"""
item = ValueService(name=name, value=value, tex_name=tex_name, unit=unit,
info=info, vtype=vtype, model=model)
item = ValueService(name=name, tex_name=tex_name,

Check warning on line 794 in ams/routines/routine.py

View check run for this annotation

Codecov / codecov/patch

ams/routines/routine.py#L794

Added line #L794 was not covered by tests
unit=unit, info=info,
vtype=vtype, value=value)
# add the service as an routine attribute
setattr(self, name, item)

Expand Down Expand Up @@ -1159,4 +1165,4 @@ def igraph(
default_name += f"\n${input.tex_name}$" + f" [${input.unit}$]"
ax.set_title(title if title else default_name, loc=title_loc)
ig.plot(g, autocurve=autocurve, target=ax, **vstyle)
return ax, g
return ax, g

Check warning on line 1168 in ams/routines/routine.py

View check run for this annotation

Codecov / codecov/patch

ams/routines/routine.py#L1168

Added line #L1168 was not covered by tests
1 change: 1 addition & 0 deletions docs/source/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ folder of the repository
../_examples/ex5.ipynb
../_examples/ex6.ipynb
../_examples/ex7.ipynb
../_examples/ex8.ipynb
Binary file added docs/source/getting_started/formats/xlsx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/source/getting_started/formats/xlsx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Format definition
The AMS xlsx format contains multiple workbooks (also known as "sheets") shown
as tabs at the bottom. The name of a workbook is a *model* name, and each
workbook contains the parameters of all *devices* that are *instances* of the
model.
model.
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ dynamic simulator ANDES.
release-notes
routineref
modelref
api
api
114 changes: 57 additions & 57 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-24 17:28:40\n",
"ams:0.8.5.post62.dev0+gf6ed683\n"
]
}
],
Expand Down Expand Up @@ -127,7 +127,7 @@
"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.2701 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"
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 0x1102ec910),\n",
" ('Bus', Bus (5 devices) at 0x11001f6a0),\n",
" ('PQ', PQ (3 devices) at 0x14cf7a490),\n",
" ('PV', PV (3 devices) at 0x137ae0100),\n",
" ('Slack', Slack (1 device) at 0x14cf7d610),\n",
" ('Shunt', Shunt (0 devices) at 0x14cfa14c0),\n",
" ('Line', Line (7 devices) at 0x14cfa1970),\n",
" ('PVD1', PVD1 (0 devices) at 0x14cfbb0a0),\n",
" ('ESD1', ESD1 (0 devices) at 0x14cfbb6a0),\n",
" ('REGCA1', REGCA1 (0 devices) at 0x14cfbbc10),\n",
" ('REGCV1', REGCV1 (0 devices) at 0x14cfc5250),\n",
" ('REGCV2', REGCV2 (0 devices) at 0x14cfc5a30),\n",
" ('Area', Area (3 devices) at 0x14cfc5f70),\n",
" ('Region', Region (2 devices) at 0x14cfd3730),\n",
" ('SFR', SFR (2 devices) at 0x14cfd3ee0),\n",
" ('SR', SR (2 devices) at 0x14cfde580),\n",
" ('NSR', NSR (2 devices) at 0x14cfde9a0),\n",
" ('VSGR', VSGR (0 devices) at 0x14cfdedc0),\n",
" ('GCost', GCost (4 devices) at 0x15e5de250),\n",
" ('SFRCost', SFRCost (4 devices) at 0x15e5de8e0),\n",
" ('SRCost', SRCost (4 devices) at 0x15e5dee80),\n",
" ('NSRCost', NSRCost (4 devices) at 0x15e5ec2e0),\n",
" ('VSGCost', VSGCost (0 devices) at 0x15e5ec700),\n",
" ('DCost', DCost (3 devices) at 0x15e5eca00),\n",
" ('TimeSlot', TimeSlot (0 devices) at 0x15e5ecf70),\n",
" ('EDTSlot', EDTSlot (24 devices) at 0x15e5f5a30),\n",
" ('UCTSlot', UCTSlot (24 devices) at 0x15e5f5e50)])"
]
},
"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 0x1102eb970),\n",
" ('PFlow', PFlow at 0x15e60d3a0),\n",
" ('CPF', CPF at 0x15e60d910),\n",
" ('ACOPF', ACOPF at 0x15e632a00),\n",
" ('DCOPF', DCOPF at 0x15e64f160),\n",
" ('ED', ED at 0x15e6901c0),\n",
" ('EDDG', EDDG at 0x15e688040),\n",
" ('EDES', EDES at 0x15e60ce50),\n",
" ('RTED', RTED at 0x15e6b8460),\n",
" ('RTEDDG', RTEDDG at 0x15e6b8520),\n",
" ('RTEDES', RTEDES at 0x15e6dbbb0),\n",
" ('RTEDVIS', RTEDVIS at 0x15e6ff940),\n",
" ('UC', UC at 0x162648400),\n",
" ('UCDG', UCDG at 0x16307a490),\n",
" ('UCES', UCES at 0x16309f3d0),\n",
" ('DOPF', DOPF at 0x1630c2dc0),\n",
" ('DOPFVIS', DOPFVIS at 0x1630e60d0)])"
]
},
"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.0139 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.0207 seconds, converged after 9 iterations using solver ECOS.\n"
]
},
{
Expand Down
Loading

0 comments on commit b48e82a

Please sign in to comment.