Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc #100

Merged
merged 96 commits into from
Nov 23, 2024
Merged

Misc #100

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
ff9ec5d
[WIP] PFlow, write formulation
jinningwang Nov 15, 2024
fc073da
Add a test of profile run
jinningwang Nov 15, 2024
390d530
Add more tests on OModel __repr__
jinningwang Nov 15, 2024
291b816
Add more tests on cli
jinningwang Nov 15, 2024
e5ddf1d
[WIP] PFlow, fix its type
jinningwang Nov 15, 2024
5957a68
Update project README to clarify we use CVXPY to handle optimization …
jinningwang Nov 15, 2024
f87e66f
Clarify that MatProcessor has taken devices connectivity into account
jinningwang Nov 15, 2024
512a014
Remove RParam uqp from DCOPF
jinningwang Nov 15, 2024
a393857
Clarify ExpressionCalc
jinningwang Nov 15, 2024
d5be8ce
[WIP] PFlow, formulation
jinningwang Nov 15, 2024
4885eed
Add a new omodel atom type Expression, which is different from Expres…
jinningwang Nov 15, 2024
20b0a3e
Refactor class ExpressionCalc for efficiency
jinningwang Nov 15, 2024
944516e
Fix RDocumenter for ExpressionCalc
jinningwang Nov 15, 2024
3b9e23b
Update release notes
jinningwang Nov 15, 2024
551b9da
Include demo_debug in documentation
jinningwang Nov 15, 2024
e9fe1fb
Fix documenter for ExpressionCalc
jinningwang Nov 15, 2024
82805f7
Typo
jinningwang Nov 15, 2024
4857875
Format
jinningwang Nov 15, 2024
8f1cecf
Format
jinningwang Nov 15, 2024
4c403c0
Add method for easier usage
jinningwang Nov 15, 2024
04e6f41
Move constants _prefix and _max_length from module omodel to shared
jinningwang Nov 15, 2024
d128277
Refactor module opt
jinningwang Nov 15, 2024
beaeb40
Update release notes
jinningwang Nov 15, 2024
a1b1b50
Typo
jinningwang Nov 15, 2024
f8d4770
Typo
jinningwang Nov 15, 2024
4676445
Typo
jinningwang Nov 16, 2024
528c9b7
Typo
jinningwang Nov 16, 2024
233557f
Add exp to val_map replacement
jinningwang Nov 16, 2024
89b2d72
Add more attributes to class Expression
jinningwang Nov 16, 2024
6686232
Add docstring to class Expression
jinningwang Nov 16, 2024
e69687c
[WIP] PFlow2, add complex bus voltage using Expression
jinningwang Nov 16, 2024
d26e677
Fix class Expression usage
jinningwang Nov 16, 2024
6de04ae
Refactor DCOPF line flow constraints using Expression
jinningwang Nov 16, 2024
3dbfd4f
Include class Expression in documenter
jinningwang Nov 16, 2024
7471a0e
Refactor DCOPF generator power limits using Expression
jinningwang Nov 16, 2024
a6e0990
Typo
jinningwang Nov 16, 2024
09bc28b
Refactor ED pg limits using Expression
jinningwang Nov 16, 2024
761ad85
Refactor UC pg limits using Expression
jinningwang Nov 16, 2024
8034bb2
Use in-place assign for class Expression._v
jinningwang Nov 16, 2024
2987977
Rename file expr to expression for calrity
jinningwang Nov 16, 2024
a8b9a98
Fix symprocessor sub_map and val_map for Expression when no_parse
jinningwang Nov 16, 2024
54df059
[WIP] PFlow2, formulation
jinningwang Nov 16, 2024
4279dfd
[WIP] PFlow2, formulation
jinningwang Nov 16, 2024
3b6991f
[WIP] PFlow2, formulation
jinningwang Nov 16, 2024
17b4c06
Add a module nlopt for non-linear problems
jinningwang Nov 16, 2024
b149fa7
Remove unused files
jinningwang Nov 16, 2024
16b9ba1
Rename file pfopt to pfmodel for clarity
jinningwang Nov 16, 2024
9a52c05
[WIP] PFlow2, solver outline
jinningwang Nov 16, 2024
1899e67
[WIP] PFlow2, minor change
jinningwang Nov 16, 2024
a6bd8b4
Add Expression into syms.val_map
jinningwang Nov 16, 2024
9243ebb
Minor refactor
jinningwang Nov 17, 2024
7899363
Docstring
jinningwang Nov 17, 2024
7d47cbe
Remove no_parse option for class Expression
jinningwang Nov 17, 2024
93f1668
Update release notes
jinningwang Nov 17, 2024
b2c7f50
Remove module ams.opt.pfmodel
jinningwang Nov 22, 2024
4b0ab69
Refactor func to_andes
jinningwang Nov 22, 2024
ea25c96
Fix ams.interface._to_andes_pflow kwargs
jinningwang Nov 22, 2024
d5e38fc
[WIP] PFlow2, draft using ANDES PFlow routine
jinningwang Nov 22, 2024
76fdf8f
Initialize RoutineBase.om as OModel
jinningwang Nov 22, 2024
d81e36e
In ams.main.config_logger, set ANDES using the same streaming level
jinningwang Nov 22, 2024
b47fbc7
Minor enhancement on ams.report.write
jinningwang Nov 22, 2024
5bf77f9
PFlow2, interface ANDES PFlow routine
jinningwang Nov 22, 2024
5eaae11
[WIP] DCPF
jinningwang Nov 22, 2024
9eb8f31
Switch from PYPOWER PFlow to ANDES PFlow
jinningwang Nov 22, 2024
924b7ff
Rename func _sync_adsys as sync_adsys
jinningwang Nov 22, 2024
2df2927
Typo
jinningwang Nov 22, 2024
635cc1a
Skip sutogen_stale when instantiating an example ANDES system
jinningwang Nov 22, 2024
6d6f3d2
Adapt module omodel for PFlow
jinningwang Nov 22, 2024
2c9329f
Temp alleviate DCPF init
jinningwang Nov 22, 2024
fccfb7f
Typo
jinningwang Nov 23, 2024
f218b6a
Draft DCPF using CVXPY
jinningwang Nov 23, 2024
238bd76
[WIP] In DCPF, switch from PYPOWER to CVXPY
jinningwang Nov 23, 2024
1f8a084
Typo
jinningwang Nov 23, 2024
5778f2d
Typo
jinningwang Nov 23, 2024
b597b47
Typo
jinningwang Nov 23, 2024
d3ce6a7
Add place holder obj for PFlow routine
jinningwang Nov 23, 2024
ade36cb
Add deprecation notice in DCPF0 and PFlow0
jinningwang Nov 23, 2024
94c81ac
In Documenter, set Srouce to be owner if there is no src
jinningwang Nov 23, 2024
ff80200
In Documenter, set Srouce to be owner if there is no src
jinningwang Nov 23, 2024
bfea3d8
Typo
jinningwang Nov 23, 2024
bdb3401
Format
jinningwang Nov 23, 2024
0fde998
Refactor DCPF and DCOPF
jinningwang Nov 23, 2024
6635382
Typo
jinningwang Nov 23, 2024
15611e5
Typo
jinningwang Nov 23, 2024
4b54628
Update release notes
jinningwang Nov 23, 2024
5efcf8c
Typo
jinningwang Nov 23, 2024
6b210bf
Specify multiprocess<=0.70.16 in requirements as 0.70.17 run into err…
jinningwang Nov 23, 2024
e46c2e0
Format
jinningwang Nov 23, 2024
e57dff1
Format
jinningwang Nov 23, 2024
b72a571
Format
jinningwang Nov 23, 2024
12676ec
Refactor ExpressionCalc and Expression __repr__ to reduce duplication
jinningwang Nov 23, 2024
3c28bb2
Format
jinningwang Nov 23, 2024
50efe15
Format
jinningwang Nov 23, 2024
96c3ebf
Typo
jinningwang Nov 23, 2024
5c1b47f
Remove implementation of DCOPF.dc2ac
jinningwang Nov 23, 2024
d8c7b38
Minor fix
jinningwang Nov 23, 2024
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ Python Software for Power System Scheduling Modeling and Co-Simulation with Dyna

# Why AMS

With the built-in interface with dynamic simulation engine, ANDES, AMS enables Dynamics Interfaced Stability Constrained Production Cost and Market Operation Modeling.
With the built-in interface with ANDES, AMS enables **Dynamics Incorporated Stability-Constrained Scheduling**.

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.

AMS produces credible scheduling results and competitive performance.
The following results show the comparison of DCOPF between AMS and other tools.
Expand Down
3 changes: 2 additions & 1 deletion ams/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from . import _version
__version__ = _version.get_versions()['version']

from ams import opt # NOQA
from ams import benchmarks # NOQA

from ams.main import config_logger, load, run # NOQA
Expand All @@ -10,4 +11,4 @@

__author__ = 'Jining Wang'

__all__ = ['System', 'get_case', 'System']
__all__ = ['System', 'get_case']
80 changes: 74 additions & 6 deletions ams/core/documenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@
# add tables
self.parent.syms.generate_symbols()
out += self._obj_doc(max_width=max_width, export=export)
out += self._constr_doc(max_width=max_width, export=export)
out += self._expr_doc(max_width=max_width, export=export)
out += self._constr_doc(max_width=max_width, export=export)
out += self._var_doc(max_width=max_width, export=export)
out += self._exprc_doc(max_width=max_width, export=export)
out += self._service_doc(max_width=max_width, export=export)
out += self._param_doc(max_width=max_width, export=export)
out += self.config.doc(max_width=max_width, export=export)
Expand Down Expand Up @@ -316,17 +317,26 @@
rest_dict=rest_dict)

def _expr_doc(self, max_width=78, export='plain'):
# expression documentation
# Expression documentation
if len(self.parent.exprs) == 0:
return ''

# prepare temporary lists
names, var_names, info = list(), list(), list()
names, info = list(), list()
units, sources, units_rest = list(), list(), list()

for p in self.parent.exprs.values():
names.append(p.name)
var_names.append(p.var)
info.append(p.info if p.info else '')
units.append(p.unit if p.unit else '')
units_rest.append(f'*{p.unit}*' if p.unit else '')

slist = []
if p.owner is not None and p.src is not None:
slist.append(f'{p.owner.class_name}.{p.src}')

Check warning on line 336 in ams/core/documenter.py

View check run for this annotation

Codecov / codecov/patch

ams/core/documenter.py#L336

Added line #L336 was not covered by tests
elif p.owner is not None and p.src is None:
slist.append(f'{p.owner.class_name}')
sources.append(','.join(slist))

# expressions based on output format
expressions = []
Expand All @@ -342,13 +352,67 @@
expressions = math_wrap(expressions, export=export)

plain_dict = OrderedDict([('Name', names),
('Variable', var_names),
('Description', info),
('Unit', units),
])
rest_dict = OrderedDict([('Name', names),
('Description', info),
('Expression', expressions),
('Unit', units_rest),
('Source', sources),
])

# convert to rows and export as table
return make_doc_table(title=title,
max_width=max_width,
export=export,
plain_dict=plain_dict,
rest_dict=rest_dict)

def _exprc_doc(self, max_width=78, export='plain'):
# ExpressionCalc documentation
if len(self.parent.exprcs) == 0:
return ''

# prepare temporary lists
names, info = list(), list()
units, sources, units_rest = list(), list(), list()

for p in self.parent.exprcs.values():
names.append(p.name)
info.append(p.info if p.info else '')
units.append(p.unit if p.unit else '')
units_rest.append(f'*{p.unit}*' if p.unit else '')

slist = []
if p.owner is not None and p.src is not None:
slist.append(f'{p.owner.class_name}.{p.src}')

Check warning on line 389 in ams/core/documenter.py

View check run for this annotation

Codecov / codecov/patch

ams/core/documenter.py#L389

Added line #L389 was not covered by tests
elif p.owner is not None and p.src is None:
slist.append(f'{p.owner.class_name}')
sources.append(','.join(slist))

# expressions based on output format
expressions = []
if export == 'rest':
for p in self.parent.exprcs.values():
expr = _tex_pre(self, p, self.parent.syms.tex_map)
logger.debug(f'{p.name} math: {expr}')
expressions.append(expr)

title = 'ExpressionCalcs\n----------------------------------'
else:
title = 'ExpressionCalcs'
expressions = math_wrap(expressions, export=export)

plain_dict = OrderedDict([('Name', names),
('Description', info),
('Unit', units),
])
rest_dict = OrderedDict([('Name', names),
('Variable', var_names),
('Description', info),
('Expression', expressions),
('Unit', units_rest),
('Source', sources),
])

# convert to rows and export as table
Expand Down Expand Up @@ -423,6 +487,8 @@
slist = []
if p.owner is not None and p.src is not None:
slist.append(f'{p.owner.class_name}.{p.src}')
elif p.owner is not None and p.src is None:
slist.append(f'{p.owner.class_name}')
sources.append(','.join(slist))

# symbols based on output format
Expand Down Expand Up @@ -490,6 +556,8 @@
slist = []
if p.owner is not None and p.src is not None:
slist.append(f'{p.owner.class_name}.{p.src}')
elif p.owner is not None and p.src is None:
slist.append(f'{p.owner.class_name}')

Check warning on line 560 in ams/core/documenter.py

View check run for this annotation

Codecov / codecov/patch

ams/core/documenter.py#L559-L560

Added lines #L559 - L560 were not covered by tests
sources.append(','.join(slist))

# symbols based on output format
Expand Down
6 changes: 4 additions & 2 deletions ams/core/matprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from andes.shared import tqdm, tqdm_nb
from andes.utils.misc import elapsed, is_notebook

from ams.opt.omodel import Param
from ams.opt import Param
from ams.shared import pd, sps

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -140,7 +140,9 @@ def class_name(self):

class MatProcessor:
"""
Class for matrix processing in AMS system.
Class for matrices processing in AMS system.
The connectivity matrices `Cft`, `Cg`, `Cl`, and `Csh` ***have taken*** the
devices connectivity into account.

The MParams' row names and col names are assigned in `System.setup()`.
"""
Expand Down
2 changes: 1 addition & 1 deletion ams/core/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import numpy as np
from scipy.sparse import issparse

from ams.opt.omodel import Param
from ams.opt import Param

logger = logging.getLogger(__name__)

Expand Down
66 changes: 43 additions & 23 deletions ams/core/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from andes.core.service import BaseService

from ams.opt.omodel import Param
from ams.opt import Param


logger = logging.getLogger(__name__)
Expand All @@ -33,8 +33,6 @@ class RBaseService(BaseService, Param):
Description.
vtype : Type, optional
Variable type.
model : str, optional
Model name.
no_parse: bool, optional
True to skip parsing the service.
sparse: bool, optional
Expand Down Expand Up @@ -106,8 +104,8 @@ class ValueService(RBaseService):
Description.
vtype : Type, optional
Variable type.
model : str, optional
Model name.
no_parse: bool, optional
True to skip parsing the service.
sparse: bool, optional
True to return output as scipy csr_matrix.
"""
Expand Down Expand Up @@ -155,8 +153,8 @@ class ROperationService(RBaseService):
Description.
vtype : Type, optional
Variable type.
model : str, optional
Model name.
no_parse: bool, optional
True to skip parsing the service.
sparse: bool, optional
True to return output as scipy csr_matrix.
"""
Expand Down Expand Up @@ -194,6 +192,8 @@ class LoadScale(ROperationService):
Unit.
info : str, optional
Description.
no_parse: bool, optional
True to skip parsing the service.
sparse: bool, optional
True to return output as scipy csr_matrix.
"""
Expand Down Expand Up @@ -236,7 +236,7 @@ class NumOp(ROperationService):

Note that the scalar output is converted to a 1D array.

The optional kwargs are passed to the input function.
The `rargs` are passed to the input function.

Parameters
----------
Expand Down Expand Up @@ -397,8 +397,6 @@ class NumOpDual(NumOp):
Description.
vtype : Type, optional
Variable type.
model : str, optional
Model name.
rfun : Callable, optional
Function to apply to the output of ``fun``.
rargs : dict, optional
Expand All @@ -407,6 +405,8 @@ class NumOpDual(NumOp):
Expand the dimensions of the output array along a specified axis.
array_out : bool, optional
Whether to force the output to be an array.
no_parse: bool, optional
True to skip parsing the service.
sparse: bool, optional
True to return output as scipy csr_matrix.
"""
Expand Down Expand Up @@ -467,6 +467,10 @@ class MinDur(NumOpDual):
Unit.
info : str, optional
Description.
vtype : Type, optional
Variable type.
no_parse: bool, optional
True to skip parsing the service.
sparse: bool, optional
True to return output as scipy csr_matrix.
"""
Expand Down Expand Up @@ -537,8 +541,12 @@ class NumHstack(NumOp):
Description.
vtype : Type, optional
Variable type.
model : str, optional
Model name.
rfun : Callable, optional
Function to apply to the output of ``fun``.
rargs : dict, optional
Keyword arguments to pass to ``rfun``.
no_parse: bool, optional
True to skip parsing the service.
sparse: bool, optional
True to return output as scipy csr_matrix.
"""
Expand Down Expand Up @@ -624,8 +632,12 @@ class ZonalSum(NumOp):
Description.
vtype : Type
Variable type.
model : str
Model name.
rfun : Callable, optional
Function to apply to the output of ``fun``.
rargs : dict, optional
Keyword arguments to pass to ``rfun``.
no_parse: bool, optional
True to skip parsing the service.
sparse: bool, optional
True to return output as scipy csr_matrix.
"""
Expand Down Expand Up @@ -676,7 +688,7 @@ class VarSelect(NumOp):
A numerical matrix to select a subset of a 2D variable,
``u.v[:, idx]``.

For example, if nned to select Energy Storage output
For example, if need to select Energy Storage output
power from StaticGen `pg`, following definition can be used:
```python
class RTED:
Expand Down Expand Up @@ -709,6 +721,8 @@ class RTED:
Keyword arguments to pass to ``rfun``.
array_out : bool, optional
Whether to force the output to be an array.
no_parse: bool, optional
True to skip parsing the service.
sparse: bool, optional
True to return output as scipy csr_matrix.
"""
Expand Down Expand Up @@ -801,8 +815,12 @@ class VarReduction(NumOp):
A description of the operation.
vtype : Type, optional
The variable type.
model : str, optional
The model name associated with the operation.
rfun : Callable, optional
Function to apply to the output of ``fun``.
rargs : dict, optional
Keyword arguments to pass to ``rfun``.
no_parse: bool, optional
True to skip parsing the service.
sparse: bool, optional
True to return output as scipy csr_matrix.
"""
Expand All @@ -818,13 +836,11 @@ def __init__(self,
rfun: Callable = None,
rargs: dict = None,
no_parse: bool = False,
sparse: bool = False,
**kwargs):
sparse: bool = False,):
super().__init__(name=name, tex_name=tex_name, unit=unit,
info=info, vtype=vtype,
u=u, fun=None, rfun=rfun, rargs=rargs,
no_parse=no_parse, sparse=sparse,
**kwargs)
no_parse=no_parse, sparse=sparse,)
self.fun = fun

@property
Expand Down Expand Up @@ -859,8 +875,12 @@ class RampSub(NumOp):
Description.
vtype : Type
Variable type.
model : str
Model name.
rfun : Callable, optional
Function to apply to the output of ``fun``.
rargs : dict, optional
Keyword arguments to pass to ``rfun``.
no_parse: bool, optional
True to skip parsing the service.
sparse: bool, optional
True to return output as scipy csr_matrix.
"""
Expand Down
Loading
Loading