ComponentReferenceTest

class ip_manager.testing.ComponentReferenceTest

Test LayoutView, NetlistView and CircuitModelView of a component against known-good reference files.

Pytest test class which integrates multiple tests into one.

  • The tests to be run can be selected by marking the class with the comparisons mark (see example below).

  • Known-good reference files can be regenerated after a known change by running pytest --regenerate.

  • Configuration of each test is done through pytest fixtures.

Compare.LayoutToGds:

Compares the in-memory layout to a layout imported from a GDSII file, without GDSII filters applied. Also writes a temporary GDSII file with the in-memory layout for easy comparison.

Compare.GdsToGds:

Writes the in-memory layout to a temporary GDSII file and reads it back in. Then, compares it with a layout imported from a GDSII file with GDSII filters applied.

Compare.LayoutToXML:

Exports an XML of the Layout (layout drawing data only, no port information), without TECH.GDSII.FILTER applied. Compares the exported XML to a reference XML.

Compare.LayoutDrawingToXML:

Exports an XML of the Layout (layout drawing data only, no port information) without TECH.GDSII.FILTER applied. Compares the exported XML to a reference XML.

Compare.NetlistToXML:

Exports an XML of the Netlist and compares to a reference XML.

Compare.SMatrix:

Compares the in-memory s-matrix of the CircuitModelView to a reference smatrix for the specified wavelengths. Also, writes the in-memory s-matrix to a temporary file.

Examples

# Example of how to select 3 tests on a ComponentReferenceTest

from ip_manager.testing import ComponentReferenceTest, Compare
import pytest

@pytest.mark.comparisons([Compare.LayoutToGds, Compare.NetlistToXML, Compare.SMatrix])
class TestMyComponent(ComponentReferenceTest):
    @pytest.fixture
    def wavelengths(self):
        return np.arange(1.25, 1.351, 0.01)

    @pytest.fixture
    def component(self):
        return MyComponent(name="my_component")
class Config
xor_equivalence = True
similarity_tolerance = 0.02
ref_time = datetime.datetime(2014, 6, 10, 10, 10, 10, tzinfo=datetime.timezone.utc)
export_layer_map(TECH)

Fixture to configure the GDSII export layer map.

Used by Compare.LayoutToGds, Compare.GdsToGds and Compare.LayoutDrawingToXML. Defaults to TECH.GDSII.EXPORT_LAYER_MAP.

import_layer_map(TECH)

Fixture to configure the GDSII import layer map.

Used by Compare.LayoutToGds and Compare.GdsToGds. Defaults to TECH.GDSII.IMPORT_LAYER_MAP.

xor_equivalence(reference_test_config)

Fixture to configure if XOR equivalence is enough on geometrical object

similarity_tolerance(reference_test_config)

Fixture to configure the maximum relative tolerance for S-models to be considered equal.

Used by Compare.SMatrix. A value of 0.0 means perfect equality, while 0.1 would allow for sizable deviations. Defaults to 0.02

ref_time(reference_test_config)

Fixture to configure the timestamp in the GDS reference files.

Timestamp can be either specified as:

timestamp(ref_time)

Convert the reference time to a datetime.datetime

refname_layout_to_gds(reference_name)

Fixture to configure the name of the known-good reference file for Compare.LayoutToGds

Defaults to reference_name + ‘_layout_nofilter.gds’.

tmpname_layout_to_gds(reference_name)

Fixture to configure the name of the temporary file (current layout) saved by Compare.LayoutToGds

Defaults to reference_name + ‘_layout_nofilter.tmp.gds’.

refname_gds_to_gds(reference_name)

Fixture to configure the name of the known-good reference file for Compare.GdsToGds

Defaults to reference_name + ‘_layout.gds’.

tmpname_gds_to_gds(reference_name)

Fixture to configure the name of the temporary file (current layout) saved by Compare.GdsToGds

Defaults to reference_name + ‘_layout.tmp.gds’.

refname_layout_to_xml(reference_name)

Fixture to configure the name of the known-good reference file for Compare.LayoutToXML

Defaults to reference_name + ‘_layout.xml’.

tmpname_layout_to_xml(reference_name)

Fixture to configure the name of the temporary file (current layout) saved by Compare.LayoutToXML

Defaults to reference_name + ‘_layout.tmp.xml’.

refname_layoutdrawing_to_xml(reference_name)

Fixture to configure the name of the known-good reference file for Compare.LayoutDrawingToXML

Defaults to reference_name + ‘_layout_nofilter.xml’.

tmpname_layoutdrawing_to_xml(reference_name)

Fixture to configure the name of the temporary file (current layout) saved by Compare.LayoutDrawingToXML

Defaults to reference_name + ‘_layout_nofilter.tmp.xml’.

refname_netlist_to_xml(reference_name)

Fixture to configure the name of the known-good reference file for Compare.NetlistToXML

Defaults to reference_name + ‘_netlist.xml’.

tmpname_netlist_to_xml(reference_name)

Fixture to configure the name of the temporary file (current layout) saved by Compare.NetlistToXML

Defaults to reference_name + ‘_netlist.tmp.xml’.

refname_smatrix(smatrix, reference_name)

Fixture to configure the name of the known-good reference file for Compare.SMatrix

Defaults to reference_name + ‘_caphe.s${n_ports * n_modes}p’.

tmpname_smatrix(smatrix, reference_name)

Fixture to configure the name of the temporary file (current layout) saved by Compare.SMatrix

Defaults to reference_name + ‘_caphe.tmp.s${n_ports * n_modes}p’.

circuitmodel(component)

Fixture returning the circuit model view to be tested.

Defaults to the default CircuitModelView of component.

abstract component()

Fixture returning the component (i3.PCell object) to be tested.

Needs to be implemented by the user.

library_name(component)

Fixture specifying the library name to use in the files.

Defaults to component.name.

plot_dB_range()

Fixture specifying the power [dB] range, for example: (-20.0, 0.0).

An empty tuple or ‘False’ means that a linear scale will be employed instead of a dB-scale.

Note that ‘autouse=True’ should always be supplied!

plot_terms()

Fixture specifying a list of term links to be plotted in the HTML report in case of failed tests.

reference_folder(request, reference_folder_name)

Fixture returning the full reference folder path

Creates the necessary directories if they don’t exist. Should not be overridden (use ‘reference_folder_name’ instead).

reference_folder_name()

Fixture for configuring the relative folder path in which the known-good reference files are saved.

Defaults to ‘ref’

reference_name(request)

Fixture for configuring the reference file name, without the folder path.

Defaults to the class name of the test class. Should be overridden when defining parametrized tests!

smatrix(circuitmodel, wavelengths)

Fixture returning the S-matrix calculated from ‘circuitmodel’.

Calls get_smatrix() on circuitmodel. Uses the wavelengths fixture, which needs to be defined by the user.

temp_folder(request, temp_folder_name)

Fixture returning the full temporary folder path.

Creates the necessary directories if they don’t exist. Should not be overridden (use ‘temp_folder_name’ instead).

temp_folder_name(reference_folder_name)

Fixture specifying the relative folder path in which the temporary files are saved.

Defaults to be the same as reference_folder_name.

wavelengths()

Fixture specifying the wavelength array for which to generate the smatrix fixture.

Takes the form of a numpy array or a list. Needs to be overriden by the user.