Skip to content

Commit

Permalink
Merge pull request #108 from CURENT/develop
Browse files Browse the repository at this point in the history
Prep for v0.9.13
  • Loading branch information
jinningwang authored Dec 5, 2024
2 parents 377b36f + c665d88 commit 2337538
Show file tree
Hide file tree
Showing 34 changed files with 2,194 additions and 648 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# LTB AMS

Python Software for Power System Scheduling Modeling and Co-Simulation with Dynanic, serving as the market simulator for the [CURENT Largescale Testbed][LTB Repository].
Python Software for Power System Scheduling Modeling and Co-Simulation with Dynamics, serving as the market simulator for the [CURENT Largescale Testbed][LTB Repository].

[![License: GPL-3.0](https://img.shields.io/badge/License-GPL--3.0-blue.svg)](https://github.com/CURENT/ams/blob/master/LICENSE)
![platforms](https://anaconda.org/conda-forge/ltbams/badges/platforms.svg)
[![Python Versions](https://img.shields.io/badge/Python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)](https://www.python.org/)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
![Repo Size](https://img.shields.io/github/repo-size/CURENT/ams)
[![GitHub last commit (master)](https://img.shields.io/github/last-commit/CURENT/ams/master?label=last%20commit%20to%20master)](https://github.com/CURENT/ams/commits/master/)
[![GitHub last commit (develop)](https://img.shields.io/github/last-commit/CURENT/ams/develop?label=last%20commit%20to%20develop)](https://github.com/CURENT/ams/commits/develop/)
Expand All @@ -31,6 +32,10 @@ Python Software for Power System Scheduling Modeling and Co-Simulation with Dyna
With the built-in interface with ANDES, AMS enables **Dynamics Incorporated**
**Stability-Constrained Scheduling**.

This package can be helpful for power system engineers, researchers, and students
who need to conduct scheduling studies and transient stability studies at given
operating points.

AMS is a **Modeling Framework** that provides a descriptive way to formulate
scheduling problems. The optimization problems are then handled by **CVXPY**
and solved with third-party solvers.
Expand Down Expand Up @@ -67,6 +72,7 @@ Use the following resources to get involved.
- Version **0.9.9** has known issues and has been yanked from PyPI
- `kvxopt` is recommended to install via `conda` as sometimes ``pip`` struggles to set the correct path for compiled libraries
- `cvxpy` versions **below 1.5** are incompatible with `numpy` versions **2.0 and above**
- If solver `SCIP` run into import error, try to reinstall its Python interface by running `pip install pyscipopt --no-binary scip --force`

AMS is released as ``ltbams`` on PyPI and conda-forge.
Install from PyPI using pip:
Expand All @@ -89,15 +95,22 @@ pip install git+https://github.com/CURENT/ams.git

# Example Usage

Using AMS to run a Real-Time Economic Dispatch (RTED) simulation:

```python
import ams

ss = ams.load(ams.get_case('ieee14_uced.xlsx'))
ss.RTED.run()
ss = ams.load(ams.get_case('ieee14/ieee14_uced.xlsx'))

# solve RTED
ss.RTED.run(solver='CLARABEL')

ss.RTED.pg.v
>>> array([1.8743862, 0.3226138, 0.01 , 0.02 , 0.01 ])

print(ss.RTED.pg.v)
# convert to ANDES case
sa = ss.to_andes(addfile=andes.get_case('ieee14/ieee14_full.xlsx'),
setup=True, verify=False)
sa
>>> <andes.system.System at 0x14bd98190>
```

# Sponsors and Contributors
Expand Down
Binary file modified ams/cases/5bus/pjm5bus_demo.xlsx
Binary file not shown.
48 changes: 46 additions & 2 deletions ams/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def sync_adsys(amsys, adsys):
ad_mdl.set(src=param, attr='v', idx=idx,
value=am_mdl.get(src=param, attr='v', idx=idx))
except Exception:
logger.debug(f"Skip updating {mname}.{param}")
continue
return True

Expand Down Expand Up @@ -333,6 +332,27 @@ def parse_addfile(adsys, amsys, addfile):
df[idxn] = df[idxn].replace(idx_map[mdl_guess])
logger.debug(f'Adjust {idxp.class_name} <{name}.{idxp.name}>')

# NOTE: Group TimedEvent needs special treatment
# adjust Toggle and Fault models
toggle_df = df_models.get('Toggle') or df_models.get('Toggler')
if toggle_df is not None:
toggle_df['dev'] = toggle_df.apply(replace_dev, axis=1,
mdl='model', dev='dev',
idx_map=idx_map)

alter_df = df_models.get('Alter')
if alter_df is not None:
alter_df['dev'] = alter_df.apply(replace_dev, axis=1,
mdl='model', dev='dev',
idx_map=idx_map)

# adjust Fault model
fault_df = df_models.get('Fault')
if fault_df is not None:
fault_df['bus'] = fault_df.apply(replace_dev, axis=1,
mdl='bus', dev='bus',
idx_map=idx_map)

# add dynamic models
for name, df in df_models.items():
# drop rows that all nan
Expand Down Expand Up @@ -966,7 +986,7 @@ def make_link_table(adsys):
right=ssa_rg[['stg_idx', 'rg_idx']])

# NOTE: use this instead of fillna to avoid type conversion
idxc = ['stg_idx', 'syg_idx', 'dg_idx', 'rg_idx']
idxc = ['syg_idx', 'dg_idx', 'rg_idx']
ssa_key0[idxc] = ssa_key0[idxc].astype('str').replace({'nan': ''}).astype('bool')

dyr = ssa_key0['syg_idx'] + ssa_key0['dg_idx'] + ssa_key0['rg_idx']
Expand Down Expand Up @@ -1037,3 +1057,27 @@ def verify_pf(amsys, adsys, tol=1e-3):
logger.warning(msg)
logger.warning(diff_msg)
return check


def replace_dev(row, mdl, dev, idx_map):
"""
Replace the device idx in the row based on the idx_map.
Parameters
----------
row : pd.Series
The row of the DataFrame.
mdl : str
The column name for the Model.
dev : str
The column name for the Device idx.
idx_map : dict
The index map for replacement.
Returns
-------
str
The new device idx.
"""
old_idx = row[dev]
return idx_map.get(row[mdl], {}).get(old_idx, old_idx)
Loading

0 comments on commit 2337538

Please sign in to comment.