pmrf.models.containers

Classes

Cascade(models, *[, name, separator, ...])

Represents a cascade, or series connection, of two or more Model objects.

Circuit(connections)

Represents an arbitrary circuit defined by component connections.

Connected(models, ports, *[, name, ...])

Represents a connection of multiple models at a single intersection.

Flipped(model, *[, name, separator, ...])

A model container that flips the ports of a multi-port network.

Renumbered(model, to_ports, from_ports, *[, ...])

A container that re-numbers the ports of a given Model.

Stacked(models, *[, name, separator, ...])

A container that stacks multiple models in a block-diagonal fashion.

class pmrf.models.containers.Circuit(connections)[source]

Bases: Model

Represents 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]]])

models

The list of unique models involved in the circuit.

Type:

list[Model]

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.

models: list[Model]
indexed_connections: list[list[tuple[int, int]]]
port_idxs: list[int]
s(freq)[source]

Scattering parameter matrix.

If only a() is implemented, converts via pmrf.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 a nor s is implemented in a subclass.

class pmrf.models.containers.Connected(models, ports, *, name=None, separator='_', metadata=<factory>, _z0=(50+0j), _param_groups=<factory>)[source]

Bases: Model

Represents a connection of multiple models at a single intersection.

The algorithm in pmrf.functions.connections.connect_one() is used.

Parameters:
  • models (Sequence[Model] | Model)

  • ports (Sequence[int | Sequence[int]])

  • name (str | None)

  • separator (str)

  • metadata (dict)

  • _z0 (complex)

  • _param_groups (list[ParameterGroup])

models

The models to connect.

Type:

Sequence[Model] | Model

ports

The port indices on each model that are connected to the common node.

Type:

Sequence[int | Sequence[int]]

models: Sequence[Model] | Model
ports: Sequence[int | Sequence[int]]
s(freq)[source]

Scattering parameter matrix.

If only a() is implemented, converts via pmrf.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 a nor s is implemented in a subclass.

__init__(models, ports, *, name=None, separator='_', metadata=<factory>, _z0=(50+0j), _param_groups=<factory>)
Parameters:
  • models (Sequence[Model] | Model)

  • 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: Model

Represents 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])

models

The sequence of models in the cascade.

Type:

tuple[Model]

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}")
models: tuple[Model]
property first_model: Model

The first model in the cascade chain.

Type:

Model

property inner_models: tuple[Model]

A tuple of the inner models in the cascade chain.

Type:

tuple[Model]

property last_model: Model

The last model in the cascade chain.

Type:

Model

a(freq)[source]

Calculates the ABCD parameter matrix.

If only s() is implemented, this is calculated using the conversion pmrf.functions.conversions.s2a().

Parameters:

freq (Frequency) – Frequency grid.

Returns:

ABCD matrix with shape (nf, 2, 2).

Return type:

jnp.ndarray

Raises:

NotImplementedError – If neither a nor s is implemented in a subclass.

s(freq)[source]

Scattering parameter matrix.

If only a() is implemented, converts via pmrf.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 a nor s is 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: Model

A 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])

model

The underlying model to renumber.

Type:

Model

to_ports

The new port indices.

Type:

tuple[int]

from_ports

The original port indices that map to to_ports.

Type:

tuple[int]

model: Model
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 conversion pmrf.functions.conversions.s2a().

Parameters:

freq (Frequency) – Frequency grid.

Returns:

ABCD matrix with shape (nf, 2, 2).

Return type:

jnp.ndarray

Raises:

NotImplementedError – If neither a nor s is implemented in a subclass.

s(freq)[source]

Scattering parameter matrix.

If only a() is implemented, converts via pmrf.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 a nor s is 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: Renumbered

A 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: Model

A 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])

models

The models to stack.

Type:

tuple[Model, …]

__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

models: tuple[Model, ...]
s(freq)[source]

Scattering parameter matrix.

If only a() is implemented, converts via pmrf.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 a nor s is implemented in a subclass.