def test_mutation_add_node_max_vertex(): complex_operation = MutableEdge((PointConv2D((1, 4)), ), max_vertices=2) assert not complex_operation.mutation_add_vertex() complex_operation = MutableEdge((PointConv2D((1, 4)), ), max_vertices=3) assert complex_operation.mutation_add_vertex() assert len(complex_operation.vertices_topo_order) == 3 assert not complex_operation.mutation_add_vertex()
def test_max_vertices(): try: MutableEdge((PointConv2D((1, 4)), ), max_vertices=1) assert False except RuntimeError: pass try: MutableEdge((PointConv2D((1, 4)), ), max_vertices=2) except RuntimeError: assert False
def build_graph(self) -> None: conv_edge1 = MutableEdge((BatchNorm(), PointConv2D( (20, 40)), DepthwiseConv2D(), IdentityOperation(), SeparableConv2D( (20, 40)), Dropout(0.25), ReLU()), max_vertices=10, initialize_with_identity=False) conv_edge2 = conv_edge1.deep_copy() vertex1 = Vertex(name='V1') vertex2 = Vertex(name='V2') self.input_vertex.add_edge(conv_edge1, vertex1) vertex7 = Vertex(name='V7') vertex1.add_edge(MaxPool2D(), vertex7) vertex7.add_edge(conv_edge2, vertex2) vertex3 = Vertex(name='V3') vertex2.add_edge(Flatten(), vertex3) vertex4 = Vertex(name='V4') vertex3.add_edge(Dense(512), vertex4) vertex5 = Vertex(name='V5') vertex4.add_edge(ReLU(), vertex5) vertex6 = Vertex(name='V6') vertex5.add_edge(Dropout(0.5), vertex6) vertex6.add_edge(Dense(num_classes), self.output_vertex)
def basic_graph_no_v12() -> Tuple[MutableEdge, Vertex, Vertex, Vertex, Vertex]: complex_operation = MutableEdge((PointConv2D((1, 4)), MaxPool2D())) vertex1 = Vertex() vertex2 = Vertex() vertex3 = Vertex() vertex4 = Vertex() edge1 = IdentityOperation() edge2 = IdentityOperation() edge3 = IdentityOperation() edge4 = IdentityOperation() edge5 = IdentityOperation() edge6 = IdentityOperation() complex_operation.input_vertex.out_bound_edges.clear() complex_operation.input_vertex.out_bound_edges.extend([edge1, edge2, edge3]) edge1.end_vertex = vertex1 edge2.end_vertex = vertex2 edge3.end_vertex = vertex4 vertex1.out_bound_edges.append(edge6) edge6.end_vertex = complex_operation.output_vertex vertex2.out_bound_edges.append(edge4) edge4.end_vertex = complex_operation.output_vertex vertex3.out_bound_edges.append(edge5) edge5.end_vertex = complex_operation.output_vertex return complex_operation, vertex1, vertex2, vertex3, vertex4
def test_complex_op_creation(): complex_operation = MutableEdge((PointConv2D((1, 4)), )) assert len(complex_operation.available_operations) == 1 assert len(complex_operation.vertices_topo_order) == 2 assert (complex_operation.vertices_topo_order[0] is complex_operation.output_vertex) assert (complex_operation.vertices_topo_order[1] is complex_operation.input_vertex)
def build_graph(self) -> None: edge1 = PointConv2D((0, 3)) edge2 = ReLU() edge3 = IdentityOperation() vertex1 = Vertex(name='V1') self.input_vertex.out_bound_edges.append(edge1) self.input_vertex.out_bound_edges.append(edge3) vertex1.out_bound_edges.append(edge2) edge1.end_vertex = vertex1 edge2.end_vertex = self.output_vertex edge3.end_vertex = self.output_vertex
def test_remove_edge_fail2(): complex_operation = MutableEdge((PointConv2D((1, 4)), MaxPool2D())) edge1 = IdentityOperation() edge2 = IdentityOperation() complex_operation.input_vertex.out_bound_edges.clear() complex_operation.input_vertex.out_bound_edges.append(edge1) middle_vertex = Vertex() complex_operation.vertices_topo_order.append(middle_vertex) edge1.end_vertex = middle_vertex middle_vertex.out_bound_edges.append(edge2) edge2.end_vertex = complex_operation.output_vertex assert not complex_operation.mutation_remove_edge()
def test_remove_edge_success(): complex_operation = MutableEdge((PointConv2D((1, 4)), MaxPool2D())) edge1 = IdentityOperation() edge2 = IdentityOperation() complex_operation.input_vertex.out_bound_edges.clear() complex_operation.input_vertex.out_bound_edges.append(edge1) middle_vertex = Vertex() complex_operation.vertices_topo_order.append(middle_vertex) edge1.end_vertex = middle_vertex middle_vertex.out_bound_edges.append(edge2) edge2.end_vertex = complex_operation.output_vertex # Edge from input to output. So now we can remove one edge edge3 = IdentityOperation() complex_operation.input_vertex.out_bound_edges.append(edge3) edge3.end_vertex = complex_operation.output_vertex assert complex_operation.mutation_remove_edge() assert len(complex_operation.input_vertex.out_bound_edges) == 1
def test_remove_node_fail(): complex_operation = MutableEdge((PointConv2D((1, 4)), )) assert not complex_operation.mutation_remove_vertex() complex_operation.input_vertex.out_bound_edges.clear() vertex1 = Vertex() vertex2 = Vertex() edge1 = IdentityOperation() edge2 = IdentityOperation() edge3 = IdentityOperation() complex_operation.input_vertex.out_bound_edges.append(edge1) edge1.end_vertex = vertex1 vertex1.out_bound_edges.append(edge2) edge2.end_vertex = vertex2 vertex2.out_bound_edges.append(edge3) edge3.end_vertex = complex_operation.output_vertex complex_operation.sort_vertices() assert len(complex_operation.vertices_topo_order) == 4 assert not complex_operation.mutation_remove_vertex()
def test_point_conv2d(): edge = PointConv2D((0, 100)) edge_copy = cast(type(edge), edge.deep_copy()) assert edge.out_channel_range == edge_copy.out_channel_range
def test_remove_edge_fail1(): complex_operation = MutableEdge((PointConv2D((1, 4)), MaxPool2D())) assert not complex_operation.mutation_remove_edge()