From c98b4ea2f0a57c5254ce2608992480d0de120b83 Mon Sep 17 00:00:00 2001 From: jinningwang Date: Sat, 5 Apr 2025 17:22:54 -0400 Subject: [PATCH 1/5] Enhance model.set when destination is list --- andes/core/model/model.py | 12 +++++++++++- docs/source/release-notes.rst | 4 ++++ tests/test_model_set.py | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/andes/core/model/model.py b/andes/core/model/model.py index 339c4dc0b..c7e0224f7 100644 --- a/andes/core/model/model.py +++ b/andes/core/model/model.py @@ -508,7 +508,17 @@ def set(self, src, idx, attr, value): uid = self.idx2uid(idx) instance = self.__dict__[src] - instance.__dict__[attr][uid] = value + # Check if the destination is a list + if isinstance(instance.__dict__[attr], list): + # Use a for-loop to set values + if isinstance(uid, list): + for i, u in enumerate(uid): + instance.__dict__[attr][u] = value[i] + else: + instance.__dict__[attr][uid] = value + else: + # Default behavior for numpy arrays or other types + instance.__dict__[attr][uid] = value # update differential equations' time constants stored in `dae.Tf` diff --git a/docs/source/release-notes.rst b/docs/source/release-notes.rst index 80ba84e67..b8d090e49 100644 --- a/docs/source/release-notes.rst +++ b/docs/source/release-notes.rst @@ -9,6 +9,10 @@ The APIs before v3.0.0 are in beta and may change without prior notice. v1.9 Notes ========== +v1.9.4 (2025-xx-xx) +------------------- +- Enhance ``Model.set()`` to support assigning values when the destination is a list. + v1.9.3 (2025-01-05) ------------------- Development of connectivity manager ``ConnMan``: diff --git a/tests/test_model_set.py b/tests/test_model_set.py index ed4d5ecf0..764caa548 100644 --- a/tests/test_model_set.py +++ b/tests/test_model_set.py @@ -55,6 +55,10 @@ def test_model_set(self): np.testing.assert_equal(ss.GENROU.M.v[3], 6.0) self.assertEqual(ss.TDS.Teye[omega_addr[3], omega_addr[3]], 6.0) + # set when destination idx is list + ss.Bus.set(src='name', attr='v', idx=(1, 2, 3), value=['A', 'B', 'C']) + self.assertEqual(ss.Bus.name.v[:3], ['A', 'B', 'C']) + def test_find_idx(self): ss = andes.load(andes.get_case('ieee14/ieee14_pvd1.xlsx')) mdl = ss.PVD1 @@ -131,3 +135,7 @@ def test_model_alter(self): # alter `vin` on instances without `vin` falls back to `v` ss.GENCLS.alter(src='p0', idx=2, value=1, attr='vin') self.assertEqual(ss.GENCLS.p0.v[1], 1) + + # # alter `v` when destination idx is list + ss.Bus.alter(src='name', idx=[0, 1], value=['A', 'B'], attr='vin') + np.testing.assert_equal(ss.Bus.name.v[:2], ['A', 'B']) From 97333e7415d10c7c0349fb9a2592d08ded79e932 Mon Sep 17 00:00:00 2001 From: jinningwang Date: Sat, 5 Apr 2025 18:20:08 -0400 Subject: [PATCH 2/5] Fix numpy nan compatibility --- andes/interop/pandapower.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/andes/interop/pandapower.py b/andes/interop/pandapower.py index c43f08126..f816b1290 100644 --- a/andes/interop/pandapower.py +++ b/andes/interop/pandapower.py @@ -9,6 +9,12 @@ from andes.shared import pd, rad2deg, deg2rad from andes.shared import pandapower as pp +try: + nan = np.nan +except AttributeError: + # for older numpy versions + nan = np.NAN + logger = logging.getLogger(__name__) @@ -315,7 +321,7 @@ def _to_pp_line(ssa, ssp, ssa_bus): tf_df['parallel'] = 1 tf_df['oltc'] = False tf_df['tap_phase_shifter'] = False - tf_df['tap_step_degree'] = np.NaN + tf_df['tap_step_degree'] = np.nan tf_df['df'] = 1 tf_df['std_type'] = None From a99e5227443de3e1c4ea3831de33ac007ad98893 Mon Sep 17 00:00:00 2001 From: Hantao Cui Date: Wed, 16 Apr 2025 23:09:17 -0400 Subject: [PATCH 3/5] Fix an issue with Y matrix calculation. --- andes/models/line/line.py | 5 +++-- docs/source/release-notes.rst | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/andes/models/line/line.py b/andes/models/line/line.py index 167b87cdc..5a0daf60b 100644 --- a/andes/models/line/line.py +++ b/andes/models/line/line.py @@ -256,6 +256,7 @@ def build_y(self): nb = self.system.Bus.n + ysh = self.u.v * (self.g.v + self.b.v * 1j) / 2 y1 = self.u.v * (self.g1.v + self.b1.v * 1j) y2 = self.u.v * (self.g2.v + self.b2.v * 1j) y12 = self.u.v / (self.r.v + self.x.v * 1j) @@ -264,10 +265,10 @@ def build_y(self): mconj = np.conj(m) # build self and mutual admittances into Y - self.Y = spmatrix((y12 + y1 / m2), self.a1.a, self.a1.a, (nb, nb), 'z') + self.Y = spmatrix((y12 + y1) / m2 + ysh, self.a1.a, self.a1.a, (nb, nb), 'z') self.Y -= spmatrix(y12 / mconj, self.a1.a, self.a2.a, (nb, nb), 'z') self.Y -= spmatrix(y12 / m, self.a2.a, self.a1.a, (nb, nb), 'z') - self.Y += spmatrix(y12 + y2, self.a2.a, self.a2.a, (nb, nb), 'z') + self.Y += spmatrix(y12 + y2 + ysh, self.a2.a, self.a2.a, (nb, nb), 'z') return self.Y diff --git a/docs/source/release-notes.rst b/docs/source/release-notes.rst index b8d090e49..c83a1813e 100644 --- a/docs/source/release-notes.rst +++ b/docs/source/release-notes.rst @@ -11,7 +11,9 @@ v1.9 Notes v1.9.4 (2025-xx-xx) ------------------- -- Enhance ``Model.set()`` to support assigning values when the destination is a list. +- Enhance ``Model.set()`` to support assigning values when the destination is a + list. +- Fix a bug in line model that causes incorrect admittance matrix. v1.9.3 (2025-01-05) ------------------- From cae1f24d8b3adce25c8cd5af046da8bd99a561ba Mon Sep 17 00:00:00 2001 From: jinningwang Date: Fri, 18 Apr 2025 15:59:12 -0400 Subject: [PATCH 4/5] Correct a typo in the PSSE DYR parser --- andes/io/psse-dyr.yaml | 4 ++-- docs/source/release-notes.rst | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/andes/io/psse-dyr.yaml b/andes/io/psse-dyr.yaml index 11f652b13..d54025624 100644 --- a/andes/io/psse-dyr.yaml +++ b/andes/io/psse-dyr.yaml @@ -1459,7 +1459,7 @@ REECA1: - PMAX - PMIN - Imax - - Tprod + - Tpord - Vq1 - Iq1 - Vq2 @@ -1520,7 +1520,7 @@ REECA1: PMAX: PMAX PMIN: PMIN Imax: Imax - Tprod: Tprod + Tpord: Tpord Vq1: Vq1 Iq1: Iq1 Vq2: Vq2 diff --git a/docs/source/release-notes.rst b/docs/source/release-notes.rst index c83a1813e..ff16fe80a 100644 --- a/docs/source/release-notes.rst +++ b/docs/source/release-notes.rst @@ -14,6 +14,7 @@ v1.9.4 (2025-xx-xx) - Enhance ``Model.set()`` to support assigning values when the destination is a list. - Fix a bug in line model that causes incorrect admittance matrix. +- Corrected a typo in the PSSE DYR parser, changing "Tprod" to "Tpord". v1.9.3 (2025-01-05) ------------------- From 518882a043dd7260a00ef89cf56c25f0ab0d7bcf Mon Sep 17 00:00:00 2001 From: jinningwang Date: Fri, 18 Apr 2025 16:00:20 -0400 Subject: [PATCH 5/5] Correct a typo in the PSSE DYR parser --- docs/source/release-notes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/release-notes.rst b/docs/source/release-notes.rst index ff16fe80a..5a10ff474 100644 --- a/docs/source/release-notes.rst +++ b/docs/source/release-notes.rst @@ -14,7 +14,7 @@ v1.9.4 (2025-xx-xx) - Enhance ``Model.set()`` to support assigning values when the destination is a list. - Fix a bug in line model that causes incorrect admittance matrix. -- Corrected a typo in the PSSE DYR parser, changing "Tprod" to "Tpord". +- Correct a typo in the PSSE DYR parser, changing "Tprod" to "Tpord". v1.9.3 (2025-01-05) -------------------