ltbams 1.0.4__py3-none-any.whl → 1.0.5__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-09T22:08:11-0400",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "af7a4e10ba2e35c4180562cf62f69ba5523c6725",
15
- "version": "1.0.4"
14
+ "full-revisionid": "115b1575b21ff871fe878121b3ca1cb6020b1a93",
15
+ "version": "1.0.5"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
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,7 +19,11 @@ 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
+ 1. 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
  ----------
@@ -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
+ 1. Nodal price ``pi`` is calculated with three parts.
29
+ 1. 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/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
@@ -31,4 +31,5 @@ folder of the repository
31
31
 
32
32
  ../_examples/demo/demo_ESD1.ipynb
33
33
  ../_examples/demo/demo_AGC.ipynb
34
- ../_examples/demo/demo_debug.ipynb
34
+ ../_examples/demo/demo_debug.ipynb
35
+ ../_examples/demo/demo_mat.ipynb
@@ -9,6 +9,13 @@ 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.5 (2024-04-09)
13
+ --------------------
14
+
15
+ - Include sensitivity matrices calculation demo in documentation
16
+ - Add ``DCOPF2``, a PTDF-based DCOPF routine
17
+ - Fix bug when update routine parameters before it is initialized
18
+
12
19
  v1.0.4 (2024-04-05)
13
20
  --------------------
14
21
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ltbams
3
- Version: 1.0.4
3
+ Version: 1.0.5
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,6 +1,6 @@
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=fHaf3d1VKT7Y8k0GYj2TxX2ZeGzQ92qYr2or0jwPTXM,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
@@ -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,17 +102,18 @@ 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=6qI1nDf8LepgaHL9HnP1y6a5lGsJAWKQaL7wD7WLbJU,11070
109
+ ams/routines/dcopf2.py,sha256=EtzA1ZQVO4KGVoRdhagV8aIipecWJnXvHYeYTCfgMos,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
113
  ams/routines/ed.py,sha256=eNo-edm8qNrQCl9aHqBoIPDF6ltH65L7IobghoK7uH4,11646
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
119
  ams/routines/uc.py,sha256=kkYicT1zjD_JmL3HQFe4iBedri1OAHO9-skzjiW21Fc,15625
@@ -126,12 +127,12 @@ docs/source/conf.py,sha256=ozLsGWVbFOZZfruXlvL6ou8i-R8kyCYZedtDzSQVRoU,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=se_oKj_P3jyvKEDmnttAv78pmSpvKBjpZLMUg7B8_Q0,13125
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=6yYgETu_4VQ9x8Jmff5i6pXX4_DLrLpSIRIidhVvqPA,912
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
@@ -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.5.dist-info/METADATA,sha256=Ozov3I100t3YStip3CYXb56cb96APz1juduPF1P2YnY,14023
187
+ ltbams-1.0.5.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
188
+ ltbams-1.0.5.dist-info/entry_points.txt,sha256=FA56FlhO_yVNeEf810SrorVQb7_Xsmo3_EW-W-ijUfA,37
189
+ ltbams-1.0.5.dist-info/top_level.txt,sha256=pyKDqG2kj13F9-BYd_wkruRdBSqLXw8Nwc-cmljqrxg,15
190
+ ltbams-1.0.5.dist-info/RECORD,,
@@ -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