QPDK Models#

Imports#

Hide code cell source

import sys

if "google.colab" in sys.modules:
    import subprocess

    print("Running in Google Colab. Installing QPDK...")
    subprocess.check_call([
        sys.executable,
        "-m",
        "pip",
        "install",
        "-q",
        "qpdk[models] @ git+https://github.com/gdsfactory/quantum-rf-pdk.git",
    ])
import jax.numpy as jnp
import matplotlib.pyplot as plt

from qpdk import PDK

PDK.activate()

# ruff: disable[E402]

Constants#

from qpdk.models.constants import TEST_FREQUENCY

Media#

from qpdk.models.cpw import cpw_parameters, get_cpw_dimensions

cpw_parameters(*get_cpw_dimensions("cpw"))
(Array(6.06519124-1.49847261e-05j, dtype=complex128),
 Array(49.31279884, dtype=float64))

Generic#

from qpdk.models.generic import gamma_0_load

gamma_0_load(f=TEST_FREQUENCY, gamma_0=1, n_ports=2)
{('o1',
  'o1'): Array([[1, 1, 1],
        [1, 1, 1]], dtype=int64, weak_type=True),
 ('o1',
  'o2'): Array([[0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex128),
 ('o2',
  'o2'): Array([[1, 1, 1],
        [1, 1, 1]], dtype=int64, weak_type=True)}
from qpdk.models.generic import short

short(f=TEST_FREQUENCY, n_ports=2)
{('o1',
  'o1'): Array([[-1, -1, -1],
        [-1, -1, -1]], dtype=int64, weak_type=True),
 ('o1',
  'o2'): Array([[0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex128),
 ('o2',
  'o2'): Array([[-1, -1, -1],
        [-1, -1, -1]], dtype=int64, weak_type=True)}
from qpdk.models.generic import short_2_port

short_2_port(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[-1, -1, -1],
        [-1, -1, -1]], dtype=int64, weak_type=True),
 ('o1',
  'o2'): Array([[0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex128),
 ('o2',
  'o2'): Array([[-1, -1, -1],
        [-1, -1, -1]], dtype=int64, weak_type=True)}
from qpdk.models.generic import open

open(f=TEST_FREQUENCY, n_ports=2)
{('o1',
  'o1'): Array([[1, 1, 1],
        [1, 1, 1]], dtype=int64, weak_type=True),
 ('o1',
  'o2'): Array([[0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex128),
 ('o2',
  'o2'): Array([[1, 1, 1],
        [1, 1, 1]], dtype=int64, weak_type=True)}
from qpdk.models.generic import tee

tee(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[-0.33333333, -0.33333333, -0.33333333],
        [-0.33333333, -0.33333333, -0.33333333]],      dtype=float64, weak_type=True),
 ('o1',
  'o2'): Array([[0.66666667, 0.66666667, 0.66666667],
        [0.66666667, 0.66666667, 0.66666667]],      dtype=float64, weak_type=True),
 ('o1',
  'o3'): Array([[0.66666667, 0.66666667, 0.66666667],
        [0.66666667, 0.66666667, 0.66666667]],      dtype=float64, weak_type=True),
 ('o2',
  'o1'): Array([[0.66666667, 0.66666667, 0.66666667],
        [0.66666667, 0.66666667, 0.66666667]],      dtype=float64, weak_type=True),
 ('o2',
  'o2'): Array([[-0.33333333, -0.33333333, -0.33333333],
        [-0.33333333, -0.33333333, -0.33333333]],      dtype=float64, weak_type=True),
 ('o2',
  'o3'): Array([[0.66666667, 0.66666667, 0.66666667],
        [0.66666667, 0.66666667, 0.66666667]],      dtype=float64, weak_type=True),
 ('o3',
  'o1'): Array([[0.66666667, 0.66666667, 0.66666667],
        [0.66666667, 0.66666667, 0.66666667]],      dtype=float64, weak_type=True),
 ('o3',
  'o2'): Array([[0.66666667, 0.66666667, 0.66666667],
        [0.66666667, 0.66666667, 0.66666667]],      dtype=float64, weak_type=True),
 ('o3',
  'o3'): Array([[-0.33333333, -0.33333333, -0.33333333],
        [-0.33333333, -0.33333333, -0.33333333]],      dtype=float64, weak_type=True)}
from qpdk.models.generic import impedance

impedance(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[0.33333333, 0.33333333, 0.33333333],
        [0.33333333, 0.33333333, 0.33333333]], dtype=float64),
 ('o1',
  'o2'): Array([[0.66666667, 0.66666667, 0.66666667],
        [0.66666667, 0.66666667, 0.66666667]], dtype=float64),
 ('o2',
  'o1'): Array([[0.66666667, 0.66666667, 0.66666667],
        [0.66666667, 0.66666667, 0.66666667]], dtype=float64),
 ('o2',
  'o2'): Array([[0.33333333, 0.33333333, 0.33333333],
        [0.33333333, 0.33333333, 0.33333333]], dtype=float64)}
from qpdk.models.generic import admittance

admittance()
{('o1', 'o1'): Array(0.98039216, dtype=float64, weak_type=True),
 ('o1', 'o2'): Array(0.01960784, dtype=float64, weak_type=True),
 ('o2', 'o1'): Array(0.01960784, dtype=float64, weak_type=True),
 ('o2', 'o2'): Array(0.98039216, dtype=float64, weak_type=True)}
from qpdk.models.generic import capacitor

capacitor(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[0.99999013-0.00314156j, 0.99998579-0.00376986j,
         0.99998066-0.00439814j],
        [0.99997473-0.00502642j, 0.99996802-0.00565469j,
         0.99996052-0.00628294j]], dtype=complex128),
 ('o1',
  'o2'): Array([[9.86950699e-06+0.00314156j, 1.42120284e-05+0.00376986j,
         1.93440504e-05+0.00439814j],
        [2.52655489e-05+0.00502642j, 3.19764957e-05+0.00565469j,
         3.94768591e-05+0.00628294j]], dtype=complex128),
 ('o2',
  'o1'): Array([[9.86950699e-06+0.00314156j, 1.42120284e-05+0.00376986j,
         1.93440504e-05+0.00439814j],
        [2.52655489e-05+0.00502642j, 3.19764957e-05+0.00565469j,
         3.94768591e-05+0.00628294j]], dtype=complex128),
 ('o2',
  'o2'): Array([[0.99999013-0.00314156j, 0.99998579-0.00376986j,
         0.99998066-0.00439814j],
        [0.99997473-0.00502642j, 0.99996802-0.00565469j,
         0.99996052-0.00628294j]], dtype=complex128)}
from qpdk.models.generic import inductor

inductor(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[9.86960343e-08+0.00031416j, 1.42122283e-07+0.00037699j,
         1.93444209e-07+0.00043982j],
        [2.52661809e-07+0.00050265j, 3.19775080e-07+0.00056549j,
         3.94784020e-07+0.00062832j]], dtype=complex128),
 ('o1',
  'o2'): Array([[0.9999999 -0.00031416j, 0.99999986-0.00037699j,
         0.99999981-0.00043982j],
        [0.99999975-0.00050265j, 0.99999968-0.00056549j,
         0.99999961-0.00062832j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.9999999 -0.00031416j, 0.99999986-0.00037699j,
         0.99999981-0.00043982j],
        [0.99999975-0.00050265j, 0.99999968-0.00056549j,
         0.99999961-0.00062832j]], dtype=complex128),
 ('o2',
  'o2'): Array([[9.86960343e-08+0.00031416j, 1.42122283e-07+0.00037699j,
         1.93444209e-07+0.00043982j],
        [2.52661809e-07+0.00050265j, 3.19775080e-07+0.00056549j,
         3.94784020e-07+0.00062832j]], dtype=complex128)}
from qpdk.models.generic import lc_resonator

lc_resonator(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[0.1083328 +0.31080027j, 0.16185641+0.36831904j,
         0.22920574+0.42032187j],
        [0.31147596+0.46309684j, 0.40866831+0.49158776j,
         0.5187223 +0.49964935j]], dtype=complex128),
 ('o1',
  'o2'): Array([[0.8916672 -0.31080027j, 0.83814359-0.36831904j,
         0.77079426-0.42032187j],
        [0.68852404-0.46309684j, 0.59133169-0.49158776j,
         0.4812777 -0.49964935j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.8916672 -0.31080027j, 0.83814359-0.36831904j,
         0.77079426-0.42032187j],
        [0.68852404-0.46309684j, 0.59133169-0.49158776j,
         0.4812777 -0.49964935j]], dtype=complex128),
 ('o2',
  'o2'): Array([[0.1083328 +0.31080027j, 0.16185641+0.36831904j,
         0.22920574+0.42032187j],
        [0.31147596+0.46309684j, 0.40866831+0.49158776j,
         0.5187223 +0.49964935j]], dtype=complex128)}
from qpdk.models.generic import lc_resonator_coupled

lc_resonator_coupled(f=TEST_FREQUENCY, coupling_capacitance=10e-15)
{('o1',
  'o1'): Array([[0.1083328 +0.31080027j, 0.16185641+0.36831904j,
         0.22920574+0.42032187j],
        [0.31147596+0.46309684j, 0.40866831+0.49158776j,
         0.5187223 +0.49964935j]], dtype=complex128),
 ('o1',
  'o2'): Array([[0.8916672 -0.31080027j, 0.83814359-0.36831904j,
         0.77079426-0.42032187j],
        [0.68852404-0.46309684j, 0.59133169-0.49158776j,
         0.4812777 -0.49964935j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.8916672 -0.31080027j, 0.83814359-0.36831904j,
         0.77079426-0.42032187j],
        [0.68852404-0.46309684j, 0.59133169-0.49158776j,
         0.4812777 -0.49964935j]], dtype=complex128),
 ('o2',
  'o2'): Array([[0.1083328 +0.31080027j, 0.16185641+0.36831904j,
         0.22920574+0.42032187j],
        [0.31147596+0.46309684j, 0.40866831+0.49158776j,
         0.5187223 +0.49964935j]], dtype=complex128)}
from qpdk.models.junction import josephson_junction

josephson_junction(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[0.99066459+0.09565147j, 0.99347752+0.07987868j,
         0.99518135+0.0685268j ],
        [0.99629033+0.05996909j, 0.99705206+0.05328745j,
         0.99759763+0.04792541j]], dtype=complex128),
 ('o1',
  'o2'): Array([[0.00933541-0.09565147j, 0.00652248-0.07987868j,
         0.00481865-0.0685268j ],
        [0.00370967-0.05996909j, 0.00294794-0.05328745j,
         0.00240237-0.04792541j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.00933541-0.09565147j, 0.00652248-0.07987868j,
         0.00481865-0.0685268j ],
        [0.00370967-0.05996909j, 0.00294794-0.05328745j,
         0.00240237-0.04792541j]], dtype=complex128),
 ('o2',
  'o2'): Array([[0.99066459+0.09565147j, 0.99347752+0.07987868j,
         0.99518135+0.0685268j ],
        [0.99629033+0.05996909j, 0.99705206+0.05328745j,
         0.99759763+0.04792541j]], dtype=complex128)}
f = jnp.linspace(1e9, 25e9, 201)
S = gamma_0_load(f=f, gamma_0=0.5 + 0.5j, n_ports=2)
for key in S:
    plt.plot(f / 1e9, abs(S[key]) ** 2, label=key)
plt.ylim(-0.05, 1.05)
plt.xlabel("Frequency [GHz]")
plt.ylabel("S")
plt.grid(True)
plt.legend()
plt.show(block=False)

L = 1e-9
C = 100e-15
f_r = 1 / (2 * jnp.pi * jnp.sqrt(L * C))
f_sweep = jnp.linspace(f_r * 0.5, f_r * 1.5, 1001)

S_res = lc_resonator(f=f_sweep, inductance=L, capacitance=C)

plt.figure(figsize=(10, 6))
plt.plot(f_sweep / 1e9, 20 * jnp.log10(jnp.abs(S_res["o1", "o2"])), label="$S_{21}$")
plt.axvline(
    float(f_r / 1e9),
    color="r",
    linestyle="--",
    label=f"Theoretical $f_r$ ({float(f_r / 1e9):.2f} GHz)",
)
plt.xlabel("Frequency [GHz]")
plt.ylabel("Magnitude [dB]")
plt.title(f"LC Resonator ($L={L * 1e9}$ nH, $C={C * 1e15}$ fF)")
plt.grid(True)
plt.legend()
plt.show(block=False)

S_coupled = lc_resonator_coupled(
    f=f_sweep, inductance=L, capacitance=C, coupling_capacitance=10e-15
)

plt.figure(figsize=(10, 6))
plt.plot(
    f_sweep / 1e9,
    20 * jnp.log10(jnp.abs(S_coupled["o1", "o2"])),
    label="$S_{21}$ (coupled)",
)
plt.plot(
    f_sweep / 1e9,
    20 * jnp.log10(jnp.abs(S_res["o1", "o2"])),
    "--",
    label="$S_{21}$ (bare)",
)
plt.xlabel("Frequency [GHz]")
plt.ylabel("Magnitude [dB]")
plt.title("Coupled vs Bare LC Resonator")
plt.grid(True)
plt.legend()
plt.show(block=False)

S_cap = capacitor(f=f, capacitance=(capacitance := 100e-15))
# print(S_cap)
plt.figure()
# Polar plot of S21 and S11
plt.subplot(121, projection="polar")
plt.plot(jnp.angle(S_cap["o1", "o1"]), abs(S_cap["o1", "o1"]), label="$S_{11}$")
plt.plot(jnp.angle(S_cap["o1", "o2"]), abs(S_cap["o2", "o1"]), label="$S_{21}$")
plt.title("S-parameters capacitor")
plt.legend()
# Magnitude and phase vs frequency
ax1 = plt.subplot(122)
ax1.plot(f / 1e9, abs(S_cap["o1", "o1"]), label="|S11|", color="C0")
ax1.plot(f / 1e9, abs(S_cap["o1", "o2"]), label="|S21|", color="C1")
ax1.set_xlabel("Frequency [GHz]")
ax1.set_ylabel("Magnitude [unitless]")
ax1.grid(True)
ax1.legend(loc="upper left")

ax2 = ax1.twinx()
ax2.plot(
    f / 1e9,
    jnp.angle(S_cap["o1", "o1"]),
    label="∠S11",
    color="C0",
    linestyle="--",
)
ax2.plot(
    f / 1e9,
    jnp.angle(S_cap["o1", "o2"]),
    label="∠S21",
    color="C1",
    linestyle="--",
)
ax2.set_ylabel("Phase [rad]")
ax2.legend(loc="upper right")

plt.title(f"Capacitor $S$-parameters ($C={capacitance * 1e15}\\,$fF)")
plt.show(block=False)

S_ind = inductor(f=f, inductance=(inductance := 1e-9))
# print(S_ind)
plt.figure()
plt.subplot(121, projection="polar")
plt.plot(jnp.angle(S_ind["o1", "o1"]), abs(S_ind["o1", "o1"]), label="$S_{11}$")
plt.plot(jnp.angle(S_ind["o1", "o2"]), abs(S_ind["o2", "o1"]), label="$S_{21}$")
plt.title("S-parameters inductor")
plt.legend()
ax1 = plt.subplot(122)
ax1.plot(f / 1e9, abs(S_ind["o1", "o1"]), label="|S11|", color="C0")
ax1.plot(f / 1e9, abs(S_ind["o1", "o2"]), label="|S21|", color="C1")
ax1.set_xlabel("Frequency [GHz]")
ax1.set_ylabel("Magnitude [unitless]")
ax1.grid(True)
ax1.legend(loc="upper left")

ax2 = ax1.twinx()
ax2.plot(
    f / 1e9,
    jnp.angle(S_ind["o1", "o1"]),
    label="∠S11",
    color="C0",
    linestyle="--",
)
ax2.plot(
    f / 1e9,
    jnp.angle(S_ind["o1", "o2"]),
    label="∠S21",
    color="C1",
    linestyle="--",
)
ax2.set_ylabel("Phase [rad]")
ax2.legend(loc="upper right")

plt.title(f"Inductor $S$-parameters ($L={inductance * 1e9}\\,$nH)")
plt.show()
/tmp/ipykernel_3435/3232581677.py:4: MatplotlibDeprecationWarning: Passing label as a length 2 sequence when plotting a single dataset is deprecated in Matplotlib 3.9 and will error in 3.11.  To keep the current behavior, cast the sequence to string before passing.
  plt.plot(f / 1e9, abs(S[key]) ** 2, label=key)
../_images/d5945a17403f69a56c77e45f264956e5af38902204af65d0f4244acbd6a173eb.svg ../_images/f7e7eb437995a4abfb2944e9c60f3daa4fb0f0f0d3135bb9ea7b32295f464bfd.svg ../_images/742d57aa224c172d83d99f0a243ba45e92316c6d7774929916fc408e9c3e9985.svg
/home/runner/work/quantum-rf-pdk/quantum-rf-pdk/.venv/lib/python3.12/site-packages/IPython/core/pylabtools.py:170: UserWarning: Glyph 8736 (\N{ANGLE}) missing from font(s) Inter.
  fig.canvas.print_figure(bytes_io, **kw)
../_images/b7e5c231c27bd6eb7bacef87f015f2c2873e1fbfc6a64a44f99a9d253a50d950.svg ../_images/6bd65accdea25017851b38ec0936e78002e4eb7dee54ee5b79fd92da9e5dcee4.svg
from qpdk.models.capacitor import (
    interdigital_capacitor_capacitance_analytical,
    plate_capacitor_capacitance_analytical,
)

# 1. Plot Plate Capacitor Capacitance vs. Length for different Gaps
lengths_plate = jnp.linspace(10, 500, 100)
gaps_plate = jnp.geomspace(1.0, 20.0, 5)
width_plate = 10.0
ep_r = 11.7

plt.figure(figsize=(10, 6))

# Broadcast to compute total capacitance for all lengths and gaps (shape: (5, 100))
capacitances_plate = (
    plate_capacitor_capacitance_analytical(
        length=lengths_plate[None, :],
        width=width_plate,
        gap=gaps_plate[:, None],
        ep_r=ep_r,
    )
    * 1e15
)  # Convert to fF

for i, gap in enumerate(gaps_plate):
    plt.plot(lengths_plate, capacitances_plate[i], label=f"gap = {gap:.1f} µm")

plt.xlabel("Pad Length (µm)")
plt.ylabel("Capacitance (fF)")
plt.title(
    rf"Plate Capacitor Capacitance ($\mathtt{{width}}=${width_plate} µm, $\epsilon_r={ep_r}$)"
)
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.show()
../_images/26b858c325d878a0c0b58094452084cfceab436e60371fe71352416b24b7d47f.svg
# 2. Plot Interdigital Capacitor Capacitance vs. Finger Length for different Finger Counts
finger_lengths = jnp.linspace(10, 100, 100)
finger_counts = jnp.arange(2, 11, 2)  # [2, 4, 6, 8, 10]
finger_gap = 2.0
thickness = 5.0

plt.figure(figsize=(10, 6))

# Broadcast to compute total capacitance for all lengths and counts (shape: (5, 100))
capacitances_idc = (
    interdigital_capacitor_capacitance_analytical(
        fingers=finger_counts[:, None],
        finger_length=finger_lengths[None, :],
        finger_gap=finger_gap,
        thickness=thickness,
        ep_r=ep_r,
    )
    * 1e15
)  # Convert to fF

for i, n in enumerate(finger_counts):
    plt.plot(finger_lengths, capacitances_idc[i], label=f"n = {n} fingers")

plt.xlabel("Overlap Length (µm)")
plt.ylabel("Mutual Capacitance (fF)")
plt.title(
    rf"Interdigital Capacitor Capacitance ($\mathtt{{finger\_gap}}=${finger_gap} µm, $\mathtt{{thickness}}=${thickness} µm, $\epsilon_r={ep_r}$)"
)
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.show()
../_images/17b7cc2966017a2a6d5ce73450791f5bdda3cfc5b02cfff2f18fff4bab8c2aa7.svg

Waveguides#

from qpdk.models.waveguides import straight

straight(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
          2.47607392e-23-9.35705089e-24j],
        [ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
         -1.36985066e-17-2.41396337e-17j]], dtype=complex128),
 ('o1',
  'o2'): Array([[0.96688193-0.25522285j, 0.95242654-0.30476701j,
         0.93543428-0.35349939j],
        [0.91595042-0.40129019j, 0.89402684-0.44801211j,
         0.86972196-0.49354071j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.96688193-0.25522285j, 0.95242654-0.30476701j,
         0.93543428-0.35349939j],
        [0.91595042-0.40129019j, 0.89402684-0.44801211j,
         0.86972196-0.49354071j]], dtype=complex128),
 ('o2',
  'o2'): Array([[ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
          2.47607392e-23-9.35705089e-24j],
        [ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
         -1.36985066e-17-2.41396337e-17j]], dtype=complex128)}
from qpdk.models.waveguides import straight_shorted

straight_shorted(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[-0.86972196+0.49354071j, -0.81423338+0.58053637j,
         -0.75007547+0.66135089j],
        [-0.67793135+0.73512383j, -0.59856915+0.80106971j,
         -0.51283385+0.85848639j]], dtype=complex128)}
from qpdk.models.waveguides import bend_circular

bend_circular(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
          2.47607392e-23-9.35705089e-24j],
        [ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
         -1.36985066e-17-2.41396337e-17j]], dtype=complex128),
 ('o1',
  'o2'): Array([[0.96688193-0.25522285j, 0.95242654-0.30476701j,
         0.93543428-0.35349939j],
        [0.91595042-0.40129019j, 0.89402684-0.44801211j,
         0.86972196-0.49354071j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.96688193-0.25522285j, 0.95242654-0.30476701j,
         0.93543428-0.35349939j],
        [0.91595042-0.40129019j, 0.89402684-0.44801211j,
         0.86972196-0.49354071j]], dtype=complex128),
 ('o2',
  'o2'): Array([[ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
          2.47607392e-23-9.35705089e-24j],
        [ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
         -1.36985066e-17-2.41396337e-17j]], dtype=complex128)}
from qpdk.models.waveguides import bend_euler

bend_euler(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
          2.47607392e-23-9.35705089e-24j],
        [ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
         -1.36985066e-17-2.41396337e-17j]], dtype=complex128),
 ('o1',
  'o2'): Array([[0.96688193-0.25522285j, 0.95242654-0.30476701j,
         0.93543428-0.35349939j],
        [0.91595042-0.40129019j, 0.89402684-0.44801211j,
         0.86972196-0.49354071j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.96688193-0.25522285j, 0.95242654-0.30476701j,
         0.93543428-0.35349939j],
        [0.91595042-0.40129019j, 0.89402684-0.44801211j,
         0.86972196-0.49354071j]], dtype=complex128),
 ('o2',
  'o2'): Array([[ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
          2.47607392e-23-9.35705089e-24j],
        [ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
         -1.36985066e-17-2.41396337e-17j]], dtype=complex128)}
from qpdk.models.waveguides import bend_s

bend_s(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
          2.47607392e-23-9.35705089e-24j],
        [ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
         -1.36985066e-17-2.41396337e-17j]], dtype=complex128),
 ('o1',
  'o2'): Array([[0.96688193-0.25522285j, 0.95242654-0.30476701j,
         0.93543428-0.35349939j],
        [0.91595042-0.40129019j, 0.89402684-0.44801211j,
         0.86972196-0.49354071j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.96688193-0.25522285j, 0.95242654-0.30476701j,
         0.93543428-0.35349939j],
        [0.91595042-0.40129019j, 0.89402684-0.44801211j,
         0.86972196-0.49354071j]], dtype=complex128),
 ('o2',
  'o2'): Array([[ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
          2.47607392e-23-9.35705089e-24j],
        [ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
         -1.36985066e-17-2.41396337e-17j]], dtype=complex128)}
from qpdk.models.waveguides import rectangle

rectangle(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
          2.47607392e-23-9.35705089e-24j],
        [ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
         -1.36985066e-17-2.41396337e-17j]], dtype=complex128),
 ('o1',
  'o2'): Array([[0.96688193-0.25522285j, 0.95242654-0.30476701j,
         0.93543428-0.35349939j],
        [0.91595042-0.40129019j, 0.89402684-0.44801211j,
         0.86972196-0.49354071j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.96688193-0.25522285j, 0.95242654-0.30476701j,
         0.93543428-0.35349939j],
        [0.91595042-0.40129019j, 0.89402684-0.44801211j,
         0.86972196-0.49354071j]], dtype=complex128),
 ('o2',
  'o2'): Array([[ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
          2.47607392e-23-9.35705089e-24j],
        [ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
         -1.36985066e-17-2.41396337e-17j]], dtype=complex128)}
from qpdk.models.waveguides import taper_cross_section

taper_cross_section(f=TEST_FREQUENCY)
{('o1',
  'o1'): Array([[ 1.56231947e-19+1.72529751e-18j,  3.74607115e-19+3.44228917e-18j,
          7.06323890e-18+1.64132019e-17j],
        [ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
         -3.43954008e-23+1.95183369e-23j]], dtype=complex128),
 ('o2',
  'o2'): Array([[ 7.15547265e-19+1.57765720e-18j,  1.69335686e-18+3.02030062e-18j,
          5.55692740e-18+1.69824371e-17j],
        [ 0.00000000e+00+0.00000000e+00j,  0.00000000e+00+0.00000000e+00j,
         -3.43954008e-23+1.95183369e-23j]], dtype=complex128),
 ('o1',
  'o2'): Array([[0.96688193-0.25522285j, 0.95242654-0.30476701j,
         0.93543428-0.35349939j],
        [0.91595042-0.40129019j, 0.89402684-0.44801211j,
         0.86972196-0.49354071j]], dtype=complex128),
 ('o2',
  'o1'): Array([[0.96688193-0.25522285j, 0.95242654-0.30476701j,
         0.93543428-0.35349939j],
        [0.91595042-0.40129019j, 0.89402684-0.44801211j,
         0.86972196-0.49354071j]], dtype=complex128)}
from qpdk.models.waveguides import launcher

launcher(f=TEST_FREQUENCY)
{('waveport',
  'waveport'): Array([[-3.58280574e-19-6.92963761e-18j, -2.14926465e-19-3.46278310e-18j,
          1.78835785e-20+1.06990386e-19j],
        [ 5.67590527e-20+2.65002236e-19j,  2.68719498e-20+1.04988872e-19j,
         -7.15605070e-19-6.90189435e-18j]], dtype=complex128),
 ('o1',
  'o1'): Array([[-7.17646376e-19-6.90168240e-18j, -4.30248880e-19-3.44266532e-18j,
          5.61197620e-21+1.08329481e-19j],
        [ 1.01415282e-20+2.70822740e-19j,  3.14531068e-21+1.08325567e-19j,
         -1.42759544e-18-6.79044882e-18j]], dtype=complex128),
 ('waveport',
  'o1'): Array([[0.99698799-0.07755486j, 0.99566369-0.09302468j,
         0.99409936-0.10847208j],
        [0.99229539-0.12389333j, 0.9902522 -0.13928472j,
         0.9879703 -0.15464252j]], dtype=complex128),
 ('o1',
  'waveport'): Array([[0.99698799-0.07755486j, 0.99566369-0.09302468j,
         0.99409936-0.10847208j],
        [0.99229539-0.12389333j, 0.9902522 -0.13928472j,
         0.9879703 -0.15464252j]], dtype=complex128)}

Couplers#

from qpdk.models.couplers import cpw_cpw_coupling_capacitance

cpw_cpw_coupling_capacitance(TEST_FREQUENCY, 100, 100, "cpw")
Array(7.93590386e-16, dtype=float64, weak_type=True)
from qpdk.models.couplers import coupler_straight

coupler_straight(f=TEST_FREQUENCY)
{('o2',
  'o2'): Array([[-2.48442103e-05-0.0024628j , -3.57751427e-05-0.00295528j,
         -4.86931075e-05-0.00344771j],
        [-6.35979000e-05-0.0039401j , -8.04892837e-05-0.00443242j,
         -9.93669908e-05-0.00492467j]], dtype=complex128),
 ('o3',
  'o3'): Array([[-2.48442103e-05-0.0024628j , -3.57751427e-05-0.00295528j,
         -4.86931075e-05-0.00344771j],
        [-6.35979000e-05-0.0039401j , -8.04892837e-05-0.00443242j,
         -9.93669908e-05-0.00492467j]], dtype=complex128),
 ('o1',
  'o1'): Array([[-2.48442103e-05-0.0024628j , -3.57751427e-05-0.00295528j,
         -4.86931075e-05-0.00344771j],
        [-6.35979000e-05-0.0039401j , -8.04892837e-05-0.00443242j,
         -9.93669908e-05-0.00492467j]], dtype=complex128),
 ('o4',
  'o4'): Array([[-2.48442103e-05-0.0024628j , -3.57751427e-05-0.00295528j,
         -4.86931075e-05-0.00344771j],
        [-6.35979000e-05-0.0039401j , -8.04892837e-05-0.00443242j,
         -9.93669908e-05-0.00492467j]], dtype=complex128),
 ('o3',
  'o2'): Array([[0.99996183-0.00762434j, 0.99994504-0.00914912j,
         0.99992519-0.01067384j],
        [0.99990229-0.01219851j, 0.99987634-0.0137231j ,
         0.99984734-0.01524762j]], dtype=complex128),
 ('o2',
  'o3'): Array([[0.99996183-0.00762434j, 0.99994504-0.00914912j,
         0.99992519-0.01067384j],
        [0.99990229-0.01219851j, 0.99987634-0.0137231j ,
         0.99984734-0.01524762j]], dtype=complex128),
 ('o3',
  'o1'): Array([[2.48442103e-05+0.0024628j , 3.57751427e-05+0.00295528j,
         4.86931075e-05+0.00344771j],
        [6.35979000e-05+0.0039401j , 8.04892837e-05+0.00443242j,
         9.93669908e-05+0.00492467j]], dtype=complex128),
 ('o2',
  'o1'): Array([[2.48442103e-05+0.0024628j , 3.57751427e-05+0.00295528j,
         4.86931075e-05+0.00344771j],
        [6.35979000e-05+0.0039401j , 8.04892837e-05+0.00443242j,
         9.93669908e-05+0.00492467j]], dtype=complex128),
 ('o1',
  'o3'): Array([[2.48442103e-05+0.0024628j , 3.57751427e-05+0.00295528j,
         4.86931075e-05+0.00344771j],
        [6.35979000e-05+0.0039401j , 8.04892837e-05+0.00443242j,
         9.93669908e-05+0.00492467j]], dtype=complex128),
 ('o1',
  'o2'): Array([[2.48442103e-05+0.0024628j , 3.57751427e-05+0.00295528j,
         4.86931075e-05+0.00344771j],
        [6.35979000e-05+0.0039401j , 8.04892837e-05+0.00443242j,
         9.93669908e-05+0.00492467j]], dtype=complex128),
 ('o3',
  'o4'): Array([[2.48442103e-05+0.0024628j , 3.57751427e-05+0.00295528j,
         4.86931075e-05+0.00344771j],
        [6.35979000e-05+0.0039401j , 8.04892837e-05+0.00443242j,
         9.93669908e-05+0.00492467j]], dtype=complex128),
 ('o4',
  'o3'): Array([[2.48442103e-05+0.0024628j , 3.57751427e-05+0.00295528j,
         4.86931075e-05+0.00344771j],
        [6.35979000e-05+0.0039401j , 8.04892837e-05+0.00443242j,
         9.93669908e-05+0.00492467j]], dtype=complex128),
 ('o4',
  'o2'): Array([[2.48442103e-05+0.0024628j , 3.57751427e-05+0.00295528j,
         4.86931075e-05+0.00344771j],
        [6.35979000e-05+0.0039401j , 8.04892837e-05+0.00443242j,
         9.93669908e-05+0.00492467j]], dtype=complex128),
 ('o4',
  'o1'): Array([[0.99996183-0.00762434j, 0.99994504-0.00914912j,
         0.99992519-0.01067384j],
        [0.99990229-0.01219851j, 0.99987634-0.0137231j ,
         0.99984734-0.01524762j]], dtype=complex128),
 ('o2',
  'o4'): Array([[2.48442103e-05+0.0024628j , 3.57751427e-05+0.00295528j,
         4.86931075e-05+0.00344771j],
        [6.35979000e-05+0.0039401j , 8.04892837e-05+0.00443242j,
         9.93669908e-05+0.00492467j]], dtype=complex128),
 ('o1',
  'o4'): Array([[0.99996183-0.00762434j, 0.99994504-0.00914912j,
         0.99992519-0.01067384j],
        [0.99990229-0.01219851j, 0.99987634-0.0137231j ,
         0.99984734-0.01524762j]], dtype=complex128)}
# Define frequency range from 1 GHz to 10 GHz with 201 points
f = jnp.linspace(1e9, 10e9, 201)

# Calculate coupler S-parameters for a 20 um straight coupler with 0.27 um gap
coupler = coupler_straight(f=f, length=20, gap=0.27)

# Create figure with single plot for comparison
fig, ax = plt.subplots(1, 1, figsize=(10, 6))

# Define S-parameters to plot
s_params = [
    (("o1", "o1"), "$S_{11}$ Reflection"),
    (("o1", "o2"), "$S_{12}$ Coupled branch 1"),
    (("o1", "o3"), "$S_{13}$ Coupled branch 2"),
    (("o1", "o4"), "$S_{14}$ Insertion loss (direct through)"),
]

# Plot each S-parameter for both coupler implementations
default_color_cycler = plt.cm.tab10.colors
for idx, (ports, label) in enumerate(s_params):
    color = default_color_cycler[idx % len(default_color_cycler)]
    # Plot both implementations with same color but different linestyles
    ax.plot(
        f / 1e9,
        20 * jnp.log10(jnp.abs(coupler[ports])),
        linestyle="-",
        color=color,
        label=f"{label} coupler_straight",
    )

# Configure plot
ax.set_xlabel("Frequency [GHz]")
ax.set_ylabel("$S$-parameter [dB]")
ax.set_title(r"$S$-parameters: $\mathtt{coupler\_straight}$")
ax.grid(True, which="both")
ax.legend()

plt.tight_layout()
plt.show()

# Example calculation of coupling capacitance
from qpdk.tech import coplanar_waveguide

cs = coplanar_waveguide(width=10, gap=6)
coupling_capacitance = cpw_cpw_coupling_capacitance(
    length=20.0, gap=0.27, cross_section=cs, f=f
)
print(
    "Coupling capacitance for 20 um length and 0.27 um gap:",
    coupling_capacitance,
    "F",
)
../_images/4a0943c0297f4f738072e07a3b0f0bc753cb33e041f69ac40a1bfc1b00b7ca48.svg
Coupling capacitance for 20 um length and 0.27 um gap: 3.1796355661188964e-15 F
from qpdk.models.couplers import cpw_cpw_coupling_capacitance_per_length_analytical

lengths = jnp.linspace(10, 100, 100)
gaps = jnp.linspace(0.1, 5.0, 5)
width = 10.0
cpw_gap = 6.0
ep_r = 11.7

plt.figure(figsize=(10, 6))

# Calculate capacitance per unit length for all gaps simultaneously (shape: (5,))
c_pul = cpw_cpw_coupling_capacitance_per_length_analytical(
    gap=gaps, width=width, cpw_gap=cpw_gap, ep_r=ep_r
)

# Broadcast to compute total capacitance for all lengths and gaps (shape: (5, 100))
capacitances = c_pul[:, None] * lengths[None, :] * 1e-6 * 1e15  # Convert to fF

for i, gap in enumerate(gaps):
    plt.plot(lengths, capacitances[i], label=f"gap = {gap:.1f} µm")

plt.xlabel("Coupling Length (µm)")
plt.ylabel("Mutual Capacitance (fF)")
plt.title(
    rf"CPW-CPW Coupling Capacitance ($\mathtt{{width}}=${width} µm, $\mathtt{{cpw\_gap}}=${cpw_gap} µm, $\epsilon_r={ep_r}$)"
)
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.show()
../_images/6e082aae6d08ccd6f56b51aee6dcaba98fe5cba7133aa12ebe5f6250a05b74c1.svg

Resonators#

from qpdk.models.resonator import quarter_wave_resonator_coupled

quarter_wave_resonator_coupled(f=TEST_FREQUENCY)
{('coupling_o1',
  'coupling_o1'): Array([[-1.92127284e-05-0.0025057j , -4.11748734e-05-0.00401921j,
         -3.54557763e-05-0.00335163j],
        [-4.71561451e-05-0.00388343j, -6.00836571e-05-0.00439105j,
         -7.44965461e-05-0.00489475j]], dtype=complex128),
 ('coupling_o2',
  'coupling_o2'): Array([[-1.92127284e-05-0.0025057j , -4.11748734e-05-0.00401921j,
         -3.54557763e-05-0.00335163j],
        [-4.71561451e-05-0.00388343j, -6.00836571e-05-0.00439105j,
         -7.44965461e-05-0.00489475j]], dtype=complex128),
 ('resonator_o1',
  'resonator_o1'): Array([[1.+0.j, 1.+0.j, 1.+0.j],
        [1.+0.j, 1.+0.j, 1.+0.j]], dtype=complex128),
 ('coupling_o1',
  'coupling_o2'): Array([[0.99996746-0.00766725j, 0.99993964-0.01021305j,
         0.99993843-0.01057775j],
        [0.99991873-0.01214184j, 0.99989675-0.01368174j,
         0.99987221-0.0152177j ]], dtype=complex128),
 ('coupling_o2',
  'coupling_o1'): Array([[0.99996746-0.00766725j, 0.99993964-0.01021305j,
         0.99993843-0.01057775j],
        [0.99991873-0.01214184j, 0.99989675-0.01368174j,
         0.99987221-0.0152177j ]], dtype=complex128),
 ('resonator_o1',
  'coupling_o1'): Array([[0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex128),
 ('resonator_o1',
  'coupling_o2'): Array([[0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex128),
 ('coupling_o1',
  'resonator_o1'): Array([[0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex128),
 ('coupling_o2',
  'resonator_o1'): Array([[0.+0.j, 0.+0.j, 0.+0.j],
        [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex128)}
from qpdk.models.resonator import resonator_frequency

cs = coplanar_waveguide(width=10, gap=6)
ep_eff, z0 = cpw_parameters(*get_cpw_dimensions(cs))
print(f"{ep_eff=!r}")
print(f"{z0=!r}")  # Characteristic impedance

res_freq = resonator_frequency(
    length=4000, epsilon_eff=float(jnp.real(ep_eff)), is_quarter_wave=True
)
print("Resonance frequency (quarter-wave):", res_freq / 1e9, "GHz")

# Plot resonator_coupled example
f = jnp.linspace(0.1e9, 9e9, 1001)
resonator = quarter_wave_resonator_coupled(
    f=f,
    cross_section=cs,
    coupling_gap=0.27,
    length=4000,
)

fig, ax = plt.subplots(1, 1, figsize=(10, 6))

for key in [
    ("coupling_o2", "resonator_o1"),
    ("coupling_o1", "coupling_o2"),
    ("coupling_o1", "resonator_o1"),
]:
    ax.plot(f / 1e9, 20 * jnp.log10(jnp.abs(resonator[key])), label=f"$S${key}")
ax.set_xlabel("Frequency [GHz]")
ax.set_ylabel("Magnitude [dB]")
ax.set_title(r"$S$-parameters: $\mathtt{resonator\_coupled}$ (3-port)")
ax.grid(True, which="both")
ax.legend()

plt.show()
# ruff: enable[E402]
ep_eff=Array(6.06519124-1.49847261e-05j, dtype=complex128)
z0=Array(49.31279884, dtype=float64)
Resonance frequency (quarter-wave): 7.6081395616176914 GHz
../_images/0a13b57a19002c50dd546ecc479ef86878d52990c81904048ac4cc6bfc767739.svg