def test_component_from_yaml_without_cell():
    """ bezier does not have cell """
    c = pp.component_from_yaml(yaml)
    assert c.name == "test_component_from_yaml_without_cell"
    assert len(c.get_dependencies()) == 2
    assert len(c.ports) == 0
    return c
Пример #2
0
def test_mzi():

    netlist = """
    instances:
        CP1:
          component: mmi1x2
          settings:
              width_mmi: 4.5
              length_mmi: 10
        CP2:
            component: mmi1x2
            settings:
                width_mmi: 4.5
                length_mmi: 5
        arm_top:
            component: mzi_arm
        arm_bot:
            component: mzi_arm

    placements:
        arm_bot:
            mirror: [0,0,0,10]
    ports:
        W0: CP1,W0
        E0: CP2,W0

    connections:
        arm_bot,W0: CP1,E0
        arm_top,W0: CP1,E1
        CP2,E0: arm_bot,E0
        CP2,E1: arm_top,E0
    """

    return pp.component_from_yaml(netlist)
Пример #3
0
def test_netlist_labels():
    c = pp.component_from_yaml(yaml)
    n = c.get_netlist()
    placements = n["placements"]
    print(placements)
    assert "bend_left" in placements
    assert "bend_right" in placements
Пример #4
0
def test_netlist_read():
    import pp

    c = pp.component_from_yaml(pp.CONFIG["netlists"] / "mzi.yml")
    # print(c.get_netlist().pretty())
    # print((c.get_netlist().connections.pretty()))
    # print(len(c.get_netlist().connections))
    # print(len(c.get_dependencies()))
    assert len(c.get_dependencies()) == 5
    assert len(c.get_netlist().connections) == 18
def test_netlist_read_full():
    import pp

    filepath = pp.CONFIG["netlists"] / "mzi_full.yml"
    c = pp.component_from_yaml(filepath)
    # print(c.get_netlist().pretty())
    # print((c.get_netlist().connections.pretty()))
    # print(len(c.get_netlist().connections))
    # print(len(c.get_dependencies()))
    # assert len(c.get_netlist().connections) == 18
    assert len(c.get_dependencies()) == 18
    return c
Пример #6
0
def test_netlists(component_type, full_settings, data_regression):
    """Write netlists for hierarchical circuits.
    Checks that both netlists are the same
    jsondiff does a hierarchical diff

    Component -> netlist -> Component -> netlist
    """
    c = component_factory[component_type]()
    n = c.get_netlist(full_settings=full_settings)
    data_regression.check(n)

    yaml_str = OmegaConf.to_yaml(n, sort_keys=True)
    c2 = pp.component_from_yaml(yaml_str)
    n2 = c2.get_netlist(full_settings=full_settings)
    d = jsondiff.diff(n, n2)
    assert len(d) == 0
def test_netlist_yaml():
    """

    .. code::

           arm_top
            _____
           |     |
       CP1=       =CP2=
           |_____|

            arm_bot
   """

    yaml = """
    instances:
        mmi_long:
          component: mmi1x2
          settings:
            width_mmi: 4.5
            length_mmi: 10
        mmi_short:
          component: mmi1x2
          settings:
            width_mmi: 4.5
            length_mmi: 5

    placements:
        mmi_long:
            rotation: 180
            x: 100
            y: 100

    routes:
        optical:
            factory: optical
            links:
                mmi_short,E1: mmi_long,E0

    ports:
        E0: mmi_short,W0
        W0: mmi_long,W0
    """

    c = pp.component_from_yaml(yaml)
    return c
Пример #8
0
    coupler_lengths = [10, 20, 30, 40]
    coupler_gaps = [0.1, 0.2, 0.4, 0.5]
    delta_lengths = [10, 100, 200]

    c = pp.c.mzi_lattice(
        coupler_lengths=coupler_lengths,
        coupler_gaps=coupler_gaps,
        delta_lengths=delta_lengths,
    )
    c.get_netlist()
    print(c.get_netlist_yaml())


if __name__ == "__main__":
    from pprint import pprint

    from omegaconf import OmegaConf

    import pp
    from pp.test_component_from_yaml import sample_2x2_connections

    c = pp.component_from_yaml(sample_2x2_connections)
    pp.show(c)
    pprint(c.get_netlist())

    n = c.get_netlist()
    yaml_str = OmegaConf.to_yaml(n, sort_keys=True)
    c2 = pp.component_from_yaml(yaml_str)
    pp.show(c2)
Пример #9
0
def test_circular_import_pass():
    pp.component_from_yaml(yaml_pass)
Пример #10
0
        width_mmi: 4.5
        length_mmi: 5

placements:
    mmi_short:
        port: W0
        x: 0
        y: 0
    mmi_long:
        port: W0
        x: mmi_short,E1
        y: mmi_short,E1
        dx : 10
        dy: 20
"""

# def test_circular_import_fail():
#     with pytest.raises(ValueError):
#         pp.component_from_yaml(yaml_fail)


def test_circular_import_pass():
    pp.component_from_yaml(yaml_pass)


if __name__ == "__main__":
    # c = test_circular_import_pass()
    # c = test_circular_import_fail()
    c = pp.component_from_yaml(yaml_fail)
    pp.show(c)
def test_mzi():
    return pp.component_from_yaml(netlist)
Пример #12
0
    # c = pp.c.mzi()
    # pp.show(c)

    c = pp.c.ring_single()

    pp.show(c)

    n = get_netlist(c)
    connections = n["connections"]
    placements = n["placements"]
    instances = n["instances"]
    ports = n["ports"]

    # pprint(placements)
    pprint(instances)
    # print(placements)

    # connections, instances, placements = get_netlist(c.references[0].parent)
    # print(connections)
    # print(ports)
    # print(instances)

    n = c.get_netlist()
    # n.pop('connections')
    # n.pop('placements')

    yaml_str = OmegaConf.to_yaml(n, sort_keys=True)
    # print(yaml_str)
    c2 = pp.component_from_yaml(yaml_str)
    pp.show(c2)
Пример #13
0
import pp

yaml = """

instances:
    mmi1:
        component: mmi1x2

    mmi2:
        component: mmi1x2

placements:
    mmi2:
        port: 'E0'
        x: mmi1,E0
        dy: -0.625
        mirror: True

"""


if __name__ == "__main__":
    c = pp.component_from_yaml(yaml)
    pp.show(c)
Пример #14
0
def test_circular_import_fail():
    with pytest.raises(ValueError):
        pp.component_from_yaml(yaml_fail)
Пример #15
0
placements:
    mmi_short:
        port: W0
        x: 0
        y: 0
    mmi_long:
        port: W0
        x: mmi_short,E1
        y: mmi_short,E1
        dx: 10
        dy: -10
ports:
    W0: mmi_long,E0
"""


yaml_list = [mirror_port, mirror_x, rotation, dxdy]


@pytest.mark.parametrize("yaml_index", range(len(yaml_list)))
def test_components_ports(yaml_index, num_regression):
    yaml = yaml_list[yaml_index]
    c = pp.component_from_yaml(yaml)
    if c.ports:
        num_regression.check(c.get_ports_array())


if __name__ == "__main__":
    c = pp.component_from_yaml(mirror_port)
    pp.show(c)
Пример #16
0
def test_components_ports(yaml_index, num_regression):
    yaml = yaml_list[yaml_index]
    c = pp.component_from_yaml(yaml)
    if c.ports:
        num_regression.check(c.get_ports_array())
Пример #17
0
def demo_netlist(component_type):
    c1 = component_factory[component_type]()
    n = c1.get_netlist()
    yaml_str = OmegaConf.to_yaml(n, sort_keys=True)
    c2 = pp.component_from_yaml(yaml_str)
    pp.show(c2)