ltbams 1.0.4__py3-none-any.whl → 1.0.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ams/_version.py CHANGED
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2025-04-05T23:02:48-0400",
11
+ "date": "2025-04-10T23:17:16-0400",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "af7a4e10ba2e35c4180562cf62f69ba5523c6725",
15
- "version": "1.0.4"
14
+ "full-revisionid": "3dbdbfee9ce8361b7975c9333179b88c01560137",
15
+ "version": "1.0.6"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
ams/io/matpower.py CHANGED
@@ -203,6 +203,13 @@ def mpc2system(mpc: dict, system) -> bool:
203
203
  gcost_idx = 0
204
204
  gen_idx = np.arange(mpc['gen'].shape[0]) + 1
205
205
  mpc_cost = mpc['gencost']
206
+ if mpc_cost[0, 0] == 1:
207
+ logger.warning("Type 1 gencost detected. "
208
+ "This is not supported in AMS. "
209
+ "Default type 2 cost parameters will be used as a fallback."
210
+ "It is recommended to manually convert the gencost data to type 2.")
211
+ mpc_cost = np.repeat(np.array([[2, 0, 0, 3, 0, 0, 0]]),
212
+ mpc_cost.shape[0], axis=0)
206
213
  for data, gen in zip(mpc_cost, gen_idx):
207
214
  # NOTE: only type 2 costs are supported for now
208
215
  # type startup shutdown n c2 c1 c0
ams/models/cost.py CHANGED
@@ -100,6 +100,7 @@ class SRCost(ModelData, Model):
100
100
  def __init__(self, system, config):
101
101
  ModelData.__init__(self)
102
102
  Model.__init__(self, system, config)
103
+ self.group = 'Cost'
103
104
  self.gen = IdxParam(info="static generator index",
104
105
  model='StaticGen',
105
106
  mandatory=True,)
@@ -116,6 +117,7 @@ class NSRCost(ModelData, Model):
116
117
  def __init__(self, system, config):
117
118
  ModelData.__init__(self)
118
119
  Model.__init__(self, system, config)
120
+ self.group = 'Cost'
119
121
  self.gen = IdxParam(info="static generator index",
120
122
  model='StaticGen',
121
123
  mandatory=True,)
ams/opt/exprcalc.py CHANGED
@@ -8,6 +8,8 @@ import re
8
8
 
9
9
  import numpy as np
10
10
 
11
+ from ams.shared import sps # NOQA
12
+
11
13
  import cvxpy as cp
12
14
 
13
15
  from ams.utils import pretty_long_message
@@ -68,7 +70,7 @@ class ExpressionCalc(OptzBase):
68
70
  msg = f" - Expression <{self.name}>: {self.code}"
69
71
  logger.debug(pretty_long_message(msg, _prefix, max_length=_max_length))
70
72
  try:
71
- local_vars = {'self': self, 'np': np, 'cp': cp}
73
+ local_vars = {'self': self, 'np': np, 'cp': cp, 'sps': sps}
72
74
  self.optz = self._evaluate_expression(self.code, local_vars=local_vars)
73
75
  except Exception as e:
74
76
  raise Exception(f"Error in evaluating ExpressionCalc <{self.name}>.\n{e}")
ams/routines/__init__.py CHANGED
@@ -11,6 +11,7 @@ all_routines = OrderedDict([
11
11
  ('cpf', ['CPF']),
12
12
  ('acopf', ['ACOPF']),
13
13
  ('dcopf', ['DCOPF']),
14
+ ('dcopf2', ['DCOPF2']),
14
15
  ('ed', ['ED', 'EDDG', 'EDES']),
15
16
  ('rted', ['RTED', 'RTEDDG', 'RTEDES', 'RTEDVIS']),
16
17
  ('uc', ['UC', 'UCDG', 'UCES']),
ams/routines/dcopf.py CHANGED
@@ -19,13 +19,17 @@ class DCOPF(DCPFBase):
19
19
  """
20
20
  DC optimal power flow (DCOPF).
21
21
 
22
- The nodal price is calculated as ``pi`` in ``pic``.
22
+ Notes
23
+ -----
24
+ 1. The nodal price is calculated as ``pi`` in ``pic``.
25
+ 2. Devices online status of ``StaticGen``, ``StaticLoad``, and ``Shunt`` are considered in the connectivity
26
+ matrices ``Cft``, ``Cg``, ``Cl``, and ``Csh``.
23
27
 
24
28
  References
25
29
  ----------
26
- 1. R. D. Zimmerman, C. E. Murillo-Sanchez, and R. J. Thomas, “MATPOWER: Steady-State Operations, Planning, and
27
- Analysis Tools for Power Systems Research and Education,” IEEE Trans. Power Syst., vol. 26, no. 1, pp. 12–19,
28
- Feb. 2011
30
+ 1. R. D. Zimmerman, C. E. Murillo-Sanchez, and R. J. Thomas, “MATPOWER: Steady-State
31
+ Operations, Planning, and Analysis Tools for Power Systems Research and Education,” IEEE
32
+ Trans. Power Syst., vol. 26, no. 1, pp. 12-19, Feb. 2011
29
33
  """
30
34
 
31
35
  def __init__(self, system, config):
@@ -153,7 +157,7 @@ class DCOPF(DCPFBase):
153
157
  Parameters
154
158
  ----------
155
159
  kloss : float, optional
156
- The loss factor for the conversion. Defaults to 1.2.
160
+ The loss factor for the conversion. Defaults to 1.0.
157
161
  """
158
162
  exec_time = self.exec_time
159
163
  if self.exec_time == 0 or self.exit_code != 0:
ams/routines/dcopf2.py ADDED
@@ -0,0 +1,95 @@
1
+ """
2
+ DCOPF routines.
3
+ """
4
+ import logging
5
+
6
+ import numpy as np
7
+ from ams.core.param import RParam
8
+ from ams.core.service import NumOp
9
+
10
+ from ams.routines.dcopf import DCOPF
11
+ from ams.opt import ExpressionCalc
12
+
13
+ from ams.shared import sps
14
+
15
+
16
+ logger = logging.getLogger(__name__)
17
+
18
+
19
+ class DCOPF2(DCOPF):
20
+ """
21
+ DC optimal power flow (DCOPF) using PTDF.
22
+ For large cases, it is recommended to build the PTDF first, especially when incremental
23
+ build is necessary.
24
+
25
+ Notes
26
+ -----
27
+ 1. This routine requires PTDF matrix.
28
+ 2. Nodal price ``pi`` is calculated with three parts.
29
+ 3. Bus angle ``aBus`` is calculated after solving the problem.
30
+ """
31
+
32
+ def __init__(self, system, config):
33
+ DCOPF.__init__(self, system, config)
34
+ self.info = 'DCOPF using PTDF'
35
+ self.type = 'DCED'
36
+
37
+ # NOTE: in this way, we still follow the implementation that devices
38
+ # connectivity status is considered in connection matrix
39
+ self.ued = NumOp(u=self.Cl,
40
+ name='ued', tex_name=r'u_{e,d}',
41
+ info='Effective load connection status',
42
+ fun=np.sum, args=dict(axis=0),
43
+ no_parse=True)
44
+ self.uesh = NumOp(u=self.Csh,
45
+ name='uesh', tex_name=r'u_{e,sh}',
46
+ info='Effective shunt connection status',
47
+ fun=np.sum, args=dict(axis=0),
48
+ no_parse=True)
49
+
50
+ self.PTDF = RParam(info='PTDF',
51
+ name='PTDF', tex_name=r'P_{TDF}',
52
+ model='mats', src='PTDF',
53
+ no_parse=True, sparse=True)
54
+
55
+ # --- rewrite Expression plf: line flow---
56
+ self.plf.e_str = 'PTDF @ (Cg@pg - Cl@pd - Csh@gsh - Pbusinj)'
57
+
58
+ # --- rewrite nodal price ---
59
+ self.Cft = RParam(info='Line connection matrix',
60
+ name='Cft', tex_name=r'C_{ft}',
61
+ model='mats', src='Cft',
62
+ no_parse=True, sparse=True,)
63
+ self.pilb = ExpressionCalc(info='Congestion price, dual of <plflb>',
64
+ name='pilb',
65
+ model='Line', src=None,
66
+ e_str='plflb.dual_variables[0]')
67
+ self.piub = ExpressionCalc(info='Congestion price, dual of <plfub>',
68
+ name='piub',
69
+ model='Line', src=None,
70
+ e_str='plfub.dual_variables[0]')
71
+ self.pib = ExpressionCalc(info='Energy price, dual of <pb>',
72
+ name='pib',
73
+ model='Bus', src=None,
74
+ e_str='pb.dual_variables[0]')
75
+ pi = 'pb.dual_variables[0] + Cft@(plfub.dual_variables[0] - plflb.dual_variables[0])'
76
+ self.pi.e_str = pi
77
+
78
+ def _post_solve(self):
79
+ """Calculate aBus"""
80
+ super()._post_solve()
81
+ sys = self.system
82
+ Pbus = sys.mats.Cg._v @ self.pg.v
83
+ Pbus -= sys.mats.Cl._v @ self.pd.v
84
+ Pbus -= sys.mats.Csh._v @ self.gsh.v
85
+ Pbus -= self.Pbusinj.v
86
+ aBus = sps.linalg.spsolve(sys.mats.Bbus._v, Pbus)
87
+ slack0_uid = sys.Bus.idx2uid(sys.Slack.bus.v[0])
88
+ self.aBus.v = aBus - aBus[slack0_uid]
89
+ return super()._post_solve()
90
+
91
+ def init(self, **kwargs):
92
+ if self.system.mats.PTDF._v is None:
93
+ logger.warning('PTDF is not available, build it now')
94
+ self.system.mats.build_ptdf()
95
+ return super().init(**kwargs)
ams/routines/ed.py CHANGED
@@ -109,8 +109,7 @@ class MPBase:
109
109
  class ED(RTED, MPBase, SRBase):
110
110
  """
111
111
  DC-based multi-period economic dispatch (ED).
112
- Dispath interval ``config.t`` (:math:`T_{cfg}`) is introduced,
113
- 1 [Hour] by default.
112
+ Dispath interval ``config.t`` (:math:``T_{cfg}``) is introduced, 1 [Hour] by default.
114
113
 
115
114
  ED extends DCOPF as follows:
116
115
 
@@ -124,7 +123,7 @@ class ED(RTED, MPBase, SRBase):
124
123
 
125
124
  2. The tie-line flow is not implemented in this model.
126
125
 
127
- 3. `EDTSlot.ug` is used instead of `StaticGen.u` for generator commitment.
126
+ 3. ``EDTSlot.ug`` is used instead of ``StaticGen.u`` for generator commitment.
128
127
  """
129
128
 
130
129
  def __init__(self, system, config):
ams/routines/routine.py CHANGED
@@ -585,6 +585,8 @@ class RoutineBase:
585
585
  True to rebuild the system matrices. Set to False to speed up the process
586
586
  if no system matrices are changed.
587
587
  """
588
+ if not self.initialized:
589
+ return self.init()
588
590
  t0, _ = elapsed()
589
591
  re_finalize = False
590
592
  # sanitize input
ams/routines/uc.py CHANGED
@@ -70,17 +70,15 @@ class UC(DCOPF, RTEDBase, MPBase, SRBase, NSRBase):
70
70
  Notes
71
71
  -----
72
72
  1. Formulations has been adjusted with interval ``config.t``
73
-
74
- 3. The tie-line flow has not been implemented in formulations.
73
+ 2. The tie-line flow has not been implemented in formulations.
75
74
 
76
75
  References
77
76
  ----------
78
77
  1. Huang, Y., Pardalos, P. M., & Zheng, Q. P. (2017). Electrical power unit commitment: deterministic and
79
- two-stage stochastic programming models and algorithms. Springer.
80
-
78
+ two-stage stochastic programming models and algorithms. Springer.
81
79
  2. D. A. Tejada-Arango, S. Lumbreras, P. Sánchez-Martín and A. Ramos, "Which Unit-Commitment Formulation
82
- is Best? A Comparison Framework," in IEEE Transactions on Power Systems, vol. 35, no. 4, pp. 2926-2936,
83
- July 2020, doi: 10.1109/TPWRS.2019.2962024.
80
+ is Best? A Comparison Framework," in IEEE Transactions on Power Systems, vol. 35, no. 4, pp. 2926-2936,
81
+ July 2020, doi: 10.1109/TPWRS.2019.2962024.
84
82
  """
85
83
 
86
84
  def __init__(self, system, config):
ams/shared.py CHANGED
@@ -35,7 +35,7 @@ _prefix = r" - --------------> | " # NOQA
35
35
  _max_length = 80 # NOQA
36
36
 
37
37
  # NOTE: copyright
38
- copyright_msg = 'Copyright (C) 2023-2024 Jinning Wang'
38
+ copyright_msg = 'Copyright (C) 2023-2025 Jinning Wang'
39
39
 
40
40
  # NOTE: copied from CVXPY documentation, last checked on 2024/10/30, v1.5
41
41
  mip_solvers = ['CBC', 'COPT', 'GLPK_MI', 'CPLEX', 'GUROBI',
ams/system.py CHANGED
@@ -422,6 +422,13 @@ class System(andes_System):
422
422
  msg = f"Zero line rates detacted in {adjusted_rate}, "
423
423
  msg += f"adjusted to {default_rate}."
424
424
  logger.info(msg)
425
+ # Line max angle difference
426
+ if np.any(self.Line.amax.v == 0):
427
+ self.Line.amax.v[self.Line.amax.v == 0] = 2 * np.pi
428
+ logger.info("Zero line amax detected, adjusted to 2*pi.")
429
+ if np.any(self.Line.amin.v == 0):
430
+ self.Line.amin.v[self.Line.amin.v == 0] = -2 * np.pi
431
+ logger.info("Zero line amin detected, adjusted to -2*pi.")
425
432
  # === no device addition or removal after this point ===
426
433
  self.calc_pu_coeff() # calculate parameters in system per units
427
434
 
docs/source/conf.py CHANGED
@@ -67,7 +67,7 @@ language = "en"
67
67
 
68
68
  # General information about the project.
69
69
  project = 'AMS'
70
- copyright = '2023-2024, Jinning Wang'
70
+ copyright = '2023-2025, Jinning Wang'
71
71
  author = 'Jinning Wang'
72
72
 
73
73
  version = ams.__version__
@@ -3,10 +3,6 @@
3
3
  Examples
4
4
  ========
5
5
 
6
- .. _`development demos`: https://github.com/CURENT/ams/tree/master/dev/demo
7
-
8
- Refer to the development `development demos`_ for examples prior to preparing this section.
9
-
10
6
  A collection of examples are presented to supplement the tutorial. The
11
7
  examples below are identical to the Jupyter Notebook in the ``examples``
12
8
  folder of the repository
@@ -31,4 +27,5 @@ folder of the repository
31
27
 
32
28
  ../_examples/demo/demo_ESD1.ipynb
33
29
  ../_examples/demo/demo_AGC.ipynb
34
- ../_examples/demo/demo_debug.ipynb
30
+ ../_examples/demo/demo_debug.ipynb
31
+ ../_examples/demo/demo_mat.ipynb
@@ -9,6 +9,19 @@ The APIs before v3.0.0 are in beta and may change without prior notice.
9
9
  v1.0
10
10
  ==========
11
11
 
12
+ v1.0.6 (2024-04-10)
13
+ --------------------
14
+
15
+ - Enhance handling of Type 1 gencost: Automatically fallback to Type 2 gencost
16
+ - Add parameter correction for zero line angle difference
17
+
18
+ v1.0.5 (2024-04-09)
19
+ --------------------
20
+
21
+ - Include sensitivity matrices calculation demo in documentation
22
+ - Add ``DCOPF2``, a PTDF-based DCOPF routine
23
+ - Fix bug when update routine parameters before it is initialized
24
+
12
25
  v1.0.4 (2024-04-05)
13
26
  --------------------
14
27
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ltbams
3
- Version: 1.0.4
3
+ Version: 1.0.6
4
4
  Summary: Python software for scheduling modeling and co-simulation with dynamics.
5
5
  Home-page: https://github.com/CURENT/ams
6
6
  Author: Jinning Wang
@@ -37,7 +37,7 @@ Python Software for Power System Scheduling Modeling and Co-Simulation with Dyna
37
37
  [![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)
38
38
  [![codecov](https://codecov.io/gh/CURENT/ams/graph/badge.svg?token=RZI5GLLBQH)](https://codecov.io/gh/CURENT/ams)
39
39
 
40
- ![GitHub Tag](https://img.shields.io/github/v/tag/CURENT/ams)
40
+ [![GitHub Tag](https://img.shields.io/github/v/tag/CURENT/ams)](https://github.com/CURENT/ams/tags)
41
41
  ![GitHub commits since latest release (branch)](https://img.shields.io/github/commits-since/curent/ams/latest/develop)
42
42
  [![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/)
43
43
  [![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/)
@@ -152,7 +152,7 @@ pip install git+https://github.com/CURENT/ams.git
152
152
  - `cvxpy` is distributed with the open source solvers CLARABEL, OSQP, and SCS, but MIP-capable solvers need separate installation
153
153
  - `cvxpy` versions **below 1.5** are incompatible with `numpy` versions **2.0 and above**
154
154
  - If the solver `SCIP` encounters an import error caused by a missing `libscip.9.1.dylib`, try reinstalling its Python interface by running `pip install pyscipopt --no-binary scip --force`
155
- - `kvxopt` is recommended to install via `conda` as sometimes ``pip`` struggles to set the correct path for compiled libraries
155
+ - `kvxopt` is recommended to install via `conda` as sometimes ``pip`` struggles to set the correct path for compiled libraries, more detailes can be found in this closed issue [Bug with dependency kvxopt 1.3.2.0](https://github.com/CURENT/andes/issues/508)
156
156
  - Versions **1.0.0** and **1.0.1** are only available on PyPI
157
157
  - Version **0.9.9** has known issues and has been yanked from PyPI
158
158
 
@@ -1,12 +1,12 @@
1
1
  ams/__init__.py,sha256=dKIwng8xES4NQHn6ZHy8RCKeXphN9z2wyfmbvniIEg0,351
2
2
  ams/__main__.py,sha256=EB4GfGiKgvnQ_psNr0QwPoziYvjmGvQ2yVsBwQtfrLw,170
3
- ams/_version.py,sha256=QJewH8SVJp4BIef-1_4TgcwsHFkIMiPuupiTKidj58o,497
3
+ ams/_version.py,sha256=oAzDdazRg63AUA2MukEv3uZGF9tr0x-lHYUi17sP_Bg,497
4
4
  ams/cli.py,sha256=EyNFXn565gFCppTxpyTZviBdPgUuKtgAPZ4WE6xewRk,6164
5
5
  ams/interface.py,sha256=PCR9geO-pvCxXxljWP4u3M-BAdVD5DjA3xvf338g9x8,44487
6
6
  ams/main.py,sha256=wzKLe_BeQAUyFh-U1cxQIOwr-rAJM8ppB3EEi6_v2tw,23607
7
7
  ams/report.py,sha256=gUscOYpPjuPuruzIXAADaifIZv2BSjmP1oKCuHdD3Vw,11004
8
- ams/shared.py,sha256=Zdy4-kHKc0_3CzyZKmGyCvpmrJz4Wzs9qnFlk8eyzq0,4159
9
- ams/system.py,sha256=PbJE5JPc9_O8cXTC10HPdvlD6MyxuL8z6q9dxKHWtCc,25917
8
+ ams/shared.py,sha256=yaO4RUD0T-zCcZeML20vORcaf_dXiwMAvjTriXz1xtg,4159
9
+ ams/system.py,sha256=5P0DZ7eEqQ8yQL_JBEMDYpr5N7QKHB2X5aJOvEkjiv4,26307
10
10
  ams/cases/5bus/pjm5bus_demo.xlsx,sha256=srKTX4AkDRUVg_ygChyrQjeX7o0KKPJ9q9zU69xJqdU,31112
11
11
  ams/cases/5bus/pjm5bus_jumper.xlsx,sha256=IfcSZ3V2ZgfFqpaPMBMqitUQMgoxKRnyFyMEtqdeysI,28375
12
12
  ams/cases/5bus/pjm5bus_uced.json,sha256=0RvkZwZwzXKqr8y9shjEr3qCPGlrBrh6VpGhvYa4pMM,18256
@@ -48,14 +48,14 @@ ams/extension/__init__.py,sha256=5IFTNirDL0uDaUsg05_oociVT9VCy2rhPx1ad4LGveM,65
48
48
  ams/extension/eva.py,sha256=wUF8RNxzwas2Q6_xD0k3EVWjmX4kxHmTSkv2inJzaUY,16342
49
49
  ams/io/__init__.py,sha256=HLE3aozzXEx-6IBy8WTQVdSCpAZrrR9nX6UqaZ7okTw,3774
50
50
  ams/io/json.py,sha256=IurwcZDuKczSbRTpcbQZiIi0ARCrMK6kJ0E3wS8ENy8,2585
51
- ams/io/matpower.py,sha256=40Ga2TPs57Kysm-dirjos-rnZ47aZHMfj7FXpd6eB08,14064
51
+ ams/io/matpower.py,sha256=Oj3FW-eqcl3H5mnB0U5XG1mtCK0SaxVOkgRXaC6MIKA,14523
52
52
  ams/io/psse.py,sha256=w5VKNE6enX0lfKwPI857PRtdpwN39R6IFRIcdbPSpOg,151
53
53
  ams/io/pypower.py,sha256=E6_kSNfv1Yyv9oYfFebeNeKaQPlHyRZQpE8F6Y67g8Q,2583
54
54
  ams/io/xlsx.py,sha256=7ATW1seyxsGn7d5p5IuSRFHcoCHVVjMu3E7mP1Mc74U,2460
55
55
  ams/models/__init__.py,sha256=Y1Igq3AByDI6QjqjWxNDMeTAa2-fdnk2ZX5HtdJO6lY,703
56
56
  ams/models/area.py,sha256=AKYU6aJQKsVWRZdvMO7yic-8wZ1GumSTQXgDg5L0THw,899
57
57
  ams/models/bus.py,sha256=U0vSegkm-9fqPQS9KMJQU6gpIMX_1GK5O_dvRc8-0P0,1585
58
- ams/models/cost.py,sha256=xD_UQCnc4WvVH_sU-JUKi6vgY2h7iFa3cLJZVH4GGx0,5860
58
+ ams/models/cost.py,sha256=rmGNj9ztMbqA-OIJj8fNNBh8bdYJSY9hk10vffgxc6k,5916
59
59
  ams/models/group.py,sha256=byAp-sfsS7WhCL8L9y6wqljO6zO_u_JomgIv4syvbJA,5602
60
60
  ams/models/info.py,sha256=Oh0Xo5J4ZHBsNIkMOzIwv_DegsX1inyuv3Q5CpCfyQw,788
61
61
  ams/models/line.py,sha256=6t0_Y6rlD8riHiljThwluiZMtshu9kgd9ti_Px81KgU,8083
@@ -74,7 +74,7 @@ ams/models/static/gen.py,sha256=CZepvqhjmlGWkUwP3goiimvhZx04L2ADzzx1aVbfdDg,6685
74
74
  ams/models/static/pq.py,sha256=Ky6vcc_G7K46azn4-xBJD-6Rht_3y6r7gkSpFNXWIx0,2583
75
75
  ams/opt/__init__.py,sha256=INsl8yxtOzTKqV9pzVxlL6RSGDRaUDwxpZMY1QROrF4,459
76
76
  ams/opt/constraint.py,sha256=ERT9zwjQyGkvDo465Yd0wBexlIhjVmw0MyWq4BWnWoI,5534
77
- ams/opt/exprcalc.py,sha256=6g_d4aYEvy9uxikEwhGE6cqL4wElD3KQmtScYSAHW68,3887
77
+ ams/opt/exprcalc.py,sha256=oVtjNHzdWvYHV-8PdRehAxjledsQxpxatdNgMLeWS5o,3935
78
78
  ams/opt/expression.py,sha256=WrWnYliB61uHA_wQjtYgtAXdpgSN1pNqQmWvzHWSsdE,5569
79
79
  ams/opt/objective.py,sha256=W0dQfW5dHNdWEc2DQtWYNGMuhMY6Pu-HTD0n7-izDZA,5519
80
80
  ams/opt/omodel.py,sha256=hEtfKoSNssSxHgUDdep79pifNTsywytDTjgGgne7nKM,12750
@@ -102,36 +102,37 @@ ams/pypower/routines/cpf_callbacks.py,sha256=93f3sdibG7FsXOP9EmqX-iTe0_eZmGtH1Jh
102
102
  ams/pypower/routines/opf.py,sha256=SNklP0cC8qu-ji1vluEj7DjAtvWDneOEkZWZeMBdd5g,73447
103
103
  ams/pypower/routines/opffcns.py,sha256=o8EpvWH32x3vbN9gV7Xi-D6RHQ5V2eB8NT15cZrwX2w,78144
104
104
  ams/pypower/routines/pflow.py,sha256=q5RFZ5XuB5YQZk1jpJ5aTUB3DfgPJEGsvWyLDNo5PJo,30697
105
- ams/routines/__init__.py,sha256=hB0Nr9RWjnp7Jx2Xria0JpRyIlbIIDEcLwXHqF9v0ug,612
105
+ ams/routines/__init__.py,sha256=idfPyMhFr0hkUZjcAEQw14JA5zPHeFe3Vl3p4DCJ5d0,640
106
106
  ams/routines/acopf.py,sha256=VZC3qs1G7zE--6XxE_wXv432nj3SV5hcrR8967ogYlg,3835
107
107
  ams/routines/cpf.py,sha256=xsrUVjtGQ1b7UCXpwwYihqzTeEGJJKnO9LlX1Tz9Tks,1552
108
- ams/routines/dcopf.py,sha256=cOkqXnSD70QthATeggZUF5c_1tRskzTq2z9ODmsA1JA,10898
108
+ ams/routines/dcopf.py,sha256=PWAd0xRpgTDysG6OMRVMkBGtUEyjvmmSt8758tXajOw,11091
109
+ ams/routines/dcopf2.py,sha256=sDCP8zqYHDh7s7p9SX6G8QhMfIxCg3VPYJn6r3pRKyo,3620
109
110
  ams/routines/dcpf.py,sha256=SswIb7t37ulxe1rjroA7oSa6z01kYjO-x8P1WWOUutM,8237
110
111
  ams/routines/dcpf0.py,sha256=gPPfSUzzJbHz_gAEFVyZ3iriEHvLJ-OGpTzhza8FOkA,6811
111
112
  ams/routines/dopf.py,sha256=yIn4tdxgb_phdvlHn4kMT9dUP0c_0Lu5kFfyCAUG-tk,6241
112
- ams/routines/ed.py,sha256=eNo-edm8qNrQCl9aHqBoIPDF6ltH65L7IobghoK7uH4,11646
113
+ ams/routines/ed.py,sha256=eAgAbcnqyqR4UdhlV1VHTu6m99slAZSeEeGvkDp8BXs,11648
113
114
  ams/routines/pflow.py,sha256=I4lyXDyprkg_0j3gY5bdkkBA5ImSjnouMzRnuG1yKb8,9435
114
115
  ams/routines/pflow0.py,sha256=xocLw94jcl2hh3WwnS_mdUW6dsm3EVjvZptVb814GdE,3521
115
- ams/routines/routine.py,sha256=QoYxjpItxb7fgPajLoMlGH_TFFgIKgg8Ohhf_WP_SIk,35868
116
+ ams/routines/routine.py,sha256=I98uMg6QCt6bipNYwdgtNMbdw_gWCSNVGokS4UmvkSk,35932
116
117
  ams/routines/rted.py,sha256=BWq2XCYP99siBiLNMF0oKiUmxsCAypBPYxTNeCsjz8Y,22197
117
118
  ams/routines/type.py,sha256=lvTWSnCYIbRJXIm3HX6jA0Hv-WWYusTOUPfoW8DITlU,3877
118
- ams/routines/uc.py,sha256=kkYicT1zjD_JmL3HQFe4iBedri1OAHO9-skzjiW21Fc,15625
119
+ ams/routines/uc.py,sha256=KeKuvd6xxRQTvRiJA7MSOUUVKO5_c5654gOms3mGS9M,15632
119
120
  ams/utils/__init__.py,sha256=2hAQmWRgmnE-bCGT9cJoW9FkPDMGRiGkbBcUgj-bgjI,122
120
121
  ams/utils/misc.py,sha256=Y6tPKpUKJa7bL9alroJuG2UNW9vdQjnfAmKb2EbIls8,2027
121
122
  ams/utils/paths.py,sha256=D9VNUwtJtHy-8PFzMnxtQ9HpkOXT6vdVOjfOTuoKGKw,6699
122
123
  docs/Makefile,sha256=UKXBFAbKGPt1Xw9J84343v0Mh8ylAZ-tE0uCd74DrQU,725
123
124
  docs/make.bat,sha256=9UgKGb4SdP006622fJiFxeFT1BeycYAs6hDbV1xwPy8,804
124
125
  docs/source/api.rst,sha256=gDix4Vg_SNUqtijlSmfBktpOrWQMdaj4xsBKrO22dfw,1402
125
- docs/source/conf.py,sha256=ozLsGWVbFOZZfruXlvL6ou8i-R8kyCYZedtDzSQVRoU,6688
126
+ docs/source/conf.py,sha256=UyoWogZTUNSJU7pQS_JaR28nKddW94zr01LYoIciZZw,6688
126
127
  docs/source/genmodelref.py,sha256=IhmF7bDw8BXPvLD8V3WjQNrfc-H07r5iS-_4DHbbp-8,1420
127
128
  docs/source/genroutineref.py,sha256=0JyMc2kV5bWrWbSoO6d7o4QgDgG8mVy3JGGQWacJypw,1064
128
129
  docs/source/index.rst,sha256=N5phQS5RIyYs-NZo_5yYB8LjvHzOKLeXzRA-M8i-g3Q,2688
129
- docs/source/release-notes.rst,sha256=VX7Pf8XDe1jrT0jO1eJjoj3hRLkwKt2vId16B-cBPEg,12906
130
+ docs/source/release-notes.rst,sha256=UbY9PEvwT9Z70IvdOU34YI7dQ4MTSfHWz9yZamN5euA,13305
130
131
  docs/source/_templates/autosummary/base.rst,sha256=zl3U4baR4a6YjsHyT-x9zCOrHwKZOVUdWn1NPX2u3bc,106
131
132
  docs/source/_templates/autosummary/class.rst,sha256=Hv_igCsLsUpM62_zN0nqj6FSfKnS5xLyu8ZldMbfOAk,668
132
133
  docs/source/_templates/autosummary/module.rst,sha256=YdbpCudOrEU-JbuSlzGvcOI2hn_KrCM6FW5HcGqkaEE,1113
133
134
  docs/source/_templates/autosummary/module_toctree.rst,sha256=sg30OdqFDLyo8Y3hl9V-s2BXb1bzcjjqqWaWi-C3qFM,1126
134
- docs/source/examples/index.rst,sha256=u6-pMB5ecSpNb3x1QWC6tJ8ACh3M6MjLBc4CVFf2z_0,876
135
+ docs/source/examples/index.rst,sha256=6VT3wVeKk8BWf6pJQtZrmcumW_3jI8esdlzja8scUCA,742
135
136
  docs/source/getting_started/copyright.rst,sha256=XBfWvLm7T8p-zh1jkDy1kODvTDcH73AEV_vkiN32A2o,715
136
137
  docs/source/getting_started/index.rst,sha256=mcp1NdUwbPoNzpn7Owf5Qzfd6J_--ToU52PjmrbwjBY,1512
137
138
  docs/source/getting_started/install.rst,sha256=gE4L0ApiC_mwbjbYtkGW4ilyIAu_Jn-VIeoYlgRiOIw,7268
@@ -159,12 +160,12 @@ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
159
160
  tests/test_1st_system.py,sha256=5PQgI1DeM5yQTFagOPCMbk0eItTH6-M6FC8TMCv-CRY,1007
160
161
  tests/test_addressing.py,sha256=MIT713KCqMg0h2o4rBDZsGUrpGadmMlXnrrdq-wB77E,1364
161
162
  tests/test_andes_mats.py,sha256=3JQ2xK5B4s42EHxjCcUjJbt1VY3rZPwjkq81ubFlsLQ,1674
162
- tests/test_case.py,sha256=uR2bP1g9PO812W9tVmBwWGmyBN5ltMynOZz0ZeI82iE,7808
163
+ tests/test_case.py,sha256=zkf5jT314e97Rx_PJXCwmuvaeQDTjJ42zYR6WwJetxE,8606
163
164
  tests/test_cli.py,sha256=TtCGBy2e7Ll_2gJTFo9juZtzhaakho_MqkcqhG2w2dk,870
164
165
  tests/test_export_csv.py,sha256=rZCafNrVbwDo7ZNC4MrL1gIcrU0c6YVw2q-QGL3O4K4,2921
165
166
  tests/test_group.py,sha256=Tq0s9gtenqrv4ws5YNzWxbiF4WgyhtMEAXZfJtew6M4,2699
166
167
  tests/test_interface.py,sha256=lXKR8OAsGIg5dV2Uj0UwGAl69hKnc_7EtCYvpP_0rrU,8157
167
- tests/test_io.py,sha256=ABEtSc7-5aHZZrdVorARRhWIxfSBEzkb5fsiSJluGHA,1087
168
+ tests/test_io.py,sha256=LaNkRXZaItAFHqqXs6CC5iaxTMXiDEFGbwYODcOHPWc,1416
168
169
  tests/test_jumper.py,sha256=bdOknplEGnO_tiJc7p3xQvgTe2b6Dz53bOgbFaXKMAI,537
169
170
  tests/test_known_good.py,sha256=NBrlAxnVMxIHXR2cWps-Kwjh36fiU4Y-eupspZkM0ks,9670
170
171
  tests/test_matp.py,sha256=LkjhqxSFr6oY_ENpduDQ77rhLLBl6RzIHZ2d0m_8i-8,17262
@@ -175,14 +176,15 @@ tests/test_report.py,sha256=B2_ugz5gzF4mDdiba498DrkK9hX4Zfa6KUGW54yCGVE,8069
175
176
  tests/test_repr.py,sha256=g7MRdxLcZRI1PlREFdUG_npp0LkcQiJZfOPw1aq0EFM,570
176
177
  tests/test_routine.py,sha256=gblLHBQ3DJgYiSGsqGdIGnn-CuEZAEnq9CqhqN5m608,6234
177
178
  tests/test_rtn_dcopf.py,sha256=LOfAVFzl2t6oTqTmWhmstu1j9FnpzHxdrplbmb3Y6Mc,3660
179
+ tests/test_rtn_dcopf2.py,sha256=g0MOW8J6WPJPQAV3Xwufa3dWEEeH-cQDErzvb-cq8lE,3747
178
180
  tests/test_rtn_dcpf.py,sha256=QC6F_4LOZ7mrWOEM3s6a6j-eUDM_n49MQouPIR6fzR0,2555
179
181
  tests/test_rtn_ed.py,sha256=2CO0kg3LEN8q75_4Z0cgGz4DTOPUjRHur6Dbfw2tRLQ,10173
180
182
  tests/test_rtn_pflow.py,sha256=aDL5Ewm6lWqpdHqIIu-DTllhXzt4bMjsLJaKbJa8sXQ,6990
181
183
  tests/test_rtn_rted.py,sha256=AyW5B4A51L_nIVLX1eYeu9ZUboOh1CH2FVj2C1XJjSc,9769
182
184
  tests/test_rtn_uc.py,sha256=vdG2ss3q91CXLZ2sUgzoUr1NU-63ue7nOxAYywMordE,8286
183
185
  tests/test_service.py,sha256=8YIa_PXurwgOzsWvUqoyqS_AzlpdrKHIMxAln5fIqCU,2438
184
- ltbams-1.0.4.dist-info/METADATA,sha256=bIJkTtYXfycQdXFyh9018Jkp2aqxwXSc0jJYsr100i0,13855
185
- ltbams-1.0.4.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
186
- ltbams-1.0.4.dist-info/entry_points.txt,sha256=FA56FlhO_yVNeEf810SrorVQb7_Xsmo3_EW-W-ijUfA,37
187
- ltbams-1.0.4.dist-info/top_level.txt,sha256=pyKDqG2kj13F9-BYd_wkruRdBSqLXw8Nwc-cmljqrxg,15
188
- ltbams-1.0.4.dist-info/RECORD,,
186
+ ltbams-1.0.6.dist-info/METADATA,sha256=HPawZwqPMnM1vtyrVEA_yU8FDcs47BdNv_zJTaYy5uo,14023
187
+ ltbams-1.0.6.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
188
+ ltbams-1.0.6.dist-info/entry_points.txt,sha256=FA56FlhO_yVNeEf810SrorVQb7_Xsmo3_EW-W-ijUfA,37
189
+ ltbams-1.0.6.dist-info/top_level.txt,sha256=pyKDqG2kj13F9-BYd_wkruRdBSqLXw8Nwc-cmljqrxg,15
190
+ ltbams-1.0.6.dist-info/RECORD,,
tests/test_case.py CHANGED
@@ -264,3 +264,30 @@ class TestCaseInit(unittest.TestCase):
264
264
 
265
265
  self.assertEqual(ss.EDES.exit_code, 0, "Exit code is not 0.")
266
266
  self.assertEqual(ss.UCES.exit_code, 0, "Exit code is not 0.")
267
+
268
+
269
+ class TestCase14(unittest.TestCase):
270
+ """
271
+ Test parameter correction using case14.m
272
+ """
273
+
274
+ def test_parameter_correction(self):
275
+ """
276
+ Test if the parameter correction works.
277
+ """
278
+ mpc = ams.io.matpower.m2mpc(get_case("matpower/case14.m"))
279
+ mpc['branch'][:, 11] = 0.0
280
+ mpc['branch'][:, 12] = 0.0
281
+
282
+ ss = ams.system.System()
283
+ ams.io.matpower.mpc2system(mpc, ss)
284
+ ss.setup()
285
+
286
+ # line rate
287
+ np.testing.assert_array_less(0.0, ss.Line.rate_a.v)
288
+ np.testing.assert_array_less(0.0, ss.Line.rate_b.v)
289
+ np.testing.assert_array_less(0.0, ss.Line.rate_c.v)
290
+
291
+ # line angle difference
292
+ np.testing.assert_array_less(0.0, ss.Line.amax.v)
293
+ np.testing.assert_array_less(ss.Line.amin.v, 0.0)
tests/test_io.py CHANGED
@@ -30,3 +30,12 @@ class TestMATPOWER(unittest.TestCase):
30
30
  # In case14.m, the gencost has type 2 cost model, with 3 parameters.
31
31
  np.testing.assert_array_less(np.zeros(system14.StaticGen.n),
32
32
  system14.GCost.c2.v,)
33
+
34
+ def test_gencost1(self):
35
+ """Test when gencost is type 1."""
36
+ mpcgc1 = self.mpc14.copy()
37
+ mpcgc1['gencost'] = np.repeat(np.array([[1, 0, 0, 3, 0.01, 40, 0]]), 5, axis=0)
38
+
39
+ system = ams.system.System()
40
+ ams.io.matpower.mpc2system(mpcgc1, system)
41
+ self.assertEqual(system.GCost.n, 5)
@@ -0,0 +1,103 @@
1
+ import unittest
2
+ import numpy as np
3
+
4
+ import ams
5
+
6
+
7
+ class TestDCOPF2(unittest.TestCase):
8
+ """
9
+ Test routine `DCOPF2`.
10
+ """
11
+
12
+ def setUp(self) -> None:
13
+ self.ss = ams.load(ams.get_case("5bus/pjm5bus_demo.xlsx"),
14
+ setup=True, default_config=True, no_output=True)
15
+ # decrease load first
16
+ self.ss.PQ.set(src='p0', attr='v', idx=['PQ_1', 'PQ_2'], value=[0.3, 0.3])
17
+ # build PTDF
18
+ self.ss.mats.build_ptdf()
19
+
20
+ def test_init(self):
21
+ """
22
+ Test initialization.
23
+ """
24
+ self.ss.DCOPF2.init()
25
+ self.assertTrue(self.ss.DCOPF2.initialized, "DCOPF2 initialization failed!")
26
+
27
+ def test_trip_gen(self):
28
+ """
29
+ Test generator tripping.
30
+ """
31
+ stg = 'PV_1'
32
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=0)
33
+
34
+ self.ss.DCOPF2.update()
35
+ self.ss.DCOPF2.run(solver='CLARABEL')
36
+ self.assertTrue(self.ss.DCOPF2.converged, "DCOPF2 did not converge under generator trip!")
37
+ self.assertAlmostEqual(self.ss.DCOPF2.get(src='pg', attr='v', idx=stg),
38
+ 0, places=6,
39
+ msg="Generator trip does not take effect!")
40
+
41
+ self.ss.StaticGen.set(src='u', idx=stg, attr='v', value=1) # reset
42
+
43
+ def test_trip_line(self):
44
+ """
45
+ Test line tripping.
46
+ """
47
+ self.ss.Line.set(src='u', attr='v', idx='Line_3', value=0)
48
+
49
+ self.ss.DCOPF2.update()
50
+ self.ss.DCOPF2.run(solver='CLARABEL')
51
+ self.assertTrue(self.ss.DCOPF2.converged, "DCOPF2 did not converge under line trip!")
52
+ self.assertAlmostEqual(self.ss.DCOPF2.get(src='plf', attr='v', idx='Line_3'),
53
+ 0, places=6,
54
+ msg="Line trip does not take effect!")
55
+
56
+ self.ss.Line.alter(src='u', idx='Line_3', value=1) # reset
57
+
58
+ def test_set_load(self):
59
+ """
60
+ Test setting and tripping load.
61
+ """
62
+ # --- run DCOPF2 ---
63
+ self.ss.DCOPF2.run(solver='CLARABEL')
64
+ pgs = self.ss.DCOPF2.pg.v.sum()
65
+
66
+ # --- set load ---
67
+ self.ss.PQ.set(src='p0', attr='v', idx='PQ_1', value=0.1)
68
+ self.ss.DCOPF2.update()
69
+
70
+ self.ss.DCOPF2.run(solver='CLARABEL')
71
+ pgs_pqt = self.ss.DCOPF2.pg.v.sum()
72
+ self.assertLess(pgs_pqt, pgs, "Load set does not take effect!")
73
+
74
+ # --- trip load ---
75
+ self.ss.PQ.set(src='u', attr='v', idx='PQ_2', value=0)
76
+ self.ss.DCOPF2.update()
77
+
78
+ self.ss.DCOPF2.run(solver='CLARABEL')
79
+ pgs_pqt2 = self.ss.DCOPF2.pg.v.sum()
80
+ self.assertLess(pgs_pqt2, pgs_pqt, "Load trip does not take effect!")
81
+
82
+ def test_dc2ac(self):
83
+ """
84
+ Test `DCOPF2.dc2ac()` method.
85
+ """
86
+ self.ss.DCOPF2.run(solver='CLARABEL')
87
+ self.ss.DCOPF2.dc2ac()
88
+ self.assertTrue(self.ss.DCOPF2.converted, "AC conversion failed!")
89
+ self.assertTrue(self.ss.DCOPF2.exec_time > 0, "Execution time is not greater than 0.")
90
+
91
+ stg_idx = self.ss.StaticGen.get_all_idxes()
92
+ pg_dcopf = self.ss.DCOPF2.get(src='pg', attr='v', idx=stg_idx)
93
+ pg_acopf = self.ss.ACOPF.get(src='pg', attr='v', idx=stg_idx)
94
+ np.testing.assert_almost_equal(pg_dcopf, pg_acopf, decimal=3)
95
+
96
+ bus_idx = self.ss.Bus.get_all_idxes()
97
+ v_dcopf = self.ss.DCOPF2.get(src='vBus', attr='v', idx=bus_idx)
98
+ v_acopf = self.ss.ACOPF.get(src='vBus', attr='v', idx=bus_idx)
99
+ np.testing.assert_almost_equal(v_dcopf, v_acopf, decimal=3)
100
+
101
+ a_dcopf = self.ss.DCOPF2.get(src='aBus', attr='v', idx=bus_idx)
102
+ a_acopf = self.ss.ACOPF.get(src='aBus', attr='v', idx=bus_idx)
103
+ np.testing.assert_almost_equal(a_dcopf, a_acopf, decimal=3)
File without changes