Skip to content

Commit

Permalink
Merge pull request #28 from jinningwang/doc
Browse files Browse the repository at this point in the history
Improve examples
  • Loading branch information
jinningwang authored Jan 24, 2024
2 parents b01e982 + b6db8c0 commit 85c03eb
Show file tree
Hide file tree
Showing 15 changed files with 609 additions and 236 deletions.
37 changes: 21 additions & 16 deletions .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

jobs:
build:

name: AMS Tests
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
Expand All @@ -13,29 +13,34 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up Python 3.9
uses: actions/setup-python@v1
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: 3.9
- name: Install dependencies
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: |
# work around a pip issue with extras_require: https://github.com/pypa/pip/issues/8323
python -m pip install -U "pip @ git+https://github.com/pypa/pip.git"
python -m pip install --upgrade pip
python -m pip install .[all]
python -m pip install nbmake==0.10 pytest-xdist line_profiler # add'l packages for notebook tests.
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 .
# - name: Lint with flake8 for pull requests
# if: github.event_name == 'pull_request'
# run: |
# # stop the build if there are Python syntax errors or undefined names
# flake8 .
- name: Test with pytest
- shell: bash -el {0}
name: Test with pytest
run: |
pytest --log-cli-level=10
# - name: Test notebooks.
# run: |
# pytest --log-cli-level=10 --nbmake examples --ignore=examples/verification
pytest
- shell: bash -el {0}
name: Test notebooks.
run: |
pytest --nbmake examples --ignore=examples/demonstration
# - name: Build a distribution if tagged
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
# run: |
Expand Down
16 changes: 12 additions & 4 deletions ams/io/matpower.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def mpc2system(mpc: dict, system) -> bool:
mpc_gen[:, :10] = mpc['gen']
mbase = base_mva
mpc_gen[:, 16] = system.PV.Ragc.default * mbase / 60
mpc_gen[:, 17] = system.PV.R10.default * mbase / 6
mpc_gen[:, 18] = system.PV.R30.default * mbase / 2
mpc_gen[:, 17] = system.PV.R10.default * mbase
mpc_gen[:, 18] = system.PV.R30.default * mbase
mpc_gen[:, 19] = system.PV.Rq.default * mbase / 60
else:
mpc_gen = mpc['gen']
Expand Down Expand Up @@ -123,8 +123,8 @@ def mpc2system(mpc: dict, system) -> bool:
qc2min = data[14] / mbase
qc2max = data[15] / mbase
ramp_agc = 60 * data[16] / mbase # from MW/min to MW/h
ramp_10 = 6 * data[17] / mbase # from MW/10min to MW/h
ramp_30 = 2 * data[18] / mbase # from MW/30min to MW/h
ramp_10 = data[17] / mbase # from MW to MW/h
ramp_30 = data[18] / mbase # from MW to MW/h
ramp_q = 60 * data[19] / mbase # from MVAr/min to MVAr/h
apf = data[20]

Expand Down Expand Up @@ -341,6 +341,10 @@ def system2mpc(system) -> dict:
gen[system.Slack.n:, 7] = PV.u.v
gen[system.Slack.n:, 8] = (PV.ctrl.v * PV.pmax.v + (1 - PV.ctrl.v) * PV.pmax.v) * base_mva
gen[system.Slack.n:, 9] = (PV.ctrl.v * PV.pmin.v + (1 - PV.ctrl.v) * PV.pmin.v) * base_mva
gen[system.Slack.n:, 16] = PV.Ragc.v * base_mva * 60 # from MW/h to MW/min
gen[system.Slack.n:, 17] = PV.R10.v * base_mva
gen[system.Slack.n:, 18] = PV.R30.v * base_mva
gen[system.Slack.n:, 19] = PV.Rq.v * base_mva * 60 # from MVAr/h to MVAr/min

# --- Slack ---
if system.Slack.n > 0:
Expand All @@ -358,6 +362,10 @@ def system2mpc(system) -> dict:
gen[:system.Slack.n, 7] = system.Slack.u.v
gen[:system.Slack.n, 8] = system.Slack.pmax.v * base_mva
gen[:system.Slack.n, 9] = system.Slack.pmin.v * base_mva
gen[:system.Slack.n, 16] = system.Slack.Ragc.v * base_mva * 60 # from MW/h to MW/min
gen[:system.Slack.n, 17] = system.Slack.R10.v * base_mva
gen[:system.Slack.n, 18] = system.Slack.R30.v * base_mva
gen[:system.Slack.n, 19] = system.Slack.Rq.v * base_mva * 60 # from MVAr/h to MVAr/min

if system.Line.n > 0:
branch = mpc['branch']
Expand Down
4 changes: 2 additions & 2 deletions ams/routines/ed.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def __init__(self) -> None:

self.R30 = RParam(info='30-min ramp rate',
name='R30', tex_name=r'R_{30}',
src='R30', unit='p.u./min',
src='R30', unit='p.u./h',
model='StaticGen', no_parse=True,)
self.Mr = RampSub(u=self.pg, name='Mr', tex_name=r'M_{r}',
info='Subtraction matrix for ramping',
Expand Down Expand Up @@ -210,7 +210,7 @@ def __init__(self, system, config):
# constant cost
cost += '+ sum(mul(ugt, mul(c0, tlv)))'
# spinning reserve cost
cost += ' + sum(csr@prs)'
cost += ' + sum(csr@(t dot prs))'
self.obj.e_str = cost

def _post_solve(self):
Expand Down
13 changes: 0 additions & 13 deletions ams/routines/routine.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,6 @@ def __init__(self, system=None, config=None):

if config is not None:
self.config.load(config)
# TODO: these default configs might to be revised
self.config.add(
OrderedDict((
("sparselib", "klu"),
)
)
)
self.config.add_extra(
"_help", sparselib="linear sparse solver name",
)
self.config.add_extra(
"_alt", sparselib=("klu", "umfpack", "spsolve", "cupy"),
)

self.exec_time = 0.0 # recorded time to execute the routine in seconds
# TODO: check exit_code of gurobipy or any other similiar solvers
Expand Down
4 changes: 2 additions & 2 deletions ams/routines/rted.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def __init__(self, system, config):
self.obj.info = 'total generation and reserve cost'
# NOTE: the product of dt and pg is processed using ``dot``,
# because dt is a numnber
cost = 'sum(mul(c2, power(pg, 2)))'
cost = 'sum(mul(c2, power(t dot pg, 2)))'
cost += '+ sum(c1 @ (t dot pg))'
cost += '+ ug * c0' # constant cost
cost += '+ sum(cru * pru + crd * prd)' # reserve cost
Expand Down Expand Up @@ -545,7 +545,7 @@ def __init__(self, system, config):
gcost = 'sum(mul(c2, power(pg, 2)))'
gcost += '+ sum(c1 @ (t dot pg))'
gcost += '+ ug * c0 ' # constant cost
rcost = '+ sum(cru * pru + crd * prd) ' # reserve cost
rcost = '+ sum(cru * (t dot pru) + crd * (t dot prd)) ' # reserve cost
vsgcost = '+ sum(cm * M + cd * D)'
self.obj.e_str = gcost + rcost + vsgcost

Expand Down
5 changes: 5 additions & 0 deletions docs/source/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ The APIs before v3.0.0 are in beta and may change without prior notice.
Pre-v1.0.0
==========

v0.8.2 (2024-01-xx)
-------------------

- Improve examples

v0.8.1 (2024-01-20)
-------------------

Expand Down
Loading

0 comments on commit 85c03eb

Please sign in to comment.