sax


Namesax JSON
Version 0.15.12 PyPI version JSON
download
home_pageNone
SummaryAutograd and XLA for S-parameters
upload_time2025-07-18 15:27:15
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11.0
licenseApache Software License
keywords simulation optimization autograd simulation-framework circuit physics-simulation photonics s-parameters jax xla photonic-circuit photonic-optimization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SAX

> 0.15.12

![SAX LOGO](docs/assets/logo.svg)

SAX: S-Matrices with Autograd and XLA - a scatter parameter circuit simulator and
optimizer for the frequency domain based on [JAX](https://github.com/google/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](https://flaport.github.io/sax/nbs/examples/01_quick_start) - [Documentation](https://flaport.github.io/sax).

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

```python
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:

```python
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:

```python
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:

```python
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'):

```python
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](docs/assets/output_10_0.png)

Those are the basics. For more info, check out the **full**
[SAX Quick Start page](https://flaport.github.io/sax/nbs/examples/01_quick_start) or the rest of the [Documentation](https://flaport.github.io/sax).

## Installation

You can install SAX with pip:

```sh
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:

```sh
pip install 'sax[dev]'
```

## License

Copyright © 2025, Floris Laporte, [Apache-2.0 License](https://github.com/flaport/sax/blob/master/LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sax",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11.0",
    "maintainer_email": null,
    "keywords": "simulation, optimization, autograd, simulation-framework, circuit, physics-simulation, photonics, s-parameters, jax, xla, photonic-circuit, photonic-optimization",
    "author": null,
    "author_email": "Floris Laporte <floris.laporte@gmail.com>",
    "download_url": null,
    "platform": null,
    "description": "# SAX\n\n> 0.15.12\n\n![SAX LOGO](docs/assets/logo.svg)\n\nSAX: S-Matrices with Autograd and XLA - a scatter parameter circuit simulator and\noptimizer for the frequency domain based on [JAX](https://github.com/google/jax).\n\nThe simulator was developed for simulating Photonic Integrated Circuits but in fact is\nable to perform any S-parameter based circuit simulation. The goal of SAX is to be a\nthin wrapper around JAX with some basic tools for S-parameter based circuit simulation\nand optimization. Therefore, SAX does not define any special datastructures and tries to\nstay as close as possible to the functional nature of JAX. This makes it very easy to\nget started with SAX as you only need functions and standard python dictionaries. Let's\ndive in...\n\n## Quick Start\n\n[Full Quick Start page](https://flaport.github.io/sax/nbs/examples/01_quick_start) - [Documentation](https://flaport.github.io/sax).\n\nLet's first import the SAX library, along with JAX and the JAX-version of numpy:\n\n```python\nimport sax\nimport jax\nimport jax.numpy as jnp\n```\n\nDefine a model function for your component. A SAX model is just a function that returns\nan 'S-dictionary'. For example a directional coupler:\n\n```python\ndef coupler(coupling=0.5):\n    kappa = coupling**0.5\n    tau = (1-coupling)**0.5\n    sdict = sax.reciprocal({\n        (\"in0\", \"out0\"): tau,\n        (\"in0\", \"out1\"): 1j*kappa,\n        (\"in1\", \"out0\"): 1j*kappa,\n        (\"in1\", \"out1\"): tau,\n    })\n    return sdict\n\ncoupler(coupling=0.3)\n```\n\n    {('in0', 'out0'): 0.8366600265340756,\n     ('in0', 'out1'): 0.5477225575051661j,\n     ('in1', 'out0'): 0.5477225575051661j,\n     ('in1', 'out1'): 0.8366600265340756,\n     ('out0', 'in0'): 0.8366600265340756,\n     ('out1', 'in0'): 0.5477225575051661j,\n     ('out0', 'in1'): 0.5477225575051661j,\n     ('out1', 'in1'): 0.8366600265340756}\n\nOr a waveguide:\n\n```python\ndef waveguide(wl=1.55, wl0=1.55, neff=2.34, ng=3.4, length=10.0, loss=0.0):\n    dwl = wl - wl0\n    dneff_dwl = (ng - neff) / wl0\n    neff = neff - dwl * dneff_dwl\n    phase = 2 * jnp.pi * neff * length / wl\n    amplitude = jnp.asarray(10 ** (-loss * length / 20), dtype=complex)\n    transmission =  amplitude * jnp.exp(1j * phase)\n    sdict = sax.reciprocal({(\"in0\", \"out0\"): transmission})\n    return sdict\n\nwaveguide(length=100.0)\n```\n\n    {('in0', 'out0'): 0.97953-0.2013j, ('out0', 'in0'): 0.97953-0.2013j}\n\nThese component models can then be combined into a circuit:\n\n```python\nmzi, _ = sax.circuit(\n    netlist={\n        \"instances\": {\n            \"lft\": coupler,\n            \"top\": waveguide,\n            \"rgt\": coupler,\n        },\n        \"connections\": {\n            \"lft,out0\": \"rgt,in0\",\n            \"lft,out1\": \"top,in0\",\n            \"top,out0\": \"rgt,in1\",\n        },\n        \"ports\": {\n            \"in0\": \"lft,in0\",\n            \"in1\": \"lft,in1\",\n            \"out0\": \"rgt,out0\",\n            \"out1\": \"rgt,out1\",\n        },\n    }\n)\n\ntype(mzi)\n```\n\n    function\n\nAs 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'):\n\n```python\nwl = jnp.linspace(1.53, 1.57, 1000)\nresult = mzi(wl=wl, lft={'coupling': 0.3}, top={'length': 200.0}, rgt={'coupling': 0.8})\n\nplt.plot(1e3*wl, jnp.abs(result['in0', 'out0'])**2, label=\"in0->out0\")\nplt.plot(1e3*wl, jnp.abs(result['in0', 'out1'])**2, label=\"in0->out1\", ls=\"--\")\nplt.xlabel(\"\u03bb [nm]\")\nplt.ylabel(\"T\")\nplt.grid(True)\nplt.figlegend(ncol=2, loc=\"upper center\")\nplt.show()\n```\n\n![output](docs/assets/output_10_0.png)\n\nThose are the basics. For more info, check out the **full**\n[SAX Quick Start page](https://flaport.github.io/sax/nbs/examples/01_quick_start) or the rest of the [Documentation](https://flaport.github.io/sax).\n\n## Installation\n\nYou can install SAX with pip:\n\n```sh\npip install sax\n```\n\nIf you want to be able to run all the example notebooks, you'll need python>=3.10 and\nyou should install the development version of SAX:\n\n```sh\npip install 'sax[dev]'\n```\n\n## License\n\nCopyright \u00a9 2025, Floris Laporte, [Apache-2.0 License](https://github.com/flaport/sax/blob/master/LICENSE)\n",
    "bugtrack_url": null,
    "license": "Apache Software License",
    "summary": "Autograd and XLA for S-parameters",
    "version": "0.15.12",
    "project_urls": null,
    "split_keywords": [
        "simulation",
        " optimization",
        " autograd",
        " simulation-framework",
        " circuit",
        " physics-simulation",
        " photonics",
        " s-parameters",
        " jax",
        " xla",
        " photonic-circuit",
        " photonic-optimization"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "20e6892cd6581e90e7e9dd42c7427865b92b2c289a869f3106c4dbcd3fa1aa4c",
                "md5": "7ce327f0f893d2d6048402fcbee1d689",
                "sha256": "cc24a981b80764214809e14c51ccac9d25b1798f69f17899f6ef9a25a2e8a538"
            },
            "downloads": -1,
            "filename": "sax-0.15.12-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7ce327f0f893d2d6048402fcbee1d689",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11.0",
            "size": 97907,
            "upload_time": "2025-07-18T15:27:15",
            "upload_time_iso_8601": "2025-07-18T15:27:15.530241Z",
            "url": "https://files.pythonhosted.org/packages/20/e6/892cd6581e90e7e9dd42c7427865b92b2c289a869f3106c4dbcd3fa1aa4c/sax-0.15.12-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-18 15:27:15",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "sax"
}
        
Elapsed time: 2.21165s