{ "cells": [ { "cell_type": "markdown", "id": "60e8c162", "metadata": {}, "source": [ "# Multimode\n", "\n", "> SAX Multimode utils" ] }, { "cell_type": "code", "execution_count": null, "id": "4f926c58-97d7-4a3a-a405-ce1fa0f5aaf0", "metadata": { "tags": [] }, "outputs": [], "source": [ "import sax\n", "import jax.numpy as jnp" ] }, { "cell_type": "code", "execution_count": null, "id": "e4547870", "metadata": { "tags": [] }, "outputs": [], "source": [ "sdict_s = {(\"in0\", \"out0\"): 1.0}\n", "sdict_m = sax.multimode(sdict_s)\n", "assert sdict_m == {(\"in0@TE\", \"out0@TE\"): 1.0, (\"in0@TM\", \"out0@TM\"): 1.0}" ] }, { "cell_type": "code", "execution_count": null, "id": "bec10d4b-08de-47c3-979a-7c763ed2cdaa", "metadata": { "tags": [] }, "outputs": [], "source": [ "scoo_s = sax.scoo(sdict_s)\n", "scoo_m = sax.multimode(scoo_s)" ] }, { "cell_type": "code", "execution_count": null, "id": "3ac0dfd7-dc3d-420b-abe8-c373af3af07a", "metadata": { "tags": [] }, "outputs": [], "source": [ "assert (scoo_m[0] == jnp.array([0, 2], dtype=int)).all()\n", "assert (scoo_m[1] == jnp.array([1, 3], dtype=int)).all()\n", "assert (scoo_m[2] == jnp.array([1.0, 1.0], dtype=float)).all()\n", "assert scoo_m[3] == {\"in0@TE\": 0, \"out0@TE\": 1, \"in0@TM\": 2, \"out0@TM\": 3}" ] }, { "cell_type": "code", "execution_count": null, "id": "a1031f11-7847-45db-9df1-b978ef9c7625", "metadata": { "tags": [] }, "outputs": [], "source": [ "sdense_s = sax.sdense(sdict_s)\n", "sdense_m = sax.multimode(sdense_s)\n", "assert (\n", " sdense_m[0]\n", " == jnp.array(\n", " [\n", " [0.0 + 0.0j, 1.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j],\n", " [0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j],\n", " [0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j, 1.0 + 0.0j],\n", " [0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j, 0.0 + 0.0j],\n", " ]\n", " )\n", ").all()\n", "assert sdense_m[1] == {\"in0@TE\": 0, \"out0@TE\": 1, \"in0@TM\": 2, \"out0@TM\": 3}" ] }, { "cell_type": "code", "execution_count": null, "id": "2215f7c9", "metadata": { "tags": [] }, "outputs": [], "source": [ "sdict_s = sax.singlemode(sdict_m)\n", "assert sdict_s == {(\"in0\", \"out0\"): 1.0}" ] }, { "cell_type": "code", "execution_count": null, "id": "3f57f37b", "metadata": { "tags": [] }, "outputs": [], "source": [ "scoo_s = sax.singlemode(scoo_s)\n", "assert (scoo_s[0]==jnp.array([0], dtype=int)).all()\n", "assert (scoo_s[1]==jnp.array([1], dtype=int)).all()\n", "assert (scoo_s[2]==jnp.array([1.0], dtype=float)).all()\n", "assert scoo_s[3] == {'in0': 0, 'out0': 1}" ] }, { "cell_type": "code", "execution_count": null, "id": "94bc44fb", "metadata": { "tags": [] }, "outputs": [], "source": [ "sdense_s = sax.singlemode(sdense_m)\n", "assert (\n", " sdense_s[0] == jnp.array([[0.0 + 0.0j, 1.0 + 0.0j], [0.0 + 0.0j, 0.0 + 0.0j]])\n", ").all()\n", "assert sdense_s[1] == {\"in0\": 0, \"out0\": 1}" ] } ], "metadata": { "kernelspec": { "display_name": "sax", "language": "python", "name": "sax" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }