Skip to main content

Autograd and XLA for S-parameters

Project description

SAX

0.16.12

SAX LOGO

SAX: S-Matrices with Autograd and XLA - a scatter parameter circuit simulator and optimizer for the frequency domain based on JAX.

The simulator was developed for simulating Photonic Integrated Circuits but in fact is able to perform any S-parameter based circuit simulation. The goal of SAX is to be a thin wrapper around JAX with some basic tools for S-parameter based circuit simulation and optimization. Therefore, SAX does not define any special datastructures and tries to stay as close as possible to the functional nature of JAX. This makes it very easy to get started with SAX as you only need functions and standard python dictionaries. Let's dive in...

Quick Start

Full Quick Start page - Documentation.

Let's first import the SAX library, along with JAX and the JAX-version of numpy:

import sax
import jax
import jax.numpy as jnp

Define a model function for your component. A SAX model is just a function that returns an 'S-dictionary'. For example a directional coupler:

def coupler(coupling=0.5):
    kappa = coupling**0.5
    tau = (1-coupling)**0.5
    sdict = sax.reciprocal({
        ("in0", "out0"): tau,
        ("in0", "out1"): 1j*kappa,
        ("in1", "out0"): 1j*kappa,
        ("in1", "out1"): tau,
    })
    return sdict

coupler(coupling=0.3)
{('in0', 'out0'): 0.8366600265340756,
 ('in0', 'out1'): 0.5477225575051661j,
 ('in1', 'out0'): 0.5477225575051661j,
 ('in1', 'out1'): 0.8366600265340756,
 ('out0', 'in0'): 0.8366600265340756,
 ('out1', 'in0'): 0.5477225575051661j,
 ('out0', 'in1'): 0.5477225575051661j,
 ('out1', 'in1'): 0.8366600265340756}

Or a waveguide:

def waveguide(wl=1.55, wl0=1.55, neff=2.34, ng=3.4, length=10.0, loss=0.0):
    dwl = wl - wl0
    dneff_dwl = (ng - neff) / wl0
    neff = neff - dwl * dneff_dwl
    phase = 2 * jnp.pi * neff * length / wl
    amplitude = jnp.asarray(10 ** (-loss * length / 20), dtype=complex)
    transmission =  amplitude * jnp.exp(1j * phase)
    sdict = sax.reciprocal({("in0", "out0"): transmission})
    return sdict

waveguide(length=100.0)
{('in0', 'out0'): 0.97953-0.2013j, ('out0', 'in0'): 0.97953-0.2013j}

These component models can then be combined into a circuit:

mzi, _ = sax.circuit(
    netlist={
        "instances": {
            "lft": coupler,
            "top": waveguide,
            "rgt": coupler,
        },
        "connections": {
            "lft,out0": "rgt,in0",
            "lft,out1": "top,in0",
            "top,out0": "rgt,in1",
        },
        "ports": {
            "in0": "lft,in0",
            "in1": "lft,in1",
            "out0": "rgt,out0",
            "out1": "rgt,out1",
        },
    }
)

type(mzi)
function

As you can see, the mzi we just created is just another component model function! To simulate it, call the mzi function with the (possibly nested) settings of its subcomponents. Global settings can be added to the 'root' of the circuit call and will be distributed over all subcomponents which have a parameter with the same name (e.g. 'wl'):

wl = jnp.linspace(1.53, 1.57, 1000)
result = mzi(wl=wl, lft={'coupling': 0.3}, top={'length': 200.0}, rgt={'coupling': 0.8})

plt.plot(1e3*wl, jnp.abs(result['in0', 'out0'])**2, label="in0->out0")
plt.plot(1e3*wl, jnp.abs(result['in0', 'out1'])**2, label="in0->out1", ls="--")
plt.xlabel("λ [nm]")
plt.ylabel("T")
plt.grid(True)
plt.figlegend(ncol=2, loc="upper center")
plt.show()

output

Those are the basics. For more info, check out the full SAX Quick Start page or the rest of the Documentation.

Installation

You can install SAX with pip:

pip install sax

If you want to be able to run all the example notebooks, you'll need python>=3.10 and you should install the development version of SAX:

pip install 'sax[dev]'

License

Copyright © 2025, Floris Laporte, Apache-2.0 License

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sax-0.16.12.tar.gz (95.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sax-0.16.12-py3-none-any.whl (113.0 kB view details)

Uploaded Python 3

File details

Details for the file sax-0.16.12.tar.gz.

File metadata

  • Download URL: sax-0.16.12.tar.gz
  • Upload date:
  • Size: 95.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sax-0.16.12.tar.gz
Algorithm Hash digest
SHA256 8c7af29677cbb485b4ee6ab81718b6fabe9dd5fea03947d0050c7bb0b5962e04
MD5 807c08244a355b110e3bcc97be5d4ce1
BLAKE2b-256 a0e00291717da2ba63aa314075efa7f6023107d027f61cf0dd2a700d6f77814c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sax-0.16.12.tar.gz:

Publisher: release.yml on flaport/sax

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sax-0.16.12-py3-none-any.whl.

File metadata

  • Download URL: sax-0.16.12-py3-none-any.whl
  • Upload date:
  • Size: 113.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sax-0.16.12-py3-none-any.whl
Algorithm Hash digest
SHA256 98db7c2272cf4634d56e4186e81febc1cce62997f962aadbcf84ed71256c8afc
MD5 aab19bb5e9b10c7d0e84bc927057f464
BLAKE2b-256 287c57ae57b253c60ba4683f9b60f2f060f45b96edfa64532b03019b47806c23

See more details on using hashes here.

Provenance

The following attestation bundles were made for sax-0.16.12-py3-none-any.whl:

Publisher: release.yml on flaport/sax

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page