{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "138b2483-3eb9-44c0-bfea-2fbe5e157444", "metadata": {}, "outputs": [], "source": [ "import sax\n", "import jax.numpy as jnp" ] }, { "cell_type": "code", "execution_count": null, "id": "a5602fa9-8ead-4fa3-8ce8-9f619bd3f4d4", "metadata": {}, "outputs": [], "source": [ "instances = {\n", " \"lft\": (\n", " jnp.array(\n", " [\n", " [\n", " 5.19688622e-06 - 1.19777138e-05j,\n", " 6.30595625e-16 - 1.48061189e-17j,\n", " -3.38542541e-01 - 6.15711852e-01j,\n", " 5.80662654e-03 - 1.11068866e-02j,\n", " -3.38542542e-01 - 6.15711852e-01j,\n", " -5.80662660e-03 + 1.11068866e-02j,\n", " ],\n", " [\n", " 8.59445189e-16 - 8.29783014e-16j,\n", " -2.08640825e-06 + 8.17315497e-06j,\n", " 2.03847666e-03 - 2.10649131e-03j,\n", " 5.30509661e-01 + 4.62504708e-01j,\n", " -2.03847666e-03 + 2.10649129e-03j,\n", " 5.30509662e-01 + 4.62504708e-01j,\n", " ],\n", " [\n", " -3.38542541e-01 - 6.15711852e-01j,\n", " 2.03847660e-03 - 2.10649129e-03j,\n", " 7.60088070e-06 + 9.07340423e-07j,\n", " 2.79292426e-09 + 2.79093547e-07j,\n", " 5.07842364e-06 + 2.16385350e-06j,\n", " -6.84244232e-08 - 5.00486817e-07j,\n", " ],\n", " [\n", " 5.80662707e-03 - 1.11068869e-02j,\n", " 5.30509661e-01 + 4.62504708e-01j,\n", " 2.79291895e-09 + 2.79093540e-07j,\n", " -4.55645798e-06 + 1.50570403e-06j,\n", " 6.84244128e-08 + 5.00486817e-07j,\n", " -3.55812153e-06 + 4.59781091e-07j,\n", " ],\n", " [\n", " -3.38542541e-01 - 6.15711852e-01j,\n", " -2.03847672e-03 + 2.10649131e-03j,\n", " 5.07842364e-06 + 2.16385349e-06j,\n", " 6.84244230e-08 + 5.00486816e-07j,\n", " 7.60088070e-06 + 9.07340425e-07j,\n", " -2.79292467e-09 - 2.79093547e-07j,\n", " ],\n", " [\n", " -5.80662607e-03 + 1.11068863e-02j,\n", " 5.30509662e-01 + 4.62504708e-01j,\n", " -6.84244296e-08 - 5.00486825e-07j,\n", " -3.55812153e-06 + 4.59781093e-07j,\n", " -2.79293217e-09 - 2.79093547e-07j,\n", " -4.55645798e-06 + 1.50570403e-06j,\n", " ],\n", " ]\n", " ),\n", " {\"in0\": 0, \"out0\": 2, \"out1\": 4},\n", " ),\n", " \"top\": {(\"in0\", \"out0\"): -0.99477 - 0.10211j, (\"out0\", \"in0\"): -0.99477 - 0.10211j},\n", " \"rgt\": {\n", " (\"in0\", \"out0\"): 0.7071067811865476,\n", " (\"in0\", \"out1\"): 0.7071067811865476j,\n", " (\"in1\", \"out0\"): 0.7071067811865476j,\n", " (\"in1\", \"out1\"): 0.7071067811865476,\n", " (\"out0\", \"in0\"): 0.7071067811865476,\n", " (\"out1\", \"in0\"): 0.7071067811865476j,\n", " (\"out0\", \"in1\"): 0.7071067811865476j,\n", " (\"out1\", \"in1\"): 0.7071067811865476,\n", " },\n", "}\n", "connections = {\"lft,out0\": \"rgt,in0\", \"lft,out1\": \"top,in0\", \"top,out0\": \"rgt,in1\"}\n", "ports = {\"in0\": \"lft,in0\", \"out0\": \"rgt,out0\"}" ] }, { "cell_type": "code", "execution_count": null, "id": "9f618831-c763-4a1e-95b5-5d19a564cf0a", "metadata": {}, "outputs": [], "source": [ "sax.sdict(sax.backends.evaluate_circuit(sax.backends.analyze_circuit(connections, ports), instances))" ] }, { "cell_type": "code", "execution_count": null, "id": "ca3c64b4-8f7e-4127-87a9-c8436d947c99", "metadata": {}, "outputs": [], "source": [ "sdict_klu = sax.sdict(sax.backends.evaluate_circuit_klu(sax.backends.analyze_circuit_klu(connections, ports), instances))" ] }, { "cell_type": "code", "execution_count": null, "id": "b6ec00fb-0b0a-46a9-a3e6-7e915bd3d6dc", "metadata": {}, "outputs": [], "source": [ "sdict_fg = sax.sdict(sax.backends.evaluate_circuit_fg(sax.backends.analyze_circuit_fg(connections, ports), instances))" ] }, { "cell_type": "code", "execution_count": null, "id": "f87a6cbf-ae85-47f0-9a57-4b9513bcfda2", "metadata": { "tags": [] }, "outputs": [], "source": [ "for k in sdict_klu:\n", " val_klu = sdict_klu[k]\n", " val_fg = sdict_fg[k]\n", " assert abs(val_klu - val_fg) < 1e-5" ] } ], "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 }