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
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
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
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']