Beispiel #1
0
def test_subckt_instantiation(library, test_ckt):
    with set_context(library):
        subckt = SubCircuit(name='SUBCKT',
                            pins=['PIN1', 'PIN2'],
                            parameters={
                                'PARAM1': 1,
                                'PARAM2': 1e-3,
                                'PARAM3': 1E-16,
                                'PARAM4': "HELLO"
                            })
        library.append(subckt)
    with set_context(subckt.elements):
        X1 = Instance(name='X1',
                      model='TwoTerminalDevice',
                      pins={
                          'A': 'NET1',
                          'B': 'NET2'
                      },
                      generator='Dummy')
        X2 = Instance(name='X2',
                      model='TwoTerminalDevice',
                      pins={
                          'A': 'NET2',
                          'B': 'NET3'
                      },
                      generator='Dummy')
    subckt.elements.append(X1)
    subckt.elements.append(X2)
    assert subckt.elements == [X1, X2]
    assert subckt.elements[0] == X1
    assert subckt.elements[1] == X2
    assert subckt.get_element('x1') == X1
    assert subckt.nets == ['NET1', 'NET2', 'NET3']
    with set_context(test_ckt.elements):
        with pytest.raises(Exception):
            inst = Instance(name='X1', model='subckt', generator='Dummy')
        with pytest.raises(Exception):
            inst = Instance(name='X1',
                            model='subckt',
                            pins={'PIN1': 'NET10'},
                            generator='Dummy')
        inst = Instance(name='X1',
                        model='subckt',
                        pins={
                            'PIN1': 'NET10',
                            'PIN2': 'NET12'
                        },
                        generator='Dummy')
    assert inst.name == 'X1'
    assert inst.model == 'SUBCKT'
    assert inst.pins == {'PIN1': 'NET10', 'PIN2': 'NET12'}
    assert inst.parameters == {
        'PARAM1': '1',
        'PARAM2': '0.001',
        'PARAM3': '1E-16',
        'PARAM4': 'HELLO'
    }
Beispiel #2
0
def test_subckt_definition(library, test_ckt):
    with set_context(library):
        subckt = SubCircuit(name='SUBCKT',
                            pins=['PIN1', 'PIN2'],
                            parameters={
                                'PARAM1': 1,
                                'PARAM2': '1E-3',
                                'PARAM3': '0.1F',
                                'PARAM4': 'HELLO'
                            })
        library.append(subckt)
    with set_context(test_ckt.elements):
        with pytest.raises(Exception):
            inst = Instance(name='X1', model='subckt', generator='Dummy')
        with pytest.raises(Exception):
            inst = Instance(name='X1',
                            model='subckt',
                            pins={'PIN1': 'NET10'},
                            generator='Dummy')
        inst = Instance(name='X1',
                        model='subckt',
                        pins={
                            'PIN1': 'NET10',
                            'PIN2': 'NET12'
                        },
                        generator='Dummy')
    assert inst.name == 'X1'
    assert inst.model == 'SUBCKT'
    assert inst.pins == {'PIN1': 'NET10', 'PIN2': 'NET12'}
    assert list(
        inst.parameters.keys()) == ['PARAM1', 'PARAM2', 'PARAM3', 'PARAM4']
    assert inst.parameters['PARAM1'] == '1'
    assert inst.parameters['PARAM2'] == '1E-3'
    assert inst.parameters['PARAM3'] == '0.1F'
    assert inst.parameters['PARAM4'] == 'HELLO'
    with set_context(test_ckt.elements):
        with pytest.raises(Exception):
            inst = subckt(name='X1',
                          model='subckt',
                          pins={
                              'PIN1': 'NET10',
                              'PIN2': 'NET12'
                          },
                          parameters={'garbage': ''},
                          generator='Dummy')
        inst = Instance(name='X1',
                        model='subckt',
                        pins={
                            'PIN1': 'NET10',
                            'PIN2': 'NET12'
                        },
                        parameters={
                            'param1': '2',
                            'param3': '1e-16'
                        },
                        generator='Dummy')
    assert inst.parameters['PARAM1'] == '2'
    assert inst.parameters['PARAM3'] == '1E-16'
Beispiel #3
0
def test_parser_basic(setup_basic, parser):
    parser.library['TESTDEV'] = SubCircuit(name='TESTDEV',
                                           pins=['+', '-'],
                                           parameters={
                                               'X': '1F',
                                               'Y': '0.1'
                                           })
    parser.parse(setup_basic)
    assert len(parser.circuit.elements) == 1
    assert parser.circuit.elements[0].name == 'X1'
    assert parser.circuit.elements[0].model.name == 'TESTDEV'
    assert parser.circuit.nets == ['A', 'B']
Beispiel #4
0
def test_subckt_instantiation(TwoTerminalDevice):
    subckt = SubCircuit(name='TEST_SUBCKT', pins=['PIN1', 'PIN2'], parameters={'PARAM1':1, 'PARAM2':1e-3, 'PARAM3':1E-16, 'PARAM4':"HELLO"})
    X1 = Instance(name='X1', model=TwoTerminalDevice, pins={'A': 'NET1', 'B': 'NET2'})
    X2 = Instance(name='X2', model=TwoTerminalDevice, pins={'A': 'NET2', 'B': 'NET3'})
    subckt.add(X1)
    subckt.add(X2)
    assert subckt.elements == [X1, X2]
    assert subckt.elements[0] == X1
    assert subckt.elements[1] == X2
    assert subckt.nets == ['NET1', 'NET2', 'NET3']
    with pytest.raises(Exception):
        inst = subckt('X1')
    with pytest.raises(Exception):
        inst = subckt('X1', 'NET10')
    inst = Instance(name='X1', model=subckt, pins={'PIN1': 'NET10', 'PIN2': 'NET12'})
    assert inst.name == 'X1'
    assert inst.model.name == 'TEST_SUBCKT'
    assert inst.pins == {'PIN1': 'NET10', 'PIN2': 'NET12'}
    assert inst.parameters == {'PARAM1': '1', 'PARAM2': '0.001', 'PARAM3': '1E-16', 'PARAM4': 'HELLO'}
    assert inst.model.elements == [X1, X2]
    assert inst.model.elements[0] == X1
    assert inst.model.elements[1] == X2
    assert inst.model.nets == ['NET1', 'NET2', 'NET3']
Beispiel #5
0
def test_parser_multiline(setup_multiline, parser):
    with set_context(parser.library):
        parser.library.append(
            SubCircuit(name='TESTDEV',
                       pins=['+', '-'],
                       parameters={
                           'X': '1F',
                           'Y': '0.1'
                       }))
    parser.parse(setup_multiline)
    assert len(parser.circuit.elements) == 2
    assert parser.circuit.elements[0].name == 'X1'
    assert parser.circuit.elements[1].name == 'X2'
    assert parser.circuit.elements[0].model == 'TESTDEV'
    assert parser.circuit.elements[1].model == 'TESTDEV'
    assert parser.circuit.nets == ['A', 'B']
Beispiel #6
0
def test_subckt_definition():
    subckt = SubCircuit(
        name = 'TEST_SUBCKT',
        pins = ['PIN1', 'PIN2'],
        parameters = {'PARAM1':1, 'PARAM2':'1E-3', 'PARAM3':'0.1F', 'PARAM4':'HELLO'})
    with pytest.raises(Exception):
        inst = Instance(name='X1', model=subckt)
    with pytest.raises(Exception):
        inst = Instance(name='X1', model=subckt, pins={'PIN1': 'NET10'})
    inst = Instance(name='X1', model=subckt, pins={'PIN1': 'NET10', 'PIN2': 'NET12'})
    assert inst.name == 'X1'
    assert inst.model.name == 'TEST_SUBCKT'
    assert inst.pins == {'PIN1': 'NET10', 'PIN2': 'NET12'}
    assert list(inst.parameters.keys()) == ['PARAM1', 'PARAM2', 'PARAM3', 'PARAM4']
    assert inst.parameters['PARAM1'] == '1'
    assert inst.parameters['PARAM2'] == '1E-3'
    assert inst.parameters['PARAM3'] == '0.1F'
    assert inst.parameters['PARAM4'] == 'HELLO'
    with pytest.raises(Exception):
        inst = subckt(name='X1', model=subckt, pins={'PIN1': 'NET10', 'PIN2': 'NET12'}, parameters={'garbage':''})
    inst = Instance(name='X1', model=subckt, pins={'PIN1': 'NET10', 'PIN2': 'NET12'}, parameters={'param1': '2', 'param3': '1e-16'})
    assert inst.parameters['PARAM1'] == '2'
    assert inst.parameters['PARAM3'] == '1E-16'
Beispiel #7
0
def heirarchical_ckt(matching_subckt, ThreeTerminalDevice, circuit):
    ckt = circuit
    subckt = SubCircuit(name='parent_subckt', pins=['PIN1', 'PIN2'])
    subckt.add(
        Instance(name='X1',
                 model=matching_subckt,
                 pins={
                     'PIN1': 'PIN1',
                     'PIN2': 'PIN2',
                     'PIN3': 'NET1'
                 },
                 parameters={'MYPARAMETER': '2'}))
    subckt.add(
        Instance(name='X2',
                 model=ThreeTerminalDevice,
                 pins={
                     'A': 'NET1',
                     'B': 'PIN1',
                     'C': 'PIN2'
                 },
                 parameters={'MYPARAMETER': '1'}))
    ckt.add(
        Instance(name='XSUB1',
                 model=subckt,
                 pins={
                     'PIN1': 'NET1',
                     'PIN2': 'NET2'
                 }))
    ckt.add(
        Instance(name='XSUB2',
                 model=matching_subckt,
                 pins={
                     'PIN1': 'NET1',
                     'PIN2': 'NET2',
                     'PIN3': 'NET3'
                 },
                 parameters={'MYPARAMETER': '3'}))
    return ckt
Beispiel #8
0
def matching_subckt(ThreeTerminalDevice):
    subckt = SubCircuit(name='TEST_SUBCKT',
                        pins=['PIN1', 'PIN2', 'PIN3'],
                        parameters={'MYPARAMETER': 1})
    subckt.add(
        Instance(name='X1',
                 model=ThreeTerminalDevice,
                 pins={
                     'A': 'PIN3',
                     'B': 'PIN1',
                     'C': 'PIN1'
                 },
                 parameters={'MYPARAMETER': 1}))
    subckt.add(
        Instance(name='X2',
                 model=ThreeTerminalDevice,
                 pins={
                     'A': 'PIN3',
                     'B': 'PIN1',
                     'C': 'PIN2'
                 },
                 parameters={'MYPARAMETER': 'MYPARAMETER'}))
    return subckt
Beispiel #9
0
def test_find_subgraph_matches(simple_circuit, matching_subckt,
                               ThreeTerminalDevice, TwoTerminalDevice):
    netlist, matching_netlist = Graph(simple_circuit), Graph(matching_subckt)
    # Validate true match
    assert len(netlist.find_subgraph_matches(matching_netlist)) == 1
    assert netlist.find_subgraph_matches(matching_netlist)[0] == {
        'X3': 'X1',
        'NET3': 'PIN3',
        'NET1': 'PIN1',
        'X4': 'X2',
        'NET2': 'PIN2'
    }
    # Validate false match
    subckt2 = SubCircuit(name='test_subckt2',
                         pins=['PIN1', 'PIN2', 'PIN3', 'PIN4', 'PIN5'])
    subckt2.add(
        Instance(name='X1',
                 model=ThreeTerminalDevice,
                 pins={
                     'A': 'PIN1',
                     'B': 'PIN3',
                     'C': 'PIN4'
                 }))
    subckt2.add(
        Instance(name='X2',
                 model=ThreeTerminalDevice,
                 pins={
                     'A': 'PIN2',
                     'B': 'PIN3',
                     'C': 'PIN5'
                 }))
    assert len(netlist.find_subgraph_matches(Graph(subckt2))) == 0
    # Validate filtering of redundant subgraphs (There are 4 matches. Only 1 should be returned)
    subckt3 = SubCircuit(name='test_subckt3',
                         pins=['PIN1', 'PIN2', 'PIN3', 'PIN4'])
    subckt3.add(
        Instance(name='X1',
                 model=TwoTerminalDevice,
                 pins={
                     'A': 'PIN1',
                     'B': 'PIN2'
                 }))
    subckt3.add(
        Instance(name='X2',
                 model=TwoTerminalDevice,
                 pins={
                     'A': 'PIN3',
                     'B': 'PIN4'
                 }))
    assert len(netlist.find_subgraph_matches(Graph(subckt3))) == 1