Model Comparison to Qucs-S#

This notebook compares the S-parameter models from qpdk (using sax) against reference results from Qucs-S simulations. Each test suite validates a different component model.

The comparisons include:

  • Polar plots showing S-parameters in the complex plane

  • Magnitude and phase plots versus frequency

  • Visual validation of model accuracy against reference data

Hide code cell source

import sys

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

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

Hide code cell source

import inspect
import sys

import numpy as np
from IPython.display import Markdown, display

from qpdk import PDK
from qpdk.config import PATH as QPDK_PATH

# Add the tests directory to the path so we can import the test modules
sys.path.insert(0, str(QPDK_PATH.tests))

from models.test_compare_to_qucs import BaseCompareToQucs

PDK.activate()

Discover Test Suites#

Dynamically discover all test suite classes that compare qpdk models to Qucs-S results. We find all classes that:

  1. Are subclasses of BaseCompareToQucs

  2. Are not the base class itself

  3. Are concrete classes (not abstract)

Hide code cell source

def discover_test_suites() -> list[type[BaseCompareToQucs]]:
    """Discover all test suite classes for Qucs-S comparison.

    Returns:
        List of test suite classes that inherit from :class:`~BaseCompareToQucs`.
    """
    # Import the module to get all classes
    from models import test_compare_to_qucs  # noqa: PLC0415

    test_suites = []

    # Get all members of the module
    for _name, obj in inspect.getmembers(test_compare_to_qucs):
        # Check if it's a class
        if not inspect.isclass(obj):
            continue

        # Check if it's a subclass of BaseCompareToQucs but not the base class itself
        if not issubclass(obj, BaseCompareToQucs) or obj is BaseCompareToQucs:
            continue

        # Check if it's a concrete class (not abstract)
        if inspect.isabstract(obj):
            continue

        test_suites.append(obj)

    return test_suites
# Discover all available test suites
test_suites = discover_test_suites()
print(f"Found {len(test_suites)} test suite(s):")
for suite in test_suites:
    print(f"\t· {suite.__name__}")
Found 5 test suite(s):
	· TestCPWCompareToQucs
	· TestCapacitorCompareToQucs
	· TestCouplerStraightCompareToQucs
	· TestInductorCompareToQucs
	· TestLCResonatorCompareToQucs

Model Comparison#

Compare the S-parameter models against Qucs-S reference data.

# Find and plot all test suites

for suite in test_suites:
    test_instance = suite()
    display(Markdown(f"### {test_instance.component_name}"))
    display(Markdown(f"**Test Suite:** `{suite.__name__}`"))

    param_strs = [
        f"{p.name} = {p.value / p.unit:.2f} × 10^{int(np.log10(p.unit))}"
        for p in sorted(test_instance.parameters, key=lambda x: x.name)
    ]
    param_text = "**Parameters:**\n" + "\n".join(f"- {p}" for p in param_strs)
    display(Markdown(param_text))

    display(Markdown(f"**CSV:** `{test_instance.csv_filename}`"))
    test_instance.plot_comparison()

Coplanar waveguide

Test Suite: TestCPWCompareToQucs

Parameters:

  • length = 10000000000.00 × 10^-6

CSV: cpw_w10_s_6_l10mm.csv

../_images/cd0788d14d244b804239dc32c1665ecf1d02b26866361e3c0aaa81f02061cb2c.svg

Capacitor

Test Suite: TestCapacitorCompareToQucs

Parameters:

  • capacitance = 60.00 × 10^-15

CSV: capacitor_qucs.csv

../_images/ae6f5ef96d8843706ee5f4dc4ddf843b1fad8fad8dab26f2f07e9dd006debc90.svg

Coupler Straight

Test Suite: TestCouplerStraightCompareToQucs

Parameters:

  • gap = 1520000.00 × 10^-6

  • length = 500000000.00 × 10^-6

CSV: coupler_straight_qucs.csv

../_images/bbc2db91d5abc7bc3df25d0c4d353f840cf8183072f369bdf1f8e05e6dd786da.svg

Inductor

Test Suite: TestInductorCompareToQucs

Parameters:

  • inductance = 10.00 × 10^-9

CSV: inductor_qucs.csv

../_images/d8c3f63a3d6463869938c44d4120844c27008f6eb32cdd5c41eee503e91624b3.svg

LC Resonator

Test Suite: TestLCResonatorCompareToQucs

Parameters:

  • capacitance = 10.00 × 10^-15

  • inductance = 10.00 × 10^-9

CSV: lc_resonator_qucs.csv

../_images/3a028183b4eb1e92491728e4c8f9853ed107b06f462f841ef12902915b0958ff.svg

Summary#

The plots above show comparisons between qpdk models (dashed lines) and Qucs-S reference simulations (solid lines) for various passive components:

  • Left plot: Polar representation showing S-parameters in the complex plane

  • Right plot: Magnitude (in dB) and phase (in radians) versus frequency

Good agreement between the models validates the accuracy of the qpdk implementations for use in circuit simulations and design optimization.