sax.saxtypes module#

SAX Types and type coercions

IntArray1D#

One dimensional integer array

FloatArray1D#

One dimensional float array

ComplexArray1D#

One dimensional complex array

IntArrayND#

N-dimensional integer array

FloatArrayND#

N-dimensional float array

ComplexArrayND#

N-dimensional complex array

PortMap#

A mapping from a port name (str) to a port index (int)

alias of Dict[str, int]

PortCombination#

A combination of two port names (str, str)

alias of Tuple[str, str]

SDict#

A mapping from a port combination to an S-parameter or an array of S-parameters

Example:

sdict: sax.SDict = {
    ("in0", "out0"): 3.0,
}

alias of Dict[Tuple[str, str], ']]

SDense#

A dense S-matrix (2D array) or multidimensional batched S-matrix (N+2)-D array combined with a port map. If (N+2)-D array the S-matrix dimensions are the last two.

Example:

Sd = jnp.arange(9, dtype=float).reshape(3, 3)
port_map = {"in0": 0, "in1": 2, "out0": 1}
sdense = Sd, port_map

alias of Tuple['], Dict[str, int]]

SCoo#

A sparse S-matrix in COO format (recommended for internal library use only)

An SCoo is a sparse matrix based representation of an S-matrix consisting of three arrays and a port map. The three arrays represent the input port indices [int], output port indices [int] and the S-matrix values [ComplexFloat] of the sparse matrix. The port map maps a port name [str] to a port index [int]. Only these four arrays together and in this specific order are considered a valid SCoo representation!

Example:

Si = jnp.arange(3, dtype=int)
Sj = jnp.array([0, 1, 0], dtype=int)
Sx = jnp.array([3.0, 4.0, 1.0])
port_map = {"in0": 0, "in1": 2, "out0": 1}
scoo: sax.SCoo = (Si, Sj, Sx, port_map)

alias of Tuple[Int[Array, 'dim'], Int[Array, 'dim'], '], Dict[str, int]]

Settings#

A (possibly recursive) mapping from a setting name to a float or complex value or array

Example:

mzi_settings: sax.Settings = {
    "wl": 1.5,  # global settings
    "lft": {"coupling": 0.5},  # settings for the left coupler
    "top": {"neff": 3.4},  # settings for the top waveguide
    "rgt": {"coupling": 0.3},  # settings for the right coupler
}

alias of Dict[str, Union[Settings, ']]]

SType#

An SDict, SDense or SCOO

alias of Union[Dict[Tuple[str, str], ']], Tuple[Int[Array, 'dim'], Int[Array, 'dim'], '], Dict[str, int]], Tuple['], Dict[str, int]]]

Model#

A keyword-only function producing an SType

alias of Callable[[…], Union[Dict[Tuple[str, str], ']], Tuple[Int[Array, 'dim'], Int[Array, 'dim'], '], Dict[str, int]], Tuple['], Dict[str, int]]]]

ModelFactory#

A keyword-only function producing a Model

alias of Callable[[…], Callable[[…], Union[Dict[Tuple[str, str], ']], Tuple[Int[Array, 'dim'], Int[Array, 'dim'], '], Dict[str, int]], Tuple['], Dict[str, int]]]]]

is_float(x)[source]#

Check if an object is a Float

Parameters:

x (Any) –

Return type:

bool

is_complex(x)[source]#

check if an object is a ComplexFloat

Parameters:

x (Any) –

Return type:

bool

is_complex_float(x)[source]#

check if an object is either a ComplexFloat or a Float

Parameters:

x (Any) –

Return type:

bool

is_sdict(x)[source]#

check if an object is an SDict (a SAX S-dictionary)

Parameters:

x (Any) –

Return type:

bool

is_scoo(x)[source]#

check if an object is an SCoo (a SAX sparse S representation in COO-format)

Parameters:

x (Any) –

Return type:

bool

is_sdense(x)[source]#

check if an object is an SDense (a SAX dense S-matrix representation)

Parameters:

x (Any) –

Return type:

bool

is_model(model)[source]#

check if a callable is a Model (a callable returning an SType)

Parameters:

model (Any) –

Return type:

bool

is_model_factory(model)[source]#

check if a callable is a model function.

Parameters:

model (Any) –

Return type:

bool

validate_model(model)[source]#

Validate the parameters of a model

Parameters:

model (Callable) –

is_stype(stype)[source]#

check if an object is an SDict, SCoo or SDense

Parameters:

stype (Any) –

Return type:

bool

is_singlemode(S)[source]#

check if an stype is single mode

Parameters:

S (Any) –

Return type:

bool

is_multimode(S)[source]#

check if an stype is single mode

Parameters:

S (Any) –

Return type:

bool

is_mixedmode(S)[source]#

check if an stype is neither single mode nor multimode (hence invalid)

Parameters:

S (Any) –

Return type:

bool

sdict(S: Model) Model[source]#
sdict(S: SType) SDict

Convert an SCoo or SDense to SDict

scoo(S: Callable) Callable[source]#
scoo(S: SType) SCoo

Convert an SDict or SDense to SCoo

sdense(S: Callable) Callable[source]#
sdense(S: SType) SDense

Convert an SDict or SCoo to SDense

modelfactory(func)[source]#

Decorator that marks a function as ModelFactory