Skip to content

Commit

Permalink
Merge pull request #77 from CURENT/misc
Browse files Browse the repository at this point in the history
Fix ANDES conversion under parameter updating
  • Loading branch information
jinningwang authored Apr 7, 2024
2 parents fbdb830 + 06992a1 commit c67a909
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
9 changes: 7 additions & 2 deletions ams/interop/andes.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ def to_andes(system, addfile=None,

for mdl_name, mdl_cols in pflow_dict.items():
mdl = getattr(system, mdl_name)
# refresh cache to get the latest data
mdl.cache.refresh("df_in")
mdl.cache.refresh("df_in") # refresh cache
for row in mdl.cache.df_in[mdl_cols].to_dict(orient='records'):
adsys.add(mdl_name, row)
# FIXME: this is a temporary fix to ensure parameters are latest values
# the reason is in ANDES, model.cache.df_in is not the latest values
# if altered, even after cache.refresh("df_in")
for num_name, num_param in adsys.models[mdl_name].num_params.items():
if num_name in mdl.__dict__.keys():
num_param.v = mdl.__dict__[num_name].v

_, s = elapsed(t0)

Expand Down
2 changes: 1 addition & 1 deletion ams/routines/dcopf.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def unpack(self, **kwargs):
self.system.recent = self.system.routines[self.class_name]
return True

def dc2ac(self, kloss=1.1, **kwargs):
def dc2ac(self, kloss=1.0, **kwargs):
"""
Convert the DCOPF results with ACOPF.
Expand Down
2 changes: 1 addition & 1 deletion ams/routines/rted.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def __init__(self, system, config):
cost += f'+ t dot sum({_to_sum})'
self.obj.e_str = cost

def dc2ac(self, kloss=1.1, **kwargs):
def dc2ac(self, kloss=1.0, **kwargs):
"""
Convert the RTED results with ACOPF.
Expand Down
18 changes: 18 additions & 0 deletions tests/test_andes.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,24 @@ def test_convert(self):
for mdl in pflow_mdls:
self.assertTrue(sp.models[mdl].as_df().equals(sa.PFlow.models[mdl].as_df()))

def test_convert_after_update(self):
"""
Test conversion from AMS case to ANDES case after updating parameters.
"""
for ad_case, am_case in zip(self.ad_cases, self.am_cases):
sp = ams.load(ams.get_case(am_case),
setup=True, no_output=True, default_config=True,)
# record initial values
pq_idx = sp.PQ.idx.v
p0 = sp.PQ.p0.v.copy()
sa = to_andes(sp, setup=False, no_output=True, default_config=True)
# before update
np.testing.assert_array_equal(sp.PQ.p0.v, sa.PQ.p0.v)
# after update
sp.PQ.set(src='p0', attr='v', idx=pq_idx, value=0.9*p0)
sa = to_andes(sp, setup=False, no_output=True, default_config=True)
np.testing.assert_array_equal(sp.PQ.p0.v, sa.PQ.p0.v)

def test_extra_dyn(self):
"""
Test conversion when extra dynamic models exist.
Expand Down

0 comments on commit c67a909

Please sign in to comment.