def test_dont_omit_for_inference():
    source = open(filename, 'rb').read().decode('utf-8', 'ignore')
    (components, adj) = h.netlist_as_graph(source)
    dataset = PrototypeLinkDataset(['LT1001_TA05.net'], resample=False, train=False)

    assert len(dataset) == 1
    graph = dataset[0]
    expected_node_count = len(components) + len(h.component_types)

    assert graph.n_nodes == expected_node_count 
def test_inference_proto_count():
    source = open(filename, 'rb').read().decode('utf-8', 'ignore')
    (components, adj) = h.netlist_as_graph(source)
    dataset = PrototypeLinkDataset(['LT1001_TA05.net'], resample=False, train=False, normalize=False)

    graph = dataset[0]

    print(graph.x[:,-1])
    proto_count = len(graph.x[:, -1].nonzero()[0])
    print('proto_count', proto_count)
    assert proto_count == len(h.component_types)
def test_load_graph_adj_shuffle():
    source = open(filename, 'rb').read().decode('utf-8', 'ignore')
    (components, adj) = h.netlist_as_graph(source)
    for omitted_idx in range(len(components)):
        graph = OmittedDataset.load_graph(components, adj, omitted_idx, True)
        omitted_degree = len(adj[omitted_idx].nonzero()[0]) + len(
            adj.transpose()[omitted_idx].nonzero()[0])
        assert len(adj[omitted_idx].nonzero()[0]) == len(
            adj.transpose()[omitted_idx].nonzero()
            [0]), f"Found edge without bidirectional edge: {omitted_idx}"
        assert len(adj.nonzero()[0]) - omitted_degree == len(
            graph.a.nonzero()[0])
def test_load_graph_adj():
    source = open(filename, 'rb').read().decode('utf-8', 'ignore')
    (components, adj) = h.netlist_as_graph(source)
    for omitted_idx in range(len(components)):
        graph = OmittedDataset.load_graph(components, adj, omitted_idx)
        omitted_degree = len(adj[omitted_idx].nonzero()[0]) + len(
            adj.transpose()[omitted_idx].nonzero()[0])
        assert len(adj[omitted_idx].nonzero()[0]) == len(
            adj.transpose()[omitted_idx].nonzero()
            [0]), f"Found edge without bidirectional edge: {omitted_idx}"
        assert len(adj.nonzero()[0]) - omitted_degree == len(
            graph.a.nonzero()[0])

        # Check that all edges existed in original
        all_edges = np.array(adj.nonzero()).transpose().tolist()
        edges = np.array(graph.a.nonzero()).transpose().tolist()
        for edge_pair in edges:
            original_ids = [
                e + 1 if e >= omitted_idx else e for e in edge_pair
            ]
            assert original_ids in all_edges
def test_action_nodes_disconnected():
    source = open(filename, 'rb').read().decode('utf-8', 'ignore')
    (components, adj) = h.netlist_as_graph(source)
    for omitted_idx in range(len(components)):
        graph = PrototypeLinkDataset.load_graph(components, adj, omitted_idx)
        assert len(graph.a[len(components)].nonzero()[0]) == 0
def test_flag_omitted_node():
    source = open(filename, 'rb').read().decode('utf-8', 'ignore')
    (components, adj) = h.netlist_as_graph(source)
    for omitted_idx in range(len(components)):
        graph = PrototypeLinkDataset.load_graph(components, adj, omitted_idx)
        assert graph.x[omitted_idx][-1] == 1
def test_component_removed():
    dataset = datasets.omitted([filename], resample=False)
    contents = next(h.valid_netlist_sources([filename]))
    (components, adj) = h.netlist_as_graph(contents)
    for graph in dataset:
        assert graph.x.shape[0] == len(components) - 1