pmrf.models.containers
Classes
|
Represents a cascade, or series connection, of two or more Model objects. |
|
Represents an arbitrary circuit defined by component connections. |
|
Represents a connection of multiple models at a single intersection. |
|
A model container that flips the ports of a multi-port network. |
|
A container that re-numbers the ports of a given Model. |
|
A container that stacks multiple models in a block-diagonal fashion. |
- class pmrf.models.containers.Circuit(connections)[source]
Bases:
ModelRepresents an arbitrary circuit defined by component connections.
This model allows for the definition of a circuit by specifying how the ports of various sub-models are connected together.
- Parameters:
connections (list[list[tuple[Model, int]]])
- indexed_connections
Internal representation of connections using model indices instead of objects.
- Type:
list[list[tuple[int, int]]]
- port_idxs
Indices of the models that act as external ports for the circuit.
- Type:
list[int]
- __init__(connections)[source]
Initialize the Circuit.
- Parameters:
connections (list[list[tuple[Model, int]]]) – A list of connections (nodes). Each connection is a list of (model_instance, port_index) tuples that are electrically connected.
- indexed_connections: list[list[tuple[int, int]]]
- port_idxs: list[int]
- s(freq)[source]
Scattering parameter matrix.
If only
a()is implemented, converts viapmrf.functions.conversions.a2s().- Parameters:
freq (Frequency) – Frequency grid.
- Returns:
S-parameter matrix with shape
(nf, n, n).- Return type:
jnp.ndarray
- Raises:
NotImplementedError – If neither
anorsis implemented in a subclass.
- class pmrf.models.containers.Connected(models, ports, *, name=None, separator='_', metadata=<factory>, _z0=(50+0j), _param_groups=<factory>)[source]
Bases:
ModelRepresents a connection of multiple models at a single intersection.
The algorithm in
pmrf.functions.connections.connect_one()is used.- Parameters:
ports (Sequence[int | Sequence[int]])
name (str | None)
separator (str)
metadata (dict)
_z0 (complex)
_param_groups (list[ParameterGroup])
- ports
The port indices on each model that are connected to the common node.
- Type:
Sequence[int | Sequence[int]]
- ports: Sequence[int | Sequence[int]]
- s(freq)[source]
Scattering parameter matrix.
If only
a()is implemented, converts viapmrf.functions.conversions.a2s().- Parameters:
freq (Frequency) – Frequency grid.
- Returns:
S-parameter matrix with shape
(nf, n, n).- Return type:
jnp.ndarray
- Raises:
NotImplementedError – If neither
anorsis implemented in a subclass.
- __init__(models, ports, *, name=None, separator='_', metadata=<factory>, _z0=(50+0j), _param_groups=<factory>)
- Parameters:
ports (Sequence[int | Sequence[int]])
name (str | None)
separator (str)
metadata (dict)
_z0 (complex)
_param_groups (list[ParameterGroup])
- Return type:
None
- class pmrf.models.containers.Cascade(models, *, name=None, separator='_', metadata=<factory>, _z0=(50+0j), _param_groups=<factory>)[source]
Bases:
ModelRepresents a cascade, or series connection, of two or more Model objects.
This container connects multiple models end-to-end. The output port of one model is connected to the input port of the next. This is mathematically equivalent to chain-multiplying the ABCD-parameter matrices of the constituent models.
The Cascade model automatically flattens any nested Cascade instances to maintain a simple, linear chain of models. The number of ports of the resulting Cascade network depends on the port count of the final model in the chain.
- Parameters:
models (tuple[Model])
name (str | None)
separator (str)
metadata (dict)
_z0 (complex)
_param_groups (list[ParameterGroup])
Examples
Cascading models is most easily done using the ** operator, which is an alias for creating a Cascade model.
>>> import pmrf as prf >>> from pmrf.models import Resistor, Capacitor, Inductor
# Create individual component models >>> res = Resistor(50) >>> cap = Capacitor(1e-12) >>> ind = Inductor(1e-9)
# Cascade them together in a series R-L-C configuration # This is equivalent to Cascade(models=(res, ind, cap)) >>> rlc_series = res ** ind ** cap
# Define a frequency axis >>> freq = prf.Frequency(start=1, stop=10, npoints=101, unit=’ghz’)
# Calculate the S-parameters of the cascaded network >>> s_params = rlc_series.s(freq)
>>> print(f"Cascaded model has {rlc_series.nports} ports.") >>> print(f"S11 at first frequency point: {s_params[0,0,0]:.2f}")
- property inner_models: tuple[Model]
A tuple of the inner models in the cascade chain.
- Type:
tuple[Model]
- a(freq)[source]
Calculates the ABCD parameter matrix.
If only
s()is implemented, this is calculated using the conversionpmrf.functions.conversions.s2a().- Parameters:
freq (Frequency) – Frequency grid.
- Returns:
ABCD matrix with shape
(nf, 2, 2).- Return type:
jnp.ndarray
- Raises:
NotImplementedError – If neither
anorsis implemented in a subclass.
- s(freq)[source]
Scattering parameter matrix.
If only
a()is implemented, converts viapmrf.functions.conversions.a2s().- Parameters:
freq (Frequency) – Frequency grid.
- Returns:
S-parameter matrix with shape
(nf, n, n).- Return type:
jnp.ndarray
- Raises:
NotImplementedError – If neither
anorsis implemented in a subclass.
- __init__(models, *, name=None, separator='_', metadata=<factory>, _z0=(50+0j), _param_groups=<factory>)
- Parameters:
models (tuple[Model])
name (str | None)
separator (str)
metadata (dict)
_z0 (complex)
_param_groups (list[ParameterGroup])
- Return type:
None
- class pmrf.models.containers.Renumbered(model, to_ports, from_ports, *, name=None, separator='_', metadata=<factory>, _z0=(50+0j), _param_groups=<factory>)[source]
Bases:
ModelA container that re-numbers the ports of a given Model.
This is useful for creating complex network topologies by explicitly re-mapping the port indices of a sub-network.
- Parameters:
model (Model)
to_ports (tuple[int])
from_ports (tuple[int])
name (str | None)
separator (str)
metadata (dict)
_z0 (complex)
_param_groups (list[ParameterGroup])
- to_ports
The new port indices.
- Type:
tuple[int]
- from_ports
The original port indices that map to to_ports.
- Type:
tuple[int]
- to_ports: tuple[int]
- from_ports: tuple[int]
- renumber(p)[source]
Applies the port renumbering to a parameter matrix.
- Parameters:
p (jnp.ndarray) – The parameter matrix to renumber (e.g., S-parameters).
- Returns:
The renumbered parameter matrix.
- Return type:
jnp.ndarray
- a(freq)[source]
Calculates the ABCD parameter matrix.
If only
s()is implemented, this is calculated using the conversionpmrf.functions.conversions.s2a().- Parameters:
freq (Frequency) – Frequency grid.
- Returns:
ABCD matrix with shape
(nf, 2, 2).- Return type:
jnp.ndarray
- Raises:
NotImplementedError – If neither
anorsis implemented in a subclass.
- s(freq)[source]
Scattering parameter matrix.
If only
a()is implemented, converts viapmrf.functions.conversions.a2s().- Parameters:
freq (Frequency) – Frequency grid.
- Returns:
S-parameter matrix with shape
(nf, n, n).- Return type:
jnp.ndarray
- Raises:
NotImplementedError – If neither
anorsis implemented in a subclass.
- __init__(model, to_ports, from_ports, *, name=None, separator='_', metadata=<factory>, _z0=(50+0j), _param_groups=<factory>)
- Parameters:
model (Model)
to_ports (tuple[int])
from_ports (tuple[int])
name (str | None)
separator (str)
metadata (dict)
_z0 (complex)
_param_groups (list[ParameterGroup])
- Return type:
None
- class pmrf.models.containers.Flipped(model, *, name=None, separator='_', metadata=<factory>, _z0=(50+0j), _param_groups=<factory>)[source]
Bases:
RenumberedA model container that flips the ports of a multi-port network.
For a 2-port network, this is equivalent to swapping port 1 and port 2. For a 4-port network, ports (1,2) are swapped with (3,4), and so on. This is a convenient specialization of the Renumbered model.
- Parameters:
model (Model)
name (str | None)
separator (str)
metadata (dict)
_z0 (complex)
_param_groups (list[ParameterGroup])
- to_ports: tuple[int]
- from_ports: tuple[int]
- __init__(model, *, name=None, separator='_', metadata=<factory>, _z0=(50+0j), _param_groups=<factory>)
- Parameters:
model (Model)
name (str | None)
separator (str)
metadata (dict)
_z0 (complex)
_param_groups (list[ParameterGroup])
- Return type:
None
- class pmrf.models.containers.Stacked(models, *, name=None, separator='_', metadata=<factory>, _z0=(50+0j), _param_groups=<factory>)[source]
Bases:
ModelA container that stacks multiple models in a block-diagonal fashion.
This combines several Model objects into a single, larger model where the individual S-parameter matrices are placed along the diagonal of the combined S-parameter matrix. This represents a set of unconnected networks treated as a single component.
- Parameters:
models (tuple[Model, ...])
name (str | None)
separator (str)
metadata (dict)
_z0 (complex)
_param_groups (list[ParameterGroup])
- __init__(models, *, name=None, separator='_', metadata=<factory>, _z0=(50+0j), _param_groups=<factory>)
- Parameters:
models (tuple[Model, ...])
name (str | None)
separator (str)
metadata (dict)
_z0 (complex)
_param_groups (list[ParameterGroup])
- Return type:
None
- s(freq)[source]
Scattering parameter matrix.
If only
a()is implemented, converts viapmrf.functions.conversions.a2s().- Parameters:
freq (Frequency) – Frequency grid.
- Returns:
S-parameter matrix with shape
(nf, n, n).- Return type:
jnp.ndarray
- Raises:
NotImplementedError – If neither
anorsis implemented in a subclass.