Adding and Removing Components

This tutorial demonstrates how to add and remove nodes from the killweb.

[1]:
import os
%matplotlib widget

from mimik.killweb import Killweb

Initialize an empty killweb.

[2]:
killweb = Killweb(silent=True)

Define the first component to add to the killweb and visualize.

[3]:
killweb.add_new_component("Find1")
killweb.create_component_networkx_visualization();

Define the second component and add to the graph. Use the from_components argument to define a list of nodes that connect to the new component.

[4]:
killweb.add_new_component("Fix1", from_components = ['Find1'])
killweb.create_component_networkx_visualization();

Add a new find component that connects to Fix1. Use the to_components arguement to define the list of connected components.

[5]:
killweb.add_new_component("Find2", to_components = ['Fix1'])
killweb.create_component_networkx_visualization();

Add the rest of the components.

[6]:
killweb.add_new_component("Fix2", from_components = ["Find1", "Find2"])
killweb.add_new_component("Track1", from_components = ["Fix1", "Fix2"])
killweb.add_new_component("Track2", from_components = ["Fix1", "Fix2"])
killweb.add_new_component("Target", from_components = ["Track1", "Track2"])
killweb.create_component_networkx_visualization();

Components can be removed from the graph. The cell below lists the components in the graph. The next cell removes the ‘Target” component from the graph and prints the new list of components.

[7]:
killweb.component_graph.nodes()
[7]:
NodeView(('Find1', 'Fix1', 'Find2', 'Fix2', 'Track1', 'Track2', 'Target'))
[8]:
killweb.remove_component("Target")
killweb.component_graph.nodes()
[8]:
NodeView(('Find1', 'Fix1', 'Find2', 'Fix2', 'Track1', 'Track2'))

Edges can be added to and removed from the graph to connect components. The cell below adds an edge from ‘Find1’ to ‘Track1’. The following cell demonstrates how to remove this edge.

[9]:
killweb.add_new_edge('Find1', 'Track1')
killweb.create_component_networkx_visualization();
[10]:
killweb.remove_edge('Find1', 'Track1')
killweb.create_component_networkx_visualization();