paramrf 0.22.0__tar.gz → 0.23.2__tar.gz
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.
- {paramrf-0.22.0/paramrf.egg-info → paramrf-0.23.2}/PKG-INFO +1 -1
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/api/index.rst +1 -1
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/examples/parameter_and_model_manipulation.rst +3 -3
- {paramrf-0.22.0 → paramrf-0.23.2}/paper/paper.md +2 -2
- {paramrf-0.22.0 → paramrf-0.23.2/paramrf.egg-info}/PKG-INFO +1 -1
- {paramrf-0.22.0 → paramrf-0.23.2}/paramrf.egg-info/SOURCES.txt +6 -2
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/__init__.py +3 -3
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/infer/base.py +4 -2
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/__init__.py +45 -11
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/base.py +38 -40
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/components/__init__.py +2 -2
- paramrf-0.23.2/pmrf/models/components/ideal.py +314 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/components/lines/uniform.py +42 -4
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/components/lumped.py +131 -97
- paramrf-0.23.2/pmrf/models/components/sections.py +354 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/composite/__init__.py +2 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/composite/interconnected.py +140 -16
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/composite/nodal.py +6 -5
- paramrf-0.23.2/pmrf/models/composite/topological.py +150 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/optimize/base.py +8 -3
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/parameters.py +4 -4
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/rf/__init__.py +4 -2
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/rf/cascades.py +7 -30
- paramrf-0.23.2/pmrf/rf/connections/__init__.py +3 -0
- paramrf-0.22.0/pmrf/rf/connections.py → paramrf-0.23.2/pmrf/rf/connections/s_arbitrary.py +54 -119
- paramrf-0.23.2/pmrf/rf/connections/s_common.py +111 -0
- paramrf-0.23.2/pmrf/rf/connections/y_arbitrary.py +127 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/rf/terminations.py +12 -1
- {paramrf-0.22.0 → paramrf-0.23.2}/pyproject.toml +1 -1
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_models/test_topological.py +7 -7
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_naming.py +1 -1
- paramrf-0.22.0/pmrf/models/components/ideal.py +0 -61
- paramrf-0.22.0/pmrf/models/components/topological.py +0 -362
- {paramrf-0.22.0 → paramrf-0.23.2}/.github/workflows/docs.yml +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/.github/workflows/draft-pdf.yml +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/.github/workflows/publish.yml +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/.github/workflows/tests.yml +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/.gitignore +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/CONTRIBUTING.md +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/LICENSE +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/README.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/assets/logo.png +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/Makefile +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/_static/custom.css +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/_templates/autosummary/class.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/_templates/autosummary/function.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/_templates/autosummary/module.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/api/models.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/conf.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/core_concepts/core_primitives.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/core_concepts/index.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/core_concepts/jax_overview.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/core_concepts/optimization_and_inference.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/examples/auto_differentiation.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/examples/cascading_and_terminating.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/examples/circuit_clc.png +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/examples/circuit_models.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/examples/custom_composite_models.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/examples/custom_parametric_models.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/examples/index.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/examples/model_optimization.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/index.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/license.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/make.bat +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/skrf_comparison.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/tutorials/1_cable_fitting.ipynb +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/tutorials/data/CBN-1.5FT-SMSM.s2p +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/docs/tutorials/index.rst +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/paper/paper.bib +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/paper/rlc.png +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/paramrf.egg-info/dependency_links.txt +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/paramrf.egg-info/requires.txt +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/paramrf.egg-info/top_level.txt +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/constraints.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/covariance_kernels.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/discrepancy_models.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/distributions.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/evaluators.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/fitting/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/fitting/minimize.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/fitting/result.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/fitting/routers.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/fitting/sample.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/frequency.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/infer/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/infer/backends/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/infer/backends/blackjax.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/infer/backends/polychord.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/infer/result.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/infer/sample.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/likelihoods.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/losses.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/math/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/math/aggregations.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/math/conversions.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/math/losses.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/math/misc.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/adapters/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/adapters/base.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/adapters/bridge.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/adapters/callable.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/adapters/static.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/components/lines/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/components/lines/nonuniform.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/composite/transformed.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/composite/wrapped.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/surrogates/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/surrogates/expansion.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/models/surrogates/rational.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/network_collection.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/noise_models.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/optimize/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/optimize/backends/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/optimize/backends/jaxopt.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/optimize/backends/optimistix.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/optimize/backends/scipy.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/optimize/minimize.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/optimize/result.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/problem.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/rf/conversions.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/serialization.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/solve/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/utils/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/utils/array.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/utils/network.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/utils/optix.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/utils/random.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/utils/rf.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/utils/tree.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/utils/type.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/viz/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/pmrf/viz/plots.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/setup.cfg +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/__init__.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/data/10m_cable.s2p +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_autodiff.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_evaluators.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_fitting_minimize.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_fitting_routers.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_fitting_sample.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_frequency.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_infer_base.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_infer_sample.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_model.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_models/test_adapters.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_models/test_interconnected.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_models/test_lines.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_models/test_lumped.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_models/test_nodal.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_models/test_transformed.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_optimize_base.py +0 -0
- {paramrf-0.22.0 → paramrf-0.23.2}/tests/test_optimize_minimize.py +0 -0
|
@@ -19,8 +19,8 @@ Let's first define a custom RLC composite model to manipulate:
|
|
|
19
19
|
|
|
20
20
|
class RLC(prf.Model):
|
|
21
21
|
res: Resistor = Resistor(R=100.0)
|
|
22
|
-
ind: Inductor = Inductor(L=prf.
|
|
23
|
-
cap: Capacitor = Capacitor(C=prf.
|
|
22
|
+
ind: Inductor = Inductor(L=prf.Variable(2.0, scale=1e-9))
|
|
23
|
+
cap: Capacitor = Capacitor(C=prf.Variable(1.0, scale=1e-12))
|
|
24
24
|
|
|
25
25
|
def build(self) -> prf.Model:
|
|
26
26
|
return self.res ** self.ind ** self.cap
|
|
@@ -48,7 +48,7 @@ Using :meth:`pmrf.Model.at`, we can traverse down the model tree to focus on spe
|
|
|
48
48
|
|
|
49
49
|
.. code-block:: python
|
|
50
50
|
|
|
51
|
-
rlc_R200 = rlc.at(lambda m: m.res.R).set(prf.
|
|
51
|
+
rlc_R200 = rlc.at(lambda m: m.res.R).set(prf.Variable(200.0))
|
|
52
52
|
rlc_fixed = rlc.at(lambda m: m.cap.C).set(prf.Fixed(rlc.cap.C))
|
|
53
53
|
|
|
54
54
|
Since a model's structure is not rigid, we can also completely swap out components:
|
|
@@ -58,8 +58,8 @@ import pmrf as prf
|
|
|
58
58
|
from pmrf.models import Resistor, Inductor, Capacitor
|
|
59
59
|
|
|
60
60
|
res = Resistor(50)
|
|
61
|
-
ind = Inductor(prf.
|
|
62
|
-
cap = Capacitor(prf.
|
|
61
|
+
ind = Inductor(prf.Variable(1.0, scale=1e-9))
|
|
62
|
+
cap = Capacitor(prf.Variable(1.0, scale=1e-12))
|
|
63
63
|
model = res ** ind ** cap
|
|
64
64
|
|
|
65
65
|
goal = prf.evaluators.Goal('s11_db', '<', -20)
|
|
@@ -85,13 +85,14 @@ pmrf/models/adapters/static.py
|
|
|
85
85
|
pmrf/models/components/__init__.py
|
|
86
86
|
pmrf/models/components/ideal.py
|
|
87
87
|
pmrf/models/components/lumped.py
|
|
88
|
-
pmrf/models/components/
|
|
88
|
+
pmrf/models/components/sections.py
|
|
89
89
|
pmrf/models/components/lines/__init__.py
|
|
90
90
|
pmrf/models/components/lines/nonuniform.py
|
|
91
91
|
pmrf/models/components/lines/uniform.py
|
|
92
92
|
pmrf/models/composite/__init__.py
|
|
93
93
|
pmrf/models/composite/interconnected.py
|
|
94
94
|
pmrf/models/composite/nodal.py
|
|
95
|
+
pmrf/models/composite/topological.py
|
|
95
96
|
pmrf/models/composite/transformed.py
|
|
96
97
|
pmrf/models/composite/wrapped.py
|
|
97
98
|
pmrf/models/surrogates/__init__.py
|
|
@@ -107,9 +108,12 @@ pmrf/optimize/backends/optimistix.py
|
|
|
107
108
|
pmrf/optimize/backends/scipy.py
|
|
108
109
|
pmrf/rf/__init__.py
|
|
109
110
|
pmrf/rf/cascades.py
|
|
110
|
-
pmrf/rf/connections.py
|
|
111
111
|
pmrf/rf/conversions.py
|
|
112
112
|
pmrf/rf/terminations.py
|
|
113
|
+
pmrf/rf/connections/__init__.py
|
|
114
|
+
pmrf/rf/connections/s_arbitrary.py
|
|
115
|
+
pmrf/rf/connections/s_common.py
|
|
116
|
+
pmrf/rf/connections/y_arbitrary.py
|
|
113
117
|
pmrf/solve/__init__.py
|
|
114
118
|
pmrf/utils/__init__.py
|
|
115
119
|
pmrf/utils/array.py
|
|
@@ -30,12 +30,12 @@ from pmrf.frequency import Frequency as Frequency
|
|
|
30
30
|
|
|
31
31
|
#: The canonical type hint for a parameter in a model.
|
|
32
32
|
#: Parameters should be created using factories in :mod:`pmrf.parameters`,
|
|
33
|
-
#: most of which are re-exported at root (e.g. :func:`pmrf.
|
|
33
|
+
#: most of which are re-exported at root (e.g. :func:`pmrf.Variable`, :func:`pmrf.Fixed`, :func:`pmrf.Bounded`).
|
|
34
34
|
Param: TypeAlias = parax.AbstractVariable | Inexact[Array, "..."]
|
|
35
35
|
from pmrf.parameters import (
|
|
36
36
|
param as param,
|
|
37
37
|
as_param as as_param,
|
|
38
|
-
|
|
38
|
+
Variable as Variable,
|
|
39
39
|
Fixed as Fixed,
|
|
40
40
|
Bounded as Bounded,
|
|
41
41
|
Constrained as Constrained,
|
|
@@ -92,7 +92,7 @@ __all__ = [
|
|
|
92
92
|
"Param",
|
|
93
93
|
"param",
|
|
94
94
|
"as_param",
|
|
95
|
-
"
|
|
95
|
+
"Variable",
|
|
96
96
|
"Fixed",
|
|
97
97
|
"Bounded",
|
|
98
98
|
"Constrained",
|
|
@@ -5,6 +5,7 @@ Base inference functions and classes.
|
|
|
5
5
|
from typing import Callable, Any, Optional, TypeVar, TypeAlias
|
|
6
6
|
import abc
|
|
7
7
|
|
|
8
|
+
import numpy as np
|
|
8
9
|
import jax.numpy as jnp
|
|
9
10
|
import jax
|
|
10
11
|
from jaxtyping import Array, PyTree, Scalar
|
|
@@ -237,12 +238,13 @@ def sample(
|
|
|
237
238
|
A tuple of `(batched_model, payload, metrics)`.
|
|
238
239
|
"""
|
|
239
240
|
# Filtering/unwrapping
|
|
240
|
-
is_dynamic
|
|
241
|
+
is_dynamic = lambda x: prx.probability.is_dynamic(x) and not isinstance(x, np.ndarray)
|
|
242
|
+
is_leaf = prx.probability.is_leaf
|
|
241
243
|
dynamic, static = eqx.partition(model, is_dynamic, is_leaf=is_leaf)
|
|
242
244
|
params = prx.unwrap(dynamic, only_if=prx.is_probabilistic)
|
|
243
245
|
|
|
244
246
|
try:
|
|
245
|
-
eqx.combine(params, static)
|
|
247
|
+
eqx.combine(params, static, is_leaf=is_leaf)
|
|
246
248
|
except Exception as e:
|
|
247
249
|
raise Exception(f"Error re-combining params and static. Error: {e}")
|
|
248
250
|
|
|
@@ -10,12 +10,17 @@ from pmrf.models.base import (
|
|
|
10
10
|
validate as validate,
|
|
11
11
|
)
|
|
12
12
|
|
|
13
|
+
# Adapters
|
|
13
14
|
from pmrf.models.adapters.base import (
|
|
14
15
|
AbstractDiscrete as AbstractDiscrete,
|
|
15
16
|
AbstractSingleProperty as AbstractSingleProperty,
|
|
16
17
|
AbstractSingleDiscreteProperty as AbstractSingleDiscreteProperty,
|
|
17
18
|
)
|
|
18
|
-
|
|
19
|
+
|
|
20
|
+
from pmrf.models.adapters.bridge import (
|
|
21
|
+
Host as Host
|
|
22
|
+
)
|
|
23
|
+
|
|
19
24
|
from pmrf.models.adapters.static import (
|
|
20
25
|
Measured as Measured,
|
|
21
26
|
SModel as SModel,
|
|
@@ -23,16 +28,28 @@ from pmrf.models.adapters.static import (
|
|
|
23
28
|
YModel as YModel,
|
|
24
29
|
ZModel as ZModel,
|
|
25
30
|
)
|
|
31
|
+
|
|
26
32
|
from pmrf.models.adapters.callable import (
|
|
27
33
|
ContinuousCallable as ContinuousCallable,
|
|
28
34
|
DiscreteCallable as DiscreteCallable,
|
|
29
35
|
)
|
|
36
|
+
|
|
37
|
+
# Components
|
|
30
38
|
from pmrf.models.components.ideal import (
|
|
39
|
+
Load as Load,
|
|
40
|
+
Short as Short,
|
|
41
|
+
Open as Open,
|
|
42
|
+
Match as Match,
|
|
31
43
|
Port as Port,
|
|
32
44
|
Ground as Ground,
|
|
33
45
|
SourceConverter as SourceConverter,
|
|
34
46
|
Transformer as Transformer,
|
|
47
|
+
Splitter as Splitter,
|
|
48
|
+
Tee as Tee,
|
|
49
|
+
Attenuator as Attenuator,
|
|
50
|
+
DirectionalCoupler as DirectionalCoupler,
|
|
35
51
|
)
|
|
52
|
+
|
|
36
53
|
from pmrf.models.components.lines import (
|
|
37
54
|
TransmissionLine as TransmissionLine,
|
|
38
55
|
FloatingLine as FloatingLine,
|
|
@@ -44,8 +61,8 @@ from pmrf.models.components.lines import (
|
|
|
44
61
|
CoaxialLine as CoaxialLine,
|
|
45
62
|
MicrostripLine as MicrostripLine,
|
|
46
63
|
)
|
|
64
|
+
|
|
47
65
|
from pmrf.models.components.lumped import (
|
|
48
|
-
Load as Load,
|
|
49
66
|
Resistor as Resistor,
|
|
50
67
|
Capacitor as Capacitor,
|
|
51
68
|
Inductor as Inductor,
|
|
@@ -54,21 +71,26 @@ from pmrf.models.components.lumped import (
|
|
|
54
71
|
ShuntInductor as ShuntInductor,
|
|
55
72
|
CapacitorQ as CapacitorQ,
|
|
56
73
|
InductorQ as InductorQ,
|
|
57
|
-
Short as Short,
|
|
58
|
-
Open as Open,
|
|
59
|
-
Match as Match,
|
|
60
74
|
)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
75
|
+
|
|
76
|
+
from pmrf.models.components.sections import (
|
|
77
|
+
PiSection as PiSection,
|
|
78
|
+
TSection as TSection,
|
|
79
|
+
LSection as LSection,
|
|
80
|
+
BoxSection as BoxSection,
|
|
81
|
+
PiSectionCLC as PiSectionCLC,
|
|
82
|
+
BoxSectionCLCC as BoxSectionCLCC,
|
|
83
|
+
TSectionLCL as TSectionLCL,
|
|
65
84
|
LSectionLC as LSectionLC,
|
|
66
85
|
)
|
|
86
|
+
|
|
87
|
+
# Composite
|
|
67
88
|
from pmrf.models.composite.interconnected import (
|
|
68
89
|
Circuit as Circuit,
|
|
69
90
|
Cascade as Cascade,
|
|
70
91
|
Terminated as Terminated,
|
|
71
92
|
)
|
|
93
|
+
|
|
72
94
|
from pmrf.models.composite.transformed import (
|
|
73
95
|
Renumbered as Renumbered,
|
|
74
96
|
Flipped as Flipped,
|
|
@@ -76,24 +98,36 @@ from pmrf.models.composite.transformed import (
|
|
|
76
98
|
)
|
|
77
99
|
|
|
78
100
|
from pmrf.models.composite.nodal import (
|
|
101
|
+
Shunt as Shunt,
|
|
79
102
|
GroundLifted as GroundLifted,
|
|
80
103
|
GroundExposed as GroundExposed,
|
|
81
|
-
Shunt as Shunt,
|
|
82
104
|
CoupledOnePorts as CoupledOnePorts,
|
|
83
105
|
CoupledTwoPorts as CoupledTwoPorts,
|
|
84
106
|
)
|
|
107
|
+
|
|
108
|
+
from pmrf.models.composite.topological import (
|
|
109
|
+
PiTopology as PiTopology,
|
|
110
|
+
TTopology as TTopology,
|
|
111
|
+
LTopology as LTopology,
|
|
112
|
+
)
|
|
113
|
+
|
|
85
114
|
from pmrf.models.composite.wrapped import (
|
|
86
115
|
Tied as Tied,
|
|
87
116
|
Probabilistic as Probabilistic,
|
|
88
117
|
)
|
|
89
118
|
|
|
90
|
-
|
|
119
|
+
# Surrogates
|
|
120
|
+
from pmrf.models.surrogates.expansion import (
|
|
121
|
+
VectorExpansion as VectorExpansion
|
|
122
|
+
)
|
|
123
|
+
|
|
91
124
|
from pmrf.models.surrogates.rational import (
|
|
92
125
|
PolynomialRatio as PolynomialRatio,
|
|
93
126
|
PoleResidue as PoleResidue,
|
|
94
127
|
StateSpace as StateSpace,
|
|
95
128
|
BarycentricRational as BarycentricRational,
|
|
96
129
|
)
|
|
130
|
+
|
|
97
131
|
from pmrf.models import adapters, components, composite, surrogates
|
|
98
132
|
|
|
99
133
|
__all__ = [
|
|
@@ -582,40 +582,40 @@ class Model(eqx.Module):
|
|
|
582
582
|
|
|
583
583
|
# ---- Magic methods and copying --------------------------------------------------
|
|
584
584
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
585
|
+
def __repr__(self) -> str:
|
|
586
|
+
"""String representation of the Model."""
|
|
587
|
+
import numpy as np
|
|
588
|
+
import jax
|
|
589
|
+
|
|
590
|
+
class _RawFormatter:
|
|
591
|
+
"""Wrapper to print arrays cleanly with rounded float values."""
|
|
592
|
+
def __init__(self, val):
|
|
593
|
+
self.val = np.asarray(val)
|
|
594
594
|
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
595
|
+
def __repr__(self):
|
|
596
|
+
# precision=4 limits decimal places
|
|
597
|
+
# suppress_small=True formats numbers very close to zero as 0
|
|
598
|
+
return np.array2string(
|
|
599
|
+
self.val,
|
|
600
|
+
separator=', ',
|
|
601
|
+
precision=4,
|
|
602
|
+
)
|
|
603
|
+
|
|
604
|
+
# Unwrap the model to resolve variables
|
|
605
|
+
unwrapped = unwrap(self)
|
|
606
606
|
|
|
607
|
-
|
|
608
|
-
|
|
607
|
+
# Identify JAX arrays
|
|
608
|
+
is_array = lambda x: isinstance(x, (jax.Array, jnp.ndarray))
|
|
609
609
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
610
|
+
# Replace JAX arrays with our custom formatter
|
|
611
|
+
unwrapped_clean = jax.tree_util.tree_map(
|
|
612
|
+
lambda x: _RawFormatter(x) if is_array(x) else x,
|
|
613
|
+
unwrapped,
|
|
614
|
+
is_leaf=is_array
|
|
615
|
+
)
|
|
616
616
|
|
|
617
|
-
|
|
618
|
-
|
|
617
|
+
# Use Equinox's formatter, displaying full internal arrays instead of generic shape labels
|
|
618
|
+
return eqx.tree_pformat(unwrapped_clean, short_arrays=False)
|
|
619
619
|
|
|
620
620
|
def __str__(self) -> str:
|
|
621
621
|
return repr(self)
|
|
@@ -904,26 +904,24 @@ def validate(tree):
|
|
|
904
904
|
|
|
905
905
|
for node in nodes:
|
|
906
906
|
if isinstance(node, Model):
|
|
907
|
-
# Inspect the dataclass fields of our custom RF models
|
|
908
907
|
for f in dataclasses.fields(node):
|
|
909
908
|
val = getattr(node, f.name)
|
|
910
909
|
|
|
911
|
-
|
|
912
|
-
is_array = isinstance(val, (jnp.ndarray, np.ndarray))
|
|
910
|
+
is_array = isinstance(val, jnp.ndarray)
|
|
913
911
|
is_static = f.metadata.get("static", False)
|
|
914
912
|
|
|
915
913
|
if is_array and not is_static and jnp.issubdtype(val.dtype, jnp.inexact):
|
|
916
914
|
raise TypeError(
|
|
917
|
-
f"Field '{f.name}' in '{node.__class__.__name__}' is a raw JAX
|
|
918
|
-
f"
|
|
915
|
+
f"Field '{f.name}' in '{node.__class__.__name__}' is a raw JAX array, "
|
|
916
|
+
f"meaning it is unclear whether this is a free or fixed parameter.\n\n"
|
|
919
917
|
f"To make your intention clear, you must either:\n"
|
|
920
|
-
f" 1. Use
|
|
921
|
-
f" 2.
|
|
922
|
-
f"
|
|
918
|
+
f" 1. Use a factory in `pmrf.parameters` (e.g. `prf.Variable`) for free variables, or a numpy array for fixed variables\n"
|
|
919
|
+
f" 2. Use a field specifier in the model class definition, e.g. `{f.name}: prf.Param = prf.param()` for automatic parameter conversion, "
|
|
920
|
+
f"or `{f.name}: jnp.ndarray = prf.field(converter=prf.freeze)` combined with `prf.unwrap` to ensure the variable is not optimized.\n"
|
|
921
|
+
f"This restriction is enforced to allow compatibility with machine learning models from othe libraries."
|
|
923
922
|
)
|
|
924
923
|
|
|
925
|
-
#
|
|
926
|
-
# lists of Models, dicts of Models, etc.
|
|
924
|
+
# Recurse into submodels
|
|
927
925
|
validate(val)
|
|
928
926
|
|
|
929
927
|
|
|
@@ -5,11 +5,11 @@ This module provides all the built-in components and circuit elements for buildi
|
|
|
5
5
|
This includes lumped elements, transmission lines, topological sub-circuits, and more.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from pmrf.models.components import ideal, lines, lumped,
|
|
8
|
+
from pmrf.models.components import ideal, lines, lumped, sections
|
|
9
9
|
|
|
10
10
|
__all__ = [
|
|
11
11
|
"ideal",
|
|
12
12
|
"lines",
|
|
13
13
|
"lumped",
|
|
14
|
-
"
|
|
14
|
+
"sections",
|
|
15
15
|
]
|