ltbams 0.9.9__py3-none-any.whl → 1.0.2__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/__init__.py +4 -11
- ams/_version.py +3 -3
- ams/cases/5bus/pjm5bus_demo.xlsx +0 -0
- ams/cases/5bus/pjm5bus_jumper.xlsx +0 -0
- ams/cases/5bus/pjm5bus_uced.json +1062 -0
- ams/cases/5bus/pjm5bus_uced.xlsx +0 -0
- ams/cases/5bus/pjm5bus_uced_esd1.xlsx +0 -0
- ams/cases/5bus/pjm5bus_uced_ev.xlsx +0 -0
- ams/cases/ieee123/ieee123.xlsx +0 -0
- ams/cases/ieee123/ieee123_regcv1.xlsx +0 -0
- ams/cases/ieee14/ieee14.json +1166 -0
- ams/cases/ieee14/ieee14.raw +92 -0
- ams/cases/ieee14/ieee14_conn.xlsx +0 -0
- ams/cases/ieee14/ieee14_uced.xlsx +0 -0
- ams/cases/ieee39/ieee39.xlsx +0 -0
- ams/cases/ieee39/ieee39_uced.xlsx +0 -0
- ams/cases/ieee39/ieee39_uced_esd1.xlsx +0 -0
- ams/cases/ieee39/ieee39_uced_pvd1.xlsx +0 -0
- ams/cases/ieee39/ieee39_uced_vis.xlsx +0 -0
- ams/cases/matpower/benchmark.json +1594 -0
- ams/cases/matpower/case118.m +787 -0
- ams/cases/matpower/case14.m +129 -0
- ams/cases/matpower/case300.m +1315 -0
- ams/cases/matpower/case39.m +205 -0
- ams/cases/matpower/case5.m +62 -0
- ams/cases/matpower/case_ACTIVSg2000.m +9460 -0
- ams/cases/npcc/npcc.m +644 -0
- ams/cases/npcc/npcc_uced.xlsx +0 -0
- ams/cases/pglib/pglib_opf_case39_epri__api.m +243 -0
- ams/cases/wecc/wecc.m +714 -0
- ams/cases/wecc/wecc_uced.xlsx +0 -0
- ams/cli.py +6 -0
- ams/core/__init__.py +2 -0
- ams/core/documenter.py +652 -0
- ams/core/matprocessor.py +782 -0
- ams/core/model.py +330 -0
- ams/core/param.py +322 -0
- ams/core/service.py +918 -0
- ams/core/symprocessor.py +224 -0
- ams/core/var.py +59 -0
- ams/extension/__init__.py +5 -0
- ams/extension/eva.py +401 -0
- ams/interface.py +1085 -0
- ams/io/__init__.py +133 -0
- ams/io/json.py +82 -0
- ams/io/matpower.py +406 -0
- ams/io/psse.py +6 -0
- ams/io/pypower.py +103 -0
- ams/io/xlsx.py +80 -0
- ams/main.py +81 -4
- ams/models/__init__.py +24 -0
- ams/models/area.py +40 -0
- ams/models/bus.py +52 -0
- ams/models/cost.py +169 -0
- ams/models/distributed/__init__.py +3 -0
- ams/models/distributed/esd1.py +71 -0
- ams/models/distributed/ev.py +60 -0
- ams/models/distributed/pvd1.py +67 -0
- ams/models/group.py +231 -0
- ams/models/info.py +26 -0
- ams/models/line.py +238 -0
- ams/models/renewable/__init__.py +5 -0
- ams/models/renewable/regc.py +119 -0
- ams/models/reserve.py +94 -0
- ams/models/shunt.py +14 -0
- ams/models/static/__init__.py +2 -0
- ams/models/static/gen.py +165 -0
- ams/models/static/pq.py +61 -0
- ams/models/timeslot.py +69 -0
- ams/models/zone.py +49 -0
- ams/opt/__init__.py +12 -0
- ams/opt/constraint.py +175 -0
- ams/opt/exprcalc.py +127 -0
- ams/opt/expression.py +188 -0
- ams/opt/objective.py +174 -0
- ams/opt/omodel.py +432 -0
- ams/opt/optzbase.py +192 -0
- ams/opt/param.py +156 -0
- ams/opt/var.py +233 -0
- ams/pypower/__init__.py +8 -0
- ams/pypower/_compat.py +9 -0
- ams/pypower/core/__init__.py +8 -0
- ams/pypower/core/pips.py +894 -0
- ams/pypower/core/ppoption.py +244 -0
- ams/pypower/core/ppver.py +18 -0
- ams/pypower/core/solver.py +2451 -0
- ams/pypower/eps.py +6 -0
- ams/pypower/idx.py +174 -0
- ams/pypower/io.py +604 -0
- ams/pypower/make/__init__.py +11 -0
- ams/pypower/make/matrices.py +665 -0
- ams/pypower/make/pdv.py +506 -0
- ams/pypower/routines/__init__.py +7 -0
- ams/pypower/routines/cpf.py +513 -0
- ams/pypower/routines/cpf_callbacks.py +114 -0
- ams/pypower/routines/opf.py +1803 -0
- ams/pypower/routines/opffcns.py +1946 -0
- ams/pypower/routines/pflow.py +852 -0
- ams/pypower/toggle.py +1098 -0
- ams/pypower/utils.py +293 -0
- ams/report.py +212 -50
- ams/routines/__init__.py +23 -0
- ams/routines/acopf.py +117 -0
- ams/routines/cpf.py +65 -0
- ams/routines/dcopf.py +241 -0
- ams/routines/dcpf.py +209 -0
- ams/routines/dcpf0.py +196 -0
- ams/routines/dopf.py +150 -0
- ams/routines/ed.py +312 -0
- ams/routines/pflow.py +255 -0
- ams/routines/pflow0.py +113 -0
- ams/routines/routine.py +1033 -0
- ams/routines/rted.py +519 -0
- ams/routines/type.py +160 -0
- ams/routines/uc.py +376 -0
- ams/shared.py +63 -9
- ams/system.py +61 -22
- ams/utils/__init__.py +3 -0
- ams/utils/misc.py +77 -0
- ams/utils/paths.py +257 -0
- docs/Makefile +21 -0
- docs/make.bat +35 -0
- docs/source/_templates/autosummary/base.rst +5 -0
- docs/source/_templates/autosummary/class.rst +35 -0
- docs/source/_templates/autosummary/module.rst +65 -0
- docs/source/_templates/autosummary/module_toctree.rst +66 -0
- docs/source/api.rst +102 -0
- docs/source/conf.py +206 -0
- docs/source/examples/index.rst +34 -0
- docs/source/genmodelref.py +61 -0
- docs/source/genroutineref.py +47 -0
- docs/source/getting_started/copyright.rst +20 -0
- docs/source/getting_started/formats/index.rst +20 -0
- docs/source/getting_started/formats/matpower.rst +183 -0
- docs/source/getting_started/formats/psse.rst +46 -0
- docs/source/getting_started/formats/pypower.rst +223 -0
- docs/source/getting_started/formats/xlsx.png +0 -0
- docs/source/getting_started/formats/xlsx.rst +23 -0
- docs/source/getting_started/index.rst +76 -0
- docs/source/getting_started/install.rst +231 -0
- docs/source/getting_started/overview.rst +26 -0
- docs/source/getting_started/testcase.rst +45 -0
- docs/source/getting_started/verification.rst +13 -0
- docs/source/images/curent.ico +0 -0
- docs/source/images/dcopf_time.png +0 -0
- docs/source/images/sponsors/CURENT_Logo_NameOnTrans.png +0 -0
- docs/source/images/sponsors/CURENT_Logo_Transparent.png +0 -0
- docs/source/images/sponsors/CURENT_Logo_Transparent_Name.png +0 -0
- docs/source/images/sponsors/doe.png +0 -0
- docs/source/index.rst +108 -0
- docs/source/modeling/example.rst +159 -0
- docs/source/modeling/index.rst +17 -0
- docs/source/modeling/model.rst +210 -0
- docs/source/modeling/routine.rst +122 -0
- docs/source/modeling/system.rst +51 -0
- docs/source/release-notes.rst +398 -0
- ltbams-1.0.2.dist-info/METADATA +215 -0
- ltbams-1.0.2.dist-info/RECORD +188 -0
- {ltbams-0.9.9.dist-info → ltbams-1.0.2.dist-info}/WHEEL +1 -1
- ltbams-1.0.2.dist-info/top_level.txt +3 -0
- tests/__init__.py +0 -0
- tests/test_1st_system.py +33 -0
- tests/test_addressing.py +40 -0
- tests/test_andes_mats.py +61 -0
- tests/test_case.py +266 -0
- tests/test_cli.py +34 -0
- tests/test_export_csv.py +89 -0
- tests/test_group.py +83 -0
- tests/test_interface.py +216 -0
- tests/test_io.py +32 -0
- tests/test_jumper.py +27 -0
- tests/test_known_good.py +267 -0
- tests/test_matp.py +437 -0
- tests/test_model.py +54 -0
- tests/test_omodel.py +119 -0
- tests/test_paths.py +22 -0
- tests/test_report.py +251 -0
- tests/test_repr.py +21 -0
- tests/test_routine.py +178 -0
- tests/test_rtn_dcopf.py +101 -0
- tests/test_rtn_dcpf.py +77 -0
- tests/test_rtn_ed.py +279 -0
- tests/test_rtn_pflow.py +219 -0
- tests/test_rtn_rted.py +273 -0
- tests/test_rtn_uc.py +248 -0
- tests/test_service.py +73 -0
- ltbams-0.9.9.dist-info/LICENSE +0 -692
- ltbams-0.9.9.dist-info/METADATA +0 -859
- ltbams-0.9.9.dist-info/RECORD +0 -14
- ltbams-0.9.9.dist-info/top_level.txt +0 -1
- {ltbams-0.9.9.dist-info → ltbams-1.0.2.dist-info}/entry_points.txt +0 -0
ams/opt/param.py
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
"""
|
2
|
+
Module for optimization Param.
|
3
|
+
"""
|
4
|
+
import logging
|
5
|
+
|
6
|
+
from typing import Optional
|
7
|
+
from collections import OrderedDict
|
8
|
+
import re
|
9
|
+
|
10
|
+
import numpy as np
|
11
|
+
|
12
|
+
from andes.core.common import Config
|
13
|
+
|
14
|
+
import cvxpy as cp
|
15
|
+
|
16
|
+
from ams.shared import sps
|
17
|
+
|
18
|
+
from ams.opt import OptzBase, ensure_symbols, ensure_mats_and_parsed
|
19
|
+
|
20
|
+
logger = logging.getLogger(__name__)
|
21
|
+
|
22
|
+
|
23
|
+
class Param(OptzBase):
|
24
|
+
"""
|
25
|
+
Base class for parameters used in a routine.
|
26
|
+
|
27
|
+
Parameters
|
28
|
+
----------
|
29
|
+
no_parse: bool, optional
|
30
|
+
True to skip parsing the parameter.
|
31
|
+
nonneg: bool, optional
|
32
|
+
True to set the parameter as non-negative.
|
33
|
+
nonpos: bool, optional
|
34
|
+
True to set the parameter as non-positive.
|
35
|
+
cplx: bool, optional
|
36
|
+
True to set the parameter as complex, avoiding the use of `complex`.
|
37
|
+
imag: bool, optional
|
38
|
+
True to set the parameter as imaginary.
|
39
|
+
symmetric: bool, optional
|
40
|
+
True to set the parameter as symmetric.
|
41
|
+
diag: bool, optional
|
42
|
+
True to set the parameter as diagonal.
|
43
|
+
hermitian: bool, optional
|
44
|
+
True to set the parameter as hermitian.
|
45
|
+
boolean: bool, optional
|
46
|
+
True to set the parameter as boolean.
|
47
|
+
integer: bool, optional
|
48
|
+
True to set the parameter as integer.
|
49
|
+
pos: bool, optional
|
50
|
+
True to set the parameter as positive.
|
51
|
+
neg: bool, optional
|
52
|
+
True to set the parameter as negative.
|
53
|
+
sparse: bool, optional
|
54
|
+
True to set the parameter as sparse.
|
55
|
+
"""
|
56
|
+
|
57
|
+
def __init__(self,
|
58
|
+
name: Optional[str] = None,
|
59
|
+
info: Optional[str] = None,
|
60
|
+
unit: Optional[str] = None,
|
61
|
+
no_parse: Optional[bool] = False,
|
62
|
+
nonneg: Optional[bool] = False,
|
63
|
+
nonpos: Optional[bool] = False,
|
64
|
+
cplx: Optional[bool] = False,
|
65
|
+
imag: Optional[bool] = False,
|
66
|
+
symmetric: Optional[bool] = False,
|
67
|
+
diag: Optional[bool] = False,
|
68
|
+
hermitian: Optional[bool] = False,
|
69
|
+
boolean: Optional[bool] = False,
|
70
|
+
integer: Optional[bool] = False,
|
71
|
+
pos: Optional[bool] = False,
|
72
|
+
neg: Optional[bool] = False,
|
73
|
+
sparse: Optional[bool] = False,
|
74
|
+
):
|
75
|
+
OptzBase.__init__(self, name=name, info=info, unit=unit)
|
76
|
+
self.no_parse = no_parse # True to skip parsing the parameter
|
77
|
+
self.sparse = sparse
|
78
|
+
|
79
|
+
self.config = Config(name=self.class_name) # `config` that can be exported
|
80
|
+
|
81
|
+
self.config.add(OrderedDict((('nonneg', nonneg),
|
82
|
+
('nonpos', nonpos),
|
83
|
+
('complex', cplx),
|
84
|
+
('imag', imag),
|
85
|
+
('symmetric', symmetric),
|
86
|
+
('diag', diag),
|
87
|
+
('hermitian', hermitian),
|
88
|
+
('boolean', boolean),
|
89
|
+
('integer', integer),
|
90
|
+
('pos', pos),
|
91
|
+
('neg', neg),
|
92
|
+
)))
|
93
|
+
|
94
|
+
@ensure_symbols
|
95
|
+
def parse(self):
|
96
|
+
"""
|
97
|
+
Parse the parameter.
|
98
|
+
|
99
|
+
Returns
|
100
|
+
-------
|
101
|
+
bool
|
102
|
+
Returns True if the parsing is successful, False otherwise.
|
103
|
+
"""
|
104
|
+
sub_map = self.om.rtn.syms.sub_map
|
105
|
+
code_param = "param(**config)"
|
106
|
+
for pattern, replacement, in sub_map.items():
|
107
|
+
try:
|
108
|
+
code_param = re.sub(pattern, replacement, code_param)
|
109
|
+
except Exception as e:
|
110
|
+
raise Exception(f"Error in parsing param <{self.name}>.\n{e}")
|
111
|
+
self.code = code_param
|
112
|
+
return True
|
113
|
+
|
114
|
+
@ensure_mats_and_parsed
|
115
|
+
def evaluate(self):
|
116
|
+
"""
|
117
|
+
Evaluate the parameter.
|
118
|
+
"""
|
119
|
+
if self.no_parse:
|
120
|
+
return True
|
121
|
+
|
122
|
+
config = self.config.as_dict()
|
123
|
+
try:
|
124
|
+
msg = f"Parameter <{self.name}> is set as sparse, "
|
125
|
+
msg += "but the value is not sparse."
|
126
|
+
if self.sparse:
|
127
|
+
self.v = sps.csr_matrix(self.v)
|
128
|
+
|
129
|
+
# Create the cvxpy.Parameter object
|
130
|
+
if isinstance(self.v, np.ndarray):
|
131
|
+
self.optz = cp.Parameter(shape=self.v.shape, **config)
|
132
|
+
else:
|
133
|
+
self.optz = cp.Parameter(**config)
|
134
|
+
self.optz.value = self.v
|
135
|
+
except ValueError:
|
136
|
+
msg = f"Parameter <{self.name}> has non-numeric value, "
|
137
|
+
msg += "set `no_parse=True`."
|
138
|
+
logger.warning(msg)
|
139
|
+
self.no_parse = True
|
140
|
+
return True
|
141
|
+
except Exception as e:
|
142
|
+
raise Exception(f"Error in evaluating Param <{self.name}>.\n{e}")
|
143
|
+
return True
|
144
|
+
|
145
|
+
def update(self):
|
146
|
+
"""
|
147
|
+
Update the Parameter value.
|
148
|
+
"""
|
149
|
+
# NOTE: skip no_parse parameters
|
150
|
+
if self.optz is None:
|
151
|
+
return None
|
152
|
+
self.optz.value = self.v
|
153
|
+
return True
|
154
|
+
|
155
|
+
def __repr__(self):
|
156
|
+
return f'{self.__class__.__name__}: {self.name}'
|
ams/opt/var.py
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
"""
|
2
|
+
Module for optimization Var.
|
3
|
+
"""
|
4
|
+
import logging
|
5
|
+
|
6
|
+
from typing import Optional, Union
|
7
|
+
from collections import OrderedDict
|
8
|
+
import re
|
9
|
+
|
10
|
+
import numpy as np
|
11
|
+
|
12
|
+
from andes.core.common import Config
|
13
|
+
|
14
|
+
import cvxpy as cp
|
15
|
+
|
16
|
+
from ams.utils import pretty_long_message
|
17
|
+
from ams.shared import _prefix, _max_length
|
18
|
+
|
19
|
+
from ams.opt import OptzBase, ensure_symbols, ensure_mats_and_parsed
|
20
|
+
|
21
|
+
logger = logging.getLogger(__name__)
|
22
|
+
|
23
|
+
|
24
|
+
class Var(OptzBase):
|
25
|
+
"""
|
26
|
+
Base class for variables used in a routine.
|
27
|
+
|
28
|
+
When `horizon` is provided, the variable will be expanded to a matrix,
|
29
|
+
where rows are indexed by the source variable index and columns are
|
30
|
+
indexed by the horizon index.
|
31
|
+
|
32
|
+
Parameters
|
33
|
+
----------
|
34
|
+
info : str, optional
|
35
|
+
Descriptive information
|
36
|
+
unit : str, optional
|
37
|
+
Unit
|
38
|
+
tex_name : str
|
39
|
+
LaTeX-formatted variable symbol. Defaults to the value of ``name``.
|
40
|
+
name : str, optional
|
41
|
+
Variable name. One should typically assigning the name directly because
|
42
|
+
it will be automatically assigned by the model. The value of ``name``
|
43
|
+
will be the symbol name to be used in expressions.
|
44
|
+
src : str, optional
|
45
|
+
Source variable name. Defaults to the value of ``name``.
|
46
|
+
model : str, optional
|
47
|
+
Name of the owner model or group.
|
48
|
+
horizon : ams.routines.RParam, optional
|
49
|
+
Horizon idx.
|
50
|
+
nonneg : bool, optional
|
51
|
+
Non-negative variable
|
52
|
+
nonpos : bool, optional
|
53
|
+
Non-positive variable
|
54
|
+
cplx : bool, optional
|
55
|
+
Complex variable
|
56
|
+
imag : bool, optional
|
57
|
+
Imaginary variable
|
58
|
+
symmetric : bool, optional
|
59
|
+
Symmetric variable
|
60
|
+
diag : bool, optional
|
61
|
+
Diagonal variable
|
62
|
+
psd : bool, optional
|
63
|
+
Positive semi-definite variable
|
64
|
+
nsd : bool, optional
|
65
|
+
Negative semi-definite variable
|
66
|
+
hermitian : bool, optional
|
67
|
+
Hermitian variable
|
68
|
+
boolean : bool, optional
|
69
|
+
Boolean variable
|
70
|
+
integer : bool, optional
|
71
|
+
Integer variable
|
72
|
+
pos : bool, optional
|
73
|
+
Positive variable
|
74
|
+
neg : bool, optional
|
75
|
+
Negative variable
|
76
|
+
|
77
|
+
Attributes
|
78
|
+
----------
|
79
|
+
a : np.ndarray
|
80
|
+
Variable address.
|
81
|
+
_v : np.ndarray
|
82
|
+
Local-storage of the variable value.
|
83
|
+
rtn : ams.routines.Routine
|
84
|
+
The owner routine instance.
|
85
|
+
"""
|
86
|
+
|
87
|
+
def __init__(self,
|
88
|
+
name: Optional[str] = None,
|
89
|
+
tex_name: Optional[str] = None,
|
90
|
+
info: Optional[str] = None,
|
91
|
+
src: Optional[str] = None,
|
92
|
+
unit: Optional[str] = None,
|
93
|
+
model: Optional[str] = None,
|
94
|
+
shape: Optional[Union[tuple, int]] = None,
|
95
|
+
v0: Optional[str] = None,
|
96
|
+
horizon: Optional[str] = None,
|
97
|
+
nonneg: Optional[bool] = False,
|
98
|
+
nonpos: Optional[bool] = False,
|
99
|
+
cplx: Optional[bool] = False,
|
100
|
+
imag: Optional[bool] = False,
|
101
|
+
symmetric: Optional[bool] = False,
|
102
|
+
diag: Optional[bool] = False,
|
103
|
+
psd: Optional[bool] = False,
|
104
|
+
nsd: Optional[bool] = False,
|
105
|
+
hermitian: Optional[bool] = False,
|
106
|
+
boolean: Optional[bool] = False,
|
107
|
+
integer: Optional[bool] = False,
|
108
|
+
pos: Optional[bool] = False,
|
109
|
+
neg: Optional[bool] = False,
|
110
|
+
):
|
111
|
+
self.name = name
|
112
|
+
self.info = info
|
113
|
+
self.unit = unit
|
114
|
+
|
115
|
+
self.tex_name = tex_name if tex_name else name
|
116
|
+
# variable internal index inside a model (assigned in run time)
|
117
|
+
self.id = None
|
118
|
+
OptzBase.__init__(self, name=name, info=info, unit=unit, model=model)
|
119
|
+
self.src = src
|
120
|
+
self.v0 = v0
|
121
|
+
self.horizon = horizon
|
122
|
+
self._shape = shape
|
123
|
+
self._v = None
|
124
|
+
self.a: np.ndarray = np.array([], dtype=int)
|
125
|
+
|
126
|
+
self.config = Config(name=self.class_name) # `config` that can be exported
|
127
|
+
|
128
|
+
self.config.add(OrderedDict((('nonneg', nonneg),
|
129
|
+
('nonpos', nonpos),
|
130
|
+
('complex', cplx),
|
131
|
+
('imag', imag),
|
132
|
+
('symmetric', symmetric),
|
133
|
+
('diag', diag),
|
134
|
+
('psd', psd),
|
135
|
+
('nsd', nsd),
|
136
|
+
('hermitian', hermitian),
|
137
|
+
('boolean', boolean),
|
138
|
+
('integer', integer),
|
139
|
+
('pos', pos),
|
140
|
+
('neg', neg),
|
141
|
+
)))
|
142
|
+
|
143
|
+
@property
|
144
|
+
def v(self):
|
145
|
+
"""
|
146
|
+
Return the CVXPY variable value.
|
147
|
+
"""
|
148
|
+
if self.optz is None:
|
149
|
+
return None
|
150
|
+
if self.optz.value is None:
|
151
|
+
try:
|
152
|
+
shape = self.optz.shape
|
153
|
+
return np.zeros(shape)
|
154
|
+
except AttributeError:
|
155
|
+
return None
|
156
|
+
else:
|
157
|
+
return self.optz.value
|
158
|
+
|
159
|
+
@v.setter
|
160
|
+
def v(self, value):
|
161
|
+
if self.optz is None:
|
162
|
+
logger.info(f"Variable <{self.name}> is not initialized yet.")
|
163
|
+
else:
|
164
|
+
self.optz.value = value
|
165
|
+
|
166
|
+
@ensure_symbols
|
167
|
+
def parse(self):
|
168
|
+
"""
|
169
|
+
Parse the variable.
|
170
|
+
"""
|
171
|
+
sub_map = self.om.rtn.syms.sub_map
|
172
|
+
# NOTE: number of rows is the size of the source variable
|
173
|
+
if self.owner is not None:
|
174
|
+
nr = self.owner.n
|
175
|
+
nc = 0
|
176
|
+
if self.horizon:
|
177
|
+
# NOTE: numer of columns is the horizon if exists
|
178
|
+
nc = int(self.horizon.n)
|
179
|
+
shape = (nr, nc)
|
180
|
+
else:
|
181
|
+
shape = (nr,)
|
182
|
+
elif isinstance(self._shape, int):
|
183
|
+
shape = (self._shape,)
|
184
|
+
nr = shape
|
185
|
+
nc = 0
|
186
|
+
elif isinstance(self._shape, tuple):
|
187
|
+
shape = self._shape
|
188
|
+
nr = shape[0]
|
189
|
+
nc = shape[1] if len(shape) > 1 else 0
|
190
|
+
else:
|
191
|
+
raise ValueError(f"Invalid shape {self._shape}.")
|
192
|
+
code_var = f"var({shape}, **config)"
|
193
|
+
logger.debug(f" - Var <{self.name}>: {self.code}")
|
194
|
+
for pattern, replacement, in sub_map.items():
|
195
|
+
try:
|
196
|
+
code_var = re.sub(pattern, replacement, code_var)
|
197
|
+
except Exception as e:
|
198
|
+
raise Exception(f"Error in parsing var <{self.name}>.\n{e}")
|
199
|
+
self.code = code_var
|
200
|
+
return True
|
201
|
+
|
202
|
+
@ensure_mats_and_parsed
|
203
|
+
def evaluate(self):
|
204
|
+
"""
|
205
|
+
Evaluate the variable.
|
206
|
+
|
207
|
+
Returns
|
208
|
+
-------
|
209
|
+
bool
|
210
|
+
Returns True if the evaluation is successful, False otherwise.
|
211
|
+
"""
|
212
|
+
# NOTE: in CVXPY, Config only allow lower case letters
|
213
|
+
config = {} # used in `self.code`
|
214
|
+
for k, v in self.config.as_dict().items():
|
215
|
+
if k == 'psd':
|
216
|
+
config['PSD'] = v
|
217
|
+
elif k == 'nsd':
|
218
|
+
config['NSD'] = v
|
219
|
+
elif k == 'bool':
|
220
|
+
config['boolean'] = v
|
221
|
+
else:
|
222
|
+
config[k] = v
|
223
|
+
msg = f" - Var <{self.name}>: {self.code}"
|
224
|
+
logger.debug(pretty_long_message(msg, _prefix, max_length=_max_length))
|
225
|
+
try:
|
226
|
+
local_vars = {'self': self, 'config': config, 'cp': cp}
|
227
|
+
self.optz = eval(self.code, {}, local_vars)
|
228
|
+
except Exception as e:
|
229
|
+
raise Exception(f"Error in evaluating Var <{self.name}>.\n{e}")
|
230
|
+
return True
|
231
|
+
|
232
|
+
def __repr__(self):
|
233
|
+
return f'{self.__class__.__name__}: {self.owner.__class__.__name__}.{self.name}'
|
ams/pypower/__init__.py
ADDED
ams/pypower/_compat.py
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
"""
|
2
|
+
Module for the core of PYPOWER.
|
3
|
+
"""
|
4
|
+
|
5
|
+
from ams.pypower.core.ppoption import ppoption # NOQA
|
6
|
+
from ams.pypower.core.pips import pips, pipsver, pipsopf_solver # NOQA
|
7
|
+
from ams.pypower.core.ppver import ppver # NOQA
|
8
|
+
from ams.pypower.core.solver import ipoptopf_solver # NOQA
|