Skip to content

Commit

Permalink
refactor: add checking of sysLoss version when loading System from file
Browse files Browse the repository at this point in the history
  • Loading branch information
geddy11 committed Oct 12, 2024
1 parent bee1610 commit 29eb5a4
Show file tree
Hide file tree
Showing 5 changed files with 365 additions and 8 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ rich = ">=12.0"
toml = ">=0.10.2"
matplotlib = "^3.0"
tqdm = ">=4.63"
packaging = ">=21.1"

[tool.poetry.dev-dependencies]
pytest = "^8.0"
Expand All @@ -36,6 +37,7 @@ jupyter-book = "^1.0.0"
toml = ">=0.10.2"
pandas = "^2.0"
tqdm = ">=4.63"
packaging = ">=21.1"

[tool.poetry.group.docs]
optional = true
Expand All @@ -48,6 +50,7 @@ rich = ">=12.0"
toml = ">=0.10.2"
matplotlib = "^3.0"
tqdm = ">=4.63"
packaging = ">=21.1"

[tool.semantic_release]
allow_zero_version = false
Expand Down
9 changes: 5 additions & 4 deletions src/sysloss/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class _ComponentTypes(Enum):

MAX_DEFAULT = 1.0e6
IQ_DEFAULT = 0.0
IG_DEFAULT = 0.0
IIS_DEFAULT = 0.0
RS_DEFAULT = 0.0
RT_DEFAULT = 0.0
Expand Down Expand Up @@ -1144,7 +1145,7 @@ class LinReg:
If vi - vo < vdrop, the output voltage is reduced to vi - vdrop during analysis.
The regulator ground current can be either a constant (float) or interpolated.
The regulator ground current (iq) can be either a constant (float) or interpolated.
Interpolation data dict for ground current can be either 1D (function of output current only):
``iq = {vi = [5.0], io = [0.0, 0.05, 0.1], iq = [[2.0e-6, 0.5e-3, 0.85e-3]]}``
Expand Down Expand Up @@ -1219,8 +1220,8 @@ def __init__(
for v in iq["vi"]:
cur += iq["io"]
volt += len(iq["io"]) * [v]
iqi = np.asarray(iq["iq"]).reshape(1, -1)[0].tolist()
self._ipr = _Interp2d(cur, volt, iqi)
igi = np.asarray(iq["iq"]).reshape(1, -1)[0].tolist()
self._ipr = _Interp2d(cur, volt, igi)
else:
self._ipr = _Interp0d(abs(iq))
self._params["iq"] = iq
Expand All @@ -1244,7 +1245,7 @@ def from_file(cls, name: str, *, fname: str):

v = _get_mand(config["linreg"], "vo")
vd = _get_opt(config["linreg"], "vdrop", VDROP_DEFAULT)
iq = _get_opt(config["linreg"], "iq", IQ_DEFAULT)
iq = _get_opt(config["linreg"], "iq", IG_DEFAULT)
lim = _get_opt(config, "limits", LIMITS_DEFAULT)
iis = _get_opt(config["linreg"], "iis", IIS_DEFAULT)
rt = _get_opt(config["linreg"], "rt", RT_DEFAULT)
Expand Down
17 changes: 13 additions & 4 deletions src/sysloss/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from scipy.interpolate import LinearNDInterpolator
from typing import Callable
import warnings
from packaging import version
from tqdm import TqdmExperimentalWarning

warnings.filterwarnings("ignore", category=TqdmExperimentalWarning)
Expand Down Expand Up @@ -109,6 +110,11 @@ def from_file(cls, fname: str):
System
A new `System` instance.
Raises
------
ValueError
If file was created by a newer version of sysLoss.
Examples
--------
>>> sys = System.from_file("my_system.json")
Expand All @@ -121,6 +127,13 @@ def from_file(cls, fname: str):
sysparams = _get_mand(sys, "system")
sysname = _get_mand(sysparams, "name")
ver = _get_mand(sysparams, "version")
# check version compatability
if version.parse(sysloss.__version__) < version.parse(ver):
raise ValueError(
'"{}" was created by sysLoss version {} - please update sysLoss to load this file'.format(
fname, ver
)
)
# add sources
for e in range(1, len(entires)):
vo = _get_mand(sys[entires[e]]["params"], "vo")
Expand All @@ -135,14 +148,12 @@ def from_file(cls, fname: str):
for p in list(sys[entires[e]]["childs"].keys()):
for c in sys[entires[e]]["childs"][p]:
cname = _get_mand(c["params"], "name")
# print(" " + cname)
limits = _get_opt(c, "limits", LIMITS_DEFAULT)
iq = _get_opt(c["params"], "iq", 0.0)
iis = _get_opt(c["params"], "iis", 0.0)
if c["type"] == "CONVERTER":
vo = _get_mand(c["params"], "vo")
eff = _get_mand(c["params"], "eff")
# af = _get_opt(c["params"], "active_phases", [])
self.add_comp(
p,
comp=Converter(
Expand All @@ -152,7 +163,6 @@ def from_file(cls, fname: str):
iq=iq,
limits=limits,
iis=iis,
# active_phases=af,
),
)
elif c["type"] == "LINREG":
Expand All @@ -168,7 +178,6 @@ def from_file(cls, fname: str):
iq=iq,
limits=limits,
iis=iis,
# active_phases=af,
),
)
elif c["type"] == "SLOSS":
Expand Down
Loading

0 comments on commit 29eb5a4

Please sign in to comment.