def test_netlists(
    yaml_key: str,
    full_settings: bool,
    data_regression: DataRegressionFixture,
    check: bool = True,
) -> None:
    """Write netlists for hierarchical circuits.
    Checks that both netlists are the same
    jsondiff does a hierarchical diff

    Component -> netlist -> Component -> netlist
    """
    yaml_string = yaml_strings[yaml_key]
    c = from_yaml(yaml_string)
    n = c.get_netlist(full_settings=full_settings)
    if check:
        data_regression.check(OmegaConf.to_container(n))

    yaml_str = OmegaConf.to_yaml(n, sort_keys=True)
    # print(yaml_str)
    c2 = from_yaml(yaml_str)
    n2 = c2.get_netlist(full_settings=full_settings)
    d = jsondiff.diff(n, n2)
    assert len(d) == 0, print(d)
    return c2
def _demo_netlist():
    """path on the route"""
    import gdsfactory as gf

    # c = from_yaml(sample_2x2_connections)
    c = from_yaml(sample_waypoints)
    c = from_yaml(sample_different_factory)
    c.show()
    full_settings = True
    n = c.get_netlist(full_settings=full_settings)
    yaml_str = OmegaConf.to_yaml(n, sort_keys=True)
    c2 = from_yaml(yaml_str)
    n2 = c2.get_netlist(full_settings=full_settings)
    d = jsondiff.diff(n, n2)
    assert len(d) == 0
    gf.show(c2)
def test_connections_waypoints() -> Component:
    c = from_yaml(sample_waypoints)

    length = 2036.548
    route_name = "b,e11:t,e11"
    assert np.isclose(c.routes[route_name], length), c.routes[route_name]
    return c
def test_connections_different_link_factory() -> Component:
    c = from_yaml(sample_different_link_factory)

    length = 1719.822
    assert np.isclose(c.routes["tl,e3:tr,e1"], length), c.routes["tl,e3:tr,e1"]
    assert np.isclose(c.routes["bl,e3:br,e1"], length), c.routes["bl,e3:br,e1"]
    return c
def test_connections_regex_backwargs() -> Component:
    c = from_yaml(sample_regex_connections_backwards)
    route_names = ["left,o1:right,o1", "left,o2:right,o2", "left,o3:right,o3"]

    length = 12.0
    for route_name in route_names:
        assert np.isclose(c.routes[route_name], length), c.routes[route_name]
    return c
def test_connections_2x2() -> Component:
    c = from_yaml(sample_2x2_connections)
    assert len(c.get_dependencies()) == 8, len(c.get_dependencies())
    assert len(c.ports) == 0, len(c.ports)

    length = c.routes["mmi_bottom,o3:mmi_top,o2"]
    assert np.isclose(length, 165.774), length
    return c
def test_settings(yaml_key: str,
                  data_regression: DataRegressionFixture,
                  check: bool = True) -> Component:
    """Avoid regressions when exporting settings."""
    yaml_string = yaml_strings[yaml_key]
    c = from_yaml(yaml_string)

    if check:
        data_regression.check(c.to_dict())
    return c
def test_connections_different_factory() -> Component:
    c = from_yaml(sample_different_factory)
    lengths = [693.274, 693.274, 1199.144]

    assert np.isclose(c.routes["tl,e3:tr,e1"],
                      lengths[0]), c.routes["tl,e3:tr,e1"]
    assert np.isclose(c.routes["bl,e3:br,e1"],
                      lengths[1]), c.routes["bl,e3:br,e1"]
    assert np.isclose(c.routes["bl,e4:br,e3"],
                      lengths[2]), c.routes["bl,e4:br,e3"]

    return c
def test_connections() -> Component:
    c = from_yaml(sample_connections)
    assert len(c.get_dependencies()) == 2
    assert len(c.ports) == 0
    return c
def test_sample() -> Component:
    c = from_yaml(sample_mmis)
    assert len(c.get_dependencies()) == 6, len(c.get_dependencies())
    assert len(c.ports) == 3, len(c.ports)
    return c
def test_gds(yaml_key: str, data_regression: DataRegressionFixture) -> None:
    """Avoid regressions in GDS geometry shapes and layers."""
    yaml_string = yaml_strings[yaml_key]
    c = from_yaml(yaml_string)
    difftest(c)
def test_docstring_sample() -> Component:
    c = from_yaml(sample_docstring)
    route_name = "mmi_top,o3:mmi_bot,o1"
    length = 72.024
    assert np.isclose(c.routes[route_name], length), c.routes[route_name]
    return c