# Buggy code
def extract_descriptor(self):
    ret = NetworkDescriptor()
    topological_node_list = self.topological_order
    for u in topological_node_list:
        for v, layer_id in self.adj_list[u]:
            layer = self.layer_list[layer_id]
            if is_layer(layer, "Conv") and layer.kernel_size not in [
                1,
                (1,),
                (1, 1),
                (1, 1, 1),
            ]:
                ret.add_conv_width(layer_width(layer))
            if is_layer(layer, "Dense"):
                ret.add_dense_width(layer_width(layer))

    # The position of each node, how many Conv and Dense layers before it.
    pos = [0] * len(topological_node_list)
    for v in topological_node_list:
        layer_count = 0
        for u, layer_id in self.reverse_adj_list[v]:
            layer = self.layer_list[layer_id]
            weighted = 0
            if (
                is_layer(layer, "Conv")
                and layer.kernel_size not in [1, (1,), (1, 1), (1, 1, 1)]
            ) or is_layer(layer, "Dense"):
                weighted = 1
            layer_count = max(pos[u] + weighted, layer_count)
        pos[v] = layer_count

    for u in topological_node_list:
        for v, layer_id in self.adj_list[u]:
            if pos[u] == pos[v]:
                continue
            layer = self.layer_list[layer_id]
            if is_layer(layer, "Concatenate"):
                ret.add_skip_connection(
                    pos[u], pos[v], NetworkDescriptor.CONCAT_CONNECT
                )
            if is_layer(layer, "Add"):
                ret.add_skip_connection(pos[u], pos[v], NetworkDescriptor.ADD_CONNECT)

    return ret


# Traceback (RuntimeError)
.....
Epoch 14: loss 0.9113655090332031, metric_value 0.9318181818181818
No loss decrease after 3 epochs
Father ID:  2
[('to_dense_deeper_model', 14), ('to_conv_deeper_model', 1, 5), ('to_add_skip_model', 20, 5), ('to_concat_skip_model', 1, 5), ('to_add_skip_model', 1, 20), ('to_wider_model', 5, 64), ('to_concat_skip_model', 20, 5), ('to_conv_deeper_model', 20, 5), ('to_dense_deeper_model', 18), ('to_concat_skip_model', 1, 20)]
Saving model.
Model ID: 7
Loss: tensor(0.9246, device='cuda:0')
Metric Value: 0.92739898989899
Training model  8
Traceback (most recent call last):
File "ak_my.py", line 15, in <module>
clf.fit(x_train, y_train, time_limit=12 * 60 * 60)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\image_supervised.py", line 238, in fit
run_searcher_once(train_data, test_data, self.path, int(time_remain))
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\image_supervised.py", line 41, in run_searcher_once
searcher.search(train_data, test_data, timeout)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\search.py", line 173, in search
self.metric, self.loss, self.verbose)]))
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\search.py", line 269, in train
verbose).train_model(**trainer_args)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\utils.py", line 101, in train_model
self._train()
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\utils.py", line 122, in _train
outputs = self.model(inputs)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\autokeras\graph.py", line 607, in forward
temp_tensor = torch_layer(edge_input_tensor)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\torch\nn\modules\linear.py", line 55, in forward
return F.linear(input, self.weight, self.bias)
File "C:\Users\kmbmjn\Anaconda3\lib\site-packages\torch\nn\functional.py", line 1024, in linear
return torch.addmm(bias, input, weight.t())
RuntimeError: size mismatch, m1: [128 x 2], m2: [64 x 64] at c:\programdata\miniconda3\conda-bld\pytorch_1533090623466\work\aten\src\thc\generic/THCTensorMathBlas.cu:249

# Fixed code
def extract_descriptor(self):
    ret = NetworkDescriptor()
    topological_node_list = self.topological_order
    for u in topological_node_list:
        for v, layer_id in self.adj_list[u]:
            layer = self.layer_list[layer_id]
            if is_layer(layer, "Conv") and layer.kernel_size not in [
                1,
                (1,),
                (1, 1),
                (1, 1, 1),
            ]:
                ret.add_conv_width(layer_width(layer))
            if is_layer(layer, "Dense"):
                ret.add_dense_width(layer_width(layer))

    # The position of each node, how many Conv and Dense layers before it.
    pos = [0] * len(topological_node_list)
    print(sorted(topological_node_list))
    for v in topological_node_list:
        layer_count = 0
        for u, layer_id in self.reverse_adj_list[v]:
            layer = self.layer_list[layer_id]
            weighted = 0
            if (
                is_layer(layer, "Conv")
                and layer.kernel_size not in [1, (1,), (1, 1), (1, 1, 1)]
            ) or is_layer(layer, "Dense"):
                weighted = 1
            layer_count = max(pos[u] + weighted, layer_count)
        pos[v] = layer_count

    for u in topological_node_list:
        for v, layer_id in self.adj_list[u]:
            if pos[u] == pos[v]:
                continue
            layer = self.layer_list[layer_id]
            if is_layer(layer, "Concatenate"):
                ret.add_skip_connection(
                    pos[u], pos[v], NetworkDescriptor.CONCAT_CONNECT
                )
            if is_layer(layer, "Add"):
                ret.add_skip_connection(pos[u], pos[v], NetworkDescriptor.ADD_CONNECT)

    return ret