pmrf.models.containers

Classes

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

Overview

Circuit(connections)

Connected(models, pmrf.models.model.Model], ...)

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

Overview

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

Overview

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

Overview

class pmrf.models.containers.Circuit(connections: list[list[tuple[pmrf.models.model.Model, int]]])[source]

Bases: Model

Parameters:

connections (list[list[tuple[Model, int]]])

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: Union[Sequence[pmrf.models.model.Model], pmrf.models.model.Model], ports: Sequence[Union[int, Sequence[int]]], *, name: str | None = None, separator: str = '_', _z0: complex = (50+0j), _param_groups: list[pmrf.parameters.ParameterGroup] = <factory>)[source]

Bases: Model

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

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

  • name (str | None)

  • separator (str)

  • _z0 (complex)

  • _param_groups (list[ParameterGroup])

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.

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

Bases: Model

Overview

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.

Example:

Cascading models is most easily done using the ** operator, which is an alias for creating a Cascade model.

```python 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}”) ```

Parameters:
  • models (tuple[Model])

  • name (str | None)

  • separator (str)

  • _z0 (complex)

  • _param_groups (list[ParameterGroup])

models: tuple[Model]
property first_model: Model

The first model in the cascade chain.

property inner_models: tuple[Model]

A tuple of the inner models in the cascade chain.

property last_model: Model

The last model in the cascade chain.

a(freq)[source]

Calculates the cascaded ABCD-parameter matrix.

Args:

freq (Frequency): Specifies the frequency to calculate the parameters at.

Returns:

jnp.ndarray: The resultant ABCD-parameter matrix.

Parameters:

freq (Frequency)

Return type:

Array

s(freq)[source]

Calculates the S-parameter matrix.

If the cascade is terminated in a one-port, this computes the resultant one-port reflection coefficient. Otherwise, it converts the cascaded ABCD-matrix to S-parameters.

Args:

freq (Frequency): Specifies the frequency to calculate the parameters at.

Returns:

jnp.ndarray: The resultant S-parameter matrix.

Parameters:

freq (Frequency)

Return type:

Array

class pmrf.models.containers.Renumbered(model, to_ports, from_ports, *, name=None, separator='_', _z0=(50+0j), _param_groups=<factory>)[source]

Bases: Model

Overview

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)

  • _z0 (complex)

  • _param_groups (list[ParameterGroup])

model: Model
to_ports: tuple[int]
from_ports: tuple[int]
renumber(p)[source]

Applies the port renumbering to a parameter matrix.

Args:

p (jnp.ndarray): The parameter matrix to renumber (e.g., S-parameters).

Returns:

jnp.ndarray: The renumbered parameter matrix.

Parameters:

p (Array)

Return type:

Array

a(freq)[source]

Calculates the renumbered ABCD-parameter matrix.

Args:

freq (Frequency): Specifies the frequency to calculate the parameters at.

Returns:

jnp.ndarray: The resultant renumbered ABCD-parameter matrix.

Parameters:

freq (Frequency)

Return type:

Array

s(freq)[source]

Calculates the renumbered S-parameter matrix.

Args:

freq (Frequency): Specifies the frequency to calculate the parameters at.

Returns:

jnp.ndarray: The resultant renumbered S-parameter matrix.

Parameters:

freq (Frequency)

Return type:

Array

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

Bases: Renumbered

Overview

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)

  • _z0 (complex)

  • _param_groups (list[ParameterGroup])

to_ports: tuple[int]
from_ports: tuple[int]
class pmrf.models.containers.Stacked(models, *, name=None, separator='_', _z0=(50+0j), _param_groups=<factory>)[source]

Bases: Model

Overview

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)

  • _z0 (complex)

  • _param_groups (list[ParameterGroup])

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

Calculates the stacked S-parameter matrix.

Args:

freq (Frequency): Specifies the frequency to calculate the parameters at.

Returns:

jnp.ndarray: The resultant block-diagonal S-parameter matrix.

Parameters:

freq (Frequency)

Return type:

Array