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 inspect
import sys

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

from qpdk.config import PATH as QPDKPath

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

from models.test_compare_to_qucs import BaseCompareToQucs

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

    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 4 test suite(s):
	· TestCPWCompareToQucs
	· TestCapacitorCompareToQucs
	· TestCouplerStraightCompareToQucs
	· TestInductorCompareToQucs

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__}`"))
    display(
        Markdown(
            f"**Parameter:** {test_instance.parameter_name} = {test_instance.parameter_value / test_instance.parameter_unit:.2f} × 10^{int(np.log10(test_instance.parameter_unit))}"
        )
    )
    display(Markdown(f"**CSV:** `{test_instance.csv_filename}`"))
    test_instance.plot_comparison()

Coplanar waveguide

Test Suite: TestCPWCompareToQucs

Parameter: length = 10000000000.00 × 10^-6

CSV: cpw_w10_s_6_l10mm.csv

../_images/06bbe8ef8ca9143f861452d1d6049705948bc8c37f1d86f63379e53b25f1b391.svg

Capacitor

Test Suite: TestCapacitorCompareToQucs

Parameter: capacitance = 60.00 × 10^-15

CSV: capacitor_qucs.csv

../_images/0a248e0b2565ff710149efaea9c6edcbc2e474fa17bf1eaa4d49090694baed71.svg

Coupler Straight

Test Suite: TestCouplerStraightCompareToQucs

Parameter: length = 10000000.00 × 10^-6

CSV: coupler_straight_qucs.csv

../_images/b4836988de6405fa7faab301e0b2c372371db52932e8ad0838fb940365f8bd8b.svg

Inductor

Test Suite: TestInductorCompareToQucs

Parameter: inductance = 10.00 × 10^-9

CSV: inductor_qucs.csv

../_images/f048e724c45824c7ce067b24413adc82fcfeaeef72312079bc5847c3ddbc6c37.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.